[Scummvm-cvs-logs] CVS: scummvm/gui newfont.cpp,NONE,1.1 scummfont.cpp,NONE,1.1 PopUpWidget.cpp,1.30,1.31 console.cpp,1.41,1.42 dialog.h,1.27,1.28 font.cpp,1.1,1.2 font.h,1.2,1.3 module.mk,1.10,1.11 newgui.cpp,1.79,1.80 newgui.h,1.38,1.39 widget.cpp,1.37,1.38 widget.h,1.34,1.35

Max Horn fingolfin at users.sourceforge.net
Sat Mar 13 05:13:01 CET 2004


Update of /cvsroot/scummvm/scummvm/gui
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv11408

Modified Files:
	PopUpWidget.cpp console.cpp dialog.h font.cpp font.h module.mk 
	newgui.cpp newgui.h widget.cpp widget.h 
Added Files:
	newfont.cpp scummfont.cpp 
Log Message:
Revamped the font code: now it's very easy to switch between the 'original' SCUMM font and any new font... or to have multiple different fonts (like, one for 320x240 and and one for 640x480); furthermore, font rendering can now be done w/o using NewGui

--- NEW FILE: newfont.cpp ---
/* Generated by convbdf on Thu Nov 20 00:15:51 2003. */
#include "common/stdafx.h"
#include "gui/font.h"

/* Font information:
   name: 04b-16b-10
   facename: 04b-16b-10
   w x h: 9x10
   size: 94
   ascent: 8
   descent: 2
   first char: 33 (0x21)
   last char: 126 (0x7e)
   default char: 33 (0x21)
   proportional: yes
   
*/

namespace GUI {
[...2561 lines suppressed...]

const NewFont g_sysfont;

#if 0
const Font g_sysfont = {
	"04b-16b-10",
	9,
	10,
	8,
	33,
	94,
	_font_bits,
	0,  /* no encode table*/
	_sysfont_width,
	33,
	sizeof(_font_bits)/sizeof(bitmap_t),
};
#endif

} // End of namespace GUI

--- NEW FILE: scummfont.cpp ---
/* ScummVM - Scumm Interpreter
 * Copyright (C) 2002-2004 The ScummVM project
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 *
 * $Header: /cvsroot/scummvm/scummvm/gui/scummfont.cpp,v 1.1 2004/03/13 13:03:25 fingolfin Exp $
 */

#include "stdafx.h"
#include "gui/font.h"

namespace GUI {

#ifdef __PALM_OS__
static const byte *guifont;
#else
// Built-in font
static const byte guifont[] = {
0,0,99,1,226,8,4,8,6,8,6,0,0,0,0,0,0,0,0,0,0,0,8,2,1,8,0,0,0,0,0,0,0,0,0,0,0,0,4,3,7,8,7,7,8,4,5,5,8,7,4,7,3,8,7,7,7,7,8,7,7,7,7,7,3,4,7,5,7,7,8,7,7,7,7,7,7,7,7,5,7,7,
7,8,7,7,7,7,7,7,7,7,7,8,7,7,7,5,8,5,8,8,7,7,7,6,7,7,7,7,7,5,6,7,5,8,7,7,7,7,7,7,7,7,7,8,7,7,7,5,3,5,7,8,7,7,7,7,7,7,0,6,7,7,7,5,5,5,7,0,6,8,8,7,7,7,7,7,0,7,7,0,0,
0,0,0,7,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,7,0,0,0,0,0,0,0,0,1,3,6,12,
24,62,3,0,128,192,96,48,24,124,192,0,0,3,62,24,12,6,3,1,0,192,124,24,48,96,192,128,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,237,74,72,0,0,0,0,0,128,128,128,0,0,0,0,0,0,0,0,0,0,0,0,0,60,66,153,161,161,153,66,60,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,96,96,96,96,0,0,96,0,102,102,102,0,0,0,0,0,102,102,255,102,255,102,102,0,24,62,96,60,6,124,24,0,98,102,12,24,48,102,70,0,60,102,60,56,103,102,63,0,96,48,16,0,0,0,0,0,24,48,96,96,96,48,24,0,96,48,24,24,24,48,96,0,
0,102,60,255,60,102,0,0,0,24,24,126,24,24,0,0,0,0,0,0,0,48,48,96,0,0,0,126,0,0,0,0,0,0,0,0,0,96,96,0,0,3,6,12,24,48,96,0,60,102,102,102,102,102,60,0,24,24,56,24,24,24,126,0,60,102,6,12,48,96,126,0,60,102,6,28,6,102,60,0,6,
14,30,102,127,6,6,0,126,96,124,6,6,102,60,0,60,102,96,124,102,102,60,0,126,102,12,24,24,24,24,0,60,102,102,60,102,102,60,0,60,102,102,62,6,102,60,0,0,0,96,0,0,96,0,0,0,0,48,0,0,48,48,96,14,24,48,96,48,24,14,0,0,0,120,0,120,0,0,0,112,24,
12,6,12,24,112,0,60,102,6,12,24,0,24,0,0,0,0,255,255,0,0,0,24,60,102,126,102,102,102,0,124,102,102,124,102,102,124,0,60,102,96,96,96,102,60,0,120,108,102,102,102,108,120,0,126,96,96,120,96,96,126,0,126,96,96,120,96,96,96,0,60,102,96,110,102,102,60,0,102,102,102,
126,102,102,102,0,120,48,48,48,48,48,120,0,30,12,12,12,12,108,56,0,102,108,120,112,120,108,102,0,96,96,96,96,96,96,126,0,99,119,127,107,99,99,99,0,102,118,126,126,110,102,102,0,60,102,102,102,102,102,60,0,124,102,102,124,96,96,96,0,60,102,102,102,102,60,14,0,124,102,102,124,
120,108,102,0,60,102,96,60,6,102,60,0,126,24,24,24,24,24,24,0,102,102,102,102,102,102,60,0,102,102,102,102,102,60,24,0,99,99,99,107,127,119,99,0,102,102,60,24,60,102,102,0,102,102,102,60,24,24,24,0,126,6,12,24,48,96,126,0,120,96,96,96,96,96,120,0,3,6,12,24,48,
96,192,0,120,24,24,24,24,24,120,0,0,0,0,0,0,219,219,0,0,0,0,0,0,0,0,255,102,102,102,0,0,0,0,0,0,0,60,6,62,102,62,0,0,96,96,124,102,102,124,0,0,0,60,96,96,96,60,0,0,6,6,62,102,102,62,0,0,0,60,102,126,96,60,0,0,14,24,62,24,24,
24,0,0,0,62,102,102,62,6,124,0,96,96,124,102,102,102,0,0,48,0,112,48,48,120,0,0,12,0,12,12,12,12,120,0,96,96,108,120,108,102,0,0,112,48,48,48,48,120,0,0,0,102,127,127,107,99,0,0,0,124,102,102,102,102,0,0,0,60,102,102,102,60,0,0,0,124,102,102,124,96,
96,0,0,62,102,102,62,6,6,0,0,124,102,96,96,96,0,0,0,62,96,60,6,124,0,0,24,126,24,24,24,14,0,0,0,102,102,102,102,62,0,0,0,102,102,102,60,24,0,0,0,99,107,127,62,54,0,0,0,102,60,24,60,102,0,0,0,102,102,102,62,12,120,0,0,126,12,24,48,126,0,
24,48,48,96,48,48,24,0,96,96,96,0,96,96,96,0,96,48,48,24,48,48,96,0,0,0,97,153,134,0,0,0,8,12,14,255,255,14,12,8,60,102,96,96,102,60,24,56,102,0,102,102,102,102,62,0,12,24,60,102,126,96,60,0,24,36,60,6,62,102,62,0,102,0,60,6,62,102,62,0,48,
24,60,6,62,102,62,0,0,0,0,0,0,0,0,0,0,60,96,96,96,60,24,56,24,36,60,102,126,96,60,0,102,0,60,102,126,96,60,0,48,24,60,102,126,96,60,0,0,216,0,112,48,48,120,0,48,72,0,112,48,48,120,0,96,48,0,112,48,48,120,0,102,24,60,102,126,102,102,0,0,0,
0,0,0,0,0,0,24,48,124,96,120,96,124,0,0,0,108,26,126,216,110,0,30,40,40,126,72,136,142,0,24,36,60,102,102,102,60,0,102,0,60,102,102,102,60,0,48,24,60,102,102,102,60,0,24,36,0,102,102,102,62,0,48,24,102,102,102,102,62,0,0,0,0,0,0,0,0,0,102,60,102,
102,102,102,60,0,102,0,102,102,102,102,60,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,12,24,60,6,62,102,62,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,28,54,54,124,102,102,124,64,0,0,0
};
#endif

int ScummFont::getCharWidth(byte chr) const {
	return guifont[chr+6];
}

//void ScummFont::drawChar(byte chr, int xx, int yy, OverlayColor color) {
void ScummFont::drawChar(const Surface *dst, byte chr, int x, int y, uint32 color) const {
	assert(dst != 0);
	byte *ptr = (byte *)dst->pixels + x * dst->bytesPerPixel + y * dst->pitch;

	const byte *tmp = guifont + 6 + guifont[4] + chr * 8;
	uint buffer = 0;
	uint mask = 0;

	for (y = 0; y < 8; y++) {
		for (x = 0; x < 8; x++) {
			unsigned char c;
			mask >>= 1;
			if (mask == 0) {
				buffer = *tmp++;
				mask = 0x80;
			}
			c = ((buffer & mask) != 0);
			if (c) {
				if (dst->bytesPerPixel == 1)
					ptr[x] = color;
				else if (dst->bytesPerPixel == 2)
					((uint16 *)ptr)[x] = color;
			}
		}
		ptr += dst->pitch;
	}
}

const ScummFont g_scummfont;

} // End of namespace GUI

#ifdef __PALM_OS__
#include "scumm_globals.h"

_GINIT(NewGui)
#ifndef NEW_FONT_CODE
_GSETPTR(GUI::guifont, GBVARS_GUIFONT_INDEX, byte, GBVARS_SCUMM)
#endif
_GEND

_GRELEASE(NewGui)
#ifndef NEW_FONT_CODE
_GRELEASEPTR(GBVARS_GUIFONT_INDEX, GBVARS_SCUMM)
#endif
_GEND

#endif

Index: PopUpWidget.cpp
===================================================================
RCS file: /cvsroot/scummvm/scummvm/gui/PopUpWidget.cpp,v
retrieving revision 1.30
retrieving revision 1.31
diff -u -d -r1.30 -r1.31
--- PopUpWidget.cpp	13 Mar 2004 12:33:31 -0000	1.30
+++ PopUpWidget.cpp	13 Mar 2004 13:03:25 -0000	1.31
@@ -345,7 +345,7 @@
 
 	// Draw the selected entry, if any
 	if (_selectedItem >= 0) {
-		int align = (gui->getStringWidth(_entries[_selectedItem].name) > w-6) ? kTextAlignRight : kTextAlignLeft;
+		TextAlignment align = (gui->getStringWidth(_entries[_selectedItem].name) > w-6) ? kTextAlignRight : kTextAlignLeft;
 		gui->drawString(_entries[_selectedItem].name, x+2, _y+3, w-6, !isEnabled() ? gui->_color : gui->_textcolor, align);
 	}
 }

Index: console.cpp
===================================================================
RCS file: /cvsroot/scummvm/scummvm/gui/console.cpp,v
retrieving revision 1.41
retrieving revision 1.42
diff -u -d -r1.41 -r1.42
--- console.cpp	9 Feb 2004 01:27:26 -0000	1.41
+++ console.cpp	13 Mar 2004 13:03:25 -0000	1.42
@@ -25,14 +25,8 @@
 #include "base/engine.h"
 #include "base/version.h"
 
-#ifdef NEW_FONT_CODE
 #include "gui/font.h"
-#define kCharWidth	g_sysfont.maxwidth
-#else
-enum {
-	kCharWidth = 8
-};
-#endif
+#define kCharWidth	g_guifont.getMaxCharWidth()
 
 
 namespace GUI {
@@ -85,7 +79,7 @@
 }
 
 void ConsoleDialog::reflowLayout() {
-	// Calculate the real width/height (rounded to char/line multiples
+	// Calculate the real width/height (rounded to char/line multiples)
 	_w = (uint16)(_widthPercent * g_system->get_overlay_width());
 //	_w = (_widthPercent * g_system->get_overlay_width() - kScrollBarWidth - 2) / kCharWidth;
 //	_w = _w * kCharWidth + kScrollBarWidth + 2;

Index: dialog.h
===================================================================
RCS file: /cvsroot/scummvm/scummvm/gui/dialog.h,v
retrieving revision 1.27
retrieving revision 1.28
diff -u -d -r1.27 -r1.28
--- dialog.h	6 Jan 2004 12:45:29 -0000	1.27
+++ dialog.h	13 Mar 2004 13:03:25 -0000	1.28
@@ -74,6 +74,7 @@
 	virtual void handleKeyUp(uint16 ascii, int keycode, int modifiers);
 	virtual void handleMouseMoved(int x, int y, int button);
 	virtual void handleCommand(CommandSender *sender, uint32 cmd, uint32 data);
+	virtual void handleScreenChanged() {}
 	
 	Widget *findWidget(int x, int y); // Find the widget at pos x,y if any
 

Index: font.cpp
===================================================================
RCS file: /cvsroot/scummvm/scummvm/gui/font.cpp,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -d -r1.1 -r1.2
--- font.cpp	19 Nov 2003 23:46:39 -0000	1.1
+++ font.cpp	13 Mar 2004 13:03:25 -0000	1.2
@@ -1,2581 +1,153 @@
-/* Generated by convbdf on Thu Nov 20 00:15:51 2003. */
-#include "font.h"
+/* ScummVM - Scumm Interpreter
+ * Copyright (C) 2002-2004 The ScummVM project
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
[...2682 lines suppressed...]
+		x += w;
+	}
+}
 
-/* Exported structure definition. */
-const Font g_sysfont = {
-	"04b-16b-10",
-	9,
-	10,
-	8,
-	33,
-	94,
-	_font_bits,
-	0,  /* no encode table*/
-	_sysfont_width,
-	33,
-	sizeof(_font_bits)/sizeof(bitmap_t),
-};
 
 } // End of namespace GUI

Index: font.h
===================================================================
RCS file: /cvsroot/scummvm/scummvm/gui/font.h,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -d -r1.2 -r1.3
--- font.h	6 Jan 2004 12:45:29 -0000	1.2
+++ font.h	13 Mar 2004 13:03:25 -0000	1.3
@@ -21,13 +21,62 @@
 #ifndef FONT_H
 #define FONT_H
 
+#include "common/str.h"
+
 namespace GUI {
 
+// Text alignment modes for drawString()
+enum TextAlignment {
+	kTextAlignLeft,
+	kTextAlignCenter,
+	kTextAlignRight
+};
+
+/**
+ * An arbitrary graphics surface, which can be the target (or source) of blit
+ * operations, font rendering, etc.
+ * @todo This shouldn't be in font.h, but rather in e.g. graphics/surface.h
+ */
+struct Surface {
+	void *pixels;
+	uint16 w;
+	uint16 h;
+	uint16 pitch;
+	uint8 bytesPerPixel;
+};
+
+class Font {
+public:
+	virtual int getFontHeight() const = 0;
+	virtual int getMaxCharWidth() const = 0;
+
+	virtual int getCharWidth(byte chr) const = 0;
+	virtual void drawChar(const Surface *dst, byte chr, int x, int y, uint32 color) const = 0;
+
+	void drawString(const Surface *dst, const Common::String &str, int x, int y, int w, uint32 color, TextAlignment align = kTextAlignLeft, int deltax = 0, bool useEllipsis = true) const;
+	int getStringWidth(const Common::String &str) const;
+};
+
+
+class ScummFont : public Font {
+public:
+	virtual int getFontHeight() const { return 8; }
+	virtual int getMaxCharWidth() const { return 8; };
+
+	virtual int getCharWidth(byte chr) const;
+	virtual void drawChar(const Surface *dst, byte chr, int x, int y, uint32 color) const;
+};
+
+extern const ScummFont g_scummfont;
+
+
+
 typedef unsigned short bitmap_t; /* bitmap image unit size*/
 
 /* builtin C-based proportional/fixed font structure */
 /* based on The Microwindows Project http://microwindows.org */
-struct Font {
+class NewFont : public Font {
+protected:
 	const char *	name;		/* font name*/
 	int		maxwidth;	/* max width in pixels*/
 	int 	height;		/* height in pixels*/
@@ -39,9 +88,18 @@
 	const unsigned char* width;	/* character widths or NULL if fixed*/
 	int		defaultchar;	/* default char (not glyph index)*/
 	long	bits_size;	/* # words of bitmap_t bits*/
+
+public:
+	NewFont();
+	
+	virtual int getFontHeight() const { return height; }
+	virtual int getMaxCharWidth() const { return maxwidth; };
+
+	virtual int getCharWidth(byte chr) const;
+	virtual void drawChar(const Surface *dst, byte chr, int x, int y, uint32 color) const;
 };
 
-extern const Font g_sysfont;
+extern const NewFont g_sysfont;
 
 } // End of namespace GUI
 

Index: module.mk
===================================================================
RCS file: /cvsroot/scummvm/scummvm/gui/module.mk,v
retrieving revision 1.10
retrieving revision 1.11
diff -u -d -r1.10 -r1.11
--- module.mk	30 Jan 2004 21:54:27 -0000	1.10
+++ module.mk	13 Mar 2004 13:03:25 -0000	1.11
@@ -7,7 +7,6 @@
 	gui/console.o \
 	gui/dialog.o \
 	gui/EditTextWidget.o \
-	gui/font.o \
 	gui/launcher.o \
 	gui/ListWidget.o \
 	gui/message.o \
@@ -16,7 +15,15 @@
 	gui/PopUpWidget.o \
 	gui/ScrollBarWidget.o \
 	gui/TabWidget.o \
-	gui/widget.o \
+	gui/widget.o
+
+# TODO: Move the fonts to a separate dir?
+MODULE_OBJS += \
+	gui/font.o \
+	gui/scummfont.o \
+	gui/newfont.o
+
+
 
 MODULE_DIRS += \
 	gui

Index: newgui.cpp
===================================================================
RCS file: /cvsroot/scummvm/scummvm/gui/newgui.cpp,v
retrieving revision 1.79
retrieving revision 1.80
diff -u -d -r1.79 -r1.80
--- newgui.cpp	28 Feb 2004 12:57:53 -0000	1.79
+++ newgui.cpp	13 Mar 2004 13:03:25 -0000	1.80
@@ -20,12 +20,8 @@
 
 #include "stdafx.h"
 #include "common/util.h"
-#include "newgui.h"
-#include "dialog.h"
-
-#ifdef NEW_FONT_CODE
-#include "gui/font.h"
-#endif
+#include "gui/newgui.h"
+#include "gui/dialog.h"
 
 
 namespace GUI {
@@ -49,49 +45,6 @@
 	kKeyRepeatSustainDelay = 100
 };
 
-#ifdef NEW_FONT_CODE
-/*
- * TODO: 
- *  - replace kLineHeight by global variable or query method
- *  - ....
- */
-#else
-#ifdef __PALM_OS__
-static const byte *guifont;
-#else
-// Built-in font
-static const byte guifont[] = {
-0,0,99,1,226,8,4,8,6,8,6,0,0,0,0,0,0,0,0,0,0,0,8,2,1,8,0,0,0,0,0,0,0,0,0,0,0,0,4,3,7,8,7,7,8,4,5,5,8,7,4,7,3,8,7,7,7,7,8,7,7,7,7,7,3,4,7,5,7,7,8,7,7,7,7,7,7,7,7,5,7,7,
-7,8,7,7,7,7,7,7,7,7,7,8,7,7,7,5,8,5,8,8,7,7,7,6,7,7,7,7,7,5,6,7,5,8,7,7,7,7,7,7,7,7,7,8,7,7,7,5,3,5,7,8,7,7,7,7,7,7,0,6,7,7,7,5,5,5,7,0,6,8,8,7,7,7,7,7,0,7,7,0,0,
-0,0,0,7,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,7,0,0,0,0,0,0,0,0,1,3,6,12,
-24,62,3,0,128,192,96,48,24,124,192,0,0,3,62,24,12,6,3,1,0,192,124,24,48,96,192,128,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
-0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,237,74,72,0,0,0,0,0,128,128,128,0,0,0,0,0,0,0,0,0,0,0,0,0,60,66,153,161,161,153,66,60,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
-0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
-0,0,0,0,0,0,0,0,0,96,96,96,96,0,0,96,0,102,102,102,0,0,0,0,0,102,102,255,102,255,102,102,0,24,62,96,60,6,124,24,0,98,102,12,24,48,102,70,0,60,102,60,56,103,102,63,0,96,48,16,0,0,0,0,0,24,48,96,96,96,48,24,0,96,48,24,24,24,48,96,0,
-0,102,60,255,60,102,0,0,0,24,24,126,24,24,0,0,0,0,0,0,0,48,48,96,0,0,0,126,0,0,0,0,0,0,0,0,0,96,96,0,0,3,6,12,24,48,96,0,60,102,102,102,102,102,60,0,24,24,56,24,24,24,126,0,60,102,6,12,48,96,126,0,60,102,6,28,6,102,60,0,6,
-14,30,102,127,6,6,0,126,96,124,6,6,102,60,0,60,102,96,124,102,102,60,0,126,102,12,24,24,24,24,0,60,102,102,60,102,102,60,0,60,102,102,62,6,102,60,0,0,0,96,0,0,96,0,0,0,0,48,0,0,48,48,96,14,24,48,96,48,24,14,0,0,0,120,0,120,0,0,0,112,24,
-12,6,12,24,112,0,60,102,6,12,24,0,24,0,0,0,0,255,255,0,0,0,24,60,102,126,102,102,102,0,124,102,102,124,102,102,124,0,60,102,96,96,96,102,60,0,120,108,102,102,102,108,120,0,126,96,96,120,96,96,126,0,126,96,96,120,96,96,96,0,60,102,96,110,102,102,60,0,102,102,102,
-126,102,102,102,0,120,48,48,48,48,48,120,0,30,12,12,12,12,108,56,0,102,108,120,112,120,108,102,0,96,96,96,96,96,96,126,0,99,119,127,107,99,99,99,0,102,118,126,126,110,102,102,0,60,102,102,102,102,102,60,0,124,102,102,124,96,96,96,0,60,102,102,102,102,60,14,0,124,102,102,124,
-120,108,102,0,60,102,96,60,6,102,60,0,126,24,24,24,24,24,24,0,102,102,102,102,102,102,60,0,102,102,102,102,102,60,24,0,99,99,99,107,127,119,99,0,102,102,60,24,60,102,102,0,102,102,102,60,24,24,24,0,126,6,12,24,48,96,126,0,120,96,96,96,96,96,120,0,3,6,12,24,48,
-96,192,0,120,24,24,24,24,24,120,0,0,0,0,0,0,219,219,0,0,0,0,0,0,0,0,255,102,102,102,0,0,0,0,0,0,0,60,6,62,102,62,0,0,96,96,124,102,102,124,0,0,0,60,96,96,96,60,0,0,6,6,62,102,102,62,0,0,0,60,102,126,96,60,0,0,14,24,62,24,24,
-24,0,0,0,62,102,102,62,6,124,0,96,96,124,102,102,102,0,0,48,0,112,48,48,120,0,0,12,0,12,12,12,12,120,0,96,96,108,120,108,102,0,0,112,48,48,48,48,120,0,0,0,102,127,127,107,99,0,0,0,124,102,102,102,102,0,0,0,60,102,102,102,60,0,0,0,124,102,102,124,96,
-96,0,0,62,102,102,62,6,6,0,0,124,102,96,96,96,0,0,0,62,96,60,6,124,0,0,24,126,24,24,24,14,0,0,0,102,102,102,102,62,0,0,0,102,102,102,60,24,0,0,0,99,107,127,62,54,0,0,0,102,60,24,60,102,0,0,0,102,102,102,62,12,120,0,0,126,12,24,48,126,0,
-24,48,48,96,48,48,24,0,96,96,96,0,96,96,96,0,96,48,48,24,48,48,96,0,0,0,97,153,134,0,0,0,8,12,14,255,255,14,12,8,60,102,96,96,102,60,24,56,102,0,102,102,102,102,62,0,12,24,60,102,126,96,60,0,24,36,60,6,62,102,62,0,102,0,60,6,62,102,62,0,48,
-24,60,6,62,102,62,0,0,0,0,0,0,0,0,0,0,60,96,96,96,60,24,56,24,36,60,102,126,96,60,0,102,0,60,102,126,96,60,0,48,24,60,102,126,96,60,0,0,216,0,112,48,48,120,0,48,72,0,112,48,48,120,0,96,48,0,112,48,48,120,0,102,24,60,102,126,102,102,0,0,0,
-0,0,0,0,0,0,24,48,124,96,120,96,124,0,0,0,108,26,126,216,110,0,30,40,40,126,72,136,142,0,24,36,60,102,102,102,60,0,102,0,60,102,102,102,60,0,48,24,60,102,102,102,60,0,24,36,0,102,102,102,62,0,48,24,102,102,102,102,62,0,0,0,0,0,0,0,0,0,102,60,102,
-102,102,102,60,0,102,0,102,102,102,102,60,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,12,24,60,6,62,102,62,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
-0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
-0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
-0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
-0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
-0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
-0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
-0,0,0,0,0,0,28,54,54,124,102,102,124,64,0,0,0
-};
-#endif
-
-#endif // NEW_FONT_CODE
-
 
 // Constructor
 NewGui::NewGui() : _screen(0), _needRedraw(false),
@@ -204,6 +157,7 @@
 				return;
 			case OSystem::EVENT_SCREEN_CHANGED:
 				updateColors();
+				activeDialog->handleScreenChanged();
 				break;
 			}
 		}
@@ -402,57 +356,16 @@
 }
 
 void NewGui::drawChar(byte chr, int xx, int yy, OverlayColor color) {
-	OverlayColor *ptr = getBasePtr(xx, yy);
-	uint x, y;
-
-#ifdef NEW_FONT_CODE
-	assert(g_sysfont.bits != 0 && g_sysfont.maxwidth <= 16);
-
-	// If this character is not included in the font, use the default char.
-	if (chr < g_sysfont.firstchar || chr >= g_sysfont.firstchar + g_sysfont.size) {
-		if (chr == ' ')
-			return;
-		chr = g_sysfont.defaultchar;
-	}
-
-	const uint w = getCharWidth(chr);
-	const uint h = g_sysfont.height;
-	chr -= g_sysfont.firstchar;
-	const bitmap_t *tmp = g_sysfont.bits + (g_sysfont.offset ? g_sysfont.offset[chr] : (chr * h));
-//printf("Char '%c', width %d\n", chr, w);
-
-	for (y = 0; y < h; y++) {
-		const bitmap_t buffer = *tmp++;
-		bitmap_t mask = 0x8000;
-		for (x = 0; x < w; x++) {
-			if ((buffer & mask) != 0)
-				ptr[x] = color;
-			mask >>= 1;
-		}
-		ptr += _screenPitch;
-	}
-#else
-	const uint w = 8;
-	const uint h = 8;
-	const byte *tmp = guifont + 6 + guifont[4] + chr * 8;
-	uint buffer = 0;
-	uint mask = 0;
-
-	for (y = 0; y < h; y++) {
-		for (x = 0; x < w; x++) {
-			unsigned char c;
-			mask >>= 1;
-			if (mask == 0) {
-				buffer = *tmp++;
-				mask = 0x80;
-			}
-			c = ((buffer & mask) != 0);
-			if (c)
-				ptr[x] = color;
-		}
-		ptr += _screenPitch;
-	}
-#endif
+	const int sys_height = _system->get_overlay_height();
+	const int sys_width = _system->get_overlay_width();
+	Surface dst = {
+			_screen,
+			sys_width,
+			sys_height,
+			sizeof(OverlayColor) * _screenPitch,
+			sizeof(OverlayColor)
+		};
+	g_guifont.drawChar(&dst, chr, xx, yy, color);
 }
 
 int NewGui::getStringWidth(const String &str) {
@@ -464,89 +377,20 @@
 }
 
 int NewGui::getCharWidth(byte c) {
-#ifdef NEW_FONT_CODE
-	// If no width table is specified, return the maximum width
-	if (!g_sysfont.width)
-		return g_sysfont.maxwidth;
-	// If this character is not included in the font, use the default char.
-	if (c < g_sysfont.firstchar || g_sysfont.firstchar + g_sysfont.size < c) {
-		if (c == ' ')
-			return g_sysfont.maxwidth / 2;
-		c = g_sysfont.defaultchar;
-	}
-	return g_sysfont.width[c - g_sysfont.firstchar];
-#else
-	return guifont[c+6];
-#endif
+	return g_guifont.getCharWidth(c);
 }
 
-void NewGui::drawString(const String &s, int x, int y, int w, OverlayColor color, int align, int deltax, bool useEllipsis) {
-	const int leftX = x, rightX = x + w;
-	uint 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 (i = 0; i < str.size(); ++i) {
-		w = getCharWidth(str[i]);
-		if (x+w > rightX)
-			break;
-		if (x >= leftX)
-			drawChar(str[i], x, y, color);
-		x += w;
-	}
+void NewGui::drawString(const String &s, int x, int y, int w, OverlayColor color, TextAlignment align, int deltax, bool useEllipsis) {
+	const int sys_height = _system->get_overlay_height();
+	const int sys_width = _system->get_overlay_width();
+	Surface dst = {
+			_screen,
+			sys_width,
+			sys_height,
+			sizeof(OverlayColor) * _screenPitch,
+			sizeof(OverlayColor)
+		};
+	g_guifont.drawString(&dst, s, x, y, w, color, align, deltax, useEllipsis);
 }
 
 //
@@ -620,20 +464,3 @@
 }
 
 } // End of namespace GUI
-
-#ifdef __PALM_OS__
-#include "scumm_globals.h"
-
-_GINIT(NewGui)
-#ifndef NEW_FONT_CODE
-_GSETPTR(GUI::guifont, GBVARS_GUIFONT_INDEX, byte, GBVARS_SCUMM)
-#endif
-_GEND
-
-_GRELEASE(NewGui)
-#ifndef NEW_FONT_CODE
-_GRELEASEPTR(GBVARS_GUIFONT_INDEX, GBVARS_SCUMM)
-#endif
-_GEND
-
-#endif

Index: newgui.h
===================================================================
RCS file: /cvsroot/scummvm/scummvm/gui/newgui.h,v
retrieving revision 1.38
retrieving revision 1.39
diff -u -d -r1.38 -r1.39
--- newgui.h	28 Feb 2004 12:58:09 -0000	1.38
+++ newgui.h	13 Mar 2004 13:03:25 -0000	1.39
@@ -25,22 +25,12 @@
 #include "common/singleton.h"
 #include "common/str.h"
 #include "common/system.h"	// For events
+#include "gui/font.h"
 
 // Uncomment the following to enable the new font code:
 //#define NEW_FONT_CODE
 
 
-// Height of a single text line
-#ifdef NEW_FONT_CODE
-#include "gui/font.h"
-#define kLineHeight	(g_sysfont.height + 2)
-#else
-enum {
-	kLineHeight			= 10
-};
-#endif
-
-
 namespace GUI {
 
 class Dialog;
@@ -51,12 +41,14 @@
 #define g_gui	(GUI::NewGui::instance())
 
 
-// Text alignment modes for drawString()
-enum {
-	kTextAlignLeft,
-	kTextAlignCenter,
-	kTextAlignRight
-};
+// Height of a single text line
+#ifdef NEW_FONT_CODE
+#define		g_guifont		g_sysfont
+#else
+#define		g_guifont		g_scummfont
+#endif
+#define kLineHeight	(g_guifont.getFontHeight() + 2)
+
 
 // Extremly simple stack class, doesn't even do any error checking (for now)
 class DialogStack {
@@ -150,7 +142,7 @@
 	void drawChar(byte c, int x, int y, OverlayColor color);
 	int getStringWidth(const String &str);
 	int getCharWidth(byte c);
-	void drawString(const String &str, int x, int y, int w, OverlayColor color, int align = kTextAlignLeft, int deltax = 0, bool useEllipsis = true);
+	void drawString(const String &str, int x, int y, int w, OverlayColor color, TextAlignment 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: widget.cpp
===================================================================
RCS file: /cvsroot/scummvm/scummvm/gui/widget.cpp,v
retrieving revision 1.37
retrieving revision 1.38
diff -u -d -r1.37 -r1.38
--- widget.cpp	28 Feb 2004 12:58:09 -0000	1.37
+++ widget.cpp	13 Mar 2004 13:03:25 -0000	1.38
@@ -107,7 +107,7 @@
 
 #pragma mark -
 
-StaticTextWidget::StaticTextWidget(GuiObject *boss, int x, int y, int w, int h, const String &text, int align)
+StaticTextWidget::StaticTextWidget(GuiObject *boss, int x, int y, int w, int h, const String &text, TextAlignment align)
 	: Widget(boss, x, y, w, h), _align(align) {
 	_flags = WIDGET_ENABLED;
 	_type = kStaticTextWidget;

Index: widget.h
===================================================================
RCS file: /cvsroot/scummvm/scummvm/gui/widget.h,v
retrieving revision 1.34
retrieving revision 1.35
diff -u -d -r1.34 -r1.35
--- widget.h	6 Jan 2004 12:45:29 -0000	1.34
+++ widget.h	13 Mar 2004 13:03:25 -0000	1.35
@@ -23,6 +23,7 @@
 
 #include "common/scummsys.h"
 #include "common/str.h"
+#include "gui/font.h"
 #include "gui/object.h"
 
 namespace GUI {
@@ -127,15 +128,15 @@
 protected:
 	typedef Common::String String;
 
-	String _label;
-	int		_align;
+	String			_label;
+	TextAlignment	_align;
 public:
-	StaticTextWidget(GuiObject *boss, int x, int y, int w, int h, const String &text, int align);
+	StaticTextWidget(GuiObject *boss, int x, int y, int w, int h, const String &text, TextAlignment align);
 	void setValue(int value);
 	void setLabel(const String &label)	{ _label = label; }
 	const String &getLabel() const		{ return _label; }
-	void setAlign(int align)			{ _align = align; }
-	int getAlign() const				{ return _align; }
+	void setAlign(TextAlignment align)	{ _align = align; }
+	TextAlignment getAlign() const		{ return _align; }
 
 protected:
 	void drawWidget(bool hilite);





More information about the Scummvm-git-logs mailing list