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