[Scummvm-cvs-logs] CVS: scummvm/gui newgui.cpp,1.7,1.8 newgui.h,1.4,1.5

Max Horn fingolfin at users.sourceforge.net
Thu Sep 19 10:04:03 CEST 2002


Update of /cvsroot/scummvm/scummvm/gui
In directory usw-pr-cvs1:/tmp/cvs-serv9164/gui

Modified Files:
	newgui.cpp newgui.h 
Log Message:
improved the text display in a newgui a bit: make the font proportiona; implemented text alignment (left/right/center); alpha blending now not anymore at 50% but at 66%; moved some #defines to util.h

Index: newgui.cpp
===================================================================
RCS file: /cvsroot/scummvm/scummvm/gui/newgui.cpp,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -d -r1.7 -r1.8
--- newgui.cpp	19 Sep 2002 16:06:50 -0000	1.7
+++ newgui.cpp	19 Sep 2002 17:03:24 -0000	1.8
@@ -28,6 +28,7 @@
 
 /*
  * TODO list
+ * - use a nice font
  * - implement the missing / incomplete dialogs
  * - add more widgets
  * - allow multi line (l/c/r aligned) text via StaticTextWidget ?
@@ -37,18 +38,6 @@
  * - ...
  */
 
-// FIXME - this macro assumes that we use 565 mode. But what if we are in 555 mode?
-#define RGB_TO_16(r,g,b)	(((((r)>>3)&0x1F) << 11) | ((((g)>>2)&0x3F) << 5) | (((b)>>3)&0x1F))
-//#define RGB_TO_16(r,g,b)	(((((r)>>3)&0x1F) << 10) | ((((g)>>3)&0x1F) << 5) | (((b)>>3)&0x1F))
-
-#define RED_FROM_16(x)		((((x)>>11)&0x1F) << 3)
-#define GREEN_FROM_16(x)	((((x)>>5)&0x3F) << 2)
-#define BLUE_FROM_16(x)		(((x)&0x1F) << 3)
-
-//#define RED_FROM_16(x)	((((x)>>10)&0x1F) << 3)
-//#define GREEN_FROM_16(x)	((((x)>>5)&0x1F) << 3)
-//#define BLUE_FROM_16(x)	(((x)&0x1F) << 3)
-
 
 NewGui::NewGui(Scumm *s) : _s(s), _system(s->_system), _screen(0),
 	_use_alpha_blending(true), _need_redraw(false),_prepare_for_gui(true),
@@ -368,18 +357,18 @@
 
 void NewGui::blendRect(int x, int y, int w, int h, int16 color)
 {
-	int r = RED_FROM_16(color);
-	int g = GREEN_FROM_16(color);
-	int b = BLUE_FROM_16(color);
+	int r = RED_FROM_16(color) * 2;
+	int g = GREEN_FROM_16(color) * 2;
+	int b = BLUE_FROM_16(color) * 2;
 	int16 *ptr = getBasePtr(x, y);
 	if (ptr == NULL)
 		return;
 
 	while (h--) {
 		for (int i = 0; i < w; i++) {
-			ptr[i] = RGB_TO_16((RED_FROM_16(ptr[i])+r)/2,
-			                   (GREEN_FROM_16(ptr[i])+g)/2,
-			                   (BLUE_FROM_16(ptr[i])+b)/2);
+			ptr[i] = RGB_TO_16((RED_FROM_16(ptr[i])+r)/3,
+			                   (GREEN_FROM_16(ptr[i])+g)/3,
+			                   (BLUE_FROM_16(ptr[i])+b)/3);
 //			ptr[i] = color;
 		}
 		ptr += _screen_pitch;
@@ -474,37 +463,66 @@
 	}
 }
 
-void NewGui::drawString(const char *str, int x, int y, int w, int16 color, int align)
+int NewGui::getStringWidth(const char *str)
 {
-#if 1
-	if (0) {
-#else
-	if (_s->_gameId) {						/* If a game is active.. */
-		StringTab *st = &_s->string[5];
-		st->charset = 1;
-		st->center = (align == kTextAlignCenter);
-		st->color = color;
+	int space = 0;
+	while (*str)
+		space += getCharWidth(*str++);
+	return space;
+}
 
-		if (align == kTextAlignLeft)
-			st->xpos = x;
-		else if (align == kTextAlignCenter)
-			st->xpos = x + w/2;
-		else if (align == kTextAlignRight)
-			st->xpos = x + w - _s->charset.getStringWidth(0, (byte *)str, 0);
+int NewGui::getCharWidth(char c)
+{
+	int space;
 
-		st->ypos = y;
-		st->right = x + w;
-	
-		_s->_messagePtr = (byte *)str;
-		_s->drawString(5);
-#endif
-	} else {
-		// FIXME - support center/right align, use nicer custom font.
-		// Ultimately, we might want to *always* draw our messages this way,
-		// but only if we have a nice font.
-		uint len = strlen(str);
-		for (uint letter = 0; letter < len; letter++)
-			drawChar(str[letter], x + (letter * 8), y, color);
+	switch (c) {
+	case '.':
+	case ':':
+	case '\'':
+	case '!':
+		space = 3;
+		break;
+	case 'I':
+	case 'i':
+	case 'l':
+		space = 5;
+		break;
+	case ';':
+	case ' ':
+		space = 4;
+		break;
+	case '(':
+	case ')':
+		space = 5;
+		break;
+	case 'c':
+		space = 6;
+		break;
+	case '4':
+	case '/':
+	case 'W':
+	case 'w':
+	case 'M':
+	case 'm':
+		space = 8;
+		break;
+	default:
+		space = 7;
+	}
+	return space;
+}
+
+void NewGui::drawString(const char *str, int x, int y, int w, int16 color, int align)
+{
+	int width = getStringWidth(str);
+	if (align == kTextAlignCenter)
+		x = x + (w - width - 1)/2;
+	else if (align == kTextAlignRight)
+		x = x + w - width;
+	while (*str) {
+		drawChar(*str, x, y, color);
+		x += getCharWidth(*str);
+		str++;
 	}
 }
 

Index: newgui.h
===================================================================
RCS file: /cvsroot/scummvm/scummvm/gui/newgui.h,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -d -r1.4 -r1.5
--- newgui.h	19 Sep 2002 16:06:51 -0000	1.4
+++ newgui.h	19 Sep 2002 17:03:24 -0000	1.5
@@ -139,7 +139,9 @@
 	void checkerRect(int x, int y, int w, int h, int16 color);
 	void frameRect(int x, int y, int w, int h, int16 color);
 	void addDirtyRect(int x, int y, int w, int h);
-	void drawChar(const char c, int x, int y, int16 color);
+	void drawChar(char c, int x, int y, int16 color);
+	int getStringWidth(const char *str);
+	int getCharWidth(char c);
 	void drawString(const char *str, int x, int y, int w, int16 color, int align = kTextAlignLeft);
 
 	void drawBitmap(uint32 bitmap[8], int x, int y, int16 color);





More information about the Scummvm-git-logs mailing list