From 95ca2ea04349e79629e8a34c803331cbae5f9b95 Mon Sep 17 00:00:00 2001 From: Max Horn Date: Sat, 27 Jul 2002 00:36:09 +0000 Subject: added support for right aligned text; made use of that in the sound dialog; less redrawing in the sound dialog svn-id: r4649 --- gui/dialog.cpp | 40 ++++++++++++++++++++++------------------ gui/widget.cpp | 10 ++++------ gui/widget.h | 8 ++++---- newgui.cpp | 19 +++++++++++++------ newgui.h | 8 +++++++- 5 files changed, 50 insertions(+), 35 deletions(-) diff --git a/gui/dialog.cpp b/gui/dialog.cpp index 0a31b457dc..0db49e8600 100644 --- a/gui/dialog.cpp +++ b/gui/dialog.cpp @@ -244,7 +244,7 @@ void Dialog::addResText(int x, int y, int w, int h, int resID) const char *str = _gui->queryResString(resID); if (!str) str = "Dummy!"; - new StaticTextWidget(this, x, y, w, h, str); + new StaticTextWidget(this, x, y, w, h, str, kTextAlignLeft); } void Dialog::addButton(int x, int y, int w, int h, const char *label, uint32 cmd, char hotkey) @@ -385,11 +385,11 @@ AboutDialog::AboutDialog(NewGui *gui) : Dialog (gui, 30, 10, 260, 134) { addButton(110, 110, 40, 16, CUSTOM_STRING(23), kCloseCmd, 'C'); // Close dialog - FIXME - new StaticTextWidget(this, 10, 17, 240, 16, "Build " SCUMMVM_VERSION " (" SCUMMVM_CVS ")", true); - new StaticTextWidget(this, 10, 37, 240, 16, "ScummVM http://scummvm.sourceforge.net", true); - new StaticTextWidget(this, 10, 67, 240, 16, "All games (c) LucasArts", true); - new StaticTextWidget(this, 10, 84, 240, 16, "Except", true); - new StaticTextWidget(this, 10, 97, 240, 16, "Simon the Sorcerer (c) Adventuresoft", true); + new StaticTextWidget(this, 10, 17, 240, 16, "Build " SCUMMVM_VERSION " (" SCUMMVM_CVS ")", kTextAlignCenter); + new StaticTextWidget(this, 10, 37, 240, 16, "ScummVM http://scummvm.sourceforge.net", kTextAlignCenter); + new StaticTextWidget(this, 10, 67, 240, 16, "All games (c) LucasArts", kTextAlignCenter); + new StaticTextWidget(this, 10, 84, 240, 16, "Except", kTextAlignCenter); + new StaticTextWidget(this, 10, 97, 240, 16, "Simon the Sorcerer (c) Adventuresoft", kTextAlignCenter); } PauseDialog::PauseDialog(NewGui *gui) @@ -405,21 +405,25 @@ SoundDialog::SoundDialog(NewGui *gui) // set up dialog addButton(70, 90, 54, 16, "OK", kOKCmd, 'O'); // Confirm dialog addButton(136, 90, 54, 16, "Cancel", kCancelCmd, 'C'); // Abort dialog - new StaticTextWidget(this, 10, 17, 140, 16, "Master volume:", false); - new StaticTextWidget(this, 10, 37, 140, 16, "Music volume:", false); - new StaticTextWidget(this, 10, 57, 140, 16, "SFX volume:", false); + new StaticTextWidget(this, 20, 17, 85, 16, "Master volume:", kTextAlignRight); + new StaticTextWidget(this, 20, 37, 85, 16, "Music volume:", kTextAlignRight); + new StaticTextWidget(this, 20, 57, 85, 16, "SFX volume:", kTextAlignRight); - masterVolumeSlider = new SliderWidget(this, 100, 13, 80, 16, "Volume1", kMasterVolumeChanged); - musicVolumeSlider = new SliderWidget(this, 100, 33, 80, 16, "Volume2", kMusicVolumeChanged); - sfxVolumeSlider = new SliderWidget(this, 100, 53, 80, 16, "Volume3", kSfxVolumeChanged); + masterVolumeSlider = new SliderWidget(this, 110, 13, 80, 16, "Volume1", kMasterVolumeChanged); + musicVolumeSlider = new SliderWidget(this, 110, 33, 80, 16, "Volume2", kMusicVolumeChanged); + sfxVolumeSlider = new SliderWidget(this, 110, 53, 80, 16, "Volume3", kSfxVolumeChanged); masterVolumeSlider->setMinValue(0); masterVolumeSlider->setMaxValue(255); musicVolumeSlider->setMinValue(0); musicVolumeSlider->setMaxValue(255); sfxVolumeSlider->setMinValue(0); sfxVolumeSlider->setMaxValue(255); - masterVolumeLabel = new StaticTextWidget(this, 190, 16, 60, 16, "Volume1"); - musicVolumeLabel = new StaticTextWidget(this, 190, 36, 60, 16, "Volume2"); - sfxVolumeLabel = new StaticTextWidget(this, 190, 56, 60, 16, "Volume3"); + masterVolumeLabel = new StaticTextWidget(this, 195, 17, 60, 16, "Volume1", kTextAlignLeft); + musicVolumeLabel = new StaticTextWidget(this, 195, 37, 60, 16, "Volume2", kTextAlignLeft); + sfxVolumeLabel = new StaticTextWidget(this, 195, 57, 60, 16, "Volume3", kTextAlignLeft); + + masterVolumeLabel->setFlags(WIDGET_CLEARBG); + musicVolumeLabel->setFlags(WIDGET_CLEARBG); + sfxVolumeLabel->setFlags(WIDGET_CLEARBG); } void SoundDialog::open() @@ -449,14 +453,17 @@ void SoundDialog::handleCommand(CommandSender *sender, uint32 cmd, uint32 data) case kMasterVolumeChanged: _soundVolumeMaster = masterVolumeSlider->getValue(); masterVolumeLabel->setValue(_soundVolumeMaster); + masterVolumeLabel->draw(); break; case kMusicVolumeChanged: _soundVolumeMusic = musicVolumeSlider->getValue(); musicVolumeLabel->setValue(_soundVolumeMusic); + musicVolumeLabel->draw(); break; case kSfxVolumeChanged: _soundVolumeSfx = sfxVolumeSlider->getValue(); sfxVolumeLabel->setValue(_soundVolumeSfx); + sfxVolumeLabel->draw(); break; case kOKCmd: { Scumm *scumm = _gui->getScumm(); @@ -482,7 +489,4 @@ void SoundDialog::handleCommand(CommandSender *sender, uint32 cmd, uint32 data) default: Dialog::handleCommand(sender, cmd, data); } - - draw(); - } diff --git a/gui/widget.cpp b/gui/widget.cpp index c13ae7f4e1..79354de515 100644 --- a/gui/widget.cpp +++ b/gui/widget.cpp @@ -76,8 +76,8 @@ void Widget::draw() #pragma mark - -StaticTextWidget::StaticTextWidget(Dialog *boss, int x, int y, int w, int h, const char *text, bool centred) - : Widget (boss, x, y, w, h), _label(0), _centred(centred) +StaticTextWidget::StaticTextWidget(Dialog *boss, int x, int y, int w, int h, const char *text, int align) + : Widget (boss, x, y, w, h), _label(0), _align(align) { _type = kStaticTextWidget; setLabel(text); @@ -117,7 +117,7 @@ void StaticTextWidget::setValue(int value) void StaticTextWidget::drawWidget(bool hilite) { NewGui *gui = _boss->getGui(); - gui->drawString(_label, _x, _y, _w, hilite ? gui->_textcolorhi : gui->_textcolor, _centred); + gui->drawString(_label, _x, _y, _w, hilite ? gui->_textcolorhi : gui->_textcolor, _align); } @@ -125,13 +125,11 @@ void StaticTextWidget::drawWidget(bool hilite) ButtonWidget::ButtonWidget(Dialog *boss, int x, int y, int w, int h, const char *label, uint32 cmd, uint8 hotkey) - : StaticTextWidget(boss, x, y, w, h, label), CommandSender(boss), _cmd(cmd), _hotkey(hotkey) + : StaticTextWidget(boss, x, y, w, h, label, kTextAlignCenter), CommandSender(boss), _cmd(cmd), _hotkey(hotkey) { 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 53f2194b8f..83df0e6735 100644 --- a/gui/widget.h +++ b/gui/widget.h @@ -118,15 +118,15 @@ protected: class StaticTextWidget : public Widget { protected: char *_label; - bool _centred; + int _align; public: - StaticTextWidget(Dialog *boss, int x, int y, int w, int h, const char *text, bool centred = false); + StaticTextWidget(Dialog *boss, int x, int y, int w, int h, const char *text, int align); ~StaticTextWidget(); void setValue(int value); void setLabel(const char *label); const char *getLabel() const { return _label; } - void setCentred(bool centred) { _centred = centred; } - bool isCentred() const { return _centred; } + void setAlign(int align) { _align = align; } + int getAlign() const { return _align; } protected: void drawWidget(bool hilite); diff --git a/newgui.cpp b/newgui.cpp index 4a71be6c79..f301d8677e 100644 --- a/newgui.cpp +++ b/newgui.cpp @@ -29,7 +29,6 @@ * TODO list * - implement the missing / incomplete dialogs * - add more widgets - * - add support for right/center aligned text * - allow multi line (l/c/r aligned) text via StaticTextWidget ? * - add "close" widget to all dialogs (with a flag to turn it off) ? * - make dialogs "moveable" ? @@ -438,22 +437,30 @@ void NewGui::drawChar(const char str, int xx, int yy) } -void NewGui::drawString(const char *str, int x, int y, int w, byte color, bool center) +void NewGui::drawString(const char *str, int x, int y, int w, byte color, int align) { if (_s->_gameId) { /* If a game is active.. */ StringTab *st = &_s->string[5]; st->charset = 1; - st->center = center; + st->center = (align == kTextAlignCenter); st->color = color; - st->xpos = center ? x+w/2 : x; + + if (align == kTextAlignLeft) + st->xpos = x; + else if (align == kTextAlignCenter) + st->xpos = x + w/2; + else if (align == kTextAlignRight) + st->xpos = x + w - _s->charset.getStringWidth(0, (byte *)str, 0); + 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. + // FIXME - support center/right align, use nicer custom font. + // Ultimately, we might want to *always* draw our messages this way, + // but only if we have a nice font. uint len = strlen(str); for (uint letter = 0; letter < len; letter++) drawChar(str[letter], x + (letter * 8), y); diff --git a/newgui.h b/newgui.h index 4f27aaa2a9..10d2861c84 100644 --- a/newgui.h +++ b/newgui.h @@ -31,6 +31,12 @@ class Scumm; #define hline(x, y, x2, color) line(x, y, x2, y, color); #define vline(x, y, y2, color) line(x, y, x, y2, color); +enum { + kTextAlignLeft, + kTextAlignCenter, + kTextAlignRight, +}; + // Extremly simple stack class, doesn't even do any error checking (for now) class DialogStack { protected: @@ -124,7 +130,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, bool center = false); + void drawString(const char *str, int x, int y, int w, byte color, int align = kTextAlignLeft); 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); -- cgit v1.2.3