Debian Codegraph @

Descent3/newui.h

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/newui.h $
21 * $Revision: 49 $
22 * $Date: 4/27/99 8:51a $
23 * $Author: Matt $
24 *
25 * New UI Enhancements for D3
26 *
27 * $Log: /DescentIII/Main/newui.h $
28 *
29 * 49 4/27/99 8:51a Matt
30 * Added defines for dialog title sizes
31 *
32 * 48 4/26/99 9:12p Matt
33 * Made the hotspot color full bright for old newui to make up for the
34 * removal of saturation.
35 *
36 * 47 4/25/99 3:35a Jeff
37 * added a please wait popup dialog when entering telcom
38 *
39 * 46 4/24/99 11:13p Jeff
40 * added flags for creating a newui window for a title bar
41 *
42 * 45 4/20/99 3:32p Kevin
43 * made it possible for an edit box to not have a cancel button... used it
44 * for choosing team count for server
45 *
46 * 44 4/16/99 3:58a Jeff
47 * for linux builds include linux_fix.h to get rid of some errors for
48 * stricmp
49 *
50 * 43 4/15/99 5:28p Samir
51 * added advanced messagebox
52 *
53 * 42 3/05/99 11:38a Kevin
54 * new color scheme
55 *
56 * 41 3/03/99 5:14a Jeff
57 * added DoWaitMessage()
58 *
59 * 40 2/28/99 3:06a Jeff
60 * adjust ok/cancel y offset for new ui artwork
61 *
62 * 39 2/27/99 8:34p Samir
63 * NewuiGameWindow inherits newuiTiledWindow.
64 *
65 * 38 2/21/99 6:39p Samir
66 * new edit box.
67 *
68 * 37 2/16/99 12:06p Samir
69 * added new ui api.
70 *
71 * 36 12/09/98 4:17p Samir
72 * messageboxes use new art.
73 *
74 * 35 11/10/98 5:17p Jeff
75 * fixed define for OK_CANCEL for new ui artwork
76 *
77 * 34 10/07/98 6:27p Samir
78 * added code to quit menus if mutliplayer bailed.
79 *
80 * 33 10/06/98 5:34p Jeff
81 * various UI changes/improvements
82 *
83 * 32 9/28/98 4:35p Jeff
84 * general UI changes and improvements
85 *
86 * 31 9/23/98 3:08p Jeff
87 * updated the colors and various other items of config and UI
88 *
89 * 30 9/22/98 3:55p Samir
90 * moved simple callback to NewUI system.
91 *
92 * 29 9/02/98 6:50p Samir
93 * added new combo box.
94 *
95 * 28 9/02/98 2:54p Jeff
96 * added defines for text colors to be used throughout the game...fixed up
97 * buddy menu too
98 *
99 * 27 8/27/98 2:52p Samir
100 * changing window system to work in two modes.
101 *
102 * 26 8/20/98 6:46p Samir
103 * added DoEditDialog.
104 *
105 * 25 8/19/98 2:18p Jeff
106 * changed ddio_CleanPath
107 *
108 * 24 8/14/98 7:37p Matt
109 * Since PSFILENAME_LEN is now considered to be the max length of the
110 * string itself (not counting the terminating null), buffers for file
111 * name need to be PSFILENAME_LEN+1 bytes long.
112 *
113 * 23 7/29/98 5:39p Jeff
114 * added DoPathFileDialog
115 *
116 * 22 6/22/98 2:34p Samir
117 * added ability to use a bitmap as background for NewUIWindows.
118 *
119 * 21 6/05/98 5:35p Samir
120 * added Class functions to all newui classes.
121 *
122 * 20 5/26/98 8:16p Samir
123 * implemented UIFileDialog's ONDestroy function.
124 *
125 * 19 5/25/98 8:18p Samir
126 * File dialogs implemented.
127 *
128 * 18 5/19/98 6:23p Samir
129 * added NewUIButton
130 *
131 * 17 4/29/98 12:55p Samir
132 * added titile bar to NewUIWindow.
133 *
134 * 16 4/13/98 7:01p Samir
135 * added snazzy listbox and edit box art.
136 *
137 * 15 3/24/98 10:45a Samir
138 * Added GetUICallback.
139 *
140 * 14 3/13/98 12:00p Jeff
141 * Fixed up DoMessageBox so the text position is correct, it prints a
142 * window title, and you can specify text color
143 *
144 * 13 3/11/98 2:35p Samir
145 * New message box implemented.
146 *
147 * 12 3/10/98 7:26p Samir
148 * Added new slider.
149 *
150 * 11 3/10/98 12:49p Samir
151 * Bitmapped dialog supported.
152 *
153 * 10 3/02/98 5:53p Samir
154 * Default value for alpha of windows is set.
155 *
156 * 9 2/15/98 7:07p Samir
157 * Updated NewUIWindow to UIWindow's changes.
158 *
159 * 8 2/13/98 6:37p Samir
160 * Added DoUIFrameWithoutInput.
161 *
162 * 7 2/02/98 4:31p Samir
163 * Added prototype for DoUIFrame.
164 *
165 * 6 1/30/98 7:04p Samir
166 * Added the first NewUIWindow class.
167 *
168 * 5 1/26/98 2:15p Samir
169 * Message box params are char*.
170 *
171 * 4 1/13/98 6:29p Samir
172 * Moved Large Bitmap code from Menu.cpp to newui.cpp.
173 *
174 * 3 1/08/98 12:18p Samir
175 * New menu interface.
176 *
177 * 2 1/05/98 10:56a Samir
178 * New menu stuff.
179 *
180 * 1 1/02/98 2:09p Samir
181 * Initial revision
182 *
183 *
184 * $NoKeywords: $
185 */
186
187 #ifndef NEWUI_H
188 #define NEWUI_H
189
190 #if defined(POSIX)
191 #include "linux_fix.h" //fix some of the stricmp's
192 #endif
193
194 #include "newui_core.h"
195
196 // flags for creating a newui window
197 #define NUWF_TITLENONE 0x00000000 // don't display a title bar
198 #define NUWF_TITLESMALL 0x00100000 // display a small title bar
199 #define NUWF_TITLEMED 0x00200000 // display a medium size title bar
200 #define NUWF_TITLELARGE 0x00300000 // display a large title bar
201 #define NUWF_TITLEBARMASK 0x00300000 // mask to use with flags to get title bar flags
202
203 #define NEWUI_GETTITLEBAR(flags) (flags & NUWF_TITLEBARMASK)
204
205 // the sizes of the various title bars
206 #define NUW_TITLESMALL_WIDTH 64
207 #define NUW_TITLEMED_WIDTH 128
208 #define NUW_TITLELARGE_WIDTH 196
209
210 //////////////////////////////////////////////////////////////////////////////
211 // Definitions
212
213 // The following defines are RGB definitions for colors that should be used throughout the UI for text
214 #define UICOL_HOTSPOT_LO \
215 GR_RGB(85, 234, 3) // Color for a hotspot when it isn't in focus//GR_RGB(50,50,255) // Color for a hotspot
216 // when it isn't in focus
217 #define UICOL_HOTSPOT_HI GR_WHITE // Color for a hotspot when it is in focus
218 #define UICOL_TEXT_NORMAL GR_RGB(206, 254, 241) // Color for text that is used for labels
219 #define UICOL_WINDOW_TITLE GR_RGB(207, 248, 105) // Color for window title text
220 #define UICOL_TEXT_AUX GR_RGB(200, 200, 200) // Color for auxillary text (text that isn't a label)
221 #define UICOL_LISTBOX_LO GR_RGB(85, 234, 3) // Color for listbox text that isn't in focus
222 #define UICOL_LISTBOX_HI GR_RGB(207, 248, 105) // Color for listbox text that is in focus
223 #define UICOL_BUTTON_LO GR_RGB(85, 234, 3) // Color for text on a button that isn't in focus
224 #define UICOL_BUTTON_HI GR_RGB(207, 248, 105) // Color for text on a button that is in focus
225 #define UIALPHA_HOTSPOT_LO 192 // Alpha value for hotspots not in focus
226 #define UIALPHA_HOTSPOT_HI 255 // Alpha value for hotspots in focus
227
228 // returns x coordinates to use to determine center position of text items for in a window/dialog
229 // width - total width of dialog/window
230 // gap - size (in pixels) of the gap you want between the left and right item
231 // left_item_width - the width (in pixels) of the left item
232 // right_item_width - the widht (in pixels) of the right item
233 // lx - will contain the left item's x coord
234 // rx - will contain the right item's x coord
235 void GetCenteredTextPos(int width, int gap, int left_item_width, int right_item_width, int *lx, int *rx);
236 // returns x coordinates to use to determine center position of text items for in a window/dialog
237 // width - total width of dialog/window
238 // gap - size (in pixels) of the gap you want between the left and right item
239 // left_item_width - the width (in pixels) of the left item
240 // middle_item_width - the width (in pixels) of the middle item
241 // right_item_width - the width (in pixels) of the right item
242 // lx - will contain the left item's x coord
243 // rx - will contain the right item's x coord
244 // mx - will contain the middle item's x coord
245 void GetCenteredTextPos(int width, int gap, int left_item_width, int middle_item_width, int right_item_width, int *lx,
246 int *mx, int *rx);
247
248 // The following defines are y offset values to be used for "OK","Cancel" and "Done" (take the height of the window
249 // minus the offset to get the correct y)
250 #define OKCANCEL_YOFFSET 50 // subtract this from the height of the window
251
252 #define UI_BORDERSIZE 20
253
254 #define NEWUIBMP_NUM 48
255
256 // bitmap ids for user interface bitmaps.
257 #define NEWUIBMP_DIALOG_CORNER1 0
258 #define NEWUIBMP_DIALOG_CORNER2 1
259 #define NEWUIBMP_DIALOG_CORNER3 2
260 #define NEWUIBMP_DIALOG_CORNER4 3
261 #define NEWUIBMP_DIALOG_HORIZTOP 4
262 #define NEWUIBMP_DIALOG_VERTRIGHT 5
263 #define NEWUIBMP_DIALOG_HORIZBOT 6
264 #define NEWUIBMP_DIALOG_VERTLEFT 7
265 #define NEWUIBMP_DIALOG_BACK 8
266 #define NEWUIBMP_DIALOG_PANEL 9
267 #define NEWUIBMP_MSGBOX_LEFT 10
268 #define NEWUIBMP_MSGBOX_RIGHT 11
269 #define NEWUIBMP_MSGBOX_CENTER 12
270 #define NEWUIBMP_SLIDER_BAR 13
271 #define NEWUIBMP_SLIDER_BUTTON 14
272 #define NEWUIBMP_EDIT_LEFT 15
273 #define NEWUIBMP_EDIT_CENTER 16
274 #define NEWUIBMP_EDIT_RIGHT 17
275 #define NEWUIBMP_LIST_CORNER1 18
276 #define NEWUIBMP_LIST_CORNER2 19
277 #define NEWUIBMP_LIST_CORNER3 20
278 #define NEWUIBMP_LIST_CORNER4 21
279 #define NEWUIBMP_LIST_HORIZTOP 22
280 #define NEWUIBMP_LIST_VERTRIGHT 23
281 #define NEWUIBMP_LIST_HORIZBOT 24
282 #define NEWUIBMP_LIST_VERTLEFT 25
283 #define NEWUIBMP_LIST_BACK 26
284 #define NEWUIBMP_BTN_UP 27
285 #define NEWUIBMP_BTN_DOWN 28
286 #define NEWUIBMP_BTN_HILITE 29
287 #define NEWUIBMP_BTN_UP_L 30
288 #define NEWUIBMP_BTN_DOWN_L 31
289 #define NEWUIBMP_BTN_HILITE_L 32
290 #define NEWUIBMP_BTN_UP_R 33
291 #define NEWUIBMP_BTN_DOWN_R 34
292 #define NEWUIBMP_BTN_HILITE_R 35
293
294 // Large Bitmap system
295 struct tLargeBitmap {
296 int bmps_w;
297 int bmps_h;
298 int *bm_array;
299 };
300
301 // alpha for all NewUIWindows.
302 extern uint8_t NewUIWindow_alpha;
303
304 //////////////////////////////////////////////////////////////////////////////
305 // Core interface with UI system
306
307 // load in D3 user interface resources
308 void NewUIInit();
309
310 // closes New UI system
311 void NewUIClose();
312
313 // shows or hides windows
314 void OpenUIWindow(UIWindow *wnd);
315 void CloseUIWindow(UIWindow *wnd);
316
317 //////////////////////////////////////////////////////////////////////////////
318 // quick and dirty functions
319
320 // Displays a 'temporary' dialog with a message
321 // for example:
322 // ...
323 // DoWaitMessage(true,"Please Wait...");
324 // ... //some code
325 // DoWaitMessage(false);
326 void DoWaitMessage(bool enable, const char *message = NULL);
327 void DoWaitPopup(bool enable, const char *message = NULL);
328
329 // puts up a message box with a title and message.
330 int DoMessageBox(const char *title, const char *msg, int type, ddgr_color title_color = UICOL_WINDOW_TITLE,
331 ddgr_color text_color = UICOL_TEXT_NORMAL);
332
333 // puts up a message box with a title and message.
334 // define text for buttons, btn0_title, btn1_title, ..., until NULL.
335 // also define hotkey for button immediately after title is defined.
336 //
337 // DoMessageBoxAdvanced("Title", "Hi", "Abort", KEY_A, "Retry", KEY_R, "Cancel", KEY_ESC, NULL)
338 //
339 // if button with btn0_title pressed, returns 0, btn1_title, returns 1, etc.
340 // safe for up to three buttons.
341 int DoMessageBoxAdvanced(const char *title, const char *msg, const char *btn0_title, int key0, ...);
342
343 // edit dialog.
344 bool DoEditDialog(const char *title, char *buffer, int buflen, bool showcancel = true);
345
346 // puts up a file selector box
347 // Parameters: max_filename_len - the max length for the filename. filebuf have a length of at least max_filename_len+1
348 bool DoFileDialog(const char *title, const char *search_path, const char *ext, char *filebuf,
349 unsigned max_filename_len);
350
351 #define PFDF_FILEMUSTEXIST 0x0001
352 // Displays a file dialog that is very much like a Windows file dialog (you can move around directories)
353 // save_dialog = is this dialog being used to save file, or load a file. If save, than pass true
354 // path = on entry is the initial path to start in (must be set...set to 0 length string to go to root directory)
355 // on exit it is the absolute path to selected file on return (if return is true) must be at least
356 //_MAX_PATH in size title = Title of the dialog wildc = semicolon seperated list of wildcards
357 //("*.txt;*.doc;*.exe")
358 bool DoPathFileDialog(bool save_dialog, char *path, const char *title, const char *wildc, int flags);
359
360 //////////////////////////////////////////////////////////////////////////////
361 // quick and dirty functions
362
363 int LoadLargeBitmap(const char *filename, tLargeBitmap *bmp);
364 void FreeLargeBitmap(tLargeBitmap *bmp);
365 void DrawLargeBitmap(tLargeBitmap *bmp, int x, int y, float alpha);
366
367 //////////////////////////////////////////////////////////////////////////////
368 // NewUI Classes
369
370 const tUIClass newuiWindow = uiNewClass, newuiGameWindow = uiNewClass + 1;
371 // newuiMessageBox = uiNewClass+2,
372 // newuiSlider = uiNewClass+3,
373 // newuiEdit = uiNewClass+4,
374 // newuiListBox = uiNewClass+5,
375 // newuiButton = uiNewClass+6;
376
377 const tUIClass newuiNewClass = 1000;
378
379 // NewUIGameWindow
380 // this draws a UI window, but with a not-so-cool faded background.
381
382 class NewUIWindow : public UIWindow {
383 chunked_bitmap m_Chunk;
384
385 public:
386 NewUIWindow();
387
388 void Create(int x, int y, int w, int h, int flags = UIF_PROCESS_MENU);
389
390 virtual tUIClass Class() const { // Overide this function to name the class
391 return newuiWindow;
392 };
393
394 // specify filename of image to use as background.
395 void LoadBackgroundImage(const char *image_name);
396
397 // ui system overridables
398 protected:
399 virtual void OnDraw(); // overridable draws the window background before gadgets
400 virtual void OnDestroy(); // when window is nuked.
401 };
402
403 // NewUIGameWindow
404 // this draws a UI window, but with the cool standard game dialog background.
405
406 class NewUIGameWindow : public newuiTiledWindow {
407 public:
408 NewUIGameWindow();
409
410 void Create(int x, int y, int w, int h, int flags = UIF_PROCESS_MENU);
411
412 virtual tUIClass Class() const { // Overide this function to name the class
413 return newuiGameWindow;
414 };
415 };
416
417 // NewUIMessageBox
418 // this draws a UI window, but with the cool standard game dialog background.
419
420 class NewUIMessageBox : public NewUIGameWindow {
421 public:
422 NewUIMessageBox();
423
424 void Create(int x, int y, int w, int flags = 0);
425 };
426
427 // NewUISlider
428 // this draws a nicer loking slider.
429
430 class NewUISlider : public UISlider {
431 UIBitmapItem m_SliderBar;
432 UIBitmapItem m_Slider;
433
434 public:
435 void Create(UIWindow *parent, int id, int x, int y, int flags = 0);
436 };
437
438 // NewUIEdit
439 // this draws a nicer edit box
440
441 class NewUIEdit : public UIEdit {
442 UIBitmapItem m_EditLeft;
443 UIBitmapItem m_EditCen;
444 UIBitmapItem m_EditRight;
445
446 int m_TileWidth;
447
448 public:
449 void Create(UIWindow *parent, int id, int x, int y, int w, int h, int flags = 0);
450
451 // ui system overridables
452 protected:
453 virtual void OnDraw(); // overridable draws the background first
454 };
455
456 // NewUIListBox
457 // this draws a nicer list box
458
459 class NewUIListBox : public UIListBox {
460 UIBitmapItem m_BackNW;
461 UIBitmapItem m_BackN;
462 UIBitmapItem m_BackNE;
463 UIBitmapItem m_BackE;
464 UIBitmapItem m_BackSE;
465 UIBitmapItem m_BackS;
466 UIBitmapItem m_BackSW;
467 UIBitmapItem m_BackW;
468 UIBitmapItem m_Back;
469
470 int m_TileWidth;
471 int m_TileHeight;
472
473 public:
474 void Create(UIWindow *parent, int id, int x, int y, int w, int h, int flags = 0);
475
476 // ui system overridables
477 protected:
478 virtual void OnDraw(); // overridable draws the background first
479 };
480
481 // NewUIComboBox
482 // displays a listbox just one item.
483
484 class NewUIComboBox : public UIComboBox {
485 UIBitmapItem m_CmbLeft;
486 UIBitmapItem m_CmbCen;
487 UIBitmapItem m_CmbRight;
488
489 int m_TileWidth;
490
491 public:
492 void Create(UIWindow *parent, int id, int x, int y, int w, int flags = 0);
493
494 // ui system overridables
495 protected:
496 virtual void OnDraw(); // overridable draws the background first
497 };
498
499 // NewUIButton
500 // a nicer fixed size button.
501
502 class NewUIButton : public UIButton {
503 UIBitmapItem m_BtnUpL, m_BtnUpC, m_BtnUpR;
504 UIBitmapItem m_BtnDownL, m_BtnDownC, m_BtnDownR;
505 UIBitmapItem m_BtnHiliteL, m_BtnHiliteC, m_BtnHiliteR;
506
507 UIItem *m_BtnTitle;
508
509 int m_TileWidth;
510
511 public:
512 NewUIButton() { m_BtnTitle = NULL; };
513
514 virtual ~NewUIButton() {
515 if (m_BtnTitle)
516 delete m_BtnTitle;
517 };
518
519 void Create(UIWindow *parent, int id, UIItem *item, int x, int y, int w, int h, int flags = 0);
520 void SetTitle(UIItem *item);
521
522 // ui system overridables
523 protected:
524 virtual void OnDraw(); // overridable draws the background first
525 virtual void OnFormat(); // override: called when resized or before drawing.
526 };
527
528 // NewUIFileDialog
529 // this draws a file lister.
530
531 class NewUIFileDialog : public NewUIGameWindow {
532 NewUIListBox m_ListBox;
533 NewUIButton m_Ok;
534 NewUIButton m_Cancel;
535 UIText m_TitleStr;
536
537 UITextItem *m_FileItems; // file item array.
538
539 char m_SearchPath[_MAX_PATH];
540 char m_SearchExt[PSFILENAME_LEN + 1];
541 char m_NewPath[_MAX_PATH];
542
543 private:
544 void UpdateList();
545
546 public:
547 void Create(const char *title, int x, int y, int w, int h, const char *path, const char *filecard);
548
549 void SetSearchPath(const char *path);
550 const char *GetFilename();
551
552 public:
553 // call this function to execute dialog.
554 virtual bool DoModal();
555
556 protected:
557 virtual void OnDestroy();
558 };
559
560 #endif