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_EVENT_MASK 33
98 #define GDI_CALLBACK_INFO 35
99 #define GDI_CALLBACK_ACTION 36
100 #define GDI_AREA_SIZE 37
101 #define GDI_ITEM_SIZE 38
102 #define GDI_SCROLLBAR_ITEMS_MAX 39
103 #define GDI_SCROLLBAR_ITEMS_VISIBLE 40
104 #define GDI_SCROLLBAR_ITEM_POSITION 41
105 #define GDI_WHEEL_AREA_X 42
106 #define GDI_WHEEL_AREA_Y 43
107 #define GDI_WHEEL_AREA_WIDTH 44
108 #define GDI_WHEEL_AREA_HEIGHT 45
109 #define GDI_INFO_TEXT 46
110 #define GDI_ACTIVE 47
111 #define GDI_DIRECT_DRAW 48
113 /* gadget deactivation hack */
114 #define GDI_ACTIVE_POS(a) ((a) < 0 ? POS_OFFSCREEN : (a))
117 typedef void (*gadget_function)(void *);
121 int xsize, ysize; /* size of gadget border */
122 int xsize_selectbutton; /* for selectbox gadgets */
123 int width; /* for selectbox/text input gadgets */
128 Bitmap *bitmap; /* Bitmap with gadget surface */
129 int x, y; /* position of rectangle in Bitmap */
132 struct GadgetDecoration
134 struct GadgetDesign design; /* decoration design structure */
135 int x, y; /* position of deco on the gadget */
136 int width, height; /* width and height of decoration */
137 int xshift, yshift; /* deco shifting when gadget pressed */
142 unsigned int type; /* event type */
143 int button; /* button number for button events */
144 int x, y; /* gadget position at event time */
145 boolean off_borders; /* mouse pointer outside gadget? */
146 int item_x, item_y, item_position; /* new item position */
149 struct GadgetDrawingArea
151 int area_xsize, area_ysize; /* size of drawing area (in items) */
152 int item_xsize, item_ysize; /* size of each item in drawing area */
155 struct GadgetTextButton
157 char value[MAX_GADGET_TEXTSIZE + 1]; /* text written on the button */
158 int size; /* maximal size of button text */
161 struct GadgetTextInput
163 char value[MAX_GADGET_TEXTSIZE + 1]; /* text string in input field */
164 char last_value[MAX_GADGET_TEXTSIZE + 1];/* last text string in input field */
165 int cursor_position; /* actual text cursor position */
166 int number_value; /* integer value, if numeric */
167 int number_min; /* minimal allowed numeric value */
168 int number_max; /* maximal allowed numeric value */
169 int size; /* maximal size of input text */
172 struct GadgetTextArea
174 char value[MAX_GADGET_TEXTSIZE + 1]; /* text string in input field */
175 char last_value[MAX_GADGET_TEXTSIZE + 1];/* last text string in input field */
176 int cursor_position; /* actual text cursor position */
177 int cursor_x; /* actual x cursor position */
178 int cursor_y; /* actual y cursor position */
179 int cursor_x_preferred; /* "preferred" x cursor position */
180 int size; /* maximal size of input text */
181 int xsize, ysize; /* size of text area (in chars) */
184 struct GadgetSelectbox
186 struct ValueTextInfo *options; /* pointer to text/value array */
187 int index; /* index of actual text string */
188 int size; /* maximal size of text strings */
189 char char_unselectable; /* first char of unselectable options */
191 /* automatically determined values */
192 int x, y; /* open selectbox position */
193 int width, height; /* open selectbox size */
194 int num_values; /* number of text strings */
195 Pixel inverse_color; /* color for highlighting */
198 boolean open; /* opening state of selectbox */
199 boolean stay_open; /* open after button release */
200 int current_index; /* index of text while selecting */
203 struct GadgetScrollbar
205 int items_max; /* number of items to access */
206 int items_visible; /* number of visible items */
207 int item_position; /* actual item position */
208 int size_min; /* minimal scrollbar size */
209 int size_max; /* this is either width or height */
210 int size_max_cmp; /* needed for minimal scrollbar size */
211 int size; /* scrollbar size on screen */
212 int position; /* scrollbar position on screen */
213 int position_max; /* bottom/right scrollbar position */
214 int drag_position; /* drag position on scrollbar */
215 int correction; /* scrollbar position correction */
218 struct GadgetWheelArea
220 int x, y; /* active area for wheel (start) */
221 int width, height; /* active area for wheel (size) */
226 int id; /* internal gadget identifier */
227 int custom_id; /* custom gadget identifier */
228 int custom_type_id; /* custom gadget type identifier */
229 char info_text[MAX_INFO_TEXTSIZE + 1];/* short popup info text */
230 int x, y; /* gadget position */
231 int width, height; /* gadget size */
232 unsigned int type; /* type (button, text input, ...) */
233 unsigned int state; /* state (pressed, released, ...) */
234 boolean checked; /* check/radio button state */
235 int radio_nr; /* number of radio button series */
236 boolean mapped; /* gadget is mapped on the screen */
237 boolean active; /* gadget is active */
238 boolean direct_draw; /* directly draw to frontbuffer */
239 int font; /* font to use when inactive */
240 int font_active; /* font to use when active */
241 int font_unselectable; /* font to use when unselectable */
242 struct GadgetBorder border; /* gadget border design */
243 struct GadgetDesign design[2]; /* 0: normal; 1: pressed */
244 struct GadgetDesign alt_design[2]; /* alternative design */
245 struct GadgetDecoration deco; /* decoration on top of gadget */
246 unsigned int event_mask; /* possible events for this gadget */
247 struct GadgetEvent event; /* actual gadget event */
248 gadget_function callback_info; /* function for pop-up info text */
249 gadget_function callback_action; /* function for gadget action */
250 struct GadgetDrawingArea drawing; /* fields for drawing area gadget */
251 struct GadgetTextButton textbutton; /* fields for text button gadget */
252 struct GadgetTextInput textinput; /* fields for text input gadget */
253 struct GadgetTextArea textarea; /* fields for text area gadget */
254 struct GadgetSelectbox selectbox; /* fields for selectbox gadget */
255 struct GadgetScrollbar scrollbar; /* fields for scrollbar gadget */
256 struct GadgetWheelArea wheelarea; /* fields for scroll wheel area */
257 struct GadgetInfo *next; /* next list entry */
261 void InitGadgetsSoundCallback(void (*activating_function)(void),
262 void (*selecting_function)(void));
264 struct GadgetInfo *CreateGadget(int, ...);
265 void FreeGadget(struct GadgetInfo *);
267 void ModifyGadget(struct GadgetInfo *, int, ...);
268 void RedrawGadget(struct GadgetInfo *);
270 void MapGadget(struct GadgetInfo *);
271 void UnmapGadget(struct GadgetInfo *);
272 void UnmapAllGadgets();
273 void RemapAllGadgets();
275 boolean anyTextInputGadgetActive();
276 boolean anyTextAreaGadgetActive();
277 boolean anySelectboxGadgetActive();
278 boolean anyScrollbarGadgetActive();
279 boolean anyTextGadgetActive();
281 void ClickOnGadget(struct GadgetInfo *, int);
283 boolean HandleGadgets(int, int, int);
284 boolean HandleGadgetsKeyInput(Key);
286 #endif /* GADGETS_H */