diff options
Diffstat (limited to 'engines')
-rw-r--r-- | engines/neverhood/graphics.h | 1 | ||||
-rw-r--r-- | engines/neverhood/menumodule.cpp | 48 | ||||
-rw-r--r-- | engines/neverhood/menumodule.h | 22 |
3 files changed, 71 insertions, 0 deletions
diff --git a/engines/neverhood/graphics.h b/engines/neverhood/graphics.h index 3ca3339585..d6808e37f5 100644 --- a/engines/neverhood/graphics.h +++ b/engines/neverhood/graphics.h @@ -149,6 +149,7 @@ public: void drawChar(BaseSurface *destSurface, int16 x, int16 y, byte chr); void drawString(BaseSurface *destSurface, int16 x, int16 y, const byte *string, int stringLen); int16 getStringWidth(const byte *string, int stringLen); + uint16 getCharHeight() const { return _charHeight; } protected: uint16 _numRows; byte _firstChar; diff --git a/engines/neverhood/menumodule.cpp b/engines/neverhood/menumodule.cpp index bec640e5d4..01fcd41d75 100644 --- a/engines/neverhood/menumodule.cpp +++ b/engines/neverhood/menumodule.cpp @@ -450,4 +450,52 @@ uint32 Widget::handleMessage(int messageNum, const MessageParam ¶m, Entity * return messageResult; } +TextLabelWidget::TextLabelWidget(NeverhoodEngine *vm, int16 x, int16 y, int16 itemID, WidgetScene *parentScene, + int baseObjectPriority, int baseSurfacePriority, bool visible, + const byte *string, int stringLen, BaseSurface *drawSurface, int16 tx, int16 ty, TextSurface *textSurface) + : Widget(vm, x, y, itemID, parentScene, baseObjectPriority, baseSurfacePriority, visible), + _string(string), _stringLen(stringLen), _drawSurface(drawSurface), _tx(tx), _ty(ty), _textSurface(textSurface) { + +} + +void TextLabelWidget::addSprite() { + _parentScene->addSprite(this); + _vm->_collisionMan->addSprite(this); +} + +int16 TextLabelWidget::getWidth() { + return _textSurface->getStringWidth(_string, _stringLen); +} + +int16 TextLabelWidget::getHeight() { + return _textSurface->getCharHeight(); +} + +void TextLabelWidget::drawString(int maxStringLength) { + _textSurface->drawString(_drawSurface, _x, _y, _string, MIN(_stringLen, maxStringLength)); + _visible = true; + _collisionBoundsOffset.set(_tx, _ty, getWidth(), getHeight()); + updateBounds(); +} + +void TextLabelWidget::clear() { + _visible = false; + _collisionBoundsOffset.set(0, 0, 0, 0); + updateBounds(); +} + +void TextLabelWidget::onClick() { + Widget::onClick(); + // TODO Click handler? +} + +void TextLabelWidget::setString(const byte *string, int stringLen) { + _string = string; + _stringLen = stringLen; +} + +void TextLabelWidget::setY(int16 y) { + _ty = y; +} + } // End of namespace Neverhood diff --git a/engines/neverhood/menumodule.h b/engines/neverhood/menumodule.h index 1b6ba8a9f7..8381b4eb30 100644 --- a/engines/neverhood/menumodule.h +++ b/engines/neverhood/menumodule.h @@ -114,6 +114,28 @@ protected: uint32 handleMessage(int messageNum, const MessageParam ¶m, Entity *sender); }; +class TextLabelWidget : public Widget { +public: + TextLabelWidget(NeverhoodEngine *vm, int16 x, int16 y, int16 itemID, WidgetScene *parentScene, + int baseObjectPriority, int baseSurfacePriority, bool visible, + const byte *string, int stringLen, BaseSurface *drawSurface, int16 tx, int16 ty, TextSurface *textSurface); + virtual void onClick(); + virtual void addSprite(); + virtual int16 getWidth(); + virtual int16 getHeight(); + void drawString(int maxStringLength); + void clear(); + void setString(const byte *string, int stringLen); + TextSurface *getTextSurface() const { return _textSurface; } + void setY(int16 y); +protected: + BaseSurface *_drawSurface; + int16 _tx, _ty; + TextSurface *_textSurface; + const byte *_string; + int _stringLen; +}; + } // End of namespace Neverhood #endif /* NEVERHOOD_MENUMODULE_H */ |