Restructured label handling and moved all related code to Gfx.

svn-id: r30345
This commit is contained in:
Nicola Mettifogo 2008-01-08 20:46:58 +00:00
parent 359f56cd35
commit e21fd496f8
8 changed files with 47 additions and 27 deletions

View File

@ -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();
}

View File

@ -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);

View File

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

View File

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

View File

@ -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);
}

View File

@ -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();

View File

@ -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");

View File

@ -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]);
}