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