[Scummvm-cvs-logs] SF.net SVN: scummvm:[55099] scummvm/trunk/gui

sev at users.sourceforge.net sev at users.sourceforge.net
Mon Jan 3 13:23:50 CET 2011


Revision: 55099
          http://scummvm.svn.sourceforge.net/scummvm/?rev=55099&view=rev
Author:   sev
Date:     2011-01-03 12:23:50 +0000 (Mon, 03 Jan 2011)

Log Message:
-----------
GUI: Implement PicButtonWidget

It is a button with picture intead of text. To be used by Hugo engine

Modified Paths:
--------------
    scummvm/trunk/gui/widget.cpp
    scummvm/trunk/gui/widget.h

Modified: scummvm/trunk/gui/widget.cpp
===================================================================
--- scummvm/trunk/gui/widget.cpp	2011-01-03 11:36:39 UTC (rev 55098)
+++ scummvm/trunk/gui/widget.cpp	2011-01-03 12:23:50 UTC (rev 55099)
@@ -303,6 +303,54 @@
 
 #pragma mark -
 
+PicButtonWidget::PicButtonWidget(GuiObject *boss, int x, int y, int w, int h, const char *tooltip, uint32 cmd, uint8 hotkey)
+	: Widget(boss, x, y, w, h, tooltip), CommandSender(boss),
+	  _cmd(cmd), _hotkey(hotkey), _gfx(), _alpha(256), _transparency(false) {
+
+	setFlags(WIDGET_ENABLED/* | WIDGET_BORDER*/ | WIDGET_CLEARBG);
+	_type = kButtonWidget;
+}
+
+PicButtonWidget::PicButtonWidget(GuiObject *boss, const Common::String &name, const char *tooltip, uint32 cmd, uint8 hotkey)
+	: Widget(boss, name, tooltip), CommandSender(boss),
+	  _cmd(cmd), _gfx(), _alpha(256), _transparency(false) {
+	setFlags(WIDGET_ENABLED/* | WIDGET_BORDER*/ | WIDGET_CLEARBG);
+	_type = kButtonWidget;
+}
+
+void PicButtonWidget::handleMouseUp(int x, int y, int button, int clickCount) {
+	if (isEnabled() && x >= 0 && x < _w && y >= 0 && y < _h)
+		sendCommand(_cmd, 0);
+}
+
+void PicButtonWidget::setGfx(const Graphics::Surface *gfx) {
+	_gfx.free();
+
+	if (!gfx || !gfx->pixels)
+		return;
+
+	if (gfx->w > _w || gfx->h > _h) {
+		warning("PicButtonWidget has size %dx%d, but a surface with %dx%d is to be set", _w, _h, gfx->w, gfx->h);
+		return;
+	}
+
+	// TODO: add conversion to OverlayColor
+	_gfx.copyFrom(*gfx);
+}
+
+void PicButtonWidget::drawWidget() {
+	g_gui.theme()->drawButton(Common::Rect(_x, _y, _x+_w, _y+_h), "", _state, getFlags());
+
+	if (sizeof(OverlayColor) == _gfx.bytesPerPixel && _gfx.pixels) {
+		const int x = _x + (_w - _gfx.w) / 2;
+		const int y = _y + (_h - _gfx.h) / 2;
+
+		g_gui.theme()->drawSurface(Common::Rect(x, y, x + _gfx.w,  y + _gfx.h), _gfx, _state, _alpha, _transparency);
+	}
+}
+
+#pragma mark -
+
 CheckboxWidget::CheckboxWidget(GuiObject *boss, int x, int y, int w, int h, const Common::String &label, const char *tooltip, uint32 cmd, uint8 hotkey)
 	: ButtonWidget(boss, x, y, w, h, label, tooltip, cmd, hotkey), _state(false) {
 	setFlags(WIDGET_ENABLED);

Modified: scummvm/trunk/gui/widget.h
===================================================================
--- scummvm/trunk/gui/widget.h	2011-01-03 11:36:39 UTC (rev 55098)
+++ scummvm/trunk/gui/widget.h	2011-01-03 12:23:50 UTC (rev 55099)
@@ -198,6 +198,36 @@
 	void drawWidget();
 };
 
+/* PicButtonWidget */
+class PicButtonWidget : public Widget, public CommandSender {
+	friend class Dialog;	// Needed for the hotkey handling
+protected:
+	uint32	_cmd;
+	uint8	_hotkey;
+public:
+	PicButtonWidget(GuiObject *boss, int x, int y, int w, int h, const char *tooltip = 0, uint32 cmd = 0, uint8 hotkey = 0);
+	PicButtonWidget(GuiObject *boss, const Common::String &name, const char *tooltip = 0, uint32 cmd = 0, uint8 hotkey = 0);
+
+	void setCmd(uint32 cmd)				{ _cmd = cmd; }
+	uint32 getCmd() const				{ return _cmd; }
+
+	void setGfx(const Graphics::Surface *gfx);
+
+	void useAlpha(int alpha) { _alpha = alpha; }
+	void useThemeTransparency(bool enable) { _transparency = enable; }
+
+	void handleMouseUp(int x, int y, int button, int clickCount);
+	void handleMouseEntered(int button)	{ setFlags(WIDGET_HILITED); draw(); }
+	void handleMouseLeft(int button)	{ clearFlags(WIDGET_HILITED); draw(); }
+
+protected:
+	void drawWidget();
+
+	Graphics::Surface _gfx;
+	int _alpha;
+	bool _transparency;
+};
+
 /* CheckboxWidget */
 class CheckboxWidget : public ButtonWidget {
 protected:


This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.




More information about the Scummvm-git-logs mailing list