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