ScummVM API documentation
Widget.h
1 /* ScummVM - Graphic Adventure Engine
2  *
3  * ScummVM is the legal property of its developers, whose names
4  * are too numerous to list here. Please refer to the COPYRIGHT
5  * file distributed with this source distribution.
6  *
7  * This program is free software: you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation, either version 3 of the License, or
10  * (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program. If not, see <http://www.gnu.org/licenses/>.
19  *
20  */
21 
22 /*
23  * Copyright (C) 2006-2010 - Frictional Games
24  *
25  * This file is part of HPL1 Engine.
26  */
27 
28 #ifndef HPL_WIDGET_H
29 #define HPL_WIDGET_H
30 
31 #include "common/array.h"
32 #include "common/list.h"
33 #include "hpl1/engine/gui/GuiTypes.h"
34 #include "hpl1/engine/system/low_level_system.h"
35 
36 namespace hpl {
37 
38 class cGui;
39 class cGuiSet;
40 class cGuiSkin;
41 class cGuiSkinFont;
42 
43 class cGuiGfxElement;
44 class cGuiClipRegion;
45 
46 class FontData;
47 
48 //--------------------------------
49 
51  cWidgetCallback(void *apObject, tGuiCallbackFunc apFunc) {
52  mpObject = apObject;
53  mpFunc = apFunc;
54  }
55 
56  void *mpObject;
57  tGuiCallbackFunc mpFunc;
58 };
59 
62 
63 //--------------------------------
64 
65 class iWidget {
66  friend class cGuiSet;
67 
68 public:
69  iWidget(eWidgetType aType, cGuiSet *apSet, cGuiSkin *apSkin);
70  virtual ~iWidget();
71 
73  // General
74  void Update(float afTimeStep);
75 
76  void Draw(float afTimeStep, cGuiClipRegion *apClipRegion);
77 
78  bool ProcessMessage(eGuiMessage aMessage, cGuiMessageData &aData);
79 
80  void AddCallback(eGuiMessage aMessage, void *apObject, tGuiCallbackFunc apFunc);
81 
82  eWidgetType GetType() { return mType; }
83 
84  void Init();
85 
87  // Public Helper functions
88  bool PointIsInside(const cVector2f &avPoint, bool abOnlyClipped);
89 
91  // Hierarchy
92  void AttachChild(iWidget *apChild);
93  void RemoveChild(iWidget *apChild);
94 
96  // Properties
97  cGuiSet *GetSet() { return mpSet; }
98 
99  iWidget *GetParent() { return mpParent; }
100 
101  void SetEnabled(bool abX);
102  bool IsEnabled();
103  void SetVisible(bool abX);
104  bool IsVisible();
105 
106  bool HasFocus();
107 
108  void SetName(const tString &asName) { msName = asName; }
109  const tString &GetName() { return msName; }
110 
111  void SetText(const tWString &asText);
112  const tWString &GetText() { return msText; }
113 
114  FontData *GetDefaultFontType() { return mpDefaultFontType; }
115  void SetDefaultFontType(FontData *apFont) { mpDefaultFontType = apFont; }
116 
117  const cColor &GetDefaultFontColor() { return mDefaultFontColor; }
118  void SetDefaultFontColor(const cColor &aColor) { mDefaultFontColor = aColor; }
119 
120  const cVector2f &GetDefaultFontSize() { return mvDefaultFontSize; }
121  void SetDefaultFontSize(const cVector2f &avSize) { mvDefaultFontSize = avSize; }
122 
123  void SetClipActive(bool abX) { mbClipsGraphics = abX; }
124  bool GetClipActive() { return mbClipsGraphics; }
125 
126  void SetPosition(const cVector3f &avPos);
127  void SetGlobalPosition(const cVector3f &avPos);
128  const cVector3f &GetLocalPosition();
129  const cVector3f &GetGlobalPosition();
130 
131  void SetSize(const cVector2f &avSize);
132  cVector2f GetSize() { return mvSize; }
133 
134  bool ClipsGraphics();
135 
136  bool GetMouseIsOver() { return mbMouseIsOver; }
137 
138  bool IsConnectedTo(iWidget *apWidget, bool abIsStartWidget = true);
139  bool IsConnectedToChildren() { return mbConnectedToChildren; }
140  void SetConnectedToChildren(bool abX) { mbConnectedToChildren = abX; }
141 
142  cGuiGfxElement *GetPointerGfx();
143 
144 protected:
146  // Upper Widget functions
147  virtual void OnLoadGraphics() {}
148 
149  virtual void OnChangeSize() {}
150  virtual void OnChangePosition() {}
151  virtual void OnChangeText() {}
152 
153  virtual void OnInit() {}
154 
155  virtual void OnDraw(float afTimeStep, cGuiClipRegion *apClipRegion) {}
156  virtual void OnDrawAfterClip(float afTimeStep, cGuiClipRegion *apClipRegion) {}
157 
158  virtual void OnUpdate(float afTimeStep) {}
159 
160  virtual bool OnMessage(eGuiMessage aMessage, cGuiMessageData &aData) { return false; }
161  virtual bool OnMouseMove(cGuiMessageData &aData) { return false; }
162  virtual bool OnMouseDown(cGuiMessageData &aData) { return false; }
163  virtual bool OnMouseUp(cGuiMessageData &aData) { return false; }
164  virtual bool OnMouseDoubleClick(cGuiMessageData &aData) { return false; }
165  virtual bool OnMouseEnter(cGuiMessageData &aData) { return false; }
166  virtual bool OnMouseLeave(cGuiMessageData &aData) { return false; }
167 
168  virtual bool OnGotFocus(cGuiMessageData &aData);
169  virtual bool OnLostFocus(cGuiMessageData &aData) { return false; }
170 
171  virtual bool OnKeyPress(cGuiMessageData &aData) { return false; }
172 
174  // Private Helper functions
175  cVector3f WorldToLocalPosition(const cVector3f &avPos);
176  cVector2f GetPosRelativeToMouse(cGuiMessageData &aData);
177 
178  // The order must be like this:
179  // Borders: Right, Left, Up and Down
180  // Corners: LEftUp, RightUp, RightDown and LEftDown.
181  void DrawBordersAndCorners(cGuiGfxElement *apBackground,
182  cGuiGfxElement **apBorderVec, cGuiGfxElement **apCornerVec,
183  const cVector3f &avPosition, const cVector2f &avSize);
184 
185  void DrawSkinText(const tWString &asText, eGuiSkinFont aFont, const cVector3f &avPosition,
186  eFontAlign aAlign = eFontAlign_Left);
187 
188  void DrawDefaultText(const tWString &asText,
189  const cVector3f &avPosition, eFontAlign aAlign);
190 
191  void SetPositionUpdated();
192 
193  void LoadGraphics();
194 
196  // Variables
197  cGuiSet *mpSet;
198  cGuiSkin *mpSkin;
199  cGui *mpGui;
200 
201  tWString msText;
202  cVector3f mvPosition;
203  cVector3f mvGlobalPosition;
204  cVector2f mvSize;
205 
206  tString msName;
207 
208  eWidgetType mType;
209 
210  int mlPositionCount;
211 
212  cGuiSkinFont *mpDefaultFont;
213  FontData *mpDefaultFontType;
214  cColor mDefaultFontColor;
215  cVector2f mvDefaultFontSize;
216 
217  iWidget *mpParent;
218 
219  tWidgetList mlstChildren;
220 
221  bool mbEnabled;
222  bool mbVisible;
223 
224  bool mbMouseIsOver;
225 
226  bool mbClipsGraphics;
227 
228  cGuiGfxElement *mpPointerGfx;
229 
230  bool mbConnectedToChildren;
231 
232 private:
233  void SetMouseIsOver(bool abX) { mbMouseIsOver = abX; }
234  bool ProcessCallbacks(eGuiMessage aMessage, cGuiMessageData &aData);
235 
236  Common::Array<tWidgetCallbackList> mvCallbackLists;
237 
238  bool mbPositionIsUpdated;
239 };
240 
241 } // namespace hpl
242 
243 #endif // HPL_WIDGET_H
Definition: AI.h:36
Definition: Gui.h:73
Definition: GuiGfxElement.h:72
Definition: str.h:59
Definition: array.h:52
Definition: font_data.h:67
Definition: list.h:44
Definition: GuiTypes.h:263
Definition: GuiSkin.h:43
Definition: Widget.h:50
Definition: ustr.h:57
Definition: Widget.h:65
Definition: GuiSet.h:112
Definition: GuiSet.h:96
Definition: GuiSkin.h:59
Definition: Color.h:37
Definition: list_intern.h:51