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_SELECTBOX_OPTIONS 18
82 #define GDI_SELECTBOX_INDEX 19
83 #define GDI_DESIGN_UNPRESSED 20
84 #define GDI_DESIGN_PRESSED 21
85 #define GDI_ALT_DESIGN_UNPRESSED 22
86 #define GDI_ALT_DESIGN_PRESSED 23
87 #define GDI_BORDER_SIZE 24
88 #define GDI_BORDER_SIZE_SELECTBUTTON 25
89 #define GDI_DESIGN_WIDTH 26
90 #define GDI_DECORATION_DESIGN 27
91 #define GDI_DECORATION_POSITION 28
92 #define GDI_DECORATION_SIZE 29
93 #define GDI_DECORATION_SHIFTING 30
94 #define GDI_EVENT_MASK 31
96 #define GDI_CALLBACK_INFO 33
97 #define GDI_CALLBACK_ACTION 34
98 #define GDI_AREA_SIZE 35
99 #define GDI_ITEM_SIZE 36
100 #define GDI_SCROLLBAR_ITEMS_MAX 37
101 #define GDI_SCROLLBAR_ITEMS_VISIBLE 38
102 #define GDI_SCROLLBAR_ITEM_POSITION 39
103 #define GDI_WHEEL_AREA_X 40
104 #define GDI_WHEEL_AREA_Y 41
105 #define GDI_WHEEL_AREA_WIDTH 42
106 #define GDI_WHEEL_AREA_HEIGHT 43
107 #define GDI_INFO_TEXT 44
108 #define GDI_ACTIVE 45
109 #define GDI_DIRECT_DRAW 46
111 /* gadget deactivation hack */
112 #define GDI_ACTIVE_POS(a) ((a) < 0 ? POS_OFFSCREEN : (a))
115 typedef void (*gadget_function)(void *);
119 int xsize, ysize; /* size of gadget border */
120 int xsize_selectbutton; /* for selectbox gadgets */
121 int width; /* for selectbox/text input gadgets */
126 Bitmap *bitmap; /* Bitmap with gadget surface */
127 int x, y; /* position of rectangle in Bitmap */
130 struct GadgetDecoration
132 struct GadgetDesign design; /* decoration design structure */
133 int x, y; /* position of deco on the gadget */
134 int width, height; /* width and height of decoration */
135 int xshift, yshift; /* deco shifting when gadget pressed */
140 unsigned int type; /* event type */
141 int button; /* button number for button events */
142 int x, y; /* gadget position at event time */
143 boolean off_borders; /* mouse pointer outside gadget? */
144 int item_x, item_y, item_position; /* new item position */
147 struct GadgetDrawingArea
149 int area_xsize, area_ysize; /* size of drawing area (in items) */
150 int item_xsize, item_ysize; /* size of each item in drawing area */
153 struct GadgetTextButton
155 char value[MAX_GADGET_TEXTSIZE + 1]; /* text written on the button */
156 int size; /* maximal size of button text */
159 struct GadgetTextInput
161 char value[MAX_GADGET_TEXTSIZE + 1]; /* text string in input field */
162 char last_value[MAX_GADGET_TEXTSIZE + 1];/* last text string in input field */
163 int cursor_position; /* actual text cursor position */
164 int number_value; /* integer value, if numeric */
165 int number_min; /* minimal allowed numeric value */
166 int number_max; /* maximal allowed numeric value */
167 int size; /* maximal size of input text */
170 struct GadgetTextArea
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 cursor_x; /* actual x cursor position */
176 int cursor_y; /* actual y cursor position */
177 int cursor_x_preferred; /* "preferred" x cursor position */
178 int size; /* maximal size of input text */
179 int xsize, ysize; /* size of text area (in chars) */
182 struct GadgetSelectbox
184 struct ValueTextInfo *options; /* pointer to text/value array */
185 int index; /* index of actual text string */
186 int size; /* maximal size of text strings */
188 /* automatically determined values */
189 int x, y; /* open selectbox position */
190 int width, height; /* open selectbox size */
191 int num_values; /* number of text strings */
192 Pixel inverse_color; /* color for highlighting */
195 boolean open; /* opening state of selectbox */
196 boolean stay_open; /* open after button release */
197 int current_index; /* index of text while selecting */
200 struct GadgetScrollbar
202 int items_max; /* number of items to access */
203 int items_visible; /* number of visible items */
204 int item_position; /* actual item position */
205 int size_min; /* minimal scrollbar size */
206 int size_max; /* this is either width or height */
207 int size_max_cmp; /* needed for minimal scrollbar size */
208 int size; /* scrollbar size on screen */
209 int position; /* scrollbar position on screen */
210 int position_max; /* bottom/right scrollbar position */
211 int drag_position; /* drag position on scrollbar */
212 int correction; /* scrollbar position correction */
215 struct GadgetWheelArea
217 int x, y; /* active area for wheel (start) */
218 int width, height; /* active area for wheel (size) */
223 int id; /* internal gadget identifier */
224 int custom_id; /* custom gadget identifier */
225 int custom_type_id; /* custom gadget type identifier */
226 char info_text[MAX_INFO_TEXTSIZE + 1];/* short popup info text */
227 int x, y; /* gadget position */
228 int width, height; /* gadget size */
229 unsigned int type; /* type (button, text input, ...) */
230 unsigned int state; /* state (pressed, released, ...) */
231 boolean checked; /* check/radio button state */
232 int radio_nr; /* number of radio button series */
233 boolean mapped; /* gadget is mapped on the screen */
234 boolean active; /* gadget is active */
235 boolean direct_draw; /* directly draw to frontbuffer */
236 int font; /* font to use when inactive */
237 int font_active; /* font to use when active */
238 struct GadgetBorder border; /* gadget border design */
239 struct GadgetDesign design[2]; /* 0: normal; 1: pressed */
240 struct GadgetDesign alt_design[2]; /* alternative design */
241 struct GadgetDecoration deco; /* decoration on top of gadget */
242 unsigned int event_mask; /* possible events for this gadget */
243 struct GadgetEvent event; /* actual gadget event */
244 gadget_function callback_info; /* function for pop-up info text */
245 gadget_function callback_action; /* function for gadget action */
246 struct GadgetDrawingArea drawing; /* fields for drawing area gadget */
247 struct GadgetTextButton textbutton; /* fields for text button gadget */
248 struct GadgetTextInput textinput; /* fields for text input gadget */
249 struct GadgetTextArea textarea; /* fields for text area gadget */
250 struct GadgetSelectbox selectbox; /* fields for selectbox gadget */
251 struct GadgetScrollbar scrollbar; /* fields for scrollbar gadget */
252 struct GadgetWheelArea wheelarea; /* fields for scroll wheel area */
253 struct GadgetInfo *next; /* next list entry */
257 void InitGadgetsSoundCallback(void (*activating_function)(void),
258 void (*selecting_function)(void));
260 struct GadgetInfo *CreateGadget(int, ...);
261 void FreeGadget(struct GadgetInfo *);
263 void ModifyGadget(struct GadgetInfo *, int, ...);
264 void RedrawGadget(struct GadgetInfo *);
266 void MapGadget(struct GadgetInfo *);
267 void UnmapGadget(struct GadgetInfo *);
268 void UnmapAllGadgets();
269 void RemapAllGadgets();
271 boolean anyTextInputGadgetActive();
272 boolean anyTextAreaGadgetActive();
273 boolean anySelectboxGadgetActive();
274 boolean anyScrollbarGadgetActive();
275 boolean anyTextGadgetActive();
277 void ClickOnGadget(struct GadgetInfo *, int);
279 boolean HandleGadgets(int, int, int);
280 boolean HandleGadgetsKeyInput(Key);
282 #endif /* GADGETS_H */