rnd-20001202-2-src
[rocksndiamonds.git] / src / libgame / gadgets.h
1 /***********************************************************
2 *  Rocks'n'Diamonds -- McDuffin Strikes Back!              *
3 *----------------------------------------------------------*
4 *  (c) 1995-98 Artsoft Entertainment                       *
5 *              Holger Schemel                              *
6 *              Oststrasse 11a                              *
7 *              33604 Bielefeld                             *
8 *              phone: ++49 +521 290471                     *
9 *              email: aeglos@valinor.owl.de                *
10 *----------------------------------------------------------*
11 *  gadgets.h                                               *
12 ***********************************************************/
13
14 #ifndef GADGETS_H
15 #define GADGETS_H
16
17 #include "libgame.h"
18
19 /* the following definitions are also used by tools.c */
20
21 /* some positions in the video tape control window */
22 #define VIDEO_DISPLAY1_XPOS     5
23 #define VIDEO_DISPLAY1_YPOS     5
24 #define VIDEO_DISPLAY2_XPOS     5
25 #define VIDEO_DISPLAY2_YPOS     41
26 #define VIDEO_DISPLAY_XSIZE     90
27 #define VIDEO_DISPLAY_YSIZE     31
28 #define VIDEO_BUTTON_XSIZE      18
29 #define VIDEO_BUTTON_YSIZE      18
30 #define VIDEO_CONTROL_XPOS      5
31 #define VIDEO_CONTROL_YPOS      77
32 #define VIDEO_CONTROL_XSIZE     VIDEO_DISPLAY_XSIZE
33 #define VIDEO_CONTROL_YSIZE     VIDEO_BUTTON_YSIZE
34
35 /* values for video tape control */
36 #define VIDEO_STATE_PLAY_OFF    (1L << 0)
37 #define VIDEO_STATE_PLAY_ON     (1L << 1)
38 #define VIDEO_STATE_PLAY        (VIDEO_STATE_PLAY_OFF   | VIDEO_STATE_PLAY_ON)
39 #define VIDEO_STATE_REC_OFF     (1L << 2)
40 #define VIDEO_STATE_REC_ON      (1L << 3)
41 #define VIDEO_STATE_REC         (VIDEO_STATE_REC_OFF    | VIDEO_STATE_REC_ON)
42 #define VIDEO_STATE_PAUSE_OFF   (1L << 4)
43 #define VIDEO_STATE_PAUSE_ON    (1L << 5)
44 #define VIDEO_STATE_PAUSE       (VIDEO_STATE_PAUSE_OFF  | VIDEO_STATE_PAUSE_ON)
45 #define VIDEO_STATE_DATE_OFF    (1L << 6)
46 #define VIDEO_STATE_DATE_ON     (1L << 7)
47 #define VIDEO_STATE_DATE        (VIDEO_STATE_DATE_OFF   | VIDEO_STATE_DATE_ON)
48 #define VIDEO_STATE_TIME_OFF    (1L << 8)
49 #define VIDEO_STATE_TIME_ON     (1L << 9)
50 #define VIDEO_STATE_TIME        (VIDEO_STATE_TIME_OFF   | VIDEO_STATE_TIME_ON)
51 #define VIDEO_PRESS_PLAY_ON     (1L << 10)
52 #define VIDEO_PRESS_PLAY_OFF    (1L << 11)
53 #define VIDEO_PRESS_PLAY        (VIDEO_PRESS_PLAY_OFF   | VIDEO_PRESS_PLAY_ON)
54 #define VIDEO_PRESS_REC_ON      (1L << 12)
55 #define VIDEO_PRESS_REC_OFF     (1L << 13)
56 #define VIDEO_PRESS_REC         (VIDEO_PRESS_REC_OFF    | VIDEO_PRESS_REC_ON)
57 #define VIDEO_PRESS_PAUSE_ON    (1L << 14)
58 #define VIDEO_PRESS_PAUSE_OFF   (1L << 15)
59 #define VIDEO_PRESS_PAUSE       (VIDEO_PRESS_PAUSE_OFF  | VIDEO_PRESS_PAUSE_ON)
60 #define VIDEO_PRESS_STOP_ON     (1L << 16)
61 #define VIDEO_PRESS_STOP_OFF    (1L << 17)
62 #define VIDEO_PRESS_STOP        (VIDEO_PRESS_STOP_OFF   | VIDEO_PRESS_STOP_ON)
63 #define VIDEO_PRESS_EJECT_ON    (1L << 18)
64 #define VIDEO_PRESS_EJECT_OFF   (1L << 19)
65 #define VIDEO_PRESS_EJECT       (VIDEO_PRESS_EJECT_OFF  | VIDEO_PRESS_EJECT_ON)
66
67 /* special */
68 #define VIDEO_STATE_FFWD_OFF    ((1L << 20) | VIDEO_STATE_PAUSE_OFF)
69 #define VIDEO_STATE_FFWD_ON     (1L << 21)
70 #define VIDEO_STATE_FFWD        (VIDEO_STATE_FFWD_OFF   | VIDEO_STATE_FFWD_ON)
71 #define VIDEO_STATE_PBEND_OFF   (1L << 22)
72 #define VIDEO_STATE_PBEND_ON    (1L << 23)
73 #define VIDEO_STATE_PBEND       (VIDEO_STATE_PBEND_OFF  | VIDEO_STATE_PBEND_ON)
74
75 /* tags to draw video display labels or symbols only */
76 #define VIDEO_DISPLAY_DEFAULT           0
77 #define VIDEO_DISPLAY_LABEL_ONLY        1
78 #define VIDEO_DISPLAY_SYMBOL_ONLY       2
79
80 void DrawVideoDisplay(unsigned long, unsigned long);
81 void DrawCompleteVideoDisplay(void);
82
83
84 /* NEW GADGET STUFF -------------------------------------------------------- */
85
86 /* gadget types */
87 #define GD_TYPE_NORMAL_BUTTON           (1 << 0)
88 #define GD_TYPE_CHECK_BUTTON            (1 << 1)
89 #define GD_TYPE_RADIO_BUTTON            (1 << 2)
90 #define GD_TYPE_DRAWING_AREA            (1 << 3)
91 #define GD_TYPE_TEXTINPUT_ALPHANUMERIC  (1 << 4)
92 #define GD_TYPE_TEXTINPUT_NUMERIC       (1 << 5)
93 #define GD_TYPE_SCROLLBAR_VERTICAL      (1 << 6)
94 #define GD_TYPE_SCROLLBAR_HORIZONTAL    (1 << 7)
95
96 #define GD_TYPE_BUTTON                  (GD_TYPE_NORMAL_BUTTON | \
97                                          GD_TYPE_CHECK_BUTTON | \
98                                          GD_TYPE_RADIO_BUTTON)
99 #define GD_TYPE_SCROLLBAR               (GD_TYPE_SCROLLBAR_VERTICAL | \
100                                          GD_TYPE_SCROLLBAR_HORIZONTAL)
101 #define GD_TYPE_TEXTINPUT               (GD_TYPE_TEXTINPUT_ALPHANUMERIC | \
102                                          GD_TYPE_TEXTINPUT_NUMERIC)
103
104 /* gadget events */
105 #define GD_EVENT_PRESSED                (1 << 0)
106 #define GD_EVENT_RELEASED               (1 << 1)
107 #define GD_EVENT_MOVING                 (1 << 2)
108 #define GD_EVENT_REPEATED               (1 << 3)
109 #define GD_EVENT_OFF_BORDERS            (1 << 4)
110 #define GD_EVENT_TEXT_RETURN            (1 << 5)
111 #define GD_EVENT_TEXT_LEAVING           (1 << 6)
112
113 /* gadget button states */
114 #define GD_BUTTON_UNPRESSED             0
115 #define GD_BUTTON_PRESSED               1
116
117 /* gadget structure constants */
118 #define MAX_GADGET_TEXTSIZE             1024
119 #define MAX_INFO_TEXTSIZE               1024
120
121 /* gadget creation tags */
122 #define GDI_END                         0
123 #define GDI_CUSTOM_ID                   1
124 #define GDI_CUSTOM_TYPE_ID              2
125 #define GDI_X                           3
126 #define GDI_Y                           4
127 #define GDI_WIDTH                       5
128 #define GDI_HEIGHT                      6
129 #define GDI_TYPE                        7
130 #define GDI_STATE                       8
131 #define GDI_CHECKED                     9
132 #define GDI_RADIO_NR                    10
133 #define GDI_NUMBER_VALUE                11
134 #define GDI_NUMBER_MIN                  12
135 #define GDI_NUMBER_MAX                  13
136 #define GDI_TEXT_VALUE                  14
137 #define GDI_TEXT_SIZE                   15
138 #define GDI_TEXT_FONT                   16
139 #define GDI_DESIGN_UNPRESSED            17
140 #define GDI_DESIGN_PRESSED              18
141 #define GDI_ALT_DESIGN_UNPRESSED        19
142 #define GDI_ALT_DESIGN_PRESSED          20
143 #define GDI_BORDER_SIZE                 21
144 #define GDI_TEXTINPUT_DESIGN_WIDTH      22
145 #define GDI_DECORATION_DESIGN           23
146 #define GDI_DECORATION_POSITION         24
147 #define GDI_DECORATION_SIZE             25
148 #define GDI_DECORATION_SHIFTING         26
149 #define GDI_EVENT_MASK                  27
150 #define GDI_EVENT                       28
151 #define GDI_CALLBACK_INFO               29
152 #define GDI_CALLBACK_ACTION             30
153 #define GDI_AREA_SIZE                   31
154 #define GDI_ITEM_SIZE                   32
155 #define GDI_SCROLLBAR_ITEMS_MAX         33
156 #define GDI_SCROLLBAR_ITEMS_VISIBLE     34
157 #define GDI_SCROLLBAR_ITEM_POSITION     35
158 #define GDI_INFO_TEXT                   36
159
160 typedef void (*gadget_function)(void *);
161
162 struct GadgetBorder
163 {
164   int size;                             /* size of gadget border */
165   int width;                            /* for text input gadgets */
166 };
167
168 struct GadgetDesign
169 {
170   Bitmap bitmap;                        /* Bitmap with gadget surface */
171   int x, y;                             /* position of rectangle in Bitmap */
172 };
173
174 struct GadgetDecoration
175 {
176   struct GadgetDesign design;           /* decoration design structure */
177   int x, y;                             /* position of deco on the gadget */
178   int width, height;                    /* width and height of decoration */
179   int xshift, yshift;                   /* deco shifting when gadget pressed */
180 };
181
182 struct GadgetEvent
183 {
184   unsigned long type;                   /* event type */
185   int button;                           /* button number for button events */
186   int x, y;                             /* gadget position at event time */
187   boolean off_borders;                  /* mouse pointer outside gadget? */
188   int item_x, item_y, item_position;    /* new item position */
189 };
190
191 struct GadgetDrawingArea
192 {
193   int area_xsize, area_ysize;           /* size of drawing area (in items) */
194   int item_xsize, item_ysize;           /* size of each item in drawing area */
195 };
196
197 struct GadgetTextInput
198 {
199   char value[MAX_GADGET_TEXTSIZE];      /* text string in input field */
200   int number_value;                     /* integer value, if numeric */
201   int number_min;                       /* minimal allowed numeric value */
202   int number_max;                       /* maximal allowed numeric value */
203   int size;                             /* maximal size of input text */
204   int cursor_position;                  /* actual cursor position */
205   int font_type;                        /* font to use for text input */
206 };
207
208 struct GadgetScrollbar
209 {
210   int items_max;                        /* number of items to access */
211   int items_visible;                    /* number of visible items */
212   int item_position;                    /* actual item position */
213   int size_max;                         /* this is either width or height */
214   int size;                             /* scrollbar size on screen */
215   int position;                         /* scrollbar position on screen */
216   int position_max;                     /* bottom/right scrollbar position */
217   int drag_position;                    /* drag position on scrollbar */
218   int correction;                       /* scrollbar position correction */
219 };
220
221 struct GadgetInfo
222 {
223   int id;                               /* internal gadget identifier */
224   int custom_id;                        /* custom gadget identifier */
225   int custom_type_id;                   /* custom gadget type identifier */
226   char info_text[MAX_INFO_TEXTSIZE];    /* short popup info text */
227   int x, y;                             /* gadget position */
228   int width, height;                    /* gadget size */
229   unsigned long type;                   /* type (button, text input, ...) */
230   unsigned long state;                  /* state (pressed, released, ...) */
231   boolean checked;                      /* check/radio button state */
232   int radio_nr;                         /* number of radio button series */
233   boolean mapped;                       /* gadget is active */
234   struct GadgetBorder border;           /* gadget border design */
235   struct GadgetDesign design[2];        /* 0: normal; 1: pressed */
236   struct GadgetDesign alt_design[2];    /* alternative design */
237   struct GadgetDecoration deco;         /* decoration on top of gadget */
238   unsigned long event_mask;             /* possible events for this gadget */
239   struct GadgetEvent event;             /* actual gadget event */
240   gadget_function callback_info;        /* function for pop-up info text */
241   gadget_function callback_action;      /* function for gadget action */
242   struct GadgetDrawingArea drawing;     /* fields for drawing area gadget */
243   struct GadgetTextInput text;          /* fields for text input gadget */
244   struct GadgetScrollbar scrollbar;     /* fields for scrollbar gadget */
245   struct GadgetInfo *next;              /* next list entry */
246 };
247
248 struct GadgetInfo *CreateGadget(int, ...);
249 void FreeGadget(struct GadgetInfo *);
250
251 void ModifyGadget(struct GadgetInfo *, int, ...);
252 void RedrawGadget(struct GadgetInfo *);
253
254 void MapGadget(struct GadgetInfo *);
255 void UnmapGadget(struct GadgetInfo *);
256 void UnmapAllGadgets();
257 void RemapAllGadgets();
258
259 boolean anyTextGadgetActive();
260 void ClickOnGadget(struct GadgetInfo *, int);
261
262 void HandleGadgets(int, int, int);
263 void HandleGadgetsKeyInput(Key);
264
265 #endif  /* GADGETS_H */