new font code (currently disabled by default), which allows using 'arbitrary' BDF fonts (via convbdf)

svn-id: r11350
This commit is contained in:
Max Horn 2003-11-19 23:46:39 +00:00
parent 083c328077
commit b8c0fbf06e
11 changed files with 2732 additions and 25 deletions

View file

@ -150,7 +150,7 @@ void EditTextWidget::drawWidget(bool hilite) {
// 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 {

View file

@ -277,7 +277,7 @@ void ListWidget::drawWidget(bool hilite) {
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);
}
}

View file

@ -27,7 +27,7 @@
namespace GUI {
enum {
kTabHeight = 15,
kTabHeight = 16,
kTabLeftOffset = 4,
kTabSpacing = 2,
@ -130,7 +130,7 @@ void TabWidget::drawWidget(bool hilite) {
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;
}

View file

@ -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 {

View file

@ -31,7 +31,6 @@ namespace GUI {
enum {
kBufferSize = 32768,
kLineBufferSize = 256,
kCharWidth = 8,
kHistorySize = 20
};

2581
gui/font.cpp Normal file

File diff suppressed because it is too large Load diff

48
gui/font.h Normal file
View file

@ -0,0 +1,48 @@
/* 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$
*/
#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

View file

@ -7,6 +7,7 @@ MODULE_OBJS := \
gui/console.o \
gui/dialog.o \
gui/EditTextWidget.o \
gui/font.o \
gui/launcher.o \
gui/ListWidget.o \
gui/message.o \

View file

@ -27,6 +27,11 @@
# include "palm.h"
#endif
#ifdef NEW_FONT_CODE
#include "gui/font.h"
#endif
namespace GUI {
/*
@ -49,6 +54,13 @@ enum {
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 @@ static byte guifont[] = {
};
#endif
#endif // NEW_FONT_CODE
// Constructor
NewGui::NewGui() : _screen(0), _needRedraw(false),
_stateIsSaved(false), _cursorAnimateCounter(0), _cursorAnimateTimer(0) {
@ -113,9 +128,8 @@ void NewGui::runLoop() {
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 @@ void NewGui::addDirtyRect(int x, int y, int w, int h) {
_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;
tmp = guifont + 224 + (chr + 1) * 8;
void NewGui::drawChar(byte chr, int xx, int yy, NewGuiColor color) {
NewGuiColor *ptr = getBasePtr(xx, yy);
uint x, y;
for (y = 0; y < 8; y++) {
for (x = 0; x < 8; x++) {
#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 + 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 @@ void NewGui::drawChar(const byte chr, int xx, int yy, NewGuiColor color) {
}
ptr += _screenPitch;
}
#endif
}
int NewGui::getStringWidth(const String &str) {
@ -434,7 +479,20 @@ int NewGui::getStringWidth(const String &str) {
}
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) {

View file

@ -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 @@ class Dialog;
#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 @@ public:
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;

View file

@ -141,7 +141,7 @@ void ButtonWidget::handleMouseUp(int x, int y, int button, int clickCount) {
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);
}