[Scummvm-cvs-logs] CVS: scummvm/gui dialog.cpp,1.8,1.9 dialog.h,1.4,1.5 widget.cpp,1.7,1.8 widget.h,1.4,1.5

Max Horn fingolfin at users.sourceforge.net
Sun Jul 7 17:30:02 CEST 2002


Update of /cvsroot/scummvm/scummvm/gui
In directory usw-pr-cvs1:/tmp/cvs-serv30120/gui

Modified Files:
	dialog.cpp dialog.h widget.cpp widget.h 
Log Message:
implemented hotkey support in new GUI code

Index: dialog.cpp
===================================================================
RCS file: /cvsroot/scummvm/scummvm/gui/dialog.cpp,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -d -r1.8 -r1.9
--- dialog.cpp	8 Jul 2002 00:10:11 -0000	1.8
+++ dialog.cpp	8 Jul 2002 00:29:47 -0000	1.9
@@ -18,6 +18,8 @@
  * $Header$
  */
 
+#include <ctype.h>
+
 #include "stdafx.h"
 #include "dialog.h"
 #include "widget.h"
@@ -44,6 +46,25 @@
 		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 @@
 	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 @@
 //  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 @@
 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)

Index: dialog.h
===================================================================
RCS file: /cvsroot/scummvm/scummvm/gui/dialog.h,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -d -r1.4 -r1.5
--- dialog.h	7 Jul 2002 23:37:47 -0000	1.4
+++ dialog.h	8 Jul 2002 00:29:47 -0000	1.5
@@ -52,8 +52,7 @@
 
 	//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 @@
 	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 {

Index: widget.cpp
===================================================================
RCS file: /cvsroot/scummvm/scummvm/gui/widget.cpp,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -d -r1.7 -r1.8
--- widget.cpp	8 Jul 2002 00:10:11 -0000	1.7
+++ widget.cpp	8 Jul 2002 00:29:47 -0000	1.8
@@ -90,8 +90,8 @@
 #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 @@
 	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;
 }

Index: widget.h
===================================================================
RCS file: /cvsroot/scummvm/scummvm/gui/widget.h,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -d -r1.4 -r1.5
--- widget.h	7 Jul 2002 23:37:47 -0000	1.4
+++ widget.h	8 Jul 2002 00:29:47 -0000	1.5
@@ -78,11 +78,12 @@
 
 /* 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 @@
 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; }
 





More information about the Scummvm-git-logs mailing list