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