rnd-20060726-3-src
[rocksndiamonds.git] / src / libgame / gadgets.h
1 /***********************************************************
2 * Artsoft Retro-Game Library                               *
3 *----------------------------------------------------------*
4 * (c) 1994-2002 Artsoft Entertainment                      *
5 *               Holger Schemel                             *
6 *               Detmolder Strasse 189                      *
7 *               33604 Bielefeld                            *
8 *               Germany                                    *
9 *               e-mail: info@artsoft.org                   *
10 *----------------------------------------------------------*
11 * gadgets.h                                                *
12 ***********************************************************/
13
14 #ifndef GADGETS_H
15 #define GADGETS_H
16
17 #include "system.h"
18
19
20 #define GADGET_FRAME_DELAY_FIRST        250     /* delay after first click */
21 #define GADGET_FRAME_DELAY              100     /* delay for pressed butten */
22
23 /* gadget types */
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)
35
36 #define GD_TYPE_BUTTON                  (GD_TYPE_NORMAL_BUTTON | \
37                                          GD_TYPE_TEXT_BUTTON | \
38                                          GD_TYPE_CHECK_BUTTON | \
39                                          GD_TYPE_RADIO_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)
44
45 /* gadget events */
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)
55
56 /* gadget button states */
57 #define GD_BUTTON_UNPRESSED             0
58 #define GD_BUTTON_PRESSED               1
59
60 /* gadget structure constants */
61 #define MAX_GADGET_TEXTSIZE             1024
62 #define MAX_INFO_TEXTSIZE               1024
63
64 /* gadget creation tags */
65 #define GDI_END                         0
66 #define GDI_CUSTOM_ID                   1
67 #define GDI_CUSTOM_TYPE_ID              2
68 #define GDI_X                           3
69 #define GDI_Y                           4
70 #define GDI_WIDTH                       5
71 #define GDI_HEIGHT                      6
72 #define GDI_TYPE                        7
73 #define GDI_STATE                       8
74 #define GDI_CHECKED                     9
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
97 #define GDI_EVENT                       32
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
112
113 typedef void (*gadget_function)(void *);
114
115 struct GadgetBorder
116 {
117   int xsize, ysize;                     /* size of gadget border */
118   int xsize_selectbutton;               /* for selectbox gadgets */
119   int width;                            /* for selectbox/text input gadgets */
120 };
121
122 struct GadgetDesign
123 {
124   Bitmap *bitmap;                       /* Bitmap with gadget surface */
125   int x, y;                             /* position of rectangle in Bitmap */
126 };
127
128 struct GadgetDecoration
129 {
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 */
134 };
135
136 struct GadgetEvent
137 {
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 */
143 };
144
145 struct GadgetDrawingArea
146 {
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 */
149 };
150
151 struct GadgetTextButton
152 {
153   char value[MAX_GADGET_TEXTSIZE];      /* text written on the button */
154   int size;                             /* maximal size of button text */
155 };
156
157 struct GadgetTextInput
158 {
159   char value[MAX_GADGET_TEXTSIZE];      /* text string in input field */
160   char last_value[MAX_GADGET_TEXTSIZE]; /* 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 */
166 };
167
168 struct GadgetTextArea
169 {
170   char value[MAX_GADGET_TEXTSIZE];      /* text string in input field */
171   char last_value[MAX_GADGET_TEXTSIZE]; /* 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) */
178 };
179
180 struct GadgetSelectbox
181 {
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 */
185
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 */
191
192   /* runtime values */
193   boolean open;                         /* opening state of selectbox */
194   boolean stay_open;                    /* open after button release */
195   int current_index;                    /* index of text while selecting */
196 };
197
198 struct GadgetScrollbar
199 {
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 */
211 };
212
213 struct GadgetWheelArea
214 {
215   int x, y;                             /* active area for wheel (start) */
216   int width, height;                    /* active area for wheel (size) */ 
217 };
218
219 struct GadgetInfo
220 {
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];    /* 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 */
252 };
253
254 struct GadgetInfo *CreateGadget(int, ...);
255 void FreeGadget(struct GadgetInfo *);
256
257 void ModifyGadget(struct GadgetInfo *, int, ...);
258 void RedrawGadget(struct GadgetInfo *);
259
260 void MapGadget(struct GadgetInfo *);
261 void UnmapGadget(struct GadgetInfo *);
262 void UnmapAllGadgets();
263 void RemapAllGadgets();
264
265 boolean anyTextInputGadgetActive();
266 boolean anyTextAreaGadgetActive();
267 boolean anySelectboxGadgetActive();
268 boolean anyScrollbarGadgetActive();
269 boolean anyTextGadgetActive();
270
271 void ClickOnGadget(struct GadgetInfo *, int);
272
273 boolean HandleGadgets(int, int, int);
274 boolean HandleGadgetsKeyInput(Key);
275
276 #endif  /* GADGETS_H */