diff options
author | Max Horn | 2002-07-07 23:37:47 +0000 |
---|---|---|
committer | Max Horn | 2002-07-07 23:37:47 +0000 |
commit | c3b606cd9b0b0445b0360f9a95225186252ae1c1 (patch) | |
tree | 00b31845f07a89afb6f2bb425d3e2e7a478554e1 /gui | |
parent | 10d86be56456b57392cca05d5a2135408289223c (diff) | |
download | scummvm-rg350-c3b606cd9b0b0445b0360f9a95225186252ae1c1.tar.gz scummvm-rg350-c3b606cd9b0b0445b0360f9a95225186252ae1c1.tar.bz2 scummvm-rg350-c3b606cd9b0b0445b0360f9a95225186252ae1c1.zip |
added CheckboxWidget; added NewGui::drawBitmap
svn-id: r4486
Diffstat (limited to 'gui')
-rw-r--r-- | gui/dialog.cpp | 3 | ||||
-rw-r--r-- | gui/dialog.h | 3 | ||||
-rw-r--r-- | gui/widget.cpp | 53 | ||||
-rw-r--r-- | gui/widget.h | 23 |
4 files changed, 76 insertions, 6 deletions
diff --git a/gui/dialog.cpp b/gui/dialog.cpp index a4491d0c07..ab64eafe67 100644 --- a/gui/dialog.cpp +++ b/gui/dialog.cpp @@ -124,6 +124,9 @@ SaveLoadDialog::SaveLoadDialog(NewGui *gui) addButton(200, 60, 54, 16, 'P', RES_STRING(6), kPlayCmd); // Play addButton(200, 80, 54, 16, 'O', CUSTOM_STRING(17), kOptionsCmd); // Options addButton(200, 100, 54, 16, 'Q', RES_STRING(8), kQuitCmd); // Quit + + // FIXME - test + new CheckboxWidget(this, 50, 20, 100, 16, "Toggle me", 0); } void SaveLoadDialog::handleCommand(uint32 cmd) diff --git a/gui/dialog.h b/gui/dialog.h index 9d7756a2c4..e057fd136c 100644 --- a/gui/dialog.h +++ b/gui/dialog.h @@ -37,7 +37,6 @@ enum { class Dialog { friend class Widget; - friend class StaticTextWidget; protected: NewGui *_gui; Widget *_firstWidget; @@ -57,6 +56,8 @@ public: { if (key == 27) close(); } virtual void handleMouseMoved(int x, int y, int button); virtual void handleCommand(uint32 cmd); + + NewGui *getGui() { return _gui; } protected: Widget* findWidget(int x, int y); // Find the widget at pos x,y if any diff --git a/gui/widget.cpp b/gui/widget.cpp index 0fbcfd20ba..38033a2d06 100644 --- a/gui/widget.cpp +++ b/gui/widget.cpp @@ -78,7 +78,7 @@ StaticTextWidget::StaticTextWidget(Dialog *boss, int x, int y, int w, int h, con void StaticTextWidget::drawWidget(bool hilite) { - NewGui *gui = _boss->_gui; + NewGui *gui = _boss->getGui(); gui->drawString(_text, _x, _y, _w, hilite ? gui->_textcolorhi : gui->_textcolor); } @@ -94,6 +94,55 @@ ButtonWidget::ButtonWidget(Dialog *boss, int x, int y, int w, int h, const char void ButtonWidget::handleClick(int button) { - if (_flags & WIDGET_ENABLED) + if (_flags & WIDGET_ENABLED && _cmd) _boss->handleCommand(_cmd); } + + +#pragma mark - + + +/* 8x8 checkbox bitmap */ +static uint32 checked_img[8] = { + 0x00000000, + 0x01000010, + 0x00100100, + 0x00011000, + 0x00011000, + 0x00100100, + 0x01000010, + 0x00000000, +}; + +CheckboxWidget::CheckboxWidget(Dialog *boss, int x, int y, int w, int h, const char *label, uint32 cmd) + : ButtonWidget(boss, x, y, w, h, label, cmd), _state(false) +{ + _flags = WIDGET_ENABLED; +} + +void CheckboxWidget::handleClick(int button) +{ + if (_flags & WIDGET_ENABLED) { + _state = !_state; + draw(); + if (_cmd) + _boss->handleCommand(_cmd); + } +} + +void CheckboxWidget::drawWidget(bool hilite) +{ + NewGui *gui = _boss->getGui(); + + // Draw the box + gui->box(_x, _y, 14, 14); + + // If checked, draw cross inside the box + if (_state) + gui->drawBitmap(checked_img, _x + 3, _y + 3, gui->_textcolor); + else + gui->clearArea(_x + 3, _y + 3, 8, 8); + + // Finally draw the label + gui->drawString(_text, _x + 20, _y + 3, _w, gui->_textcolor); +} diff --git a/gui/widget.h b/gui/widget.h index 58e04d48a9..a1ea0fcf64 100644 --- a/gui/widget.h +++ b/gui/widget.h @@ -83,13 +83,30 @@ protected: uint8 _hotkey; public: ButtonWidget(Dialog *boss, int x, int y, int w, int h, const char *label, uint32 cmd); - void setCmd(uint32 cmd); - uint32 getCmd(); - void handleClick(int button); + void setCmd(uint32 cmd) { _cmd = cmd; } + uint32 getCmd() { return _cmd; } + void handleClick(int button); void handleMouseEntered(int button) { setFlags(WIDGET_HILITED); draw(); } void handleMouseLeft(int button) { clearFlags(WIDGET_HILITED); draw(); } }; +/* CheckboxWidget */ +class CheckboxWidget : public ButtonWidget { +protected: + bool _state; +public: + CheckboxWidget(Dialog *boss, int x, int y, int w, int h, const char *label, uint32 cmd); + void setState(bool state) { _state = state; } + bool getState() { return _state; } + + void handleClick(int button); + virtual void handleMouseEntered(int button) {} + virtual void handleMouseLeft(int button) {} + +protected: + void drawWidget(bool hilite); +}; + #endif |