diff options
author | Max Horn | 2002-07-08 00:29:47 +0000 |
---|---|---|
committer | Max Horn | 2002-07-08 00:29:47 +0000 |
commit | 28852f14975ba9fddbee838fcf9723386870d39c (patch) | |
tree | 0d5c4e04c46f71ac204d6068bb2c0fa8b4018652 /gui | |
parent | c9b1d393b836dc4239a42c0efad7712fb786930f (diff) | |
download | scummvm-rg350-28852f14975ba9fddbee838fcf9723386870d39c.tar.gz scummvm-rg350-28852f14975ba9fddbee838fcf9723386870d39c.tar.bz2 scummvm-rg350-28852f14975ba9fddbee838fcf9723386870d39c.zip |
implemented hotkey support in new GUI code
svn-id: r4488
Diffstat (limited to 'gui')
-rw-r--r-- | gui/dialog.cpp | 46 | ||||
-rw-r--r-- | gui/dialog.h | 5 | ||||
-rw-r--r-- | gui/widget.cpp | 8 | ||||
-rw-r--r-- | gui/widget.h | 5 |
4 files changed, 42 insertions, 22 deletions
diff --git a/gui/dialog.cpp b/gui/dialog.cpp index 9d253db2cf..850c490702 100644 --- a/gui/dialog.cpp +++ b/gui/dialog.cpp @@ -18,6 +18,8 @@ * $Header$ */ +#include <ctype.h> + #include "stdafx.h" #include "dialog.h" #include "widget.h" @@ -44,6 +46,25 @@ void Dialog::handleClick(int x, int y, int button) w->handleClick(button); } +void Dialog::handleKey(char key, int modifiers) +{ + // ESC closes all dialogs by default + if (key == 27) + close(); + + // Hotkey handling + Widget *w = _firstWidget; + key = toupper(key); + while (w) { + ButtonWidget *b = dynamic_cast<ButtonWidget *>(w); + if (b && key == toupper(b->_hotkey)) { + b->handleClick(1); + break; + } + w = w->_next; + } +} + void Dialog::handleMouseMoved(int x, int y, int button) { Widget *w = findWidget(x - _x, y - _y); @@ -96,10 +117,9 @@ void Dialog::addResText(int x, int y, int w, int h, int resID) new StaticTextWidget(this, x, y, w, h, str); } -void Dialog::addButton(int x, int y, int w, int h, char hotkey, const char *label, uint32 cmd) +void Dialog::addButton(int x, int y, int w, int h, const char *label, uint32 cmd, char hotkey) { - new ButtonWidget(this, x, y, w, h, label, cmd); - // TODO - handle hotkey + new ButtonWidget(this, x, y, w, h, label, cmd, hotkey); } #pragma mark - @@ -120,11 +140,11 @@ SaveLoadDialog::SaveLoadDialog(NewGui *gui) // addResText(10, 7, 240, 16, 2); // addResText(10, 7, 240, 16, 3); - addButton(200, 20, 54, 16, 'S', RES_STRING(4), kSaveCmd); // Save - addButton(200, 40, 54, 16, 'L', RES_STRING(5), kLoadCmd); // Load - 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 + addButton(200, 20, 54, 16, RES_STRING(4), kSaveCmd, 'S'); // Save + addButton(200, 40, 54, 16, RES_STRING(5), kLoadCmd, 'L'); // Load + addButton(200, 60, 54, 16, RES_STRING(6), kPlayCmd, 'P'); // Play + addButton(200, 80, 54, 16, CUSTOM_STRING(17), kOptionsCmd, 'O'); // Options + addButton(200, 100, 54, 16, RES_STRING(8), kQuitCmd, 'Q'); // Quit // FIXME - test new CheckboxWidget(this, 50, 20, 100, 16, "Toggle me", 0); @@ -164,11 +184,11 @@ enum { OptionsDialog::OptionsDialog(NewGui *gui) : Dialog (gui, 50, 80, 210, 60) { - addButton( 10, 10, 40, 15, 'S', CUSTOM_STRING(5), kSoundCmd); // Sound - addButton( 80, 10, 40, 15, 'K', CUSTOM_STRING(6), kKeysCmd); // Keys - addButton(150, 10, 40, 15, 'A', CUSTOM_STRING(7), kAboutCmd); // About - addButton( 10, 35, 40, 15, 'M', CUSTOM_STRING(18), kMiscCmd); // Misc - addButton(150, 35, 40, 15, 'C', CUSTOM_STRING(23), kCloseCmd); // Close dialog - FIXME + addButton( 10, 10, 40, 15, CUSTOM_STRING(5), kSoundCmd, 'S'); // Sound + addButton( 80, 10, 40, 15, CUSTOM_STRING(6), kKeysCmd, 'K'); // Keys + addButton(150, 10, 40, 15, CUSTOM_STRING(7), kAboutCmd, 'A'); // About + addButton( 10, 35, 40, 15, CUSTOM_STRING(18), kMiscCmd, 'M'); // Misc + addButton(150, 35, 40, 15, CUSTOM_STRING(23), kCloseCmd, 'C'); // Close dialog - FIXME } void OptionsDialog::handleCommand(uint32 cmd) diff --git a/gui/dialog.h b/gui/dialog.h index e057fd136c..9473ebf690 100644 --- a/gui/dialog.h +++ b/gui/dialog.h @@ -52,8 +52,7 @@ public: //virtual void handleIdle(); // Called periodically virtual void handleClick(int x, int y, int button); - virtual void handleKey(char key, int modifiers) // modifiers = alt/shift/ctrl etc. - { if (key == 27) close(); } + virtual void handleKey(char key, int modifiers); // modifiers = alt/shift/ctrl etc. virtual void handleMouseMoved(int x, int y, int button); virtual void handleCommand(uint32 cmd); @@ -64,7 +63,7 @@ protected: void close(); void addResText(int x, int y, int w, int h, int resID); - void addButton(int x, int y, int w, int h, char hotkey, const char *label, uint32 cmd); + void addButton(int x, int y, int w, int h, const char *label, uint32 cmd, char hotkey); }; class SaveLoadDialog : public Dialog { diff --git a/gui/widget.cpp b/gui/widget.cpp index ecc4c66608..1975001733 100644 --- a/gui/widget.cpp +++ b/gui/widget.cpp @@ -90,8 +90,8 @@ void StaticTextWidget::drawWidget(bool hilite) #pragma mark - -ButtonWidget::ButtonWidget(Dialog *boss, int x, int y, int w, int h, const char *label, uint32 cmd) - : StaticTextWidget(boss, x, y, w, h, label), _cmd(cmd), _hotkey(0) +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), _cmd(cmd), _hotkey(hotkey) { _flags = WIDGET_ENABLED | WIDGET_BORDER /* | WIDGET_CLEARBG */ ; } @@ -118,8 +118,8 @@ static uint32 checked_img[8] = { 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) +CheckboxWidget::CheckboxWidget(Dialog *boss, int x, int y, int w, int h, const char *label, uint32 cmd, uint8 hotkey) + : ButtonWidget(boss, x, y, w, h, label, cmd, hotkey), _state(false) { _flags = WIDGET_ENABLED; } diff --git a/gui/widget.h b/gui/widget.h index a1ea0fcf64..aed1e5590b 100644 --- a/gui/widget.h +++ b/gui/widget.h @@ -78,11 +78,12 @@ protected: /* ButtonWidget */ class ButtonWidget : public StaticTextWidget { +friend class Dialog; protected: uint32 _cmd; uint8 _hotkey; public: - ButtonWidget(Dialog *boss, int x, int y, int w, int h, const char *label, uint32 cmd); + ButtonWidget(Dialog *boss, int x, int y, int w, int h, const char *label, uint32 cmd = 0, uint8 hotkey = 0); void setCmd(uint32 cmd) { _cmd = cmd; } uint32 getCmd() { return _cmd; } @@ -96,7 +97,7 @@ class CheckboxWidget : public ButtonWidget { protected: bool _state; public: - CheckboxWidget(Dialog *boss, int x, int y, int w, int h, const char *label, uint32 cmd); + CheckboxWidget(Dialog *boss, int x, int y, int w, int h, const char *label, uint32 cmd = 0, uint8 hotkey = 0); void setState(bool state) { _state = state; } bool getState() { return _state; } |