Debian Codegraph @

ui/UICombo.cpp

raw symbols SCIP
1 /*
2 * Descent 3
3 * Copyright (C) 2024 Parallax Software
4 *
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, either version 3 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17
18 --- HISTORICAL COMMENTS FOLLOW ---
19
20 * $Logfile: /DescentIII/Main/ui/UICombo.cpp $
21 * $Revision: 3 $
22 * $Date: 4/14/99 1:52a $
23 * $Author: Jeff $
24 *
25 *
26 *
27 * $Log: /DescentIII/Main/ui/UICombo.cpp $
28 *
29 * 3 4/14/99 1:52a Jeff
30 * fixed case mismatched #includes
31 *
32 * 2 3/03/99 2:45p Samir
33 * use arrows up and down for combo boxes.
34 *
35 * 1 9/02/98 6:49p Samir
36 * New combo box
37 *
38 * $NoKeywords: $
39 */
40
41 #include "UIlib.h"cxx . . $ `<file>/ui/UIlib.h`/
42
43 // ----------------------------------------------------------------------------
44 // UIComboBox
45 // A listbox may contain text items, BUT only one will be visible
46 // Allows the user to scroll through them too.
47
48 UIComboBoxcxx . . $ UIComboBox#::UIComboBoxcxx . . $ UIComboBox#UIComboBox(49f6e7a06ebc5aa8).() {
49 m_ItemListcxx . . $ UIComboBox#m_ItemList. = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!;
50 m_nItemscxx . . $ UIComboBox#m_nItems. = 0;
51 m_Indexcxx . . $ UIComboBox#m_Index. = 0;
52 m_ShowUpcxx . . $ UIComboBox#m_ShowUp. = false;
53 m_ShowDowncxx . . $ UIComboBox#m_ShowDown. = false;
54 selectchange_fncxx . . $ UIComboBox#selectchange_fn. = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!;
55 }
56
57 UIComboBoxcxx . . $ UIComboBox#::~cxx . . $ UIComboBox#`~UIComboBox`(ced63f7c635d850d).UIComboBoxcxx . . $ UIComboBox#() {}
58
59 // creates a combo box
60 void UIComboBoxcxx . . $ UIComboBox#::Createcxx . . $ UIComboBox#Create(43707b8add2f137d).(UIWindowcxx . . $ UIWindow# *parent, int id, int x, int y, int w, int h, int flags) {
61 m_ItemListcxx . . $ UIComboBox#m_ItemList. = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!;
62 m_nItemscxx . . $ UIComboBox#m_nItems. = 0;
63 m_Indexcxx . . $ UIComboBox#m_Index. = 0;
64 m_ShowUpcxx . . $ UIComboBox#m_ShowUp. = false;
65 m_ShowDowncxx . . $ UIComboBox#m_ShowDown. = false;
66 selectchange_fncxx . . $ UIComboBox#selectchange_fn. = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!;
67 m_scrolltimercxx . . $ UIComboBox#m_scrolltimer. = 0.0f;
68 m_scrollstagecxx . . $ UIComboBox#m_scrollstage. = 0;
69
70 UIGadgetcxx . . $ UIGadget#::Createcxx . . $ UIGadget#Create(43707b8add2f137d).(parent, id, x, y, w, h, flags);
71
72 m_CXcxx . . $ UIComboBox#m_CX. = 1;
73 m_CYcxx . . $ UIComboBox#m_CY. = 1;
74 m_CX2cxx . . $ UIComboBox#m_CX2. = m_Wcxx . . $ UIObject#m_W. - 1;
75 m_CY2cxx . . $ UIComboBox#m_CY2. = m_Hcxx . . $ UIObject#m_H. - 1;
76 }
77
78 void UIComboBoxcxx . . $ UIComboBox#::AddItemcxx . . $ UIComboBox#AddItem(f57aa2fef0df48a8).(const UIItemcxx . . $ UIItem# *item) {
79 int i;
80
81 if ((m_nItemscxx . . $ UIComboBox#m_nItems. % LISTBOX_BUFFER_SIZEcxx . . $ `ui/ui.h:879:9`!) == 0) {
82 // dynamically allocated memory for listbox, expand as needed.
83 UIItemcxx . . $ UIItem# **temp = new UIItemcxx . . $ UIItem# *[m_nItemscxx . . $ UIComboBox#m_nItems. + LISTBOX_BUFFER_SIZEcxx . . $ `ui/ui.h:879:9`!];
84 if (m_ItemListcxx . . $ UIComboBox#m_ItemList.) {
85 for (i = 0; i < m_nItemscxx . . $ UIComboBox#m_nItems.; i++)
86 temp[i] = m_ItemListcxx . . $ UIComboBox#m_ItemList.[i];
87 delete[] m_ItemListcxx . . $ UIComboBox#m_ItemList.;
88 }
89 m_ItemListcxx . . $ UIComboBox#m_ItemList. = temp;
90 }
91
92 // copy item passed to list.
93 m_ItemListcxx . . $ UIComboBox#m_ItemList.[m_nItemscxx . . $ UIComboBox#m_nItems.++] = (UIItemcxx . . $ UIItem# *)item;
94 }
95
96 // removes an item from the list.
97 void UIComboBoxcxx . . $ UIComboBox#::RemoveItemcxx . . $ UIComboBox#RemoveItem(f57aa2fef0df48a8).(const UIItemcxx . . $ UIItem# *item) {
98 int i, j;
99
100 for (i = 0; i < m_nItemscxx . . $ UIComboBox#m_nItems.; i++) {
101 if (item == m_ItemListcxx . . $ UIComboBox#m_ItemList.[i]) {
102 for (j = i; j < (m_nItemscxx . . $ UIComboBox#m_nItems. - 1); j++)
103 m_ItemListcxx . . $ UIComboBox#m_ItemList.[j] = m_ItemListcxx . . $ UIComboBox#m_ItemList.[j + 1];
104 m_nItemscxx . . $ UIComboBox#m_nItems.--;
105 break;
106 }
107 }
108 }
109
110 // empties combobox
111 void UIComboBoxcxx . . $ UIComboBox#::RemoveAllcxx . . $ UIComboBox#RemoveAll(49f6e7a06ebc5aa8).() { m_Indexcxx . . $ UIComboBox#m_Index. = m_nItemscxx . . $ UIComboBox#m_nItems. = 0; }
112
113 // selects the given item in the list.
114 void UIComboBoxcxx . . $ UIComboBox#::SelectItemcxx . . $ UIComboBox#SelectItem(f57aa2fef0df48a8).(const UIItemcxx . . $ UIItem# *item) {
115 int i;
116
117 for (i = 0; i < m_nItemscxx . . $ UIComboBox#m_nItems.; i++) {
118 if (item == m_ItemListcxx . . $ UIComboBox#m_ItemList.[i]) {
119 SetSelectedIndexcxx . . $ UIComboBox#SetSelectedIndex(d4f767463ce0a6b3).(i);
120 break;
121 }
122 }
123 }
124
125 // returns the item at listbox index given.
126 UIItemcxx . . $ UIItem# *UIComboBoxcxx . . $ UIComboBox#::GetItemcxx . . $ UIComboBox#GetItem(546e15a08a69e3a5).(int index) const { return (index < m_nItemscxx . . $ UIComboBox#m_nItems.) ? m_ItemListcxx . . $ UIComboBox#m_ItemList.[index] : NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!; }
127
128 // sets the selected index.
129 void UIComboBoxcxx . . $ UIComboBox#::SetSelectedIndexcxx . . $ UIComboBox#SetSelectedIndex(d4f767463ce0a6b3).(int index) {
130 if (index < m_nItemscxx . . $ UIComboBox#m_nItems.) {
131 m_Indexcxx . . $ UIComboBox#m_Index. = index;
132 if (selectchange_fncxx . . $ UIComboBox#selectchange_fn.)
133 (*selectchange_fncxx . . $ UIComboBox#selectchange_fn.)(index);
134 }
135 }
136
137 void UIComboBoxcxx . . $ UIComboBox#::SetSelectChangeCallbackcxx . . $ UIComboBox#SetSelectChangeCallback(94eb4457dc8d4d10).(void (*fn)(int)) { selectchange_fncxx . . $ UIComboBox#selectchange_fn. = fn; }
138
139 // called from outside gadget hierarchy.
140
141 void UIComboBoxcxx . . $ UIComboBox#::OnDestroycxx . . $ UIComboBox#OnDestroy(49f6e7a06ebc5aa8).() {
142 UIGadgetcxx . . $ UIGadget#::OnDestroycxx . . $ UIGadget#OnDestroy(49f6e7a06ebc5aa8).();
143
144 if (m_ItemListcxx . . $ UIComboBox#m_ItemList.)
145 delete[] m_ItemListcxx . . $ UIComboBox#m_ItemList.;
146
147 m_ItemListcxx . . $ UIComboBox#m_ItemList. = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!;
148 }
149
150 // behavior when gadget is being drawn.
151 void UIComboBoxcxx . . $ UIComboBox#::OnDrawcxx . . $ UIComboBox#OnDraw(49f6e7a06ebc5aa8).() {
152 UITextItemcxx . . $ UITextItem# uarrowcxx . . $ UITextItem#UITextItem(49f6e7a06ebc5aa8).;
153 UITextItemcxx . . $ UITextItem# darrowcxx . . $ UITextItem#UITextItem(49f6e7a06ebc5aa8).;
154 char arrowbuf[2];
155
156 if (m_Flagscxx . . $ UIGadget#m_Flags. & UIF_BORDERcxx . . $ `ui/ui.h:344:9`!)
157 ui_DrawBoxcxx . . $ ui_DrawBox(fe09a4b73d8d396f).(GR_WHITEcxx . . $ GR_WHITE., 0, 0, m_Wcxx . . $ UIObject#m_W., m_Hcxx . . $ UIObject#m_H.);
158
159 // draw all items in box that can be visible.
160 int x = m_CXcxx . . $ UIComboBox#m_CX.;
161 int y = m_CYcxx . . $ UIComboBox#m_CY.;
162
163 if (!m_nItemscxx . . $ UIComboBox#m_nItems.)
164 return;
165
166 snprintf(arrowbuf, sizeof(arrowbuf), "%c", UI_UP_ARROW_CHARcxx . . $ `ui/UIlib.h:96:9`!);
167 uarrow =cxx . . $ UITextItem#`operator=`(5ad635489e71ed3b). UITextItemcxx . . $ UITextItem#UITextItem(5f8aa4f2725849c4).(arrowbuf, m_ItemListcxx . . $ UIComboBox#m_ItemList.[m_Indexcxx . . $ UIComboBox#m_Index.]->get_colorcxx . . $ UIItem#get_color(ddd8539a2fcdd4ce).(), 255);
168 snprintf(arrowbuf, sizeof(arrowbuf), "%c", UI_DOWN_ARROW_CHARcxx . . $ `ui/UIlib.h:98:9`!);
169 darrow =cxx . . $ UITextItem#`operator=`(5ad635489e71ed3b). UITextItemcxx . . $ UITextItem#UITextItem(5f8aa4f2725849c4).(arrowbuf, m_ItemListcxx . . $ UIComboBox#m_ItemList.[m_Indexcxx . . $ UIComboBox#m_Index.]->get_colorcxx . . $ UIItem#get_color(ddd8539a2fcdd4ce).(), 255);
170
171 ui_SetTextClipcxx . . $ ui_SetTextClip(748afa4755bc9595).(m_CXcxx . . $ UIComboBox#m_CX., m_CYcxx . . $ UIComboBox#m_CY., m_CX2cxx . . $ UIComboBox#m_CX2., m_CY2cxx . . $ UIComboBox#m_CY2.);
172
173 // reset these
174 m_ShowUpcxx . . $ UIComboBox#m_ShowUp. = m_ShowDowncxx . . $ UIComboBox#m_ShowDown. = false;
175 m_ArrYcxx . . $ UIComboBox#m_ArrY. = y;
176 m_ArrHcxx . . $ UIComboBox#m_ArrH. = uarrow.heightcxx . . $ UITextItem#height(b126dc7c1de90089).();
177
178 if (m_Indexcxx . . $ UIComboBox#m_Index. > 0) {
179 m_UpArrXcxx . . $ UIComboBox#m_UpArrX. = m_CXcxx . . $ UIComboBox#m_CX.;
180 m_UpArrWcxx . . $ UIComboBox#m_UpArrW. = uarrow.widthcxx . . $ UITextItem#width(b126dc7c1de90089).();
181 uarrow.drawcxx . . $ UITextItem#draw(84329bcd07240ccf).(m_UpArrXcxx . . $ UIComboBox#m_UpArrX., m_ArrYcxx . . $ UIComboBox#m_ArrY.);
182 m_ShowUpcxx . . $ UIComboBox#m_ShowUp. = true;
183 }
184 if (m_Indexcxx . . $ UIComboBox#m_Index. < (m_nItemscxx . . $ UIComboBox#m_nItems. - 1)) {
185 m_DownArrXcxx . . $ UIComboBox#m_DownArrX. = m_CX2cxx . . $ UIComboBox#m_CX2. - darrow.widthcxx . . $ UITextItem#width(b126dc7c1de90089).();
186 m_DownArrWcxx . . $ UIComboBox#m_DownArrW. = darrow.widthcxx . . $ UITextItem#width(b126dc7c1de90089).();
187 darrow.drawcxx . . $ UITextItem#draw(84329bcd07240ccf).(m_DownArrXcxx . . $ UIComboBox#m_DownArrX., m_ArrYcxx . . $ UIComboBox#m_ArrY.);
188 m_ShowDowncxx . . $ UIComboBox#m_ShowDown. = true;
189 }
190
191 // draw current item.
192 x = m_CXcxx . . $ UIComboBox#m_CX. + uarrow.widthcxx . . $ UITextItem#width(b126dc7c1de90089).() + 2;
193 ui_SetTextClipcxx . . $ ui_SetTextClip(748afa4755bc9595).(x, m_CYcxx . . $ UIComboBox#m_CY., m_CX2cxx . . $ UIComboBox#m_CX2. - darrow.widthcxx . . $ UITextItem#width(b126dc7c1de90089).() - 2, m_CY2cxx . . $ UIComboBox#m_CY2.);
194 m_ItemListcxx . . $ UIComboBox#m_ItemList.[m_Indexcxx . . $ UIComboBox#m_Index.]->drawcxx . . $ UIItem#draw(84329bcd07240ccf).(x, y);
195
196 ui_ResetTextClipcxx . . $ ui_ResetTextClip(49f6e7a06ebc5aa8).();
197 }
198
199 // behavior when key is pressed.
200 void UIComboBoxcxx . . $ UIComboBox#::OnKeyDowncxx . . $ UIComboBox#OnKeyDown(d4f767463ce0a6b3).(int key) {
201 if (key == KEY_UPcxx . . $ `ddio/ddio_common.h:318:9`!) {
202 if (m_Indexcxx . . $ UIComboBox#m_Index. > 0) {
203 UIComboBoxcxx . . $ UIComboBox#::SetSelectedIndexcxx . . $ UIComboBox#SetSelectedIndex(d4f767463ce0a6b3).(m_Indexcxx . . $ UIComboBox#m_Index. - 1);
204 }
205 } else if (key == KEY_DOWNcxx . . $ `ddio/ddio_common.h:319:9`!) {
206 if (m_Indexcxx . . $ UIComboBox#m_Index. < (m_nItemscxx . . $ UIComboBox#m_nItems. - 1)) {
207 UIComboBoxcxx . . $ UIComboBox#::SetSelectedIndexcxx . . $ UIComboBox#SetSelectedIndex(d4f767463ce0a6b3).(m_Indexcxx . . $ UIComboBox#m_Index. + 1);
208 }
209 }
210 }
211
212 // behavior when mouse button is pressed.
213 void UIComboBoxcxx . . $ UIComboBox#::OnMouseBtnDowncxx . . $ UIComboBox#OnMouseBtnDown(d4f767463ce0a6b3).(int btn) {
214 if (btn == UILMSEBTNcxx . . $ `ui/uisys.h:36:9`!) {
215 int mx = SCREEN_TO_GAD_Xcxx . . $ SCREEN_TO_GAD_X(dafe5a5d85eeac89).(this, UI_inputcxx . . $ UI_input..mxcxx . . $ tUIInput#mx.);
216 int my = SCREEN_TO_GAD_Ycxx . . $ SCREEN_TO_GAD_Y(dafe5a5d85eeac89).(this, UI_inputcxx . . $ UI_input..mycxx . . $ tUIInput#my.);
217
218 // determine whether to accept mouse input at this time.
219 if (m_scrollstagecxx . . $ UIComboBox#m_scrollstage. == 0) {
220 m_scrollstagecxx . . $ UIComboBox#m_scrollstage. = 1;
221 } else if (m_scrollstagecxx . . $ UIComboBox#m_scrollstage. == 1) {
222 if ((m_scrolltimercxx . . $ UIComboBox#m_scrolltimer. - UI_TIMEcxx . . $ UI_TIME(9b8c9e39889c762c).()) < KEYDOWN_FIRST_DELAYcxx . . $ `ui/ui.h:753:9`!)
223 return;
224 m_scrollstagecxx . . $ UIComboBox#m_scrollstage. = 2;
225 } else if (m_scrollstagecxx . . $ UIComboBox#m_scrollstage. == 2) {
226 if ((m_scrolltimercxx . . $ UIComboBox#m_scrolltimer. - UI_TIMEcxx . . $ UI_TIME(9b8c9e39889c762c).()) < KEYDOWN_REPEAT_DELAYcxx . . $ `ui/ui.h:754:9`!)
227 return;
228 }
229 m_scrolltimercxx . . $ UIComboBox#m_scrolltimer. = UI_TIMEcxx . . $ UI_TIME(9b8c9e39889c762c).();
230
231 // do mouse processing.
232 if (m_ShowUpcxx . . $ UIComboBox#m_ShowUp. && PT_IN_RECTcxx . . $ PT_IN_RECT(33820514f83722bc).(mx, my, m_UpArrXcxx . . $ UIComboBox#m_UpArrX., m_ArrYcxx . . $ UIComboBox#m_ArrY., m_UpArrWcxx . . $ UIComboBox#m_UpArrW., m_ArrHcxx . . $ UIComboBox#m_ArrH.)) {
233 if (m_Indexcxx . . $ UIComboBox#m_Index. > 0)
234 UIComboBoxcxx . . $ UIComboBox#::SetSelectedIndexcxx . . $ UIComboBox#SetSelectedIndex(d4f767463ce0a6b3).(m_Indexcxx . . $ UIComboBox#m_Index. - 1);
235 } else if (m_ShowDowncxx . . $ UIComboBox#m_ShowDown. && PT_IN_RECTcxx . . $ PT_IN_RECT(33820514f83722bc).(mx, my, m_DownArrXcxx . . $ UIComboBox#m_DownArrX., m_ArrYcxx . . $ UIComboBox#m_ArrY., m_DownArrWcxx . . $ UIComboBox#m_DownArrW., m_ArrHcxx . . $ UIComboBox#m_ArrH.)) {
236 if (m_Indexcxx . . $ UIComboBox#m_Index. < (m_nItemscxx . . $ UIComboBox#m_nItems. - 1))
237 UIComboBoxcxx . . $ UIComboBox#::SetSelectedIndexcxx . . $ UIComboBox#SetSelectedIndex(d4f767463ce0a6b3).(m_Indexcxx . . $ UIComboBox#m_Index. + 1);
238 }
239 }
240 }
241
242 // behavior when mouse button is released.
243 void UIComboBoxcxx . . $ UIComboBox#::OnMouseBtnUpcxx . . $ UIComboBox#OnMouseBtnUp(d4f767463ce0a6b3).(int btn) {
244 if (btn == UILMSEBTNcxx . . $ `ui/uisys.h:36:9`!) {
245 m_scrollstagecxx . . $ UIComboBox#m_scrollstage. = 0;
246 }
247 }
248
249 void UIComboBoxcxx . . $ UIComboBox#::OnSelectcxx . . $ UIComboBox#OnSelect(49f6e7a06ebc5aa8).() { UIGadgetcxx . . $ UIGadget#::OnSelectcxx . . $ UIGadget#OnSelect(49f6e7a06ebc5aa8).(); }