1 // ============================================================================
2 // Artsoft Retro-Game Library
3 // ----------------------------------------------------------------------------
4 // (c) 1995-2014 by Artsoft Entertainment
7 // http://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_RADIO_BUTTON (1 << 3)
26 #define GD_TYPE_DRAWING_AREA (1 << 4)
27 #define GD_TYPE_TEXT_INPUT_ALPHANUMERIC (1 << 5)
28 #define GD_TYPE_TEXT_INPUT_NUMERIC (1 << 6)
29 #define GD_TYPE_TEXT_AREA (1 << 7)
30 #define GD_TYPE_SELECTBOX (1 << 8)
31 #define GD_TYPE_SCROLLBAR_VERTICAL (1 << 9)
32 #define GD_TYPE_SCROLLBAR_HORIZONTAL (1 << 10)
34 #define GD_TYPE_BUTTON (GD_TYPE_NORMAL_BUTTON | \
35 GD_TYPE_TEXT_BUTTON | \
36 GD_TYPE_CHECK_BUTTON | \
38 #define GD_TYPE_SCROLLBAR (GD_TYPE_SCROLLBAR_VERTICAL | \
39 GD_TYPE_SCROLLBAR_HORIZONTAL)
40 #define GD_TYPE_TEXT_INPUT (GD_TYPE_TEXT_INPUT_ALPHANUMERIC | \
41 GD_TYPE_TEXT_INPUT_NUMERIC)
44 #define GD_EVENT_PRESSED (1 << 0)
45 #define GD_EVENT_RELEASED (1 << 1)
46 #define GD_EVENT_MOVING (1 << 2)
47 #define GD_EVENT_REPEATED (1 << 3)
48 #define GD_EVENT_OFF_BORDERS (1 << 4)
49 #define GD_EVENT_TEXT_RETURN (1 << 5)
50 #define GD_EVENT_TEXT_LEAVING (1 << 6)
51 #define GD_EVENT_INFO_ENTERING (1 << 7)
52 #define GD_EVENT_INFO_LEAVING (1 << 8)
53 #define GD_EVENT_PIXEL_PRECISE (1 << 9)
55 /* gadget button states */
56 #define GD_BUTTON_UNPRESSED 0
57 #define GD_BUTTON_PRESSED 1
59 /* gadget structure constants */
60 #define MAX_GADGET_TEXTSIZE 1024
61 #define MAX_INFO_TEXTSIZE 1024
63 /* gadget creation tags */
65 #define GDI_CUSTOM_ID 1
66 #define GDI_CUSTOM_TYPE_ID 2
74 #define GDI_RADIO_NR 10
75 #define GDI_NUMBER_VALUE 11
76 #define GDI_NUMBER_MIN 12
77 #define GDI_NUMBER_MAX 13
78 #define GDI_TEXT_VALUE 14
79 #define GDI_TEXT_SIZE 15
80 #define GDI_TEXT_FONT 16
81 #define GDI_TEXT_FONT_ACTIVE 17
82 #define GDI_TEXT_FONT_UNSELECTABLE 18
83 #define GDI_SELECTBOX_OPTIONS 19
84 #define GDI_SELECTBOX_INDEX 20
85 #define GDI_SELECTBOX_CHAR_UNSELECTABLE 21
86 #define GDI_DESIGN_UNPRESSED 22
87 #define GDI_DESIGN_PRESSED 23
88 #define GDI_ALT_DESIGN_UNPRESSED 24
89 #define GDI_ALT_DESIGN_PRESSED 25
90 #define GDI_BORDER_SIZE 26
91 #define GDI_BORDER_SIZE_SELECTBUTTON 27
92 #define GDI_DESIGN_WIDTH 28
93 #define GDI_DECORATION_DESIGN 29
94 #define GDI_DECORATION_POSITION 30
95 #define GDI_DECORATION_SIZE 31
96 #define GDI_DECORATION_SHIFTING 32
97 #define GDI_DECORATION_MASKED 33
98 #define GDI_EVENT_MASK 34
100 #define GDI_CALLBACK_INFO 36
101 #define GDI_CALLBACK_ACTION 37
102 #define GDI_AREA_SIZE 38
103 #define GDI_ITEM_SIZE 39
104 #define GDI_SCROLLBAR_ITEMS_MAX 40
105 #define GDI_SCROLLBAR_ITEMS_VISIBLE 41
106 #define GDI_SCROLLBAR_ITEM_POSITION 42
107 #define GDI_WHEEL_AREA_X 43
108 #define GDI_WHEEL_AREA_Y 44
109 #define GDI_WHEEL_AREA_WIDTH 45
110 #define GDI_WHEEL_AREA_HEIGHT 46
111 #define GDI_INFO_TEXT 47
112 #define GDI_ACTIVE 48
113 #define GDI_DIRECT_DRAW 49
115 /* gadget deactivation hack */
116 #define GDI_ACTIVE_POS(a) ((a) < 0 ? POS_OFFSCREEN : (a))
119 typedef void (*gadget_function)(void *);
123 int xsize, ysize; /* size of gadget border */
124 int xsize_selectbutton; /* for selectbox gadgets */
125 int width; /* for selectbox/text input gadgets */
130 Bitmap *bitmap; /* Bitmap with gadget surface */
131 int x, y; /* position of rectangle in Bitmap */
134 struct GadgetDecoration
136 struct GadgetDesign design; /* decoration design structure */
137 int x, y; /* position of deco on the gadget */
138 int width, height; /* width and height of decoration */
139 int xshift, yshift; /* deco shifting when gadget pressed */
140 boolean masked; /* draw decoration masked over button */
145 unsigned int type; /* event type */
146 int button; /* button number for button events */
147 int mx, my; /* raw gadget position at event time */
148 int x, y; /* gadget position at event time */
149 boolean off_borders; /* mouse pointer outside gadget? */
150 int item_x, item_y, item_position; /* new item position */
153 struct GadgetDrawingArea
155 int area_xsize, area_ysize; /* size of drawing area (in items) */
156 int item_xsize, item_ysize; /* size of each item in drawing area */
159 struct GadgetTextButton
161 char value[MAX_GADGET_TEXTSIZE + 1]; /* text written on the button */
162 int size; /* maximal size of button text */
165 struct GadgetTextInput
167 char value[MAX_GADGET_TEXTSIZE + 1]; /* text string in input field */
168 char last_value[MAX_GADGET_TEXTSIZE + 1];/* last text string in input field */
169 int cursor_position; /* actual text cursor position */
170 int number_value; /* integer value, if numeric */
171 int number_min; /* minimal allowed numeric value */
172 int number_max; /* maximal allowed numeric value */
173 int size; /* maximal size of input text */
176 struct GadgetTextArea
178 char value[MAX_GADGET_TEXTSIZE + 1]; /* text string in input field */
179 char last_value[MAX_GADGET_TEXTSIZE + 1];/* last text string in input field */
180 int cursor_position; /* actual text cursor position */
181 int cursor_x; /* actual x cursor position */
182 int cursor_y; /* actual y cursor position */
183 int cursor_x_preferred; /* "preferred" x cursor position */
184 int size; /* maximal size of input text */
185 int xsize, ysize; /* size of text area (in chars) */
188 struct GadgetSelectbox
190 struct ValueTextInfo *options; /* pointer to text/value array */
191 int index; /* index of actual text string */
192 int size; /* maximal size of text strings */
193 char char_unselectable; /* first char of unselectable options */
195 /* automatically determined values */
196 int x, y; /* open selectbox position */
197 int width, height; /* open selectbox size */
198 int num_values; /* number of text strings */
199 Pixel inverse_color; /* color for highlighting */
202 boolean open; /* opening state of selectbox */
203 boolean stay_open; /* open after button release */
204 int current_index; /* index of text while selecting */
207 struct GadgetScrollbar
209 int items_max; /* number of items to access */
210 int items_visible; /* number of visible items */
211 int item_position; /* actual item position */
212 int size_min; /* minimal scrollbar size */
213 int size_max; /* this is either width or height */
214 int size_max_cmp; /* needed for minimal scrollbar size */
215 int size; /* scrollbar size on screen */
216 int position; /* scrollbar position on screen */
217 int position_max; /* bottom/right scrollbar position */
218 int drag_position; /* drag position on scrollbar */
219 int correction; /* scrollbar position correction */
222 struct GadgetWheelArea
224 int x, y; /* active area for wheel (start) */
225 int width, height; /* active area for wheel (size) */
230 boolean deactivated; /* flag to deactivate gadget */
232 int id; /* internal gadget identifier */
233 int custom_id; /* custom gadget identifier */
234 int custom_type_id; /* custom gadget type identifier */
235 char info_text[MAX_INFO_TEXTSIZE + 1];/* short popup info text */
236 int x, y; /* gadget position */
237 int width, height; /* gadget size */
238 unsigned int type; /* type (button, text input, ...) */
239 unsigned int state; /* state (pressed, released, ...) */
240 boolean checked; /* check/radio button state */
241 int radio_nr; /* number of radio button series */
242 boolean mapped; /* gadget is mapped on the screen */
243 boolean active; /* gadget is active */
244 boolean direct_draw; /* directly draw to frontbuffer */
245 int font; /* font to use when inactive */
246 int font_active; /* font to use when active */
247 int font_unselectable; /* font to use when unselectable */
248 struct GadgetBorder border; /* gadget border design */
249 struct GadgetDesign design[2]; /* 0: normal; 1: pressed */
250 struct GadgetDesign alt_design[2]; /* alternative design */
251 struct GadgetDecoration deco; /* decoration on top of gadget */
252 unsigned int event_mask; /* possible events for this gadget */
253 struct GadgetEvent event; /* actual gadget event */
254 gadget_function callback_info; /* function for pop-up info text */
255 gadget_function callback_action; /* function for gadget action */
256 struct GadgetDrawingArea drawing; /* fields for drawing area gadget */
257 struct GadgetTextButton textbutton; /* fields for text button gadget */
258 struct GadgetTextInput textinput; /* fields for text input gadget */
259 struct GadgetTextArea textarea; /* fields for text area gadget */
260 struct GadgetSelectbox selectbox; /* fields for selectbox gadget */
261 struct GadgetScrollbar scrollbar; /* fields for scrollbar gadget */
262 struct GadgetWheelArea wheelarea; /* fields for scroll wheel area */
263 struct GadgetInfo *next; /* next list entry */
267 void InitGadgetsSoundCallback(void (*activating_function)(void),
268 void (*selecting_function)(void));
270 struct GadgetInfo *CreateGadget(int, ...);
271 void FreeGadget(struct GadgetInfo *);
273 void ModifyGadget(struct GadgetInfo *, int, ...);
274 void RedrawGadget(struct GadgetInfo *);
276 void MapGadget(struct GadgetInfo *);
277 void UnmapGadget(struct GadgetInfo *);
278 void UnmapAllGadgets();
279 void RemapAllGadgets();
281 boolean anyTextInputGadgetActive();
282 boolean anyTextAreaGadgetActive();
283 boolean anySelectboxGadgetActive();
284 boolean anyScrollbarGadgetActive();
285 boolean anyTextGadgetActive();
287 void ClickOnGadget(struct GadgetInfo *, int);
289 boolean HandleGadgets(int, int, int);
290 boolean HandleGadgetsKeyInput(Key);
292 #endif /* GADGETS_H */