Move EventMgr to GUI.
[gemrb.git] / gemrb / core / GUI / Window.h
bloba4798ddee4d9782803d6f7a13f264fcd86184c44
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 Window.h
23 * Declares Window, class serving as a container for Control/widget objects
24 * and displaying windows in GUI
25 * @author The GemRB Project
28 #ifndef WINDOW_H
29 #define WINDOW_H
31 #include "GUI/Control.h"
32 #include "GUI/ScrollBar.h"
33 #include "GUI/TextArea.h"
35 #include "exports.h"
37 #include "Sprite2D.h"
39 #include <vector>
41 // Window Flags
42 #define WF_CHANGED 1 //window changed
43 #define WF_FRAME 2 //window has frame
44 #define WF_FLOAT 4 //floating window
45 #define WF_CHILD 8 //if invalidated, it invalidates all windows on top of it
47 // Window position anchors (actually flags for WindowSetPos())
48 // !!! Keep these synchronized with GUIDefines.py !!!
49 #define WINDOW_TOPLEFT 0x00
50 #define WINDOW_CENTER 0x01
51 #define WINDOW_ABSCENTER 0x02
52 #define WINDOW_RELATIVE 0x04
53 #define WINDOW_SCALE 0x08
54 #define WINDOW_BOUNDED 0x10
56 // IE specific cursor types
58 #define IE_CURSOR_INVALID -1
59 #define IE_CURSOR_NORMAL 0
60 #define IE_CURSOR_TAKE 2 //over pile type containers
61 #define IE_CURSOR_WALK 4
62 #define IE_CURSOR_BLOCKED 6
63 #define IE_CURSOR_USE 8 //never hardcoded
64 #define IE_CURSOR_WAIT 10 //hourglass
65 #define IE_CURSOR_ATTACK 12
66 #define IE_CURSOR_SWAP 14 //dragging portraits
67 #define IE_CURSOR_DEFEND 16
68 #define IE_CURSOR_TALK 18
69 #define IE_CURSOR_CAST 20 //targeting with non weapon
70 #define IE_CURSOR_INFO 22 //never hardcoded
71 #define IE_CURSOR_LOCK 24 //locked door
72 #define IE_CURSOR_LOCK2 26 //locked container
73 #define IE_CURSOR_STAIR 28 //never hardcoded
74 #define IE_CURSOR_DOOR 30 //doors
75 #define IE_CURSOR_CHEST 32
76 #define IE_CURSOR_TRAVEL 34
77 #define IE_CURSOR_STEALTH 36
78 #define IE_CURSOR_TRAP 38
79 #define IE_CURSOR_PICK 40 //pickpocket
80 #define IE_CURSOR_PASS 42 //never hardcoded
81 #define IE_CURSOR_GRAB 44
82 #define IE_CURSOR_WAY 46 //waypoint (not in PST)
83 #define IE_CURSOR_INFO2 46 //PST
84 #define IE_CURSOR_PORTAL 48 //PST
85 #define IE_CURSOR_STAIR2 50 //PST
86 #define IE_CURSOR_EXTRA 52 //PST
88 #define IE_CURSOR_MASK 127
89 #define IE_CURSOR_GRAY 128
90 /**
91 * @class Window
92 * Class serving as a container for Control/widget objects
93 * and displaying windows in GUI.
96 class GEM_EXPORT Window {
97 public:
98 Window(unsigned short WindowID, unsigned short XPos, unsigned short YPos,
99 unsigned short Width, unsigned short Height);
100 ~Window();
101 /** Set the Window's BackGround Image.
102 * If 'img' is NULL, no background will be set. If the 'clean' parameter is true (default is false) the old background image will be deleted. */
103 void SetBackGround(Sprite2D* img, bool clean = false);
104 /** Add a Control in the Window */
105 void AddControl(Control* ctrl);
106 /** This function Draws the Window on the Output Screen */
107 void DrawWindow();
108 /** Set window frame used to fill screen on higher resolutions*/
109 void SetFrame();
110 /** Returns the Control at X,Y Coordinates */
111 Control* GetControl(unsigned short x, unsigned short y, bool ignore=0);
112 /** Returns the Control by Index */
113 Control* GetControl(unsigned short i) const;
114 /** Returns the number of Controls */
115 unsigned int GetControlCount() const;
116 /** Returns true if ctrl is valid and ctrl->ControlID is ID */
117 bool IsValidControl(unsigned short ID, Control *ctrl) const;
118 /** Deletes the xth. Control */
119 void DelControl(unsigned short i);
120 /** Returns the Default Control which may be a button/gamecontrol atm */
121 Control* GetDefaultControl(unsigned int ctrltype) const;
122 /** Returns the Control which should get mouse scroll events */
123 Control* GetScrollControl() const;
124 /** Sets 'ctrl' as currently under mouse */
125 void SetOver(Control* ctrl);
126 /** Returns last control under mouse */
127 Control* GetOver() const;
128 /** Sets 'ctrl' as Focused */
129 void SetFocused(Control* ctrl);
130 /** Sets 'ctrl' as mouse event Focused */
131 void SetMouseFocused(Control* ctrl);
132 /** Returns last focused control */
133 Control* GetFocus() const;
134 /** Returns last mouse event focused control */
135 Control* GetMouseFocus() const;
136 /** Redraw all the Window */
137 void Invalidate();
138 /** Redraw enough to update the specified Control */
139 void InvalidateForControl(Control *ctrl);
140 /** Redraw controls of the same group */
141 void RedrawControls(const char* VarName, unsigned int Sum);
142 /** Links a scrollbar to a text area */
143 void Link(unsigned short SBID, unsigned short TAID);
144 /** Mouse entered a new control's rectangle */
145 void OnMouseEnter(unsigned short x, unsigned short y, Control *ctrl);
146 /** Mouse left the current control */
147 void OnMouseLeave(unsigned short x, unsigned short y);
148 /** Mouse is over the current control */
149 void OnMouseOver(unsigned short x, unsigned short y);
150 public: //Public attributes
151 /** WinPack */
152 char WindowPack[10];
153 /** Window ID */
154 unsigned short WindowID;
155 /** X Position */
156 unsigned short XPos;
157 /** Y Position */
158 unsigned short YPos;
159 /** Width */
160 unsigned short Width;
161 /** Height */
162 unsigned short Height;
163 /** Visible value: deleted, invisible, visible, grayed */
164 signed char Visible; //-1,0,1,2
165 /** Window flags: Changed, Floating, Framed, Child */
166 int Flags;
167 int Cursor;
168 int DefaultControl[2]; //default enter and cancel
169 int ScrollControl;
170 private: // Private attributes
171 /** BackGround Image. No BackGround if this variable is NULL. */
172 Sprite2D* BackGround;
173 /** Controls Array */
174 std::vector< Control*> Controls;
175 /** Last Control returned by GetControl */
176 Control* lastC;
177 /** Last Focused Control */
178 Control* lastFocus;
179 /** Last mouse event Focused Control */
180 Control* lastMouseFocus;
181 /** Last Control under mouse */
182 Control* lastOver;
183 /** Regions which need to be redrawn */
184 std::vector< Region> clip_regions;
186 public:
187 void release(void);
190 #endif