rnd-20031130-1-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      150     /* delay between gadget actions */
21
22 /* gadget types */
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_TEXT_INPUT_ALPHANUMERIC (1 << 5)
29 #define GD_TYPE_TEXT_INPUT_NUMERIC      (1 << 6)
30 #define GD_TYPE_TEXT_AREA               (1 << 7)
31 #define GD_TYPE_SELECTBOX               (1 << 8)
32 #define GD_TYPE_SCROLLBAR_VERTICAL      (1 << 9)
33 #define GD_TYPE_SCROLLBAR_HORIZONTAL    (1 << 10)
34
35 #define GD_TYPE_BUTTON                  (GD_TYPE_NORMAL_BUTTON | \
36                                          GD_TYPE_TEXT_BUTTON | \
37                                          GD_TYPE_CHECK_BUTTON | \
38                                          GD_TYPE_RADIO_BUTTON)
39 #define GD_TYPE_SCROLLBAR               (GD_TYPE_SCROLLBAR_VERTICAL | \
40                                          GD_TYPE_SCROLLBAR_HORIZONTAL)
41 #define GD_TYPE_TEXT_INPUT              (GD_TYPE_TEXT_INPUT_ALPHANUMERIC | \
42                                          GD_TYPE_TEXT_INPUT_NUMERIC)
43
44 /* gadget events */
45 #define GD_EVENT_PRESSED                (1 << 0)
46 #define GD_EVENT_RELEASED               (1 << 1)
47 #define GD_EVENT_MOVING                 (1 << 2)
48 #define GD_EVENT_REPEATED               (1 << 3)
49 #define GD_EVENT_OFF_BORDERS            (1 << 4)
50 #define GD_EVENT_TEXT_RETURN            (1 << 5)
51 #define GD_EVENT_TEXT_LEAVING           (1 << 6)
52 #define GD_EVENT_INFO_ENTERING          (1 << 7)
53 #define GD_EVENT_INFO_LEAVING           (1 << 8)
54
55 /* gadget button states */
56 #define GD_BUTTON_UNPRESSED             0
57 #define GD_BUTTON_PRESSED               1
58
59 /* gadget structure constants */
60 #define MAX_GADGET_TEXTSIZE             1024
61 #define MAX_INFO_TEXTSIZE               1024
62
63 /* gadget creation tags */
64 #define GDI_END                         0
65 #define GDI_CUSTOM_ID                   1
66 #define GDI_CUSTOM_TYPE_ID              2
67 #define GDI_X                           3
68 #define GDI_Y                           4
69 #define GDI_WIDTH                       5
70 #define GDI_HEIGHT                      6
71 #define GDI_TYPE                        7
72 #define GDI_STATE                       8
73 #define GDI_CHECKED                     9
74 #define GDI_RADIO_NR                    10
75 #define GDI_NUMBER_VALUE                11
76 #define GDI_NUMBER_MIN                  12
77 #define GDI_NUMBER_MAX                  13
78 #define GDI_TEXT_VALUE                  14
79 #define GDI_TEXT_SIZE                   15
80 #define GDI_TEXT_FONT                   16
81 #define GDI_TEXT_FONT_ACTIVE            17
82 #define GDI_SELECTBOX_OPTIONS           18
83 #define GDI_SELECTBOX_INDEX             19
84 #define GDI_DESIGN_UNPRESSED            20
85 #define GDI_DESIGN_PRESSED              21
86 #define GDI_ALT_DESIGN_UNPRESSED        22
87 #define GDI_ALT_DESIGN_PRESSED          23
88 #define GDI_BORDER_SIZE                 24
89 #define GDI_BORDER_SIZE_SELECTBUTTON    25
90 #define GDI_DESIGN_WIDTH                26
91 #define GDI_DECORATION_DESIGN           27
92 #define GDI_DECORATION_POSITION         28
93 #define GDI_DECORATION_SIZE             29
94 #define GDI_DECORATION_SHIFTING         30
95 #define GDI_EVENT_MASK                  31
96 #define GDI_EVENT                       32
97 #define GDI_CALLBACK_INFO               33
98 #define GDI_CALLBACK_ACTION             34
99 #define GDI_AREA_SIZE                   35
100 #define GDI_ITEM_SIZE                   36
101 #define GDI_SCROLLBAR_ITEMS_MAX         37
102 #define GDI_SCROLLBAR_ITEMS_VISIBLE     38
103 #define GDI_SCROLLBAR_ITEM_POSITION     39
104 #define GDI_INFO_TEXT                   40
105 #define GDI_ACTIVE                      41
106 #define GDI_DIRECT_DRAW                 42
107
108 typedef void (*gadget_function)(void *);
109
110 struct GadgetBorder
111 {
112   int xsize, ysize;                     /* size of gadget border */
113   int xsize_selectbutton;               /* for selectbox gadgets */
114   int width;                            /* for selectbox/text input gadgets */
115 };
116
117 struct GadgetDesign
118 {
119   Bitmap *bitmap;                       /* Bitmap with gadget surface */
120   int x, y;                             /* position of rectangle in Bitmap */
121 };
122
123 struct GadgetDecoration
124 {
125   struct GadgetDesign design;           /* decoration design structure */
126   int x, y;                             /* position of deco on the gadget */
127   int width, height;                    /* width and height of decoration */
128   int xshift, yshift;                   /* deco shifting when gadget pressed */
129 };
130
131 struct GadgetEvent
132 {
133   unsigned long type;                   /* event type */
134   int button;                           /* button number for button events */
135   int x, y;                             /* gadget position at event time */
136   boolean off_borders;                  /* mouse pointer outside gadget? */
137   int item_x, item_y, item_position;    /* new item position */
138 };
139
140 struct GadgetDrawingArea
141 {
142   int area_xsize, area_ysize;           /* size of drawing area (in items) */
143   int item_xsize, item_ysize;           /* size of each item in drawing area */
144 };
145
146 struct GadgetTextButton
147 {
148   char value[MAX_GADGET_TEXTSIZE];      /* text written on the button */
149   int size;                             /* maximal size of button text */
150 };
151
152 struct GadgetTextInput
153 {
154   char value[MAX_GADGET_TEXTSIZE];      /* text string in input field */
155   int cursor_position;                  /* actual text cursor position */
156   int number_value;                     /* integer value, if numeric */
157   int number_min;                       /* minimal allowed numeric value */
158   int number_max;                       /* maximal allowed numeric value */
159   int size;                             /* maximal size of input text */
160 };
161
162 struct GadgetTextArea
163 {
164   char value[MAX_GADGET_TEXTSIZE];      /* text string in input field */
165   int cursor_position;                  /* actual text cursor position */
166   int cursor_x;                         /* actual x cursor position */
167   int cursor_y;                         /* actual y cursor position */
168   int cursor_x_preferred;               /* "preferred" x cursor position */
169   int size;                             /* maximal size of input text */
170   int xsize, ysize;                     /* size of text area (in chars) */
171 };
172
173 struct GadgetSelectbox
174 {
175   struct ValueTextInfo *options;        /* pointer to text/value array */
176   int index;                            /* index of actual text string */
177   int size;                             /* maximal size of text strings */
178
179   /* automatically determined values */
180   int x, y;                             /* open selectbox position */
181   int width, height;                    /* open selectbox size */
182   int num_values;                       /* number of text strings */
183   Pixel inverse_color;                  /* color for highlighting */
184
185   /* runtime values */
186   boolean open;                         /* opening state of selectbox */
187   boolean stay_open;                    /* open after button release */
188   int current_index;                    /* index of text while selecting */
189 };
190
191 struct GadgetScrollbar
192 {
193   int items_max;                        /* number of items to access */
194   int items_visible;                    /* number of visible items */
195   int item_position;                    /* actual item position */
196   int size_max;                         /* this is either width or height */
197   int size;                             /* scrollbar size on screen */
198   int position;                         /* scrollbar position on screen */
199   int position_max;                     /* bottom/right scrollbar position */
200   int drag_position;                    /* drag position on scrollbar */
201   int correction;                       /* scrollbar position correction */
202 };
203
204 struct GadgetInfo
205 {
206   int id;                               /* internal gadget identifier */
207   int custom_id;                        /* custom gadget identifier */
208   int custom_type_id;                   /* custom gadget type identifier */
209   char info_text[MAX_INFO_TEXTSIZE];    /* short popup info text */
210   int x, y;                             /* gadget position */
211   int width, height;                    /* gadget size */
212   unsigned long type;                   /* type (button, text input, ...) */
213   unsigned long state;                  /* state (pressed, released, ...) */
214   boolean checked;                      /* check/radio button state */
215   int radio_nr;                         /* number of radio button series */
216   boolean mapped;                       /* gadget is mapped on the screen */
217   boolean active;                       /* gadget is active */
218   boolean direct_draw;                  /* directly draw to frontbuffer */
219   int font;                             /* font to use when inactive */
220   int font_active;                      /* font to use when active */
221   struct GadgetBorder border;           /* gadget border design */
222   struct GadgetDesign design[2];        /* 0: normal; 1: pressed */
223   struct GadgetDesign alt_design[2];    /* alternative design */
224   struct GadgetDecoration deco;         /* decoration on top of gadget */
225   unsigned long event_mask;             /* possible events for this gadget */
226   struct GadgetEvent event;             /* actual gadget event */
227   gadget_function callback_info;        /* function for pop-up info text */
228   gadget_function callback_action;      /* function for gadget action */
229   struct GadgetDrawingArea drawing;     /* fields for drawing area gadget */
230   struct GadgetTextButton textbutton;   /* fields for text button gadget */
231   struct GadgetTextInput textinput;     /* fields for text input gadget */
232   struct GadgetTextArea textarea;       /* fields for text area gadget */
233   struct GadgetSelectbox selectbox;     /* fields for selectbox gadget */
234   struct GadgetScrollbar scrollbar;     /* fields for scrollbar gadget */
235   struct GadgetInfo *next;              /* next list entry */
236 };
237
238 struct GadgetInfo *CreateGadget(int, ...);
239 void FreeGadget(struct GadgetInfo *);
240
241 void ModifyGadget(struct GadgetInfo *, int, ...);
242 void RedrawGadget(struct GadgetInfo *);
243
244 void MapGadget(struct GadgetInfo *);
245 void UnmapGadget(struct GadgetInfo *);
246 void UnmapAllGadgets();
247 void RemapAllGadgets();
248
249 boolean anyTextGadgetActive();
250 void ClickOnGadget(struct GadgetInfo *, int);
251
252 boolean HandleGadgets(int, int, int);
253 boolean HandleGadgetsKeyInput(Key);
254
255 #endif  /* GADGETS_H */