[Scummvm-cvs-logs] CVS: scummvm/gui font.cpp,NONE,1.1 font.h,NONE,1.1 EditTextWidget.cpp,1.22,1.23 ListWidget.cpp,1.31,1.32 TabWidget.cpp,1.8,1.9 console.cpp,1.37,1.38 console.h,1.21,1.22 module.mk,1.8,1.9 newgui.cpp,1.70,1.71 newgui.h,1.34,1.35 widget.cpp,1.31,1.32

Max Horn fingolfin at users.sourceforge.net
Wed Nov 19 16:00:32 CET 2003


Update of /cvsroot/scummvm/scummvm/gui
In directory sc8-pr-cvs1:/tmp/cvs-serv15031

Modified Files:
	EditTextWidget.cpp ListWidget.cpp TabWidget.cpp console.cpp 
	console.h module.mk newgui.cpp newgui.h widget.cpp 
Added Files:
	font.cpp font.h 
Log Message:
new font code (currently disabled by default), which allows using 'arbitrary' BDF fonts (via convbdf)

--- NEW FILE: font.cpp ---
/* Generated by convbdf on Thu Nov 20 00:15:51 2003. */
#include "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 {

[...2542 lines suppressed...]
	5,	/* (0x7d) */
	5,	/* (0x7e) */
};

/* 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

--- NEW FILE: font.h ---
/* ScummVM - Scumm Interpreter
 * Copyright (C) 2002-2003 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/font.h,v 1.1 2003/11/19 23:46:39 fingolfin Exp $
 */

#ifndef FONT_H
#define FONT_H

namespace GUI {

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 {
	const char *	name;		/* font name*/
	int		maxwidth;	/* max width in pixels*/
	int 	height;		/* height in pixels*/
	int		ascent;		/* ascent (baseline) height*/
	int		firstchar;	/* first character in bitmap*/
	int		size;		/* font size in glyphs*/
	const bitmap_t*	bits;		/* 16-bit right-padded bitmap data*/
	const unsigned long* offset;	/* offsets into bitmap data*/
	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*/
};

extern const Font g_sysfont;

} // End of namespace GUI

#endif

Index: EditTextWidget.cpp
===================================================================
RCS file: /cvsroot/scummvm/scummvm/gui/EditTextWidget.cpp,v
retrieving revision 1.22
retrieving revision 1.23
diff -u -d -r1.22 -r1.23
--- EditTextWidget.cpp	18 Nov 2003 23:44:28 -0000	1.22
+++ EditTextWidget.cpp	19 Nov 2003 23:46:39 -0000	1.23
@@ -150,7 +150,7 @@
 
 	// Draw the text
 	adjustOffset();
-	g_gui.drawString(_label, _x + 2, _y + 3, _w - 6, g_gui._textcolor, kTextAlignLeft, -_labelOffset, false);
+	g_gui.drawString(_label, _x + 2, _y + 2, _w - 6, g_gui._textcolor, kTextAlignLeft, -_labelOffset, false);
 }
 
 int EditTextWidget::getCaretPos() const {

Index: ListWidget.cpp
===================================================================
RCS file: /cvsroot/scummvm/scummvm/gui/ListWidget.cpp,v
retrieving revision 1.31
retrieving revision 1.32
diff -u -d -r1.31 -r1.32
--- ListWidget.cpp	18 Nov 2003 23:44:28 -0000	1.31
+++ ListWidget.cpp	19 Nov 2003 23:46:39 -0000	1.32
@@ -277,7 +277,7 @@
 			else
 				gui->frameRect(_x + 1, _y + 1 + kLineHeight * i, _w - 1, kLineHeight, gui->_textcolorhi);
 		}
-		gui->drawString(buffer, _x + 2, _y + 3 + kLineHeight * i, _w - 4,
+		gui->drawString(buffer, _x + 2, _y + 2 + kLineHeight * i, _w - 4,
 							(_selectedItem == pos && _hasFocus) ? gui->_bgcolor : gui->_textcolor);
 	}
 }

Index: TabWidget.cpp
===================================================================
RCS file: /cvsroot/scummvm/scummvm/gui/TabWidget.cpp,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -d -r1.8 -r1.9
--- TabWidget.cpp	10 Nov 2003 23:40:48 -0000	1.8
+++ TabWidget.cpp	19 Nov 2003 23:46:39 -0000	1.9
@@ -27,7 +27,7 @@
 namespace GUI {
 
 enum {
-	kTabHeight = 15,
+	kTabHeight = 16,
 
 	kTabLeftOffset = 4,
 	kTabSpacing = 2,
@@ -130,7 +130,7 @@
 		NewGuiColor color = (i == _activeTab) ? gui->_color : gui->_shadowcolor;
 		int yOffset = (i == _activeTab) ? 0 : 2; 
 		gui->box(x, _y + yOffset, _tabWidth, kTabHeight - yOffset, color, color);
-		gui->drawString(_tabs[i].title, x + kTabPadding, _y + yOffset / 2 + 4, _tabWidth - 2 * kTabPadding, gui->_textcolor, kTextAlignCenter);
+		gui->drawString(_tabs[i].title, x + kTabPadding, _y + yOffset / 2 + (kTabHeight - kLineHeight - 1), _tabWidth - 2 * kTabPadding, gui->_textcolor, kTextAlignCenter);
 		x += _tabWidth + kTabSpacing;
 	}
 

Index: console.cpp
===================================================================
RCS file: /cvsroot/scummvm/scummvm/gui/console.cpp,v
retrieving revision 1.37
retrieving revision 1.38
diff -u -d -r1.37 -r1.38
--- console.cpp	10 Nov 2003 23:40:48 -0000	1.37
+++ console.cpp	19 Nov 2003 23:46:39 -0000	1.38
@@ -24,6 +24,15 @@
 
 #include "base/engine.h"
 
+#ifdef NEW_FONT_CODE
+#include "gui/font.h"
+#define kCharWidth	g_sysfont.maxwidth
+#else
+enum {
+	kCharWidth = 8
+};
+#endif
+
 
 namespace GUI {
 

Index: console.h
===================================================================
RCS file: /cvsroot/scummvm/scummvm/gui/console.h,v
retrieving revision 1.21
retrieving revision 1.22
diff -u -d -r1.21 -r1.22
--- console.h	10 Nov 2003 23:40:48 -0000	1.21
+++ console.h	19 Nov 2003 23:46:39 -0000	1.22
@@ -31,7 +31,6 @@
 enum {
 	kBufferSize	= 32768,
 	kLineBufferSize = 256,
-	kCharWidth = 8,
 
 	kHistorySize = 20
 };

Index: module.mk
===================================================================
RCS file: /cvsroot/scummvm/scummvm/gui/module.mk,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -d -r1.8 -r1.9
--- module.mk	2 Nov 2003 19:11:03 -0000	1.8
+++ module.mk	19 Nov 2003 23:46:39 -0000	1.9
@@ -7,6 +7,7 @@
 	gui/console.o \
 	gui/dialog.o \
 	gui/EditTextWidget.o \
+	gui/font.o \
 	gui/launcher.o \
 	gui/ListWidget.o \
 	gui/message.o \

Index: newgui.cpp
===================================================================
RCS file: /cvsroot/scummvm/scummvm/gui/newgui.cpp,v
retrieving revision 1.70
retrieving revision 1.71
diff -u -d -r1.70 -r1.71
--- newgui.cpp	12 Nov 2003 12:36:36 -0000	1.70
+++ newgui.cpp	19 Nov 2003 23:46:39 -0000	1.71
@@ -27,6 +27,11 @@
 #	include "palm.h"
 #endif
 
+#ifdef NEW_FONT_CODE
+#include "gui/font.h"
+#endif
+
+
 namespace GUI {
 
 /*
@@ -49,6 +54,13 @@
 	kKeyRepeatSustainDelay = 100
 };
 
+#ifdef NEW_FONT_CODE
+/*
+ * TODO: 
+ *  - replace kLineHeight by global variable or query method
+ *  - ....
+ */
+#else
 #ifdef __PALM_OS__
 static byte *guifont;
 #else
@@ -83,6 +95,9 @@
 };
 #endif
 
+#endif // NEW_FONT_CODE
+
+
 // Constructor
 NewGui::NewGui() : _screen(0), _needRedraw(false),
 	_stateIsSaved(false), _cursorAnimateCounter(0), _cursorAnimateTimer(0) {
@@ -113,9 +128,8 @@
 		return;
 	
 	// Setup some default GUI colors. Normally this will be done whenever an
-	// EVENT_SCREEN_CHANGED is received. However, not all backends support
-	// that even at this time, so we also do it "manually" whenever a run loop
-	// is entered.
+	// EVENT_SCREEN_CHANGED is received. However, not yet all backends support
+	// that event, so we also do it "manually" whenever a run loop is entered.
 	updateColors();
 
 	if (!_stateIsSaved) {
@@ -402,18 +416,48 @@
 	_system->copy_rect_overlay(buf, _screenPitch, x, y, w, h);
 }
 
-void NewGui::drawChar(const byte chr, int xx, int yy, NewGuiColor color) {
-	unsigned int buffer = 0, mask = 0, x, y;
-	byte *tmp;
+void NewGui::drawChar(byte chr, int xx, int yy, NewGuiColor color) {
+	NewGuiColor *ptr = getBasePtr(xx, yy);
+	uint x, y;
 
-	tmp = guifont + 224 + (chr + 1) * 8;
+#ifdef NEW_FONT_CODE
+	assert(g_sysfont.bits != 0 && g_sysfont.maxwidth <= 16);
 
-	NewGuiColor *ptr = getBasePtr(xx, yy);
+	// 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;
+	}
 
-	for (y = 0; y < 8; y++) {
-		for (x = 0; x < 8; x++) {
+	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 + 224 + (chr + 1) * 8;
+	uint buffer = 0;
+	uint mask = 0;
+
+	for (y = 0; y < h; y++) {
+		for (x = 0; x < w; x++) {
 			unsigned char c;
-			if ((mask >>= 1) == 0) {
+			mask >>= 1;
+			if (mask == 0) {
 				buffer = *tmp++;
 				mask = 0x80;
 			}
@@ -423,6 +467,7 @@
 		}
 		ptr += _screenPitch;
 	}
+#endif
 }
 
 int NewGui::getStringWidth(const String &str) {
@@ -434,7 +479,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
 }
 
 void NewGui::drawString(const String &s, int x, int y, int w, NewGuiColor color, int align, int deltax, bool useEllipsis) {

Index: newgui.h
===================================================================
RCS file: /cvsroot/scummvm/scummvm/gui/newgui.h,v
retrieving revision 1.34
retrieving revision 1.35
diff -u -d -r1.34 -r1.35
--- newgui.h	10 Nov 2003 23:40:48 -0000	1.34
+++ newgui.h	19 Nov 2003 23:46:39 -0000	1.35
@@ -26,6 +26,21 @@
 #include "common/str.h"
 #include "common/system.h"	// For events
 
+// 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;
@@ -36,12 +51,6 @@
 #define g_gui	(NewGui::instance())
 
 
-// Height of a single text line
-enum {
-	kLineHeight			= 11
-};
-
-
 // Text alignment modes for drawString()
 enum {
 	kTextAlignLeft,
@@ -65,7 +74,9 @@
 	Dialog	*operator [](int i)	{ return _stack[i]; }
 };
 
-// This class hopefully will replace the old Gui class completly one day 
+/**
+ * GUI manager singleton.
+ */ 
 class NewGui : public Common::Singleton<NewGui> {
 	typedef Common::String String;
 	friend class Dialog;

Index: widget.cpp
===================================================================
RCS file: /cvsroot/scummvm/scummvm/gui/widget.cpp,v
retrieving revision 1.31
retrieving revision 1.32
diff -u -d -r1.31 -r1.32
--- widget.cpp	10 Nov 2003 23:40:48 -0000	1.31
+++ widget.cpp	19 Nov 2003 23:46:39 -0000	1.32
@@ -141,7 +141,7 @@
 
 void ButtonWidget::drawWidget(bool hilite) {
 	NewGui *gui = &g_gui;
-	gui->drawString(_label, _x, _y, _w,
+	gui->drawString(_label, _x, _y + (_h - kLineHeight)/2 + 1, _w,
 					!isEnabled() ? gui->_color :
 					hilite ? gui->_textcolorhi : gui->_textcolor, _align);
 }





More information about the Scummvm-git-logs mailing list