1 // ============================================================================
2 // Artsoft Retro-Game Library
3 // ----------------------------------------------------------------------------
4 // (c) 1995-2014 by Artsoft Entertainment
7 // https://www.artsoft.org/
8 // ----------------------------------------------------------------------------
10 // ============================================================================
18 #define GADGET_FRAME_DELAY_FIRST 250 // delay after first click
19 #define GADGET_FRAME_DELAY 100 // delay for pressed butten
22 #define GD_TYPE_NORMAL_BUTTON (1 << 0)
23 #define GD_TYPE_TEXT_BUTTON (1 << 1)
24 #define GD_TYPE_CHECK_BUTTON (1 << 2)
25 #define GD_TYPE_CHECK_BUTTON_2 (1 << 3)
26 #define GD_TYPE_RADIO_BUTTON (1 << 4)
27 #define GD_TYPE_DRAWING_AREA (1 << 5)
28 #define GD_TYPE_TEXT_INPUT_ALPHANUMERIC (1 << 6)
29 #define GD_TYPE_TEXT_INPUT_NUMERIC (1 << 7)
30 #define GD_TYPE_TEXT_AREA (1 << 8)
31 #define GD_TYPE_SELECTBOX (1 << 9)
32 #define GD_TYPE_SCROLLBAR_VERTICAL (1 << 10)
33 #define GD_TYPE_SCROLLBAR_HORIZONTAL (1 << 11)
35 #define GD_TYPE_BUTTON (GD_TYPE_NORMAL_BUTTON | \
36 GD_TYPE_TEXT_BUTTON | \
37 GD_TYPE_CHECK_BUTTON | \
38 GD_TYPE_CHECK_BUTTON_2 | \
40 #define GD_TYPE_SCROLLBAR (GD_TYPE_SCROLLBAR_VERTICAL | \
41 GD_TYPE_SCROLLBAR_HORIZONTAL)
42 #define GD_TYPE_TEXT_INPUT (GD_TYPE_TEXT_INPUT_ALPHANUMERIC | \
43 GD_TYPE_TEXT_INPUT_NUMERIC)
46 #define GD_EVENT_PRESSED (1 << 0)
47 #define GD_EVENT_RELEASED (1 << 1)
48 #define GD_EVENT_MOVING (1 << 2)
49 #define GD_EVENT_REPEATED (1 << 3)
50 #define GD_EVENT_OFF_BORDERS (1 << 4)
51 #define GD_EVENT_TEXT_RETURN (1 << 5)
52 #define GD_EVENT_TEXT_LEAVING (1 << 6)
53 #define GD_EVENT_INFO_ENTERING (1 << 7)
54 #define GD_EVENT_INFO_LEAVING (1 << 8)
55 #define GD_EVENT_PIXEL_PRECISE (1 << 9)
57 // gadget button states
58 #define GD_BUTTON_UNPRESSED 0
59 #define GD_BUTTON_PRESSED 1
61 // gadget structure constants
62 #define MAX_GADGET_TEXTSIZE 1024
63 #define MAX_INFO_TEXTSIZE 1024
65 // gadget creation tags
67 #define GDI_IMAGE_ID 1
68 #define GDI_CUSTOM_ID 2
69 #define GDI_CUSTOM_TYPE_ID 3
76 #define GDI_CHECKED 10
77 #define GDI_RADIO_NR 11
78 #define GDI_NUMBER_VALUE 12
79 #define GDI_NUMBER_MIN 13
80 #define GDI_NUMBER_MAX 14
81 #define GDI_TEXT_VALUE 15
82 #define GDI_TEXT_SIZE 16
83 #define GDI_TEXT_FONT 17
84 #define GDI_TEXT_FONT_ACTIVE 18
85 #define GDI_TEXT_FONT_UNSELECTABLE 19
86 #define GDI_SELECTBOX_OPTIONS 20
87 #define GDI_SELECTBOX_INDEX 21
88 #define GDI_SELECTBOX_CHAR_UNSELECTABLE 22
89 #define GDI_DESIGN_UNPRESSED 23
90 #define GDI_DESIGN_PRESSED 24
91 #define GDI_ALT_DESIGN_UNPRESSED 25
92 #define GDI_ALT_DESIGN_PRESSED 26
93 #define GDI_BORDER_SIZE 27
94 #define GDI_BORDER_SIZE_SELECTBUTTON 28
95 #define GDI_DESIGN_WIDTH 29
96 #define GDI_DECORATION_DESIGN 30
97 #define GDI_DECORATION_POSITION 31
98 #define GDI_DECORATION_SIZE 32
99 #define GDI_DECORATION_SHIFTING 33
100 #define GDI_DECORATION_MASKED 34
101 #define GDI_EVENT_MASK 35
103 #define GDI_CALLBACK_INFO 37
104 #define GDI_CALLBACK_ACTION 38
105 #define GDI_AREA_SIZE 39
106 #define GDI_ITEM_SIZE 40
107 #define GDI_SCROLLBAR_ITEMS_MAX 41
108 #define GDI_SCROLLBAR_ITEMS_VISIBLE 42
109 #define GDI_SCROLLBAR_ITEM_POSITION 43
110 #define GDI_WHEEL_AREA_X 44
111 #define GDI_WHEEL_AREA_Y 45
112 #define GDI_WHEEL_AREA_WIDTH 46
113 #define GDI_WHEEL_AREA_HEIGHT 47
114 #define GDI_INFO_TEXT 48
115 #define GDI_ACTIVE 49
116 #define GDI_DIRECT_DRAW 50
117 #define GDI_OVERLAY_TOUCH_BUTTON 51
118 #define GDI_CALLBACK_ACTION_ALWAYS 52
120 // gadget deactivation hack
121 #define GDI_ACTIVE_POS(a) ((a) < 0 ? POS_OFFSCREEN : (a))
124 typedef void (*gadget_function)(void *);
128 int xsize, ysize; // size of gadget border
129 int xsize_selectbutton; // for selectbox gadgets
130 int width; // for selectbox/text input gadgets
135 Bitmap *bitmap; // Bitmap with gadget surface
136 int x, y; // position of rectangle in Bitmap
139 struct GadgetDecoration
141 struct GadgetDesign design; // decoration design structure
142 int x, y; // position of deco on the gadget
143 int width, height; // width and height of decoration
144 int xshift, yshift; // deco shifting when gadget pressed
145 boolean masked; // draw decoration masked over button
150 unsigned int type; // event type
151 int button; // button number for button events
152 int mx, my; // raw gadget position at event time
153 int x, y; // gadget position at event time
154 boolean off_borders; // mouse pointer outside gadget?
155 int item_x, item_y, item_position; // new item position
158 struct GadgetDrawingArea
160 int area_xsize, area_ysize; // size of drawing area (in items)
161 int item_xsize, item_ysize; // size of each item in drawing area
164 struct GadgetTextButton
166 char value[MAX_GADGET_TEXTSIZE + 1]; // text written on the button
167 int size; // maximal size of button text
170 struct GadgetTextInput
172 char value[MAX_GADGET_TEXTSIZE + 1]; // text string in input field
173 char last_value[MAX_GADGET_TEXTSIZE + 1];// last text string in input field
174 int cursor_position; // actual text cursor position
175 int number_value; // integer value, if numeric
176 int number_min; // minimal allowed numeric value
177 int number_max; // maximal allowed numeric value
178 int size; // maximal size of input text
181 struct GadgetTextArea
183 char value[MAX_GADGET_TEXTSIZE + 1]; // text string in input field
184 char last_value[MAX_GADGET_TEXTSIZE + 1];// last text string in input field
185 int cursor_position; // actual text cursor position
186 int cursor_x; // actual x cursor position
187 int cursor_y; // actual y cursor position
188 int cursor_x_preferred; // "preferred" x cursor position
189 int size; // maximal size of input text
190 int xsize, ysize; // size of text area (in chars)
193 struct GadgetSelectbox
195 struct ValueTextInfo *options; // pointer to text/value array
196 int index; // index of actual text string
197 int size; // maximal size of text strings
198 char char_unselectable; // first char of unselectable options
200 // automatically determined values
201 int x, y; // open selectbox position
202 int width, height; // open selectbox size
203 int num_values; // number of text strings
204 Pixel inverse_color; // color for highlighting
207 boolean open; // opening state of selectbox
208 boolean stay_open; // open after button release
209 int current_index; // index of text while selecting
212 struct GadgetScrollbar
214 int items_max; // number of items to access
215 int items_visible; // number of visible items
216 int item_position; // actual item position
217 int size_min; // minimal scrollbar size
218 int size_max; // this is either width or height
219 int size_max_cmp; // needed for minimal scrollbar size
220 int size; // scrollbar size on screen
221 int position; // scrollbar position on screen
222 int position_max; // bottom/right scrollbar position
223 int drag_position; // drag position on scrollbar
224 int correction; // scrollbar position correction
227 struct GadgetWheelArea
229 int x, y; // active area for wheel (start)
230 int width, height; // active area for wheel (size)
235 boolean deactivated; // flag to deactivate gadget
237 int id; // internal gadget identifier
238 int image_id; // internal gadget image identifier
239 int custom_id; // custom gadget identifier
240 int custom_type_id; // custom gadget type identifier
241 char info_text[MAX_INFO_TEXTSIZE + 1];// short popup info text
242 int x, y; // gadget position
243 int orig_x, orig_y; // gadget position (original)
244 int width, height; // gadget size
245 unsigned int type; // type (button, text input, ...)
246 unsigned int state; // state (pressed, released, ...)
247 boolean checked; // check/radio button state
248 int radio_nr; // number of radio button series
249 boolean mapped; // gadget is mapped on the screen
250 boolean active; // gadget is active
251 boolean direct_draw; // directly draw to frontbuffer
252 boolean overlay_touch_button; // gadget is overlay touch button
253 int overlay_touch_button_alpha; // overlay touch button alpha value
254 boolean callback_action_always; // also callback if gadget unchanged
255 int font; // font to use when inactive
256 int font_active; // font to use when active
257 int font_unselectable; // font to use when unselectable
258 struct GadgetBorder border; // gadget border design
259 struct GadgetDesign design[2]; // 0: normal; 1: pressed
260 struct GadgetDesign alt_design[2]; // alternative design
261 struct GadgetDecoration deco; // decoration on top of gadget
262 unsigned int event_mask; // possible events for this gadget
263 struct GadgetEvent event; // actual gadget event
264 gadget_function callback_info; // function for pop-up info text
265 gadget_function callback_action; // function for gadget action
266 struct GadgetDrawingArea drawing; // fields for drawing area gadget
267 struct GadgetTextButton textbutton; // fields for text button gadget
268 struct GadgetTextInput textinput; // fields for text input gadget
269 struct GadgetTextArea textarea; // fields for text area gadget
270 struct GadgetSelectbox selectbox; // fields for selectbox gadget
271 struct GadgetScrollbar scrollbar; // fields for scrollbar gadget
272 struct GadgetWheelArea wheelarea; // fields for scroll wheel area
273 struct GadgetInfo *next; // next list entry
277 void InitGadgetsSoundCallback(void (*activating_function)(void),
278 void (*selecting_function)(void));
280 struct GadgetInfo *CreateGadget(int, ...);
281 void FreeGadget(struct GadgetInfo *);
283 void ModifyGadget(struct GadgetInfo *, int, ...);
284 void RedrawGadget(struct GadgetInfo *);
286 void MapGadget(struct GadgetInfo *);
287 void UnmapGadget(struct GadgetInfo *);
288 void UnmapAllGadgets(void);
289 void RemapAllGadgets(void);
291 void SetGadgetsPosition_OverlayTouchButtons(void);
292 void DrawGadgets_OverlayTouchButtons(void);
293 boolean CheckPosition_OverlayTouchButtons(int, int, int);
295 boolean anyTextInputGadgetActive(void);
296 boolean anyTextAreaGadgetActive(void);
297 boolean anySelectboxGadgetActive(void);
298 boolean anyScrollbarGadgetActive(void);
299 boolean anyTextGadgetActive(void);
301 void ClickOnGadget(struct GadgetInfo *, int);
303 boolean HandleGadgets(int, int, int);
304 boolean HandleGadgetsKeyInput(Key);
306 void DumpGadgetIdentifiers(void);
307 boolean DoGadgetAction(int);