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