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