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
105 #define GDI_DIRECT_DRAW 42
107 typedef void (*gadget_function)(void *);
111 int xsize, ysize; /* size of gadget border */
112 int xsize_selectbutton; /* for selectbox gadgets */
113 int width; /* for selectbox/text input gadgets */
118 Bitmap *bitmap; /* Bitmap with gadget surface */
119 int x, y; /* position of rectangle in Bitmap */
122 struct GadgetDecoration
124 struct GadgetDesign design; /* decoration design structure */
125 int x, y; /* position of deco on the gadget */
126 int width, height; /* width and height of decoration */
127 int xshift, yshift; /* deco shifting when gadget pressed */
132 unsigned long type; /* event type */
133 int button; /* button number for button events */
134 int x, y; /* gadget position at event time */
135 boolean off_borders; /* mouse pointer outside gadget? */
136 int item_x, item_y, item_position; /* new item position */
139 struct GadgetDrawingArea
141 int area_xsize, area_ysize; /* size of drawing area (in items) */
142 int item_xsize, item_ysize; /* size of each item in drawing area */
145 struct GadgetTextButton
147 char value[MAX_GADGET_TEXTSIZE]; /* text written on the button */
148 int size; /* maximal size of button text */
151 struct GadgetTextInput
153 char value[MAX_GADGET_TEXTSIZE]; /* text string in input field */
154 int cursor_position; /* actual text cursor position */
155 int number_value; /* integer value, if numeric */
156 int number_min; /* minimal allowed numeric value */
157 int number_max; /* maximal allowed numeric value */
158 int size; /* maximal size of input text */
161 struct GadgetSelectbox
163 struct ValueTextInfo *options; /* pointer to text/value array */
164 int index; /* index of actual text string */
165 int size; /* maximal size of text strings */
167 /* automatically determined values */
168 int x, y; /* open selectbox position */
169 int width, height; /* open selectbox size */
170 int num_values; /* number of text strings */
171 Pixel inverse_color; /* color for highlighting */
174 boolean open; /* opening state of selectbox */
175 boolean stay_open; /* open after button release */
176 int current_index; /* index of text while selecting */
179 struct GadgetScrollbar
181 int items_max; /* number of items to access */
182 int items_visible; /* number of visible items */
183 int item_position; /* actual item position */
184 int size_max; /* this is either width or height */
185 int size; /* scrollbar size on screen */
186 int position; /* scrollbar position on screen */
187 int position_max; /* bottom/right scrollbar position */
188 int drag_position; /* drag position on scrollbar */
189 int correction; /* scrollbar position correction */
194 int id; /* internal gadget identifier */
195 int custom_id; /* custom gadget identifier */
196 int custom_type_id; /* custom gadget type identifier */
197 char info_text[MAX_INFO_TEXTSIZE]; /* short popup info text */
198 int x, y; /* gadget position */
199 int width, height; /* gadget size */
200 unsigned long type; /* type (button, text input, ...) */
201 unsigned long state; /* state (pressed, released, ...) */
202 boolean checked; /* check/radio button state */
203 int radio_nr; /* number of radio button series */
204 boolean mapped; /* gadget is mapped on the screen */
205 boolean active; /* gadget is active */
206 boolean direct_draw; /* directly draw to frontbuffer */
207 int font; /* font to use when inactive */
208 int font_active; /* font to use when active */
209 struct GadgetBorder border; /* gadget border design */
210 struct GadgetDesign design[2]; /* 0: normal; 1: pressed */
211 struct GadgetDesign alt_design[2]; /* alternative design */
212 struct GadgetDecoration deco; /* decoration on top of gadget */
213 unsigned long event_mask; /* possible events for this gadget */
214 struct GadgetEvent event; /* actual gadget event */
215 gadget_function callback_info; /* function for pop-up info text */
216 gadget_function callback_action; /* function for gadget action */
217 struct GadgetDrawingArea drawing; /* fields for drawing area gadget */
218 struct GadgetTextButton textbutton; /* fields for text button gadget */
219 struct GadgetTextInput text; /* fields for text input gadget */
220 struct GadgetSelectbox selectbox; /* fields for selectbox gadget */
221 struct GadgetScrollbar scrollbar; /* fields for scrollbar gadget */
222 struct GadgetInfo *next; /* next list entry */
225 struct GadgetInfo *CreateGadget(int, ...);
226 void FreeGadget(struct GadgetInfo *);
228 void ModifyGadget(struct GadgetInfo *, int, ...);
229 void RedrawGadget(struct GadgetInfo *);
231 void MapGadget(struct GadgetInfo *);
232 void UnmapGadget(struct GadgetInfo *);
233 void UnmapAllGadgets();
234 void RemapAllGadgets();
236 boolean anyTextGadgetActive();
237 void ClickOnGadget(struct GadgetInfo *, int);
239 void HandleGadgets(int, int, int);
240 void HandleGadgetsKeyInput(Key);
242 #endif /* GADGETS_H */