Debian Codegraph @

ui/UISystem.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/UISystem.cpp $
21 * $Revision: 44 $
22 * $Date: 3/20/00 12:30p $
23 * $Author: Matt $
24 *
25 * UI system code.
26 *
27 * $Log: /DescentIII/Main/ui/UISystem.cpp $
28 *
29 * 44 3/20/00 12:30p Matt
30 * Merge of Duane's post-1.3 changes.
31 * Mac-only debugging change.
32 *
33 * 43 10/21/99 3:33p Kevin
34 * Mac merge!
35 *
36 * 42 7/28/99 2:03p Kevin
37 * Macintosh Changes
38 *
39 * 41 5/05/99 6:48p Samir
40 * hack to get pause key to properly register in UI system.
41 *
42 * 40 5/01/99 1:14a Samir
43 * fixed mouse sequencing probs with selections being canceled out by
44 * UISystem.
45 *
46 * 39 4/14/99 1:54a Jeff
47 * fixed case mismatched #includes
48 *
49 * 38 4/01/99 11:28a Samir
50 * never flush mouse during ui_Flush. This will screw up emulated mouse
51 * input and maybe mess up some hardware mouse support from the ddio
52 * library.
53 *
54 * 37 3/23/99 9:02p Samir
55 * added mouse flush for ui flush. also made keyboard flush too.
56 *
57 * 36 2/21/99 6:38p Samir
58 * mouse and key input better. buffered mouse.
59 *
60 * 35 1/28/99 6:49p Samir
61 * frame limit ui system.
62 *
63 * 34 1/25/99 11:02a Samir
64 * revamped mouse and key controls.
65 *
66 * 33 10/19/98 2:50p Samir
67 * added function to cleanup ui windows.
68 *
69 * 32 10/16/98 5:54p Samir
70 * to prevent infinite loops, error check.
71 *
72 * 31 10/16/98 5:53p Samir
73 * redid add and remove window mechanisms.
74 *
75 * 30 10/13/98 8:23p Samir
76 * added more keyboard input options.
77 *
78 * 29 10/13/98 3:47p Samir
79 * added function to check if a cursor is visible
80 *
81 * 28 10/06/98 7:31p Samir
82 * changed behavior of mouse b1_count calculation.
83 *
84 * 27 10/02/98 5:47p Samir
85 * changed behavior of mouse cursor.
86 *
87 * 26 9/30/98 4:32p Samir
88 * added frametime value.
89 *
90 * 25 9/27/98 3:52p Samir
91 * made mouse input delay 25 fps.
92 *
93 * 24 9/01/98 4:12p Samir
94 * added screenshot caparbilities.
95 *
96 * 23 8/31/98 4:08p Samir
97 * don't reset mouse position when flushing ui.
98 *
99 * 22 8/24/98 3:13p Samir
100 * fixed swimming of mouse.
101 *
102 * 21 6/30/98 6:13p Samir
103 * call ddio_MouseReset on ui_SetScreenMode.
104 *
105 * 20 6/29/98 6:44p Samir
106 * redid ui input polling.
107 *
108 * 19 6/05/98 5:35p Samir
109 * massive improvement in UI keyboard interface.
110 *
111 * 18 5/06/98 4:34p Samir
112 * added function to set ui screen resolution.
113 *
114 * 17 5/05/98 5:15p Samir
115 * ui system now takes a width and height too
116 *
117 * 16 4/10/98 7:51p Samir
118 * added ui_Flush
119 *
120 * 15 3/24/98 4:27p Samir
121 * To check key states in ui_Poll, calls ddio_GetAdjKeyValue.
122 *
123 * 14 3/18/98 6:25p Samir
124 * Don't turn Z-buffering back on.
125 *
126 * 13 3/10/98 12:50p Samir
127 * Made UI_screen_width & height accessable.
128 *
129 * 12 2/18/98 2:39p Samir
130 * fixed mouse cursor clipping.
131 *
132 * 11 2/17/98 2:22p Jason
133 * fixed some potential z sorting problems
134 *
135 * 10 2/13/98 6:36p Samir
136 * Added ability to prevent input polling and mouse input.
137 *
138 * 9 2/11/98 5:55p Samir
139 * Hide and Show cursor aren't cumulative now.
140 *
141 * 8 2/02/98 7:35p Samir
142 * Added show/hide cursor functions.
143 *
144 * 7 1/30/98 7:07p Samir
145 * Cleaned up Window handling code.
146 *
147 * 6 1/18/98 4:22p Samir
148 * Changed some UI initialization stuff.
149 *
150 * 5 1/16/98 1:27p Jeff
151 * Poll always at least once.
152 *
153 * 4 1/13/98 4:32p Samir
154 * Made tUIInput a shared structure to be used by ui_DoFrame to return UI
155 * input values.
156 *
157 * 3 1/08/98 12:17p Samir
158 * Added TitledWindow and modified the UI interface for polling.
159 *
160 * 2 1/02/98 12:48p Samir
161 * Better keyboard support and full mouse cursor support.
162 *
163 * 1 12/30/97 4:36p Samir
164 * Initial revision
165 *
166 * $NoKeywords: $
167 */
168
169 #include "UIlib.h"cxx . . $ `<file>/ui/UIlib.h`/
170 #include "application.h"cxx . . $ `<file>/lib/application.h`/
171 #include "bitmap.h"cxx . . $ `<file>/lib/bitmap.h`/
172 #include "ddvid.h"cxx . . $ `<file>/lib/ddvid.h`/
173 #include "renderer.h"cxx . . $ `<file>/lib/renderer.h`/
174 #include "Macros.h"cxx . . $ `<file>/lib/Macros.h`/
175
176 #define UI_MOUSE_HOTXcxx . . $ `ui/UISystem.cpp:176:9`! 2
177 #define UI_MOUSE_HOTYcxx . . $ `ui/UISystem.cpp:177:9`! 2
178 #define UI_FRAMETIMEcxx . . $ `ui/UISystem.cpp:178:9`! 0.05
179 //////////////////////////////////////////////////////////////////////////////
180 // VARIABLES
181 struct tUIWindowNodecxx . . $ tUIWindowNode# {
182 UIWindowcxx . . $ UIWindow# *wndcxx . . $ tUIWindowNode#wnd.;
183 struct tUIWindowNodecxx . . $ tUIWindowNode# *nextcxx . . $ tUIWindowNode#next.;
184 struct tUIWindowNodecxx . . $ tUIWindowNode# *prevcxx . . $ tUIWindowNode#prev.;
185 };
186 // user input structure
187 tUIInputcxx . . $ tUIInput# UI_inputcxx . . $ UI_input.;
188 // user output structure
189 tUIOutputcxx . . $ tUIOutput# UI_outputcxx . . $ UI_output.;
190 int UI_screen_widthcxx . . $ UI_screen_width., UI_screen_heightcxx . . $ UI_screen_height.;
191 float UI_aspect_xcxx . . $ UI_aspect_x. = 1.0f;
192 float UI_aspect_ycxx . . $ UI_aspect_y. = 1.0f;
193 // application object
194 static bool UI_initcxx . . $ UI_init. = false;
195 static oeApplicationcxx . . $ oeApplication# *UI_appcxx . . $ UI_app. = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!;
196 static int UI_cursor_bmcxx . . $ UI_cursor_bm. = -1;
197 static tUIWindowNodecxx . . $ tUIWindowNode# *UIWindowListcxx . . $ UIWindowList. = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!;
198 static tUIWindowNodecxx . . $ tUIWindowNode# *UIWindowTailcxx . . $ UIWindowTail. = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!;
199 static UIWindowcxx . . $ UIWindow# *UIWindowFocuscxx . . $ UIWindowFocus. = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!;
200 static int UI_cursor_showcxx . . $ UI_cursor_show. = 0;
201 float UIFrameTimecxx . . $ UIFrameTime. = 0.0f;
202 bool ui_MousePollcxx . . $ ui_MousePoll(efaadfb7dc14930a).(bool buttons);
203 bool ui_KeyPollcxx . . $ ui_KeyPoll(c9857a73d68e59ba).();
204 void ui_UpdateWindowscxx . . $ ui_UpdateWindows(49f6e7a06ebc5aa8).();
205 //////////////////////////////////////////////////////////////////////////////
206 // FUNCTIONS
207 // call this function to initialize the UI system. pass a surface where all UI will occur
208 void ui_Initcxx . . $ ui_Init(506d4ea8517b8bcc).(oeApplicationcxx . . $ oeApplication# *app, tUIInitInfocxx . . $ tUIInitInfo# *init_info) {
209 // initialize variables
210 if (UI_appcxx . . $ UI_app.) {
211 ui_Closecxx . . $ ui_Close(49f6e7a06ebc5aa8).();
212 }
213 // clear out input poller.
214 ui_Flushcxx . . $ ui_Flush(49f6e7a06ebc5aa8).();
215 UI_cursor_bmcxx . . $ UI_cursor_bm. = -1;
216 UI_cursor_showcxx . . $ UI_cursor_show. = 0;
217 UI_appcxx . . $ UI_app. = app;
218 UIWindowListcxx . . $ UIWindowList. = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!;
219 UIWindowTailcxx . . $ UIWindowTail. = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!;
220 UITextItemcxx . . $ UITextItem#::SetDefaultFontcxx . . $ UITextItem#SetDefaultFont(d4f767463ce0a6b3).(init_info->window_fontcxx . . $ tUIInitInfo#window_font.);
221 ui_SetScreenModecxx . . $ ui_SetScreenMode(3e454b8ccf442868).(init_info->wcxx . . $ tUIInitInfo#w., init_info->hcxx . . $ tUIInitInfo#h.);
222 UI_initcxx . . $ UI_init. = true;
223 }
224 // frees ui input cache
225 void ui_Flushcxx . . $ ui_Flush(49f6e7a06ebc5aa8).() {
226 // UI_input.mx = 0;
227 // UI_input.last_mx = 0;
228 // UI_input.my = 0;
229 // UI_input.last_my = 0;
230 UI_inputcxx . . $ UI_input..b1_statuscxx . . $ tUIInput#b1_status. = 0;
231 UI_inputcxx . . $ UI_input..b1_last_statuscxx . . $ tUIInput#b1_last_status. = 0;
232 UI_inputcxx . . $ UI_input..b1_countcxx . . $ tUIInput#b1_count. = 0;
233 UIFrameTimecxx . . $ UIFrameTime. = 0.0f;
234 UI_inputcxx . . $ UI_input..cur_timecxx . . $ tUIInput#cur_time. = timer_GetTimecxx . . $ `ddio/ddio.h:236:9`!();
235 ui_KeyFlushcxx . . $ ui_KeyFlush(49f6e7a06ebc5aa8).();
236 }
237 // flushes out key input info currently in ui.
238 void ui_KeyFlushcxx . . $ ui_KeyFlush(49f6e7a06ebc5aa8).() {
239 UI_inputcxx . . $ UI_input..keycxx . . $ tUIInput#key. = 0;
240 UI_inputcxx . . $ UI_input..key_first_presscxx . . $ tUIInput#key_first_press. = false;
241 UI_inputcxx . . $ UI_input..key_statuscxx . . $ tUIInput#key_status. = 0;
242 UI_inputcxx . . $ UI_input..last_keycxx . . $ tUIInput#last_key. = 0;
243 UI_inputcxx . . $ UI_input..last_key_statuscxx . . $ tUIInput#last_key_status. = 0;
244 UI_inputcxx . . $ UI_input..printscreencxx . . $ tUIInput#printscreen. = false;
245 ddio_KeyFlushcxx . . $ ddio_KeyFlush(49f6e7a06ebc5aa8).();
246 }
247 // closes UI system. do this when setting a new surface.
248 void ui_Closecxx . . $ ui_Close(49f6e7a06ebc5aa8).() {
249 if (UI_cursor_bmcxx . . $ UI_cursor_bm. > -1) {
250 bm_FreeBitmapcxx . . $ bm_FreeBitmap(d4f767463ce0a6b3).(UI_cursor_bmcxx . . $ UI_cursor_bm.);
251 UI_cursor_bmcxx . . $ UI_cursor_bm. = -1;
252 }
253 // delete window node list.
254 ui_RemoveAllWindowscxx . . $ ui_RemoveAllWindows(49f6e7a06ebc5aa8).();
255 UI_appcxx . . $ UI_app. = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!;
256 UI_initcxx . . $ UI_init. = false;
257 }
258 // retrieves input for user interface
259 // mouse
260 // keyboard
261 // possibly joystick?
262 bool ui_MousePollcxx . . $ ui_MousePoll(efaadfb7dc14930a).(bool buttons) {
263 int mx, my;
264 static int btn_mask = 0;
265 int msebtn;
266 bool state;
267 if (!buttons) {
268 // get all input, mouse maintains persistent button info. key doesn't.
269 btn_mask = ddio_MouseGetStatecxx . . $ ddio_MouseGetState(150f8a26046a094b).(&mx, &my, NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!, NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!);
270 UI_inputcxx . . $ UI_input..last_mxcxx . . $ tUIInput#last_mx. = UI_inputcxx . . $ UI_input..mxcxx . . $ tUIInput#mx.;
271 UI_inputcxx . . $ UI_input..last_mycxx . . $ tUIInput#last_my. = UI_inputcxx . . $ UI_input..mycxx . . $ tUIInput#my.;
272 UI_inputcxx . . $ UI_input..mxcxx . . $ tUIInput#mx. = mx;
273 UI_inputcxx . . $ UI_input..mycxx . . $ tUIInput#my. = my;
274 } else if (UI_cursor_showcxx . . $ UI_cursor_show.) {
275 // if bX_count is 0, then repeat processing can occur, otherwise only real mouse events are processed.
276 if (ddio_MouseGetEventcxx . . $ ddio_MouseGetEvent(ee4fd70245e09a47).(&msebtn, &state)) {
277 // mprintf(2, "mouse #%d state %d at %04d %04d\n", msebtn, UI_input.b1_status, UI_input.mx, UI_input.my);
278 if (msebtn == 0) {
279 UI_inputcxx . . $ UI_input..b1_last_statuscxx . . $ tUIInput#b1_last_status. = UI_inputcxx . . $ UI_input..b1_statuscxx . . $ tUIInput#b1_status.;
280 UI_inputcxx . . $ UI_input..b1_statuscxx . . $ tUIInput#b1_status. = state ? UIMSEBTN_PRESSEDcxx . . $ `ui/uisys.h:27:9`! : UIMSEBTN_RELEASEDcxx . . $ `ui/uisys.h:28:9`!;
281 UI_inputcxx . . $ UI_input..b1_countcxx . . $ tUIInput#b1_count. = 1;
282 // mprintf(0, "M");
283 return true;
284 } else {
285 UI_inputcxx . . $ UI_input..b1_statuscxx . . $ tUIInput#b1_status. = 0;
286 }
287 } else {
288 if (UI_inputcxx . . $ UI_input..b1_countcxx . . $ tUIInput#b1_count. == 0) {
289 // this frame, there was no down or up event, so now we can check if we should
290 // report button 1's state.
291 UI_inputcxx . . $ UI_input..b1_last_statuscxx . . $ tUIInput#b1_last_status. = UI_inputcxx . . $ UI_input..b1_statuscxx . . $ tUIInput#b1_status.;
292 UI_inputcxx . . $ UI_input..b1_countcxx . . $ tUIInput#b1_count. = 1;
293 if (CHECK_FLAGcxx . . $ `lib/Macros.h:63:9`!(btn_mask, MOUSE_LBcxx . . $ `ddio/ddio.h:243:9`!)) {
294 // process repeat key events.
295 UI_inputcxx . . $ UI_input..b1_statuscxx . . $ tUIInput#b1_status. = UIMSEBTN_PRESSEDcxx . . $ `ui/uisys.h:27:9`!;
296 // mprintf(0, "m");
297 return true;
298 }
299 UI_inputcxx . . $ UI_input..b1_statuscxx . . $ tUIInput#b1_status. = 0;
300 }
301 }
302 }
303 return false;
304 }
305 bool ui_KeyPollcxx . . $ ui_KeyPoll(c9857a73d68e59ba).() {
306 int key;
307 key = ddio_KeyInKeycxx . . $ ddio_KeyInKey(b126dc7c1de90089).();
308 if (key == KEY_PRINT_SCREENcxx . . $ `ddio/ddio_common.h:322:9`!)
309 UI_inputcxx . . $ UI_input..printscreencxx . . $ tUIInput#printscreen. = true;
310 UI_inputcxx . . $ UI_input..last_keycxx . . $ tUIInput#last_key. = UI_inputcxx . . $ UI_input..keycxx . . $ tUIInput#key.;
311 UI_inputcxx . . $ UI_input..last_key_statuscxx . . $ tUIInput#last_key_status. = UI_inputcxx . . $ UI_input..key_statuscxx . . $ tUIInput#key_status.;
312 // messy hack for pause key
313 if ((key & 0x00ff) == KEY_PAUSEcxx . . $ `ddio/ddio_common.h:323:9`!) {
314 key = key & 0xff;
315 }
316 UI_inputcxx . . $ UI_input..keycxx . . $ tUIInput#key. = key;
317 if (UI_inputcxx . . $ UI_input..keycxx . . $ tUIInput#key.) {
318 if (ddio_GetAdjKeyStatecxx . . $ ddio_GetAdjKeyState(83c267b20bac841a).(UI_inputcxx . . $ UI_input..keycxx . . $ tUIInput#key.)) {
319 UI_inputcxx . . $ UI_input..key_statuscxx . . $ tUIInput#key_status. = UIKEY_PRESSEDcxx . . $ `ui/uisys.h:31:9`!;
320 UI_inputcxx . . $ UI_input..key_first_presscxx . . $ tUIInput#key_first_press. = true;
321 } else {
322 UI_inputcxx . . $ UI_input..key_statuscxx . . $ tUIInput#key_status. = UIKEY_CLICKEDcxx . . $ `ui/uisys.h:33:9`!;
323 UI_inputcxx . . $ UI_input..key_first_presscxx . . $ tUIInput#key_first_press. = true;
324 }
325 } else if (UI_inputcxx . . $ UI_input..last_keycxx . . $ tUIInput#last_key. && UI_inputcxx . . $ UI_input..last_key_statuscxx . . $ tUIInput#last_key_status. == UIKEY_PRESSEDcxx . . $ `ui/uisys.h:31:9`!) {
326 if (ddio_GetAdjKeyStatecxx . . $ ddio_GetAdjKeyState(83c267b20bac841a).(UI_inputcxx . . $ UI_input..last_keycxx . . $ tUIInput#last_key.)) {
327 UI_inputcxx . . $ UI_input..keycxx . . $ tUIInput#key. = UI_inputcxx . . $ UI_input..last_keycxx . . $ tUIInput#last_key.;
328 UI_inputcxx . . $ UI_input..key_statuscxx . . $ tUIInput#key_status. = UIKEY_PRESSEDcxx . . $ `ui/uisys.h:31:9`!;
329 UI_inputcxx . . $ UI_input..key_first_presscxx . . $ tUIInput#key_first_press. = false;
330 } else {
331 UI_inputcxx . . $ UI_input..key_statuscxx . . $ tUIInput#key_status. = UIKEY_RELEASEDcxx . . $ `ui/uisys.h:32:9`!;
332 UI_inputcxx . . $ UI_input..keycxx . . $ tUIInput#key. = UI_inputcxx . . $ UI_input..last_keycxx . . $ tUIInput#last_key.;
333 UI_inputcxx . . $ UI_input..key_first_presscxx . . $ tUIInput#key_first_press. = false;
334 }
335 } else {
336 UI_inputcxx . . $ UI_input..key_statuscxx . . $ tUIInput#key_status. = 0;
337 UI_inputcxx . . $ UI_input..key_first_presscxx . . $ tUIInput#key_first_press. = false;
338 }
339 // mprintf(0, "key=%d status=%d.\n", UI_input.key, UI_input.key_status);
340 return UI_inputcxx . . $ UI_input..keycxx . . $ tUIInput#key. ? true : false;
341 }
342 // ability to load/use mouse cursors
343 void ui_UseCursorcxx . . $ ui_UseCursor(85c52e162fed56f9).(const char *fname) {
344 if (UI_cursor_bmcxx . . $ UI_cursor_bm. > -1)
345 bm_FreeBitmapcxx . . $ bm_FreeBitmap(d4f767463ce0a6b3).(UI_cursor_bmcxx . . $ UI_cursor_bm.);
346 UI_cursor_bmcxx . . $ UI_cursor_bm. = bm_AllocLoadFileBitmapcxx . . $ bm_AllocLoadFileBitmap(1163be050dbfff7).(fname, 0);
347 ASSERTcxx . . $ `misc/pserror.h:246:9`!(UI_cursor_bm > -1);
348 }
349 // adds a window to the ui list.
350 void ui_AddWindowcxx . . $ ui_AddWindow(e2cbbde2a2931ad2).(UIWindowcxx . . $ UIWindow# *wnd) {
351 tUIWindowNodecxx . . $ tUIWindowNode# *newnode = new tUIWindowNodecxx . . $ tUIWindowNode#;
352
353 if (!UIWindowListcxx . . $ UIWindowList.) {
354 // first item to add to list.
355 UIWindowListcxx . . $ UIWindowList. = newnode;
356 newnode->prevcxx . . $ tUIWindowNode#prev. = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!;
357 } else {
358 // add to existing list.
359 tUIWindowNodecxx . . $ tUIWindowNode# *node = UIWindowListcxx . . $ UIWindowList.;
360 while (node->nextcxx . . $ tUIWindowNode#next.) {
361 node = node->nextcxx . . $ tUIWindowNode#next.;
362 }
363 node->nextcxx . . $ tUIWindowNode#next. = newnode;
364 newnode->prevcxx . . $ tUIWindowNode#prev. = node;
365 }
366 newnode->nextcxx . . $ tUIWindowNode#next. = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!;
367 newnode->wndcxx . . $ tUIWindowNode#wnd. = wnd;
368 UIWindowTailcxx . . $ UIWindowTail. = newnode;
369 }
370 // removes a window from ui list.if topmost, the next topmost window has focus.
371 void ui_RemoveAllWindowscxx . . $ ui_RemoveAllWindows(49f6e7a06ebc5aa8).() {
372 int count = 0;
373 while (UIWindowTailcxx . . $ UIWindowTail.) {
374 ui_RemoveWindowcxx . . $ ui_RemoveWindow(e2cbbde2a2931ad2).(UIWindowTailcxx . . $ UIWindowTail.->wndcxx . . $ tUIWindowNode#wnd.);
375 count++;
376 ASSERTcxx . . $ `misc/pserror.h:246:9`!(count < 50);
377 }
378 if (count) {
379 mprintfcxx . . $ `ddebug/mono.h:82:9`!(0, "%d UI windows left open. Closed them!\n", count);
380 }
381 }
382 // removes a window from ui list.
383 void ui_RemoveWindowcxx . . $ ui_RemoveWindow(e2cbbde2a2931ad2).(UIWindowcxx . . $ UIWindow# *wnd) {
384 tUIWindowNodecxx . . $ tUIWindowNode# *node = UIWindowListcxx . . $ UIWindowList.;
385 bool found_wnd = false;
386 while (node) {
387 if (node->wndcxx . . $ tUIWindowNode#wnd. == wnd) {
388 // we found a node.
389 if (node->prevcxx . . $ tUIWindowNode#prev.) {
390 node->prevcxx . . $ tUIWindowNode#prev.->nextcxx . . $ tUIWindowNode#next. = node->nextcxx . . $ tUIWindowNode#next.;
391 }
392 if (node->nextcxx . . $ tUIWindowNode#next.) {
393 node->nextcxx . . $ tUIWindowNode#next.->prevcxx . . $ tUIWindowNode#prev. = node->prevcxx . . $ tUIWindowNode#prev.;
394 }
395 if (node == UIWindowListcxx . . $ UIWindowList.) {
396 UIWindowListcxx . . $ UIWindowList. = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!;
397 UIWindowListcxx . . $ UIWindowList. = node->nextcxx . . $ tUIWindowNode#next.;
398 }
399 if (node == UIWindowTailcxx . . $ UIWindowTail.) {
400 UIWindowTailcxx . . $ UIWindowTail. = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!;
401 UIWindowTailcxx . . $ UIWindowTail. = node->prevcxx . . $ tUIWindowNode#prev.;
402 }
403 delete node;
404 found_wnd = true;
405 break;
406 }
407 node = node->nextcxx . . $ tUIWindowNode#next.;
408 }
409 ASSERTcxx . . $ `misc/pserror.h:246:9`!(found_wnd);
410 }
411 // Procedure to find which window should gain focus in the
412 // first check what window contains mouse pointer and save that window
413 // check if keystroke,
414 // then adjust focus and save as current focus
415 // else
416 // set current focus = saved mouse focus.
417 void ui_DoWindowFocuscxx . . $ ui_DoWindowFocus(49f6e7a06ebc5aa8).() {
418 // right now, the topmost window always has focus!
419 tUIWindowNodecxx . . $ tUIWindowNode# *wndnode = UIWindowTailcxx . . $ UIWindowTail.;
420 if (wndnode)
421 UIWindowFocuscxx . . $ UIWindowFocus. = wndnode->wndcxx . . $ tUIWindowNode#wnd.;
422 else
423 UIWindowFocuscxx . . $ UIWindowFocus. = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!;
424 }
425 // returns a result and processes input of a window in focus
426 int ui_ProcessFocusedWindowcxx . . $ ui_ProcessFocusedWindow(b126dc7c1de90089).() {
427 int res = -1;
428 int res2;
429 // no input processing, just render frame
430 // process the window in focus.
431 // process at least once regardless of input (for user processes.)
432 // get keys. get mouse while real events (non ui manuipulated) are there.
433 ui_MousePollcxx . . $ ui_MousePoll(efaadfb7dc14930a).(false);
434 if (UIWindowFocuscxx . . $ UIWindowFocus.) {
435 UI_inputcxx . . $ UI_input..b1_countcxx . . $ tUIInput#b1_count. = 0; // button one state reset.
436 ui_KeyPollcxx . . $ ui_KeyPoll(c9857a73d68e59ba).();
437 ui_MousePollcxx . . $ ui_MousePoll(efaadfb7dc14930a).(true);
438 do {
439 res2 = UIWindowFocuscxx . . $ UIWindowFocus.->Processcxx . . $ UIWindow#Process(b126dc7c1de90089).();
440 if (res2 != -1)
441 res = res2;
442 } while (ui_MousePollcxx . . $ ui_MousePoll(efaadfb7dc14930a).(true));
443 }
444 return res;
445 }
446 // updates all visible windows.
447 void ui_UpdateWindowscxx . . $ ui_UpdateWindows(49f6e7a06ebc5aa8).() {
448 tUIWindowNodecxx . . $ tUIWindowNode# *wndnode = UIWindowListcxx . . $ UIWindowList.;
449 while (wndnode) {
450 if (wndnode->nextcxx . . $ tUIWindowNode#next. == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!) {
451 }
452 wndnode->wndcxx . . $ tUIWindowNode#wnd.->Rendercxx . . $ UIWindow#Render(49f6e7a06ebc5aa8).();
453 wndnode = wndnode->nextcxx . . $ tUIWindowNode#next.;
454 }
455 }
456 // do cursor display and update
457 void ui_DoCursorcxx . . $ ui_DoCursor(49f6e7a06ebc5aa8).() {
458 ui_StartDrawcxx . . $ ui_StartDraw(748afa4755bc9595).(0, 0, UI_screen_widthcxx . . $ UI_screen_width., UI_screen_heightcxx . . $ UI_screen_height.);
459
460 rend_SetOverlayTypecxx . . $ rend_SetOverlayType(ac50b47256ae7414).(OT_NONEcxx . . $ `lib/renderer.h:333:9`!);
461 rend_SetLightingcxx . . $ rend_SetLighting(e55526c9d3dd1656).(LS_NONEcxx . . $ LS_NONE.);
462 rend_SetColorModelcxx . . $ rend_SetColorModel(e3c5062d5af601c7).(CM_MONOcxx . . $ CM_MONO.);
463 rend_SetZBufferStatecxx . . $ rend_SetZBufferState(4af4fd0e2b26c4ac).(0);
464 rend_SetAlphaTypecxx . . $ rend_SetAlphaType(4af4fd0e2b26c4ac).(AT_CONSTANTcxx . . $ `lib/renderer.h:400:9`! + AT_TEXTUREcxx . . $ `lib/renderer.h:401:9`!);
465 rend_SetAlphaValuecxx . . $ rend_SetAlphaValue(ac50b47256ae7414).(255);
466
467 // This function needs to get called do if there are no windows, stuff gets drawn using
468 // the ui_StartDraw and ui_EndDraw
469 if (UI_cursor_showcxx . . $ UI_cursor_show. && UI_cursor_bmcxx . . $ UI_cursor_bm. > -1) {
470 ui_MousePollcxx . . $ ui_MousePoll(efaadfb7dc14930a).(false); // DAJ
471
472 float u0 = 0.0f, v0 = 0.0f, u1 = 1.0f, v1 = 1.0f;
473 int cur_w = bm_wcxx . . $ bm_w(9b79fb6aee4c0440).(UI_cursor_bmcxx . . $ UI_cursor_bm., 0);
474 int cur_h = bm_hcxx . . $ bm_h(9b79fb6aee4c0440).(UI_cursor_bmcxx . . $ UI_cursor_bm., 0);
475 if (UI_inputcxx . . $ UI_input..mxcxx . . $ tUIInput#mx. > (UI_screen_widthcxx . . $ UI_screen_width. - cur_w))
476 u1 = ((float)(UI_screen_widthcxx . . $ UI_screen_width. - UI_inputcxx . . $ UI_input..mxcxx . . $ tUIInput#mx.)) / ((float)cur_w);
477 if (UI_inputcxx . . $ UI_input..mycxx . . $ tUIInput#my. > (UI_screen_heightcxx . . $ UI_screen_height. - cur_h))
478 v1 = ((float)(UI_screen_heightcxx . . $ UI_screen_height. - UI_inputcxx . . $ UI_input..mycxx . . $ tUIInput#my.)) / ((float)cur_h);
479 if (UI_inputcxx . . $ UI_input..mxcxx . . $ tUIInput#mx. < UI_MOUSE_HOTXcxx . . $ `ui/UISystem.cpp:176:9`!)
480 u0 = (float)(UI_MOUSE_HOTXcxx . . $ `ui/UISystem.cpp:176:9`! - UI_inputcxx . . $ UI_input..mxcxx . . $ tUIInput#mx.) / (float)cur_w;
481 if (UI_inputcxx . . $ UI_input..mycxx . . $ tUIInput#my. < UI_MOUSE_HOTYcxx . . $ `ui/UISystem.cpp:177:9`!)
482 v0 = (float)(UI_MOUSE_HOTYcxx . . $ `ui/UISystem.cpp:177:9`! - UI_inputcxx . . $ UI_input..mycxx . . $ tUIInput#my.) / (float)cur_h;
483 // mprintf_at(1,5,30,"mx=%d my=%d ", UI_input.mx,UI_input.my);
484 rend_DrawScaledBitmapcxx . . $ rend_DrawScaledBitmap(bffd21ce5f93b71b).(UI_inputcxx . . $ UI_input..mxcxx . . $ tUIInput#mx. - UI_MOUSE_HOTXcxx . . $ `ui/UISystem.cpp:176:9`!, UI_inputcxx . . $ UI_input..mycxx . . $ tUIInput#my. - UI_MOUSE_HOTYcxx . . $ `ui/UISystem.cpp:177:9`!,
485 UI_inputcxx . . $ UI_input..mxcxx . . $ tUIInput#mx. + (int)((float)cur_w * u1) - UI_MOUSE_HOTXcxx . . $ `ui/UISystem.cpp:176:9`!,
486 UI_inputcxx . . $ UI_input..mycxx . . $ tUIInput#my. + (int)((float)cur_h * v1) - UI_MOUSE_HOTYcxx . . $ `ui/UISystem.cpp:177:9`!, UI_cursor_bmcxx . . $ UI_cursor_bm., u0, v0, u1, v1);
487 }
488 ui_EndDrawcxx . . $ ui_EndDraw(49f6e7a06ebc5aa8).();
489 }
490 // ui_DoFrame
491 // polls input
492 // does a ui frame given a list of windows
493 int ui_DoFramecxx . . $ ui_DoFrame(73da94e76e6bd037).(bool input) {
494 int res = -1;
495 if (!UI_initcxx . . $ UI_init.)
496 return res;
497
498 // reset this flag here, so that print screen is valid only until next call to ui_DoFrame
499 if (input)
500 UI_inputcxx . . $ UI_input..printscreencxx . . $ tUIInput#printscreen. = false;
501 if (input) {
502 ui_DoWindowFocuscxx . . $ ui_DoWindowFocus(49f6e7a06ebc5aa8).(); // determine window with current input focus.
503 res = ui_ProcessFocusedWindowcxx . . $ ui_ProcessFocusedWindow(b126dc7c1de90089).(); // process focused window
504
505 // int64_t cur_time = timer_GetMSTime();
506 while ((timer_GetTimecxx . . $ `ddio/ddio.h:236:9`!() - UI_inputcxx . . $ UI_input..cur_timecxx . . $ tUIInput#cur_time.) < UI_FRAMETIMEcxx . . $ `ui/UISystem.cpp:178:9`!) {
507 };
508
509 float temp_time = timer_GetTimecxx . . $ `ddio/ddio.h:236:9`!();
510 UIFrameTimecxx . . $ UIFrameTime. = temp_time - UI_inputcxx . . $ UI_input..cur_timecxx . . $ tUIInput#cur_time.;
511 UI_inputcxx . . $ UI_input..cur_timecxx . . $ tUIInput#cur_time. = temp_time;
512 }
513 ui_UpdateWindowscxx . . $ ui_UpdateWindows(49f6e7a06ebc5aa8).();
514 ui_DoCursorcxx . . $ ui_DoCursor(49f6e7a06ebc5aa8).(); // update mouse cursor position
515
516 return res;
517 }
518 // does a ui frame and gets mouse and key information.
519 int ui_DoFramecxx . . $ ui_DoFrame(5389c97c8c5fa9ba).(tUIInputcxx . . $ tUIInput# *input, bool doinput) {
520 int res;
521 res = ui_DoFramecxx . . $ ui_DoFrame(73da94e76e6bd037).(doinput);
522 *input =cxx . . $ tUIInput#`operator=`(e3502dab5674448a). UI_inputcxx . . $ UI_input.;
523 return res;
524 }
525 // hide and show cursor. effects are cumulative
526 bool ui_ShowCursorcxx . . $ ui_ShowCursor(c9857a73d68e59ba).() {
527 if (!UI_cursor_showcxx . . $ UI_cursor_show.) {
528 UI_cursor_showcxx . . $ UI_cursor_show. = 1;
529 return false;
530 }
531 return true;
532 }
533 bool ui_HideCursorcxx . . $ ui_HideCursor(c9857a73d68e59ba).() {
534 if (UI_cursor_showcxx . . $ UI_cursor_show.) {
535 UI_cursor_showcxx . . $ UI_cursor_show. = 0;
536 return false;
537 }
538 return true; // cursor was hidden before.
539 }
540 // set user interface screen resolution
541 void ui_SetScreenModecxx . . $ ui_SetScreenMode(3e454b8ccf442868).(int w, int h) {
542 int old_w = UI_screen_widthcxx . . $ UI_screen_width.;
543 int old_h = UI_screen_heightcxx . . $ UI_screen_height.;
544 UI_screen_widthcxx . . $ UI_screen_width. = w;
545 UI_screen_heightcxx . . $ UI_screen_height. = h;
546 UI_aspect_xcxx . . $ UI_aspect_x. = (float)w / (float)FIXED_SCREEN_WIDTHcxx . . $ `lib/grdefs.h:65:9`!;
547 UI_aspect_ycxx . . $ UI_aspect_y. = (float)h / (float)FIXED_SCREEN_HEIGHTcxx . . $ `lib/grdefs.h:66:9`!;
548 ddio_MouseResetcxx . . $ ddio_MouseReset(49f6e7a06ebc5aa8).();
549 // ddio_MouseSetLimits(0,0, UI_screen_width, UI_screen_height);
550 ddio_MouseSetVCoordscxx . . $ ddio_MouseSetVCoords(3e454b8ccf442868).(UI_screen_widthcxx . . $ UI_screen_width., UI_screen_heightcxx . . $ UI_screen_height.);
551 UI_inputcxx . . $ UI_input..cur_timecxx . . $ tUIInput#cur_time. = timer_GetTimecxx . . $ `ddio/ddio.h:236:9`!();
552 // reposition all active open windows to their correct locations in this new resolution
553 //@@ tUIWindowNode *wndnode = UIWindowList;
554 //@@ float scalar_x = -1.0f + (float)w/(float)old_w;
555 //@@ float scalar_y = -1.0f + (float)h/(float)old_h;
556 //@@
557 //@@ while (wndnode)
558 //@@ {
559 //@@ wndnode->wnd->Move(wndnode->wnd->X() + (int)(scalar_x*old_w), wndnode->wnd->Y() + (int)(scalar_y*old_h),
560 //@@ wndnode->wnd->W(), wndnode->wnd->H());
561 //@@ wndnode = wndnode->next;
562 //@@ }
563 }
564 bool ui_IsCursorVisiblecxx . . $ ui_IsCursorVisible(c9857a73d68e59ba).() { return UI_cursor_showcxx . . $ UI_cursor_show. ? true : false; }