| 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 | * $Source: $ |
| 21 | * $Revision: 27 $ |
| 22 | * $Author: Samir $ |
| 23 | * $Date: 4/29/99 2:18a $ |
| 24 | * |
| 25 | * new NewUI Header |
| 26 | * |
| 27 | * $Log: /DescentIII/main/newui_core.h $ |
| 28 | * |
| 29 | * 27 4/29/99 2:18a Samir |
| 30 | * updated art for options style menu. |
| 31 | * |
| 32 | * 26 4/28/99 1:54a Samir |
| 33 | * visual tweaks to text |
| 34 | * |
| 35 | * 25 4/27/99 2:13p Matt |
| 36 | * Replaced the two (new) new UI fonts with one new font from Doug. |
| 37 | * |
| 38 | * 24 4/27/99 9:24a Matt |
| 39 | * Added system for drawing title bars on dialogs. |
| 40 | * |
| 41 | * 23 4/26/99 7:46p Samir |
| 42 | * newuiTiledWindow flags passed to create is an int now. |
| 43 | * |
| 44 | * 22 4/21/99 10:58a Samir |
| 45 | * added changable text. |
| 46 | * |
| 47 | * 21 4/20/99 11:46a Samir |
| 48 | * numerous ui 'feel' fixes. |
| 49 | * |
| 50 | * 20 4/18/99 7:55p Samir |
| 51 | * fixed listbox double click and added functions to load and release |
| 52 | * pertinent newui graphic data. |
| 53 | * |
| 54 | * 19 4/15/99 5:28p Samir |
| 55 | * added advanced messagebox |
| 56 | * |
| 57 | * 18 4/05/99 5:13p Samir |
| 58 | * fixed combo box asthetics. |
| 59 | * |
| 60 | */ |
| 61 | |
| 62 | #ifndef NEWUI_CORE_H |
| 63 | #define NEWUI_CORE_H |
| 64 | |
| 65 | #include "ui.h" |
| 66 | |
| 67 | #define N_NEWUI_BMPS 32 // number of ui bitmaps. |
| 68 | #define N_NEWUI_SHEETS 8 // number of sheets allowed in a menu. |
| 69 | |
| 70 | #define NEWUI_MONITORFONT_COLOR GR_GREEN // GR_RGB(255,255,255) |
| 71 | #define NEWUI_GADGETFONT_COLOR GR_BLACK // GR_RGB(255,255,255) |
| 72 | |
| 73 | #define NEWUI_GADGETFONT_HICOLOR GR_RGB(192, 192, 0) |
| 74 | |
| 75 | #ifndef MSGBOX_OK |
| 76 | // types of message boxes |
| 77 | #define MSGBOX_NULL 0 |
| 78 | #define MSGBOX_OK 1 |
| 79 | #define MSGBOX_OKCANCEL 2 |
| 80 | #define MSGBOX_YESNO 3 |
| 81 | #endif |
| 82 | |
| 83 | // used internally for ease of management |
| 84 | #define N_DIRECTIONS 12 |
| 85 | #define N_PIECE_IDX 0 |
| 86 | #define NE_PIECE_IDX 1 |
| 87 | #define E_PIECE_IDX 2 |
| 88 | #define SE_PIECE_IDX 3 |
| 89 | #define S_PIECE_IDX 4 |
| 90 | #define SW_PIECE_IDX 5 |
| 91 | #define W_PIECE_IDX 6 |
| 92 | #define NW_PIECE_IDX 7 |
| 93 | #define C_PIECE_IDX 8 |
| 94 | #define TL_PIECE_IDX 9 |
| 95 | #define TC_PIECE_IDX 10 |
| 96 | #define TR_PIECE_IDX 11 |
| 97 | |
| 98 | // types of 'arrow' buttons used in newuiArrowButton |
| 99 | #define NEWUI_ARROW_LEFT 0x1 |
| 100 | #define NEWUI_ARROW_RIGHT 0x2 |
| 101 | #define NEWUI_ARROW_UP 0x3 |
| 102 | #define NEWUI_ARROW_DOWN 0x4 |
| 103 | #define NEWUI_ARROW_CBUP 0x5 |
| 104 | #define NEWUI_ARROW_CBDOWN 0x6 |
| 105 | |
| 106 | // initializes the core system for the newui |
| 107 | void newuiCore_Init(); |
| 108 | |
| 109 | // initializes the core system for the newui |
| 110 | void newuiCore_Close(); |
| 111 | |
| 112 | // touches all newui bitmaps, do before any newui menus open |
| 113 | void newuiCore_PageInBitmaps(); |
| 114 | |
| 115 | // call when NO newui menus open |
| 116 | void newuiCore_ReleaseBitmaps(); |
| 117 | |
| 118 | // C interface to load and free bitmap resources |
| 119 | UIBitmapItem *newui_LoadBitmap(const char *filename); |
| 120 | |
| 121 | // C interface to load and free bitmap resources |
| 122 | void newui_FreeBitmap(UIBitmapItem *bmitem); |
| 123 | |
| 124 | // sets the callback for background rendering of desktop for UI |
| 125 | #define DEFAULT_UICALLBACK ((void (*)())1) |
| 126 | |
| 127 | void SetUICallback(void (*fn)()); |
| 128 | void (*GetUICallback())(); |
| 129 | |
| 130 | // predefined return values for DoUI or UI_frame_result. |
| 131 | #define NEWUIRES_FORCEQUIT -2 |
| 132 | |
| 133 | // does a UI loop: returns a result value for the current window in focus. |
| 134 | int DoUI(); |
| 135 | |
| 136 | // does one frame of UI input (returns result.) |
| 137 | void DoUIFrame(); |
| 138 | |
| 139 | // does one frame of UI without polling input. |
| 140 | void DoUIFrameWithoutInput(); |
| 141 | |
| 142 | // gets frame result of ui input. |
| 143 | int GetUIFrameResult(); |
| 144 | |
| 145 | ////////////////////////////////////////////////////////////////////////////// |
| 146 | |
| 147 | // CLASS simple buttons |
| 148 | |
| 149 | class newuiSlider; |
| 150 | class newuiCheckBox; |
| 151 | class newuiRadioButton; |
| 152 | class newuiButton; |
| 153 | class newuiMenu; |
| 154 | class newuiListBox; |
| 155 | class newuiEditBox; |
| 156 | class newuiComboBox; |
| 157 | class newuiHotspot; |
| 158 | |
| 159 | #define DEFAULT_NEWUID -5 |
| 160 | |
| 161 | enum tAlignment { NEWUI_ALIGN_VERT, NEWUI_ALIGN_HORIZ }; |
| 162 | |
| 163 | #define SLIDER_UNITS_INT 0 |
| 164 | #define SLIDER_UNITS_PERCENT 1 |
| 165 | #define SLIDER_UNITS_FLOAT 2 |
| 166 | |
| 167 | // used optionally for sliders. |
| 168 | struct tSliderSettings { |
| 169 | union { |
| 170 | int i; |
| 171 | float f; |
| 172 | } min_val; |
| 173 | union { |
| 174 | int i; |
| 175 | float f; |
| 176 | } max_val; |
| 177 | int type; // enumerated above in SLIDER_UNITS |
| 178 | }; |
| 179 | |
| 180 | #define NEWUI_EDIT_CANCELED_STR "\1" // if a newuiEditbox returns this, then we cancelled. invalid string |
| 181 | |
| 182 | #define NEWUI_EDIT_BUFLEN 63 |
| 183 | |
| 184 | #define NEWUI_BTNF_FRAMED UIF_CUSTOMF // when Adding a button, this button have 'framed' art. |
| 185 | #define NEWUI_BTNF_LONG (UIF_CUSTOMF << 1) // button will be a long version (with art) |
| 186 | |
| 187 | // CLASS contains gadgets |
| 188 | |
| 189 | class newuiSheet { |
| 190 | int m_sx, m_sy; // origin of sheet gadgets relative to parent. |
| 191 | int16_t m_initial_focus_id; // gadget that will have focus upon realization. |
| 192 | |
| 193 | public: |
| 194 | newuiSheet(); |
| 195 | |
| 196 | // called usually by other classes, used to initialize the sheet |
| 197 | void Create(UIWindow *menu, const char *title, int n_items, int sx, int sy); |
| 198 | |
| 199 | // deallocates memory |
| 200 | void Destroy(); |
| 201 | |
| 202 | // get properties |
| 203 | int X() const { return m_sx; }; |
| 204 | int Y() const { return m_sy; }; |
| 205 | |
| 206 | // resets gadget list |
| 207 | void Reset(); |
| 208 | |
| 209 | // call this to initialize gadgets specified above in parent window |
| 210 | void Realize(); |
| 211 | |
| 212 | // call this to release gadgets specified above in parent window, retreives checkbox,radio,etc values too. |
| 213 | void Unrealize(); |
| 214 | |
| 215 | // ALL following functions that return a pointer, that pointer contains the value of the gadget added |
| 216 | // i.e. checkbox will have a true or false value. you can use this pointer to modify gadget values. |
| 217 | // to validate these modifications, call 'UpdateChanges'. (done internally most of the time) |
| 218 | |
| 219 | // call these functions to determine if a pointer's value has changed after call to UpdateReturnValues (internal) |
| 220 | bool HasChanged(bool *bptr); |
| 221 | bool HasChanged(int16_t *sptr); |
| 222 | bool HasChanged(int *iptr); |
| 223 | bool HasChanged(char *cptr); |
| 224 | |
| 225 | // obtain's pointer to gadget of respective item. it is your responsibility to typecast the gadget |
| 226 | // only works if you specified an ID! Also the sheet must have been realized by now. |
| 227 | UIGadget *GetGadget(int16_t id); |
| 228 | |
| 229 | // set focus on this gadget specified by id upon realization. |
| 230 | void SetInitialFocusedGadget(int16_t id); |
| 231 | |
| 232 | // creates gadget list.pix_offset is the pixel offset from the group title to the first control. |
| 233 | void NewGroup(const char *title, int16_t x, int16_t y, tAlignment align = NEWUI_ALIGN_VERT, int16_t pix_offset = -1); |
| 234 | |
| 235 | // adds standard button to current group. (flags see NEWUI_BTNF_xxxx) |
| 236 | void AddButton(const char *title, int16_t id, int16_t flags = 0); |
| 237 | |
| 238 | // adds a long button (flags see NEWUI_BTNF_xxxx) |
| 239 | void AddLongButton(const char *title, int16_t id, int16_t flags = 0); |
| 240 | |
| 241 | // adds checkbox to current group. initial state of checkbox can be set. |
| 242 | bool *AddCheckBox(const char *title, bool init_state = false, int16_t id = DEFAULT_NEWUID); |
| 243 | |
| 244 | // adds long checkbox to current group. initial state of checkbox can be set. |
| 245 | bool *AddLongCheckBox(const char *title, bool init_state = false, int16_t id = DEFAULT_NEWUID); |
| 246 | |
| 247 | // adds a radio button to current group. initial state of radio may be set |
| 248 | // pointer returned will return index of radio button in group currently selected. |
| 249 | int *AddFirstRadioButton(const char *title, int16_t id = DEFAULT_NEWUID); |
| 250 | |
| 251 | // adds a radio button to current group. initial state of radio may be set |
| 252 | void AddRadioButton(const char *title, int16_t id = DEFAULT_NEWUID); |
| 253 | |
| 254 | // adds a radio button to current group. initial state of radio may be set |
| 255 | int *AddFirstLongRadioButton(const char *title, int16_t id = DEFAULT_NEWUID); |
| 256 | |
| 257 | // adds a radio button to current group. initial state of radio may be set |
| 258 | void AddLongRadioButton(const char *title, int16_t id = DEFAULT_NEWUID); |
| 259 | |
| 260 | // adds a slider, set the range for it too., returns two values, int16_t[0] = position, int16_t[1] = range |
| 261 | int16_t *AddSlider(const char *title, int16_t range, int16_t init_pos = 0, tSliderSettings *settings = NULL, |
| 262 | int16_t id = DEFAULT_NEWUID); |
| 263 | |
| 264 | // adds a static text item |
| 265 | void AddText(const char *text, ...); |
| 266 | |
| 267 | // adds a static bitmap |
| 268 | void AddBitmap(int bm_handle); |
| 269 | |
| 270 | // adds a static text item |
| 271 | char *AddChangeableText(int buflen); |
| 272 | |
| 273 | // adds a listbox |
| 274 | newuiListBox *AddListBox(int16_t w, int16_t h, int16_t id, uint16_t flags = 0); |
| 275 | |
| 276 | // adds a listbox |
| 277 | newuiComboBox *AddComboBox(int16_t id, uint16_t flags = 0); |
| 278 | |
| 279 | // adds an edit box |
| 280 | char *AddEditBox(const char *title, int16_t maxlen = NEWUI_EDIT_BUFLEN, int16_t w = 0, int16_t id = DEFAULT_NEWUID, |
| 281 | int16_t flags = 0, bool return_on_esc = false); |
| 282 | |
| 283 | // adds a hotspot :(, should word wrap too. |
| 284 | void AddHotspot(const char *title, int16_t w, int16_t h, int16_t id, bool group = false); |
| 285 | |
| 286 | // THESE FUNCTIONS ARE CALLED BY FRAMEWORK, BUT IF YOU NEED TO DO SOME CUSTOM UI HANDLING, THESE |
| 287 | // FUNCTIONS ARE MADE PUBLIC. |
| 288 | public: |
| 289 | // refreshes gadget states with values passed to the pointers returned by the below functions |
| 290 | // depends on no direct manipulation of gadgets outside framework. |
| 291 | void UpdateChanges(); |
| 292 | |
| 293 | // refreshes return values of gadgets, so they are accessible by the pointers returned by below functions |
| 294 | // if a gadget has changed since last call to DoUI, the user can tell this by calling HasChanged |
| 295 | void UpdateReturnValues(); |
| 296 | |
| 297 | private: |
| 298 | struct t_gadget_desc { |
| 299 | int8_t type; // enumerated ui gadget type |
| 300 | bool changed; // parameters are different than defaults? |
| 301 | int16_t id; // id value |
| 302 | char *title; // title of gadget |
| 303 | union { |
| 304 | int i; |
| 305 | int16_t s[2]; |
| 306 | bool b; |
| 307 | void *p; |
| 308 | } parm; // parameter list. |
| 309 | union { |
| 310 | UIGadget *gadget; |
| 311 | UIText *text; |
| 312 | newuiSlider *slider; |
| 313 | newuiCheckBox *chbox; |
| 314 | newuiRadioButton *radio; |
| 315 | newuiButton *button; |
| 316 | newuiListBox *lb; |
| 317 | newuiComboBox *cb; |
| 318 | newuiEditBox *edit; |
| 319 | newuiHotspot *hot; |
| 320 | } obj; |
| 321 | void *internal; // internal info. |
| 322 | } *m_gadgetlist; |
| 323 | |
| 324 | UIWindow *m_parent; |
| 325 | int m_ngadgets, m_gadgetlimit; |
| 326 | bool m_realized; |
| 327 | char *m_title; |
| 328 | |
| 329 | t_gadget_desc *AddGadget(int16_t id, int8_t type, const char *title); |
| 330 | |
| 331 | public: |
| 332 | const char *GetTitle() { return m_title; }; |
| 333 | }; |
| 334 | |
| 335 | // CLASS new button class. |
| 336 | |
| 337 | class newuiButton : virtual public UIButton { |
| 338 | public: |
| 339 | newuiButton(); |
| 340 | |
| 341 | // see (NEWUI_BTNF_xxx) flags |
| 342 | void Create(UIWindow *wnd, int16_t id, const char *name, int16_t x, int16_t y, int16_t flags = 0); |
| 343 | |
| 344 | protected: |
| 345 | virtual void OnDraw(); // overridable draws the background first |
| 346 | virtual void OnDestroy(); // override: frees memory and such. |
| 347 | virtual void OnFormat(); // new formatting |
| 348 | virtual void OnLostFocus(); |
| 349 | virtual void OnGainFocus(); |
| 350 | |
| 351 | UIBitmapItem *m_bkg, *m_litbkg; // used to define visual characteristics of button |
| 352 | UISnazzyTextItem *m_text; |
| 353 | |
| 354 | // this is used in multiple inheritance cases.(flags are additional attributes usually passed when creating gadget) |
| 355 | void InitStates(const char *name, bool is_long, int16_t flags = 0); |
| 356 | |
| 357 | public: |
| 358 | UISnazzyTextItem *GetTitle() { return m_text; }; |
| 359 | }; |
| 360 | |
| 361 | // CLASS a large option button used in menus. |
| 362 | |
| 363 | class newuiMenuOptionButton : public newuiButton { |
| 364 | public: |
| 365 | void Create(newuiMenu *menu, newuiMenuOptionButton *last, int16_t id, const char *name, int16_t x, int16_t y, |
| 366 | bool m_mono_press); |
| 367 | |
| 368 | protected: |
| 369 | void OnMouseBtnDown(int btn); |
| 370 | void OnMouseBtnUp(int btn); |
| 371 | virtual void OnKeyDown(int key); |
| 372 | virtual void OnKeyUp(int key); |
| 373 | |
| 374 | private: |
| 375 | bool m_mono_press; |
| 376 | newuiMenuOptionButton *m_prev_btn, *m_next_btn; |
| 377 | }; |
| 378 | |
| 379 | class newuiTinyButton : public newuiButton { |
| 380 | public: |
| 381 | void Create(UIWindow *wnd, int16_t id, const char *name, int16_t x, int16_t y); |
| 382 | }; |
| 383 | |
| 384 | // CLASS creates an arrow button that is sensitive to touch (when down, always select) |
| 385 | |
| 386 | class newuiArrowButton : public newuiButton { |
| 387 | public: |
| 388 | newuiArrowButton(){}; |
| 389 | |
| 390 | void Create(UIWindow *wnd, int16_t id, int16_t type, const char *name, int16_t x, int16_t y); |
| 391 | void Show(bool show = true); // this will activate or deactivate a button. |
| 392 | |
| 393 | protected: |
| 394 | virtual void OnMouseBtnDown(int btn); |
| 395 | virtual void OnMouseBtnUp(int btn); |
| 396 | virtual void OnDraw(); |
| 397 | |
| 398 | private: |
| 399 | float m_timer, m_selecttimer; |
| 400 | bool m_hidden; |
| 401 | }; |
| 402 | |
| 403 | // CLASS a new listbox. uses less memory than the old listbox hopefully. |
| 404 | |
| 405 | #define SUBGADGET_UP 0x3 |
| 406 | #define SUBGADGET_DOWN 0x4 |
| 407 | |
| 408 | class newuiListBox : public UIGadget { |
| 409 | public: |
| 410 | newuiListBox(); |
| 411 | |
| 412 | // creates listbox |
| 413 | void Create(UIWindow *wnd, int16_t id, int16_t x, int16_t y, int16_t w, int16_t h, uint16_t flags); |
| 414 | |
| 415 | // functions to add or remove items, |
| 416 | void AddItem(const char *name); |
| 417 | void RemoveItem(const char *name); |
| 418 | void RemoveAll(); |
| 419 | |
| 420 | // item information |
| 421 | int GetCurrentIndex(); |
| 422 | void SetCurrentIndex(int index); |
| 423 | bool GetCurrentItem(char *buffer, int buflen); |
| 424 | bool GetItem(int index, char *buffer, int buflen); |
| 425 | bool SetCurrentItem(const char *name); |
| 426 | |
| 427 | // set callbacks |
| 428 | void SetSelectChangeCallback(void (*fn)(int)); |
| 429 | void SetSelectChangeCallback(void (*fn)(int, void *), void *ptr); |
| 430 | |
| 431 | protected: |
| 432 | virtual void OnLostFocus(); // override: behavior when gadget loses input focus. |
| 433 | virtual void OnGainFocus(); // override: behavior when gadget gains input focus. |
| 434 | virtual void OnDraw(); // behavior when gadget is being drawn. |
| 435 | virtual void OnKeyDown(int key); // behavior when key is pressed. |
| 436 | virtual void OnKeyUp(int key); // behavior when key is released. |
| 437 | virtual void OnMouseBtnDown(int btn); // behavior when mouse button is pressed. |
| 438 | virtual void OnMouseBtnUp(int btn); // behavior when mouse button is released. |
| 439 | virtual void OnNotifySelect(UIGadget *g); // this function will handle when an arrow button was pressed |
| 440 | virtual void OnSelect(); // when a listbox item was double clicked (or entered) |
| 441 | virtual void OnDestroy(); // called when destroyed. |
| 442 | virtual void OnUserProcess(); // override: behavior when gadget is processed |
| 443 | virtual void OnAttachToWindow(); // when gadget is added to a window (AddGadget is called) |
| 444 | virtual void OnDetachFromWindow(); // when gadget is detached from window |
| 445 | |
| 446 | private: |
| 447 | char **m_ItemList; // list of strings. |
| 448 | int *m_Virt2Real; // translates virtual(user) id to real index |
| 449 | int *m_Real2Virt; // translates real index into virtual(user) id |
| 450 | |
| 451 | void (*selectchange_fn)(int); // callback when selection changes in listbox. |
| 452 | void (*selectchange_id_fn)(int, void *); // callback when selection changes in listbox..also return the ID |
| 453 | void *m_callbackptr; // user defined callback pointer |
| 454 | |
| 455 | int m_NumItems; // number of items in list. |
| 456 | int m_SelectedIndex; // current selected index into listbox |
| 457 | int m_Index; // current index of visible items. |
| 458 | int m_NumVisibleItems; // number of items visible in listbox |
| 459 | int m_boffs; // offset from edge to text region (border width) |
| 460 | int m_mse_x, m_mse_y; // mouse x and y of last click. |
| 461 | int m_last_mse_x, m_last_mse_y; |
| 462 | int m_last_selected_index; |
| 463 | float m_click_time; // time in between clicks. |
| 464 | int8_t m_nclicks; |
| 465 | bool m_mse_clicked; |
| 466 | |
| 467 | newuiArrowButton m_up_btn; // buttons to scroll. |
| 468 | newuiArrowButton m_down_btn; |
| 469 | |
| 470 | UIBitmapItem *m_pieces[N_DIRECTIONS]; // bitmap pieces |
| 471 | |
| 472 | void Offset(int16_t offs); |
| 473 | void SetInternalCurrentIndex(int index); |
| 474 | }; |
| 475 | |
| 476 | // CLASS newuiComboBox |
| 477 | |
| 478 | class newuiComboBox : public UIGadget { |
| 479 | public: |
| 480 | newuiComboBox(); |
| 481 | |
| 482 | // creates listbox |
| 483 | void Create(UIWindow *wnd, int16_t id, int16_t x, int16_t y, uint16_t flags); |
| 484 | |
| 485 | // functions to add or remove items, |
| 486 | void AddItem(const char *name); |
| 487 | void RemoveItem(const char *name); |
| 488 | void RemoveAll(); |
| 489 | |
| 490 | // item information |
| 491 | int GetCurrentIndex(); |
| 492 | void SetCurrentIndex(int index); |
| 493 | bool GetCurrentItem(char *buffer, int buflen); |
| 494 | bool GetItem(int index, char *buffer, int buflen); |
| 495 | bool SetCurrentItem(const char *name); |
| 496 | |
| 497 | // set callbacks |
| 498 | void SetSelectChangeCallback(void (*fn)(int)); |
| 499 | |
| 500 | protected: |
| 501 | virtual void OnDraw(); // behavior when gadget is being drawn. |
| 502 | virtual void OnKeyDown(int key); // behavior when key is pressed. |
| 503 | virtual void OnNotifySelect(UIGadget *g); // this function will handle when an arrow button was pressed |
| 504 | virtual void OnSelect(); // when a listbox item was double clicked (or entered) |
| 505 | virtual void OnDestroy(); // called when destroyed. |
| 506 | virtual void OnAttachToWindow(); // when gadget is added to a window (AddGadget is called) |
| 507 | virtual void OnDetachFromWindow(); // when gadget is detached from window |
| 508 | |
| 509 | private: |
| 510 | char **m_ItemList; // list of strings. |
| 511 | int *m_Virt2Real; // translates virtual(user) id to real index |
| 512 | int *m_Real2Virt; // translates real index into virtual(user) id |
| 513 | |
| 514 | void (*selectchange_fn)(int); // callback when selection changes in listbox. |
| 515 | |
| 516 | int m_NumItems; // number of items in list. |
| 517 | int m_Index; // current index of visible items. |
| 518 | int m_boffs; // offset from edge to text region (border width) |
| 519 | bool m_showup, m_showdown; |
| 520 | |
| 521 | newuiArrowButton m_up_btn; // buttons to scroll. |
| 522 | newuiArrowButton m_down_btn; |
| 523 | |
| 524 | UIBitmapItem *m_barbmp; // bitmap pieces |
| 525 | }; |
| 526 | |
| 527 | // the new classic hotspot CLASS |
| 528 | |
| 529 | class newuiHotspot : public UIGadget { |
| 530 | private: |
| 531 | char *m_title; |
| 532 | int16_t m_alpha, m_alpha_adjust; |
| 533 | float m_mse_timer; |
| 534 | |
| 535 | public: |
| 536 | newuiHotspot(); |
| 537 | |
| 538 | void Create(UIWindow *wnd, int16_t id, const char *title, int16_t x, int16_t y, int16_t w, int16_t h, int16_t flags = 0); |
| 539 | const char *GetTitle() const { return m_title; }; |
| 540 | |
| 541 | protected: |
| 542 | virtual void OnDraw(); // this will use the newuiButton drawing scheme |
| 543 | virtual void OnDestroy(); |
| 544 | virtual void OnMouseBtnDown(int btn); |
| 545 | virtual void OnMouseBtnUp(int btn); |
| 546 | virtual void OnGainFocus(); |
| 547 | virtual void OnLostFocus(); |
| 548 | }; |
| 549 | |
| 550 | /////////////////////////////////////////////////////////////////////////////// |
| 551 | |
| 552 | // CLASS, contains options buttons and sheets of ui stuff |
| 553 | |
| 554 | #define NEWUIMENU_SMALL 0x10 |
| 555 | #define NEWUIMENU_MEDIUM 0x20 |
| 556 | #define NEWUIMENU_LARGE 0x40 |
| 557 | |
| 558 | class newuiMenu : public UIWindow { |
| 559 | public: |
| 560 | newuiMenu(); |
| 561 | |
| 562 | // creates a menu |
| 563 | void Create(); |
| 564 | |
| 565 | // adds an option to a menu, returns a newuiSheet object to add user interface to. |
| 566 | newuiSheet *AddOption(int16_t id, const char *title, int size = NEWUIMENU_SMALL, bool has_sheet = true, int yoff = 0); |
| 567 | void AddSimpleOption(int16_t id, const char *title, int yoff = 0); |
| 568 | |
| 569 | // sets current option to display. |
| 570 | void SetCurrentOption(int16_t id); |
| 571 | |
| 572 | // returns current option |
| 573 | int16_t GetCurrentOption() const; |
| 574 | |
| 575 | // returns current sheet |
| 576 | newuiSheet *GetCurrentSheet() const; |
| 577 | |
| 578 | // set master sheet,button locations |
| 579 | void SetPlacements(int x, int y, int options_x, int options_y, int options_w, int options_h, int title_x, int title_y, |
| 580 | tAlignment align = NEWUI_ALIGN_VERT); |
| 581 | |
| 582 | // processes a menu |
| 583 | int DoUI(); |
| 584 | |
| 585 | // THESE FUNCTIONS DEAL WITH CALLBACK PROCEDURES |
| 586 | public: |
| 587 | // when a new option is realized, this function will be called. |
| 588 | // passed in: the menu object, the old option and the new option and an optional pointer respectively |
| 589 | void SetOnOptionSwitchCB(void (*fn)(newuiMenu *, int16_t, int16_t, void *), void *data); |
| 590 | |
| 591 | // when a new option is ready. at this point the system sets the focus on this option |
| 592 | void SetOnOptionFocusCB(void (*fn)(newuiMenu *, int16_t, void *), void *data); |
| 593 | |
| 594 | // equivalent of SetUICallback, called before gadgets are drawn |
| 595 | void SetOnUIFrameCB(void (*fn)()); |
| 596 | |
| 597 | protected: |
| 598 | virtual void OnDraw(); // overridable draws the window background before gadgets |
| 599 | virtual void OnDestroy(); // overridable: called in Destroy |
| 600 | |
| 601 | UIBitmapItem *m_bkg; // background |
| 602 | |
| 603 | private: |
| 604 | newuiMenuOptionButton m_sheetbtn[N_NEWUI_SHEETS]; |
| 605 | newuiSheet m_sheets[N_NEWUI_SHEETS]; |
| 606 | bool m_hassheet[N_NEWUI_SHEETS]; |
| 607 | newuiSheet *m_cursheet; // current sheet |
| 608 | int m_nsheets, m_sheetx, m_sheety; // sheet characteristics |
| 609 | int m_optionsw, m_optionsh; |
| 610 | int m_optionsx, m_optionsy; // option button placements |
| 611 | int m_titlex, m_titley; // title location. |
| 612 | tAlignment m_align; // alignment of text |
| 613 | int16_t m_newoptionid; // tells that a new option has been selected. |
| 614 | int16_t m_cursheetidx; |
| 615 | bool m_refreshgadgets; // refreshes gadgets on current sheet. |
| 616 | |
| 617 | void (*m_activate_sheet_cb)(newuiMenu *, int16_t, int16_t, void *); |
| 618 | void (*m_option_focus_cb)(newuiMenu *, int16_t, void *); |
| 619 | void (*m_uiframe_cb)(); |
| 620 | |
| 621 | void *m_activate_sheet_cb_data; |
| 622 | void *m_option_focus_cb_data; |
| 623 | }; |
| 624 | |
| 625 | // CLASS, large (fullscreen) menu |
| 626 | |
| 627 | class newuiLargeMenu : public newuiMenu { |
| 628 | public: |
| 629 | // creates a menu |
| 630 | void Create(); |
| 631 | |
| 632 | // adds an option to a menu, returns a newuiSheet object to add user interface to. |
| 633 | newuiSheet *AddOption(int16_t id, const char *title, int size = NEWUIMENU_MEDIUM); |
| 634 | }; |
| 635 | |
| 636 | // CLASS, small message box |
| 637 | #define NEWUI_MSGBOX_SHEET_W 200 |
| 638 | #define NEWUI_MSGBOX_MAXBTNS 4 |
| 639 | |
| 640 | class newuiMessageBox : public UIWindow { |
| 641 | public: |
| 642 | newuiMessageBox(); |
| 643 | |
| 644 | void Create(const char *title, int type = MSGBOX_OK); |
| 645 | |
| 646 | void AddButton(const char *title, int slot, int key = 0); |
| 647 | |
| 648 | // grab the message box's sheet. |
| 649 | newuiSheet *GetSheet(); |
| 650 | |
| 651 | // do user interface, return UID_OK or UID_CANCEL or UID_??? (UID_OK and UID_CANCEL are predefined) |
| 652 | int DoUI(); |
| 653 | |
| 654 | protected: |
| 655 | virtual void OnDraw(); // overridable draws the window background before gadgets |
| 656 | virtual void OnDestroy(); |
| 657 | |
| 658 | private: |
| 659 | newuiSheet m_sheet; |
| 660 | newuiButton m_btn[NEWUI_MSGBOX_MAXBTNS]; |
| 661 | |
| 662 | UIBitmapItem *m_bkg; |
| 663 | }; |
| 664 | |
| 665 | // CLASS, sizable window |
| 666 | |
| 667 | class newuiTiledWindow : public UIWindow { |
| 668 | public: |
| 669 | newuiTiledWindow(); |
| 670 | |
| 671 | void Create(const char *title, int16_t x, int16_t y, int16_t w, int16_t h, int flags = 0); |
| 672 | |
| 673 | // grab a newui interface from it. |
| 674 | newuiSheet *GetSheet(); |
| 675 | |
| 676 | // do user interface on it. |
| 677 | int DoUI(); |
| 678 | |
| 679 | // set callbacks, SetData keeps a pointer that is passed to all callbacks |
| 680 | void SetData(void *data); |
| 681 | |
| 682 | // first called when DoUI is called. |
| 683 | void SetOnStartUICB(void (*fn)(newuiTiledWindow *, void *)); |
| 684 | |
| 685 | // called when DoUI returns |
| 686 | void SetOnEndUICB(void (*fn)(newuiTiledWindow *, void *)); |
| 687 | |
| 688 | // called before rend_Flip but after ui has drawn. (SetUICallback is before ui has been rendered) |
| 689 | void SetOnDrawCB(void (*fn)(newuiTiledWindow *, void *)); |
| 690 | |
| 691 | // called after DoUIFrame is called. for immediate results. |
| 692 | void SetOnUIFrameCB(void (*fn)(newuiTiledWindow *, void *)); |
| 693 | |
| 694 | protected: |
| 695 | virtual void OnDraw(); |
| 696 | virtual void OnDestroy(); |
| 697 | |
| 698 | private: |
| 699 | UIBitmapItem *m_pieces[N_DIRECTIONS]; // bitmap pieces |
| 700 | newuiSheet m_sheet; |
| 701 | char m_title[64]; |
| 702 | void *m_data; |
| 703 | bool m_realized; |
| 704 | |
| 705 | void (*m_startui_cb)(newuiTiledWindow *, void *); |
| 706 | void (*m_endui_cb)(newuiTiledWindow *, void *); |
| 707 | void (*m_draw_cb)(newuiTiledWindow *, void *); |
| 708 | void (*m_onframe_cb)(newuiTiledWindow *, void *); |
| 709 | |
| 710 | int GetTopTileIndex(int tx, int window_width); |
| 711 | }; |
| 712 | |
| 713 | // inlines and macros |
| 714 | |
| 715 | #define F_APPROXIMATE(_f) ((_f) + 0.000001f) |
| 716 | |
| 717 | inline int16_t CALC_SLIDER_POS_FLOAT(float val, const tSliderSettings *settings, int16_t range) { |
| 718 | int16_t curpos; |
| 719 | curpos = (int16_t)F_APPROXIMATE(((val - settings->min_val.f) * range) / (settings->max_val.f - settings->min_val.f)); |
| 720 | return curpos; |
| 721 | } |
| 722 | |
| 723 | inline int16_t CALC_SLIDER_POS_INT(int val, const tSliderSettings *settings, int16_t range) { |
| 724 | int16_t curpos; |
| 725 | float num = (float)((val - settings->min_val.i) * range); |
| 726 | float dem = (float)((settings->max_val.i - settings->min_val.i)); |
| 727 | curpos = (int16_t)F_APPROXIMATE(num / dem); |
| 728 | return curpos; |
| 729 | } |
| 730 | |
| 731 | inline float CALC_SLIDER_FLOAT_VALUE(int16_t val, float min, float max, int16_t range) { |
| 732 | float retval; |
| 733 | retval = F_APPROXIMATE((max - min) * val / range) + min; |
| 734 | return retval; |
| 735 | } |
| 736 | |
| 737 | inline int CALC_SLIDER_INT_VALUE(int16_t val, int min, int max, int16_t range) { |
| 738 | int retval; |
| 739 | float num = (float)((max - min) * val); |
| 740 | retval = (int)(F_APPROXIMATE(num / range)) + min; |
| 741 | return retval; |
| 742 | } |
| 743 | |
| 744 | #endif |