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