1 /***********************************************************
2 * Artsoft Retro-Game Library *
3 *----------------------------------------------------------*
4 * (c) 1994-2006 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_WHEEL_AREA_X 40
106 #define GDI_WHEEL_AREA_Y 41
107 #define GDI_WHEEL_AREA_WIDTH 42
108 #define GDI_WHEEL_AREA_HEIGHT 43
109 #define GDI_INFO_TEXT 44
110 #define GDI_ACTIVE 45
111 #define GDI_DIRECT_DRAW 46
113 typedef void (*gadget_function)(void *);
117 int xsize, ysize; /* size of gadget border */
118 int xsize_selectbutton; /* for selectbox gadgets */
119 int width; /* for selectbox/text input gadgets */
124 Bitmap *bitmap; /* Bitmap with gadget surface */
125 int x, y; /* position of rectangle in Bitmap */
128 struct GadgetDecoration
130 struct GadgetDesign design; /* decoration design structure */
131 int x, y; /* position of deco on the gadget */
132 int width, height; /* width and height of decoration */
133 int xshift, yshift; /* deco shifting when gadget pressed */
138 unsigned long type; /* event type */
139 int button; /* button number for button events */
140 int x, y; /* gadget position at event time */
141 boolean off_borders; /* mouse pointer outside gadget? */
142 int item_x, item_y, item_position; /* new item position */
145 struct GadgetDrawingArea
147 int area_xsize, area_ysize; /* size of drawing area (in items) */
148 int item_xsize, item_ysize; /* size of each item in drawing area */
151 struct GadgetTextButton
153 char value[MAX_GADGET_TEXTSIZE + 1]; /* text written on the button */
154 int size; /* maximal size of button text */
157 struct GadgetTextInput
159 char value[MAX_GADGET_TEXTSIZE + 1]; /* text string in input field */
160 char last_value[MAX_GADGET_TEXTSIZE + 1];/* last text string in input field */
161 int cursor_position; /* actual text cursor position */
162 int number_value; /* integer value, if numeric */
163 int number_min; /* minimal allowed numeric value */
164 int number_max; /* maximal allowed numeric value */
165 int size; /* maximal size of input text */
168 struct GadgetTextArea
170 char value[MAX_GADGET_TEXTSIZE + 1]; /* text string in input field */
171 char last_value[MAX_GADGET_TEXTSIZE + 1];/* last text string in input field */
172 int cursor_position; /* actual text cursor position */
173 int cursor_x; /* actual x cursor position */
174 int cursor_y; /* actual y cursor position */
175 int cursor_x_preferred; /* "preferred" x cursor position */
176 int size; /* maximal size of input text */
177 int xsize, ysize; /* size of text area (in chars) */
180 struct GadgetSelectbox
182 struct ValueTextInfo *options; /* pointer to text/value array */
183 int index; /* index of actual text string */
184 int size; /* maximal size of text strings */
186 /* automatically determined values */
187 int x, y; /* open selectbox position */
188 int width, height; /* open selectbox size */
189 int num_values; /* number of text strings */
190 Pixel inverse_color; /* color for highlighting */
193 boolean open; /* opening state of selectbox */
194 boolean stay_open; /* open after button release */
195 int current_index; /* index of text while selecting */
198 struct GadgetScrollbar
200 int items_max; /* number of items to access */
201 int items_visible; /* number of visible items */
202 int item_position; /* actual item position */
203 int size_min; /* minimal scrollbar size */
204 int size_max; /* this is either width or height */
205 int size_max_cmp; /* needed for minimal scrollbar size */
206 int size; /* scrollbar size on screen */
207 int position; /* scrollbar position on screen */
208 int position_max; /* bottom/right scrollbar position */
209 int drag_position; /* drag position on scrollbar */
210 int correction; /* scrollbar position correction */
213 struct GadgetWheelArea
215 int x, y; /* active area for wheel (start) */
216 int width, height; /* active area for wheel (size) */
221 int id; /* internal gadget identifier */
222 int custom_id; /* custom gadget identifier */
223 int custom_type_id; /* custom gadget type identifier */
224 char info_text[MAX_INFO_TEXTSIZE + 1];/* short popup info text */
225 int x, y; /* gadget position */
226 int width, height; /* gadget size */
227 unsigned int type; /* type (button, text input, ...) */
228 unsigned int state; /* state (pressed, released, ...) */
229 boolean checked; /* check/radio button state */
230 int radio_nr; /* number of radio button series */
231 boolean mapped; /* gadget is mapped on the screen */
232 boolean active; /* gadget is active */
233 boolean direct_draw; /* directly draw to frontbuffer */
234 int font; /* font to use when inactive */
235 int font_active; /* font to use when active */
236 struct GadgetBorder border; /* gadget border design */
237 struct GadgetDesign design[2]; /* 0: normal; 1: pressed */
238 struct GadgetDesign alt_design[2]; /* alternative design */
239 struct GadgetDecoration deco; /* decoration on top of gadget */
240 unsigned int event_mask; /* possible events for this gadget */
241 struct GadgetEvent event; /* actual gadget event */
242 gadget_function callback_info; /* function for pop-up info text */
243 gadget_function callback_action; /* function for gadget action */
244 struct GadgetDrawingArea drawing; /* fields for drawing area gadget */
245 struct GadgetTextButton textbutton; /* fields for text button gadget */
246 struct GadgetTextInput textinput; /* fields for text input gadget */
247 struct GadgetTextArea textarea; /* fields for text area gadget */
248 struct GadgetSelectbox selectbox; /* fields for selectbox gadget */
249 struct GadgetScrollbar scrollbar; /* fields for scrollbar gadget */
250 struct GadgetWheelArea wheelarea; /* fields for scroll wheel area */
251 struct GadgetInfo *next; /* next list entry */
255 void InitGadgetsSoundCallback(void (*activating_function)(void),
256 void (*selecting_function)(void));
258 struct GadgetInfo *CreateGadget(int, ...);
259 void FreeGadget(struct GadgetInfo *);
261 void ModifyGadget(struct GadgetInfo *, int, ...);
262 void RedrawGadget(struct GadgetInfo *);
264 void MapGadget(struct GadgetInfo *);
265 void UnmapGadget(struct GadgetInfo *);
266 void UnmapAllGadgets();
267 void RemapAllGadgets();
269 boolean anyTextInputGadgetActive();
270 boolean anyTextAreaGadgetActive();
271 boolean anySelectboxGadgetActive();
272 boolean anyScrollbarGadgetActive();
273 boolean anyTextGadgetActive();
275 void ClickOnGadget(struct GadgetInfo *, int);
277 boolean HandleGadgets(int, int, int);
278 boolean HandleGadgetsKeyInput(Key);
280 #endif /* GADGETS_H */