diff options
author | Max Horn | 2002-07-15 12:59:56 +0000 |
---|---|---|
committer | Max Horn | 2002-07-15 12:59:56 +0000 |
commit | e6f6e5df8f97caf7ba2f009336efda4c760ed193 (patch) | |
tree | 9eb83388adbcda403d7263e1bad2e06aaef81be7 | |
parent | 272c391eb04b51a088e43fcbae37a84c39d8ff35 (diff) | |
download | scummvm-rg350-e6f6e5df8f97caf7ba2f009336efda4c760ed193.tar.gz scummvm-rg350-e6f6e5df8f97caf7ba2f009336efda4c760ed193.tar.bz2 scummvm-rg350-e6f6e5df8f97caf7ba2f009336efda4c760ed193.zip |
allow static text/button widgets in NewGUI to be drawn centred
svn-id: r4551
-rw-r--r-- | gui/widget.cpp | 8 | ||||
-rw-r--r-- | gui/widget.h | 3 | ||||
-rw-r--r-- | newgui.cpp | 22 | ||||
-rw-r--r-- | newgui.h | 2 |
4 files changed, 22 insertions, 13 deletions
diff --git a/gui/widget.cpp b/gui/widget.cpp index c72d44647c..4b8219cc08 100644 --- a/gui/widget.cpp +++ b/gui/widget.cpp @@ -52,6 +52,7 @@ void Widget::draw() gui->box(_x, _y, _w, _h); _x += 4; _y += 4; + _w -= 8; } // Now perform the actual widget draw @@ -64,6 +65,7 @@ void Widget::draw() if (_flags & WIDGET_BORDER) { _x -= 4; _y -= 4; + _w += 8; } _x -= _boss->_x; _y -= _boss->_y; @@ -74,7 +76,7 @@ void Widget::draw() StaticTextWidget::StaticTextWidget(Dialog *boss, int x, int y, int w, int h, const char *text) - : Widget (boss, x, y, w, h), _label(0) + : Widget (boss, x, y, w, h), _label(0), _centred(false) { _type = kStaticTextWidget; setLabel(text); @@ -104,7 +106,7 @@ void StaticTextWidget::setLabel(const char *label) void StaticTextWidget::drawWidget(bool hilite) { NewGui *gui = _boss->getGui(); - gui->drawString(_label, _x, _y, _w, hilite ? gui->_textcolorhi : gui->_textcolor); + gui->drawString(_label, _x, _y, _w, hilite ? gui->_textcolorhi : gui->_textcolor, _centred); } @@ -117,6 +119,8 @@ ButtonWidget::ButtonWidget(Dialog *boss, int x, int y, int w, int h, const char assert(label); _flags = WIDGET_ENABLED | WIDGET_BORDER | WIDGET_CLEARBG ; _type = kButtonWidget; + + setCentred(true); } ButtonWidget::~ButtonWidget() diff --git a/gui/widget.h b/gui/widget.h index 8d2f49e164..4b72df1b42 100644 --- a/gui/widget.h +++ b/gui/widget.h @@ -112,11 +112,14 @@ protected: class StaticTextWidget : public Widget { protected: char *_label; + bool _centred; public: StaticTextWidget(Dialog *boss, int x, int y, int w, int h, const char *text); ~StaticTextWidget(); void setLabel(const char *label); const char *getLabel() const { return _label; } + void setCentred(bool centred) { _centred = centred; } + bool isCentred() const { return _centred; } protected: void drawWidget(bool hilite); diff --git a/newgui.cpp b/newgui.cpp index e642e0ec86..0d9de41f8b 100644 --- a/newgui.cpp +++ b/newgui.cpp @@ -401,23 +401,25 @@ void NewGui::drawChar(const char str, int xx, int yy) } -void NewGui::drawString(const char *str, int x, int y, int w, byte color) +void NewGui::drawString(const char *str, int x, int y, int w, byte color, bool center) { - StringTab *st = &_s->string[5]; - st->charset = 1; - st->center = false; - st->color = color; - st->xpos = x; - st->ypos = y; - st->right = x + w; - if (_s->_gameId) { /* If a game is active.. */ + StringTab *st = &_s->string[5]; + st->charset = 1; + st->center = center; + st->color = color; + st->xpos = center ? x+w/2 : x; + st->ypos = y; + st->right = x + w; + _s->_messagePtr = (byte *)str; _s->drawString(5); } else { + // FIXME - support center, use nicer custom font. Ultimately, we might + // want to *always* draw our messages this way. uint len = strlen(str); for (uint letter = 0; letter < len; letter++) - drawChar(str[letter], st->xpos + (letter * 8), st->ypos); + drawChar(str[letter], x + (letter * 8), y); } } @@ -133,7 +133,7 @@ public: void frameRect(int x, int y, int w, int h, byte color); void addDirtyRect(int x, int y, int w, int h); void drawChar(const char c, int x, int y); - void drawString(const char *str, int x, int y, int w, byte color); + void drawString(const char *str, int x, int y, int w, byte color, bool center = false); void drawBitmap(uint32 bitmap[8], int x, int y, byte color); void blitTo(byte buffer[320*200], int x, int y, int w, int h); |