diff options
author | Nicola Mettifogo | 2008-02-06 14:12:59 +0000 |
---|---|---|
committer | Nicola Mettifogo | 2008-02-06 14:12:59 +0000 |
commit | 014511f380c200874c3fe39515f8b377d1a02861 (patch) | |
tree | e7346511c680f4c03e0a92497741de647fda602a | |
parent | 246fbfd1e42e2946e10e1e1fe716edac72cbbf4a (diff) | |
download | scummvm-rg350-014511f380c200874c3fe39515f8b377d1a02861.tar.gz scummvm-rg350-014511f380c200874c3fe39515f8b377d1a02861.tar.bz2 scummvm-rg350-014511f380c200874c3fe39515f8b377d1a02861.zip |
Made font handling stateless.
svn-id: r30809
-rw-r--r-- | engines/parallaction/graphics.cpp | 59 | ||||
-rw-r--r-- | engines/parallaction/graphics.h | 8 |
2 files changed, 25 insertions, 42 deletions
diff --git a/engines/parallaction/graphics.cpp b/engines/parallaction/graphics.cpp index 5654eddffb..5984c0a2e9 100644 --- a/engines/parallaction/graphics.cpp +++ b/engines/parallaction/graphics.cpp @@ -611,8 +611,7 @@ Label *Gfx::renderFloatingLabel(Font *font, char *text) { setupLabelSurface(*cnv, w, h); - setFont(font); - drawText(cnv, 0, 0, text, 0); + drawText(font, cnv, 0, 0, text, 0); } return label; @@ -626,23 +625,21 @@ uint Gfx::createLabel(Font *font, const char *text, byte color) { uint w, h; - setFont(font); - if (_vm->getPlatform() == Common::kPlatformAmiga) { w = font->getStringWidth(text) + 2; h = font->height() + 2; setupLabelSurface(*cnv, w, h); - drawText(cnv, 0, 2, text, 0); - drawText(cnv, 2, 0, text, color); + drawText(font, cnv, 0, 2, text, 0); + drawText(font, cnv, 2, 0, text, color); } else { w = font->getStringWidth(text); h = font->height(); setupLabelSurface(*cnv, w, h); - drawText(cnv, 0, 0, text, color); + drawText(font, cnv, 0, 0, text, color); } uint id = _numLabels; @@ -762,13 +759,13 @@ void Label::resetPosition() { } -void Gfx::getStringExtent(char *text, uint16 maxwidth, int16* width, int16* height) { +void Gfx::getStringExtent(Font *font, char *text, uint16 maxwidth, int16* width, int16* height) { uint16 lines = 0; uint16 w = 0; *width = 0; - uint16 blankWidth = _font->getStringWidth(" "); + uint16 blankWidth = font->getStringWidth(" "); uint16 tokenWidth = 0; char token[MAX_TOKEN_LEN]; @@ -776,7 +773,7 @@ void Gfx::getStringExtent(char *text, uint16 maxwidth, int16* width, int16* heig while (strlen(text) != 0) { text = parseNextToken(text, token, MAX_TOKEN_LEN, " ", true); - tokenWidth = _font->getStringWidth(token); + tokenWidth = font->getStringWidth(token); w += tokenWidth; @@ -806,13 +803,6 @@ void Gfx::getStringExtent(char *text, uint16 maxwidth, int16* width, int16* heig } -void Gfx::setFont(Font *font) { - assert(font); - _font = font; -} - - - void Gfx::copyRect(const Common::Rect &r, Graphics::Surface &src, Graphics::Surface &dst) { byte *s = (byte*)src.getBasePtr(r.left, r.top); @@ -854,8 +844,6 @@ Gfx::Gfx(Parallaction* vm) : _halfbrite = false; _hbCircleRadius = 0; - _font = NULL; - registerVar("background_mode", 1); _varBackgroundMode = 1; @@ -934,13 +922,12 @@ int Gfx::setSingleBalloon(char *text, uint16 x, uint16 y, uint16 winding, byte t int16 w, h; - setFont(_vm->_dialogueFont); - getStringExtent(text, MAX_BALLOON_WIDTH, &w, &h); + getStringExtent(_vm->_dialogueFont, text, MAX_BALLOON_WIDTH, &w, &h); int id = createBalloon(w+5, h, winding, 1); Gfx::Balloon *balloon = &_balloons[id]; - drawWrappedText(&balloon->surface, text, textColor, MAX_BALLOON_WIDTH); + drawWrappedText(_vm->_dialogueFont, &balloon->surface, text, textColor, MAX_BALLOON_WIDTH); balloon->x = x; balloon->y = y; @@ -952,13 +939,12 @@ int Gfx::setDialogueBalloon(char *text, uint16 winding, byte textColor) { int16 w, h; - setFont(_vm->_dialogueFont); - getStringExtent(text, MAX_BALLOON_WIDTH, &w, &h); + getStringExtent(_vm->_dialogueFont, text, MAX_BALLOON_WIDTH, &w, &h); int id = createBalloon(w+5, h, winding, 1); Gfx::Balloon *balloon = &_balloons[id]; - drawWrappedText(&balloon->surface, text, textColor, MAX_BALLOON_WIDTH); + drawWrappedText(_vm->_dialogueFont, &balloon->surface, text, textColor, MAX_BALLOON_WIDTH); balloon->x = _dialogueBalloonX[id]; balloon->y = 10; @@ -974,7 +960,7 @@ int Gfx::setDialogueBalloon(char *text, uint16 winding, byte textColor) { void Gfx::setBalloonText(uint id, char *text, byte textColor) { Gfx::Balloon *balloon = getBalloon(id); balloon->surface.fillRect(balloon->innerBox, 1); - drawWrappedText(&balloon->surface, text, textColor, MAX_BALLOON_WIDTH); + drawWrappedText(_vm->_dialogueFont, &balloon->surface, text, textColor, MAX_BALLOON_WIDTH); } @@ -982,12 +968,11 @@ int Gfx::setLocationBalloon(char *text, bool endGame) { int16 w, h; - setFont(_vm->_dialogueFont); - getStringExtent(text, MAX_BALLOON_WIDTH, &w, &h); + getStringExtent(_vm->_dialogueFont, text, MAX_BALLOON_WIDTH, &w, &h); int id = createBalloon(w+(endGame ? 5 : 10), h+5, -1, BALLOON_TRANSPARENT_COLOR); Gfx::Balloon *balloon = &_balloons[id]; - drawWrappedText(&balloon->surface, text, 0, MAX_BALLOON_WIDTH); + drawWrappedText(_vm->_dialogueFont, &balloon->surface, text, 0, MAX_BALLOON_WIDTH); balloon->x = 5; balloon->y = 5; @@ -1027,13 +1012,13 @@ void Gfx::hideDialogueStuff() { freeBalloons(); } -void Gfx::drawText(Graphics::Surface* surf, uint16 x, uint16 y, const char *text, byte color) { +void Gfx::drawText(Font *font, Graphics::Surface* surf, uint16 x, uint16 y, const char *text, byte color) { byte *dst = (byte*)surf->getBasePtr(x, y); - _font->setColor(color); - _font->drawString(dst, surf->w, text); + font->setColor(color); + font->drawString(dst, surf->w, text); } -void Gfx::drawWrappedText(Graphics::Surface* surf, char *text, byte color, int16 wrapwidth) { +void Gfx::drawWrappedText(Font *font, Graphics::Surface* surf, char *text, byte color, int16 wrapwidth) { uint16 lines = 0; uint16 linewidth = 0; @@ -1041,7 +1026,7 @@ void Gfx::drawWrappedText(Graphics::Surface* surf, char *text, byte color, int16 uint16 rx = 10; uint16 ry = 4; - uint16 blankWidth = _font->getStringWidth(" "); + uint16 blankWidth = font->getStringWidth(" "); uint16 tokenWidth = 0; char token[MAX_TOKEN_LEN]; @@ -1060,9 +1045,9 @@ void Gfx::drawWrappedText(Graphics::Surface* surf, char *text, byte color, int16 strcpy(token, "> ......."); strncpy(token+2, _password, strlen(_password)); - tokenWidth = _font->getStringWidth(token); + tokenWidth = font->getStringWidth(token); } else { - tokenWidth = _font->getStringWidth(token); + tokenWidth = font->getStringWidth(token); linewidth += tokenWidth; @@ -1080,7 +1065,7 @@ void Gfx::drawWrappedText(Graphics::Surface* surf, char *text, byte color, int16 } - drawText(surf, rx, ry, token, color); + drawText(font, surf, rx, ry, token, color); rx += tokenWidth + blankWidth; linewidth += blankWidth; diff --git a/engines/parallaction/graphics.h b/engines/parallaction/graphics.h index 7a036a8da8..d61cee2b76 100644 --- a/engines/parallaction/graphics.h +++ b/engines/parallaction/graphics.h @@ -481,7 +481,7 @@ public: int setSingleBalloon(char *text, uint16 x, uint16 y, uint16 winding, byte textColor); void setBalloonText(uint id, char *text, byte textColor); int hitTestDialogueBalloon(int x, int y); - void getStringExtent(char *text, uint16 maxwidth, int16* width, int16* height); + void getStringExtent(Font *font, char *text, uint16 maxwidth, int16* width, int16* height); // other items int setItem(Frames* frames, uint16 x, uint16 y, byte transparentColor = 0); @@ -529,7 +529,6 @@ public: protected: Parallaction* _vm; - Font *_font; bool _halfbrite; Common::Point _hbCirclePos; @@ -583,9 +582,8 @@ protected: Balloon *getBalloon(uint id); // low level text and patches - void setFont(Font* font); - void drawText(Graphics::Surface* surf, uint16 x, uint16 y, const char *text, byte color); - void drawWrappedText(Graphics::Surface* surf, char *text, byte color, int16 wrapwidth); + void drawText(Font *font, Graphics::Surface* surf, uint16 x, uint16 y, const char *text, byte color); + void drawWrappedText(Font *font, Graphics::Surface* surf, char *text, byte color, int16 wrapwidth); void blt(const Common::Rect& r, byte *data, Graphics::Surface *surf, uint16 z, byte transparentColor); void unpackBlt(const Common::Rect& r, byte *data, uint size, Graphics::Surface *surf, uint16 z, byte transparentColor); |