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