1 /***********************************************************
2 * Artsoft Retro-Game Library *
3 *----------------------------------------------------------*
4 * (c) 1994-2002 Artsoft Entertainment *
6 * Detmolder Strasse 189 *
9 * e-mail: info@artsoft.org *
10 *----------------------------------------------------------*
12 ***********************************************************/
20 #define GADGET_FRAME_DELAY 150 /* delay between gadget actions */
23 #define GD_TYPE_NORMAL_BUTTON (1 << 0)
24 #define GD_TYPE_CHECK_BUTTON (1 << 1)
25 #define GD_TYPE_RADIO_BUTTON (1 << 2)
26 #define GD_TYPE_DRAWING_AREA (1 << 3)
27 #define GD_TYPE_TEXTINPUT_ALPHANUMERIC (1 << 4)
28 #define GD_TYPE_TEXTINPUT_NUMERIC (1 << 5)
29 #define GD_TYPE_SELECTBOX (1 << 6)
30 #define GD_TYPE_SCROLLBAR_VERTICAL (1 << 7)
31 #define GD_TYPE_SCROLLBAR_HORIZONTAL (1 << 8)
33 #define GD_TYPE_BUTTON (GD_TYPE_NORMAL_BUTTON | \
34 GD_TYPE_CHECK_BUTTON | \
36 #define GD_TYPE_SCROLLBAR (GD_TYPE_SCROLLBAR_VERTICAL | \
37 GD_TYPE_SCROLLBAR_HORIZONTAL)
38 #define GD_TYPE_TEXTINPUT (GD_TYPE_TEXTINPUT_ALPHANUMERIC | \
39 GD_TYPE_TEXTINPUT_NUMERIC)
42 #define GD_EVENT_PRESSED (1 << 0)
43 #define GD_EVENT_RELEASED (1 << 1)
44 #define GD_EVENT_MOVING (1 << 2)
45 #define GD_EVENT_REPEATED (1 << 3)
46 #define GD_EVENT_OFF_BORDERS (1 << 4)
47 #define GD_EVENT_TEXT_RETURN (1 << 5)
48 #define GD_EVENT_TEXT_LEAVING (1 << 6)
49 #define GD_EVENT_INFO_ENTERING (1 << 7)
50 #define GD_EVENT_INFO_LEAVING (1 << 8)
52 /* gadget button states */
53 #define GD_BUTTON_UNPRESSED 0
54 #define GD_BUTTON_PRESSED 1
56 /* gadget structure constants */
57 #define MAX_GADGET_TEXTSIZE 1024
58 #define MAX_INFO_TEXTSIZE 1024
60 /* gadget creation tags */
62 #define GDI_CUSTOM_ID 1
63 #define GDI_CUSTOM_TYPE_ID 2
71 #define GDI_RADIO_NR 10
72 #define GDI_NUMBER_VALUE 11
73 #define GDI_NUMBER_MIN 12
74 #define GDI_NUMBER_MAX 13
75 #define GDI_TEXT_VALUE 14
76 #define GDI_TEXT_SIZE 15
77 #define GDI_TEXT_FONT 16
78 #define GDI_SELECTBOX_VALUES 17
79 #define GDI_SELECTBOX_INDEX 18
80 #define GDI_DESIGN_UNPRESSED 19
81 #define GDI_DESIGN_PRESSED 20
82 #define GDI_ALT_DESIGN_UNPRESSED 21
83 #define GDI_ALT_DESIGN_PRESSED 22
84 #define GDI_BORDER_SIZE 23
85 #define GDI_BORDER_SIZE_SELECTBUTTON 24
86 #define GDI_TEXTINPUT_DESIGN_WIDTH 25
87 #define GDI_DECORATION_DESIGN 26
88 #define GDI_DECORATION_POSITION 27
89 #define GDI_DECORATION_SIZE 28
90 #define GDI_DECORATION_SHIFTING 29
91 #define GDI_EVENT_MASK 30
93 #define GDI_CALLBACK_INFO 32
94 #define GDI_CALLBACK_ACTION 33
95 #define GDI_AREA_SIZE 34
96 #define GDI_ITEM_SIZE 35
97 #define GDI_SCROLLBAR_ITEMS_MAX 36
98 #define GDI_SCROLLBAR_ITEMS_VISIBLE 37
99 #define GDI_SCROLLBAR_ITEM_POSITION 38
100 #define GDI_INFO_TEXT 39
102 typedef void (*gadget_function)(void *);
106 int size; /* size of gadget border */
107 int size_selectbutton; /* for selectbox gadgets */
108 int width; /* for selectbox/text input gadgets */
113 Bitmap *bitmap; /* Bitmap with gadget surface */
114 int x, y; /* position of rectangle in Bitmap */
117 struct GadgetDecoration
119 struct GadgetDesign design; /* decoration design structure */
120 int x, y; /* position of deco on the gadget */
121 int width, height; /* width and height of decoration */
122 int xshift, yshift; /* deco shifting when gadget pressed */
127 unsigned long type; /* event type */
128 int button; /* button number for button events */
129 int x, y; /* gadget position at event time */
130 boolean off_borders; /* mouse pointer outside gadget? */
131 int item_x, item_y, item_position; /* new item position */
134 struct GadgetDrawingArea
136 int area_xsize, area_ysize; /* size of drawing area (in items) */
137 int item_xsize, item_ysize; /* size of each item in drawing area */
140 struct GadgetTextInput
142 char value[MAX_GADGET_TEXTSIZE]; /* text string in input field */
143 int number_value; /* integer value, if numeric */
144 int number_min; /* minimal allowed numeric value */
145 int number_max; /* maximal allowed numeric value */
146 int size; /* maximal size of input text */
147 int cursor_position; /* actual cursor position */
148 int font_type; /* font to use for text input */
151 struct GadgetSelectbox
153 const char **values; /* pointer to array of text strings */
154 int index; /* index of actual text string */
155 int size; /* maximal size of text strings */
156 int font_type; /* font to use for text input */
158 /* automatically determined values */
159 int x, y; /* open selectbox position */
160 int width, height; /* open selectbox size */
161 int num_values; /* number of text strings */
162 Pixel reverse_color; /* color for highlighting */
165 boolean open; /* opening state of selectbox */
166 boolean stay_open; /* open after button release */
167 int current_index; /* index of text while selecting */
170 struct GadgetScrollbar
172 int items_max; /* number of items to access */
173 int items_visible; /* number of visible items */
174 int item_position; /* actual item position */
175 int size_max; /* this is either width or height */
176 int size; /* scrollbar size on screen */
177 int position; /* scrollbar position on screen */
178 int position_max; /* bottom/right scrollbar position */
179 int drag_position; /* drag position on scrollbar */
180 int correction; /* scrollbar position correction */
185 int id; /* internal gadget identifier */
186 int custom_id; /* custom gadget identifier */
187 int custom_type_id; /* custom gadget type identifier */
188 char info_text[MAX_INFO_TEXTSIZE]; /* short popup info text */
189 int x, y; /* gadget position */
190 int width, height; /* gadget size */
191 unsigned long type; /* type (button, text input, ...) */
192 unsigned long state; /* state (pressed, released, ...) */
193 boolean checked; /* check/radio button state */
194 int radio_nr; /* number of radio button series */
195 boolean mapped; /* gadget is active */
196 struct GadgetBorder border; /* gadget border design */
197 struct GadgetDesign design[2]; /* 0: normal; 1: pressed */
198 struct GadgetDesign alt_design[2]; /* alternative design */
199 struct GadgetDecoration deco; /* decoration on top of gadget */
200 unsigned long event_mask; /* possible events for this gadget */
201 struct GadgetEvent event; /* actual gadget event */
202 gadget_function callback_info; /* function for pop-up info text */
203 gadget_function callback_action; /* function for gadget action */
204 struct GadgetDrawingArea drawing; /* fields for drawing area gadget */
205 struct GadgetTextInput text; /* fields for text input gadget */
206 struct GadgetSelectbox selectbox; /* fields for selectbox gadget */
207 struct GadgetScrollbar scrollbar; /* fields for scrollbar gadget */
208 struct GadgetInfo *next; /* next list entry */
211 struct GadgetInfo *CreateGadget(int, ...);
212 void FreeGadget(struct GadgetInfo *);
214 void ModifyGadget(struct GadgetInfo *, int, ...);
215 void RedrawGadget(struct GadgetInfo *);
217 void MapGadget(struct GadgetInfo *);
218 void UnmapGadget(struct GadgetInfo *);
219 void UnmapAllGadgets();
220 void RemapAllGadgets();
222 boolean anyTextGadgetActive();
223 void ClickOnGadget(struct GadgetInfo *, int);
225 void HandleGadgets(int, int, int);
226 void HandleGadgetsKeyInput(Key);
228 #endif /* GADGETS_H */