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