rnd-20140305-1-src
[rocksndiamonds.git] / src / libgame / gadgets.h
1 /***********************************************************
2 * Artsoft Retro-Game Library                               *
3 *----------------------------------------------------------*
4 * (c) 1994-2006 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 /* gadget deactivation hack */
114 #define GDI_ACTIVE_POS(a)               ((a) < 0 ? POS_OFFSCREEN : (a))
115
116
117 typedef void (*gadget_function)(void *);
118
119 struct GadgetBorder
120 {
121   int xsize, ysize;                     /* size of gadget border */
122   int xsize_selectbutton;               /* for selectbox gadgets */
123   int width;                            /* for selectbox/text input gadgets */
124 };
125
126 struct GadgetDesign
127 {
128   Bitmap *bitmap;                       /* Bitmap with gadget surface */
129   int x, y;                             /* position of rectangle in Bitmap */
130 };
131
132 struct GadgetDecoration
133 {
134   struct GadgetDesign design;           /* decoration design structure */
135   int x, y;                             /* position of deco on the gadget */
136   int width, height;                    /* width and height of decoration */
137   int xshift, yshift;                   /* deco shifting when gadget pressed */
138 };
139
140 struct GadgetEvent
141 {
142   unsigned int type;                    /* event type */
143   int button;                           /* button number for button events */
144   int x, y;                             /* gadget position at event time */
145   boolean off_borders;                  /* mouse pointer outside gadget? */
146   int item_x, item_y, item_position;    /* new item position */
147 };
148
149 struct GadgetDrawingArea
150 {
151   int area_xsize, area_ysize;           /* size of drawing area (in items) */
152   int item_xsize, item_ysize;           /* size of each item in drawing area */
153 };
154
155 struct GadgetTextButton
156 {
157   char value[MAX_GADGET_TEXTSIZE + 1];  /* text written on the button */
158   int size;                             /* maximal size of button text */
159 };
160
161 struct GadgetTextInput
162 {
163   char value[MAX_GADGET_TEXTSIZE + 1];  /* text string in input field */
164   char last_value[MAX_GADGET_TEXTSIZE + 1];/* last text string in input field */
165   int cursor_position;                  /* actual text cursor position */
166   int number_value;                     /* integer value, if numeric */
167   int number_min;                       /* minimal allowed numeric value */
168   int number_max;                       /* maximal allowed numeric value */
169   int size;                             /* maximal size of input text */
170 };
171
172 struct GadgetTextArea
173 {
174   char value[MAX_GADGET_TEXTSIZE + 1];  /* text string in input field */
175   char last_value[MAX_GADGET_TEXTSIZE + 1];/* last text string in input field */
176   int cursor_position;                  /* actual text cursor position */
177   int cursor_x;                         /* actual x cursor position */
178   int cursor_y;                         /* actual y cursor position */
179   int cursor_x_preferred;               /* "preferred" x cursor position */
180   int size;                             /* maximal size of input text */
181   int xsize, ysize;                     /* size of text area (in chars) */
182 };
183
184 struct GadgetSelectbox
185 {
186   struct ValueTextInfo *options;        /* pointer to text/value array */
187   int index;                            /* index of actual text string */
188   int size;                             /* maximal size of text strings */
189
190   /* automatically determined values */
191   int x, y;                             /* open selectbox position */
192   int width, height;                    /* open selectbox size */
193   int num_values;                       /* number of text strings */
194   Pixel inverse_color;                  /* color for highlighting */
195
196   /* runtime values */
197   boolean open;                         /* opening state of selectbox */
198   boolean stay_open;                    /* open after button release */
199   int current_index;                    /* index of text while selecting */
200 };
201
202 struct GadgetScrollbar
203 {
204   int items_max;                        /* number of items to access */
205   int items_visible;                    /* number of visible items */
206   int item_position;                    /* actual item position */
207   int size_min;                         /* minimal scrollbar size */
208   int size_max;                         /* this is either width or height */
209   int size_max_cmp;                     /* needed for minimal scrollbar size */
210   int size;                             /* scrollbar size on screen */
211   int position;                         /* scrollbar position on screen */
212   int position_max;                     /* bottom/right scrollbar position */
213   int drag_position;                    /* drag position on scrollbar */
214   int correction;                       /* scrollbar position correction */
215 };
216
217 struct GadgetWheelArea
218 {
219   int x, y;                             /* active area for wheel (start) */
220   int width, height;                    /* active area for wheel (size) */ 
221 };
222
223 struct GadgetInfo
224 {
225   int id;                               /* internal gadget identifier */
226   int custom_id;                        /* custom gadget identifier */
227   int custom_type_id;                   /* custom gadget type identifier */
228   char info_text[MAX_INFO_TEXTSIZE + 1];/* short popup info text */
229   int x, y;                             /* gadget position */
230   int width, height;                    /* gadget size */
231   unsigned int type;                    /* type (button, text input, ...) */
232   unsigned int state;                   /* state (pressed, released, ...) */
233   boolean checked;                      /* check/radio button state */
234   int radio_nr;                         /* number of radio button series */
235   boolean mapped;                       /* gadget is mapped on the screen */
236   boolean active;                       /* gadget is active */
237   boolean direct_draw;                  /* directly draw to frontbuffer */
238   int font;                             /* font to use when inactive */
239   int font_active;                      /* font to use when active */
240   struct GadgetBorder border;           /* gadget border design */
241   struct GadgetDesign design[2];        /* 0: normal; 1: pressed */
242   struct GadgetDesign alt_design[2];    /* alternative design */
243   struct GadgetDecoration deco;         /* decoration on top of gadget */
244   unsigned int event_mask;              /* possible events for this gadget */
245   struct GadgetEvent event;             /* actual gadget event */
246   gadget_function callback_info;        /* function for pop-up info text */
247   gadget_function callback_action;      /* function for gadget action */
248   struct GadgetDrawingArea drawing;     /* fields for drawing area gadget */
249   struct GadgetTextButton textbutton;   /* fields for text button gadget */
250   struct GadgetTextInput textinput;     /* fields for text input gadget */
251   struct GadgetTextArea textarea;       /* fields for text area gadget */
252   struct GadgetSelectbox selectbox;     /* fields for selectbox gadget */
253   struct GadgetScrollbar scrollbar;     /* fields for scrollbar gadget */
254   struct GadgetWheelArea wheelarea;     /* fields for scroll wheel area */
255   struct GadgetInfo *next;              /* next list entry */
256 };
257
258
259 void InitGadgetsSoundCallback(void (*activating_function)(void),
260                               void (*selecting_function)(void));
261
262 struct GadgetInfo *CreateGadget(int, ...);
263 void FreeGadget(struct GadgetInfo *);
264
265 void ModifyGadget(struct GadgetInfo *, int, ...);
266 void RedrawGadget(struct GadgetInfo *);
267
268 void MapGadget(struct GadgetInfo *);
269 void UnmapGadget(struct GadgetInfo *);
270 void UnmapAllGadgets();
271 void RemapAllGadgets();
272
273 boolean anyTextInputGadgetActive();
274 boolean anyTextAreaGadgetActive();
275 boolean anySelectboxGadgetActive();
276 boolean anyScrollbarGadgetActive();
277 boolean anyTextGadgetActive();
278
279 void ClickOnGadget(struct GadgetInfo *, int);
280
281 boolean HandleGadgets(int, int, int);
282 boolean HandleGadgetsKeyInput(Key);
283
284 #endif  /* GADGETS_H */