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)
54 /* gadget button states */
55 #define GD_BUTTON_UNPRESSED 0
56 #define GD_BUTTON_PRESSED 1
58 /* gadget structure constants */
59 #define MAX_GADGET_TEXTSIZE 1024
60 #define MAX_INFO_TEXTSIZE 1024
62 /* gadget creation tags */
64 #define GDI_CUSTOM_ID 1
65 #define GDI_CUSTOM_TYPE_ID 2
73 #define GDI_RADIO_NR 10
74 #define GDI_NUMBER_VALUE 11
75 #define GDI_NUMBER_MIN 12
76 #define GDI_NUMBER_MAX 13
77 #define GDI_TEXT_VALUE 14
78 #define GDI_TEXT_SIZE 15
79 #define GDI_TEXT_FONT 16
80 #define GDI_TEXT_FONT_ACTIVE 17
81 #define GDI_TEXT_FONT_UNSELECTABLE 18
82 #define GDI_SELECTBOX_OPTIONS 19
83 #define GDI_SELECTBOX_INDEX 20
84 #define GDI_SELECTBOX_CHAR_UNSELECTABLE 21
85 #define GDI_DESIGN_UNPRESSED 22
86 #define GDI_DESIGN_PRESSED 23
87 #define GDI_ALT_DESIGN_UNPRESSED 24
88 #define GDI_ALT_DESIGN_PRESSED 25
89 #define GDI_BORDER_SIZE 26
90 #define GDI_BORDER_SIZE_SELECTBUTTON 27
91 #define GDI_DESIGN_WIDTH 28
92 #define GDI_DECORATION_DESIGN 29
93 #define GDI_DECORATION_POSITION 30
94 #define GDI_DECORATION_SIZE 31
95 #define GDI_DECORATION_SHIFTING 32
96 #define GDI_DECORATION_MASKED 33
97 #define GDI_EVENT_MASK 34
99 #define GDI_CALLBACK_INFO 36
100 #define GDI_CALLBACK_ACTION 37
101 #define GDI_AREA_SIZE 38
102 #define GDI_ITEM_SIZE 39
103 #define GDI_SCROLLBAR_ITEMS_MAX 40
104 #define GDI_SCROLLBAR_ITEMS_VISIBLE 41
105 #define GDI_SCROLLBAR_ITEM_POSITION 42
106 #define GDI_WHEEL_AREA_X 43
107 #define GDI_WHEEL_AREA_Y 44
108 #define GDI_WHEEL_AREA_WIDTH 45
109 #define GDI_WHEEL_AREA_HEIGHT 46
110 #define GDI_INFO_TEXT 47
111 #define GDI_ACTIVE 48
112 #define GDI_DIRECT_DRAW 49
114 /* gadget deactivation hack */
115 #define GDI_ACTIVE_POS(a) ((a) < 0 ? POS_OFFSCREEN : (a))
118 typedef void (*gadget_function)(void *);
122 int xsize, ysize; /* size of gadget border */
123 int xsize_selectbutton; /* for selectbox gadgets */
124 int width; /* for selectbox/text input gadgets */
129 Bitmap *bitmap; /* Bitmap with gadget surface */
130 int x, y; /* position of rectangle in Bitmap */
133 struct GadgetDecoration
135 struct GadgetDesign design; /* decoration design structure */
136 int x, y; /* position of deco on the gadget */
137 int width, height; /* width and height of decoration */
138 int xshift, yshift; /* deco shifting when gadget pressed */
139 boolean masked; /* draw decoration masked over button */
144 unsigned int type; /* event type */
145 int button; /* button number for button events */
146 int x, y; /* gadget position at event time */
147 boolean off_borders; /* mouse pointer outside gadget? */
148 int item_x, item_y, item_position; /* new item position */
151 struct GadgetDrawingArea
153 int area_xsize, area_ysize; /* size of drawing area (in items) */
154 int item_xsize, item_ysize; /* size of each item in drawing area */
157 struct GadgetTextButton
159 char value[MAX_GADGET_TEXTSIZE + 1]; /* text written on the button */
160 int size; /* maximal size of button text */
163 struct GadgetTextInput
165 char value[MAX_GADGET_TEXTSIZE + 1]; /* text string in input field */
166 char last_value[MAX_GADGET_TEXTSIZE + 1];/* last text string in input field */
167 int cursor_position; /* actual text cursor position */
168 int number_value; /* integer value, if numeric */
169 int number_min; /* minimal allowed numeric value */
170 int number_max; /* maximal allowed numeric value */
171 int size; /* maximal size of input text */
174 struct GadgetTextArea
176 char value[MAX_GADGET_TEXTSIZE + 1]; /* text string in input field */
177 char last_value[MAX_GADGET_TEXTSIZE + 1];/* last text string in input field */
178 int cursor_position; /* actual text cursor position */
179 int cursor_x; /* actual x cursor position */
180 int cursor_y; /* actual y cursor position */
181 int cursor_x_preferred; /* "preferred" x cursor position */
182 int size; /* maximal size of input text */
183 int xsize, ysize; /* size of text area (in chars) */
186 struct GadgetSelectbox
188 struct ValueTextInfo *options; /* pointer to text/value array */
189 int index; /* index of actual text string */
190 int size; /* maximal size of text strings */
191 char char_unselectable; /* first char of unselectable options */
193 /* automatically determined values */
194 int x, y; /* open selectbox position */
195 int width, height; /* open selectbox size */
196 int num_values; /* number of text strings */
197 Pixel inverse_color; /* color for highlighting */
200 boolean open; /* opening state of selectbox */
201 boolean stay_open; /* open after button release */
202 int current_index; /* index of text while selecting */
205 struct GadgetScrollbar
207 int items_max; /* number of items to access */
208 int items_visible; /* number of visible items */
209 int item_position; /* actual item position */
210 int size_min; /* minimal scrollbar size */
211 int size_max; /* this is either width or height */
212 int size_max_cmp; /* needed for minimal scrollbar size */
213 int size; /* scrollbar size on screen */
214 int position; /* scrollbar position on screen */
215 int position_max; /* bottom/right scrollbar position */
216 int drag_position; /* drag position on scrollbar */
217 int correction; /* scrollbar position correction */
220 struct GadgetWheelArea
222 int x, y; /* active area for wheel (start) */
223 int width, height; /* active area for wheel (size) */
228 boolean deactivated; /* flag to deactivate gadget */
230 int id; /* internal gadget identifier */
231 int custom_id; /* custom gadget identifier */
232 int custom_type_id; /* custom gadget type identifier */
233 char info_text[MAX_INFO_TEXTSIZE + 1];/* short popup info text */
234 int x, y; /* gadget position */
235 int width, height; /* gadget size */
236 unsigned int type; /* type (button, text input, ...) */
237 unsigned int state; /* state (pressed, released, ...) */
238 boolean checked; /* check/radio button state */
239 int radio_nr; /* number of radio button series */
240 boolean mapped; /* gadget is mapped on the screen */
241 boolean active; /* gadget is active */
242 boolean direct_draw; /* directly draw to frontbuffer */
243 int font; /* font to use when inactive */
244 int font_active; /* font to use when active */
245 int font_unselectable; /* font to use when unselectable */
246 struct GadgetBorder border; /* gadget border design */
247 struct GadgetDesign design[2]; /* 0: normal; 1: pressed */
248 struct GadgetDesign alt_design[2]; /* alternative design */
249 struct GadgetDecoration deco; /* decoration on top of gadget */
250 unsigned int event_mask; /* possible events for this gadget */
251 struct GadgetEvent event; /* actual gadget event */
252 gadget_function callback_info; /* function for pop-up info text */
253 gadget_function callback_action; /* function for gadget action */
254 struct GadgetDrawingArea drawing; /* fields for drawing area gadget */
255 struct GadgetTextButton textbutton; /* fields for text button gadget */
256 struct GadgetTextInput textinput; /* fields for text input gadget */
257 struct GadgetTextArea textarea; /* fields for text area gadget */
258 struct GadgetSelectbox selectbox; /* fields for selectbox gadget */
259 struct GadgetScrollbar scrollbar; /* fields for scrollbar gadget */
260 struct GadgetWheelArea wheelarea; /* fields for scroll wheel area */
261 struct GadgetInfo *next; /* next list entry */
265 void InitGadgetsSoundCallback(void (*activating_function)(void),
266 void (*selecting_function)(void));
268 struct GadgetInfo *CreateGadget(int, ...);
269 void FreeGadget(struct GadgetInfo *);
271 void ModifyGadget(struct GadgetInfo *, int, ...);
272 void RedrawGadget(struct GadgetInfo *);
274 void MapGadget(struct GadgetInfo *);
275 void UnmapGadget(struct GadgetInfo *);
276 void UnmapAllGadgets();
277 void RemapAllGadgets();
279 boolean anyTextInputGadgetActive();
280 boolean anyTextAreaGadgetActive();
281 boolean anySelectboxGadgetActive();
282 boolean anyScrollbarGadgetActive();
283 boolean anyTextGadgetActive();
285 void ClickOnGadget(struct GadgetInfo *, int);
287 boolean HandleGadgets(int, int, int);
288 boolean HandleGadgetsKeyInput(Key);
290 #endif /* GADGETS_H */