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 Window, class serving as a container for Control/widget objects
24 * and displaying windows in GUI
25 * @author The GemRB Project
31 #include "GUI/Control.h"
32 #include "GUI/ScrollBar.h"
33 #include "GUI/TextArea.h"
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
92 * Class serving as a container for Control/widget objects
93 * and displaying windows in GUI.
96 class GEM_EXPORT Window
{
98 Window(unsigned short WindowID
, unsigned short XPos
, unsigned short YPos
,
99 unsigned short Width
, unsigned short Height
);
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 */
108 /** Set window frame used to fill screen on higher resolutions*/
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 */
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
154 unsigned short WindowID
;
160 unsigned short Width
;
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 */
168 int DefaultControl
[2]; //default enter and cancel
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 */
177 /** Last Focused Control */
179 /** Last mouse event Focused Control */
180 Control
* lastMouseFocus
;
181 /** Last Control under mouse */
183 /** Regions which need to be redrawn */
184 std::vector
< Region
> clip_regions
;