rnd-20041017-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   char last_value[MAX_GADGET_TEXTSIZE]; /* last text string in input field */
156   int cursor_position;                  /* actual text cursor position */
157   int number_value;                     /* integer value, if numeric */
158   int number_min;                       /* minimal allowed numeric value */
159   int number_max;                       /* maximal allowed numeric value */
160   int size;                             /* maximal size of input text */
161 };
162
163 struct GadgetTextArea
164 {
165   char value[MAX_GADGET_TEXTSIZE];      /* text string in input field */
166   char last_value[MAX_GADGET_TEXTSIZE]; /* last text string in input field */
167   int cursor_position;                  /* actual text cursor position */
168   int cursor_x;                         /* actual x cursor position */
169   int cursor_y;                         /* actual y cursor position */
170   int cursor_x_preferred;               /* "preferred" x cursor position */
171   int size;                             /* maximal size of input text */
172   int xsize, ysize;                     /* size of text area (in chars) */
173 };
174
175 struct GadgetSelectbox
176 {
177   struct ValueTextInfo *options;        /* pointer to text/value array */
178   int index;                            /* index of actual text string */
179   int size;                             /* maximal size of text strings */
180
181   /* automatically determined values */
182   int x, y;                             /* open selectbox position */
183   int width, height;                    /* open selectbox size */
184   int num_values;                       /* number of text strings */
185   Pixel inverse_color;                  /* color for highlighting */
186
187   /* runtime values */
188   boolean open;                         /* opening state of selectbox */
189   boolean stay_open;                    /* open after button release */
190   int current_index;                    /* index of text while selecting */
191 };
192
193 struct GadgetScrollbar
194 {
195   int items_max;                        /* number of items to access */
196   int items_visible;                    /* number of visible items */
197   int item_position;                    /* actual item position */
198   int size_min;                         /* minimal scrollbar size */
199   int size_max;                         /* this is either width or height */
200   int size_max_cmp;                     /* needed for minimal scrollbar size */
201   int size;                             /* scrollbar size on screen */
202   int position;                         /* scrollbar position on screen */
203   int position_max;                     /* bottom/right scrollbar position */
204   int drag_position;                    /* drag position on scrollbar */
205   int correction;                       /* scrollbar position correction */
206 };
207
208 struct GadgetInfo
209 {
210   int id;                               /* internal gadget identifier */
211   int custom_id;                        /* custom gadget identifier */
212   int custom_type_id;                   /* custom gadget type identifier */
213   char info_text[MAX_INFO_TEXTSIZE];    /* short popup info text */
214   int x, y;                             /* gadget position */
215   int width, height;                    /* gadget size */
216   unsigned long type;                   /* type (button, text input, ...) */
217   unsigned long state;                  /* state (pressed, released, ...) */
218   boolean checked;                      /* check/radio button state */
219   int radio_nr;                         /* number of radio button series */
220   boolean mapped;                       /* gadget is mapped on the screen */
221   boolean active;                       /* gadget is active */
222   boolean direct_draw;                  /* directly draw to frontbuffer */
223   int font;                             /* font to use when inactive */
224   int font_active;                      /* font to use when active */
225   struct GadgetBorder border;           /* gadget border design */
226   struct GadgetDesign design[2];        /* 0: normal; 1: pressed */
227   struct GadgetDesign alt_design[2];    /* alternative design */
228   struct GadgetDecoration deco;         /* decoration on top of gadget */
229   unsigned long event_mask;             /* possible events for this gadget */
230   struct GadgetEvent event;             /* actual gadget event */
231   gadget_function callback_info;        /* function for pop-up info text */
232   gadget_function callback_action;      /* function for gadget action */
233   struct GadgetDrawingArea drawing;     /* fields for drawing area gadget */
234   struct GadgetTextButton textbutton;   /* fields for text button gadget */
235   struct GadgetTextInput textinput;     /* fields for text input gadget */
236   struct GadgetTextArea textarea;       /* fields for text area gadget */
237   struct GadgetSelectbox selectbox;     /* fields for selectbox gadget */
238   struct GadgetScrollbar scrollbar;     /* fields for scrollbar gadget */
239   struct GadgetInfo *next;              /* next list entry */
240 };
241
242 struct GadgetInfo *CreateGadget(int, ...);
243 void FreeGadget(struct GadgetInfo *);
244
245 void ModifyGadget(struct GadgetInfo *, int, ...);
246 void RedrawGadget(struct GadgetInfo *);
247
248 void MapGadget(struct GadgetInfo *);
249 void UnmapGadget(struct GadgetInfo *);
250 void UnmapAllGadgets();
251 void RemapAllGadgets();
252
253 boolean anyTextGadgetActive();
254
255 void ClickOnGadget(struct GadgetInfo *, int);
256
257 boolean HandleGadgets(int, int, int);
258 boolean HandleGadgetsKeyInput(Key);
259
260 #endif  /* GADGETS_H */