[Scummvm-cvs-logs] CVS: scummvm/gui dialog.cpp,1.10,1.11 widget.cpp,1.9,1.10 widget.h,1.6,1.7

James Brown ender at users.sourceforge.net
Mon Jul 8 06:53:10 CEST 2002


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

Modified Files:
	dialog.cpp widget.cpp widget.h 
Log Message:
Add slider widget



Index: dialog.cpp
===================================================================
RCS file: /cvsroot/scummvm/scummvm/gui/dialog.cpp,v
retrieving revision 1.10
retrieving revision 1.11
diff -u -d -r1.10 -r1.11
--- dialog.cpp	8 Jul 2002 11:55:55 -0000	1.10
+++ dialog.cpp	8 Jul 2002 13:52:50 -0000	1.11
@@ -67,12 +67,17 @@
 void Dialog::handleMouseMoved(int x, int y, int button)
 {
 	Widget *w = findWidget(x - _x, y - _y);
+	if (!w)
+		return;
+
 	if (_mouseWidget != w) {
 		if (_mouseWidget)
 			_mouseWidget->handleMouseLeft(button);
 		if (w)
 			w->handleMouseEntered(button);
 		_mouseWidget = w;
+	} else if (w->getFlags() & WIDGET_TRACK_MOUSE) {
+		w->handleMouseMoved(x - _x - w->_x, y - _y - w->_y, button);
 	}
 }
 
@@ -147,6 +152,9 @@
 	
 	// FIXME - test
 	new CheckboxWidget(this, 50, 20, 100, 16, "Toggle me", 0);
+
+	// FIXME - test
+	new SliderWidget(this, 50, 50, 100, 16, "Volume", 0);
 }
 
 void SaveLoadDialog::handleCommand(uint32 cmd)

Index: widget.cpp
===================================================================
RCS file: /cvsroot/scummvm/scummvm/gui/widget.cpp,v
retrieving revision 1.9
retrieving revision 1.10
diff -u -d -r1.9 -r1.10
--- widget.cpp	8 Jul 2002 11:55:55 -0000	1.9
+++ widget.cpp	8 Jul 2002 13:52:50 -0000	1.10
@@ -153,3 +153,33 @@
 	// Finally draw the label
 	gui->drawString(_text, _x + 20, _y + 3, _w, gui->_textcolor);
 }
+
+#pragma mark -
+SliderWidget::SliderWidget(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)
+{
+	_flags = WIDGET_ENABLED | WIDGET_TRACK_MOUSE;
+	_type = kSliderWidget;
+}
+
+void SliderWidget::drawWidget(bool hilite)
+{
+	NewGui *gui = _boss->getGui();
+	
+	// Draw the box
+	gui->box(_x, _y, _w, _h);
+
+	// Draw the 'bar'
+	gui->line(_x + 2 + ((_w - 5)* _value / 100), _y + 2, _x + 2 + ((_w - 5)* _value / 100), _y + _h - 3, hilite ? gui->_textcolorhi : gui->_textcolor);
+}
+
+void SliderWidget::handleMouseMoved(int x, int y, int state) { 
+	if (state == 1) {
+		int newvalue = x * 100 / _w;
+
+		if (newvalue != _value) {
+			_value = newvalue; 
+			setFlags(WIDGET_CLEARBG); draw(); clearFlags(WIDGET_CLEARBG);
+		}
+	}
+}
\ No newline at end of file

Index: widget.h
===================================================================
RCS file: /cvsroot/scummvm/scummvm/gui/widget.h,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -d -r1.6 -r1.7
--- widget.h	8 Jul 2002 11:55:55 -0000	1.6
+++ widget.h	8 Jul 2002 13:52:50 -0000	1.7
@@ -33,12 +33,14 @@
 	WIDGET_BORDER		= 1 << 3,
 	WIDGET_CLEARBG		= 1 << 4,
 	WIDGET_WANT_TICKLE	= 1 << 5,
+	WIDGET_TRACK_MOUSE  = 1 << 6
 };
 
 enum {
 	kStaticTextWidget	= 'TEXT',
 	kButtonWidget		= 'BTTN',
 	kCheckboxWidget		= 'CHKB',
+	kSliderWidget		= 'SLDE'
 };
 
 /* Widget */
@@ -58,6 +60,7 @@
 	virtual void handleClick(int button)		{}
 	virtual void handleMouseEntered(int button)	{}
 	virtual void handleMouseLeft(int button)	{}
+	virtual void handleMouseMoved(int x, int y, int button) {}
 	void draw();
 
 	void setFlags(int flags)	{ _flags |= flags; }
@@ -115,6 +118,19 @@
 protected:
 	void drawWidget(bool hilite);
 };
+
+/* SliderWidget */
+class SliderWidget : public ButtonWidget {
+protected:
+	int	_value;
+public:
+	SliderWidget(Dialog *boss, int x, int y, int w, int h, const char *label, uint32 cmd = 0, uint8 hotkey = 0);
+	void handleMouseMoved(int x, int y, int button);
+
+protected:
+	void drawWidget(bool hilite);
+};
+
 
 
 #endif





More information about the Scummvm-git-logs mailing list