Descent3/lib/ui.h

1221 lines
42 KiB
C
Raw Normal View History

/*
* Descent 3
* Copyright (C) 2024 Parallax Software
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
--- HISTORICAL COMMENTS FOLLOW ---
2024-04-16 03:43:29 +00:00
* $Logfile: /DescentIII/Main/Lib/ui.h $
* $Revision: 75 $
* $Date: 5/17/99 5:19p $
* $Author: Samir $
*
* UI system
*
* $Log: /DescentIII/Main/Lib/ui.h $
2024-04-16 18:56:40 +00:00
*
2024-04-16 03:43:29 +00:00
* 75 5/17/99 5:19p Samir
* added ability for edit box to autoselect when hitting the max number of
* characters typable.
2024-04-16 18:56:40 +00:00
*
2024-04-16 03:43:29 +00:00
* 74 5/02/99 2:08a Samir
* added Enable and Disable and only accept locking of button if mouse is
* inside the button.
2024-04-16 18:56:40 +00:00
*
2024-04-16 03:43:29 +00:00
* 73 4/29/99 2:21a Samir
* added flag for gadgets.
2024-04-16 18:56:40 +00:00
*
2024-04-16 03:43:29 +00:00
* 72 4/28/99 1:54a Samir
* visual tweaks to text
2024-04-16 18:56:40 +00:00
*
2024-04-16 03:43:29 +00:00
* 71 4/26/99 7:46p Samir
* you can get flags from a window now.
2024-04-16 18:56:40 +00:00
*
2024-04-16 03:43:29 +00:00
* 70 4/16/99 4:02a Jeff
* include linux_fix.h for linxu builds...reduces errors
2024-04-16 18:56:40 +00:00
*
2024-04-16 03:43:29 +00:00
* 69 4/15/99 1:45a Jeff
* changes for linux compile
2024-04-16 18:56:40 +00:00
*
2024-04-16 03:43:29 +00:00
* 68 4/03/99 9:26p Jeff
* changed dialogs that weren't using UID_OK and UID_CANCEL to use and
* handle them properly
2024-04-16 18:56:40 +00:00
*
2024-04-16 03:43:29 +00:00
* 67 3/23/99 9:02p Samir
* up accelerator count for windows to 48.
2024-04-16 18:56:40 +00:00
*
2024-04-16 03:43:29 +00:00
* 66 2/28/99 3:25a Samir
* added flag to input only numbers.
2024-04-16 18:56:40 +00:00
*
2024-04-16 03:43:29 +00:00
* 65 2/26/99 2:12a Samir
* added window accelrators
2024-04-16 18:56:40 +00:00
*
2024-04-16 03:43:29 +00:00
* 64 2/22/99 8:13p Samir
* added slave gadget system that only uses mouse input from window, but
* defers keys to its master.
2024-04-16 18:56:40 +00:00
*
2024-04-16 03:43:29 +00:00
* 63 2/21/99 6:36p Samir
* focusing changes and key input changes to ui.,
2024-04-16 18:56:40 +00:00
*
2024-04-16 03:43:29 +00:00
* 62 2/17/99 8:32p Samir
* fixed bugs in remove gadget, added callbacks for attaching and
* detaching gadgets.
2024-04-16 18:56:40 +00:00
*
2024-04-16 03:43:29 +00:00
* 61 2/16/99 12:08p Samir
* added gadget notification system.
2024-04-16 18:56:40 +00:00
*
2024-04-16 03:43:29 +00:00
* 60 1/18/99 5:08a Jeff
* added some flags related to sorted listboxes
2024-04-16 18:56:40 +00:00
*
2024-04-16 03:43:29 +00:00
* 59 12/30/98 12:16p Kevin
* Auto Mission Download system
2024-04-16 18:56:40 +00:00
*
2024-04-16 03:43:29 +00:00
* 58 11/03/98 7:05p Samir
* added word wrapping console.
2024-04-16 18:56:40 +00:00
*
2024-04-16 03:43:29 +00:00
* 57 10/20/98 12:14p Jeff
* added color to the UIGroup
2024-04-16 18:56:40 +00:00
*
2024-04-16 03:43:29 +00:00
* 56 10/19/98 6:30p Jeff
* changes made for detail variables. Put in preset values. Preset
* options. Removed terrain_cast from detail. Put new callbacks in
* UIListBox and UISlider
2024-04-16 18:56:40 +00:00
*
2024-04-16 03:43:29 +00:00
* 55 10/19/98 12:18p Samir
* made tabbing between edit controls possible.
2024-04-16 18:56:40 +00:00
*
2024-04-16 03:43:29 +00:00
* 54 10/17/98 11:26a Samir
* fixed some edit box scrolling issues.
2024-04-16 18:56:40 +00:00
*
2024-04-16 03:43:29 +00:00
* 53 10/16/98 1:42p Jeff
* updated UIGroup
2024-04-16 18:56:40 +00:00
*
2024-04-16 03:43:29 +00:00
* 52 10/07/98 11:25a Jeff
* created UIGroup
2024-04-16 18:56:40 +00:00
*
2024-04-16 03:43:29 +00:00
* 51 9/30/98 4:34p Samir
* added enable function.
2024-04-16 18:56:40 +00:00
*
2024-04-16 03:43:29 +00:00
* 50 9/22/98 3:57p Samir
* listbox prob fixed again.
2024-04-16 18:56:40 +00:00
*
2024-04-16 03:43:29 +00:00
* 49 9/14/98 11:22a Samir
* enhanced editboxes
2024-04-16 18:56:40 +00:00
*
2024-04-16 03:43:29 +00:00
* 48 9/02/98 6:50p Samir
* added new combo box.
2024-04-16 18:56:40 +00:00
*
2024-04-16 03:43:29 +00:00
* 47 8/27/98 5:03p Kevin
* Prettied up multiplayer screens and fixed some bugs.
2024-04-16 18:56:40 +00:00
*
2024-04-16 03:43:29 +00:00
* 46 8/27/98 2:52p Samir
* changing window system to work in two modes.
2024-04-16 18:56:40 +00:00
*
2024-04-16 03:43:29 +00:00
* 45 8/26/98 12:25p Samir
* fixed the whole editbox, keyboard access mess.
2024-04-16 18:56:40 +00:00
*
2024-04-16 03:43:29 +00:00
* 44 8/25/98 7:08p Samir
* select how keys are sent to a gadget.
2024-04-16 18:56:40 +00:00
*
2024-04-16 03:43:29 +00:00
* 43 8/25/98 5:27p Samir
* new focusing rules for keyboard.
2024-04-16 18:56:40 +00:00
*
2024-04-16 03:43:29 +00:00
* 42 8/24/98 3:12p Samir
* fixed text clipping
2024-04-16 18:56:40 +00:00
*
2024-04-16 03:43:29 +00:00
* 41 8/11/98 11:38a Samir
* fixed listbox probs yet again. arrows on side this time.
2024-04-16 18:56:40 +00:00
*
2024-04-16 03:43:29 +00:00
* 40 7/29/98 3:26p Samir
* fixed some listbox mouse problems.
2024-04-16 18:56:40 +00:00
*
2024-04-16 03:43:29 +00:00
* 39 6/23/98 5:05p Samir
* console supports color per line ONLY.
2024-04-16 18:56:40 +00:00
*
2024-04-16 03:43:29 +00:00
* 38 6/22/98 7:31p Samir
* added UIEdit::Activate, which activates an edit box manually.
2024-04-16 18:56:40 +00:00
*
2024-04-16 03:43:29 +00:00
* 37 6/22/98 2:15p Samir
* added UIConsoleGadget.
2024-04-16 18:56:40 +00:00
*
2024-04-16 03:43:29 +00:00
* 36 6/05/98 5:58p Jeff
* Added a way to change the items for the states of a HotSpot
2024-04-16 18:56:40 +00:00
*
2024-04-16 03:43:29 +00:00
* 35 6/05/98 5:35p Samir
* massive improvement in UI keyboard interface.
2024-04-16 18:56:40 +00:00
*
2024-04-16 03:43:29 +00:00
* 34 5/22/98 5:02p Jeff
* Added a flag for radio buttons so the button part won't be drawn (just
* the text)
2024-04-16 18:56:40 +00:00
*
2024-04-16 03:43:29 +00:00
* 33 5/08/98 3:58p Samir
* added ability to move a UI object.
2024-04-16 18:56:40 +00:00
*
2024-04-16 03:43:29 +00:00
* 32 4/29/98 1:04p Jeff
* fixed up the UIListBox a bit (color control and scroll buttons)
2024-04-16 18:56:40 +00:00
*
2024-04-16 03:43:29 +00:00
* 31 4/29/98 11:55a Samir
* allow user to change color of selected listbox item.
2024-04-16 18:56:40 +00:00
*
2024-04-16 03:43:29 +00:00
* 30 4/24/98 2:42a Samir
* added UICheckBox
2024-04-16 18:56:40 +00:00
*
2024-04-16 03:43:29 +00:00
* 29 4/13/98 7:02p Samir
* made some things protected.
2024-04-16 18:56:40 +00:00
*
2024-04-16 03:43:29 +00:00
* 28 3/13/98 5:18p Jeff
* Added 2 flags for new UIListBox for scrolling and some member vars for
* UIListBox
2024-04-16 18:56:40 +00:00
*
2024-04-16 03:43:29 +00:00
* 27 3/10/98 7:25p Samir
* Changes to UISlider
2024-04-16 18:56:40 +00:00
*
2024-04-16 03:43:29 +00:00
* 26 3/10/98 12:48p Samir
* Fixed flags for UIWindow so centering is supported.
2024-04-16 18:56:40 +00:00
*
2024-04-16 03:43:29 +00:00
* 25 3/09/98 5:05p Samir
* Added callback to selection change function.
2024-04-16 18:56:40 +00:00
*
2024-04-16 03:43:29 +00:00
* 24 3/09/98 3:43p Samir
* Made some window flag changes.
2024-04-16 18:56:40 +00:00
*
2024-04-16 03:43:29 +00:00
* 23 3/06/98 10:48a Samir
* Check if button is active.
2024-04-16 18:56:40 +00:00
*
2024-04-16 03:43:29 +00:00
* 22 3/05/98 6:40p Samir
* Implemented radio buttons.
2024-04-16 18:56:40 +00:00
*
2024-04-16 03:43:29 +00:00
* 21 3/04/98 12:08p Samir
* Slider fixed.
2024-04-16 18:56:40 +00:00
*
2024-04-16 03:43:29 +00:00
* 20 2/26/98 2:50p Samir
* Did some stuff with UISlider.
2024-04-16 18:56:40 +00:00
*
2024-04-16 03:43:29 +00:00
* 19 2/15/98 7:07p Samir
* Revamped way keys like up and down are handled in window system.
2024-04-16 18:56:40 +00:00
*
2024-04-16 03:43:29 +00:00
* 18 2/13/98 6:34p Samir
* Added UIStatic class.
2024-04-16 18:56:40 +00:00
*
2024-04-16 03:43:29 +00:00
* 17 2/10/98 4:55p Samir
* Added radio buttons.
2024-04-16 18:56:40 +00:00
*
2024-04-16 03:43:29 +00:00
* 16 2/02/98 7:36p Samir
* Added UIObject::Destroy.
2024-04-16 18:56:40 +00:00
*
2024-04-16 03:43:29 +00:00
* 15 1/30/98 7:03p Samir
* Added UIConsole.
2024-04-16 18:56:40 +00:00
*
2024-04-16 03:43:29 +00:00
* 14 1/23/98 5:45p Samir
* Added OnUserProcess to UIWindow class.
2024-04-16 18:56:40 +00:00
*
2024-04-16 03:43:29 +00:00
* 13 1/18/98 4:22p Samir
* Implemented new UIItem system.
2024-04-16 18:56:40 +00:00
*
2024-04-16 03:43:29 +00:00
* 12 1/13/98 6:59p Jeff
* (Samir) moved defines from UIlib.h to ui.h.
2024-04-16 18:56:40 +00:00
*
2024-04-16 03:43:29 +00:00
* 11 1/13/98 4:32p Samir
* Made tUIInput a shared structure to be used by ui_DoFrame to return UI
* input values.
2024-04-16 18:56:40 +00:00
*
2024-04-16 03:43:29 +00:00
* 10 1/13/98 4:28p Samir
* Added sliders.
2024-04-16 18:56:40 +00:00
*
2024-04-16 03:43:29 +00:00
* 9 1/09/98 12:01p Samir
* Added prototypes for sliders, listboxes, and scrollbars.
2024-04-16 18:56:40 +00:00
*
2024-04-16 03:43:29 +00:00
* 8 1/08/98 12:17p Samir
* Added TitledWindow and modified the UI interface for polling.
2024-04-16 18:56:40 +00:00
*
2024-04-16 03:43:29 +00:00
* 7 1/05/98 4:55p Samir
* Took out m_Flags from child classes of UIGadget
2024-04-16 18:56:40 +00:00
*
2024-04-16 03:43:29 +00:00
* 6 1/05/98 4:36p Samir
* Moved centering and fittext control flags to UIGadget class.
2024-04-16 18:56:40 +00:00
*
2024-04-16 03:43:29 +00:00
* 5 1/05/98 4:19p Samir
* UIGadget has fewer pure virtuals.
2024-04-16 18:56:40 +00:00
*
2024-04-16 03:43:29 +00:00
* 4 1/05/98 3:48p Jason
* added SetAllText function for buttons
2024-04-16 18:56:40 +00:00
*
2024-04-16 03:43:29 +00:00
* 3 1/05/98 3:18p Samir
* Added some button flags.
2024-04-16 18:56:40 +00:00
*
2024-04-16 03:43:29 +00:00
* 2 1/02/98 12:49p Samir
* Edit control and static control added.
2024-04-16 18:56:40 +00:00
*
2024-04-16 03:43:29 +00:00
* 1 12/30/97 4:37p Samir
* Initial revision
2024-04-16 18:56:40 +00:00
*
2024-04-16 03:43:29 +00:00
* $NoKeywords: $
*/
#ifndef UI_H
#define UI_H
#if defined(__LINUX__)
#include "linux_fix.h" //for stricmp's through code
2024-04-16 03:43:29 +00:00
#endif
#include "uires.h"
#include "pstypes.h"
#include "pserror.h"
#include "grdefs.h"
// Class identification
typedef unsigned tUIClass;
2024-04-16 18:56:40 +00:00
const tUIClass uiObject = 0, uiWindow = 1, uiTitledWindow = 2, uiGadget = 3, uiHotspot = 4, uiButton = 5, uiEdit = 6,
uiText = 7, uiSlider = 8, uiVScrollBar = 9, uiListBox = 10;
2024-04-16 03:43:29 +00:00
2024-04-16 18:56:40 +00:00
const tUIClass uiNewClass = 100;
2024-04-16 03:43:29 +00:00
typedef int tUIBmpHandle;
class UIObject;
class UIGadget;
class UIInterface;
class UIItem;
class UITextItem;
class UIWindow;
// ----------------------------------------------------------------------------
// UIObject
// The absolute primitive for the UI system. All UI class are derived from
2024-04-16 18:56:40 +00:00
// tUIObject.
2024-04-16 03:43:29 +00:00
2024-04-16 18:56:40 +00:00
class UIObject {
bool m_Created; // is this object created?
2024-04-16 03:43:29 +00:00
2024-04-16 18:56:40 +00:00
// variables shared by the entire UI hierarchy
2024-04-16 03:43:29 +00:00
protected:
2024-04-16 18:56:40 +00:00
int m_X, m_Y; // Location of UIObject relative to some other object.
int m_W, m_H; // Dimensions of the UIObject
2024-04-16 03:43:29 +00:00
public:
2024-04-16 18:56:40 +00:00
UIObject();
virtual ~UIObject();
2024-04-16 03:43:29 +00:00
2024-04-16 18:56:40 +00:00
void Create(int x, int y, int w, int h); // define the ui object.
void Destroy() { m_Created = false; };
bool IsCreated() const { return m_Created; };
2024-04-16 03:43:29 +00:00
2024-04-16 18:56:40 +00:00
// data access
int X() const { return m_X; }; // access the X,Y,W,H fields.
int Y() const { return m_Y; };
int W() const { return m_W; };
int H() const { return m_H; };
2024-04-16 03:43:29 +00:00
2024-04-16 18:56:40 +00:00
// moves the object.
void Move(int x, int y, int w, int h);
2024-04-16 03:43:29 +00:00
2024-04-16 18:56:40 +00:00
// inheritable operations
2024-04-16 03:43:29 +00:00
public:
2024-04-16 18:56:40 +00:00
virtual tUIClass Class() const { // Overide this function to name the class
return uiObject;
};
2024-04-16 03:43:29 +00:00
};
// ----------------------------------------------------------------------------
// UIGadget
// A gadget is a user interface item which a mouse or keyboard may interact with.
// Gadgets typically are managed by their parent interface.
// All buttons, checkboxes, listboxes, etc use tUIGadget as their parent.
// flags
2024-04-16 18:56:40 +00:00
#define UIF_CENTER 0x01
#define UIF_FIT 0x02
#define UIF_BORDER 0x04 // for certain gadgets specifies that the border be drawn.
#define UIF_SLAVE 0x10 // gadget never gets focus from ui system directly (child gadgets).
#define UIF_NOTIFYMASTERSEL 0x20 // when slave gadget is selected, the master will know.
#define UIF_PROCESS_MENU 0x40 // use this to create a 'menu style' window (Options menu)
#define UIF_PROCESS_ALL UIF_PROCESS_MENU // to maintain compatibility with older code.
#define UIF_GROUP_START 0x80 // starts a group of gadgets that use the up and down arrows to move between
#define UIF_GROUP_END 0x100 // ends a group
2024-04-16 03:43:29 +00:00
2024-04-16 18:56:40 +00:00
#define UIF_CUSTOMF 0x200 // use this flag and any higher for custom gadget flags, a list of predefs below
2024-04-16 03:43:29 +00:00
2024-04-16 18:56:40 +00:00
#define UILB_NOSCROLL 0x800 // turns off automatic scroll buttons on UIListBox
#define UILB_AUTOSELECT 0x1000 // turns on automatic change of SelectedIndex if scrolled out of view
#define UILB_NOSORT 0x2000 // disables sorting in a listbox
#define UILB_CASESENSITIVE 0x4000 // only if !UILB_NOSORT. Makes the sorting case sensitive
2024-04-16 03:43:29 +00:00
2024-04-16 18:56:40 +00:00
#define UIRB_NOBUTTON 0x800 // disables the drawing of the button on the left of the text of a radio button
2024-04-16 03:43:29 +00:00
2024-04-16 18:56:40 +00:00
#define UIED_PASSWORD 0x800 // special password masking for edit box text (*)
#define UIED_NUMBERS 0x1000 // only accept numbers for input!
#define UIED_AUTOSELECT 0x2000 // selects when input reaches buffer length.
2024-04-16 03:43:29 +00:00
// any flags after 0x10000-0x40000000 are reserved internal to gadget controls
// ids
2024-04-16 18:56:40 +00:00
#define UID_OK 0xEE
#define UID_CANCEL 0xEF
2024-04-16 03:43:29 +00:00
2024-04-16 18:56:40 +00:00
class UIGadget : public UIObject {
friend class UIWindow;
2024-04-16 03:43:29 +00:00
2024-04-16 18:56:40 +00:00
UIGadget *m_Prev;
UIGadget *m_Next; // for maintaining list of linked gadgets.
2024-04-16 03:43:29 +00:00
2024-04-16 18:56:40 +00:00
// master gadgets
UIGadget *m_MasterGadget; // select target
UIGadget *m_CurrentSlave; // current slave gadget in master.
2024-04-16 03:43:29 +00:00
2024-04-16 18:56:40 +00:00
// slave gadgets
UIGadget *m_SlaveGadgets; // contains a list of slave gadgets.
UIGadget *m_NextSlave;
UIGadget *m_PrevSlave;
2024-04-16 03:43:29 +00:00
2024-04-16 18:56:40 +00:00
// information for gadgets
2024-04-16 03:43:29 +00:00
private:
2024-04-16 18:56:40 +00:00
int m_ID; // id value of gadget.
int16_t m_Datum; // used to pass info around.
uint16_t m_Hotkey;
2024-04-16 18:56:40 +00:00
int m_SavedW, m_SavedH; // saved values of width and height.
bool m_Disabled; // is gadget disabled?
2024-04-16 03:43:29 +00:00
2024-04-16 18:56:40 +00:00
static int m_LastKey; // the last key pressed.
static int m_LastKeyCount; // number of times last key was pressed.
static float m_LastKeyTime; // last key time.
2024-04-16 03:43:29 +00:00
2024-04-16 18:56:40 +00:00
bool TrapKey(int key); // used to manage keypresses so repeating isn't quick.
void UntrapKey(int key);
void CheckFocusOnSlaves(int mx, int my);
2024-04-16 03:43:29 +00:00
// universal variables
2024-04-16 18:56:40 +00:00
#ifdef __LINUX__ // gcc has a hard time tracing through some of the derived classes that access m_Wnd
2024-04-16 03:43:29 +00:00
public:
#else
protected:
#endif
2024-04-16 18:56:40 +00:00
UIWindow *m_Wnd; // the gadget's parent window
2024-04-16 03:43:29 +00:00
protected:
2024-04-16 18:56:40 +00:00
int m_Flags; // flags
bool m_infocus; // gadget has focus.
int GetSavedW() const { return m_SavedW; };
int GetSavedH() const { return m_SavedH; };
inline bool HasFocus() const;
UIGadget *GetPrevUsableGadget(); // gets next gadget lower in chain that's not disabled
UIGadget *GetNextUsableGadget(); // gets next gadget higher in chain that's not disabled
void LostFocus(); // called by window system
void GainFocus(); // called by window system
void LockFocus(); // forces input to this gadget
void UnlockFocus(); // releases lock on input to gadget.
2024-04-16 03:43:29 +00:00
// called from outside gadget hierarchy.
2024-04-16 18:56:40 +00:00
#ifdef __LINUX__ // gcc has a hard time tracing through the dervived classes of newuiButton and thinks it can't access
// OnFormat()
2024-04-16 03:43:29 +00:00
public:
#else
protected:
#endif
2024-04-16 18:56:40 +00:00
virtual void OnFormat(); // override: called when resized or before drawing.
2024-04-16 03:43:29 +00:00
protected:
2024-04-16 18:56:40 +00:00
virtual void OnLostFocus(){}; // override: behavior when gadget loses input focus.
virtual void OnGainFocus(){}; // override: behavior when gadget gains input focus.
virtual void OnAttachToWindow(){}; // override: when gadget is attached to window, this is called.
virtual void OnDetachFromWindow(){}; // override: when gadget is detached from window, this is called.
virtual void OnDraw() = 0; // MUST override: behavior when gadget is being drawn.
2024-04-16 03:43:29 +00:00
2024-04-16 18:56:40 +00:00
// called by Process.
2024-04-16 03:43:29 +00:00
protected:
2024-04-16 18:56:40 +00:00
virtual void OnKeyDown(int key){}; // override: behavior when key is pressed.
virtual void OnKeyUp(int key){}; // override: behavior when key is released.
virtual void OnMouseBtnDown(int btn){}; // override: behavior when mouse button is pressed.
virtual void OnMouseBtnUp(int btn){}; // override: behavior when mouse button is released.
virtual void OnDestroy(){}; // override: behavior when gadget is destroyed.
virtual void OnUserProcess(){}; // override: behavior when gadget is processed
virtual void OnNotifySelect(UIGadget *sender){}; // override: send gadget select message to another gadget.
// typically this function is called by a child class when we want
// to tell the caller that this gadget was selected for something.
virtual void OnSelect(); // override: behavior when gadget is selected.
2024-04-16 03:43:29 +00:00
public:
2024-04-16 18:56:40 +00:00
virtual void OnNotify(UIGadget *){}; // usually called by a child gadget of a gadget.
2024-04-16 03:43:29 +00:00
public:
2024-04-16 18:56:40 +00:00
UIGadget();
virtual ~UIGadget();
UIWindow *GetWindow() { // returns the parent window for a gadget.
return m_Wnd;
};
// returns link in gadget chain.
UIGadget *Next() const { return m_Next; };
UIGadget *Prev() const { return m_Prev; };
// defines the graphical representation of a gadget within a window.
// ALL Gadgets must have a wnd.
void Create(UIWindow *wnd, int id, int x, int y, int w, int h, int flags);
void Destroy();
// interprets input on this gadget. this gadget is in focus.
void Process(bool do_keys = true, bool do_mouse = true, bool do_user = true);
bool IsLocked() const; // is this gadget's focus locked?
// settings
void SetHotkey(int key); // set this when key is pressed, selects gadget.
int GetID() const { return m_ID; };
int16_t GetDatum() const { return m_Datum; };
void SetDatum(int16_t datum) { m_Datum = datum; };
2024-04-16 18:56:40 +00:00
bool IsDisabled() { return m_Disabled; }; // returns disabled state.
void Disable() { m_Disabled = true; }; // disables gadget.
void Enable() { m_Disabled = false; }; // enables gadget.
int GetFlags() const { return m_Flags; }; // gets flags for gadget.
void SetFlag(int flag);
void ClearFlag(int flag);
// OnSelect messages to another gadget
void AttachSlaveGadget(UIGadget *gadget);
void DetachSlaveGadget(UIGadget *gadget);
// class id
virtual tUIClass Class() const { // Overide this function to name the class
return uiGadget;
};
2024-04-16 03:43:29 +00:00
};
// ----------------------------------------------------------------------------
// UIHotspot
// This is simply a region within the parent window that when clicked on
// or key pressed, does something.
2024-04-16 18:56:40 +00:00
class UIHotspot : public UIGadget {
UIItem *m_ItemOff, *m_ItemOn; // off and on states items.
UIItem *m_ItemCur; // current item.
2024-04-16 03:43:29 +00:00
protected:
2024-04-16 18:56:40 +00:00
virtual void OnKeyDown(int key); // override: behavior when key is pressed.
virtual void OnKeyUp(int key){}; // override: behavior when key is released.
virtual void OnMouseBtnDown(int btn); // override: behavior when mouse button is pressed.
virtual void OnMouseBtnUp(int btn); // override: behavior when mouse button is released.
virtual void OnFormat(); // override: called when resized or before drawing.
virtual void OnDraw(); // override: behavior when gadget is being drawn.
virtual void OnLostFocus(); // override: behavior when gadget loses input focus.
virtual void OnGainFocus(); // override: behavior when gadget gains input focus.
virtual void OnDestroy(); // override: behavior when gadget is destroyed.
2024-04-16 03:43:29 +00:00
public:
2024-04-16 18:56:40 +00:00
UIHotspot();
virtual ~UIHotspot();
2024-04-16 03:43:29 +00:00
2024-04-16 18:56:40 +00:00
// optional key, when pressed, triggers hotspot.
void Create(UIWindow *wnd, int id, int key, UIItem *itemoff, UIItem *itemon, int x, int y, int w, int h,
int flags = 0);
2024-04-16 03:43:29 +00:00
2024-04-16 18:56:40 +00:00
// sets the items for the on/off state of the hotspot
void SetStates(UIItem *itemoff, UIItem *itemon);
2024-04-16 03:43:29 +00:00
2024-04-16 18:56:40 +00:00
// class id
virtual tUIClass Class() const { // Overide this function to name the class
return uiHotspot;
};
2024-04-16 03:43:29 +00:00
};
// tUIButton family
// this family contains buttons, radio buttons, and checkboxes
// states
2024-04-16 18:56:40 +00:00
#define UI_BTS_NUM 4
#define UI_BTS_DISABLED 0
#define UI_BTS_INACTIVE 1
#define UI_BTS_HILITE 2
#define UI_BTS_ACTIVATED 3
2024-04-16 03:43:29 +00:00
// ----------------------------------------------------------------------------
// UIButton
// This is a simple 2 state button (push down or push up)
// Buttons have properties of gadgets, plus bitmap information per state.
2024-04-16 18:56:40 +00:00
class UIButton : public UIGadget {
private:
UIItem *m_Items[UI_BTS_NUM]; // UI Items for each state
ddgr_color m_Colors[UI_BTS_NUM]; // Backgrounds for states
2024-04-16 03:43:29 +00:00
2024-04-16 18:56:40 +00:00
static int m_ButtonFont; // button fonts.
2024-04-16 03:43:29 +00:00
protected:
2024-04-16 18:56:40 +00:00
int m_State; // state of button
2024-04-16 03:43:29 +00:00
2024-04-16 18:56:40 +00:00
UIItem *GetStateItem(int state) {
ASSERT(state < UI_BTS_NUM);
return m_Items[state];
};
2024-04-16 03:43:29 +00:00
2024-04-16 18:56:40 +00:00
int GetColor(int state) const {
ASSERT(state < UI_BTS_NUM);
return m_Colors[state];
};
2024-04-16 03:43:29 +00:00
public:
2024-04-16 18:56:40 +00:00
static void SetDefaultFont(int font) { // sets the button font
UIButton::m_ButtonFont = font;
};
2024-04-16 03:43:29 +00:00
public:
2024-04-16 18:56:40 +00:00
UIButton();
virtual ~UIButton();
2024-04-16 03:43:29 +00:00
2024-04-16 18:56:40 +00:00
void Create(UIWindow *parent, int id, UIItem *title, int x, int y, int w, int h, int flags = 0);
2024-04-16 03:43:29 +00:00
2024-04-16 18:56:40 +00:00
virtual tUIClass Class() const { // Overide this function to name the class
return uiButton;
};
2024-04-16 03:43:29 +00:00
2024-04-16 18:56:40 +00:00
// settings
void SetStateItem(int state, UIItem *item); // sets the background bitmap for a specified button state
void SetAllStates(UIItem *item); // Sets text for all states
void SetColor(int state, ddgr_color col);
void Disable(); // this adds to the gadget equivalent
void Enable(); // this adds to the gadget equivalent
2024-04-16 03:43:29 +00:00
2024-04-16 18:56:40 +00:00
// inheritable operations
2024-04-16 03:43:29 +00:00
protected:
2024-04-16 18:56:40 +00:00
virtual void OnLostFocus(); // behavior when gadget loses input focus.
virtual void OnGainFocus(); // behavior when gadget gains input focus.
virtual void OnDraw(); // behavior when gadget is being drawn.
virtual void OnFormat(); // override: called when resized or before drawing.
2024-04-16 03:43:29 +00:00
2024-04-16 18:56:40 +00:00
// called by Process.
2024-04-16 03:43:29 +00:00
protected:
2024-04-16 18:56:40 +00:00
virtual void OnKeyDown(int key); // behavior when key is pressed.
virtual void OnKeyUp(int key); // behavior when key is released.
virtual void OnMouseBtnDown(int btn); // behavior when mouse button is pressed.
virtual void OnMouseBtnUp(int btn); // behavior when mouse button is released.
virtual void OnDestroy(); // override: behavior when gadget is destroyed.
// typically this function is called by a child class when we want
// to tell the caller that this gadget was selected for something.
// virtual void OnSelect(); // override: behavior when gadget is
2024-04-16 20:46:12 +00:00
// selected.
2024-04-16 03:43:29 +00:00
};
// check boxes use most of the behavior of default buttons.
// the only difference is how states are set when an item is selected.
2024-04-16 18:56:40 +00:00
class UICheckBox : virtual public UIButton {
2024-04-16 03:43:29 +00:00
public:
2024-04-16 18:56:40 +00:00
UICheckBox();
2024-04-16 03:43:29 +00:00
2024-04-16 18:56:40 +00:00
void Create(UIWindow *parent, int id, UIItem *title, int x, int y, int w, int h, int flags);
2024-04-16 03:43:29 +00:00
2024-04-16 18:56:40 +00:00
void SetCheck(bool state); // turns on button (of off)
bool IsChecked() const // returns true if button is set.
{
return (m_State == UI_BTS_ACTIVATED) ? true : false;
};
2024-04-16 03:43:29 +00:00
protected:
2024-04-16 18:56:40 +00:00
virtual void OnDraw(); // behavior when gadget is being drawn.
virtual void OnFormat(); // override: called when resized or before drawing.
virtual void OnLostFocus(); // behavior when gadget loses input focus.
virtual void OnGainFocus(); // behavior when gadget gains input focus.
virtual void OnKeyDown(int key); // behavior when key is pressed.
virtual void OnKeyUp(int key); // behavior when key is released.
virtual void OnMouseBtnDown(int btn); // behavior when mouse button is pressed.
virtual void OnMouseBtnUp(int btn); // behavior when mouse button is released.
2024-04-16 03:43:29 +00:00
};
// radio buttons use most of the behavior of default buttons.
// the only difference is how states are set when an item is selected.
2024-04-16 18:56:40 +00:00
class UIRadioButton : virtual public UIButton {
UIRadioButton *m_PrevRB; // previous radio button in group.
UIRadioButton *m_NextRB; // next radio button in group.
2024-04-16 03:43:29 +00:00
2024-04-16 18:56:40 +00:00
void ActivateButton(); // activates this button, deactivating all others.
2024-04-16 03:43:29 +00:00
public:
2024-04-16 18:56:40 +00:00
UIRadioButton();
2024-04-16 03:43:29 +00:00
2024-04-16 18:56:40 +00:00
// flags. the group flags are set internally by Create. if prev_rb is NULL, that's the start.
void Create(UIWindow *parent, UIRadioButton *prev_rb, int id, UIItem *title, int x, int y, int w, int h, int flags);
2024-04-16 03:43:29 +00:00
2024-04-16 18:56:40 +00:00
void Activate(); // turns on button, turns off others in group.
bool IsActivated() const // returns true if button is set.
{
return (m_State == UI_BTS_ACTIVATED) ? true : false;
};
2024-04-16 03:43:29 +00:00
protected:
2024-04-16 18:56:40 +00:00
virtual void OnDraw(); // behavior when gadget is being drawn.
virtual void OnFormat(); // override: called when resized or before drawing.
virtual void OnLostFocus(); // behavior when gadget loses input focus.
virtual void OnGainFocus(); // behavior when gadget gains input focus.
virtual void OnKeyDown(int key); // behavior when key is pressed.
virtual void OnKeyUp(int key); // behavior when key is released.
virtual void OnMouseBtnDown(int btn); // behavior when mouse button is pressed.
virtual void OnMouseBtnUp(int btn); // behavior when mouse button is released.
2024-04-16 03:43:29 +00:00
};
// ----------------------------------------------------------------------------
// UIStatic
// Just a static image/text/etc.
2024-04-16 18:56:40 +00:00
class UIStatic : public UIGadget {
2024-04-16 03:43:29 +00:00
protected:
2024-04-16 18:56:40 +00:00
UIPrimativeItem *m_Background;
UIItem *m_Title;
2024-04-16 03:43:29 +00:00
public:
2024-04-16 18:56:40 +00:00
UIStatic();
virtual ~UIStatic();
void Create(UIWindow *parent, UIItem *item, int x, int y, int w, int h, int flags = 0);
void SetBackground(UIPrimativeItem *prim);
void SetTitle(UIItem *item);
UIItem *GetItem() const { return m_Title; };
2024-04-16 03:43:29 +00:00
protected:
2024-04-16 18:56:40 +00:00
virtual void OnDraw(); // behavior when gadget is being drawn.
virtual void OnFormat(); // override: called when resized or before drawing.
virtual void OnDestroy(); // called when gadget is being nuked.
2024-04-16 03:43:29 +00:00
};
// ----------------------------------------------------------------------------
// UIText
// This is a simple text.
2024-04-16 18:56:40 +00:00
class UIText : public UIStatic {
2024-04-16 03:43:29 +00:00
public:
2024-04-16 18:56:40 +00:00
void Create(UIWindow *parent, UITextItem *text, int x, int y, int flags = 0);
2024-04-16 03:43:29 +00:00
2024-04-16 18:56:40 +00:00
// inheritable operations
2024-04-16 03:43:29 +00:00
protected:
2024-04-16 18:56:40 +00:00
virtual void OnFormat(); // override: called when resized or before drawing.
2024-04-16 03:43:29 +00:00
};
// ----------------------------------------------------------------------------
// UIProgress
// Progress Bar
2024-04-16 18:56:40 +00:00
class UIProgress : public UIStatic {
2024-04-16 03:43:29 +00:00
public:
2024-04-16 18:56:40 +00:00
void Create(UIWindow *parent, int x, int y, int w, int h, int flags = 0);
void Update(float progress); // Call with a value from 0-1.0 to specify progress
2024-04-16 03:43:29 +00:00
2024-04-16 18:56:40 +00:00
// inheritable operations
2024-04-16 03:43:29 +00:00
protected:
2024-04-16 18:56:40 +00:00
float m_Progress;
int m_ProgressWidth;
virtual void OnDraw(); // behavior when gadget is being drawn.
virtual void OnFormat(); // override: called when resized or before drawing.
2024-04-16 03:43:29 +00:00
};
// ----------------------------------------------------------------------------
// UIGroup
// Draws a group box on to the window
2024-04-16 18:56:40 +00:00
class UIGroup : public UIStatic {
2024-04-16 03:43:29 +00:00
public:
2024-04-16 18:56:40 +00:00
UIGroup();
~UIGroup();
void Create(UIWindow *parent, char *label, int x, int y, int w, int h, ddgr_color label_color = GR_WHITE,
ddgr_color box_color = GR_WHITE, int flags = 0);
2024-04-16 03:43:29 +00:00
2024-04-16 18:56:40 +00:00
// inheritable operations
2024-04-16 03:43:29 +00:00
protected:
2024-04-16 18:56:40 +00:00
bool m_bTextCreated;
UIText m_tLabel;
char *m_Label;
ddgr_color m_LabelColor;
ddgr_color m_BoxColor;
virtual void OnDraw();
virtual void OnDestroy();
2024-04-16 03:43:29 +00:00
};
// ----------------------------------------------------------------------------
2024-04-16 18:56:40 +00:00
// UIEdit
2024-04-16 03:43:29 +00:00
// A single line edit control.
2024-04-16 18:56:40 +00:00
#define KEYDOWN_FIRST_DELAY 0.5f
#define KEYDOWN_REPEAT_DELAY 0.10f
class UIEdit : public UIGadget {
char *m_TextBuf; // Text buffer for edit control.
int m_FontHandle; // font for edit control. (default -1 = window's font)
int m_BufSize; // buffersize
int m_Color; // color of text.
int m_CursorPosX; // text cursor position within box.
bool m_Active; // active?
int m_CurPos; // cursor postion in buffer.
int m_StartPos; // active start position in buffer of what's drawn.
int m_X1b, m_X2b, m_Yb; // x boundaries of text.
int m_ScrollThresh; // scrolling x threshold.
bool m_UpdateCount; // used to update scroll position on next draw frame.
// called from outside gadget hierarchy.
2024-04-16 03:43:29 +00:00
protected:
2024-04-16 18:56:40 +00:00
void DrawText(); // draws text in box
void Deactivate(); // deactivates edit box (use if you know what you're doing.)
void SetTextBounds(int x1, int x2, int yoff); // horizontal clipping of text within editbox
2024-04-16 03:43:29 +00:00
2024-04-16 18:56:40 +00:00
// called from outside gadget hierarchy.
2024-04-16 03:43:29 +00:00
protected:
2024-04-16 18:56:40 +00:00
virtual void OnLostFocus(); // override: behavior when gadget loses input focus.
virtual void OnGainFocus(); // override: behavior when gadget gains input focus.
virtual void OnDraw(); // behavior when gadget is being drawn.
2024-04-16 03:43:29 +00:00
2024-04-16 18:56:40 +00:00
// called by Process.
2024-04-16 03:43:29 +00:00
protected:
2024-04-16 18:56:40 +00:00
virtual void OnKeyDown(int key); // behavior when key is pressed.
virtual void OnKeyUp(int key); // behavior when key is released.
virtual void OnMouseBtnDown(int btn); // behavior when mouse button is pressed.
virtual void OnMouseBtnUp(int btn); // behavior when mouse button is released.
virtual void OnSelect();
virtual void OnDestroy(); // override: behavior when gadget is destroyed.
2024-04-16 03:43:29 +00:00
public:
2024-04-16 18:56:40 +00:00
UIEdit();
virtual ~UIEdit();
void Create(UIWindow *parent, int id, int x, int y, int w, int h, int flags = 0);
// settings
void SetBufferLen(int length); // sets the length of the input buffer.
void SetText(const char *text); // sets the text buffer.
2024-04-16 18:56:40 +00:00
void GetText(char *buffer, int len); // retrieve text in edit control.
void SetFont(int font); // sets font of control (default is window's font.)
void SetColor(ddgr_color col); // sets color of text.
void Activate(); // activates edit box manually (allows editing.)
virtual tUIClass Class() const { // Overide this function to name the class
return uiEdit;
};
2024-04-16 03:43:29 +00:00
};
// ----------------------------------------------------------------------------
// UISlider
// A simple slider
2024-04-16 18:56:40 +00:00
class UISlider : public UIGadget {
void (*selectchange_fn)(int); // callback when selection changes in slider
void (*selectchange_id_fn)(int, void *); // callback when selection changes in slider, also returns the ID
void *m_callbackptr; // user defined callback pointer
int m_Pos; // this is the returned value as shown in the range.
int m_Range; // returned value of slider is 0 to m_Range-1.
int m_PixelWidth; // used to get the current position of slider.
float m_IntervalWidth; // width of one tick o
int switch_x, switch_y; // little box width and height.
int switch_w, switch_h;
2024-04-16 03:43:29 +00:00
2024-04-16 18:56:40 +00:00
UIItem *switch_item; // slider switch item
UIItem *slider_item; // slider item
2024-04-16 03:43:29 +00:00
2024-04-16 18:56:40 +00:00
public:
UISlider();
virtual ~UISlider();
void Create(UIWindow *parent, int id, int x, int y, int w, int h, int flags = 0);
// sets visual characteristics of slider.
void SetSliderSwitchItem(UIItem *item);
void SetSliderItem(UIItem *item);
virtual tUIClass Class() const { // Overide this function to name the class
return uiSlider;
};
// settings
void SetRange(int range); // sets range of scroll bar
int GetRange() const { // range of scroll bar
return m_Range;
};
void SetPos(int pos) { // sets the position of the slider.
if (pos < 0)
pos = 0;
else if (pos >= m_Range)
pos = m_Range - 1;
m_Pos = pos;
};
int GetPos() const { // gets position of slider.
return m_Pos;
};
void SetSelectChangeCallback(void (*fn)(int));
void SetSelectChangeCallback(void (*fn)(int, void *), void *ptr);
// called from outside gadget hierarchy.
2024-04-16 03:43:29 +00:00
protected:
2024-04-16 18:56:40 +00:00
virtual void OnFormat(); // override: called when resized or before drawing.
virtual void OnLostFocus(){}; // override: behavior when gadget loses input focus.
virtual void OnGainFocus(){}; // override: behavior when gadget gains input focus.
virtual void OnDraw(); // behavior when gadget is being drawn.
virtual void OnDestroy(); // behavior when gadget is being destroyed.
virtual void OnKeyDown(int key); // behavior when key is pressed.
virtual void OnKeyUp(int key); // behavior when key is released.
virtual void OnMouseBtnDown(int btn); // behavior when mouse button is pressed.
virtual void OnMouseBtnUp(int btn); // behavior when mouse button is released.
virtual void OnSelect(); // override
2024-04-16 03:43:29 +00:00
};
// ----------------------------------------------------------------------------
// UIListBox
2024-04-16 18:56:40 +00:00
// A listbox may contain text items
2024-04-16 03:43:29 +00:00
// Allows the user to scroll through them too.
#define LISTBOX_BUFFER_SIZE 20
2024-04-16 18:56:40 +00:00
class UIListBox : public UIGadget {
void (*selectchange_fn)(int); // callback when selection changes in listbox.
void (*selectchange_id_fn)(int, void *); // callback when selection changes in listbox..also return the ID
void *m_callbackptr; // user defined callback pointer
ddgr_color m_SelectColor; // selected text color
ddgr_color m_HiliteColor; // color of hilite bar
int m_LastMseX, m_LastMseY; // used for double clicking.
2024-05-24 03:07:26 +00:00
uint8_t m_Alpha; // alpha value of listbox.
2024-04-16 03:43:29 +00:00
2024-04-16 18:56:40 +00:00
bool MseCheckSelect(int x, int y); // check if x and y selection hits a selected item.
void SetInternalSelectedIndex(int index); // call by listbox system.
2024-04-16 03:43:29 +00:00
protected:
2024-04-16 18:56:40 +00:00
int m_TextOffX, m_TextOffY; // offset of text to border.
int m_ArrowWidth; // with of arrow.
int m_CX, m_CY, m_CX2, m_CY2; // clipping text.
2024-04-16 03:43:29 +00:00
public:
2024-04-16 18:56:40 +00:00
UIListBox();
virtual ~UIListBox();
2024-04-16 03:43:29 +00:00
2024-04-16 18:56:40 +00:00
void Create(UIWindow *parent, int id, int x, int y, int w, int h, int flags = 0);
2024-04-16 03:43:29 +00:00
2024-04-16 18:56:40 +00:00
virtual tUIClass Class() const { // Overide this function to name the class
return uiListBox;
};
2024-04-16 03:43:29 +00:00
2024-04-16 18:56:40 +00:00
// settings
void AddItem(const UIItem *item); // adds an item to the list, no sorting
void RemoveItem(const UIItem *item); // removes an item from the list.
void RemoveAll(); // empties listbox
void SelectItem(const UIItem *item); // selects the given item in the list.
UIItem *GetItem(int index) const; // returns the item at listbox index given.
2024-04-16 03:43:29 +00:00
2024-04-16 18:56:40 +00:00
int GetListIndex() const; // returns the current listbox index
void SetListIndex(int index); // sets the index of a listbox
2024-04-16 03:43:29 +00:00
2024-04-16 18:56:40 +00:00
int GetSelectedIndex() const; // returns which item index is selected
void SetSelectedIndex(int index); // selects an item based on index and moves listbox
void SetSelectedColor(ddgr_color col); // selected text color.
void SetHiliteColor(ddgr_color col); // sets the hilite bar color
2024-04-16 03:43:29 +00:00
2024-04-16 18:56:40 +00:00
void SetSelectChangeCallback(void (*fn)(int));
void SetSelectChangeCallback(void (*fn)(int, void *), void *ptr);
2024-04-16 03:43:29 +00:00
2024-04-16 18:56:40 +00:00
// called from outside gadget hierarchy.
2024-04-16 03:43:29 +00:00
protected:
2024-04-16 18:56:40 +00:00
virtual void OnLostFocus(); // override: behavior when gadget loses input focus.
virtual void OnGainFocus(); // override: behavior when gadget gains input focus.
virtual void OnDraw(); // behavior when gadget is being drawn.
virtual void OnKeyDown(int key); // behavior when key is pressed.
virtual void OnKeyUp(int key); // behavior when key is released.
virtual void OnMouseBtnDown(int btn); // behavior when mouse button is pressed.
virtual void OnMouseBtnUp(int btn); // behavior when mouse button is released.
virtual void OnSelect();
virtual void OnDestroy(); // called when destroyed.
virtual void OnUserProcess(); // override: behavior when gadget is processed
2024-04-16 03:43:29 +00:00
private:
2024-04-16 18:56:40 +00:00
UIItem **m_ItemList; // list of items in listbox
int *m_Virt2Real; // translates virtual(user) id to real index
int *m_Real2Virt; // translates real index into virtual(user) id
float m_ClickTime; // done to check for double clicks?
int m_MouseState; // done for mouse selection.
int m_MouseX, m_MouseY;
int m_NumItems; // number of items in list.
int m_SelectedIndex; // current selected index into listbox
int m_Index; // current index of visible items.
bool m_ShowDown, m_ShowUp; // whether the down and up arrows are displayed
int m_UpArrowY0, m_DownArrowY0; // up and down arrow y locations.
int m_UpArrowY1, m_DownArrowY1; // up and down arrow y max locations.
int m_NumVisibleItems; // number of visible items in list viewport.
2024-04-16 03:43:29 +00:00
public:
2024-04-16 18:56:40 +00:00
int GetNumItems() const { return m_NumItems; };
2024-04-16 03:43:29 +00:00
};
// ----------------------------------------------------------------------------
// UIComboBox
// A listbox may contain text items, BUT only one will be visible
// Allows the user to scroll through them too.
2024-04-16 18:56:40 +00:00
class UIComboBox : public UIGadget {
2024-04-16 03:43:29 +00:00
public:
2024-04-16 18:56:40 +00:00
UIComboBox();
virtual ~UIComboBox();
2024-04-16 03:43:29 +00:00
2024-04-16 18:56:40 +00:00
void Create(UIWindow *parent, int id, int x, int y, int w, int h, int flags = 0);
2024-04-16 03:43:29 +00:00
private:
2024-04-16 18:56:40 +00:00
UIItem **m_ItemList; // list of items in listbox
int m_nItems; // number of items.
int m_ArrY, m_ArrH; // up and down arrow dimensions
int m_UpArrX, m_UpArrW, m_DownArrX, m_DownArrW;
int m_Index; // current index.
void (*selectchange_fn)(int); // callback when selection changes in listbox.
bool m_ShowUp, m_ShowDown;
float m_scrolltimer; // scroll timer for delay in mouse.
int m_scrollstage; // determines how scrolling will work.
2024-04-16 03:43:29 +00:00
public:
2024-04-16 18:56:40 +00:00
void AddItem(const UIItem *item);
void RemoveItem(const UIItem *item); // removes an item from the list.
void RemoveAll(); // empties listbox
void SelectItem(const UIItem *item); // selects the given item in the list.
UIItem *GetItem(int index) const; // returns the item at listbox index given.
2024-04-16 03:43:29 +00:00
2024-04-16 18:56:40 +00:00
int GetSelectedIndex() const { // returns which item index is selected
return m_Index;
};
void SetSelectedIndex(int index); // sets the selected index.
2024-04-16 03:43:29 +00:00
2024-04-16 18:56:40 +00:00
void SetSelectChangeCallback(void (*fn)(int));
2024-04-16 03:43:29 +00:00
protected:
2024-04-16 18:56:40 +00:00
virtual void OnDraw(); // behavior when gadget is being drawn.
virtual void OnKeyDown(int key); // behavior when key is pressed.
virtual void OnMouseBtnDown(int btn); // behavior when mouse button is pressed.
virtual void OnMouseBtnUp(int btn); // behavior when mouse button is released
virtual void OnSelect();
virtual void OnDestroy(); // called when destroyed.
2024-04-16 03:43:29 +00:00
protected:
2024-04-16 18:56:40 +00:00
int m_CX, m_CY, m_CX2, m_CY2; // text clippers.
2024-04-16 03:43:29 +00:00
};
// ----------------------------------------------------------------------------
// UIConsoleGadget
// a console that's a gadget within a window
2024-04-16 18:56:40 +00:00
class UIConsoleGadget : public UIGadget {
int m_ConsoleFont; // standard font for text in console
ddgr_color *m_ColorRows; // color per row.
char *m_ConsoleBuffer; // text buffer of console.
int m_Rows, m_Cols; // dimensions in text.
int m_VisRows; // visible rows and columns
int m_VisRowStart; // scroll start of visible region of buffer.
int m_CurRow, m_CurCol; // current row and column of text pointer
int m_OffX, m_OffY;
int m_Rowsize; // rowsize of character buffer.
ddgr_color m_LineColor; // color of current line.
int m_LineIndex; // index within current row memory-wise(not column wise).
int m_PutsBufLen; // current length of puts buffer
char *m_PutsBuffer; // puts buffer.
2024-04-16 03:43:29 +00:00
private:
2024-04-16 18:56:40 +00:00
void PutChar(int ch); // outputs a character onto the console.
void Scroll(); // scrolls window.
2024-04-16 03:43:29 +00:00
protected:
2024-04-16 18:56:40 +00:00
virtual void OnDraw(); // behavior when gadget is being drawn.
virtual void OnUserProcess(); // behavior when gadget is processed
virtual void OnDestroy(); // behavior when gadget is destroyed.
2024-04-16 03:43:29 +00:00
public:
2024-04-16 18:56:40 +00:00
UIConsoleGadget();
virtual ~UIConsoleGadget();
2024-04-16 03:43:29 +00:00
2024-04-16 18:56:40 +00:00
// font = console font, NOT GADGET FONT. This font is used to proportion window
void Create(UIWindow *parent, int id, int x, int y, int font, int cols, int rows, int flags = UIF_BORDER);
2024-04-16 03:43:29 +00:00
2024-04-16 18:56:40 +00:00
// functions
void puts(ddgr_color color, const char *str);
2024-04-16 03:43:29 +00:00
};
// ----------------------------------------------------------------------------
// UIWindow
2024-04-16 18:56:40 +00:00
// A window contains different UIGadgets.
2024-04-16 03:43:29 +00:00
// This is where all objects will interact with the user.
2024-04-16 18:56:40 +00:00
#define N_WINDOW_ACCELS 48
class UIWindow : public UIObject {
friend class UIGadget;
UIGadget *m_GadgetHead; // gadget list for window
UIGadget *m_GadgetTail;
UIGadget *m_GadgetCur;
UIGadget *m_LockedGadget; // marks a particular gadget that will always have focus
UIItem *m_BackItem; // background UI item.
float m_KeyTime; // time when key went down.
ddgr_color m_BackColor; // unconditional background color
int m_FontHandle;
int m_LastKey; // the last key pressed.
int m_LastKeyCount; // number of times last key was pressed.
float m_LastKeyTime; // last key time.
bool m_HoldHotkeys;
bool m_ResetCurGadget; // next process will reset current gadget to 1st valid one.
bool m_CurGadgetInGroup; // is m_GadgetCur inside a group?
struct {
int key;
int id;
} m_Accelerators[N_WINDOW_ACCELS]; // used for quick key press interaction
int m_naccels;
static int m_WindowFont; // global window default font
2024-04-16 03:43:29 +00:00
private:
2024-04-16 18:56:40 +00:00
bool TrapKey(int key);
void UntrapKey(int key);
void LockFocusOnGadget(UIGadget *gadget); // forces a particular gadget into focus, always until unlocked.
void UnlockFocusOnGadget();
2024-04-16 03:43:29 +00:00
protected:
2024-04-16 18:56:40 +00:00
ddgr_color GetBackColor() const { return m_BackColor; };
2024-04-16 03:43:29 +00:00
2024-04-16 18:56:40 +00:00
int m_Flags; // window flags.
2024-04-16 03:43:29 +00:00
2024-04-16 18:56:40 +00:00
// inheritable actions
2024-04-16 03:43:29 +00:00
protected:
2024-04-16 18:56:40 +00:00
virtual void OnDraw(); // overridable draws the window background before gadgets
virtual void OnUserProcess(); // overridable: runs after window is processed, to supplement it.
virtual void OnDestroy(){}; // overridable: called in Destroy
virtual void OnKeyDown(int key); // behavior when key is pressed.
virtual void OnKeyUp(int key); // behavior when key is released.
2024-04-16 03:43:29 +00:00
public:
2024-04-16 18:56:40 +00:00
static void SetDefaultFont(int font) { // sets the default font for any window
UIWindow::m_WindowFont = font;
};
2024-04-16 03:43:29 +00:00
public:
2024-04-16 18:56:40 +00:00
UIWindow();
virtual ~UIWindow();
void Destroy(); // must call if you created window. will be called in destructor
void Create(int x, int y, int w, int h, int flags = 0);
int GetFlags() const { return m_Flags; };
// used to mark key pressed to id numbers
void AddAcceleratorKey(int key, int id);
void ResetAcceleratorKey();
// gadget management
void AddGadget(UIGadget *gadget); // adds a gadget to the gadget list
void RemoveGadget(UIGadget *gadget); // removes a gadget from the list.
UIGadget *GetGadgetFromID(int id); // returns the gadget pointer given an id if in window
void SetFocusOnGadget(UIGadget *gadget, bool key = false);
UIGadget *GetFocus() { return m_GadgetCur; };
// input/output management
virtual int Process(); // handles gadget selection/focus and calls gadgets.
void Render(); // renders one window frame.
void Open(); // adds window to ui list.
void Close(); // removes window from ui list.
// settings
void SetFont(int handle); // sets window's font.
void SetBackItem(UIItem *item) { // sets the background drawing item.
if (m_BackItem)
delete m_BackItem;
m_BackItem = NULL;
if (item)
m_BackItem = item->CopyUIItem();
}; //
void SetBackColor(ddgr_color col) { // sets the background color. this is ALWAYS first, then the backitem
m_BackColor = col;
};
void HoldHotkeys() { m_HoldHotkeys = true; }; // no hotkeys will be processed until ResumeHotkeys is called.
void ResumeHotkeys() { m_HoldHotkeys = false; };
// class id
virtual tUIClass Class() const { // Overide this function to name the class
return uiWindow;
};
// OBSOLETE
void LockKeyFocusOnGadget(UIGadget *gadget); // forces all keyinput onto one gadget. (be wary)
2024-04-16 03:43:29 +00:00
};
// Special windows
// titled window (functions as a standard dialog box.), without modality though.
2024-04-16 18:56:40 +00:00
class UITitledWindow : public UIWindow {
UITextItem m_Title; // title of window
int m_CaptionColor; // caption's color.
int m_BorderThickness; // border thickness.
2024-04-16 03:43:29 +00:00
public:
2024-04-16 18:56:40 +00:00
UITitledWindow();
virtual ~UITitledWindow();
void Create(UITextItem &title, int x, int y, int w, int h);
// class id
virtual tUIClass Class() const { // Overide this function to name the class
return uiTitledWindow;
};
// settings
void SetText(UITextItem &text) { // sets the text for a window title.
m_Title = text;
};
void SetCaptionColor(ddgr_color col) { // sets the color of the caption region
m_CaptionColor = col;
};
void SetBorderThickness(int thickness) { // sets the pixel thickness of the border
m_BorderThickness = thickness;
};
int GetBorderThickness() const { return m_BorderThickness; }; // returns border thickness.
// inheritable actions
2024-04-16 03:43:29 +00:00
protected:
2024-04-16 18:56:40 +00:00
virtual void OnDraw(); // overridable draws the window background before gadgets
2024-04-16 03:43:29 +00:00
};
2024-04-16 18:56:40 +00:00
// UIConsole
2024-04-16 03:43:29 +00:00
// should display a simple console window where anyone can dump text into
2024-04-16 18:56:40 +00:00
class UIConsole : public UIWindow {
UIConsoleGadget m_Console;
2024-04-16 03:43:29 +00:00
protected:
2024-04-16 18:56:40 +00:00
virtual void OnDraw();
2024-04-16 03:43:29 +00:00
public:
2024-04-16 18:56:40 +00:00
UIConsole();
virtual ~UIConsole();
2024-04-16 03:43:29 +00:00
2024-04-16 18:56:40 +00:00
// font = console font, NOT GADGET FONT. This font is used to proportion window
void Create(int x, int y, int font, int cols, int rows);
void Destroy();
2024-04-16 03:43:29 +00:00
2024-04-16 18:56:40 +00:00
// functions
void puts(const char *str);
void puts(ddgr_color col, const char *str);
2024-04-16 03:43:29 +00:00
};
// other inline functions
2024-04-16 18:56:40 +00:00
inline bool UIGadget::HasFocus() const { return ((m_Wnd->GetFocus() == this) ? true : false); };
2024-04-16 03:43:29 +00:00
#include "uisys.h"
#include "uidraw.h"
#endif