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