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_FIRST 250 /* delay after first click */
21 #define GADGET_FRAME_DELAY 100 /* delay for pressed butten */
24 #define GD_TYPE_NORMAL_BUTTON (1 << 0)
25 #define GD_TYPE_TEXT_BUTTON (1 << 1)
26 #define GD_TYPE_CHECK_BUTTON (1 << 2)
27 #define GD_TYPE_RADIO_BUTTON (1 << 3)
28 #define GD_TYPE_DRAWING_AREA (1 << 4)
29 #define GD_TYPE_TEXT_INPUT_ALPHANUMERIC (1 << 5)
30 #define GD_TYPE_TEXT_INPUT_NUMERIC (1 << 6)
31 #define GD_TYPE_TEXT_AREA (1 << 7)
32 #define GD_TYPE_SELECTBOX (1 << 8)
33 #define GD_TYPE_SCROLLBAR_VERTICAL (1 << 9)
34 #define GD_TYPE_SCROLLBAR_HORIZONTAL (1 << 10)
36 #define GD_TYPE_BUTTON (GD_TYPE_NORMAL_BUTTON | \
37 GD_TYPE_TEXT_BUTTON | \
38 GD_TYPE_CHECK_BUTTON | \
40 #define GD_TYPE_SCROLLBAR (GD_TYPE_SCROLLBAR_VERTICAL | \
41 GD_TYPE_SCROLLBAR_HORIZONTAL)
42 #define GD_TYPE_TEXT_INPUT (GD_TYPE_TEXT_INPUT_ALPHANUMERIC | \
43 GD_TYPE_TEXT_INPUT_NUMERIC)
46 #define GD_EVENT_PRESSED (1 << 0)
47 #define GD_EVENT_RELEASED (1 << 1)
48 #define GD_EVENT_MOVING (1 << 2)
49 #define GD_EVENT_REPEATED (1 << 3)
50 #define GD_EVENT_OFF_BORDERS (1 << 4)
51 #define GD_EVENT_TEXT_RETURN (1 << 5)
52 #define GD_EVENT_TEXT_LEAVING (1 << 6)
53 #define GD_EVENT_INFO_ENTERING (1 << 7)
54 #define GD_EVENT_INFO_LEAVING (1 << 8)
56 /* gadget button states */
57 #define GD_BUTTON_UNPRESSED 0
58 #define GD_BUTTON_PRESSED 1
60 /* gadget structure constants */
61 #define MAX_GADGET_TEXTSIZE 1024
62 #define MAX_INFO_TEXTSIZE 1024
64 /* gadget creation tags */
66 #define GDI_CUSTOM_ID 1
67 #define GDI_CUSTOM_TYPE_ID 2
75 #define GDI_RADIO_NR 10
76 #define GDI_NUMBER_VALUE 11
77 #define GDI_NUMBER_MIN 12
78 #define GDI_NUMBER_MAX 13
79 #define GDI_TEXT_VALUE 14
80 #define GDI_TEXT_SIZE 15
81 #define GDI_TEXT_FONT 16
82 #define GDI_TEXT_FONT_ACTIVE 17
83 #define GDI_SELECTBOX_OPTIONS 18
84 #define GDI_SELECTBOX_INDEX 19
85 #define GDI_DESIGN_UNPRESSED 20
86 #define GDI_DESIGN_PRESSED 21
87 #define GDI_ALT_DESIGN_UNPRESSED 22
88 #define GDI_ALT_DESIGN_PRESSED 23
89 #define GDI_BORDER_SIZE 24
90 #define GDI_BORDER_SIZE_SELECTBUTTON 25
91 #define GDI_DESIGN_WIDTH 26
92 #define GDI_DECORATION_DESIGN 27
93 #define GDI_DECORATION_POSITION 28
94 #define GDI_DECORATION_SIZE 29
95 #define GDI_DECORATION_SHIFTING 30
96 #define GDI_EVENT_MASK 31
98 #define GDI_CALLBACK_INFO 33
99 #define GDI_CALLBACK_ACTION 34
100 #define GDI_AREA_SIZE 35
101 #define GDI_ITEM_SIZE 36
102 #define GDI_SCROLLBAR_ITEMS_MAX 37
103 #define GDI_SCROLLBAR_ITEMS_VISIBLE 38
104 #define GDI_SCROLLBAR_ITEM_POSITION 39
105 #define GDI_INFO_TEXT 40
106 #define GDI_ACTIVE 41
107 #define GDI_DIRECT_DRAW 42
109 typedef void (*gadget_function)(void *);
113 int xsize, ysize; /* size of gadget border */
114 int xsize_selectbutton; /* for selectbox gadgets */
115 int width; /* for selectbox/text input gadgets */
120 Bitmap *bitmap; /* Bitmap with gadget surface */
121 int x, y; /* position of rectangle in Bitmap */
124 struct GadgetDecoration
126 struct GadgetDesign design; /* decoration design structure */
127 int x, y; /* position of deco on the gadget */
128 int width, height; /* width and height of decoration */
129 int xshift, yshift; /* deco shifting when gadget pressed */
134 unsigned long type; /* event type */
135 int button; /* button number for button events */
136 int x, y; /* gadget position at event time */
137 boolean off_borders; /* mouse pointer outside gadget? */
138 int item_x, item_y, item_position; /* new item position */
141 struct GadgetDrawingArea
143 int area_xsize, area_ysize; /* size of drawing area (in items) */
144 int item_xsize, item_ysize; /* size of each item in drawing area */
147 struct GadgetTextButton
149 char value[MAX_GADGET_TEXTSIZE]; /* text written on the button */
150 int size; /* maximal size of button text */
153 struct GadgetTextInput
155 char value[MAX_GADGET_TEXTSIZE]; /* text string in input field */
156 char last_value[MAX_GADGET_TEXTSIZE]; /* last text string in input field */
157 int cursor_position; /* actual text cursor position */
158 int number_value; /* integer value, if numeric */
159 int number_min; /* minimal allowed numeric value */
160 int number_max; /* maximal allowed numeric value */
161 int size; /* maximal size of input text */
164 struct GadgetTextArea
166 char value[MAX_GADGET_TEXTSIZE]; /* text string in input field */
167 char last_value[MAX_GADGET_TEXTSIZE]; /* last text string in input field */
168 int cursor_position; /* actual text cursor position */
169 int cursor_x; /* actual x cursor position */
170 int cursor_y; /* actual y cursor position */
171 int cursor_x_preferred; /* "preferred" x cursor position */
172 int size; /* maximal size of input text */
173 int xsize, ysize; /* size of text area (in chars) */
176 struct GadgetSelectbox
178 struct ValueTextInfo *options; /* pointer to text/value array */
179 int index; /* index of actual text string */
180 int size; /* maximal size of text strings */
182 /* automatically determined values */
183 int x, y; /* open selectbox position */
184 int width, height; /* open selectbox size */
185 int num_values; /* number of text strings */
186 Pixel inverse_color; /* color for highlighting */
189 boolean open; /* opening state of selectbox */
190 boolean stay_open; /* open after button release */
191 int current_index; /* index of text while selecting */
194 struct GadgetScrollbar
196 int items_max; /* number of items to access */
197 int items_visible; /* number of visible items */
198 int item_position; /* actual item position */
199 int size_min; /* minimal scrollbar size */
200 int size_max; /* this is either width or height */
201 int size_max_cmp; /* needed for minimal scrollbar size */
202 int size; /* scrollbar size on screen */
203 int position; /* scrollbar position on screen */
204 int position_max; /* bottom/right scrollbar position */
205 int drag_position; /* drag position on scrollbar */
206 int correction; /* scrollbar position correction */
211 int id; /* internal gadget identifier */
212 int custom_id; /* custom gadget identifier */
213 int custom_type_id; /* custom gadget type identifier */
214 char info_text[MAX_INFO_TEXTSIZE]; /* short popup info text */
215 int x, y; /* gadget position */
216 int width, height; /* gadget size */
217 unsigned int type; /* type (button, text input, ...) */
218 unsigned int state; /* state (pressed, released, ...) */
219 boolean checked; /* check/radio button state */
220 int radio_nr; /* number of radio button series */
221 boolean mapped; /* gadget is mapped on the screen */
222 boolean active; /* gadget is active */
223 boolean direct_draw; /* directly draw to frontbuffer */
224 int font; /* font to use when inactive */
225 int font_active; /* font to use when active */
226 struct GadgetBorder border; /* gadget border design */
227 struct GadgetDesign design[2]; /* 0: normal; 1: pressed */
228 struct GadgetDesign alt_design[2]; /* alternative design */
229 struct GadgetDecoration deco; /* decoration on top of gadget */
230 unsigned int event_mask; /* possible events for this gadget */
231 struct GadgetEvent event; /* actual gadget event */
232 gadget_function callback_info; /* function for pop-up info text */
233 gadget_function callback_action; /* function for gadget action */
234 struct GadgetDrawingArea drawing; /* fields for drawing area gadget */
235 struct GadgetTextButton textbutton; /* fields for text button gadget */
236 struct GadgetTextInput textinput; /* fields for text input gadget */
237 struct GadgetTextArea textarea; /* fields for text area gadget */
238 struct GadgetSelectbox selectbox; /* fields for selectbox gadget */
239 struct GadgetScrollbar scrollbar; /* fields for scrollbar gadget */
240 struct GadgetInfo *next; /* next list entry */
243 struct GadgetInfo *CreateGadget(int, ...);
244 void FreeGadget(struct GadgetInfo *);
246 void ModifyGadget(struct GadgetInfo *, int, ...);
247 void RedrawGadget(struct GadgetInfo *);
249 void MapGadget(struct GadgetInfo *);
250 void UnmapGadget(struct GadgetInfo *);
251 void UnmapAllGadgets();
252 void RemapAllGadgets();
254 boolean anyTextInputGadgetActive();
255 boolean anyTextAreaGadgetActive();
256 boolean anySelectboxGadgetActive();
257 boolean anyScrollbarGadgetActive();
258 boolean anyTextGadgetActive();
260 void ClickOnGadget(struct GadgetInfo *, int);
262 boolean HandleGadgets(int, int, int);
263 boolean HandleGadgetsKeyInput(Key);
265 #endif /* GADGETS_H */