[Scummvm-cvs-logs] CVS: scummvm/gui widget.cpp,1.1.1.1,1.2 widget.h,1.1.1.1,1.2

Max Horn fingolfin at users.sourceforge.net
Sat Aug 31 06:43:03 CEST 2002


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

Modified Files:
	widget.cpp widget.h 
Log Message:
use class String for widget labels

Index: widget.cpp
===================================================================
RCS file: /cvsroot/scummvm/scummvm/gui/widget.cpp,v
retrieving revision 1.1.1.1
retrieving revision 1.2
diff -u -d -r1.1.1.1 -r1.2
--- widget.cpp	21 Aug 2002 16:07:25 -0000	1.1.1.1
+++ widget.cpp	31 Aug 2002 13:42:07 -0000	1.2
@@ -76,70 +76,37 @@
 #pragma mark -
 
 
-StaticTextWidget::StaticTextWidget(Dialog *boss, int x, int y, int w, int h, const char *text, int align)
-	: Widget (boss, x, y, w, h), _label(0), _align(align)
+StaticTextWidget::StaticTextWidget(Dialog *boss, int x, int y, int w, int h, const String &text, int align)
+	: Widget (boss, x, y, w, h), _align(align)
 {
 	_type = kStaticTextWidget;
 	setLabel(text);
 }
 
-StaticTextWidget::~StaticTextWidget()
-{
-	if (_label) {
-		free(_label);
-		_label = 0;
-	}
-}
-
-void StaticTextWidget::setLabel(const char *label)
-{
-	// Free old label if any
-	if (_label)
-		free(_label);
-
-	// Duplicate new label
-	if (label)
-		_label = strdup(label);
-	else
-		_label = 0;
-}
-
 void StaticTextWidget::setValue(int value)
 {
-	// Free old label if any
-	if (_label)
-		free(_label);
-
-	_label = (char *)malloc(10);
-	sprintf(_label, "%d", value);
+	char buf[256];
+	sprintf(buf, "%d", value);
+	_label = buf;
 }
 
 void StaticTextWidget::drawWidget(bool hilite)
 {
 	NewGui *gui = _boss->getGui();
-	gui->drawString(_label, _x, _y, _w, hilite ? gui->_textcolorhi : gui->_textcolor, _align);
+	gui->drawString(_label.c_str(), _x, _y, _w, hilite ? gui->_textcolorhi : gui->_textcolor, _align);
 }
 
 
 #pragma mark -
 
 
-ButtonWidget::ButtonWidget(Dialog *boss, int x, int y, int w, int h, const char *label, uint32 cmd, uint8 hotkey)
+ButtonWidget::ButtonWidget(Dialog *boss, int x, int y, int w, int h, const String &label, uint32 cmd, uint8 hotkey)
 	: StaticTextWidget(boss, x, y, w, h, label, kTextAlignCenter), CommandSender(boss), _cmd(cmd), _hotkey(hotkey)
 {
-	assert(label);
 	_flags = WIDGET_ENABLED | WIDGET_BORDER | WIDGET_CLEARBG ;
 	_type = kButtonWidget;
 }
 
-ButtonWidget::~ButtonWidget()
-{
-	if (_label) {
-		free(_label);
-		_label = 0;
-	}
-}
-
 void ButtonWidget::handleMouseUp(int x, int y, int button, int clickCount)
 {
 	if (_flags & WIDGET_ENABLED && x >= 0 && x < _w && y >= 0 && y < _h)
@@ -161,7 +128,7 @@
 	0x00000000,
 };
 
-CheckboxWidget::CheckboxWidget(Dialog *boss, int x, int y, int w, int h, const char *label, uint32 cmd, uint8 hotkey)
+CheckboxWidget::CheckboxWidget(Dialog *boss, int x, int y, int w, int h, const String &label, uint32 cmd, uint8 hotkey)
 	: ButtonWidget(boss, x, y, w, h, label, cmd, hotkey), _state(false)
 {
 	_flags = WIDGET_ENABLED;
@@ -191,12 +158,12 @@
 		gui->fillRect(_x + 2, _y + 2, 10, 10, gui->_bgcolor);
 	
 	// Finally draw the label
-	gui->drawString(_label, _x + 20, _y + 3, _w, gui->_textcolor);
+	gui->drawString(_label.c_str(), _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)
+SliderWidget::SliderWidget(Dialog *boss, int x, int y, int w, int h, const String &label, uint32 cmd, uint8 hotkey)
 	: ButtonWidget(boss, x, y, w, h, label, cmd, hotkey),
 	  _value(0), _oldValue(1), _valueMin(0), _valueMax(100)
 {

Index: widget.h
===================================================================
RCS file: /cvsroot/scummvm/scummvm/gui/widget.h,v
retrieving revision 1.1.1.1
retrieving revision 1.2
diff -u -d -r1.1.1.1 -r1.2
--- widget.h	21 Aug 2002 16:07:25 -0000	1.1.1.1
+++ widget.h	31 Aug 2002 13:42:07 -0000	1.2
@@ -22,6 +22,7 @@
 #define WIDGET_H
 
 #include "scummsys.h"
+#include "common/util.h"
 
 class Dialog;
 
@@ -117,16 +118,17 @@
 /* StaticTextWidget */
 class StaticTextWidget : public Widget {
 protected:
-	char	*_label;
+	typedef ScummVM::String String;
+
+	String _label;
 	int		_align;
 public:
-	StaticTextWidget(Dialog *boss, int x, int y, int w, int h, const char *text, int align);
-	~StaticTextWidget();
+	StaticTextWidget(Dialog *boss, int x, int y, int w, int h, const String &text, int align);
 	void setValue(int value);
-	void setLabel(const char *label);
-	const char *getLabel() const	{ return _label; }
-	void setAlign(int align)		{ _align = align; }
-	int getAlign() const			{ return _align; }
+	void setLabel(const String &label) { _label = label; }
+	const String &getLabel() const     { return _label; }
+	void setAlign(int align)           { _align = align; }
+	int getAlign() const               { return _align; }
 
 protected:
 	void drawWidget(bool hilite);
@@ -140,8 +142,7 @@
 	uint32			_cmd;
 	uint8			_hotkey;
 public:
-	ButtonWidget(Dialog *boss, int x, int y, int w, int h, const char *label, uint32 cmd = 0, uint8 hotkey = 0);
-	virtual ~ButtonWidget();
+	ButtonWidget(Dialog *boss, int x, int y, int w, int h, const String &label, uint32 cmd = 0, uint8 hotkey = 0);
 
 	void setCmd(uint32 cmd)					{ _cmd = cmd; }
 	uint32 getCmd() const					{ return _cmd; }
@@ -156,7 +157,7 @@
 protected:
 	bool	_state;
 public:
-	CheckboxWidget(Dialog *boss, int x, int y, int w, int h, const char *label, uint32 cmd = 0, uint8 hotkey = 0);
+	CheckboxWidget(Dialog *boss, int x, int y, int w, int h, const String &label, uint32 cmd = 0, uint8 hotkey = 0);
 	void setState(bool state)	{ _state = state; }
 	bool getState() const		{ return _state; }
 
@@ -175,7 +176,7 @@
 	int		_valueMin, _valueMax;
 	bool	_isDragging;
 public:
-	SliderWidget(Dialog *boss, int x, int y, int w, int h, const char *label, uint32 cmd = 0, uint8 hotkey = 0);
+	SliderWidget(Dialog *boss, int x, int y, int w, int h, const String &label, uint32 cmd = 0, uint8 hotkey = 0);
 	void setValue(int value)	{ _value = value; }
 	int getValue() const		{ return _value; }
 





More information about the Scummvm-git-logs mailing list