1 /* GemRB - Infinity Engine Emulator
2 * Copyright (C) 2003 The GemRB Project
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation; either version 2
7 * of the License, or (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
23 * Declares Control, root class for all widgets except of windows
34 #define IE_GUI_BUTTON 0
35 #define IE_GUI_PROGRESSBAR 1 //gemrb extension
36 #define IE_GUI_SLIDER 2
38 #define IE_GUI_TEXTAREA 5
39 #define IE_GUI_LABEL 6
40 #define IE_GUI_SCROLLBAR 7
41 #define IE_GUI_WORLDMAP 8 // gemrb extension
42 #define IE_GUI_MAP 9 // gemrb extension
43 #define IE_GUI_GAMECONTROL 128
44 #define IE_GUI_INVALID 255
46 #define IE_GUI_CONTROL_FOCUSED 0x80
48 //this is in the control ID
49 #define IGNORE_CONTROL 0x10000000
53 #include "RGBAColor.h"
57 * Event handler indicates code to be called when a particular
58 * (usually GUI) event occurs.
59 * Currently it's a name of a python function.
61 typedef char EventHandler
[64];
63 class ControlAnimation
;
69 * Basic Control Object, also called widget or GUI element. Parent class for Labels, Buttons, etc.
70 * Every GUI element except of a Window is a descendant of this class.
73 class GEM_EXPORT Control
{
77 /** Draws the Control on the Output Display */
78 virtual void Draw(unsigned short x
, unsigned short y
) = 0;
79 /** Sets the Text of the current control */
80 virtual int SetText(const char* string
, int pos
= 0) = 0;
81 /** Sets the Tooltip text of the current control */
82 int SetTooltip(const char* string
);
83 /** Displays the tooltip text, Worldmap handles this differently */
84 virtual void DisplayTooltip();
85 /** Variable length is 40-1 (zero terminator) */
86 char VarName
[MAX_VARIABLE_LENGTH
];
87 /** the value of the control to add to the variable */
89 /** various flags based on the control type */
91 ControlAnimation
* animation
;
92 Sprite2D
* AnimPicture
;
94 public: // Public attributes
95 /** Defines the Control ID Number used for GUI Scripting */
97 /** X position of control relative to containing window */
99 /** Y position of control relative to containing window */
101 /** Width of control */
103 /** Height of control */
105 /** Type of control */
107 /** Text to display as a tooltip when the mouse cursor hovers
108 * for some time over the control */
110 /** Focused Control */
112 /** If true, control is redrawn during next call to gc->DrawWindows.
113 * Then it's set back to false. */
115 /** True if we are currently in an event handler */
119 /** Attached Scroll Bar Pointer*/
122 /** Reset/init event handler */
123 void ResetEventHandler(EventHandler handler
);
124 /** Set handler from function name */
125 void SetEventHandler(EventHandler handler
, const char *funcName
);
126 /** Returns the Owner */
127 Window
*GetOwner() const { return Owner
; }
129 int SetFlags(int arg_flags
, int opcode
);
130 /** Set handler for specified event. Override in child classes */
131 virtual bool SetEvent(int eventType
, const char *handler
) = 0;
132 /** Run specified handler, it may return error code */
133 int RunEventHandler(EventHandler handler
);
134 /** Key Press Event */
135 virtual void OnKeyPress(unsigned char Key
, unsigned short Mod
);
136 /** Key Release Event */
137 virtual void OnKeyRelease(unsigned char Key
, unsigned short Mod
);
138 /** Mouse Enter Event */
139 virtual void OnMouseEnter(unsigned short x
, unsigned short y
);
140 /** Mouse Leave Event */
141 virtual void OnMouseLeave(unsigned short x
, unsigned short y
);
142 /** Mouse Over Event */
143 virtual void OnMouseOver(unsigned short x
, unsigned short y
);
144 /** Mouse Button Down */
145 virtual void OnMouseDown(unsigned short x
, unsigned short y
,
146 unsigned short Button
, unsigned short Mod
);
147 /** Mouse Button Up */
148 virtual void OnMouseUp(unsigned short x
, unsigned short y
,
149 unsigned short Button
, unsigned short Mod
);
150 /** Special Key Press */
151 virtual void OnSpecialKeyPress(unsigned char Key
);
152 virtual bool IsPixelTransparent(unsigned short /*x*/, unsigned short /*y*/) {
155 /** Sets the animation picture ref */
156 void SetAnimPicture(Sprite2D
* Picture
);
157 /** Sets the Scroll Bar Pointer */
158 int SetScrollBar(Control
* ptr
);