rnd-19981005-1
[rocksndiamonds.git] / src / buttons.c
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.c                                               *
12 ***********************************************************/
13
14 #include "buttons.h"
15 #include "tools.h"
16 #include "misc.h"
17 #include "editor.h"
18 #include "tape.h"
19
20 /****************************************************************/
21 /********** drawing buttons and corresponding displays **********/
22 /****************************************************************/
23
24 void DrawVideoDisplay(unsigned long state, unsigned long value)
25 {
26   int i;
27   int part_label = 0, part_symbol = 1;
28   int xpos = 0, ypos = 1, xsize = 2, ysize = 3;
29   static char *monatsname[12] =
30   {
31     "JAN", "FEB", "MAR", "APR", "MAY", "JUN",
32     "JUL", "AUG", "SEP", "OCT", "NOV", "DEC"
33   };
34   static int video_pos[10][2][4] =
35   {
36     {{ VIDEO_PLAY_LABEL_XPOS, VIDEO_PLAY_LABEL_YPOS,
37        VIDEO_PLAY_LABEL_XSIZE,VIDEO_PLAY_LABEL_YSIZE },
38      { VIDEO_PLAY_SYMBOL_XPOS, VIDEO_PLAY_SYMBOL_YPOS,
39        VIDEO_PLAY_SYMBOL_XSIZE,VIDEO_PLAY_SYMBOL_YSIZE }},
40
41     {{ VIDEO_REC_LABEL_XPOS, VIDEO_REC_LABEL_YPOS,
42        VIDEO_REC_LABEL_XSIZE,VIDEO_REC_LABEL_YSIZE },
43      { VIDEO_REC_SYMBOL_XPOS, VIDEO_REC_SYMBOL_YPOS,
44        VIDEO_REC_SYMBOL_XSIZE,VIDEO_REC_SYMBOL_YSIZE }},
45
46     {{ VIDEO_PAUSE_LABEL_XPOS, VIDEO_PAUSE_LABEL_YPOS,
47        VIDEO_PAUSE_LABEL_XSIZE,VIDEO_PAUSE_LABEL_YSIZE },
48      { VIDEO_PAUSE_SYMBOL_XPOS, VIDEO_PAUSE_SYMBOL_YPOS,
49        VIDEO_PAUSE_SYMBOL_XSIZE,VIDEO_PAUSE_SYMBOL_YSIZE }},
50
51     {{ VIDEO_DATE_LABEL_XPOS, VIDEO_DATE_LABEL_YPOS,
52        VIDEO_DATE_LABEL_XSIZE,VIDEO_DATE_LABEL_YSIZE },
53      { VIDEO_DATE_XPOS, VIDEO_DATE_YPOS,
54        VIDEO_DATE_XSIZE,VIDEO_DATE_YSIZE }},
55
56     {{ 0,0,
57        0,0 },
58      { VIDEO_TIME_XPOS, VIDEO_TIME_YPOS,
59        VIDEO_TIME_XSIZE,VIDEO_TIME_YSIZE }},
60
61     {{ VIDEO_BUTTON_PLAY_XPOS, VIDEO_BUTTON_ANY_YPOS,
62        VIDEO_BUTTON_XSIZE,VIDEO_BUTTON_YSIZE },
63      { 0,0,
64        0,0 }},
65
66     {{ VIDEO_BUTTON_REC_XPOS, VIDEO_BUTTON_ANY_YPOS,
67        VIDEO_BUTTON_XSIZE,VIDEO_BUTTON_YSIZE },
68      { 0,0,
69        0,0 }},
70
71     {{ VIDEO_BUTTON_PAUSE_XPOS, VIDEO_BUTTON_ANY_YPOS,
72        VIDEO_BUTTON_XSIZE,VIDEO_BUTTON_YSIZE },
73      { 0,0,
74        0,0 }},
75
76     {{ VIDEO_BUTTON_STOP_XPOS, VIDEO_BUTTON_ANY_YPOS,
77        VIDEO_BUTTON_XSIZE,VIDEO_BUTTON_YSIZE },
78      { 0,0,
79        0,0 }},
80
81     {{ VIDEO_BUTTON_EJECT_XPOS, VIDEO_BUTTON_ANY_YPOS,
82        VIDEO_BUTTON_XSIZE,VIDEO_BUTTON_YSIZE },
83      { 0,0,
84        0,0 }}
85   };
86
87   for(i=0;i<20;i++)
88   {
89     if (state & (1<<i))
90     {
91       int pos = i/2, cx, cy = DOOR_GFX_PAGEY2;
92
93       if (i%2)                  /* i ungerade => STATE_ON / PRESS_OFF */
94         cx = DOOR_GFX_PAGEX4;
95       else
96         cx = DOOR_GFX_PAGEX3;   /* i gerade => STATE_OFF / PRESS_ON */
97
98       if (video_pos[pos][part_label][0] && value != VIDEO_DISPLAY_SYMBOL_ONLY)
99         XCopyArea(display,pix[PIX_DOOR],drawto,gc,
100                   cx + video_pos[pos][part_label][xpos],
101                   cy + video_pos[pos][part_label][ypos],
102                   video_pos[pos][part_label][xsize],
103                   video_pos[pos][part_label][ysize],
104                   VX + video_pos[pos][part_label][xpos],
105                   VY + video_pos[pos][part_label][ypos]);
106       if (video_pos[pos][part_symbol][0] && value != VIDEO_DISPLAY_LABEL_ONLY)
107         XCopyArea(display,pix[PIX_DOOR],drawto,gc,
108                   cx + video_pos[pos][part_symbol][xpos],
109                   cy + video_pos[pos][part_symbol][ypos],
110                   video_pos[pos][part_symbol][xsize],
111                   video_pos[pos][part_symbol][ysize],
112                   VX + video_pos[pos][part_symbol][xpos],
113                   VY + video_pos[pos][part_symbol][ypos]);
114     }
115   }
116
117   if (state & VIDEO_STATE_FFWD_ON)
118   {
119     int cx = DOOR_GFX_PAGEX4, cy = DOOR_GFX_PAGEY2;
120
121     XCopyArea(display,pix[PIX_DOOR],drawto,gc,
122               cx + VIDEO_PLAY_SYMBOL_XPOS,
123               cy + VIDEO_PLAY_SYMBOL_YPOS,
124               VIDEO_PLAY_SYMBOL_XSIZE - 2,
125               VIDEO_PLAY_SYMBOL_YSIZE,
126               VX + VIDEO_PLAY_SYMBOL_XPOS - 9,
127               VY + VIDEO_PLAY_SYMBOL_YPOS);
128   }
129
130   if (state & VIDEO_STATE_DATE_ON)
131   {
132     int tag = value % 100;
133     int monat = (value/100) % 100;
134     int jahr = (value/10000);
135
136     DrawText(VX+VIDEO_DATE_XPOS,VY+VIDEO_DATE_YPOS,
137              int2str(tag,2),FS_SMALL,FC_SPECIAL1);
138     DrawText(VX+VIDEO_DATE_XPOS+27,VY+VIDEO_DATE_YPOS,
139              monatsname[monat],FS_SMALL,FC_SPECIAL1);
140     DrawText(VX+VIDEO_DATE_XPOS+64,VY+VIDEO_DATE_YPOS,
141              int2str(jahr,2),FS_SMALL,FC_SPECIAL1);
142   }
143
144   if (state & VIDEO_STATE_TIME_ON)
145   {
146     int min = value / 60;
147     int sec = value % 60;
148
149     DrawText(VX+VIDEO_TIME_XPOS,VY+VIDEO_TIME_YPOS,
150              int2str(min,2),FS_SMALL,FC_SPECIAL1);
151     DrawText(VX+VIDEO_TIME_XPOS+27,VY+VIDEO_TIME_YPOS,
152              int2str(sec,2),FS_SMALL,FC_SPECIAL1);
153   }
154
155   if (state & VIDEO_STATE_DATE)
156     redraw_mask |= REDRAW_VIDEO_1;
157   if ((state & ~VIDEO_STATE_DATE) & VIDEO_STATE)
158     redraw_mask |= REDRAW_VIDEO_2;
159   if (state & VIDEO_PRESS)
160     redraw_mask |= REDRAW_VIDEO_3;
161 }
162
163 void DrawCompleteVideoDisplay()
164 {
165   XCopyArea(display,pix[PIX_DOOR],drawto,gc,
166             DOOR_GFX_PAGEX3,DOOR_GFX_PAGEY2, VXSIZE,VYSIZE, VX,VY);
167   XCopyArea(display,pix[PIX_DOOR],drawto,gc,
168             DOOR_GFX_PAGEX4+VIDEO_CONTROL_XPOS,
169             DOOR_GFX_PAGEY2+VIDEO_CONTROL_YPOS,
170             VIDEO_CONTROL_XSIZE,VIDEO_CONTROL_YSIZE,
171             VX+VIDEO_CONTROL_XPOS,VY+VIDEO_CONTROL_YPOS);
172
173   DrawVideoDisplay(VIDEO_ALL_OFF,0);
174   if (tape.date && tape.length)
175   {
176     DrawVideoDisplay(VIDEO_STATE_DATE_ON,tape.date);
177     DrawVideoDisplay(VIDEO_STATE_TIME_ON,tape.length_seconds);
178   }
179
180   XCopyArea(display,drawto,pix[PIX_DB_DOOR],gc,
181             VX,VY, VXSIZE,VYSIZE, DOOR_GFX_PAGEX1,DOOR_GFX_PAGEY2);
182 }
183
184 void DrawSoundDisplay(unsigned long state)
185 {
186   int pos, cx = DOOR_GFX_PAGEX4, cy = 0;
187
188   pos = (state & BUTTON_SOUND_MUSIC ? SOUND_BUTTON_MUSIC_XPOS :
189          state & BUTTON_SOUND_LOOPS ? SOUND_BUTTON_LOOPS_XPOS :
190          SOUND_BUTTON_SIMPLE_XPOS);
191
192   if (state & BUTTON_ON)
193     cy -= SOUND_BUTTON_YSIZE;
194
195   if (state & BUTTON_PRESSED)
196     cx = DOOR_GFX_PAGEX3;
197
198   XCopyArea(display,pix[PIX_DOOR],drawto,gc,
199             cx + pos,cy + SOUND_BUTTON_ANY_YPOS,
200             SOUND_BUTTON_XSIZE,SOUND_BUTTON_YSIZE,
201             DX + pos,DY + SOUND_BUTTON_ANY_YPOS);
202
203   redraw_mask |= REDRAW_DOOR_1;
204 }
205
206 void DrawGameButton(unsigned long state)
207 {
208   int pos, cx = DOOR_GFX_PAGEX4, cy = -GAME_BUTTON_YSIZE;
209
210   pos = (state & BUTTON_GAME_STOP ? GAME_BUTTON_STOP_XPOS :
211          state & BUTTON_GAME_PAUSE ? GAME_BUTTON_PAUSE_XPOS :
212          GAME_BUTTON_PLAY_XPOS);
213
214   if (state & BUTTON_PRESSED)
215     cx = DOOR_GFX_PAGEX3;
216
217   XCopyArea(display,pix[PIX_DOOR],drawto,gc,
218             cx + pos,cy + GAME_BUTTON_ANY_YPOS,
219             GAME_BUTTON_XSIZE,GAME_BUTTON_YSIZE,
220             DX + pos,DY + GAME_BUTTON_ANY_YPOS);
221
222   redraw_mask |= REDRAW_DOOR_1;
223 }
224
225 void DrawYesNoButton(unsigned long state)
226 {
227   int pos, cx = DOOR_GFX_PAGEX4, cy = 0;
228
229   pos = (state & BUTTON_OK ? OK_BUTTON_XPOS : NO_BUTTON_XPOS);
230
231   if (state & BUTTON_PRESSED)
232     cx = DOOR_GFX_PAGEX3;
233
234   XCopyArea(display,pix[PIX_DOOR],drawto,gc,
235             cx + pos,cy + OK_BUTTON_GFX_YPOS,
236             OK_BUTTON_XSIZE,OK_BUTTON_YSIZE,
237             DX + pos,DY + OK_BUTTON_YPOS);
238
239   redraw_mask |= REDRAW_DOOR_1;
240 }
241
242 void DrawConfirmButton(unsigned long state)
243 {
244   int cx = DOOR_GFX_PAGEX4, cy = 0;
245
246   if (state & BUTTON_PRESSED)
247     cx = DOOR_GFX_PAGEX3;
248
249   XCopyArea(display,pix[PIX_DOOR],drawto,gc,
250             cx + CONFIRM_BUTTON_XPOS,cy + CONFIRM_BUTTON_GFX_YPOS,
251             CONFIRM_BUTTON_XSIZE,CONFIRM_BUTTON_YSIZE,
252             DX + CONFIRM_BUTTON_XPOS,DY + CONFIRM_BUTTON_YPOS);
253
254   redraw_mask |= REDRAW_DOOR_1;
255 }
256
257 void DrawPlayerButton(unsigned long state, int mode)
258 {
259   Drawable dest_drawto;
260   int dest_xoffset, dest_yoffset;
261   int graphic;
262   int graphic_offset = (PLAYER_BUTTON_XSIZE - TILEX/2)/2;
263   int xpos, ypos;
264   int cx = DOOR_GFX_PAGEX4, cy = 0;
265
266   if (mode == DB_INIT)
267   {
268     dest_drawto = pix[PIX_DB_DOOR];
269     dest_xoffset = DOOR_GFX_PAGEX1;
270     dest_yoffset = 0;
271   }
272   else
273   {
274     dest_drawto = drawto;
275     dest_xoffset = DX;
276     dest_yoffset = DY;
277   }
278
279   if (state & BUTTON_PLAYER_1)
280     graphic = GFX_SPIELER1;
281   else if (state & BUTTON_PLAYER_2)
282     graphic = GFX_SPIELER2;
283   else if (state & BUTTON_PLAYER_3)
284     graphic = GFX_SPIELER3;
285   else if (state & BUTTON_PLAYER_4)
286     graphic = GFX_SPIELER4;
287
288   xpos = (state & BUTTON_PLAYER_1 || state & BUTTON_PLAYER_3 ?
289           PLAYER_BUTTON_1_XPOS : PLAYER_BUTTON_2_XPOS);
290   ypos = (state & BUTTON_PLAYER_1 || state & BUTTON_PLAYER_2 ?
291           PLAYER_BUTTON_1_YPOS : PLAYER_BUTTON_3_YPOS);
292
293   if (state & BUTTON_PRESSED)
294   {
295     cx = DOOR_GFX_PAGEX3;
296     graphic_offset += 1;
297   }
298
299   XCopyArea(display,pix[PIX_DOOR],dest_drawto,gc,
300             cx + PLAYER_BUTTON_GFX_XPOS, cy + PLAYER_BUTTON_GFX_YPOS,
301             PLAYER_BUTTON_XSIZE, PLAYER_BUTTON_YSIZE,
302             dest_xoffset + xpos, dest_yoffset + ypos);
303   DrawMiniGraphicExt(dest_drawto,gc,
304                      dest_xoffset + xpos + graphic_offset,
305                      dest_yoffset + ypos + graphic_offset,
306                      graphic);
307
308   redraw_mask |= REDRAW_DOOR_1;
309 }
310
311 /* several buttons in the level editor */
312
313 void DrawEditButton(unsigned long state)
314 {
315   int i;
316   int xpos = 0, ypos = 1, xsize = 2, ysize = 3;
317   int cx = DOOR_GFX_PAGEX6, cy = DOOR_GFX_PAGEY2;
318   static int edit_pos[6][4] =
319   {
320    {ED_BUTTON_CTRL_XPOS,ED_BUTTON_CTRL_YPOS,
321     ED_BUTTON_CTRL_XSIZE,ED_BUTTON_CTRL_YSIZE},
322
323    {ED_BUTTON_FILL_XPOS,ED_BUTTON_FILL_YPOS,
324     ED_BUTTON_FILL_XSIZE,ED_BUTTON_FILL_YSIZE},
325
326    {ED_BUTTON_LEFT_XPOS,ED_BUTTON_LEFT_YPOS,
327     ED_BUTTON_LEFT_XSIZE,ED_BUTTON_LEFT_YSIZE},
328
329    {ED_BUTTON_UP_XPOS,ED_BUTTON_UP_YPOS,
330     ED_BUTTON_UP_XSIZE,ED_BUTTON_UP_YSIZE},
331
332    {ED_BUTTON_DOWN_XPOS,ED_BUTTON_DOWN_YPOS,
333     ED_BUTTON_DOWN_XSIZE,ED_BUTTON_DOWN_YSIZE},
334
335    {ED_BUTTON_RIGHT_XPOS,ED_BUTTON_RIGHT_YPOS,
336     ED_BUTTON_RIGHT_XSIZE,ED_BUTTON_RIGHT_YSIZE}
337   };
338
339   if (state & ED_BUTTON_PRESSED)
340     cx = DOOR_GFX_PAGEX5;
341
342   for(i=0;i<6;i++)
343   {
344     if (state & (1<<i))
345       XCopyArea(display,pix[PIX_DOOR],drawto,gc,
346                 cx + edit_pos[i][xpos],
347                 cy + edit_pos[i][ypos],
348                 edit_pos[i][xsize],
349                 edit_pos[i][ysize],
350                 VX + edit_pos[i][xpos],
351                 VY + edit_pos[i][ypos]);
352   }
353
354   redraw_mask |= REDRAW_DOOR_2;
355 }
356
357 void DrawCtrlButton(unsigned long state)
358 {
359   int i;
360   int xpos = 0, ypos = 1, xsize = 2, ysize = 3;
361   int cx = DOOR_GFX_PAGEX4, cy = DOOR_GFX_PAGEY1+80;
362   static int edit_pos[4][4] =
363   {
364    {ED_BUTTON_EDIT_XPOS,ED_BUTTON_EDIT_YPOS,
365     ED_BUTTON_EDIT_XSIZE,ED_BUTTON_EDIT_YSIZE},
366
367    {ED_BUTTON_CLEAR_XPOS,ED_BUTTON_CLEAR_YPOS,
368     ED_BUTTON_CLEAR_XSIZE,ED_BUTTON_CLEAR_YSIZE},
369
370    {ED_BUTTON_UNDO_XPOS,ED_BUTTON_UNDO_YPOS,
371     ED_BUTTON_UNDO_XSIZE,ED_BUTTON_UNDO_YSIZE},
372
373    {ED_BUTTON_EXIT_XPOS,ED_BUTTON_EXIT_YPOS,
374     ED_BUTTON_EXIT_XSIZE,ED_BUTTON_EXIT_YSIZE}
375   };
376
377   if (state & ED_BUTTON_PRESSED)
378     cx = DOOR_GFX_PAGEX3;
379
380   for(i=0;i<4;i++)
381   {
382     if (state & (1<<(i+6)))
383       XCopyArea(display,pix[PIX_DOOR],drawto,gc,
384                 cx + edit_pos[i][xpos],
385                 cy + edit_pos[i][ypos],
386                 edit_pos[i][xsize],
387                 edit_pos[i][ysize],
388                 VX + edit_pos[i][xpos],
389                 VY + edit_pos[i][ypos]);
390   }
391
392   redraw_mask |= REDRAW_DOOR_2;
393 }
394
395 void DrawElemButton(int button_nr, int button_state)
396 {
397   int xpos = 0, ypos = 1, xsize = 2, ysize = 3;
398   int cx = DOOR_GFX_PAGEX6, cy = DOOR_GFX_PAGEY1;
399   int from_x, from_y, to_x,to_y, size_x, size_y;
400   static int edit_pos[3][4] =
401   {
402    {ED_BUTTON_EUP_XPOS,ED_BUTTON_EUP_YPOS,
403     ED_BUTTON_EUP_XSIZE,ED_BUTTON_EUP_YSIZE},
404
405    {ED_BUTTON_EDOWN_XPOS,ED_BUTTON_EDOWN_YPOS,
406     ED_BUTTON_EDOWN_XSIZE,ED_BUTTON_EDOWN_YSIZE},
407
408    {ED_BUTTON_ELEM_XPOS,ED_BUTTON_ELEM_YPOS,
409     ED_BUTTON_ELEM_XSIZE,ED_BUTTON_ELEM_YSIZE}
410   };
411
412   if (button_nr<ED_BUTTON_ELEM)
413   {
414     int pos = button_nr;
415
416     from_x = cx + edit_pos[pos][xpos];
417     from_y = cy + edit_pos[pos][ypos];
418     size_x = edit_pos[pos][xsize];
419     size_y = edit_pos[pos][ysize];
420     to_x   = DX + edit_pos[pos][xpos];
421     to_y   = DY + edit_pos[pos][ypos];
422
423     if (button_state & ED_BUTTON_PRESSED)
424     {
425       if (button_nr==ED_BUTTON_EUP)
426         from_y = cy + ED_BUTTON_EUP_Y2POS;
427       else
428         from_y = cy + ED_BUTTON_EDOWN_Y2POS;
429     }
430
431     XCopyArea(display,pix[PIX_DOOR],drawto,gc,
432               from_x,from_y, size_x,size_y, to_x,to_y);
433   }
434   else
435   {
436     int pos = ED_BUTTON_ELEM;
437     int elem_pos = button_nr-ED_BUTTON_ELEM;
438     int x = elem_pos % MAX_ELEM_X;
439     int y = elem_pos / MAX_ELEM_X;
440     int graphic;
441     int shift = 0;
442
443     if (elem_pos+element_shift < elements_in_list)
444       graphic = el2gfx(editor_element[elem_pos+element_shift]);
445     else
446       graphic = GFX_LEERRAUM;
447
448     from_x = cx + edit_pos[pos][xpos];
449     from_y = cy + edit_pos[pos][ypos];
450     size_x = edit_pos[pos][xsize];
451     size_y = edit_pos[pos][ysize];
452     to_x   = DX + edit_pos[pos][xpos] + x * ED_BUTTON_ELEM_XSIZE;
453     to_y   = DY + edit_pos[pos][ypos] + y * ED_BUTTON_ELEM_YSIZE;
454
455     if (button_state & ED_BUTTON_PRESSED)
456     {
457       from_y = ED_BUTTON_ELEM_Y2POS;
458       shift = 1;
459     }
460
461     XCopyArea(display,pix[PIX_DOOR],drawto,gc,
462               from_x,from_y, size_x,size_y, to_x,to_y);
463
464     DrawMiniGraphicExt(drawto,gc,
465                        DX+ED_BUTTON_ELEM_XPOS+3+shift + 
466                        (elem_pos % MAX_ELEM_X)*ED_BUTTON_ELEM_XSIZE,
467                        DY+ED_BUTTON_ELEM_YPOS+3-shift +
468                        (elem_pos / MAX_ELEM_X)*ED_BUTTON_ELEM_YSIZE,
469                        graphic);
470   }
471
472   redraw_mask |= REDRAW_DOOR_1;
473 }
474
475 void DrawCountButton(int button_nr, int button_state)
476 {
477   int from_x, from_y, to_x,to_y, size_x, size_y;
478
479   from_x =
480     DOOR_GFX_PAGEX4+(button_nr%2 ? ED_BUTTON_PLUS_XPOS : ED_BUTTON_MINUS_XPOS);
481   from_y = DOOR_GFX_PAGEY1 + ED_BUTTON_MINUS_YPOS;
482   size_x = ED_BUTTON_MINUS_XSIZE;
483   size_y = ED_BUTTON_MINUS_YSIZE;
484   to_x = (button_nr<32 ? ED_COUNT_GADGET_XPOS : ED_SIZE_GADGET_XPOS);
485   if (button_nr % 2)
486     to_x += (ED_BUTTON_PLUS_XPOS - ED_BUTTON_MINUS_XPOS);
487   to_y = (button_nr<32 ? ED_COUNT_GADGET_YPOS : ED_SIZE_GADGET_YPOS) +
488     ((button_nr<32 ? button_nr : button_nr-32)/2)*ED_COUNT_GADGET_YSIZE;
489
490   if (button_state & ED_BUTTON_PRESSED)
491     from_x -= DXSIZE;
492
493   XCopyArea(display,pix[PIX_DOOR],drawto,gc,
494             from_x,from_y, size_x,size_y, to_x,to_y);
495   XCopyArea(display,pix[PIX_DOOR],window,gc,
496             from_x,from_y, size_x,size_y, to_x,to_y);
497 }
498
499 /**********************************************************************/
500 /********** checking buttons (and redrawing them, if needed) **********/
501 /**********************************************************************/
502
503 int CheckVideoButtons(int mx, int my, int button)
504 {
505   int return_code = 0;
506   static int choice = -1;
507   static BOOL pressed = FALSE;
508   static int video_button[5] =
509   {
510     VIDEO_PRESS_EJECT_ON,
511     VIDEO_PRESS_STOP_ON,
512     VIDEO_PRESS_PAUSE_ON,
513     VIDEO_PRESS_REC_ON,
514     VIDEO_PRESS_PLAY_ON
515   };
516
517   if (button)
518   {
519     if (!motion_status)         /* Maustaste neu gedrückt */
520     {
521       if (ON_VIDEO_BUTTON(mx,my))
522       {
523         choice = VIDEO_BUTTON(mx);
524         pressed = TRUE;
525         DrawVideoDisplay(video_button[choice],0);
526       }
527     }
528     else                        /* Mausbewegung bei gedrückter Maustaste */
529     {
530       if ((!ON_VIDEO_BUTTON(mx,my) || VIDEO_BUTTON(mx)!=choice) &&
531           choice>=0 && pressed)
532       {
533         pressed = FALSE;
534         DrawVideoDisplay(video_button[choice]<<1,0);
535       }
536       else if (ON_VIDEO_BUTTON(mx,my) && VIDEO_BUTTON(mx)==choice && !pressed)
537       {
538         pressed = TRUE;
539         DrawVideoDisplay(video_button[choice],0);
540       }
541     }
542   }
543   else                          /* Maustaste wieder losgelassen */
544   {
545     if (ON_VIDEO_BUTTON(mx,my) && VIDEO_BUTTON(mx)==choice && pressed)
546     {
547       DrawVideoDisplay(video_button[choice]<<1,0);
548       return_code = choice+1;
549       choice = -1;
550       pressed = FALSE;
551     }
552     else
553     {
554       choice = -1;
555       pressed = FALSE;
556     }
557   }
558
559   BackToFront();
560   return(return_code);
561 }
562
563 int CheckSoundButtons(int mx, int my, int button)
564 {
565   int return_code = 0;
566   static int choice = -1;
567   static BOOL pressed = FALSE;
568   int sound_state[3];
569
570   sound_state[0] = BUTTON_SOUND_MUSIC  | (BUTTON_ON * sound_music_on);
571   sound_state[1] = BUTTON_SOUND_LOOPS  | (BUTTON_ON * sound_loops_on);
572   sound_state[2] = BUTTON_SOUND_SIMPLE | (BUTTON_ON * sound_simple_on);
573
574   if (button)
575   {
576     if (!motion_status)         /* Maustaste neu gedrückt */
577     {
578       if (ON_SOUND_BUTTON(mx,my))
579       {
580         choice = SOUND_BUTTON(mx);
581         pressed = TRUE;
582         DrawSoundDisplay(sound_state[choice] | BUTTON_PRESSED);
583       }
584     }
585     else                        /* Mausbewegung bei gedrückter Maustaste */
586     {
587       if ((!ON_SOUND_BUTTON(mx,my) || SOUND_BUTTON(mx)!=choice) &&
588           choice>=0 && pressed)
589       {
590         pressed = FALSE;
591         DrawSoundDisplay(sound_state[choice] | BUTTON_RELEASED);
592       }
593       else if (ON_SOUND_BUTTON(mx,my) && SOUND_BUTTON(mx)==choice && !pressed)
594       {
595         pressed = TRUE;
596         DrawSoundDisplay(sound_state[choice] | BUTTON_PRESSED);
597       }
598     }
599   }
600   else                          /* Maustaste wieder losgelassen */
601   {
602     if (ON_SOUND_BUTTON(mx,my) && SOUND_BUTTON(mx)==choice && pressed)
603     {
604       DrawSoundDisplay(sound_state[choice] | BUTTON_RELEASED);
605       return_code = 1<<choice;
606       choice = -1;
607       pressed = FALSE;
608     }
609     else
610     {
611       choice = -1;
612       pressed = FALSE;
613     }
614   }
615
616   BackToFront();
617   return(return_code);
618 }
619
620 int CheckGameButtons(int mx, int my, int button)
621 {
622   int return_code = 0;
623   static int choice = -1;
624   static BOOL pressed = FALSE;
625   int game_state[3] =
626   {
627     BUTTON_GAME_STOP,
628     BUTTON_GAME_PAUSE,
629     BUTTON_GAME_PLAY
630   };
631
632   if (button)
633   {
634     if (!motion_status)         /* Maustaste neu gedrückt */
635     {
636       if (ON_GAME_BUTTON(mx,my))
637       {
638         choice = GAME_BUTTON(mx);
639         pressed = TRUE;
640         DrawGameButton(game_state[choice] | BUTTON_PRESSED);
641       }
642     }
643     else                        /* Mausbewegung bei gedrückter Maustaste */
644     {
645       if ((!ON_GAME_BUTTON(mx,my) || GAME_BUTTON(mx)!=choice) &&
646           choice>=0 && pressed)
647       {
648         pressed = FALSE;
649         DrawGameButton(game_state[choice] | BUTTON_RELEASED);
650       }
651       else if (ON_GAME_BUTTON(mx,my) && GAME_BUTTON(mx)==choice && !pressed)
652       {
653         pressed = TRUE;
654         DrawGameButton(game_state[choice] | BUTTON_PRESSED);
655       }
656     }
657   }
658   else                          /* Maustaste wieder losgelassen */
659   {
660     if (ON_GAME_BUTTON(mx,my) && GAME_BUTTON(mx)==choice && pressed)
661     {
662       DrawGameButton(game_state[choice] | BUTTON_RELEASED);
663       return_code = 1<<choice;
664       choice = -1;
665       pressed = FALSE;
666     }
667     else
668     {
669       choice = -1;
670       pressed = FALSE;
671     }
672   }
673
674   BackToFront();
675   return(return_code);
676 }
677
678 int CheckYesNoButtons(int mx, int my, int button)
679 {
680   int return_code = 0;
681   static int choice = -1;
682   static BOOL pressed = FALSE;
683   static int yesno_button[5] =
684   {
685     BUTTON_OK,
686     BUTTON_NO
687   };
688
689   if (button)
690   {
691     if (!motion_status)         /* Maustaste neu gedrückt */
692     {
693       if (ON_YESNO_BUTTON(mx,my))
694       {
695         choice = YESNO_BUTTON(mx);
696         pressed = TRUE;
697         DrawYesNoButton(yesno_button[choice] | BUTTON_PRESSED);
698       }
699     }
700     else                        /* Mausbewegung bei gedrückter Maustaste */
701     {
702       if ((!ON_YESNO_BUTTON(mx,my) || YESNO_BUTTON(mx)!=choice) &&
703           choice>=0 && pressed)
704       {
705         pressed = FALSE;
706         DrawYesNoButton(yesno_button[choice] | BUTTON_RELEASED);
707       }
708       else if (ON_YESNO_BUTTON(mx,my) && YESNO_BUTTON(mx)==choice && !pressed)
709       {
710         pressed = TRUE;
711         DrawYesNoButton(yesno_button[choice] | BUTTON_PRESSED);
712       }
713     }
714   }
715   else                          /* Maustaste wieder losgelassen */
716   {
717     if (ON_YESNO_BUTTON(mx,my) && YESNO_BUTTON(mx)==choice && pressed)
718     {
719       DrawYesNoButton(yesno_button[choice] | BUTTON_RELEASED);
720       return_code = choice+1;
721       choice = -1;
722       pressed = FALSE;
723     }
724     else
725     {
726       choice = -1;
727       pressed = FALSE;
728     }
729   }
730
731   BackToFront();
732   return(return_code);
733 }
734
735 int CheckConfirmButton(int mx, int my, int button)
736 {
737   int return_code = 0;
738   static int choice = -1;
739   static BOOL pressed = FALSE;
740
741   if (button)
742   {
743     if (!motion_status)         /* Maustaste neu gedrückt */
744     {
745       if (ON_CONFIRM_BUTTON(mx,my))
746       {
747         choice = 0;
748         pressed = TRUE;
749         DrawConfirmButton(BUTTON_PRESSED);
750       }
751     }
752     else                        /* Mausbewegung bei gedrückter Maustaste */
753     {
754       if (!ON_CONFIRM_BUTTON(mx,my) && choice>=0 && pressed)
755       {
756         pressed = FALSE;
757         DrawConfirmButton(BUTTON_RELEASED);
758       }
759       else if (ON_CONFIRM_BUTTON(mx,my) && !pressed)
760       {
761         pressed = TRUE;
762         DrawConfirmButton(BUTTON_PRESSED);
763       }
764     }
765   }
766   else                          /* Maustaste wieder losgelassen */
767   {
768     if (ON_CONFIRM_BUTTON(mx,my) && pressed)
769     {
770       DrawConfirmButton(BUTTON_RELEASED);
771       return_code = BUTTON_CONFIRM;
772       choice = -1;
773       pressed = FALSE;
774     }
775     else
776     {
777       choice = -1;
778       pressed = FALSE;
779     }
780   }
781
782   BackToFront();
783   return(return_code);
784 }
785
786 int CheckPlayerButtons(int mx, int my, int button)
787 {
788   int return_code = 0;
789   static int choice = -1;
790   static BOOL pressed = FALSE;
791   int player_state[4] =
792   {
793     BUTTON_PLAYER_1,
794     BUTTON_PLAYER_2,
795     BUTTON_PLAYER_3,
796     BUTTON_PLAYER_4
797   };
798
799   if (button)
800   {
801     if (!motion_status)         /* Maustaste neu gedrückt */
802     {
803       if (ON_PLAYER_BUTTON(mx,my))
804       {
805         choice = PLAYER_BUTTON(mx,my);
806         pressed = TRUE;
807         DrawPlayerButton(player_state[choice] | BUTTON_PRESSED, DB_NORMAL);
808       }
809     }
810     else                        /* Mausbewegung bei gedrückter Maustaste */
811     {
812       if ((!ON_PLAYER_BUTTON(mx,my) || PLAYER_BUTTON(mx,my)!=choice) &&
813           choice>=0 && pressed)
814       {
815         pressed = FALSE;
816         DrawPlayerButton(player_state[choice] | BUTTON_RELEASED, DB_NORMAL);
817       }
818       else if (ON_PLAYER_BUTTON(mx,my) && PLAYER_BUTTON(mx,my)==choice && !pressed)
819       {
820         pressed = TRUE;
821         DrawPlayerButton(player_state[choice] | BUTTON_PRESSED, DB_NORMAL);
822       }
823     }
824   }
825   else                          /* Maustaste wieder losgelassen */
826   {
827     if (ON_PLAYER_BUTTON(mx,my) && PLAYER_BUTTON(mx,my)==choice && pressed)
828     {
829       DrawPlayerButton(player_state[choice] | BUTTON_RELEASED, DB_NORMAL);
830       return_code = player_state[choice];
831       choice = -1;
832       pressed = FALSE;
833     }
834     else
835     {
836       choice = -1;
837       pressed = FALSE;
838     }
839   }
840
841   BackToFront();
842   return(return_code);
843 }
844
845 /* several buttons in the level editor */
846
847 int CheckEditButtons(int mx, int my, int button)
848 {
849   int return_code = 0;
850   static int choice = -1;
851   static BOOL pressed = FALSE;
852   static int edit_button[6] =
853   {
854     ED_BUTTON_CTRL,
855     ED_BUTTON_FILL,
856     ED_BUTTON_LEFT,
857     ED_BUTTON_UP,
858     ED_BUTTON_DOWN,
859     ED_BUTTON_RIGHT
860   };
861
862   if (button)
863   {
864     if (!motion_status)         /* Maustaste neu gedrückt */
865     {
866       if (ON_EDIT_BUTTON(mx,my))
867       {
868         choice = EDIT_BUTTON(mx,my);
869         pressed = TRUE;
870         DrawEditButton(edit_button[choice] | ED_BUTTON_PRESSED);
871         if (edit_button[choice]!=ED_BUTTON_CTRL &&
872             edit_button[choice]!=ED_BUTTON_FILL)
873           return_code = 1<<choice;
874       }
875     }
876     else                        /* Mausbewegung bei gedrückter Maustaste */
877     {
878       if ((!ON_EDIT_BUTTON(mx,my) || EDIT_BUTTON(mx,my)!=choice) &&
879           choice>=0 && pressed)
880       {
881         pressed = FALSE;
882         DrawEditButton(edit_button[choice] | ED_BUTTON_RELEASED);
883       }
884       else if (ON_EDIT_BUTTON(mx,my) && EDIT_BUTTON(mx,my)==choice)
885       {
886         if (!pressed)
887           DrawEditButton(edit_button[choice] | ED_BUTTON_PRESSED);
888         pressed = TRUE;
889         if (edit_button[choice]!=ED_BUTTON_CTRL &&
890             edit_button[choice]!=ED_BUTTON_FILL)
891           return_code = 1<<choice;
892       }
893     }
894   }
895   else                          /* Maustaste wieder losgelassen */
896   {
897     if (ON_EDIT_BUTTON(mx,my) && EDIT_BUTTON(mx,my)==choice && pressed)
898     {
899       DrawEditButton(edit_button[choice] | ED_BUTTON_RELEASED);
900       if (edit_button[choice]==ED_BUTTON_CTRL ||
901           edit_button[choice]==ED_BUTTON_FILL)
902         return_code = 1<<choice;
903       choice = -1;
904       pressed = FALSE;
905     }
906     else
907     {
908       choice = -1;
909       pressed = FALSE;
910     }
911   }
912
913   BackToFront();
914   return(return_code);
915 }
916
917 int CheckCtrlButtons(int mx, int my, int button)
918 {
919   int return_code = 0;
920   static int choice = -1;
921   static BOOL pressed = FALSE;
922   static int ctrl_button[4] =
923   {
924     ED_BUTTON_EDIT,
925     ED_BUTTON_CLEAR,
926     ED_BUTTON_UNDO,
927     ED_BUTTON_EXIT
928   };
929
930   if (button)
931   {
932     if (!motion_status)         /* Maustaste neu gedrückt */
933     {
934       if (ON_CTRL_BUTTON(mx,my))
935       {
936         choice = CTRL_BUTTON(mx,my);
937         pressed = TRUE;
938         DrawCtrlButton(ctrl_button[choice] | ED_BUTTON_PRESSED);
939       }
940     }
941     else                        /* Mausbewegung bei gedrückter Maustaste */
942     {
943       if ((!ON_CTRL_BUTTON(mx,my) || CTRL_BUTTON(mx,my)!=choice) &&
944           choice>=0 && pressed)
945       {
946         pressed = FALSE;
947         DrawCtrlButton(ctrl_button[choice] | ED_BUTTON_RELEASED);
948       }
949       else if (ON_CTRL_BUTTON(mx,my) && CTRL_BUTTON(mx,my)==choice && !pressed)
950       {
951         pressed = TRUE;
952         DrawCtrlButton(ctrl_button[choice] | ED_BUTTON_PRESSED);
953       }
954     }
955   }
956   else                          /* Maustaste wieder losgelassen */
957   {
958     if (ON_CTRL_BUTTON(mx,my) && CTRL_BUTTON(mx,my)==choice && pressed)
959     {
960       DrawCtrlButton(ctrl_button[choice] | ED_BUTTON_RELEASED);
961       return_code = 1<<(choice+6);
962       choice = -1;
963       pressed = FALSE;
964     }
965     else
966     {
967       choice = -1;
968       pressed = FALSE;
969     }
970   }
971
972   BackToFront();
973   return(return_code);
974 }
975
976 int CheckElemButtons(int mx, int my, int button)
977 {
978   int return_code = -1;
979   static int choice = -1;
980   static BOOL pressed = FALSE;
981
982   if (button)
983   {
984     if (!motion_status)         /* Maustaste neu gedrückt */
985     {
986       if (ON_ELEM_BUTTON(mx,my))
987       {
988         choice = ELEM_BUTTON(mx,my);
989         pressed = TRUE;
990         DrawElemButton(choice,ED_BUTTON_PRESSED);
991         if (choice==ED_BUTTON_EUP ||
992             choice==ED_BUTTON_EDOWN)
993           return_code = choice;
994       }
995     }
996     else                        /* Mausbewegung bei gedrückter Maustaste */
997     {
998       if ((!ON_ELEM_BUTTON(mx,my) || ELEM_BUTTON(mx,my)!=choice) &&
999           choice>=0 && pressed)
1000       {
1001         pressed = FALSE;
1002         DrawElemButton(choice,ED_BUTTON_RELEASED);
1003       }
1004       else if (ON_ELEM_BUTTON(mx,my) && ELEM_BUTTON(mx,my)==choice)
1005       {
1006         if (!pressed)
1007           DrawElemButton(choice,ED_BUTTON_PRESSED);
1008         pressed = TRUE;
1009         if (choice==ED_BUTTON_EUP ||
1010             choice==ED_BUTTON_EDOWN)
1011           return_code = choice;
1012       }
1013     }
1014   }
1015   else                          /* Maustaste wieder losgelassen */
1016   {
1017     if (ON_ELEM_BUTTON(mx,my) && ELEM_BUTTON(mx,my)==choice && pressed)
1018     {
1019       DrawElemButton(choice,ED_BUTTON_RELEASED);
1020       if (choice!=ED_BUTTON_EUP &&
1021           choice!=ED_BUTTON_EDOWN)
1022         return_code = choice;
1023       choice = -1;
1024       pressed = FALSE;
1025     }
1026     else
1027     {
1028       choice = -1;
1029       pressed = FALSE;
1030     }
1031   }
1032
1033   BackToFront();
1034   return(return_code);
1035 }
1036
1037 int CheckCountButtons(int mx, int my, int button)
1038 {
1039   int return_code = -1;
1040   static int choice = -1;
1041   static BOOL pressed = FALSE;
1042
1043   if (button)
1044   {
1045     if (!motion_status)         /* Maustaste neu gedrückt */
1046     {
1047       if (ON_COUNT_BUTTON(mx,my))
1048       {
1049         choice = COUNT_BUTTON(mx,my);
1050         pressed = TRUE;
1051         DrawCountButton(choice,ED_BUTTON_PRESSED);
1052         return_code = choice;
1053       }
1054     }
1055     else                        /* Mausbewegung bei gedrückter Maustaste */
1056     {
1057       if ((!ON_COUNT_BUTTON(mx,my) || COUNT_BUTTON(mx,my)!=choice) &&
1058           choice>=0 && pressed)
1059       {
1060         pressed = FALSE;
1061         DrawCountButton(choice,ED_BUTTON_RELEASED);
1062       }
1063       else if (ON_COUNT_BUTTON(mx,my) && COUNT_BUTTON(mx,my)==choice)
1064       {
1065         if (!pressed)
1066           DrawCountButton(choice,ED_BUTTON_PRESSED);
1067         pressed = TRUE;
1068         return_code = choice;
1069       }
1070     }
1071   }
1072   else                          /* Maustaste wieder losgelassen */
1073   {
1074     if (ON_COUNT_BUTTON(mx,my) && COUNT_BUTTON(mx,my)==choice && pressed)
1075     {
1076       DrawCountButton(choice,ED_BUTTON_RELEASED);
1077       choice = -1;
1078       pressed = FALSE;
1079     }
1080     else
1081     {
1082       choice = -1;
1083       pressed = FALSE;
1084     }
1085   }
1086
1087   BackToFront();
1088   return(return_code);
1089 }