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_TEXTINPUT_ALPHANUMERIC (1 << 5)
29 #define GD_TYPE_TEXTINPUT_NUMERIC (1 << 6)
30 #define GD_TYPE_SELECTBOX (1 << 7)
31 #define GD_TYPE_SCROLLBAR_VERTICAL (1 << 8)
32 #define GD_TYPE_SCROLLBAR_HORIZONTAL (1 << 9)
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_TEXTINPUT (GD_TYPE_TEXTINPUT_ALPHANUMERIC | \
41 GD_TYPE_TEXTINPUT_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_INFO_TEXT 40
104 #define GDI_ACTIVE 41
106 typedef void (*gadget_function)(void *);
110 int xsize, ysize; /* size of gadget border */
111 int xsize_selectbutton; /* for selectbox gadgets */
112 int width; /* for selectbox/text input gadgets */
117 Bitmap *bitmap; /* Bitmap with gadget surface */
118 int x, y; /* position of rectangle in Bitmap */
121 struct GadgetDecoration
123 struct GadgetDesign design; /* decoration design structure */
124 int x, y; /* position of deco on the gadget */
125 int width, height; /* width and height of decoration */
126 int xshift, yshift; /* deco shifting when gadget pressed */
131 unsigned long type; /* event type */
132 int button; /* button number for button events */
133 int x, y; /* gadget position at event time */
134 boolean off_borders; /* mouse pointer outside gadget? */
135 int item_x, item_y, item_position; /* new item position */
138 struct GadgetDrawingArea
140 int area_xsize, area_ysize; /* size of drawing area (in items) */
141 int item_xsize, item_ysize; /* size of each item in drawing area */
144 struct GadgetTextButton
146 char value[MAX_GADGET_TEXTSIZE]; /* text written on the button */
147 int size; /* maximal size of button text */
150 struct GadgetTextInput
152 char value[MAX_GADGET_TEXTSIZE]; /* text string in input field */
153 int cursor_position; /* actual text cursor position */
154 int number_value; /* integer value, if numeric */
155 int number_min; /* minimal allowed numeric value */
156 int number_max; /* maximal allowed numeric value */
157 int size; /* maximal size of input text */
160 struct GadgetSelectbox
162 struct ValueTextInfo *options; /* pointer to text/value array */
163 int index; /* index of actual text string */
164 int size; /* maximal size of text strings */
166 /* automatically determined values */
167 int x, y; /* open selectbox position */
168 int width, height; /* open selectbox size */
169 int num_values; /* number of text strings */
170 Pixel inverse_color; /* color for highlighting */
173 boolean open; /* opening state of selectbox */
174 boolean stay_open; /* open after button release */
175 int current_index; /* index of text while selecting */
178 struct GadgetScrollbar
180 int items_max; /* number of items to access */
181 int items_visible; /* number of visible items */
182 int item_position; /* actual item position */
183 int size_max; /* this is either width or height */
184 int size; /* scrollbar size on screen */
185 int position; /* scrollbar position on screen */
186 int position_max; /* bottom/right scrollbar position */
187 int drag_position; /* drag position on scrollbar */
188 int correction; /* scrollbar position correction */
193 int id; /* internal gadget identifier */
194 int custom_id; /* custom gadget identifier */
195 int custom_type_id; /* custom gadget type identifier */
196 char info_text[MAX_INFO_TEXTSIZE]; /* short popup info text */
197 int x, y; /* gadget position */
198 int width, height; /* gadget size */
199 unsigned long type; /* type (button, text input, ...) */
200 unsigned long state; /* state (pressed, released, ...) */
201 boolean checked; /* check/radio button state */
202 int radio_nr; /* number of radio button series */
203 boolean mapped; /* gadget is mapped on the screen */
204 boolean active; /* gadget is active */
205 int font; /* font to use when inactive */
206 int font_active; /* font to use when active */
207 struct GadgetBorder border; /* gadget border design */
208 struct GadgetDesign design[2]; /* 0: normal; 1: pressed */
209 struct GadgetDesign alt_design[2]; /* alternative design */
210 struct GadgetDecoration deco; /* decoration on top of gadget */
211 unsigned long event_mask; /* possible events for this gadget */
212 struct GadgetEvent event; /* actual gadget event */
213 gadget_function callback_info; /* function for pop-up info text */
214 gadget_function callback_action; /* function for gadget action */
215 struct GadgetDrawingArea drawing; /* fields for drawing area gadget */
216 struct GadgetTextButton textbutton; /* fields for text button gadget */
217 struct GadgetTextInput text; /* fields for text input gadget */
218 struct GadgetSelectbox selectbox; /* fields for selectbox gadget */
219 struct GadgetScrollbar scrollbar; /* fields for scrollbar gadget */
220 struct GadgetInfo *next; /* next list entry */
223 struct GadgetInfo *CreateGadget(int, ...);
224 void FreeGadget(struct GadgetInfo *);
226 void ModifyGadget(struct GadgetInfo *, int, ...);
227 void RedrawGadget(struct GadgetInfo *);
229 void MapGadget(struct GadgetInfo *);
230 void UnmapGadget(struct GadgetInfo *);
231 void UnmapAllGadgets();
232 void RemapAllGadgets();
234 boolean anyTextGadgetActive();
235 void ClickOnGadget(struct GadgetInfo *, int);
237 void HandleGadgets(int, int, int);
238 void HandleGadgetsKeyInput(Key);
240 #endif /* GADGETS_H */