Debian Codegraph @

Descent3/ConfigItem.h

raw symbols SCIP
1 /*
2 * Descent 3
3 * Copyright (C) 2024 Parallax Software
4 *
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, either version 3 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17
18 --- HISTORICAL COMMENTS FOLLOW ---
19
20 * $Logfile: /DescentIII/main/ConfigItem.h $
21 * $Revision: 8 $
22 * $Date: 10/19/98 6:30p $
23 * $Author: Jeff $
24 *
25 * Contains the class info for ConfigItem [config dialog UI objects]
26 *
27 * $Log: /DescentIII/main/ConfigItem.h $
28 *
29 * 8 10/19/98 6:30p Jeff
30 * changes made for detail variables. Put in preset values. Preset
31 * options. Removed terrain_cast from detail. Put new callbacks in
32 * UIListBox and UISlider
33 *
34 * 7 10/16/98 1:42p Jeff
35 * added CIF_USEGROUP and general dialog look
36 *
37 * 6 9/02/98 2:54p Jeff
38 * added defines for text colors to be used throughout the game...fixed up
39 * buddy menu too
40 *
41 * 5 6/05/98 5:59p Jeff
42 * Added a CIT_CHECKBOX style
43 *
44 * 4 5/23/98 6:33p Jeff
45 * Added some flags for the slider, and fixed it up a bit
46 *
47 * 3 5/22/98 5:02p Jeff
48 * Increased functionality
49 *
50 * 2 5/21/98 10:35p Jeff
51 * Initial creation
52 *
53 * $NoKeywords: $
54 */
55
56 #ifndef __CONFIGITEM_H_
57 #define __CONFIGITEM_H_
58
59 #include "newui.h"
60
61 #if defined(POSIX)
62 void CIListBoxCallback(int ID, void *);
63 void CISliderCallback(int ID, void *);
64 #endif
65
66 // config item types
67 #define CIT_HOTSPOTLIST 0x01
68 #define CIT_SLIDER 0x02
69 #define CIT_ONOFFBUTTON 0x03
70 #define CIT_LISTBOX 0x04
71 #define CIT_YESNOBUTTON 0x05
72 #define CIT_RADIOBUTTON 0x06
73 #define CIT_CHECKBOX 0x07
74
75 // config item value types
76 #define CIV_BOOL 0x01
77 #define CIV_INT 0x02
78 #define CIV_FLOAT 0x03
79
80 // config item flags
81 #define CIF_PERCENT 0x01 // tells a slider to display a percent sign
82 #define CIF_NODECIMAL 0x02 // tells a slider not to display a decimal point (float sliders only)
83 #define CIF_USEGROUP 0x04 // places a group box around the configitem (CIT_RADIOBUTTON only)
84
85 #define HOTSPOTLIST_GAP 8 // the horizontal gap between hotspot lists
86 #define LISTBOX_LABELGAP 3 // the vertical gap between label and listbox
87 #define RADIOBUTTON_LABELGAP 3 // the vertical gap between label and radiobutton list
88 #define RADIOBUTTON_GAP 3 // the vertical gap between radiobuttons
89
90 int GetUniqueID(void);
91
92 class ConfigItem {
93 public:
94 ConfigItem();
95 ~ConfigItem();
96
97 // create functions
98 bool Create(NewUIGameWindow *parentwnd, int type, char *label, int x, int y, int w, int h, int initialvalue,
99 int flags, int item_x);
100 bool Create(NewUIGameWindow *parentwnd, int type, char *label, int x, int y, int w, int h, bool initialvalue,
101 int flags, int item_x);
102 bool Create(NewUIGameWindow *parentwnd, int type, char *label, int x, int y, int w, int h, float initialvalue,
103 int flags, int item_x);
104
105 // destroy function
106 void Destroy(void);
107
108 // gets the current value (returns true on success)
109 bool GetCurrentValue(int *currvalue);
110 bool GetCurrentValue(bool *currvalue);
111 bool GetCurrentValue(float *currvalue);
112
113 // sets the current value for the item
114 bool SetCurrentValue(int currvalue, bool call_callback = true);
115 bool SetCurrentValue(bool currvalue, bool call_callback = true);
116 bool SetCurrentValue(float currvalue, bool call_callback = true);
117
118 // gets the initial value (returns true on success)
119 bool GetInitialValue(int *initvalue);
120 bool GetInitialValue(bool *initvalue);
121 bool GetInitialValue(float *initvalue);
122
123 // set range
124 void SetRange(int min, int max, int range);
125 void SetRange(float min, float max, int range);
126
127 // sets a callback for when an item changes
128 void SetCallback(void (*callback)(float));
129 void SetCallback(void (*callback)(int));
130 void SetCallback(void (*callback)(bool));
131
132 // updates the config item (pass in result from DoUI)
133 void Update(int result);
134
135 // adds items to the config item (count is number of items, followed by a list of UITextItems)
136 void Add(int count, ...);
137
138 friend void CIListBoxCallback(int ID, void *);
139 friend void CISliderCallback(int ID, void *);
140
141 private:
142 bool Create(NewUIGameWindow *parentwnd, int type, int flags, int x, int y, int w, int h, char *label, int item_x);
143 void UpdateHotSpotList(int index);
144 void UpdateSlider(int index, bool call_callback = true);
145 void UpdateOnOffButton(int index);
146 void UpdateListBox(int index);
147 void UpdateYesNoButton(int index);
148 void UpdateRadioButton(int index);
149 void UpdateCheckBox(int index);
150
151 bool m_bAlive; // true is the config item has been created not destroyed yet
152 // Initial value of the config item
153 union {
154 bool m_bInitial;
155 int m_iInitial;
156 float m_fInitial;
157 };
158 // current value of the config item
159 union {
160 bool m_bCurrentValue;
161 int m_iCurrentValue;
162 float m_fCurrentValue;
163 };
164 int m_X, m_Y, m_W, m_H; // x,y, width and height for the config item
165 int curr_x, curr_y; // current x and y (relative to m_X and m_Y)
166 int m_iFlags; // flags for config item
167 int m_iType; // how is this config item represented
168 int *m_iID; // unique ID[s] of the config item
169 int m_iNumIDs; // number of IDs
170 int m_iItems; // number of items associated with this config item
171 int m_iValueType; // what kind of value is this config item holding
172 UIText m_tLabel; // Text item for the label
173 UIGroup m_gGroup; // Group box if needed
174 int m_auxX; // contains the original x passed in
175 int m_auxY; // contains the original y passed in
176 UIText m_tLabel2; // Used for Sliders
177 NewUIGameWindow *m_hWnd; // parent window
178 UITextItem **m_tiList; // list of text items for config item
179 int m_tiCount; // number of text items
180 UIHotspot **m_hsList; // list of hotspot items
181 int m_hsCount; // number of hotspot items
182 NewUISlider **m_sList; // list of slider items
183 int m_sCount; // number of sliders
184 UIRadioButton **m_rbList; // list of radio buttons
185 int m_rbCount; // number of radio buttons
186 NewUIButton **m_bList; // list of button items
187 int m_bCount; // number of buttons
188 NewUIListBox **m_lbList; // list of list boxes
189 int m_lbCount; // number of list boxes
190 float m_fMin, m_fMax; // range min/max
191 int m_iRange; // range
192 float m_fUnit; // scale between min->max to fit in range
193 char *m_labeltext; // we need to save the label for group boxes
194 void (*m_fCallback)(float);
195 void (*m_iCallback)(int);
196 void (*m_bCallback)(bool);
197 };
198
199 #endif