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