From e21fd496f837dc13a4c232e931767b14fef43940 Mon Sep 17 00:00:00 2001 From: Nicola Mettifogo Date: Tue, 8 Jan 2008 20:46:58 +0000 Subject: Restructured label handling and moved all related code to Gfx. svn-id: r30345 --- engines/parallaction/graphics.cpp | 39 +++++++++++++++++++++++++++++++- engines/parallaction/graphics.h | 1 + engines/parallaction/objects.cpp | 4 ++++ engines/parallaction/objects.h | 2 +- engines/parallaction/parallaction.cpp | 3 +-- engines/parallaction/parallaction.h | 2 -- engines/parallaction/parallaction_ns.cpp | 19 ---------------- engines/parallaction/parser_ns.cpp | 4 ++-- 8 files changed, 47 insertions(+), 27 deletions(-) (limited to 'engines/parallaction') diff --git a/engines/parallaction/graphics.cpp b/engines/parallaction/graphics.cpp index a63445117d..fb62c34e87 100644 --- a/engines/parallaction/graphics.cpp +++ b/engines/parallaction/graphics.cpp @@ -505,6 +505,43 @@ void Gfx::blit(const Common::Rect& r, uint16 z, byte *data, Graphics::Surface *s } +#define LABEL_TRANSPARENT_COLOR 0xFF + +Label *Gfx::renderFloatingLabel(Font *font, char *text) { + + Label *label = new Label; + Graphics::Surface *cnv = &label->_cnv; + + uint w, h; + + if (_vm->getPlatform() == Common::kPlatformAmiga) { + w = font->getStringWidth(text) + 16; + h = 10; + + cnv->create(w, h, 1); + cnv->fillRect(Common::Rect(w,h), LABEL_TRANSPARENT_COLOR); + + font->setColor(7); + font->drawString((byte*)cnv->pixels + 1, cnv->w, text); + font->drawString((byte*)cnv->pixels + 1 + cnv->w * 2, cnv->w, text); + font->drawString((byte*)cnv->pixels + cnv->w, cnv->w, text); + font->drawString((byte*)cnv->pixels + 2 + cnv->w, cnv->w, text); + font->setColor(1); + font->drawString((byte*)cnv->pixels + 1 + cnv->w, cnv->w, text); + } else { + w = font->getStringWidth(text); + h = font->height(); + + cnv->create(w, h, 1); + cnv->fillRect(Common::Rect(w,h), LABEL_TRANSPARENT_COLOR); + + font->drawString((byte*)cnv->pixels, cnv->w, text); + } + + return label; +} + + void Gfx::setLabel(Label *label) { _label = label; @@ -544,7 +581,7 @@ void Gfx::drawLabel() { r.moveTo(_label->_pos); Graphics::Surface* surf = g_system->lockScreen(); - flatBlit(r, (byte*)_label->_cnv.getBasePtr(0, 0), surf, 0); + flatBlit(r, (byte*)_label->_cnv.getBasePtr(0, 0), surf, LABEL_TRANSPARENT_COLOR); g_system->unlockScreen(); } diff --git a/engines/parallaction/graphics.h b/engines/parallaction/graphics.h index fe9a24dd37..a40dc5dc37 100644 --- a/engines/parallaction/graphics.h +++ b/engines/parallaction/graphics.h @@ -251,6 +251,7 @@ public: // labels Label *_label; void setLabel(Label *label); + Label *renderFloatingLabel(Font *font, char *text); // cut/paste void flatBlitCnv(Graphics::Surface *cnv, int16 x, int16 y, Gfx::Buffers buffer); diff --git a/engines/parallaction/objects.cpp b/engines/parallaction/objects.cpp index 1135724cd5..337e213dfd 100644 --- a/engines/parallaction/objects.cpp +++ b/engines/parallaction/objects.cpp @@ -123,6 +123,8 @@ Zone::Zone() { _type = 0; _flags = 0; + _label = 0; + memset(_name, 0, ZONENAME_LENGTH); } @@ -166,6 +168,8 @@ Zone::~Zone() { default: break; } + + delete _label; } void Zone::getRect(Common::Rect& r) const { diff --git a/engines/parallaction/objects.h b/engines/parallaction/objects.h index 4bd290fb6b..a270ddf0f7 100644 --- a/engines/parallaction/objects.h +++ b/engines/parallaction/objects.h @@ -280,7 +280,7 @@ struct Zone { int16 _bottom; uint32 _type; uint32 _flags; - Label _label; + Label *_label; uint16 field_2C; // unused uint16 field_2E; // unused TypeData u; diff --git a/engines/parallaction/parallaction.cpp b/engines/parallaction/parallaction.cpp index 9327982a71..1cb8e05fa0 100644 --- a/engines/parallaction/parallaction.cpp +++ b/engines/parallaction/parallaction.cpp @@ -504,7 +504,7 @@ bool Parallaction::translateGameInput() { if ((_hoverZone == NULL) && ((z->_flags & kFlagsNoName) == 0)) { _hoverZone = z; _input._event = kEvEnterZone; - _input._label = &z->_label; + _input._label = z->_label; return true; } @@ -949,7 +949,6 @@ Character::Character(Parallaction *vm) : _vm(vm), _builder(&_ani) { _ani._frame = 0; _ani._flags = kFlagsActive | kFlagsNoName; _ani._type = kZoneYou; - _ani._label._cnv.pixels = NULL; strncpy(_ani._name, "yourself", ZONENAME_LENGTH); } diff --git a/engines/parallaction/parallaction.h b/engines/parallaction/parallaction.h index 10750c0f8c..283e6164b7 100644 --- a/engines/parallaction/parallaction.h +++ b/engines/parallaction/parallaction.h @@ -570,7 +570,6 @@ protected: // members public: virtual void callFunction(uint index, void* parm) { } - virtual void renderLabel(Graphics::Surface *cnv, char *text) { } virtual void setArrowCursor() = 0; virtual void setInventoryCursor(int pos) = 0; @@ -670,7 +669,6 @@ public: typedef void (Parallaction_ns::*Callable)(void*); virtual void callFunction(uint index, void* parm); - void renderLabel(Graphics::Surface *cnv, char *text); void setMousePointer(uint32 value); void initJobs(); diff --git a/engines/parallaction/parallaction_ns.cpp b/engines/parallaction/parallaction_ns.cpp index aa68866711..516f20e6c6 100644 --- a/engines/parallaction/parallaction_ns.cpp +++ b/engines/parallaction/parallaction_ns.cpp @@ -164,25 +164,6 @@ void Parallaction_ns::freeFonts() { } -void Parallaction_ns::renderLabel(Graphics::Surface *cnv, char *text) { - - if (getPlatform() == Common::kPlatformAmiga) { - cnv->create(_labelFont->getStringWidth(text) + 16, 10, 1); - - _labelFont->setColor(7); - _labelFont->drawString((byte*)cnv->pixels + 1, cnv->w, text); - _labelFont->drawString((byte*)cnv->pixels + 1 + cnv->w * 2, cnv->w, text); - _labelFont->drawString((byte*)cnv->pixels + cnv->w, cnv->w, text); - _labelFont->drawString((byte*)cnv->pixels + 2 + cnv->w, cnv->w, text); - _labelFont->setColor(1); - _labelFont->drawString((byte*)cnv->pixels + 1 + cnv->w, cnv->w, text); - } else { - cnv->create(_labelFont->getStringWidth(text), _labelFont->height(), 1); - _labelFont->drawString((byte*)cnv->pixels, cnv->w, text); - } - -} - void Parallaction_ns::initCursors() { _mouseComposedArrow = _disk->loadPointer("pointer"); diff --git a/engines/parallaction/parser_ns.cpp b/engines/parallaction/parser_ns.cpp index 85a330ddd1..fef9cf803c 100644 --- a/engines/parallaction/parser_ns.cpp +++ b/engines/parallaction/parser_ns.cpp @@ -119,7 +119,7 @@ DECLARE_ANIM_PARSER(type) { DECLARE_ANIM_PARSER(label) { debugC(7, kDebugParser, "ANIM_PARSER(label) "); - renderLabel(&_locParseCtxt.a->_label._cnv, _tokens[1]); + _locParseCtxt.a->_label = _gfx->renderFloatingLabel(_labelFont, _tokens[1]); } @@ -1237,7 +1237,7 @@ DECLARE_ZONE_PARSER(label) { debugC(7, kDebugParser, "ZONE_PARSER(label) "); // printf("label: %s", _tokens[1]); - renderLabel(&_locParseCtxt.z->_label._cnv, _tokens[1]); + _locParseCtxt.z->_label = _gfx->renderFloatingLabel(_labelFont, _tokens[1]); } -- cgit v1.2.3