rnd-19990108-1
[rocksndiamonds.git] / src / buttons.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 *  buttons.h                                               *
12 ***********************************************************/
13
14 #ifndef BUTTONS_H
15 #define BUTTONS_H
16
17 #include "main.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 requests */
36 #define BUTTON_OK               (1L<<0)
37 #define BUTTON_NO               (1L<<1)
38 #define BUTTON_CONFIRM          (1L<<2)
39
40 /* values for choosing network player */
41 #define BUTTON_PLAYER_1         (1L<<10)
42 #define BUTTON_PLAYER_2         (1L<<11)
43 #define BUTTON_PLAYER_3         (1L<<12)
44 #define BUTTON_PLAYER_4         (1L<<13)
45
46 /* for DrawPlayerButton() */
47 #define DB_INIT                 0
48 #define DB_NORMAL               1
49
50 /* the following definitions are also used by screens.c */
51
52 /* buttons of the video tape player */
53 #define BUTTON_VIDEO_EJECT      1
54 #define BUTTON_VIDEO_STOP       2
55 #define BUTTON_VIDEO_PAUSE      3
56 #define BUTTON_VIDEO_REC        4
57 #define BUTTON_VIDEO_PLAY       5
58
59 /* values for video tape control */
60 #define VIDEO_STATE_PLAY_OFF    (1L<<0)
61 #define VIDEO_STATE_PLAY_ON     (1L<<1)
62 #define VIDEO_STATE_PLAY        (VIDEO_STATE_PLAY_OFF   | VIDEO_STATE_PLAY_ON)
63 #define VIDEO_STATE_REC_OFF     (1L<<2)
64 #define VIDEO_STATE_REC_ON      (1L<<3)
65 #define VIDEO_STATE_REC         (VIDEO_STATE_REC_OFF    | VIDEO_STATE_REC_ON)
66 #define VIDEO_STATE_PAUSE_OFF   (1L<<4)
67 #define VIDEO_STATE_PAUSE_ON    (1L<<5)
68 #define VIDEO_STATE_PAUSE       (VIDEO_STATE_PAUSE_OFF  | VIDEO_STATE_PAUSE_ON)
69 #define VIDEO_STATE_DATE_OFF    (1L<<6)
70 #define VIDEO_STATE_DATE_ON     (1L<<7)
71 #define VIDEO_STATE_DATE        (VIDEO_STATE_DATE_OFF   | VIDEO_STATE_DATE_ON)
72 #define VIDEO_STATE_TIME_OFF    (1L<<8)
73 #define VIDEO_STATE_TIME_ON     (1L<<9)
74 #define VIDEO_STATE_TIME        (VIDEO_STATE_TIME_OFF   | VIDEO_STATE_TIME_ON)
75 #define VIDEO_PRESS_PLAY_ON     (1L<<10)
76 #define VIDEO_PRESS_PLAY_OFF    (1L<<11)
77 #define VIDEO_PRESS_PLAY        (VIDEO_PRESS_PLAY_OFF   | VIDEO_PRESS_PLAY_ON)
78 #define VIDEO_PRESS_REC_ON      (1L<<12)
79 #define VIDEO_PRESS_REC_OFF     (1L<<13)
80 #define VIDEO_PRESS_REC         (VIDEO_PRESS_REC_OFF    | VIDEO_PRESS_REC_ON)
81 #define VIDEO_PRESS_PAUSE_ON    (1L<<14)
82 #define VIDEO_PRESS_PAUSE_OFF   (1L<<15)
83 #define VIDEO_PRESS_PAUSE       (VIDEO_PRESS_PAUSE_OFF  | VIDEO_PRESS_PAUSE_ON)
84 #define VIDEO_PRESS_STOP_ON     (1L<<16)
85 #define VIDEO_PRESS_STOP_OFF    (1L<<17)
86 #define VIDEO_PRESS_STOP        (VIDEO_PRESS_STOP_OFF   | VIDEO_PRESS_STOP_ON)
87 #define VIDEO_PRESS_EJECT_ON    (1L<<18)
88 #define VIDEO_PRESS_EJECT_OFF   (1L<<19)
89 #define VIDEO_PRESS_EJECT       (VIDEO_PRESS_EJECT_OFF  | VIDEO_PRESS_EJECT_ON)
90
91 /* special */
92 #define VIDEO_STATE_FFWD_OFF    ((1L<<20) | VIDEO_STATE_PAUSE_OFF)
93 #define VIDEO_STATE_FFWD_ON     (1L<<21)
94 #define VIDEO_STATE_FFWD        (VIDEO_STATE_FFWD_OFF   | VIDEO_STATE_FFWD_ON)
95 #define VIDEO_STATE_PBEND_OFF   (1L<<22)
96 #define VIDEO_STATE_PBEND_ON    (1L<<23)
97 #define VIDEO_STATE_PBEND       (VIDEO_STATE_PBEND_OFF  | VIDEO_STATE_PBEND_ON)
98
99 /* tags to draw video display labels or symbols only */
100 #define VIDEO_DISPLAY_DEFAULT           0
101 #define VIDEO_DISPLAY_LABEL_ONLY        1
102 #define VIDEO_DISPLAY_SYMBOL_ONLY       2
103
104 /* values for sound control */
105 #define BUTTON_SOUND_MUSIC      (1L<<0)
106 #define BUTTON_SOUND_LOOPS      (1L<<1)
107 #define BUTTON_SOUND_SIMPLE     (1L<<2)
108 #define BUTTON_RELEASED         0
109 #define BUTTON_PRESSED          (1L<<3)
110 #define BUTTON_OFF              0
111 #define BUTTON_ON               (1L<<4)
112 #define BUTTON_SOUND_MUSIC_OFF  (BUTTON_SOUND_MUSIC  | BUTTON_OFF)
113 #define BUTTON_SOUND_LOOPS_OFF  (BUTTON_SOUND_LOOPS  | BUTTON_OFF)
114 #define BUTTON_SOUND_SIMPLE_OFF (BUTTON_SOUND_SIMPLE | BUTTON_OFF)
115 #define BUTTON_SOUND_MUSIC_ON   (BUTTON_SOUND_MUSIC  | BUTTON_ON)
116 #define BUTTON_SOUND_LOOPS_ON   (BUTTON_SOUND_LOOPS  | BUTTON_ON)
117 #define BUTTON_SOUND_SIMPLE_ON  (BUTTON_SOUND_SIMPLE | BUTTON_ON)
118
119 /* values for game control */
120 #define BUTTON_GAME_STOP        (1L<<0)
121 #define BUTTON_GAME_PAUSE       (1L<<1)
122 #define BUTTON_GAME_PLAY        (1L<<2)
123
124 /* the following definitions are also used by game.c */
125
126 /* some positions in the game control window */
127 #define GAME_BUTTON_XSIZE       30
128 #define GAME_BUTTON_YSIZE       30
129 #define GAME_CONTROL_XPOS       5
130 #define GAME_CONTROL_YPOS       215
131 #define GAME_CONTROL_XSIZE      (3*GAME_BUTTON_XSIZE)
132 #define GAME_CONTROL_YSIZE      (1*GAME_BUTTON_YSIZE)
133
134 /* the following definitions are also used by editor.c */
135
136 /* some positions in the editor control window */
137 #define ED_BUTTON_EUP_XPOS      35
138 #define ED_BUTTON_EUP_YPOS      5
139 #define ED_BUTTON_EUP_XSIZE     30
140 #define ED_BUTTON_EUP_YSIZE     25
141 #define ED_BUTTON_EDOWN_XPOS    35
142 #define ED_BUTTON_EDOWN_YPOS    250
143 #define ED_BUTTON_EDOWN_XSIZE   30
144 #define ED_BUTTON_EDOWN_YSIZE   25
145 #define ED_BUTTON_ELEM_XPOS     6
146 #define ED_BUTTON_ELEM_YPOS     30
147 #define ED_BUTTON_ELEM_XSIZE    22
148 #define ED_BUTTON_ELEM_YSIZE    22
149
150 #define ED_BUTTON_EUP_Y2POS     140
151 #define ED_BUTTON_EDOWN_Y2POS   165
152 #define ED_BUTTON_ELEM_Y2POS    190
153
154 #define ED_SCROLLBUTTON_XSIZE   30
155 #define ED_SCROLLBUTTON_YSIZE   20
156
157 #define ED_BUTTON_CTRL_XPOS     5
158 #define ED_BUTTON_CTRL_YPOS     5
159 #define ED_BUTTON_CTRL_XSIZE    90
160 #define ED_BUTTON_CTRL_YSIZE    30
161 #define ED_BUTTON_FILL_XPOS     5
162 #define ED_BUTTON_FILL_YPOS     35
163 #define ED_BUTTON_FILL_XSIZE    90
164 #define ED_BUTTON_FILL_YSIZE    20
165 #define ED_BUTTON_LEFT_XPOS     5
166 #define ED_BUTTON_LEFT_YPOS     65
167 #define ED_BUTTON_LEFT_XSIZE    ED_SCROLLBUTTON_XSIZE
168 #define ED_BUTTON_LEFT_YSIZE    ED_SCROLLBUTTON_YSIZE
169 #define ED_BUTTON_UP_XPOS       35
170 #define ED_BUTTON_UP_YPOS       55
171 #define ED_BUTTON_UP_XSIZE      ED_SCROLLBUTTON_XSIZE
172 #define ED_BUTTON_UP_YSIZE      ED_SCROLLBUTTON_YSIZE
173 #define ED_BUTTON_DOWN_XPOS     35
174 #define ED_BUTTON_DOWN_YPOS     75
175 #define ED_BUTTON_DOWN_XSIZE    ED_SCROLLBUTTON_XSIZE
176 #define ED_BUTTON_DOWN_YSIZE    ED_SCROLLBUTTON_YSIZE
177 #define ED_BUTTON_RIGHT_XPOS    65
178 #define ED_BUTTON_RIGHT_YPOS    65
179 #define ED_BUTTON_RIGHT_XSIZE   ED_SCROLLBUTTON_XSIZE
180 #define ED_BUTTON_RIGHT_YSIZE   ED_SCROLLBUTTON_YSIZE
181
182 #define ED_BUTTON_EDIT_XPOS     5
183 #define ED_BUTTON_EDIT_YPOS     5
184 #define ED_BUTTON_EDIT_XSIZE    90
185 #define ED_BUTTON_EDIT_YSIZE    30
186 #define ED_BUTTON_CLEAR_XPOS    5
187 #define ED_BUTTON_CLEAR_YPOS    35
188 #define ED_BUTTON_CLEAR_XSIZE   90
189 #define ED_BUTTON_CLEAR_YSIZE   20
190 #define ED_BUTTON_UNDO_XPOS     5
191 #define ED_BUTTON_UNDO_YPOS     55
192 #define ED_BUTTON_UNDO_XSIZE    90
193 #define ED_BUTTON_UNDO_YSIZE    20
194 #define ED_BUTTON_EXIT_XPOS     5
195 #define ED_BUTTON_EXIT_YPOS     75
196 #define ED_BUTTON_EXIT_XSIZE    90
197 #define ED_BUTTON_EXIT_YSIZE    20
198
199 #define ED_BUTTON_COUNT_YPOS    60
200 #define ED_BUTTON_COUNT_XSIZE   20
201 #define ED_BUTTON_COUNT_YSIZE   20
202 #define ED_BUTTON_MINUS_XPOS    2
203 #define ED_BUTTON_MINUS_YPOS    ED_BUTTON_COUNT_YPOS
204 #define ED_BUTTON_MINUS_XSIZE   ED_BUTTON_COUNT_XSIZE
205 #define ED_BUTTON_MINUS_YSIZE   ED_BUTTON_COUNT_YSIZE
206 #define ED_WIN_COUNT_XPOS       (ED_BUTTON_MINUS_XPOS+ED_BUTTON_MINUS_XSIZE+2)
207 #define ED_WIN_COUNT_YPOS       ED_BUTTON_COUNT_YPOS
208 #define ED_WIN_COUNT_XSIZE      52
209 #define ED_WIN_COUNT_YSIZE      ED_BUTTON_COUNT_YSIZE
210 #define ED_BUTTON_PLUS_XPOS     (ED_WIN_COUNT_XPOS+ED_WIN_COUNT_XSIZE+2)
211 #define ED_BUTTON_PLUS_YPOS     ED_BUTTON_COUNT_YPOS
212 #define ED_BUTTON_PLUS_XSIZE    ED_BUTTON_COUNT_XSIZE
213 #define ED_BUTTON_PLUS_YSIZE    ED_BUTTON_COUNT_YSIZE
214
215 #define ED_COUNT_GADGET_XPOS    16
216 #define ED_COUNT_GADGET_YPOS    (16+3*MINI_TILEY+64)
217 #define ED_COUNT_GADGET_YSIZE   (ED_BUTTON_MINUS_YSIZE+4)
218 #define ED_COUNT_TEXT_XPOS      (ED_COUNT_GADGET_XPOS+DXSIZE+10)
219 #define ED_COUNT_TEXT_YPOS      (ED_COUNT_GADGET_YPOS+3)
220 #define ED_COUNT_TEXT_YSIZE     ED_COUNT_GADGET_YSIZE
221 #define ED_COUNT_VALUE_XPOS     (ED_COUNT_GADGET_XPOS+ED_BUTTON_MINUS_XSIZE+7)
222 #define ED_COUNT_VALUE_YPOS     ED_COUNT_TEXT_YPOS
223 #define ED_SIZE_GADGET_XPOS     (SX+21*MINI_TILEX)
224 #define ED_SIZE_GADGET_YPOS     (SY+4*MINI_TILEY)
225 #define ED_SIZE_GADGET_YSIZE    (ED_BUTTON_MINUS_YSIZE+4)
226 #define ED_SIZE_TEXT_XPOS       (ED_SIZE_GADGET_XPOS+DXSIZE+10)
227 #define ED_SIZE_TEXT_YPOS       (ED_SIZE_GADGET_YPOS+3)
228 #define ED_SIZE_TEXT_YSIZE      ED_COUNT_GADGET_YSIZE
229 #define ED_SIZE_VALUE_XPOS      (ED_SIZE_GADGET_XPOS+ED_BUTTON_MINUS_XSIZE+7)
230 #define ED_SIZE_VALUE_YPOS      ED_SIZE_TEXT_YPOS
231
232 /* values for asking control */
233 #define ED_BUTTON_CTRL          (1L<<0)
234 #define ED_BUTTON_FILL          (1L<<1)
235 #define ED_BUTTON_LEFT          (1L<<2)
236 #define ED_BUTTON_UP            (1L<<3)
237 #define ED_BUTTON_DOWN          (1L<<4)
238 #define ED_BUTTON_RIGHT         (1L<<5)
239 #define ED_BUTTON_EDIT          (1L<<6)
240 #define ED_BUTTON_CLEAR         (1L<<7)
241 #define ED_BUTTON_UNDO          (1L<<8)
242 #define ED_BUTTON_EXIT          (1L<<9)
243
244 #define ED_BUTTON_PRESSED       (1L<<10)
245 #define ED_BUTTON_RELEASED      (1L<<11)
246
247 #define ED_BUTTON_EUP           0
248 #define ED_BUTTON_EDOWN         1
249 #define ED_BUTTON_ELEM          2
250
251 void DrawVideoDisplay(unsigned long, unsigned long);
252 void DrawCompleteVideoDisplay(void);
253 void DrawSoundDisplay(unsigned long);
254 void DrawGameButton(unsigned long);
255 void DrawYesNoButton(unsigned long, int);
256 void DrawConfirmButton(unsigned long, int);
257 void DrawPlayerButton(unsigned long, int);
258 void DrawEditButton(unsigned long state);
259 void DrawCtrlButton(unsigned long state);
260 void DrawElemButton(int, int);
261 void DrawCountButton(int, int);
262 int CheckVideoButtons(int, int, int);
263 int CheckSoundButtons(int, int, int);
264 int CheckGameButtons(int, int, int);
265 int CheckYesNoButtons(int, int, int);
266 int CheckConfirmButton(int, int, int);
267 int CheckPlayerButtons(int, int, int);
268 int CheckEditButtons(int, int, int);
269 int CheckCtrlButtons(int, int, int);
270 int CheckElemButtons(int, int, int);
271 int CheckCountButtons(int, int, int);
272
273
274 /* NEW GADGET STUFF -------------------------------------------------------- */
275
276
277 /* gadget types */
278 #define GD_TYPE_NORMAL_BUTTON           (1<<0)
279 #define GD_TYPE_RADIO_BUTTON            (1<<1)
280 #define GD_TYPE_DRAWING_AREA            (1<<2)
281 #define GD_TYPE_TEXTINPUT               (1<<3)
282 #define GD_TYPE_TEXTOUTPUT              (1<<4)
283 #define GD_TYPE_NUMBERINPUT             (1<<5)
284 #define GD_TYPE_NUMBEROUTPUT            (1<<6)
285 #define GD_TYPE_SCROLLBAR_VERTICAL      (1<<7)
286 #define GD_TYPE_SCROLLBAR_HORIZONTAL    (1<<8)
287
288 /* gadget events */
289 #define GD_EVENT_PRESSED                (1<<0)
290 #define GD_EVENT_RELEASED               (1<<1)
291 #define GD_EVENT_MOVING                 (1<<2)
292 #define GD_EVENT_REPEATED               (1<<3)
293 #define GD_EVENT_OFF_BORDERS            (1<<4)
294 #define GD_EVENT_TEXT_RETURN            (1<<5)
295 #define GD_EVENT_TEXT_LEAVING           (1<<6)
296
297 /* gadget button states */
298 #define GD_BUTTON_UNPRESSED             0
299 #define GD_BUTTON_PRESSED               1
300
301 /* gadget structure constants */
302 #define MAX_GADGET_TEXTSIZE             1024
303
304 /* gadget creation tags */
305 #define GDI_END                         0
306 #define GDI_CUSTOM_ID                   1
307 #define GDI_X                           2
308 #define GDI_Y                           3
309 #define GDI_WIDTH                       4
310 #define GDI_HEIGHT                      5
311 #define GDI_TYPE                        6
312 #define GDI_STATE                       7
313 #define GDI_RADIO_NR                    8
314 #define GDI_RADIO_PRESSED               9
315 #define GDI_NUMBER_VALUE                10
316 #define GDI_NUMBER_MIN                  11
317 #define GDI_NUMBER_MAX                  12
318 #define GDI_TEXT_VALUE                  13
319 #define GDI_TEXT_SIZE                   14
320 #define GDI_TEXT_BORDER                 15
321 #define GDI_DESIGN_UNPRESSED            16
322 #define GDI_DESIGN_PRESSED              17
323 #define GDI_ALT_DESIGN_UNPRESSED        18
324 #define GDI_ALT_DESIGN_PRESSED          19
325 #define GDI_EVENT_MASK                  20
326 #define GDI_EVENT                       21
327 #define GDI_CALLBACK                    22
328 #define GDI_AREA_SIZE                   23
329 #define GDI_ITEM_SIZE                   24
330
331 typedef void (*gadget_callback_function)(void *);
332
333 struct GadgetDesign
334 {
335   Pixmap pixmap;                        /* Pixmap with gadget surface */
336   int x, y;                             /* position of rectangle in Pixmap */
337 };
338
339 struct GadgetEvent
340 {
341   unsigned long type;                   /* event type */
342   int button;                           /* button number for button events */
343   int x, y;                             /* gadget position at event time */
344   boolean off_borders;                  /* mouse pointer outside gadget? */
345 };
346
347 struct GadgetDrawingArea
348 {
349   int area_xsize, area_ysize;           /* size of drawing area (in items) */
350   int item_xsize, item_ysize;           /* size of each item in drawing area */
351 };
352
353 struct GadgetInfo
354 {
355   int id;                               /* internal gadget identifier */
356   int custom_id;                        /* custom gadget identifier */
357   int x, y;                             /* gadget position */
358   int width, height;                    /* gadget size */
359   unsigned long type;                   /* type (button, text input, ...) */
360   unsigned long state;                  /* state (pressed, released, ...) */
361   int radio_nr;                         /* number of radio button series */
362   boolean radio_pressed;                /* radio button state */
363   boolean mapped;                       /* gadget is active */
364   long number_value;
365   char text_value[MAX_GADGET_TEXTSIZE];
366   int text_size;                        /* maximal size of input text */
367   int text_border;                      /* border size of text input gadget */
368   struct GadgetDesign design[2];        /* 0: normal; 1: pressed */
369   struct GadgetDesign alt_design[2];    /* alternative design */
370   unsigned long event_mask;             /* possible events for this gadget */
371   struct GadgetEvent event;             /* actual gadget event */
372   gadget_callback_function callback;
373   struct GadgetDrawingArea drawing;     /* fields for drawing area gadget */
374   struct GadgetInfo *next;              /* next list entry */
375 };
376
377 struct GadgetInfo *CreateGadget(int, ...);
378 void FreeGadget(struct GadgetInfo *);
379
380 void ClickOnGadget(struct GadgetInfo *);
381
382 void MapGadget(struct GadgetInfo *);
383 void UnmapGadget(struct GadgetInfo *);
384
385 void HandleGadgets(int, int, int);
386 void HandleGadgetsKeyInput(KeySym);
387
388 #endif