factored out the EFFv2 saving into EFFImporter
[gemrb.git] / gemrb / core / GUI / Control.h
blob50a5ad2d49d11fb55e7f992aae7ffdd5935dab83
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.
21 /**
22 * @file Control.h
23 * Declares Control, root class for all widgets except of windows
26 #ifndef CONTROL_H
27 #define CONTROL_H
29 #define IE_GUI_BUTTON 0
30 #define IE_GUI_PROGRESSBAR 1 //gemrb extension
31 #define IE_GUI_SLIDER 2
32 #define IE_GUI_EDIT 3
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"
47 #include "exports.h"
48 #include "ie_types.h"
49 #include "win32def.h"
51 #include "Callback.h"
53 class ControlAnimation;
54 class Sprite2D;
55 class Window;
57 /**
58 * @class Control
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 {
64 public:
65 Control();
66 virtual ~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 */
78 ieDword Value;
79 /** various flags based on the control type */
80 ieDword Flags;
81 ControlAnimation* animation;
82 Sprite2D* AnimPicture;
84 public: // Public attributes
85 /** Defines the Control ID Number used for GUI Scripting */
86 ieDword ControlID;
87 /** X position of control relative to containing window */
88 ieWord XPos;
89 /** Y position of control relative to containing window */
90 ieWord YPos;
91 /** Width of control */
92 ieWord Width;
93 /** Height of control */
94 ieWord Height;
95 /** Type of control */
96 ieByte ControlType;
97 /** Text to display as a tooltip when the mouse cursor hovers
98 * for some time over the control */
99 char* Tooltip;
100 /** Focused Control */
101 bool hasFocus;
102 /** If true, control is redrawn during next call to gc->DrawWindows.
103 * Then it's set back to false. */
104 bool Changed;
105 /** True if we are currently in an event handler */
106 bool InHandler;
107 /** Owner Window */
108 Window* Owner;
109 /** Attached Scroll Bar Pointer*/
110 Control* sb;
111 public: //Events
112 /** Reset/init event handler */
113 void ResetEventHandler(EventHandler handler);
114 /** Returns the Owner */
115 Window *GetOwner() const { return Owner; }
116 /** Set the Flags */
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*/) {
141 return false;
143 /** Sets the animation picture ref */
144 void SetAnimPicture(Sprite2D* Picture);
145 /** Sets the Scroll Bar Pointer */
146 int SetScrollBar(Control* ptr);
149 #endif