OpenMoHAA 0.82.0
Loading...
Searching...
No Matches
uipopupmenu.h
1/*
2===========================================================================
3Copyright (C) 2024 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
25typedef enum { UIP_NONE, UIP_EVENT, UIP_EVENT_STRING, UIP_SUBMENU, UIP_CMD, UIP_CVAR, UIP_SEPARATOR } uipopup_type;
26typedef enum { UIP_WHERE_RIGHT, UIP_WHERE_DOWN } uipopup_where;
27
28class uipopup_describe {
29public:
30 str title;
31 UIReggedMaterial *material;
32 uipopup_type type;
33 void *data;
34
35 uipopup_describe();
36 uipopup_describe( str title, uipopup_type type, void *data, UIReggedMaterial *material );
37 ~uipopup_describe();
38};
39
40inline
41uipopup_describe::uipopup_describe()
42{
43 title = "";
44 material = NULL;
45 type = UIP_NONE;
46 data = NULL;
47}
48
49inline
50uipopup_describe::uipopup_describe
51 (
52 str title,
53 uipopup_type type,
54 void *data,
55 UIReggedMaterial *material
56 )
57
58{
59 this->title = title;
60 this->type = type;
61 this->data = data;
62 this->material = material;
63}
64
65// NOTE: this is not part of the original game!
66// Added in OPM to properly clean up memory.
67inline
68uipopup_describe::~uipopup_describe()
69{
70 if (this->data == NULL) {
71 // nothing to clean up
72 return;
73 }
74
75 // only clean up these types of uipds, because:
76 // - UIP_EVENT types point to static Event instances,
77 // - UIP_EVENT_STRING types point to already freed Event instances
78 if (this->type == UIP_CMD || this->type == UIP_CVAR) {
79 // clean up strdup'd C-string from memory
80 free(this->data);
81 this->data = NULL;
82 }
83}
84
85class UIPopupMenu : public UIWidget {
86 friend class UIPulldownMenu; // so that m_submenuptr, m_submenu and m_parentMenu can be accessed
87protected:
89 int m_selected;
90 Listener *m_listener;
91 class UIPopupMenu *m_parentMenu;
92 class UIPopupMenu *m_submenuptr;
93 int m_submenu;
94 UIFont m_marlett;
95 bool m_autodismiss;
96 UColor m_highlightFGColor;
97 UColor m_highlightBGColor;
98
99public:
100 CLASS_PROTOTYPE( UIPopupMenu );
101
102protected:
103 uipopup_describe *getDescribeFromPoint( const UIPoint2D& p );
104 void MakeSubMenu( void );
105 virtual float getDescribeHeight( uipopup_describe *d );
106 virtual float getDescribeWidth( uipopup_describe *d );
107 bool MouseInSubmenus( void );
108
109public:
110 UIPopupMenu();
111 ~UIPopupMenu();
112
113 void Create( Container<uipopup_describe*> *describe, Listener *listener, const UIPoint2D& where );
114 void Create( Container<uipopup_describe*> *describe, Listener *listener, const UIRect2D& createRect, uipopup_where where, qboolean bVirtualSize, float width );
115 void YouAreASubmenu( UIPopupMenu *me );
116 void Draw( void ) override;
117 void MouseReleased( Event *ev );
118 void MouseMoved( Event *ev );
119 void MouseExited( Event *ev );
120 void Dismiss( void );
121 void DismissEvent( Event *ev );
122 void setAutoDismiss( bool b );
123 void setNextSelection( void );
124 void setPrevSelection( void );
125 uipopup_describe *getSelectedDescribe( void );
126 void setSelection( int sel );
127 void setHighlightFGColor( UColor c );
128 void setHighlightBGColor( UColor c );
129 void setPopupHighlightBGColor( str menu, UColor c );
130 void setPopupHighlightFGColor( str menu, UColor c );
131 void getPulldown( str title );
132};
133
134uipopup_type UI_PopupTypeStringToInt(str type);
Definition container.h:85
Definition listener.h:246
Definition ucolor.h:25
Definition uifont.h:40
Definition uipoint2d.h:25
Definition uirect2d.h:28
Definition uiwidget.h:35
Definition str.h:77
Definition uipopupmenu.h:28