aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMax Horn2005-01-06 21:15:52 +0000
committerMax Horn2005-01-06 21:15:52 +0000
commitc6e0d31e76134fbdd3a1626aad9ed3e38f25afb3 (patch)
tree913925590e558d57670e21479d4853e6bb15447c
parentf3b7c27cbdeb7f1801fa5ed34d2aa0b65454b72f (diff)
downloadscummvm-rg350-c6e0d31e76134fbdd3a1626aad9ed3e38f25afb3.tar.gz
scummvm-rg350-c6e0d31e76134fbdd3a1626aad9ed3e38f25afb3.tar.bz2
scummvm-rg350-c6e0d31e76134fbdd3a1626aad9ed3e38f25afb3.zip
Added a font manager (work in progress)
svn-id: r16460
-rw-r--r--backends/sdl/graphics.cpp4
-rw-r--r--graphics/font.cpp8
-rw-r--r--graphics/font.h12
-rw-r--r--graphics/fontman.cpp54
-rw-r--r--graphics/fontman.h72
-rw-r--r--graphics/module.mk3
-rw-r--r--graphics/newfont.cpp2
-rw-r--r--graphics/scummfont.cpp9
-rw-r--r--gui/newgui.cpp18
-rw-r--r--gui/newgui.h4
-rw-r--r--sound/softsynth/mt32.cpp7
11 files changed, 154 insertions, 39 deletions
diff --git a/backends/sdl/graphics.cpp b/backends/sdl/graphics.cpp
index f081acfc75..daa9906594 100644
--- a/backends/sdl/graphics.cpp
+++ b/backends/sdl/graphics.cpp
@@ -24,6 +24,7 @@
#include "common/scaler.h"
#include "common/util.h"
#include "graphics/font.h"
+#include "graphics/fontman.h"
static const OSystem::GraphicsMode s_supportedGraphicsModes[] = {
{"1x", "Normal (no scaling)", GFX_NORMAL},
@@ -1234,8 +1235,7 @@ void OSystem_SDL::displayMessageOnOSD(const char *msg) {
dst.bytesPerPixel = _osdSurface->format->BytesPerPixel;
// The font we are going to use:
-// const Graphics::Font *font = &Graphics::g_sysfont;
- const Graphics::Font *font = &Graphics::g_scummfont;
+ const Graphics::Font *font = FontMan.getFontByUsage(Graphics::FontManager::kOSDFont);
// Clear everything with the "transparent" color, i.e. the colorkey
SDL_FillRect(_osdSurface, 0, kOSDColorKey);
diff --git a/graphics/font.cpp b/graphics/font.cpp
index 387fb8f3bf..aac9813bca 100644
--- a/graphics/font.cpp
+++ b/graphics/font.cpp
@@ -20,7 +20,6 @@
#include "common/stdafx.h"
#include "graphics/font.h"
-#include "gui/newgui.h"
namespace Graphics {
@@ -37,9 +36,8 @@ int NewFont::getCharWidth(byte chr) const {
return desc.width[chr - desc.firstchar];
}
-void NewFont::drawChar(const Surface *dst, byte chr, int tx, int ty, uint32 color, bool scale) const {
+void NewFont::drawChar(const Surface *dst, byte chr, int tx, int ty, uint32 color, int scaleFactor) const {
assert(dst != 0);
- const int scaleFactor = scale ? g_gui.getScaleFactor() : 1;
tx *= scaleFactor; ty *= scaleFactor;
byte *ptr = (byte *)dst->getBasePtr(tx, ty);
@@ -103,7 +101,7 @@ int Font::getStringWidth(const Common::String &str) const {
return space;
}
-void Font::drawString(const Surface *dst, const Common::String &s, int x, int y, int w, uint32 color, TextAlignment align, int deltax, bool useEllipsis, bool scale) const {
+void Font::drawString(const Surface *dst, const Common::String &s, int x, int y, int w, uint32 color, TextAlignment align, int deltax, bool useEllipsis, int scaleFactor) const {
assert(dst != 0);
const int leftX = x, rightX = x + w;
uint i;
@@ -168,7 +166,7 @@ void Font::drawString(const Surface *dst, const Common::String &s, int x, int y,
if (x+w > rightX)
break;
if (x >= leftX)
- drawChar(dst, str[i], x, y, color, scale);
+ drawChar(dst, str[i], x, y, color, scaleFactor);
x += w;
}
}
diff --git a/graphics/font.h b/graphics/font.h
index 73f3fd0420..4bacda5dde 100644
--- a/graphics/font.h
+++ b/graphics/font.h
@@ -52,9 +52,9 @@ public:
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, bool scale = false) const = 0;
+ virtual void drawChar(const Surface *dst, byte chr, int x, int y, uint32 color, int scaleFactor = 1) 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, bool scale = false) const;
+ 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, int scaleFactor = 1) const;
int getStringWidth(const Common::String &str) const;
};
@@ -65,11 +65,9 @@ public:
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, bool scale) const;
+ virtual void drawChar(const Surface *dst, byte chr, int x, int y, uint32 color, int scaleFactor) const;
};
-extern const ScummFont g_scummfont;
-
typedef unsigned short bitmap_t; /* bitmap image unit size*/
@@ -101,11 +99,9 @@ public:
virtual int getMaxCharWidth() const { return desc.maxwidth; };
virtual int getCharWidth(byte chr) const;
- virtual void drawChar(const Surface *dst, byte chr, int x, int y, uint32 color, bool scale) const;
+ virtual void drawChar(const Surface *dst, byte chr, int x, int y, uint32 color, int scaleFactor) const;
};
-extern const NewFont g_sysfont;
-
} // End of namespace Graphics
#endif
diff --git a/graphics/fontman.cpp b/graphics/fontman.cpp
new file mode 100644
index 0000000000..ee06a138c7
--- /dev/null
+++ b/graphics/fontman.cpp
@@ -0,0 +1,54 @@
+/* ScummVM - Scumm Interpreter
+ * Copyright (C) 2005 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$
+ */
+
+#include "graphics/fontman.h"
+//#include "gui/consolefont.h"
+
+namespace GUI {
+ extern const Graphics::NewFont g_consolefont;
+};
+
+namespace Graphics {
+
+const ScummFont g_scummfont;
+extern const NewFont g_sysfont;
+
+
+DECLARE_SINGLETON(FontManager);
+
+FontManager::FontManager() {
+}
+
+//const Font *FontManager::getFontByName(const Common::String &name) const {
+//}
+
+const Font *FontManager::getFontByUsage(FontUsage usage) const {
+ switch (usage) {
+ case kOSDFont:
+ return &g_scummfont;
+ case kConsoleFont:
+ return &GUI::g_consolefont;
+ case kGUIFont:
+ return &g_sysfont;
+ }
+ return 0;
+}
+
+} // End of namespace Graphics
diff --git a/graphics/fontman.h b/graphics/fontman.h
new file mode 100644
index 0000000000..77d953b9e8
--- /dev/null
+++ b/graphics/fontman.h
@@ -0,0 +1,72 @@
+/* ScummVM - Scumm Interpreter
+ * Copyright (C) 2005 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 FONTMAN_H
+#define FONTMAN_H
+
+#include "stdafx.h"
+#include "common/scummsys.h"
+#include "common/singleton.h"
+#include "common/str.h"
+#include "graphics/font.h"
+
+
+namespace Graphics {
+
+class FontManager : public Common::Singleton<FontManager> {
+public:
+ enum FontUsage {
+ kOSDFont,
+ kConsoleFont,
+ kGUIFont
+ };
+
+ /**
+ * Retrieve a font object based on its 'name'.
+ *
+ * @param name the name of the font to be retrieved.
+ * @return a pointer to a font, or 0 if no suitable font was found.
+ */
+ //const Font *getFontByName(const Common::String &name) const;
+
+ /**
+ * Retrieve a font object based on what it is supposed
+ * to be used for
+ *
+ * @param usage a FontUsage enum value indicating what the font will be used for.
+ * @return a pointer to a font, or 0 if no suitable font was found.
+ */
+ const Font *getFontByUsage(FontUsage usage) const;
+
+ //const Font *getFontBySize(int size???) const;
+
+
+private:
+ friend class Common::Singleton<SingletonBaseType>;
+ FontManager();
+};
+
+
+} // End of namespace Graphics
+
+/** Shortcut for accessing the font manager. */
+#define FontMan (Graphics::FontManager::instance())
+
+#endif
diff --git a/graphics/module.mk b/graphics/module.mk
index 0b54431453..fc608f12c5 100644
--- a/graphics/module.mk
+++ b/graphics/module.mk
@@ -2,9 +2,10 @@ MODULE := graphics
MODULE_OBJS := \
graphics/animation.o \
+ graphics/scummfont.o \
graphics/font.o \
+ graphics/fontman.o \
graphics/newfont.o \
- graphics/scummfont.o \
graphics/surface.o
MODULE_DIRS += \
diff --git a/graphics/newfont.cpp b/graphics/newfont.cpp
index 300d818a8c..b90f620945 100644
--- a/graphics/newfont.cpp
+++ b/graphics/newfont.cpp
@@ -2579,6 +2579,6 @@ static const FontDesc desc = {
sizeof(_font_bits)/sizeof(bitmap_t)
};
-const NewFont g_sysfont(desc);
+extern const NewFont g_sysfont(desc);
} // End of namespace Graphics
diff --git a/graphics/scummfont.cpp b/graphics/scummfont.cpp
index 6c66137e9f..7ec03edcb2 100644
--- a/graphics/scummfont.cpp
+++ b/graphics/scummfont.cpp
@@ -63,9 +63,8 @@ int ScummFont::getCharWidth(byte chr) const {
}
//void ScummFont::drawChar(byte chr, int xx, int yy, OverlayColor color) {
-void ScummFont::drawChar(const Surface *dst, byte chr, int tx, int ty, uint32 color, bool scale) const {
+void ScummFont::drawChar(const Surface *dst, byte chr, int tx, int ty, uint32 color, int scaleFactor) const {
assert(dst != 0);
- const int scaleFactor = scale ? g_gui.getScaleFactor() : 1;
tx *= scaleFactor; ty *= scaleFactor;
byte *ptr = (byte *)dst->getBasePtr(tx, ty);
@@ -85,7 +84,7 @@ void ScummFont::drawChar(const Surface *dst, byte chr, int tx, int ty, uint32 co
if (tx + x < 0 || tx + x >= dst->w)
continue;
- unsigned char c;
+
if (mask == 0) {
if(scaleFactor != 1 && !(y % 2))
@@ -95,7 +94,7 @@ void ScummFont::drawChar(const Surface *dst, byte chr, int tx, int ty, uint32 co
mask = 0x80;
}
- c = ((buffer & mask) != 0);
+ const byte c = ((buffer & mask) != 0);
if (c) {
if (dst->bytesPerPixel == 1)
ptr[x] = color;
@@ -107,8 +106,6 @@ void ScummFont::drawChar(const Surface *dst, byte chr, int tx, int ty, uint32 co
}
}
-const ScummFont g_scummfont;
-
} // End of namespace Graphics
#ifdef __PALM_OS__
diff --git a/gui/newgui.cpp b/gui/newgui.cpp
index 34afd17b2a..6f718459c2 100644
--- a/gui/newgui.cpp
+++ b/gui/newgui.cpp
@@ -24,13 +24,8 @@
#include "gui/dialog.h"
-// Uncomment the following to enable the new font code:
-//#define NEW_FONT_CODE
-
-
DECLARE_SINGLETON(GUI::NewGui);
-
namespace GUI {
/*
@@ -55,7 +50,7 @@ enum {
// Constructor
NewGui::NewGui() : _scaleEnable(true), _needRedraw(false),
- _stateIsSaved(false), _cursorAnimateCounter(0), _cursorAnimateTimer(0) {
+ _stateIsSaved(false), _font(0), _cursorAnimateCounter(0), _cursorAnimateTimer(0) {
_system = &OSystem::instance();
@@ -90,6 +85,9 @@ void NewGui::updateScaleFactor() {
};
_scaleFactor = MIN(_system->getWidth() / kDefaultGUIWidth, _system->getHeight() / kDefaultGUIHeight);
+
+ // TODO: Pick a bigger font depending on the 'scale' factor.
+ _font = FontMan.getFontByUsage(Graphics::FontManager::kGUIFont);
}
void NewGui::runLoop() {
@@ -266,11 +264,7 @@ void NewGui::closeTopDialog() {
#pragma mark -
const Graphics::Font &NewGui::getFont() const {
-#ifdef NEW_FONT_CODE
- return Graphics::g_sysfont;
-#else
- return Graphics::g_scummfont;
-#endif
+ return *_font;
}
OverlayColor *NewGui::getBasePtr(int x, int y) {
@@ -355,7 +349,7 @@ void NewGui::addDirtyRect(int x, int y, int w, int h) {
void NewGui::drawChar(byte chr, int xx, int yy, OverlayColor color, const Graphics::Font *font) {
if (font == 0)
font = &getFont();
- font->drawChar(&_screen, chr, xx, yy, color, _scaleEnable);
+ font->drawChar(&_screen, chr, xx, yy, color, _scaleFactor);
}
int NewGui::getStringWidth(const String &str) {
diff --git a/gui/newgui.h b/gui/newgui.h
index 19791e74ed..f8ee91a78e 100644
--- a/gui/newgui.h
+++ b/gui/newgui.h
@@ -26,7 +26,7 @@
#include "common/stack.h"
#include "common/str.h"
#include "common/system.h" // For events
-#include "graphics/font.h"
+#include "graphics/fontman.h"
namespace GUI {
@@ -81,6 +81,8 @@ protected:
DialogStack _dialogStack;
bool _stateIsSaved;
+
+ const Graphics::Font *_font;
// for continuous events (keyDown)
struct {
diff --git a/sound/softsynth/mt32.cpp b/sound/softsynth/mt32.cpp
index 52668c9bc3..358cfacc84 100644
--- a/sound/softsynth/mt32.cpp
+++ b/sound/softsynth/mt32.cpp
@@ -32,7 +32,7 @@
#include "common/file.h"
#include "common/config-manager.h"
-#include "graphics/font.h"
+#include "graphics/fontman.h"
#include "graphics/surface.h"
class MidiChannel_MT32 : public MidiChannel_MPU401 {
@@ -124,11 +124,12 @@ static int eatSystemEvents() {
}
static void drawProgress(float progress) {
+ const Graphics::Font &font(*FontMan.getFontByUsage(Graphics::FontManager::kOSDFont));
Graphics::Surface surf;
uint32 borderColor = 0x2;
uint32 fillColor = 0x4;
surf.w = g_system->getWidth() / 7 * 5;
- surf.h = Graphics::g_scummfont.getFontHeight();
+ surf.h = font.getFontHeight();
int x = g_system->getWidth() / 7;
int y = g_system->getHeight() / 2 - surf.h / 2;
surf.pitch = surf.w;
@@ -145,7 +146,7 @@ static void drawProgress(float progress) {
}
static void drawMessage(int offset, const Common::String &text) {
- const Graphics::Font &font(Graphics::g_scummfont);
+ const Graphics::Font &font(*FontMan.getFontByUsage(Graphics::FontManager::kOSDFont));
Graphics::Surface surf;
uint32 color = 0x2;
surf.w = g_system->getWidth();