OpenMoHAA ..
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 "../corepp/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 // Added in 2.0
169 //
170 cvar_t *m_scaleCvar;
171
172 //
173 // Added in OPM
174 //
175 float lastShowTime;
176
177public:
178 CLASS_PROTOTYPE(UIWidget);
179
180 void (*m_commandhandler)(const char *, void *);
181
182protected:
183 bool addChild(UIWidget *widget);
184 bool removeChild(UIWidget *widget);
185 void PropogateCoordinateSystem(void);
186 void set2D(void);
187 virtual void Draw(void);
188 virtual void FrameInitialized(void);
189 void DrawTitle(float x, float y);
190 void Motion(void);
191 virtual void AlignPosition(void);
192 void Hide(Event *ev);
193 void Activate(Event *ev);
194 void BringToFront(void);
195 static void SplitWidgets(
197 Container<UIWidget *>& bottom,
198 Container<UIWidget *>& normal,
200 );
201 static void CombineWidgets(
203 Container<UIWidget *>& bottom,
204 Container<UIWidget *>& normal,
206 );
207 static void ArrangeWidgetList(Container<UIWidget *>& list);
208
209public:
210 UIWidget();
211 virtual ~UIWidget();
212
213 virtual void Shutdown(void);
214 virtual void InitFrame(
215 UIWidget *parentview,
216 float x,
217 float y,
218 float width,
219 float height,
220 int border = -1,
221 const char *fontname = "verdana-12"
222 );
223 void InitFrame(UIWidget *parentview, const UIRect2D& r, int border, const char *fontname = "verdana-12");
224 void LayoutSize(Event *ev);
225 void LayoutRect(Event *ev);
226 void LayoutName(Event *ev);
227 void LayoutTitle(Event *ev);
228 void LayoutFont(Event *ev);
229 void LayoutBgColor(Event *ev);
230 void LayoutFgColor(Event *ev);
231 void LayoutBorderStyle(Event *ev);
232 void LayoutBorderColor(Event *ev);
233 void LayoutShader(Event *ev);
234 void LayoutTileShader(Event *ev);
235 void LayoutHoverShader(Event *ev);
236 void LayoutPressedShader(Event *ev);
237 void LayoutFadeIn(Event *ev);
238 void LayoutStopSound(Event *ev);
239 void LayoutClickSound(Event *ev);
240 void LayoutStretch(Event *ev);
241 void LayoutVirtualRes(Event *ev);
242 void LayoutInitData(Event *ev);
243 void LayoutDirection(Event *ev);
244 void LayoutAlign(Event *ev);
245 void LayoutStuffCommand(Event *ev);
246 void LayoutLinkCvar(Event *ev);
247 void LayoutNoParentClipping(Event *ev);
248 void LayoutNoParentAdjustment(Event *ev);
249 void LayoutOrderNumber(Event *ev);
250 void TextAlignment(Event *ev);
251 void LayoutAliasCache(Event *ev);
252 void SetEnabledCvar(Event *ev);
253 void SetScaleCvar(Event *ev);
254
255 // Added in 2.0
256 //====
257 void SetDontLocalize(Event *ev);
258 void EventFadeSequence(Event *ev);
259 //====
260
261 void SetVirtualScale(vec2_t out);
262 void SetDontLocalize();
263 void setParent(UIWidget *parent);
264 class UIWidget *getParent(void);
265 class UIWidget *getFirstChild(void);
266 class UIWidget *getNextSibling(void);
267 class UIWidget *getNextChild(UIWidget *child);
268 class UIWidget *getPrevChild(UIWidget *child);
269 class UIWidget *getPrevSibling(void);
270 class UIWidget *getPrevSibling(UIWidget *curr);
271 class UIWidget *getLastSibling(void);
272 class UIWidget *findSibling(str name);
273
274 void Enable(void);
275 void Disable(void);
276 bool isEnabled(void);
277 bool IsDying(void);
278 class UIWidget *FindResponder(const UIPoint2D& pos);
279 void setFont(const char *name);
280 void setFontHorizontalAlignment(fonthorzjustify_t alignment);
281 void setFontVerticalAlignment(fontvertjustify_t alignment);
282 void setShow(bool visible);
283 bool getShow(void);
284 class UColor getBackgroundColor(void);
285 virtual void setBackgroundColor(const UColor& color, bool setbordercolor);
286 class UBorderColor getBorderColor(void);
287 void setBorderColor(const UBorderColor& color);
288 class UColor getForegroundColor(void);
289 virtual void setForegroundColor(const UColor& color);
290 borderstyle_t getBorderStyle(void);
291 void setBorderStyle(borderstyle_t style);
292 class UISize2D getSize(void);
293 void setSize(const UISize2D& newsize);
294 class UIRect2D getFrame(void);
295 void setFrame(const UIRect2D& newframe);
296 class UIPoint2D getOrigin(void);
297 void setOrigin(const UIPoint2D& neworigin);
298 void setName(str name);
299 const char *getName(void);
300 void setTitle(str title);
301 const char *getTitle(void);
302 void setDirection(direction_t dir);
303 direction_t getDirection(void);
304 void setMotionType(motion_t type);
305 motion_t getMotionType(void);
306 void setMotionTime(float time);
307 float getMotionTime(void);
308 void setAlign(int align);
309 int getAlign(void);
310 void setMaterial(UIReggedMaterial *mat);
311 void setHoverMaterial(UIReggedMaterial *mat);
312 void setPressedMaterial(UIReggedMaterial *mat);
313 class UIPoint2D getLocalPoint(const UIPoint2D& pos);
314 class UIPoint2D getGlobalPoint(const UIPoint2D& pos);
315 virtual void setBackgroundAlpha(float f);
316 float getBackgroundAlpha(void);
317 void Display(const UIRect2D& drawframe, float parent_alpha);
318 virtual qboolean KeyEvent(int key, unsigned int time);
319 virtual void CharEvent(int ch);
320 virtual void UpdateData(void);
321 virtual void UpdateUIElement(void);
322 float getTitleWidth(void);
323 float getTitleHeight(void);
324 bool CanActivate(void);
325 void AllowActivate(bool canactivate);
326 bool IsActive(void);
327 bool IsVisible(void);
328 virtual void LinkCvar(str cvarname);
329 void LinkCommand(str cmd);
330 void ExecuteShowCommands(void);
331 void ExecuteHideCommands(void);
332 void InitializeCommandHandler(void (*fcn)(const char *, void *));
333 class UIWidget *FindWidget(str name);
334 void ResetMotion(motion_t type);
335 virtual void Realign(void);
336 void BringToFrontPropogated(void);
337 class UIWidget *IsThisOrChildActive(void);
338 class UIPoint2D MouseEventToClientPoint(Event *ev);
339 class UIRect2D getClientFrame(void);
340 void setAlwaysOnBottom(bool b);
341 void setAlwaysOnTop(bool b);
342 bool getAlwaysOnBottom(void);
343 bool getAlwaysOnTop(void);
344 bool SendSignal(Event& event);
345 void ShowCommand(Event *ev);
346 void HideCommand(Event *ev);
347 void AddFlag(int flag);
348 void SetHovermaterialActive(bool a);
349 void SetPressedmaterialActive(bool a);
350 int getOrderNum(void);
351 class str getCommand(void);
352 void ActivateOrder(void);
353 void EnableEvent(Event *ev);
354 void DisableEvent(Event *ev);
355 void setConfigstringIndex(int cs);
356 int getConfigstringIndex(void);
357 bool PassEventToWidget(str name, Event *ev);
358
359 // Added in OPM
360 UIFont *getFont() const;
361 bool isVirtual() const;
362 const vec2_t& getVirtualScale() const;
363 const vec2_t& getHighResScale() const;
364};
365
366class UIWidgetContainer : public UIWidget
367{
368 UColor m_bgfill;
369 qboolean m_fullscreen;
370 int m_vidmode;
371 int m_currentwidnum;
372 int m_maxordernum;
373
374public:
375 class UILayout *m_layout;
376
377 CLASS_PROTOTYPE(UIWidgetContainer);
378
379private:
380 void AlignPosition(void) override;
381 void Draw(void) override;
382
383public:
384 UIWidgetContainer();
385
386 void Realign(void) override;
387 void SetBGFill(Event *ev);
388 void SetFullscreen(Event *ev);
389 void SetVidMode(Event *ev);
390 int getVidMode(void);
391 qboolean isFullscreen(void);
392 UIWidget *GetNextWidgetInOrder(void);
393 UIWidget *GetPrevWidgetInOrder(void);
394 void SetActiveWidgetOrderNum(UIWidget *wid);
395 void SetActiveWidgetOrderNum(int num);
396 void SetLastActiveWidgetOrderNum(void);
397};
398
399extern Event W_Destroyed;
400extern Event W_SizeChanged;
401extern Event W_FrameChanged;
402extern Event W_OriginChanged;
403extern Event W_Activated;
404extern Event EV_Widget_Activate;
405extern Event W_Deactivated;
406extern Event EV_Widget_Hide;
407extern Event EV_Widget_Enable;
408extern Event EV_Widget_Disable;
409extern Event W_RealignWidget;
410extern Event W_Draw;
411extern Event EV_Layout_Size;
412extern Event EV_Layout_Rect;
413extern Event EV_Layout_Name;
414extern Event EV_Layout_Title;
415extern Event EV_Layout_Font;
416extern Event EV_Layout_BGColor;
417extern Event EV_Layout_FGColor;
418extern Event EV_Layout_Borderstyle;
419extern Event EV_Layout_BorderColor;
420extern Event EV_Layout_Shader;
421extern Event EV_Layout_TileShader;
422extern Event EV_Layout_HoverShader;
423extern Event EV_Layout_PressedShader;
424extern Event EV_Layout_FadeIn;
425extern Event EV_Layout_StopSound;
426extern Event EV_Layout_ClickSound;
427extern Event EV_Layout_Stretch;
428extern Event EV_Layout_VirtualRes;
429extern Event EV_Layout_InitData;
430extern Event EV_Layout_Direction;
431extern Event EV_Layout_Align;
432extern Event EV_Layout_StuffCommand;
433extern Event EV_Layout_LinkCvar;
434extern Event EV_Layout_NoParentClipping;
435extern Event EV_Layout_NoParentAdjustment;
436extern Event EV_Widget_HideCommand;
437extern Event EV_Widget_ShowCommand;
438extern Event EV_Widget_OrderNumber;
439extern Event EV_Widget_TextAlignment;
440extern Event EV_Widget_EnabledCvar;
441extern Event EV_Layout_AliasCache;
442extern Event EV_Layout_BGFill;
443extern Event EV_Layout_Fullscreen;
444extern Event EV_Layout_VidMode;
445
446void SetColor(const UColor& color, float alpha);
447void DrawBox(const UIRect2D& rect, const UColor& color, float alpha);
448void Draw3DBox(const UIRect2D& rect, bool indent, const UBorderColor& color, float alpha);
449void DrawBox(float x, float y, float width, float height, const UColor& color, float alpha);
450void Draw3DBox(float x, float y, float width, float height, bool indent, const UBorderColor& color, float alpha);
451void DrawMac3DBox(const UIRect2D& rect, bool indent, const UBorderColor& color, int inset, float alpha);
452void DrawBoxWithSolidBorder(
453 const UIRect2D& rect, const UColor& inside, const UColor& outside, int size, int flags, float alpha
454);
Definition g_local.h:81
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