diff options
author | Max Horn | 2005-01-06 21:15:52 +0000 |
---|---|---|
committer | Max Horn | 2005-01-06 21:15:52 +0000 |
commit | c6e0d31e76134fbdd3a1626aad9ed3e38f25afb3 (patch) | |
tree | 913925590e558d57670e21479d4853e6bb15447c /graphics | |
parent | f3b7c27cbdeb7f1801fa5ed34d2aa0b65454b72f (diff) | |
download | scummvm-rg350-c6e0d31e76134fbdd3a1626aad9ed3e38f25afb3.tar.gz scummvm-rg350-c6e0d31e76134fbdd3a1626aad9ed3e38f25afb3.tar.bz2 scummvm-rg350-c6e0d31e76134fbdd3a1626aad9ed3e38f25afb3.zip |
Added a font manager (work in progress)
svn-id: r16460
Diffstat (limited to 'graphics')
-rw-r--r-- | graphics/font.cpp | 8 | ||||
-rw-r--r-- | graphics/font.h | 12 | ||||
-rw-r--r-- | graphics/fontman.cpp | 54 | ||||
-rw-r--r-- | graphics/fontman.h | 72 | ||||
-rw-r--r-- | graphics/module.mk | 3 | ||||
-rw-r--r-- | graphics/newfont.cpp | 2 | ||||
-rw-r--r-- | graphics/scummfont.cpp | 9 |
7 files changed, 139 insertions, 21 deletions
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__ |