[Scummvm-cvs-logs] CVS: scummvm/gui EditTextWidget.cpp,1.18,1.19 launcher.cpp,1.69,1.70 newgui.cpp,1.66,1.67 newgui.h,1.31,1.32 options.cpp,1.35,1.36
Max Horn
fingolfin at users.sourceforge.net
Tue Nov 4 14:02:07 CET 2003
Update of /cvsroot/scummvm/scummvm/gui
In directory sc8-pr-cvs1:/tmp/cvs-serv31727
Modified Files:
EditTextWidget.cpp launcher.cpp newgui.cpp newgui.h
options.cpp
Log Message:
modified NewGui::drawString to shorten strings which don't fit using ellipsis (disabled for the EditTextWidget for now)
Index: EditTextWidget.cpp
===================================================================
RCS file: /cvsroot/scummvm/scummvm/gui/EditTextWidget.cpp,v
retrieving revision 1.18
retrieving revision 1.19
diff -u -d -r1.18 -r1.19
--- EditTextWidget.cpp 2 Nov 2003 17:41:01 -0000 1.18
+++ EditTextWidget.cpp 4 Nov 2003 22:00:31 -0000 1.19
@@ -151,7 +151,7 @@
// Draw the text
adjustOffset();
- g_gui.drawString(_label, _x + 2, _y + 3, _w - 6, g_gui._textcolor, kTextAlignLeft, -_labelOffset);
+ g_gui.drawString(_label, _x + 2, _y + 3, _w - 6, g_gui._textcolor, kTextAlignLeft, -_labelOffset, false);
}
int EditTextWidget::getCaretPos() {
Index: launcher.cpp
===================================================================
RCS file: /cvsroot/scummvm/scummvm/gui/launcher.cpp,v
retrieving revision 1.69
retrieving revision 1.70
diff -u -d -r1.69 -r1.70
--- launcher.cpp 4 Nov 2003 21:17:33 -0000 1.69
+++ launcher.cpp 4 Nov 2003 22:00:32 -0000 1.70
@@ -127,7 +127,6 @@
yoffset += 16;
// GUI: Label for the game path
- // TODO: Allow editing, and clip to the RIGHT on long paths (to keep meaningful portions)
new StaticTextWidget(tab, 10, yoffset, 40, kLineHeight, "Path: ", kTextAlignRight);
new StaticTextWidget(tab, 50, yoffset, _w - 50 - 10, kLineHeight, path, kTextAlignLeft);
Index: newgui.cpp
===================================================================
RCS file: /cvsroot/scummvm/scummvm/gui/newgui.cpp,v
retrieving revision 1.66
retrieving revision 1.67
diff -u -d -r1.66 -r1.67
--- newgui.cpp 3 Nov 2003 01:16:29 -0000 1.66
+++ newgui.cpp 4 Nov 2003 22:00:35 -0000 1.67
@@ -435,16 +435,68 @@
return guifont[c+6];
}
-void NewGui::drawString(const String &str, int x, int y, int w, NewGuiColor color, int align, int deltax) {
+void NewGui::drawString(const String &s, int x, int y, int w, NewGuiColor color, int align, int deltax, bool useEllipsis) {
const int leftX = x, rightX = x + w;
- int width = getStringWidth(str);
+ int i;
+ int width = getStringWidth(s);
+ String str;
+
+ 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.
+ const int ellipsisWidth = getStringWidth("...");
+
+ // SLOW algorithm to remove enough of the middle. But it is good enough
+ // for now.
+ const int halfWidth = (w - ellipsisWidth) / 2;
+ int w2 = 0;
+
+ for (i = 0; i < s.size(); ++i) {
+ int charWidth = getCharWidth(s[i]);
+ if (w2 + charWidth > halfWidth)
+ break;
+ w2 += charWidth;
+ str += s[i];
+ }
+ // At this point we know that the first 'i' chars are together 'w2'
+ // pixels wide. We took the first i-1, and add "..." to them.
+ str += "...";
+
+ // 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
+ // (w - (w2+ellipsisWidth)) more pixels.
+ // Thus we skip ((width - w2) - (w - (w2+ellipsisWidth))) =
+ // (width + ellipsisWidth - w)
+ int skip = width + ellipsisWidth - w;
+ for (; i < s.size() && skip > 0; ++i) {
+ skip -= getCharWidth(s[i]);
+ }
+
+ // Append the remaining chars, if any
+ for (; i < s.size(); ++i) {
+ str += s[i];
+ }
+
+ width = getStringWidth(str);
+
+ } else {
+ str = s;
+ }
+
+
+
if (align == kTextAlignCenter)
x = x + (w - width - 1)/2;
else if (align == kTextAlignRight)
x = x + w - width;
x += deltax;
- for (int i = 0; i < str.size(); ++i) {
+ for (i = 0; i < str.size(); ++i) {
w = getCharWidth(str[i]);
if (x+w > rightX)
break;
Index: newgui.h
===================================================================
RCS file: /cvsroot/scummvm/scummvm/gui/newgui.h,v
retrieving revision 1.31
retrieving revision 1.32
diff -u -d -r1.31 -r1.32
--- newgui.h 2 Nov 2003 18:57:20 -0000 1.31
+++ newgui.h 4 Nov 2003 22:00:35 -0000 1.32
@@ -137,7 +137,7 @@
void drawChar(byte c, int x, int y, NewGuiColor color);
int getStringWidth(const String &str);
int getCharWidth(byte c);
- void drawString(const String &str, int x, int y, int w, NewGuiColor color, int align = kTextAlignLeft, int deltax = 0);
+ void drawString(const String &str, int x, int y, int w, NewGuiColor color, int align = kTextAlignLeft, int deltax = 0, bool useEllipsis = true);
void blitFromBuffer(int x, int y, int w, int h, const byte *buf, int pitch);
void blitToBuffer(int x, int y, int w, int h, byte *buf, int pitch);
Index: options.cpp
===================================================================
RCS file: /cvsroot/scummvm/scummvm/gui/options.cpp,v
retrieving revision 1.35
retrieving revision 1.36
diff -u -d -r1.35 -r1.36
--- options.cpp 4 Nov 2003 21:17:33 -0000 1.35
+++ options.cpp 4 Nov 2003 22:00:36 -0000 1.36
@@ -125,7 +125,6 @@
yoffset = vBorder;
// The MIDI mode popup & a label
- //new StaticTextWidget(tab, 5, vBorder+2, 100, kLineHeight, "Music driver: ", kTextAlignRight);
_midiPopUp = new PopUpWidget(tab, 5, yoffset, 280, kLineHeight, "Music driver: ", 100);
yoffset += 16;
More information about the Scummvm-git-logs
mailing list