OpenMoHAA 0.82.1
Loading...
Searching...
No Matches
uiwidget.h
1/*
2===========================================================================
3Copyright (C) 2015 the OpenMoHAA team
4
5This file is part of OpenMoHAA source code.
6
7OpenMoHAA source code is free software; you can redistribute it
8and/or modify it under the terms of the GNU General Public License as
9published by the Free Software Foundation; either version 2 of the License,
10or (at your option) any later version.
11
12OpenMoHAA source code is distributed in the hope that it will be
13useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
14MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15GNU General Public License for more details.
16
17You should have received a copy of the GNU General Public License
18along with OpenMoHAA source code; if not, write to the Free Software
19Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
20===========================================================================
21*/
22
23#pragma once
24
25#include "usignal.h"
26#include "../qcommon/q_shared.h"
27#include "../qcommon/str.h"
28#include "ui_public.h"
29#include "uirect2d.h"
30#include "ucolor.h"
31#include "uifont.h"
32
33class UIFont;
34
35class UIReggedMaterial
36{
37 uihandle_t hMat;
38 str name;
39 bool isSet;
40 bool isGot;
41
42public:
43 UIReggedMaterial();
44
45 uihandle_t GetMaterial(void);
46 void ReregisterMaterial(void);
47 void CleanupMaterial(void);
48 void SetMaterial(const str& name);
49 void RefreshMaterial(void);
50 str GetName(void);
51};
52
53// widget flags
54#define WF_STRETCH_VERTICAL (1 << 0)
55#define WF_STRETCH_HORIZONTAL (1 << 1)
56#define WF_DIRECTED (1 << 2)
57#define WF_TILESHADER (1 << 3)
58#define WF_ALWAYS_BOTTOM (1 << 4)
59#define WF_ALWAYS_TOP (1 << 5)
60#define WF_NOPARENTADJUST (1 << 6)
61#define WF_DONTLOCALIZE (1 << 7)
62
63// widget alignment flags
64#define WA_LEFT (1 << 0)
65#define WA_RIGHT (1 << 1)
66#define WA_TOP (1 << 3)
67#define WA_BOTTOM (1 << 4)
68#define WA_CENTERX (1 << 5)
69#define WA_CENTERY (1 << 6)
70#define WA_FULL (WA_LEFT | WA_RIGHT | WA_TOP | WA_BOTTOM | WA_CENTERX | WA_CENTERY)
71
73
74typedef enum {
75 border_none,
76 border_3D,
77 border_indent,
78 border_outline
79} borderstyle_t;
80
81typedef enum {
82 D_NONE,
83 D_FROM_LEFT,
84 D_FROM_RIGHT,
85 D_FROM_BOTTOM,
86 D_FROM_TOP
87} direction_t;
88
89typedef enum {
90 MOTION_IN,
91 MOTION_OUT
92} motion_t;
93
94typedef enum {
95 SEQUENCE_NONE,
96 SEQUENCE_STARTING,
97 SEQUENCE_FADEIN,
98 SEQUENCE_HOLD,
99 SEQUENCE_FADEOUT
100} fadesequence_t;
101
102class UIWidget : public USignal
103{
104 friend class Menu;
105 friend class UILayout;
106 friend class UIWindowManager;
107
108protected:
109 UIRect2D m_frame;
110 vec2_t m_vVirtualScale;
111 UIPoint2D m_startingpos;
112 UIPoint2D m_origin;
113 UIRect2D m_screenframe;
114 UIPoint2D m_screenorigin;
115 UIRect2D m_clippedframe;
116 UIPoint2D m_clippedorigin;
117 UColor m_background_color;
118 UColor m_foreground_color;
119 UBorderColor m_border_color;
120 borderstyle_t m_borderStyle;
121 bool m_visible;
122 bool m_enabled;
123 UIFont *m_font;
124 class UIWidget *m_parent;
125 Container<UIWidget *> m_children;
126 str m_name;
127 bool m_canactivate;
128 str m_cvarname;
129 str m_cvarvalue;
130 str m_command;
131 Container<str *> m_showcommands;
132 Container<str *> m_hidecommands;
133 str m_title;
134 float m_indent;
135 float m_bottomindent;
136 UIReggedMaterial *m_material;
137 UIReggedMaterial *m_hovermaterial;
138 UIReggedMaterial *m_pressedmaterial;
139 bool m_hovermaterial_active;
140 bool m_pressedmaterial_active;
141 direction_t m_direction;
142 direction_t m_direction_orig;
143 motion_t m_motiontype;
144 float m_starttime;
145 float m_fadetime;
146 float m_alpha;
147 float m_local_alpha;
148 float m_motiontime;
149 float m_fadeSequenceDelay;
150 float m_fadeSequenceFadeIn;
151 float m_fadeSequenceHold;
152 float m_fadeSequenceFadeOut;
153 float m_fadeSequenceRemainingTime;
154 float m_fadeSequenceLastTime;
155 int m_fadeSequenceState;
156 str m_stopsound;
157 str m_clicksound;
158 int m_align;
159 int m_flags;
160 bool m_dying;
161 int m_ordernum;
162 int m_configstring_index;
163 fonthorzjustify_t m_iFontAlignmentHorizontal;
164 fontvertjustify_t m_iFontAlignmentVertical;
165 qboolean m_bVirtual;
166 str m_enabledCvar;
167 //
168 // New since 2.0
169 //
170 cvar_t *m_scaleCvar;
171
172public:
173 CLASS_PROTOTYPE(UIWidget);
174
175 void (*m_commandhandler)(const char *, void *);
176
177protected:
178 bool addChild(UIWidget *widget);
179 bool removeChild(UIWidget *widget);
180 void PropogateCoordinateSystem(void);
181 void set2D(void);
182 virtual void Draw(void);
183 virtual void FrameInitialized(void);
184 void DrawTitle(float x, float y);
185 void Motion(void);
186 virtual void AlignPosition(void);
187 void Hide(Event *ev);
188 void Activate(Event *ev);
189 void BringToFront(void);
190 static void SplitWidgets(
192 Container<UIWidget *>& bottom,
193 Container<UIWidget *>& normal,
195 );
196 static void CombineWidgets(
198 Container<UIWidget *>& bottom,
199 Container<UIWidget *>& normal,
201 );
202 static void ArrangeWidgetList(Container<UIWidget *>& list);
203
204public:
205 UIWidget();
206 virtual ~UIWidget();
207
208 virtual void Shutdown(void);
209 virtual void InitFrame(
210 UIWidget *parentview,
211 float x,
212 float y,
213 float width,
214 float height,
215 int border = -1,
216 const char *fontname = "verdana-12"
217 );
218 void InitFrame(UIWidget *parentview, const UIRect2D& r, int border, const char *fontname = "verdana-12");
219 void LayoutSize(Event *ev);
220 void LayoutRect(Event *ev);
221 void LayoutName(Event *ev);
222 void LayoutTitle(Event *ev);
223 void LayoutFont(Event *ev);
224 void LayoutBgColor(Event *ev);
225 void LayoutFgColor(Event *ev);
226 void LayoutBorderStyle(Event *ev);
227 void LayoutBorderColor(Event *ev);
228 void LayoutShader(Event *ev);
229 void LayoutTileShader(Event *ev);
230 void LayoutHoverShader(Event *ev);
231 void LayoutPressedShader(Event *ev);
232 void LayoutFadeIn(Event *ev);
233 void LayoutStopSound(Event *ev);
234 void LayoutClickSound(Event *ev);
235 void LayoutStretch(Event *ev);
236 void LayoutVirtualRes(Event *ev);
237 void LayoutInitData(Event *ev);
238 void LayoutDirection(Event *ev);
239 void LayoutAlign(Event *ev);
240 void LayoutStuffCommand(Event *ev);
241 void LayoutLinkCvar(Event *ev);
242 void LayoutNoParentClipping(Event *ev);
243 void LayoutNoParentAdjustment(Event *ev);
244 void LayoutOrderNumber(Event *ev);
245 void TextAlignment(Event *ev);
246 void LayoutAliasCache(Event *ev);
247 void SetEnabledCvar(Event *ev);
248 void SetScaleCvar(Event *ev);
249
250 // Added in 2.0
251 //====
252 void SetDontLocalize(Event *ev);
253 void EventFadeSequence(Event *ev);
254 //====
255
256 void SetVirtualScale(vec2_t out);
257 void SetDontLocalize();
258 void setParent(UIWidget *parent);
259 class UIWidget *getParent(void);
260 class UIWidget *getFirstChild(void);
261 class UIWidget *getNextSibling(void);
262 class UIWidget *getNextChild(UIWidget *child);
263 class UIWidget *getPrevChild(UIWidget *child);
264 class UIWidget *getPrevSibling(void);
265 class UIWidget *getPrevSibling(UIWidget *curr);
266 class UIWidget *getLastSibling(void);
267 class UIWidget *findSibling(str name);
268
269 void Enable(void);
270 void Disable(void);
271 bool isEnabled(void);
272 bool IsDying(void);
273 class UIWidget *FindResponder(const UIPoint2D& pos);
274 void setFont(const char *name);
275 void setFontHorizontalAlignment(fonthorzjustify_t alignment);
276 void setFontVerticalAlignment(fontvertjustify_t alignment);
277 void setShow(bool visible);
278 bool getShow(void);
279 class UColor getBackgroundColor(void);
280 virtual void setBackgroundColor(const UColor& color, bool setbordercolor);
281 class UBorderColor getBorderColor(void);
282 void setBorderColor(const UBorderColor& color);
283 class UColor getForegroundColor(void);
284 virtual void setForegroundColor(const UColor& color);
285 borderstyle_t getBorderStyle(void);
286 void setBorderStyle(borderstyle_t style);
287 class UISize2D getSize(void);
288 void setSize(const UISize2D& newsize);
289 class UIRect2D getFrame(void);
290 void setFrame(const UIRect2D& newframe);
291 class UIPoint2D getOrigin(void);
292 void setOrigin(const UIPoint2D& neworigin);
293 void setName(str name);
294 const char *getName(void);
295 void setTitle(str title);
296 const char *getTitle(void);
297 void setDirection(direction_t dir);
298 direction_t getDirection(void);
299 void setMotionType(motion_t type);
300 motion_t getMotionType(void);
301 void setMotionTime(float time);
302 float getMotionTime(void);
303 void setAlign(int align);
304 int getAlign(void);
305 void setMaterial(UIReggedMaterial *mat);
306 void setHoverMaterial(UIReggedMaterial *mat);
307 void setPressedMaterial(UIReggedMaterial *mat);
308 class UIPoint2D getLocalPoint(const UIPoint2D& pos);
309 class UIPoint2D getGlobalPoint(const UIPoint2D& pos);
310 virtual void setBackgroundAlpha(float f);
311 float getBackgroundAlpha(void);
312 void Display(const UIRect2D& drawframe, float parent_alpha);
313 virtual qboolean KeyEvent(int key, unsigned int time);
314 virtual void CharEvent(int ch);
315 virtual void UpdateData(void);
316 virtual void UpdateUIElement(void);
317 float getTitleWidth(void);
318 float getTitleHeight(void);
319 bool CanActivate(void);
320 void AllowActivate(bool canactivate);
321 bool IsActive(void);
322 bool IsVisible(void);
323 virtual void LinkCvar(str cvarname);
324 void LinkCommand(str cmd);
325 void ExecuteShowCommands(void);
326 void ExecuteHideCommands(void);
327 void InitializeCommandHandler(void (*fcn)(const char *, void *));
328 class UIWidget *FindWidget(str name);
329 void ResetMotion(motion_t type);
330 virtual void Realign(void);
331 void BringToFrontPropogated(void);
332 class UIWidget *IsThisOrChildActive(void);
333 class UIPoint2D MouseEventToClientPoint(Event *ev);
334 class UIRect2D getClientFrame(void);
335 void setAlwaysOnBottom(bool b);
336 void setAlwaysOnTop(bool b);
337 bool getAlwaysOnBottom(void);
338 bool getAlwaysOnTop(void);
339 bool SendSignal(Event& event);
340 void ShowCommand(Event *ev);
341 void HideCommand(Event *ev);
342 void AddFlag(int flag);
343 void SetHovermaterialActive(bool a);
344 void SetPressedmaterialActive(bool a);
345 int getOrderNum(void);
346 class str getCommand(void);
347 void ActivateOrder(void);
348 void EnableEvent(Event *ev);
349 void DisableEvent(Event *ev);
350 void setConfigstringIndex(int cs);
351 int getConfigstringIndex(void);
352 bool PassEventToWidget(str name, Event *ev);
353
354 // Added in OPM
355 UIFont *getFont() const;
356 bool isVirtual() const;
357 const vec2_t& getVirtualScale() const;
358 const vec2_t& getHighResScale() const;
359};
360
361class UIWidgetContainer : public UIWidget
362{
363 UColor m_bgfill;
364 qboolean m_fullscreen;
365 int m_vidmode;
366 int m_currentwidnum;
367 int m_maxordernum;
368
369public:
370 class UILayout *m_layout;
371
372 CLASS_PROTOTYPE(UIWidgetContainer);
373
374private:
375 void AlignPosition(void) override;
376 void Draw(void) override;
377
378public:
379 UIWidgetContainer();
380
381 void Realign(void) override;
382 void SetBGFill(Event *ev);
383 void SetFullscreen(Event *ev);
384 void SetVidMode(Event *ev);
385 int getVidMode(void);
386 qboolean isFullscreen(void);
387 UIWidget *GetNextWidgetInOrder(void);
388 UIWidget *GetPrevWidgetInOrder(void);
389 void SetActiveWidgetOrderNum(UIWidget *wid);
390 void SetActiveWidgetOrderNum(int num);
391 void SetLastActiveWidgetOrderNum(void);
392};
393
394extern Event W_Destroyed;
395extern Event W_SizeChanged;
396extern Event W_FrameChanged;
397extern Event W_OriginChanged;
398extern Event W_Activated;
399extern Event EV_Widget_Activate;
400extern Event W_Deactivated;
401extern Event EV_Widget_Hide;
402extern Event EV_Widget_Enable;
403extern Event EV_Widget_Disable;
404extern Event W_RealignWidget;
405extern Event W_Draw;
406extern Event EV_Layout_Size;
407extern Event EV_Layout_Rect;
408extern Event EV_Layout_Name;
409extern Event EV_Layout_Title;
410extern Event EV_Layout_Font;
411extern Event EV_Layout_BGColor;
412extern Event EV_Layout_FGColor;
413extern Event EV_Layout_Borderstyle;
414extern Event EV_Layout_BorderColor;
415extern Event EV_Layout_Shader;
416extern Event EV_Layout_TileShader;
417extern Event EV_Layout_HoverShader;
418extern Event EV_Layout_PressedShader;
419extern Event EV_Layout_FadeIn;
420extern Event EV_Layout_StopSound;
421extern Event EV_Layout_ClickSound;
422extern Event EV_Layout_Stretch;
423extern Event EV_Layout_VirtualRes;
424extern Event EV_Layout_InitData;
425extern Event EV_Layout_Direction;
426extern Event EV_Layout_Align;
427extern Event EV_Layout_StuffCommand;
428extern Event EV_Layout_LinkCvar;
429extern Event EV_Layout_NoParentClipping;
430extern Event EV_Layout_NoParentAdjustment;
431extern Event EV_Widget_HideCommand;
432extern Event EV_Widget_ShowCommand;
433extern Event EV_Widget_OrderNumber;
434extern Event EV_Widget_TextAlignment;
435extern Event EV_Widget_EnabledCvar;
436extern Event EV_Layout_AliasCache;
437extern Event EV_Layout_BGFill;
438extern Event EV_Layout_Fullscreen;
439extern Event EV_Layout_VidMode;
440
441void SetColor(const UColor& color, float alpha);
442void DrawBox(const UIRect2D& rect, const UColor& color, float alpha);
443void Draw3DBox(const UIRect2D& rect, bool indent, const UBorderColor& color, float alpha);
444void DrawBox(float x, float y, float width, float height, const UColor& color, float alpha);
445void Draw3DBox(float x, float y, float width, float height, bool indent, const UBorderColor& color, float alpha);
446void DrawMac3DBox(const UIRect2D& rect, bool indent, const UBorderColor& color, int inset, float alpha);
447void DrawBoxWithSolidBorder(
448 const UIRect2D& rect, const UColor& inside, const UColor& outside, int size, int flags, float alpha
449);
Definition container.h:85
Definition listener.h:246
Definition ucolor.h:69
Definition ucolor.h:26
Definition uifont.h:40
Definition uipoint2d.h:26
Definition uirect2d.h:29
Definition uiwidget.h:36
Definition uisize2d.h:26
Definition usignal.h:44
Definition str.h:77