[Scummvm-cvs-logs] SF.net SVN: scummvm:[46381] scummvm/trunk

fingolfin at users.sourceforge.net fingolfin at users.sourceforge.net
Tue Dec 15 09:19:59 CET 2009


Revision: 46381
          http://scummvm.svn.sourceforge.net/scummvm/?rev=46381&view=rev
Author:   fingolfin
Date:     2009-12-15 08:19:59 +0000 (Tue, 15 Dec 2009)

Log Message:
-----------
GUI: Shorten button labels if too long, and improve the shortening logic

Modified Paths:
--------------
    scummvm/trunk/graphics/font.cpp
    scummvm/trunk/gui/ThemeEngine.cpp

Modified: scummvm/trunk/graphics/font.cpp
===================================================================
--- scummvm/trunk/graphics/font.cpp	2009-12-15 08:19:34 UTC (rev 46380)
+++ scummvm/trunk/graphics/font.cpp	2009-12-15 08:19:59 UTC (rev 46381)
@@ -782,20 +782,31 @@
 	return space;
 }
 
-void Font::drawString(Surface *dst, const Common::String &s, int x, int y, int w, uint32 color, TextAlign align, int deltax, bool useEllipsis) const {
+void Font::drawString(Surface *dst, const Common::String &sOld, int x, int y, int w, uint32 color, TextAlign align, int deltax, bool useEllipsis) const {
 	assert(dst != 0);
 	const int leftX = x, rightX = x + w;
 	uint i;
+	Common::String s = sOld;
 	int width = getStringWidth(s);
 	Common::String str;
 
+	if (useEllipsis && width > w && s.hasSuffix("...")) {
+		// String is too wide. Check whether it ends in an ellipsis
+		// ("..."). If so, remove that and try again!
+		s.deleteLastChar();
+		s.deleteLastChar();
+		s.deleteLastChar();
+		width = getStringWidth(s);
+	}
+
 	if (useEllipsis && width > w) {
-		// String is too wide. So we shorten it "intellegently", by replacing
-		// parts of it by an ellipsis ("..."). There are three possibilities
-		// for this: replace the start, the end, or the middle of the string.
-		// What is best really depends on the context; but unless we want to
-		// make this configurable, replacing the middle probably is a good
-		// compromise.
+		// String is too wide. So we shorten it "intelligently" by
+		// replacing parts of the string by an ellipsis. There are
+		// three possibilities for this: replace the start, the end, or
+		// the middle of the string. What is best really depends on the
+		// context; but unless we want to make this configurable,
+		// replacing the middle seems to be a good compromise.
+
 		const int ellipsisWidth = getStringWidth("...");
 
 		// SLOW algorithm to remove enough of the middle. But it is good enough
@@ -816,7 +827,7 @@
 
 		// The original string is width wide. Of those we already skipped past
 		// w2 pixels, which means (width - w2) remain.
-		// The new str is (w2+ellipsisWidth) wide, so we can accomodate about
+		// The new str is (w2+ellipsisWidth) wide, so we can accommodate about
 		// (w - (w2+ellipsisWidth)) more pixels.
 		// Thus we skip ((width - w2) - (w - (w2+ellipsisWidth))) =
 		// (width + ellipsisWidth - w)
@@ -831,7 +842,6 @@
 		}
 
 		width = getStringWidth(str);
-
 	} else {
 		str = s;
 	}

Modified: scummvm/trunk/gui/ThemeEngine.cpp
===================================================================
--- scummvm/trunk/gui/ThemeEngine.cpp	2009-12-15 08:19:34 UTC (rev 46380)
+++ scummvm/trunk/gui/ThemeEngine.cpp	2009-12-15 08:19:59 UTC (rev 46381)
@@ -850,7 +850,7 @@
 		dd = kDDButtonDisabled;
 
 	queueDD(dd, r, 0, hints & WIDGET_CLEARBG);
-	queueDDText(getTextData(dd), getTextColor(dd), r, str, false, false, _widgets[dd]->_textAlignH, _widgets[dd]->_textAlignV);
+	queueDDText(getTextData(dd), getTextColor(dd), r, str, false, true, _widgets[dd]->_textAlignH, _widgets[dd]->_textAlignV);
 }
 
 void ThemeEngine::drawLineSeparator(const Common::Rect &r, WidgetStateInfo state) {


This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.




More information about the Scummvm-git-logs mailing list