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
29 #define IE_GUI_BUTTON 0
30 #define IE_GUI_PROGRESSBAR 1 //gemrb extension
31 #define IE_GUI_SLIDER 2
33 #define IE_GUI_TEXTAREA 5
34 #define IE_GUI_LABEL 6
35 #define IE_GUI_SCROLLBAR 7
36 #define IE_GUI_WORLDMAP 8 // gemrb extension
37 #define IE_GUI_MAP 9 // gemrb extension
38 #define IE_GUI_GAMECONTROL 128
39 #define IE_GUI_INVALID 255
41 #define IE_GUI_CONTROL_FOCUSED 0x80
43 //this is in the control ID
44 #define IGNORE_CONTROL 0x10000000
46 #include "RGBAColor.h"
53 class ControlAnimation
;
59 * Basic Control Object, also called widget or GUI element. Parent class for Labels, Buttons, etc.
60 * Every GUI element except of a Window is a descendant of this class.
63 class GEM_EXPORT Control
{
67 /** Draws the Control on the Output Display */
68 virtual void Draw(unsigned short x
, unsigned short y
) = 0;
69 /** Sets the Text of the current control */
70 virtual int SetText(const char* string
, int pos
= 0) = 0;
71 /** Sets the Tooltip text of the current control */
72 int SetTooltip(const char* string
);
73 /** Displays the tooltip text, Worldmap handles this differently */
74 virtual void DisplayTooltip();
75 /** Variable length is 40-1 (zero terminator) */
76 char VarName
[MAX_VARIABLE_LENGTH
];
77 /** the value of the control to add to the variable */
79 /** various flags based on the control type */
81 ControlAnimation
* animation
;
82 Sprite2D
* AnimPicture
;
84 public: // Public attributes
85 /** Defines the Control ID Number used for GUI Scripting */
87 /** X position of control relative to containing window */
89 /** Y position of control relative to containing window */
91 /** Width of control */
93 /** Height of control */
95 /** Type of control */
97 /** Text to display as a tooltip when the mouse cursor hovers
98 * for some time over the control */
100 /** Focused Control */
102 /** If true, control is redrawn during next call to gc->DrawWindows.
103 * Then it's set back to false. */
105 /** True if we are currently in an event handler */
109 /** Attached Scroll Bar Pointer*/
112 /** Reset/init event handler */
113 void ResetEventHandler(EventHandler handler
);
114 /** Returns the Owner */
115 Window
*GetOwner() const { return Owner
; }
117 int SetFlags(int arg_flags
, int opcode
);
118 /** Set handler for specified event. Override in child classes */
119 virtual bool SetEvent(int eventType
, EventHandler handler
) = 0;
120 /** Run specified handler, it may return error code */
121 int RunEventHandler(EventHandler handler
);
122 /** Key Press Event */
123 virtual void OnKeyPress(unsigned char Key
, unsigned short Mod
);
124 /** Key Release Event */
125 virtual void OnKeyRelease(unsigned char Key
, unsigned short Mod
);
126 /** Mouse Enter Event */
127 virtual void OnMouseEnter(unsigned short x
, unsigned short y
);
128 /** Mouse Leave Event */
129 virtual void OnMouseLeave(unsigned short x
, unsigned short y
);
130 /** Mouse Over Event */
131 virtual void OnMouseOver(unsigned short x
, unsigned short y
);
132 /** Mouse Button Down */
133 virtual void OnMouseDown(unsigned short x
, unsigned short y
,
134 unsigned short Button
, unsigned short Mod
);
135 /** Mouse Button Up */
136 virtual void OnMouseUp(unsigned short x
, unsigned short y
,
137 unsigned short Button
, unsigned short Mod
);
138 /** Special Key Press */
139 virtual void OnSpecialKeyPress(unsigned char Key
);
140 virtual bool IsPixelTransparent(unsigned short /*x*/, unsigned short /*y*/) {
143 /** Sets the animation picture ref */
144 void SetAnimPicture(Sprite2D
* Picture
);
145 /** Sets the Scroll Bar Pointer */
146 int SetScrollBar(Control
* ptr
);