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)
192 // automatically determined values
193 boolean cropped; // text area cropped to fit viewport
194 int full_x, full_y; // text area position when not cropped
195 int crop_width, crop_height; // size of text area when cropped
196 int crop_xsize, crop_ysize; // size of text area when cropped
199 boolean full_open; // opening state of text area
202 struct GadgetSelectbox
204 struct ValueTextInfo *options; // pointer to text/value array
205 int index; // index of actual text string
206 int size; // maximal size of text strings
207 char char_unselectable; // first char of unselectable options
209 // automatically determined values
210 int x, y; // open selectbox position
211 int width, height; // open selectbox size
212 int num_values; // number of text strings
213 Pixel inverse_color; // color for highlighting
216 boolean open; // opening state of selectbox
217 boolean stay_open; // open after button release
218 int current_index; // index of text while selecting
221 struct GadgetScrollbar
223 int items_max; // number of items to access
224 int items_visible; // number of visible items
225 int item_position; // actual item position
226 int size_min; // minimal scrollbar size
227 int size_max; // this is either width or height
228 int size_max_cmp; // needed for minimal scrollbar size
229 int size; // scrollbar size on screen
230 int position; // scrollbar position on screen
231 int position_max; // bottom/right scrollbar position
232 int drag_position; // drag position on scrollbar
233 int correction; // scrollbar position correction
236 struct GadgetWheelArea
238 int x, y; // active area for wheel (start)
239 int width, height; // active area for wheel (size)
244 boolean deactivated; // flag to deactivate gadget
246 int id; // internal gadget identifier
247 int image_id; // internal gadget image identifier
248 int custom_id; // custom gadget identifier
249 int custom_type_id; // custom gadget type identifier
250 char info_text[MAX_INFO_TEXTSIZE + 1];// short popup info text
251 int x, y; // gadget position
252 int orig_x, orig_y; // gadget position (original)
253 int width, height; // gadget size
254 unsigned int type; // type (button, text input, ...)
255 unsigned int state; // state (pressed, released, ...)
256 boolean checked; // check/radio button state
257 int radio_nr; // number of radio button series
258 boolean mapped; // gadget is mapped on the screen
259 boolean active; // gadget is active
260 boolean direct_draw; // directly draw to frontbuffer
261 boolean overlay_touch_button; // gadget is overlay touch button
262 int overlay_touch_button_alpha; // overlay touch button alpha value
263 boolean callback_action_always; // also callback if gadget unchanged
264 int font; // font to use when inactive
265 int font_active; // font to use when active
266 int font_unselectable; // font to use when unselectable
267 struct GadgetBorder border; // gadget border design
268 struct GadgetDesign design[2]; // 0: normal; 1: pressed
269 struct GadgetDesign alt_design[2]; // alternative design
270 struct GadgetDecoration deco; // decoration on top of gadget
271 unsigned int event_mask; // possible events for this gadget
272 struct GadgetEvent event; // actual gadget event
273 gadget_function callback_info; // function for pop-up info text
274 gadget_function callback_action; // function for gadget action
275 struct GadgetDrawingArea drawing; // fields for drawing area gadget
276 struct GadgetTextButton textbutton; // fields for text button gadget
277 struct GadgetTextInput textinput; // fields for text input gadget
278 struct GadgetTextArea textarea; // fields for text area gadget
279 struct GadgetSelectbox selectbox; // fields for selectbox gadget
280 struct GadgetScrollbar scrollbar; // fields for scrollbar gadget
281 struct GadgetWheelArea wheelarea; // fields for scroll wheel area
282 struct GadgetInfo *next; // next list entry
286 void InitGadgetsSoundCallback(void (*activating_function)(void),
287 void (*selecting_function)(void));
288 void InitGadgetScreenBorders(int, int);
290 struct GadgetInfo *CreateGadget(int, ...);
291 void FreeGadget(struct GadgetInfo *);
293 void ModifyGadget(struct GadgetInfo *, int, ...);
294 void RedrawGadget(struct GadgetInfo *);
296 void MapGadget(struct GadgetInfo *);
297 void UnmapGadget(struct GadgetInfo *);
298 void UnmapAllGadgets(void);
299 void RemapAllGadgets(void);
301 void SetGadgetsPosition_OverlayTouchButtons(void);
302 void DrawGadgets_OverlayTouchButtons(void);
303 boolean CheckPosition_OverlayTouchButtons(int, int, int);
305 boolean anyTextInputGadgetActive(void);
306 boolean anyTextAreaGadgetActive(void);
307 boolean anySelectboxGadgetActive(void);
308 boolean anyScrollbarGadgetActive(void);
309 boolean anyTextGadgetActive(void);
311 void ClickOnGadget(struct GadgetInfo *, int);
313 boolean HandleGadgets(int, int, int);
314 boolean HandleGadgetsKeyInput(Key);
316 void DumpGadgetIdentifiers(void);
317 boolean DoGadgetAction(int);