| 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/Lib/ui.h $ |
| 21 | * $Revision: 75 $ |
| 22 | * $Date: 5/17/99 5:19p $ |
| 23 | * $Author: Samir $ |
| 24 | * |
| 25 | * UI system |
| 26 | * |
| 27 | * $Log: /DescentIII/Main/Lib/ui.h $ |
| 28 | * |
| 29 | * 75 5/17/99 5:19p Samir |
| 30 | * added ability for edit box to autoselect when hitting the max number of |
| 31 | * characters typable. |
| 32 | * |
| 33 | * 74 5/02/99 2:08a Samir |
| 34 | * added Enable and Disable and only accept locking of button if mouse is |
| 35 | * inside the button. |
| 36 | * |
| 37 | * 73 4/29/99 2:21a Samir |
| 38 | * added flag for gadgets. |
| 39 | * |
| 40 | * 72 4/28/99 1:54a Samir |
| 41 | * visual tweaks to text |
| 42 | * |
| 43 | * 71 4/26/99 7:46p Samir |
| 44 | * you can get flags from a window now. |
| 45 | * |
| 46 | * 70 4/16/99 4:02a Jeff |
| 47 | * include linux_fix.h for linxu builds...reduces errors |
| 48 | * |
| 49 | * 69 4/15/99 1:45a Jeff |
| 50 | * changes for linux compile |
| 51 | * |
| 52 | * 68 4/03/99 9:26p Jeff |
| 53 | * changed dialogs that weren't using UID_OK and UID_CANCEL to use and |
| 54 | * handle them properly |
| 55 | * |
| 56 | * 67 3/23/99 9:02p Samir |
| 57 | * up accelerator count for windows to 48. |
| 58 | * |
| 59 | * 66 2/28/99 3:25a Samir |
| 60 | * added flag to input only numbers. |
| 61 | * |
| 62 | * 65 2/26/99 2:12a Samir |
| 63 | * added window accelrators |
| 64 | * |
| 65 | * 64 2/22/99 8:13p Samir |
| 66 | * added slave gadget system that only uses mouse input from window, but |
| 67 | * defers keys to its master. |
| 68 | * |
| 69 | * 63 2/21/99 6:36p Samir |
| 70 | * focusing changes and key input changes to ui., |
| 71 | * |
| 72 | * 62 2/17/99 8:32p Samir |
| 73 | * fixed bugs in remove gadget, added callbacks for attaching and |
| 74 | * detaching gadgets. |
| 75 | * |
| 76 | * 61 2/16/99 12:08p Samir |
| 77 | * added gadget notification system. |
| 78 | * |
| 79 | * 60 1/18/99 5:08a Jeff |
| 80 | * added some flags related to sorted listboxes |
| 81 | * |
| 82 | * 59 12/30/98 12:16p Kevin |
| 83 | * Auto Mission Download system |
| 84 | * |
| 85 | * 58 11/03/98 7:05p Samir |
| 86 | * added word wrapping console. |
| 87 | * |
| 88 | * 57 10/20/98 12:14p Jeff |
| 89 | * added color to the UIGroup |
| 90 | * |
| 91 | * 56 10/19/98 6:30p Jeff |
| 92 | * changes made for detail variables. Put in preset values. Preset |
| 93 | * options. Removed terrain_cast from detail. Put new callbacks in |
| 94 | * UIListBox and UISlider |
| 95 | * |
| 96 | * 55 10/19/98 12:18p Samir |
| 97 | * made tabbing between edit controls possible. |
| 98 | * |
| 99 | * 54 10/17/98 11:26a Samir |
| 100 | * fixed some edit box scrolling issues. |
| 101 | * |
| 102 | * 53 10/16/98 1:42p Jeff |
| 103 | * updated UIGroup |
| 104 | * |
| 105 | * 52 10/07/98 11:25a Jeff |
| 106 | * created UIGroup |
| 107 | * |
| 108 | * 51 9/30/98 4:34p Samir |
| 109 | * added enable function. |
| 110 | * |
| 111 | * 50 9/22/98 3:57p Samir |
| 112 | * listbox prob fixed again. |
| 113 | * |
| 114 | * 49 9/14/98 11:22a Samir |
| 115 | * enhanced editboxes |
| 116 | * |
| 117 | * 48 9/02/98 6:50p Samir |
| 118 | * added new combo box. |
| 119 | * |
| 120 | * 47 8/27/98 5:03p Kevin |
| 121 | * Prettied up multiplayer screens and fixed some bugs. |
| 122 | * |
| 123 | * 46 8/27/98 2:52p Samir |
| 124 | * changing window system to work in two modes. |
| 125 | * |
| 126 | * 45 8/26/98 12:25p Samir |
| 127 | * fixed the whole editbox, keyboard access mess. |
| 128 | * |
| 129 | * 44 8/25/98 7:08p Samir |
| 130 | * select how keys are sent to a gadget. |
| 131 | * |
| 132 | * 43 8/25/98 5:27p Samir |
| 133 | * new focusing rules for keyboard. |
| 134 | * |
| 135 | * 42 8/24/98 3:12p Samir |
| 136 | * fixed text clipping |
| 137 | * |
| 138 | * 41 8/11/98 11:38a Samir |
| 139 | * fixed listbox probs yet again. arrows on side this time. |
| 140 | * |
| 141 | * 40 7/29/98 3:26p Samir |
| 142 | * fixed some listbox mouse problems. |
| 143 | * |
| 144 | * 39 6/23/98 5:05p Samir |
| 145 | * console supports color per line ONLY. |
| 146 | * |
| 147 | * 38 6/22/98 7:31p Samir |
| 148 | * added UIEdit::Activate, which activates an edit box manually. |
| 149 | * |
| 150 | * 37 6/22/98 2:15p Samir |
| 151 | * added UIConsoleGadget. |
| 152 | * |
| 153 | * 36 6/05/98 5:58p Jeff |
| 154 | * Added a way to change the items for the states of a HotSpot |
| 155 | * |
| 156 | * 35 6/05/98 5:35p Samir |
| 157 | * massive improvement in UI keyboard interface. |
| 158 | * |
| 159 | * 34 5/22/98 5:02p Jeff |
| 160 | * Added a flag for radio buttons so the button part won't be drawn (just |
| 161 | * the text) |
| 162 | * |
| 163 | * 33 5/08/98 3:58p Samir |
| 164 | * added ability to move a UI object. |
| 165 | * |
| 166 | * 32 4/29/98 1:04p Jeff |
| 167 | * fixed up the UIListBox a bit (color control and scroll buttons) |
| 168 | * |
| 169 | * 31 4/29/98 11:55a Samir |
| 170 | * allow user to change color of selected listbox item. |
| 171 | * |
| 172 | * 30 4/24/98 2:42a Samir |
| 173 | * added UICheckBox |
| 174 | * |
| 175 | * 29 4/13/98 7:02p Samir |
| 176 | * made some things protected. |
| 177 | * |
| 178 | * 28 3/13/98 5:18p Jeff |
| 179 | * Added 2 flags for new UIListBox for scrolling and some member vars for |
| 180 | * UIListBox |
| 181 | * |
| 182 | * 27 3/10/98 7:25p Samir |
| 183 | * Changes to UISlider |
| 184 | * |
| 185 | * 26 3/10/98 12:48p Samir |
| 186 | * Fixed flags for UIWindow so centering is supported. |
| 187 | * |
| 188 | * 25 3/09/98 5:05p Samir |
| 189 | * Added callback to selection change function. |
| 190 | * |
| 191 | * 24 3/09/98 3:43p Samir |
| 192 | * Made some window flag changes. |
| 193 | * |
| 194 | * 23 3/06/98 10:48a Samir |
| 195 | * Check if button is active. |
| 196 | * |
| 197 | * 22 3/05/98 6:40p Samir |
| 198 | * Implemented radio buttons. |
| 199 | * |
| 200 | * 21 3/04/98 12:08p Samir |
| 201 | * Slider fixed. |
| 202 | * |
| 203 | * 20 2/26/98 2:50p Samir |
| 204 | * Did some stuff with UISlider. |
| 205 | * |
| 206 | * 19 2/15/98 7:07p Samir |
| 207 | * Revamped way keys like up and down are handled in window system. |
| 208 | * |
| 209 | * 18 2/13/98 6:34p Samir |
| 210 | * Added UIStatic class. |
| 211 | * |
| 212 | * 17 2/10/98 4:55p Samir |
| 213 | * Added radio buttons. |
| 214 | * |
| 215 | * 16 2/02/98 7:36p Samir |
| 216 | * Added UIObject::Destroy. |
| 217 | * |
| 218 | * 15 1/30/98 7:03p Samir |
| 219 | * Added UIConsole. |
| 220 | * |
| 221 | * 14 1/23/98 5:45p Samir |
| 222 | * Added OnUserProcess to UIWindow class. |
| 223 | * |
| 224 | * 13 1/18/98 4:22p Samir |
| 225 | * Implemented new UIItem system. |
| 226 | * |
| 227 | * 12 1/13/98 6:59p Jeff |
| 228 | * (Samir) moved defines from UIlib.h to ui.h. |
| 229 | * |
| 230 | * 11 1/13/98 4:32p Samir |
| 231 | * Made tUIInput a shared structure to be used by ui_DoFrame to return UI |
| 232 | * input values. |
| 233 | * |
| 234 | * 10 1/13/98 4:28p Samir |
| 235 | * Added sliders. |
| 236 | * |
| 237 | * 9 1/09/98 12:01p Samir |
| 238 | * Added prototypes for sliders, listboxes, and scrollbars. |
| 239 | * |
| 240 | * 8 1/08/98 12:17p Samir |
| 241 | * Added TitledWindow and modified the UI interface for polling. |
| 242 | * |
| 243 | * 7 1/05/98 4:55p Samir |
| 244 | * Took out m_Flags from child classes of UIGadget |
| 245 | * |
| 246 | * 6 1/05/98 4:36p Samir |
| 247 | * Moved centering and fittext control flags to UIGadget class. |
| 248 | * |
| 249 | * 5 1/05/98 4:19p Samir |
| 250 | * UIGadget has fewer pure virtuals. |
| 251 | * |
| 252 | * 4 1/05/98 3:48p Jason |
| 253 | * added SetAllText function for buttons |
| 254 | * |
| 255 | * 3 1/05/98 3:18p Samir |
| 256 | * Added some button flags. |
| 257 | * |
| 258 | * 2 1/02/98 12:49p Samir |
| 259 | * Edit control and static control added. |
| 260 | * |
| 261 | * 1 12/30/97 4:37p Samir |
| 262 | * Initial revision |
| 263 | * |
| 264 | * $NoKeywords: $ |
| 265 | */ |
| 266 | |
| 267 | #ifndef UI_H |
| 268 | #define UI_H |
| 269 | |
| 270 | #include <cstdint> |
| 271 | |
| 272 | #if defined(POSIX) |
| 273 | #include "linux_fix.h" //for stricmp's through code |
| 274 | #endif |
| 275 | |
| 276 | #include "uires.h" |
| 277 | |
| 278 | #include "pserror.h" |
| 279 | #include "grdefs.h" |
| 280 | |
| 281 | // Class identification |
| 282 | |
| 283 | typedef unsigned tUIClass; |
| 284 | |
| 285 | const tUIClass uiObject = 0, uiWindow = 1, uiTitledWindow = 2, uiGadget = 3, uiHotspot = 4, uiButton = 5, uiEdit = 6, |
| 286 | uiText = 7, uiSlider = 8, uiVScrollBar = 9, uiListBox = 10; |
| 287 | |
| 288 | const tUIClass uiNewClass = 100; |
| 289 | |
| 290 | typedef int tUIBmpHandle; |
| 291 | |
| 292 | class UIObject; |
| 293 | class UIGadget; |
| 294 | class UIInterface; |
| 295 | class UIItem; |
| 296 | class UITextItem; |
| 297 | class UIWindow; |
| 298 | // ---------------------------------------------------------------------------- |
| 299 | // UIObject |
| 300 | // The absolute primitive for the UI system. All UI class are derived from |
| 301 | // tUIObject. |
| 302 | |
| 303 | class UIObject { |
| 304 | bool m_Created; // is this object created? |
| 305 | |
| 306 | // variables shared by the entire UI hierarchy |
| 307 | protected: |
| 308 | int m_X, m_Y; // Location of UIObject relative to some other object. |
| 309 | int m_W, m_H; // Dimensions of the UIObject |
| 310 | |
| 311 | public: |
| 312 | UIObject(); |
| 313 | virtual ~UIObject(); |
| 314 | |
| 315 | void Create(int x, int y, int w, int h); // define the ui object. |
| 316 | void Destroy() { m_Created = false; }; |
| 317 | bool IsCreated() const { return m_Created; }; |
| 318 | |
| 319 | // data access |
| 320 | int X() const { return m_X; }; // access the X,Y,W,H fields. |
| 321 | int Y() const { return m_Y; }; |
| 322 | int W() const { return m_W; }; |
| 323 | int H() const { return m_H; }; |
| 324 | |
| 325 | // moves the object. |
| 326 | void Move(int x, int y, int w, int h); |
| 327 | |
| 328 | // inheritable operations |
| 329 | public: |
| 330 | virtual tUIClass Class() const { // Overide this function to name the class |
| 331 | return uiObject; |
| 332 | }; |
| 333 | }; |
| 334 | |
| 335 | // ---------------------------------------------------------------------------- |
| 336 | // UIGadget |
| 337 | // A gadget is a user interface item which a mouse or keyboard may interact with. |
| 338 | // Gadgets typically are managed by their parent interface. |
| 339 | // All buttons, checkboxes, listboxes, etc use tUIGadget as their parent. |
| 340 | |
| 341 | // flags |
| 342 | #define UIF_CENTER 0x01 |
| 343 | #define UIF_FIT 0x02 |
| 344 | #define UIF_BORDER 0x04 // for certain gadgets specifies that the border be drawn. |
| 345 | #define UIF_SLAVE 0x10 // gadget never gets focus from ui system directly (child gadgets). |
| 346 | #define UIF_NOTIFYMASTERSEL 0x20 // when slave gadget is selected, the master will know. |
| 347 | #define UIF_PROCESS_MENU 0x40 // use this to create a 'menu style' window (Options menu) |
| 348 | #define UIF_PROCESS_ALL UIF_PROCESS_MENU // to maintain compatibility with older code. |
| 349 | #define UIF_GROUP_START 0x80 // starts a group of gadgets that use the up and down arrows to move between |
| 350 | #define UIF_GROUP_END 0x100 // ends a group |
| 351 | |
| 352 | #define UIF_CUSTOMF 0x200 // use this flag and any higher for custom gadget flags, a list of predefs below |
| 353 | |
| 354 | #define UILB_NOSCROLL 0x800 // turns off automatic scroll buttons on UIListBox |
| 355 | #define UILB_AUTOSELECT 0x1000 // turns on automatic change of SelectedIndex if scrolled out of view |
| 356 | #define UILB_NOSORT 0x2000 // disables sorting in a listbox |
| 357 | #define UILB_CASESENSITIVE 0x4000 // only if !UILB_NOSORT. Makes the sorting case sensitive |
| 358 | |
| 359 | #define UIRB_NOBUTTON 0x800 // disables the drawing of the button on the left of the text of a radio button |
| 360 | |
| 361 | #define UIED_PASSWORD 0x800 // special password masking for edit box text (*) |
| 362 | #define UIED_NUMBERS 0x1000 // only accept numbers for input! |
| 363 | #define UIED_AUTOSELECT 0x2000 // selects when input reaches buffer length. |
| 364 | |
| 365 | // any flags after 0x10000-0x40000000 are reserved internal to gadget controls |
| 366 | |
| 367 | // ids |
| 368 | #define UID_OK 0xEE |
| 369 | #define UID_CANCEL 0xEF |
| 370 | |
| 371 | class UIGadget : public UIObject { |
| 372 | friend class UIWindow; |
| 373 | |
| 374 | UIGadget *m_Prev; |
| 375 | UIGadget *m_Next; // for maintaining list of linked gadgets. |
| 376 | |
| 377 | // master gadgets |
| 378 | UIGadget *m_MasterGadget; // select target |
| 379 | UIGadget *m_CurrentSlave; // current slave gadget in master. |
| 380 | |
| 381 | // slave gadgets |
| 382 | UIGadget *m_SlaveGadgets; // contains a list of slave gadgets. |
| 383 | UIGadget *m_NextSlave; |
| 384 | UIGadget *m_PrevSlave; |
| 385 | |
| 386 | // information for gadgets |
| 387 | private: |
| 388 | int m_ID; // id value of gadget. |
| 389 | int16_t m_Datum; // used to pass info around. |
| 390 | uint16_t m_Hotkey; |
| 391 | int m_SavedW, m_SavedH; // saved values of width and height. |
| 392 | bool m_Disabled; // is gadget disabled? |
| 393 | |
| 394 | static int m_LastKey; // the last key pressed. |
| 395 | static int m_LastKeyCount; // number of times last key was pressed. |
| 396 | static float m_LastKeyTime; // last key time. |
| 397 | |
| 398 | bool TrapKey(int key); // used to manage keypresses so repeating isn't quick. |
| 399 | void UntrapKey(int key); |
| 400 | void CheckFocusOnSlaves(int mx, int my); |
| 401 | |
| 402 | // universal variables |
| 403 | #if defined(POSIX) // gcc has a hard time tracing through some of the derived classes that access m_Wnd |
| 404 | public: |
| 405 | #else |
| 406 | protected: |
| 407 | #endif |
| 408 | UIWindow *m_Wnd; // the gadget's parent window |
| 409 | |
| 410 | protected: |
| 411 | int m_Flags; // flags |
| 412 | bool m_infocus; // gadget has focus. |
| 413 | |
| 414 | int GetSavedW() const { return m_SavedW; }; |
| 415 | int GetSavedH() const { return m_SavedH; }; |
| 416 | inline bool HasFocus() const; |
| 417 | UIGadget *GetPrevUsableGadget(); // gets next gadget lower in chain that's not disabled |
| 418 | UIGadget *GetNextUsableGadget(); // gets next gadget higher in chain that's not disabled |
| 419 | void LostFocus(); // called by window system |
| 420 | void GainFocus(); // called by window system |
| 421 | void LockFocus(); // forces input to this gadget |
| 422 | void UnlockFocus(); // releases lock on input to gadget. |
| 423 | |
| 424 | // called from outside gadget hierarchy. |
| 425 | #if defined(POSIX) // gcc has a hard time tracing through the dervived classes of newuiButton and thinks it can't access |
| 426 | // OnFormat() |
| 427 | public: |
| 428 | #else |
| 429 | protected: |
| 430 | #endif |
| 431 | virtual void OnFormat(); // override: called when resized or before drawing. |
| 432 | |
| 433 | protected: |
| 434 | virtual void OnLostFocus(){}; // override: behavior when gadget loses input focus. |
| 435 | virtual void OnGainFocus(){}; // override: behavior when gadget gains input focus. |
| 436 | virtual void OnAttachToWindow(){}; // override: when gadget is attached to window, this is called. |
| 437 | virtual void OnDetachFromWindow(){}; // override: when gadget is detached from window, this is called. |
| 438 | virtual void OnDraw() = 0; // MUST override: behavior when gadget is being drawn. |
| 439 | |
| 440 | // called by Process. |
| 441 | protected: |
| 442 | virtual void OnKeyDown(int key){}; // override: behavior when key is pressed. |
| 443 | virtual void OnKeyUp(int key){}; // override: behavior when key is released. |
| 444 | virtual void OnMouseBtnDown(int btn){}; // override: behavior when mouse button is pressed. |
| 445 | virtual void OnMouseBtnUp(int btn){}; // override: behavior when mouse button is released. |
| 446 | virtual void OnDestroy(){}; // override: behavior when gadget is destroyed. |
| 447 | virtual void OnUserProcess(){}; // override: behavior when gadget is processed |
| 448 | virtual void OnNotifySelect(UIGadget *sender){}; // override: send gadget select message to another gadget. |
| 449 | |
| 450 | // typically this function is called by a child class when we want |
| 451 | // to tell the caller that this gadget was selected for something. |
| 452 | virtual void OnSelect(); // override: behavior when gadget is selected. |
| 453 | |
| 454 | public: |
| 455 | virtual void OnNotify(UIGadget *){}; // usually called by a child gadget of a gadget. |
| 456 | |
| 457 | public: |
| 458 | UIGadget(); |
| 459 | virtual ~UIGadget(); |
| 460 | |
| 461 | UIWindow *GetWindow() { // returns the parent window for a gadget. |
| 462 | return m_Wnd; |
| 463 | }; |
| 464 | |
| 465 | // returns link in gadget chain. |
| 466 | UIGadget *Next() const { return m_Next; }; |
| 467 | UIGadget *Prev() const { return m_Prev; }; |
| 468 | |
| 469 | // defines the graphical representation of a gadget within a window. |
| 470 | // ALL Gadgets must have a wnd. |
| 471 | void Create(UIWindow *wnd, int id, int x, int y, int w, int h, int flags); |
| 472 | void Destroy(); |
| 473 | |
| 474 | // interprets input on this gadget. this gadget is in focus. |
| 475 | void Process(bool do_keys = true, bool do_mouse = true, bool do_user = true); |
| 476 | bool IsLocked() const; // is this gadget's focus locked? |
| 477 | |
| 478 | // settings |
| 479 | void SetHotkey(int key); // set this when key is pressed, selects gadget. |
| 480 | int GetID() const { return m_ID; }; |
| 481 | int16_t GetDatum() const { return m_Datum; }; |
| 482 | void SetDatum(int16_t datum) { m_Datum = datum; }; |
| 483 | bool IsDisabled() { return m_Disabled; }; // returns disabled state. |
| 484 | void Disable() { m_Disabled = true; }; // disables gadget. |
| 485 | void Enable() { m_Disabled = false; }; // enables gadget. |
| 486 | int GetFlags() const { return m_Flags; }; // gets flags for gadget. |
| 487 | void SetFlag(int flag); |
| 488 | void ClearFlag(int flag); |
| 489 | |
| 490 | // OnSelect messages to another gadget |
| 491 | void AttachSlaveGadget(UIGadget *gadget); |
| 492 | void DetachSlaveGadget(UIGadget *gadget); |
| 493 | |
| 494 | // class id |
| 495 | virtual tUIClass Class() const { // Overide this function to name the class |
| 496 | return uiGadget; |
| 497 | }; |
| 498 | }; |
| 499 | |
| 500 | // ---------------------------------------------------------------------------- |
| 501 | // UIHotspot |
| 502 | // This is simply a region within the parent window that when clicked on |
| 503 | // or key pressed, does something. |
| 504 | |
| 505 | class UIHotspot : public UIGadget { |
| 506 | UIItem *m_ItemOff, *m_ItemOn; // off and on states items. |
| 507 | UIItem *m_ItemCur; // current item. |
| 508 | |
| 509 | protected: |
| 510 | virtual void OnKeyDown(int key); // override: behavior when key is pressed. |
| 511 | virtual void OnKeyUp(int key){}; // override: behavior when key is released. |
| 512 | virtual void OnMouseBtnDown(int btn); // override: behavior when mouse button is pressed. |
| 513 | virtual void OnMouseBtnUp(int btn); // override: behavior when mouse button is released. |
| 514 | virtual void OnFormat(); // override: called when resized or before drawing. |
| 515 | virtual void OnDraw(); // override: behavior when gadget is being drawn. |
| 516 | virtual void OnLostFocus(); // override: behavior when gadget loses input focus. |
| 517 | virtual void OnGainFocus(); // override: behavior when gadget gains input focus. |
| 518 | virtual void OnDestroy(); // override: behavior when gadget is destroyed. |
| 519 | |
| 520 | public: |
| 521 | UIHotspot(); |
| 522 | virtual ~UIHotspot(); |
| 523 | |
| 524 | // optional key, when pressed, triggers hotspot. |
| 525 | void Create(UIWindow *wnd, int id, int key, UIItem *itemoff, UIItem *itemon, int x, int y, int w, int h, |
| 526 | int flags = 0); |
| 527 | |
| 528 | // sets the items for the on/off state of the hotspot |
| 529 | void SetStates(UIItem *itemoff, UIItem *itemon); |
| 530 | |
| 531 | // class id |
| 532 | virtual tUIClass Class() const { // Overide this function to name the class |
| 533 | return uiHotspot; |
| 534 | }; |
| 535 | }; |
| 536 | |
| 537 | // tUIButton family |
| 538 | // this family contains buttons, radio buttons, and checkboxes |
| 539 | |
| 540 | // states |
| 541 | #define UI_BTS_NUM 4 |
| 542 | #define UI_BTS_DISABLED 0 |
| 543 | #define UI_BTS_INACTIVE 1 |
| 544 | #define UI_BTS_HILITE 2 |
| 545 | #define UI_BTS_ACTIVATED 3 |
| 546 | |
| 547 | // ---------------------------------------------------------------------------- |
| 548 | // UIButton |
| 549 | // This is a simple 2 state button (push down or push up) |
| 550 | // Buttons have properties of gadgets, plus bitmap information per state. |
| 551 | |
| 552 | class UIButton : public UIGadget { |
| 553 | private: |
| 554 | UIItem *m_Items[UI_BTS_NUM]; // UI Items for each state |
| 555 | ddgr_color m_Colors[UI_BTS_NUM]; // Backgrounds for states |
| 556 | |
| 557 | static int m_ButtonFont; // button fonts. |
| 558 | |
| 559 | protected: |
| 560 | int m_State; // state of button |
| 561 | |
| 562 | UIItem *GetStateItem(int state) { |
| 563 | ASSERT(state < UI_BTS_NUM); |
| 564 | return m_Items[state]; |
| 565 | }; |
| 566 | |
| 567 | int GetColor(int state) const { |
| 568 | ASSERT(state < UI_BTS_NUM); |
| 569 | return m_Colors[state]; |
| 570 | }; |
| 571 | |
| 572 | public: |
| 573 | static void SetDefaultFont(int font) { // sets the button font |
| 574 | UIButton::m_ButtonFont = font; |
| 575 | }; |
| 576 | |
| 577 | public: |
| 578 | UIButton(); |
| 579 | virtual ~UIButton(); |
| 580 | |
| 581 | void Create(UIWindow *parent, int id, UIItem *title, int x, int y, int w, int h, int flags = 0); |
| 582 | |
| 583 | virtual tUIClass Class() const { // Overide this function to name the class |
| 584 | return uiButton; |
| 585 | }; |
| 586 | |
| 587 | // settings |
| 588 | void SetStateItem(int state, UIItem *item); // sets the background bitmap for a specified button state |
| 589 | void SetAllStates(UIItem *item); // Sets text for all states |
| 590 | void SetColor(int state, ddgr_color col); |
| 591 | void Disable(); // this adds to the gadget equivalent |
| 592 | void Enable(); // this adds to the gadget equivalent |
| 593 | |
| 594 | // inheritable operations |
| 595 | protected: |
| 596 | virtual void OnLostFocus(); // behavior when gadget loses input focus. |
| 597 | virtual void OnGainFocus(); // behavior when gadget gains input focus. |
| 598 | virtual void OnDraw(); // behavior when gadget is being drawn. |
| 599 | virtual void OnFormat(); // override: called when resized or before drawing. |
| 600 | |
| 601 | // called by Process. |
| 602 | protected: |
| 603 | virtual void OnKeyDown(int key); // behavior when key is pressed. |
| 604 | virtual void OnKeyUp(int key); // behavior when key is released. |
| 605 | virtual void OnMouseBtnDown(int btn); // behavior when mouse button is pressed. |
| 606 | virtual void OnMouseBtnUp(int btn); // behavior when mouse button is released. |
| 607 | virtual void OnDestroy(); // override: behavior when gadget is destroyed. |
| 608 | |
| 609 | // typically this function is called by a child class when we want |
| 610 | // to tell the caller that this gadget was selected for something. |
| 611 | // virtual void OnSelect(); // override: behavior when gadget is |
| 612 | // selected. |
| 613 | }; |
| 614 | |
| 615 | // check boxes use most of the behavior of default buttons. |
| 616 | // the only difference is how states are set when an item is selected. |
| 617 | class UICheckBox : virtual public UIButton { |
| 618 | public: |
| 619 | UICheckBox(); |
| 620 | |
| 621 | void Create(UIWindow *parent, int id, UIItem *title, int x, int y, int w, int h, int flags); |
| 622 | |
| 623 | void SetCheck(bool state); // turns on button (of off) |
| 624 | bool IsChecked() const // returns true if button is set. |
| 625 | { |
| 626 | return (m_State == UI_BTS_ACTIVATED) ? true : false; |
| 627 | }; |
| 628 | |
| 629 | protected: |
| 630 | virtual void OnDraw(); // behavior when gadget is being drawn. |
| 631 | virtual void OnFormat(); // override: called when resized or before drawing. |
| 632 | |
| 633 | virtual void OnLostFocus(); // behavior when gadget loses input focus. |
| 634 | virtual void OnGainFocus(); // behavior when gadget gains input focus. |
| 635 | virtual void OnKeyDown(int key); // behavior when key is pressed. |
| 636 | virtual void OnKeyUp(int key); // behavior when key is released. |
| 637 | virtual void OnMouseBtnDown(int btn); // behavior when mouse button is pressed. |
| 638 | virtual void OnMouseBtnUp(int btn); // behavior when mouse button is released. |
| 639 | }; |
| 640 | |
| 641 | // radio buttons use most of the behavior of default buttons. |
| 642 | // the only difference is how states are set when an item is selected. |
| 643 | class UIRadioButton : virtual public UIButton { |
| 644 | UIRadioButton *m_PrevRB; // previous radio button in group. |
| 645 | UIRadioButton *m_NextRB; // next radio button in group. |
| 646 | |
| 647 | void ActivateButton(); // activates this button, deactivating all others. |
| 648 | |
| 649 | public: |
| 650 | UIRadioButton(); |
| 651 | |
| 652 | // flags. the group flags are set internally by Create. if prev_rb is NULL, that's the start. |
| 653 | void Create(UIWindow *parent, UIRadioButton *prev_rb, int id, UIItem *title, int x, int y, int w, int h, int flags); |
| 654 | |
| 655 | void Activate(); // turns on button, turns off others in group. |
| 656 | bool IsActivated() const // returns true if button is set. |
| 657 | { |
| 658 | return (m_State == UI_BTS_ACTIVATED) ? true : false; |
| 659 | }; |
| 660 | |
| 661 | protected: |
| 662 | virtual void OnDraw(); // behavior when gadget is being drawn. |
| 663 | virtual void OnFormat(); // override: called when resized or before drawing. |
| 664 | |
| 665 | virtual void OnLostFocus(); // behavior when gadget loses input focus. |
| 666 | virtual void OnGainFocus(); // behavior when gadget gains input focus. |
| 667 | virtual void OnKeyDown(int key); // behavior when key is pressed. |
| 668 | virtual void OnKeyUp(int key); // behavior when key is released. |
| 669 | virtual void OnMouseBtnDown(int btn); // behavior when mouse button is pressed. |
| 670 | virtual void OnMouseBtnUp(int btn); // behavior when mouse button is released. |
| 671 | }; |
| 672 | |
| 673 | // ---------------------------------------------------------------------------- |
| 674 | // UIStatic |
| 675 | // Just a static image/text/etc. |
| 676 | |
| 677 | class UIStatic : public UIGadget { |
| 678 | protected: |
| 679 | UIPrimativeItem *m_Background; |
| 680 | UIItem *m_Title; |
| 681 | |
| 682 | public: |
| 683 | UIStatic(); |
| 684 | virtual ~UIStatic(); |
| 685 | |
| 686 | void Create(UIWindow *parent, UIItem *item, int x, int y, int w, int h, int flags = 0); |
| 687 | void SetBackground(UIPrimativeItem *prim); |
| 688 | void SetTitle(UIItem *item); |
| 689 | UIItem *GetItem() const { return m_Title; }; |
| 690 | |
| 691 | protected: |
| 692 | virtual void OnDraw(); // behavior when gadget is being drawn. |
| 693 | virtual void OnFormat(); // override: called when resized or before drawing. |
| 694 | virtual void OnDestroy(); // called when gadget is being nuked. |
| 695 | }; |
| 696 | |
| 697 | // ---------------------------------------------------------------------------- |
| 698 | // UIText |
| 699 | // This is a simple text. |
| 700 | |
| 701 | class UIText : public UIStatic { |
| 702 | public: |
| 703 | void Create(UIWindow *parent, UITextItem *text, int x, int y, int flags = 0); |
| 704 | |
| 705 | // inheritable operations |
| 706 | protected: |
| 707 | virtual void OnFormat(); // override: called when resized or before drawing. |
| 708 | }; |
| 709 | |
| 710 | // ---------------------------------------------------------------------------- |
| 711 | // UIProgress |
| 712 | // Progress Bar |
| 713 | |
| 714 | class UIProgress : public UIStatic { |
| 715 | public: |
| 716 | void Create(UIWindow *parent, int x, int y, int w, int h, int flags = 0); |
| 717 | void Update(float progress); // Call with a value from 0-1.0 to specify progress |
| 718 | |
| 719 | // inheritable operations |
| 720 | protected: |
| 721 | float m_Progress; |
| 722 | int m_ProgressWidth; |
| 723 | virtual void OnDraw(); // behavior when gadget is being drawn. |
| 724 | virtual void OnFormat(); // override: called when resized or before drawing. |
| 725 | }; |
| 726 | |
| 727 | // ---------------------------------------------------------------------------- |
| 728 | // UIGroup |
| 729 | // Draws a group box on to the window |
| 730 | |
| 731 | class UIGroup : public UIStatic { |
| 732 | public: |
| 733 | UIGroup(); |
| 734 | ~UIGroup(); |
| 735 | void Create(UIWindow *parent, char *label, int x, int y, int w, int h, ddgr_color label_color = GR_WHITE, |
| 736 | ddgr_color box_color = GR_WHITE, int flags = 0); |
| 737 | |
| 738 | // inheritable operations |
| 739 | protected: |
| 740 | bool m_bTextCreated; |
| 741 | UIText m_tLabel; |
| 742 | char *m_Label; |
| 743 | ddgr_color m_LabelColor; |
| 744 | ddgr_color m_BoxColor; |
| 745 | virtual void OnDraw(); |
| 746 | virtual void OnDestroy(); |
| 747 | }; |
| 748 | |
| 749 | // ---------------------------------------------------------------------------- |
| 750 | // UIEdit |
| 751 | // A single line edit control. |
| 752 | |
| 753 | #define KEYDOWN_FIRST_DELAY 0.5f |
| 754 | #define KEYDOWN_REPEAT_DELAY 0.10f |
| 755 | |
| 756 | class UIEdit : public UIGadget { |
| 757 | char *m_TextBuf; // Text buffer for edit control. |
| 758 | int m_FontHandle; // font for edit control. (default -1 = window's font) |
| 759 | int m_BufSize; // buffersize |
| 760 | int m_Color; // color of text. |
| 761 | int m_CursorPosX; // text cursor position within box. |
| 762 | bool m_Active; // active? |
| 763 | int m_CurPos; // cursor postion in buffer. |
| 764 | int m_StartPos; // active start position in buffer of what's drawn. |
| 765 | int m_X1b, m_X2b, m_Yb; // x boundaries of text. |
| 766 | int m_ScrollThresh; // scrolling x threshold. |
| 767 | bool m_UpdateCount; // used to update scroll position on next draw frame. |
| 768 | |
| 769 | // called from outside gadget hierarchy. |
| 770 | protected: |
| 771 | void DrawText(); // draws text in box |
| 772 | void Deactivate(); // deactivates edit box (use if you know what you're doing.) |
| 773 | void SetTextBounds(int x1, int x2, int yoff); // horizontal clipping of text within editbox |
| 774 | |
| 775 | // called from outside gadget hierarchy. |
| 776 | protected: |
| 777 | virtual void OnLostFocus(); // override: behavior when gadget loses input focus. |
| 778 | virtual void OnGainFocus(); // override: behavior when gadget gains input focus. |
| 779 | virtual void OnDraw(); // behavior when gadget is being drawn. |
| 780 | |
| 781 | // called by Process. |
| 782 | protected: |
| 783 | virtual void OnKeyDown(int key); // behavior when key is pressed. |
| 784 | virtual void OnKeyUp(int key); // behavior when key is released. |
| 785 | virtual void OnMouseBtnDown(int btn); // behavior when mouse button is pressed. |
| 786 | virtual void OnMouseBtnUp(int btn); // behavior when mouse button is released. |
| 787 | virtual void OnSelect(); |
| 788 | virtual void OnDestroy(); // override: behavior when gadget is destroyed. |
| 789 | |
| 790 | public: |
| 791 | UIEdit(); |
| 792 | virtual ~UIEdit(); |
| 793 | |
| 794 | void Create(UIWindow *parent, int id, int x, int y, int w, int h, int flags = 0); |
| 795 | |
| 796 | // settings |
| 797 | void SetBufferLen(int length); // sets the length of the input buffer. |
| 798 | void SetText(const char *text); // sets the text buffer. |
| 799 | void GetText(char *buffer, int len); // retrieve text in edit control. |
| 800 | void SetFont(int font); // sets font of control (default is window's font.) |
| 801 | void SetColor(ddgr_color col); // sets color of text. |
| 802 | void Activate(); // activates edit box manually (allows editing.) |
| 803 | |
| 804 | virtual tUIClass Class() const { // Overide this function to name the class |
| 805 | return uiEdit; |
| 806 | }; |
| 807 | }; |
| 808 | |
| 809 | // ---------------------------------------------------------------------------- |
| 810 | // UISlider |
| 811 | // A simple slider |
| 812 | |
| 813 | class UISlider : public UIGadget { |
| 814 | void (*selectchange_fn)(int); // callback when selection changes in slider |
| 815 | void (*selectchange_id_fn)(int, void *); // callback when selection changes in slider, also returns the ID |
| 816 | void *m_callbackptr; // user defined callback pointer |
| 817 | int m_Pos; // this is the returned value as shown in the range. |
| 818 | int m_Range; // returned value of slider is 0 to m_Range-1. |
| 819 | int m_PixelWidth; // used to get the current position of slider. |
| 820 | float m_IntervalWidth; // width of one tick o |
| 821 | int switch_x, switch_y; // little box width and height. |
| 822 | int switch_w, switch_h; |
| 823 | |
| 824 | UIItem *switch_item; // slider switch item |
| 825 | UIItem *slider_item; // slider item |
| 826 | |
| 827 | public: |
| 828 | UISlider(); |
| 829 | virtual ~UISlider(); |
| 830 | |
| 831 | void Create(UIWindow *parent, int id, int x, int y, int w, int h, int flags = 0); |
| 832 | |
| 833 | // sets visual characteristics of slider. |
| 834 | void SetSliderSwitchItem(UIItem *item); |
| 835 | void SetSliderItem(UIItem *item); |
| 836 | |
| 837 | virtual tUIClass Class() const { // Overide this function to name the class |
| 838 | return uiSlider; |
| 839 | }; |
| 840 | |
| 841 | // settings |
| 842 | void SetRange(int range); // sets range of scroll bar |
| 843 | int GetRange() const { // range of scroll bar |
| 844 | return m_Range; |
| 845 | }; |
| 846 | void SetPos(int pos) { // sets the position of the slider. |
| 847 | if (pos < 0) |
| 848 | pos = 0; |
| 849 | else if (pos >= m_Range) |
| 850 | pos = m_Range - 1; |
| 851 | m_Pos = pos; |
| 852 | }; |
| 853 | int GetPos() const { // gets position of slider. |
| 854 | return m_Pos; |
| 855 | }; |
| 856 | |
| 857 | void SetSelectChangeCallback(void (*fn)(int)); |
| 858 | void SetSelectChangeCallback(void (*fn)(int, void *), void *ptr); |
| 859 | |
| 860 | // called from outside gadget hierarchy. |
| 861 | protected: |
| 862 | virtual void OnFormat(); // override: called when resized or before drawing. |
| 863 | virtual void OnLostFocus(){}; // override: behavior when gadget loses input focus. |
| 864 | virtual void OnGainFocus(){}; // override: behavior when gadget gains input focus. |
| 865 | virtual void OnDraw(); // behavior when gadget is being drawn. |
| 866 | virtual void OnDestroy(); // behavior when gadget is being destroyed. |
| 867 | virtual void OnKeyDown(int key); // behavior when key is pressed. |
| 868 | virtual void OnKeyUp(int key); // behavior when key is released. |
| 869 | virtual void OnMouseBtnDown(int btn); // behavior when mouse button is pressed. |
| 870 | virtual void OnMouseBtnUp(int btn); // behavior when mouse button is released. |
| 871 | virtual void OnSelect(); // override |
| 872 | }; |
| 873 | |
| 874 | // ---------------------------------------------------------------------------- |
| 875 | // UIListBox |
| 876 | // A listbox may contain text items |
| 877 | // Allows the user to scroll through them too. |
| 878 | |
| 879 | #define LISTBOX_BUFFER_SIZE 20 |
| 880 | |
| 881 | class UIListBox : public UIGadget { |
| 882 | void (*selectchange_fn)(int); // callback when selection changes in listbox. |
| 883 | void (*selectchange_id_fn)(int, void *); // callback when selection changes in listbox..also return the ID |
| 884 | void *m_callbackptr; // user defined callback pointer |
| 885 | ddgr_color m_SelectColor; // selected text color |
| 886 | ddgr_color m_HiliteColor; // color of hilite bar |
| 887 | int m_LastMseX, m_LastMseY; // used for double clicking. |
| 888 | uint8_t m_Alpha; // alpha value of listbox. |
| 889 | |
| 890 | bool MseCheckSelect(int x, int y); // check if x and y selection hits a selected item. |
| 891 | void SetInternalSelectedIndex(int index); // call by listbox system. |
| 892 | |
| 893 | protected: |
| 894 | int m_TextOffX, m_TextOffY; // offset of text to border. |
| 895 | int m_ArrowWidth; // with of arrow. |
| 896 | int m_CX, m_CY, m_CX2, m_CY2; // clipping text. |
| 897 | |
| 898 | public: |
| 899 | UIListBox(); |
| 900 | virtual ~UIListBox(); |
| 901 | |
| 902 | void Create(UIWindow *parent, int id, int x, int y, int w, int h, int flags = 0); |
| 903 | |
| 904 | virtual tUIClass Class() const { // Overide this function to name the class |
| 905 | return uiListBox; |
| 906 | }; |
| 907 | |
| 908 | // settings |
| 909 | void AddItem(const UIItem *item); // adds an item to the list, no sorting |
| 910 | void RemoveItem(const UIItem *item); // removes an item from the list. |
| 911 | void RemoveAll(); // empties listbox |
| 912 | void SelectItem(const UIItem *item); // selects the given item in the list. |
| 913 | UIItem *GetItem(int index) const; // returns the item at listbox index given. |
| 914 | |
| 915 | int GetListIndex() const; // returns the current listbox index |
| 916 | void SetListIndex(int index); // sets the index of a listbox |
| 917 | |
| 918 | int GetSelectedIndex() const; // returns which item index is selected |
| 919 | void SetSelectedIndex(int index); // selects an item based on index and moves listbox |
| 920 | void SetSelectedColor(ddgr_color col); // selected text color. |
| 921 | void SetHiliteColor(ddgr_color col); // sets the hilite bar color |
| 922 | |
| 923 | void SetSelectChangeCallback(void (*fn)(int)); |
| 924 | void SetSelectChangeCallback(void (*fn)(int, void *), void *ptr); |
| 925 | |
| 926 | // called from outside gadget hierarchy. |
| 927 | protected: |
| 928 | virtual void OnLostFocus(); // override: behavior when gadget loses input focus. |
| 929 | virtual void OnGainFocus(); // override: behavior when gadget gains input focus. |
| 930 | virtual void OnDraw(); // behavior when gadget is being drawn. |
| 931 | virtual void OnKeyDown(int key); // behavior when key is pressed. |
| 932 | virtual void OnKeyUp(int key); // behavior when key is released. |
| 933 | virtual void OnMouseBtnDown(int btn); // behavior when mouse button is pressed. |
| 934 | virtual void OnMouseBtnUp(int btn); // behavior when mouse button is released. |
| 935 | virtual void OnSelect(); |
| 936 | virtual void OnDestroy(); // called when destroyed. |
| 937 | virtual void OnUserProcess(); // override: behavior when gadget is processed |
| 938 | |
| 939 | private: |
| 940 | UIItem **m_ItemList; // list of items in listbox |
| 941 | int *m_Virt2Real; // translates virtual(user) id to real index |
| 942 | int *m_Real2Virt; // translates real index into virtual(user) id |
| 943 | |
| 944 | float m_ClickTime; // done to check for double clicks? |
| 945 | int m_MouseState; // done for mouse selection. |
| 946 | int m_MouseX, m_MouseY; |
| 947 | int m_NumItems; // number of items in list. |
| 948 | int m_SelectedIndex; // current selected index into listbox |
| 949 | int m_Index; // current index of visible items. |
| 950 | bool m_ShowDown, m_ShowUp; // whether the down and up arrows are displayed |
| 951 | int m_UpArrowY0, m_DownArrowY0; // up and down arrow y locations. |
| 952 | int m_UpArrowY1, m_DownArrowY1; // up and down arrow y max locations. |
| 953 | int m_NumVisibleItems; // number of visible items in list viewport. |
| 954 | |
| 955 | public: |
| 956 | int GetNumItems() const { return m_NumItems; }; |
| 957 | }; |
| 958 | |
| 959 | // ---------------------------------------------------------------------------- |
| 960 | // UIComboBox |
| 961 | // A listbox may contain text items, BUT only one will be visible |
| 962 | // Allows the user to scroll through them too. |
| 963 | |
| 964 | class UIComboBox : public UIGadget { |
| 965 | public: |
| 966 | UIComboBox(); |
| 967 | virtual ~UIComboBox(); |
| 968 | |
| 969 | void Create(UIWindow *parent, int id, int x, int y, int w, int h, int flags = 0); |
| 970 | |
| 971 | private: |
| 972 | UIItem **m_ItemList; // list of items in listbox |
| 973 | int m_nItems; // number of items. |
| 974 | int m_ArrY, m_ArrH; // up and down arrow dimensions |
| 975 | int m_UpArrX, m_UpArrW, m_DownArrX, m_DownArrW; |
| 976 | int m_Index; // current index. |
| 977 | void (*selectchange_fn)(int); // callback when selection changes in listbox. |
| 978 | bool m_ShowUp, m_ShowDown; |
| 979 | float m_scrolltimer; // scroll timer for delay in mouse. |
| 980 | int m_scrollstage; // determines how scrolling will work. |
| 981 | |
| 982 | public: |
| 983 | void AddItem(const UIItem *item); |
| 984 | void RemoveItem(const UIItem *item); // removes an item from the list. |
| 985 | void RemoveAll(); // empties listbox |
| 986 | void SelectItem(const UIItem *item); // selects the given item in the list. |
| 987 | UIItem *GetItem(int index) const; // returns the item at listbox index given. |
| 988 | |
| 989 | int GetSelectedIndex() const { // returns which item index is selected |
| 990 | return m_Index; |
| 991 | }; |
| 992 | void SetSelectedIndex(int index); // sets the selected index. |
| 993 | |
| 994 | void SetSelectChangeCallback(void (*fn)(int)); |
| 995 | |
| 996 | protected: |
| 997 | virtual void OnDraw(); // behavior when gadget is being drawn. |
| 998 | virtual void OnKeyDown(int key); // behavior when key is pressed. |
| 999 | virtual void OnMouseBtnDown(int btn); // behavior when mouse button is pressed. |
| 1000 | virtual void OnMouseBtnUp(int btn); // behavior when mouse button is released |
| 1001 | virtual void OnSelect(); |
| 1002 | virtual void OnDestroy(); // called when destroyed. |
| 1003 | |
| 1004 | protected: |
| 1005 | int m_CX, m_CY, m_CX2, m_CY2; // text clippers. |
| 1006 | }; |
| 1007 | |
| 1008 | // ---------------------------------------------------------------------------- |
| 1009 | // UIConsoleGadget |
| 1010 | // a console that's a gadget within a window |
| 1011 | |
| 1012 | class UIConsoleGadget : public UIGadget { |
| 1013 | int m_ConsoleFont; // standard font for text in console |
| 1014 | ddgr_color *m_ColorRows; // color per row. |
| 1015 | char *m_ConsoleBuffer; // text buffer of console. |
| 1016 | int m_Rows, m_Cols; // dimensions in text. |
| 1017 | int m_VisRows; // visible rows and columns |
| 1018 | int m_VisRowStart; // scroll start of visible region of buffer. |
| 1019 | int m_CurRow, m_CurCol; // current row and column of text pointer |
| 1020 | int m_OffX, m_OffY; |
| 1021 | int m_Rowsize; // rowsize of character buffer. |
| 1022 | ddgr_color m_LineColor; // color of current line. |
| 1023 | int m_LineIndex; // index within current row memory-wise(not column wise). |
| 1024 | int m_PutsBufLen; // current length of puts buffer |
| 1025 | char *m_PutsBuffer; // puts buffer. |
| 1026 | |
| 1027 | private: |
| 1028 | void PutChar(int ch); // outputs a character onto the console. |
| 1029 | void Scroll(); // scrolls window. |
| 1030 | |
| 1031 | protected: |
| 1032 | virtual void OnDraw(); // behavior when gadget is being drawn. |
| 1033 | virtual void OnUserProcess(); // behavior when gadget is processed |
| 1034 | virtual void OnDestroy(); // behavior when gadget is destroyed. |
| 1035 | |
| 1036 | public: |
| 1037 | UIConsoleGadget(); |
| 1038 | virtual ~UIConsoleGadget(); |
| 1039 | |
| 1040 | // font = console font, NOT GADGET FONT. This font is used to proportion window |
| 1041 | void Create(UIWindow *parent, int id, int x, int y, int font, int cols, int rows, int flags = UIF_BORDER); |
| 1042 | |
| 1043 | // functions |
| 1044 | void puts(ddgr_color color, const char *str); |
| 1045 | }; |
| 1046 | |
| 1047 | // ---------------------------------------------------------------------------- |
| 1048 | // UIWindow |
| 1049 | // A window contains different UIGadgets. |
| 1050 | // This is where all objects will interact with the user. |
| 1051 | #define N_WINDOW_ACCELS 48 |
| 1052 | |
| 1053 | class UIWindow : public UIObject { |
| 1054 | friend class UIGadget; |
| 1055 | |
| 1056 | UIGadget *m_GadgetHead; // gadget list for window |
| 1057 | UIGadget *m_GadgetTail; |
| 1058 | UIGadget *m_GadgetCur; |
| 1059 | UIGadget *m_LockedGadget; // marks a particular gadget that will always have focus |
| 1060 | UIItem *m_BackItem; // background UI item. |
| 1061 | |
| 1062 | float m_KeyTime; // time when key went down. |
| 1063 | |
| 1064 | ddgr_color m_BackColor; // unconditional background color |
| 1065 | int m_FontHandle; |
| 1066 | int m_LastKey; // the last key pressed. |
| 1067 | int m_LastKeyCount; // number of times last key was pressed. |
| 1068 | float m_LastKeyTime; // last key time. |
| 1069 | bool m_HoldHotkeys; |
| 1070 | bool m_ResetCurGadget; // next process will reset current gadget to 1st valid one. |
| 1071 | bool m_CurGadgetInGroup; // is m_GadgetCur inside a group? |
| 1072 | struct { |
| 1073 | int key; |
| 1074 | int id; |
| 1075 | } m_Accelerators[N_WINDOW_ACCELS]; // used for quick key press interaction |
| 1076 | int m_naccels; |
| 1077 | |
| 1078 | static int m_WindowFont; // global window default font |
| 1079 | |
| 1080 | private: |
| 1081 | bool TrapKey(int key); |
| 1082 | void UntrapKey(int key); |
| 1083 | void LockFocusOnGadget(UIGadget *gadget); // forces a particular gadget into focus, always until unlocked. |
| 1084 | void UnlockFocusOnGadget(); |
| 1085 | |
| 1086 | protected: |
| 1087 | ddgr_color GetBackColor() const { return m_BackColor; }; |
| 1088 | |
| 1089 | int m_Flags; // window flags. |
| 1090 | |
| 1091 | // inheritable actions |
| 1092 | protected: |
| 1093 | virtual void OnDraw(); // overridable draws the window background before gadgets |
| 1094 | virtual void OnUserProcess(); // overridable: runs after window is processed, to supplement it. |
| 1095 | virtual void OnDestroy(){}; // overridable: called in Destroy |
| 1096 | virtual void OnKeyDown(int key); // behavior when key is pressed. |
| 1097 | virtual void OnKeyUp(int key); // behavior when key is released. |
| 1098 | |
| 1099 | public: |
| 1100 | static void SetDefaultFont(int font) { // sets the default font for any window |
| 1101 | UIWindow::m_WindowFont = font; |
| 1102 | }; |
| 1103 | |
| 1104 | public: |
| 1105 | UIWindow(); |
| 1106 | virtual ~UIWindow(); |
| 1107 | |
| 1108 | void Destroy(); // must call if you created window. will be called in destructor |
| 1109 | |
| 1110 | void Create(int x, int y, int w, int h, int flags = 0); |
| 1111 | int GetFlags() const { return m_Flags; }; |
| 1112 | |
| 1113 | // used to mark key pressed to id numbers |
| 1114 | void AddAcceleratorKey(int key, int id); |
| 1115 | void ResetAcceleratorKey(); |
| 1116 | |
| 1117 | // gadget management |
| 1118 | void AddGadget(UIGadget *gadget); // adds a gadget to the gadget list |
| 1119 | void RemoveGadget(UIGadget *gadget); // removes a gadget from the list. |
| 1120 | UIGadget *GetGadgetFromID(int id); // returns the gadget pointer given an id if in window |
| 1121 | void SetFocusOnGadget(UIGadget *gadget, bool key = false); |
| 1122 | |
| 1123 | UIGadget *GetFocus() { return m_GadgetCur; }; |
| 1124 | |
| 1125 | // input/output management |
| 1126 | virtual int Process(); // handles gadget selection/focus and calls gadgets. |
| 1127 | void Render(); // renders one window frame. |
| 1128 | void Open(); // adds window to ui list. |
| 1129 | void Close(); // removes window from ui list. |
| 1130 | |
| 1131 | // settings |
| 1132 | void SetFont(int handle); // sets window's font. |
| 1133 | void SetBackItem(UIItem *item) { // sets the background drawing item. |
| 1134 | if (m_BackItem) |
| 1135 | delete m_BackItem; |
| 1136 | m_BackItem = NULL; |
| 1137 | if (item) |
| 1138 | m_BackItem = item->CopyUIItem(); |
| 1139 | }; // |
| 1140 | void SetBackColor(ddgr_color col) { // sets the background color. this is ALWAYS first, then the backitem |
| 1141 | m_BackColor = col; |
| 1142 | }; |
| 1143 | |
| 1144 | void HoldHotkeys() { m_HoldHotkeys = true; }; // no hotkeys will be processed until ResumeHotkeys is called. |
| 1145 | void ResumeHotkeys() { m_HoldHotkeys = false; }; |
| 1146 | |
| 1147 | // class id |
| 1148 | virtual tUIClass Class() const { // Overide this function to name the class |
| 1149 | return uiWindow; |
| 1150 | }; |
| 1151 | |
| 1152 | // OBSOLETE |
| 1153 | void LockKeyFocusOnGadget(UIGadget *gadget); // forces all keyinput onto one gadget. (be wary) |
| 1154 | }; |
| 1155 | |
| 1156 | // Special windows |
| 1157 | // titled window (functions as a standard dialog box.), without modality though. |
| 1158 | |
| 1159 | class UITitledWindow : public UIWindow { |
| 1160 | UITextItem m_Title; // title of window |
| 1161 | int m_CaptionColor; // caption's color. |
| 1162 | int m_BorderThickness; // border thickness. |
| 1163 | |
| 1164 | public: |
| 1165 | UITitledWindow(); |
| 1166 | virtual ~UITitledWindow(); |
| 1167 | |
| 1168 | void Create(UITextItem &title, int x, int y, int w, int h); |
| 1169 | |
| 1170 | // class id |
| 1171 | virtual tUIClass Class() const { // Overide this function to name the class |
| 1172 | return uiTitledWindow; |
| 1173 | }; |
| 1174 | |
| 1175 | // settings |
| 1176 | void SetText(UITextItem &text) { // sets the text for a window title. |
| 1177 | m_Title = text; |
| 1178 | }; |
| 1179 | void SetCaptionColor(ddgr_color col) { // sets the color of the caption region |
| 1180 | m_CaptionColor = col; |
| 1181 | }; |
| 1182 | void SetBorderThickness(int thickness) { // sets the pixel thickness of the border |
| 1183 | m_BorderThickness = thickness; |
| 1184 | }; |
| 1185 | |
| 1186 | int GetBorderThickness() const { return m_BorderThickness; }; // returns border thickness. |
| 1187 | |
| 1188 | // inheritable actions |
| 1189 | protected: |
| 1190 | virtual void OnDraw(); // overridable draws the window background before gadgets |
| 1191 | }; |
| 1192 | |
| 1193 | // UIConsole |
| 1194 | // should display a simple console window where anyone can dump text into |
| 1195 | |
| 1196 | class UIConsole : public UIWindow { |
| 1197 | UIConsoleGadget m_Console; |
| 1198 | |
| 1199 | protected: |
| 1200 | virtual void OnDraw(); |
| 1201 | |
| 1202 | public: |
| 1203 | UIConsole(); |
| 1204 | virtual ~UIConsole(); |
| 1205 | |
| 1206 | // font = console font, NOT GADGET FONT. This font is used to proportion window |
| 1207 | void Create(int x, int y, int font, int cols, int rows); |
| 1208 | void Destroy(); |
| 1209 | |
| 1210 | // functions |
| 1211 | void puts(const char *str); |
| 1212 | void puts(ddgr_color col, const char *str); |
| 1213 | }; |
| 1214 | |
| 1215 | // other inline functions |
| 1216 | inline bool UIGadget::HasFocus() const { return ((m_Wnd->GetFocus() == this) ? true : false); }; |
| 1217 | |
| 1218 | #include "uisys.h" |
| 1219 | #include "uidraw.h" |
| 1220 | |
| 1221 | #endif |