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

Max Horn fingolfin at users.sourceforge.net
Sun Jul 7 16:38:04 CEST 2002


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

Modified Files:
	dialog.cpp dialog.h widget.cpp widget.h 
Log Message:
added CheckboxWidget; added NewGui::drawBitmap

Index: dialog.cpp
===================================================================
RCS file: /cvsroot/scummvm/scummvm/gui/dialog.cpp,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -d -r1.6 -r1.7
--- dialog.cpp	7 Jul 2002 22:44:30 -0000	1.6
+++ dialog.cpp	7 Jul 2002 23:37:47 -0000	1.7
@@ -124,6 +124,9 @@
 	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)

Index: dialog.h
===================================================================
RCS file: /cvsroot/scummvm/scummvm/gui/dialog.h,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -d -r1.3 -r1.4
--- dialog.h	7 Jul 2002 22:44:30 -0000	1.3
+++ dialog.h	7 Jul 2002 23:37:47 -0000	1.4
@@ -37,7 +37,6 @@
 
 class Dialog {
 	friend class Widget;
-	friend class StaticTextWidget;
 protected:
 	NewGui	*_gui;
 	Widget	*_firstWidget;
@@ -57,6 +56,8 @@
 		{ 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

Index: widget.cpp
===================================================================
RCS file: /cvsroot/scummvm/scummvm/gui/widget.cpp,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -d -r1.5 -r1.6
--- widget.cpp	7 Jul 2002 21:46:53 -0000	1.5
+++ widget.cpp	7 Jul 2002 23:37:47 -0000	1.6
@@ -78,7 +78,7 @@
 
 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 @@
 
 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);
 }

Index: widget.h
===================================================================
RCS file: /cvsroot/scummvm/scummvm/gui/widget.h,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -d -r1.3 -r1.4
--- widget.h	7 Jul 2002 21:46:53 -0000	1.3
+++ widget.h	7 Jul 2002 23:37:47 -0000	1.4
@@ -83,12 +83,29 @@
 	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);
 };
 
 





More information about the Scummvm-git-logs mailing list