Skip to content

Commit

Permalink
NEVERHOOD: Add TextLabelWidget (still doesn't do anything)
Browse files Browse the repository at this point in the history
  • Loading branch information
johndoe123 authored and wjp committed May 8, 2013
1 parent 228d926 commit eecd9b8
Show file tree
Hide file tree
Showing 3 changed files with 71 additions and 0 deletions.
1 change: 1 addition & 0 deletions engines/neverhood/graphics.h
Expand Up @@ -149,6 +149,7 @@ class TextSurface : public BaseSurface {
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;
Expand Down
48 changes: 48 additions & 0 deletions engines/neverhood/menumodule.cpp
Expand Up @@ -450,4 +450,52 @@ uint32 Widget::handleMessage(int messageNum, const MessageParam &param, 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
22 changes: 22 additions & 0 deletions engines/neverhood/menumodule.h
Expand Up @@ -114,6 +114,28 @@ class Widget : public StaticSprite {
uint32 handleMessage(int messageNum, const MessageParam &param, 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 */

0 comments on commit eecd9b8

Please sign in to comment.