rnd-19980930-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 DrawChooseButton(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 /* several buttons in the level editor */
258
259 void DrawEditButton(unsigned long state)
260 {
261   int i;
262   int xpos = 0, ypos = 1, xsize = 2, ysize = 3;
263   int cx = DOOR_GFX_PAGEX6, cy = DOOR_GFX_PAGEY2;
264   static int edit_pos[6][4] =
265   {
266    {ED_BUTTON_CTRL_XPOS,ED_BUTTON_CTRL_YPOS,
267     ED_BUTTON_CTRL_XSIZE,ED_BUTTON_CTRL_YSIZE},
268
269    {ED_BUTTON_FILL_XPOS,ED_BUTTON_FILL_YPOS,
270     ED_BUTTON_FILL_XSIZE,ED_BUTTON_FILL_YSIZE},
271
272    {ED_BUTTON_LEFT_XPOS,ED_BUTTON_LEFT_YPOS,
273     ED_BUTTON_LEFT_XSIZE,ED_BUTTON_LEFT_YSIZE},
274
275    {ED_BUTTON_UP_XPOS,ED_BUTTON_UP_YPOS,
276     ED_BUTTON_UP_XSIZE,ED_BUTTON_UP_YSIZE},
277
278    {ED_BUTTON_DOWN_XPOS,ED_BUTTON_DOWN_YPOS,
279     ED_BUTTON_DOWN_XSIZE,ED_BUTTON_DOWN_YSIZE},
280
281    {ED_BUTTON_RIGHT_XPOS,ED_BUTTON_RIGHT_YPOS,
282     ED_BUTTON_RIGHT_XSIZE,ED_BUTTON_RIGHT_YSIZE}
283   };
284
285   if (state & ED_BUTTON_PRESSED)
286     cx = DOOR_GFX_PAGEX5;
287
288   for(i=0;i<6;i++)
289   {
290     if (state & (1<<i))
291       XCopyArea(display,pix[PIX_DOOR],drawto,gc,
292                 cx + edit_pos[i][xpos],
293                 cy + edit_pos[i][ypos],
294                 edit_pos[i][xsize],
295                 edit_pos[i][ysize],
296                 VX + edit_pos[i][xpos],
297                 VY + edit_pos[i][ypos]);
298   }
299
300   redraw_mask |= REDRAW_DOOR_2;
301 }
302
303 void DrawCtrlButton(unsigned long state)
304 {
305   int i;
306   int xpos = 0, ypos = 1, xsize = 2, ysize = 3;
307   int cx = DOOR_GFX_PAGEX4, cy = DOOR_GFX_PAGEY1+80;
308   static int edit_pos[4][4] =
309   {
310    {ED_BUTTON_EDIT_XPOS,ED_BUTTON_EDIT_YPOS,
311     ED_BUTTON_EDIT_XSIZE,ED_BUTTON_EDIT_YSIZE},
312
313    {ED_BUTTON_CLEAR_XPOS,ED_BUTTON_CLEAR_YPOS,
314     ED_BUTTON_CLEAR_XSIZE,ED_BUTTON_CLEAR_YSIZE},
315
316    {ED_BUTTON_UNDO_XPOS,ED_BUTTON_UNDO_YPOS,
317     ED_BUTTON_UNDO_XSIZE,ED_BUTTON_UNDO_YSIZE},
318
319    {ED_BUTTON_EXIT_XPOS,ED_BUTTON_EXIT_YPOS,
320     ED_BUTTON_EXIT_XSIZE,ED_BUTTON_EXIT_YSIZE}
321   };
322
323   if (state & ED_BUTTON_PRESSED)
324     cx = DOOR_GFX_PAGEX3;
325
326   for(i=0;i<4;i++)
327   {
328     if (state & (1<<(i+6)))
329       XCopyArea(display,pix[PIX_DOOR],drawto,gc,
330                 cx + edit_pos[i][xpos],
331                 cy + edit_pos[i][ypos],
332                 edit_pos[i][xsize],
333                 edit_pos[i][ysize],
334                 VX + edit_pos[i][xpos],
335                 VY + edit_pos[i][ypos]);
336   }
337
338   redraw_mask |= REDRAW_DOOR_2;
339 }
340
341 void DrawElemButton(int button_nr, int button_state)
342 {
343   int xpos = 0, ypos = 1, xsize = 2, ysize = 3;
344   int cx = DOOR_GFX_PAGEX6, cy = DOOR_GFX_PAGEY1;
345   int from_x, from_y, to_x,to_y, size_x, size_y;
346   static int edit_pos[3][4] =
347   {
348    {ED_BUTTON_EUP_XPOS,ED_BUTTON_EUP_YPOS,
349     ED_BUTTON_EUP_XSIZE,ED_BUTTON_EUP_YSIZE},
350
351    {ED_BUTTON_EDOWN_XPOS,ED_BUTTON_EDOWN_YPOS,
352     ED_BUTTON_EDOWN_XSIZE,ED_BUTTON_EDOWN_YSIZE},
353
354    {ED_BUTTON_ELEM_XPOS,ED_BUTTON_ELEM_YPOS,
355     ED_BUTTON_ELEM_XSIZE,ED_BUTTON_ELEM_YSIZE}
356   };
357
358   if (button_nr<ED_BUTTON_ELEM)
359   {
360     int pos = button_nr;
361
362     from_x = cx + edit_pos[pos][xpos];
363     from_y = cy + edit_pos[pos][ypos];
364     size_x = edit_pos[pos][xsize];
365     size_y = edit_pos[pos][ysize];
366     to_x   = DX + edit_pos[pos][xpos];
367     to_y   = DY + edit_pos[pos][ypos];
368
369     if (button_state & ED_BUTTON_PRESSED)
370     {
371       if (button_nr==ED_BUTTON_EUP)
372         from_y = cy + ED_BUTTON_EUP_Y2POS;
373       else
374         from_y = cy + ED_BUTTON_EDOWN_Y2POS;
375     }
376
377     XCopyArea(display,pix[PIX_DOOR],drawto,gc,
378               from_x,from_y, size_x,size_y, to_x,to_y);
379   }
380   else
381   {
382     int pos = ED_BUTTON_ELEM;
383     int elem_pos = button_nr-ED_BUTTON_ELEM;
384     int x = elem_pos % MAX_ELEM_X;
385     int y = elem_pos / MAX_ELEM_X;
386     int graphic;
387     int shift = 0;
388
389     if (elem_pos+element_shift < elements_in_list)
390       graphic = el2gfx(editor_element[elem_pos+element_shift]);
391     else
392       graphic = GFX_LEERRAUM;
393
394     from_x = cx + edit_pos[pos][xpos];
395     from_y = cy + edit_pos[pos][ypos];
396     size_x = edit_pos[pos][xsize];
397     size_y = edit_pos[pos][ysize];
398     to_x   = DX + edit_pos[pos][xpos] + x * ED_BUTTON_ELEM_XSIZE;
399     to_y   = DY + edit_pos[pos][ypos] + y * ED_BUTTON_ELEM_YSIZE;
400
401     if (button_state & ED_BUTTON_PRESSED)
402     {
403       from_y = ED_BUTTON_ELEM_Y2POS;
404       shift = 1;
405     }
406
407     XCopyArea(display,pix[PIX_DOOR],drawto,gc,
408               from_x,from_y, size_x,size_y, to_x,to_y);
409
410     DrawMiniGraphicExt(drawto,gc,
411                        DX+ED_BUTTON_ELEM_XPOS+3+shift + 
412                        (elem_pos % MAX_ELEM_X)*ED_BUTTON_ELEM_XSIZE,
413                        DY+ED_BUTTON_ELEM_YPOS+3-shift +
414                        (elem_pos / MAX_ELEM_X)*ED_BUTTON_ELEM_YSIZE,
415                        graphic);
416   }
417
418   redraw_mask |= REDRAW_DOOR_1;
419 }
420
421 void DrawCountButton(int button_nr, int button_state)
422 {
423   int from_x, from_y, to_x,to_y, size_x, size_y;
424
425   from_x =
426     DOOR_GFX_PAGEX4+(button_nr%2 ? ED_BUTTON_PLUS_XPOS : ED_BUTTON_MINUS_XPOS);
427   from_y = DOOR_GFX_PAGEY1 + ED_BUTTON_MINUS_YPOS;
428   size_x = ED_BUTTON_MINUS_XSIZE;
429   size_y = ED_BUTTON_MINUS_YSIZE;
430   to_x = (button_nr<32 ? ED_COUNT_GADGET_XPOS : ED_SIZE_GADGET_XPOS);
431   if (button_nr % 2)
432     to_x += (ED_BUTTON_PLUS_XPOS - ED_BUTTON_MINUS_XPOS);
433   to_y = (button_nr<32 ? ED_COUNT_GADGET_YPOS : ED_SIZE_GADGET_YPOS) +
434     ((button_nr<32 ? button_nr : button_nr-32)/2)*ED_COUNT_GADGET_YSIZE;
435
436   if (button_state & ED_BUTTON_PRESSED)
437     from_x -= DXSIZE;
438
439   XCopyArea(display,pix[PIX_DOOR],drawto,gc,
440             from_x,from_y, size_x,size_y, to_x,to_y);
441   XCopyArea(display,pix[PIX_DOOR],window,gc,
442             from_x,from_y, size_x,size_y, to_x,to_y);
443 }
444
445 /**********************************************************************/
446 /********** checking buttons (and redrawing them, if needed) **********/
447 /**********************************************************************/
448
449 int CheckVideoButtons(int mx, int my, int button)
450 {
451   int return_code = 0;
452   static int choice = -1;
453   static BOOL pressed = FALSE;
454   static int video_button[5] =
455   {
456     VIDEO_PRESS_EJECT_ON,
457     VIDEO_PRESS_STOP_ON,
458     VIDEO_PRESS_PAUSE_ON,
459     VIDEO_PRESS_REC_ON,
460     VIDEO_PRESS_PLAY_ON
461   };
462
463   if (button)
464   {
465     if (!motion_status)         /* Maustaste neu gedrückt */
466     {
467       if (ON_VIDEO_BUTTON(mx,my))
468       {
469         choice = VIDEO_BUTTON(mx);
470         pressed = TRUE;
471         DrawVideoDisplay(video_button[choice],0);
472       }
473     }
474     else                        /* Mausbewegung bei gedrückter Maustaste */
475     {
476       if ((!ON_VIDEO_BUTTON(mx,my) || VIDEO_BUTTON(mx)!=choice) &&
477           choice>=0 && pressed)
478       {
479         pressed = FALSE;
480         DrawVideoDisplay(video_button[choice]<<1,0);
481       }
482       else if (ON_VIDEO_BUTTON(mx,my) && VIDEO_BUTTON(mx)==choice && !pressed)
483       {
484         pressed = TRUE;
485         DrawVideoDisplay(video_button[choice],0);
486       }
487     }
488   }
489   else                          /* Maustaste wieder losgelassen */
490   {
491     if (ON_VIDEO_BUTTON(mx,my) && VIDEO_BUTTON(mx)==choice && pressed)
492     {
493       DrawVideoDisplay(video_button[choice]<<1,0);
494       return_code = choice+1;
495       choice = -1;
496       pressed = FALSE;
497     }
498     else
499     {
500       choice = -1;
501       pressed = FALSE;
502     }
503   }
504
505   BackToFront();
506   return(return_code);
507 }
508
509 int CheckSoundButtons(int mx, int my, int button)
510 {
511   int return_code = 0;
512   static int choice = -1;
513   static BOOL pressed = FALSE;
514   int sound_state[3];
515
516   sound_state[0] = BUTTON_SOUND_MUSIC  | (BUTTON_ON * sound_music_on);
517   sound_state[1] = BUTTON_SOUND_LOOPS  | (BUTTON_ON * sound_loops_on);
518   sound_state[2] = BUTTON_SOUND_SIMPLE | (BUTTON_ON * sound_simple_on);
519
520   if (button)
521   {
522     if (!motion_status)         /* Maustaste neu gedrückt */
523     {
524       if (ON_SOUND_BUTTON(mx,my))
525       {
526         choice = SOUND_BUTTON(mx);
527         pressed = TRUE;
528         DrawSoundDisplay(sound_state[choice] | BUTTON_PRESSED);
529       }
530     }
531     else                        /* Mausbewegung bei gedrückter Maustaste */
532     {
533       if ((!ON_SOUND_BUTTON(mx,my) || SOUND_BUTTON(mx)!=choice) &&
534           choice>=0 && pressed)
535       {
536         pressed = FALSE;
537         DrawSoundDisplay(sound_state[choice] | BUTTON_RELEASED);
538       }
539       else if (ON_SOUND_BUTTON(mx,my) && SOUND_BUTTON(mx)==choice && !pressed)
540       {
541         pressed = TRUE;
542         DrawSoundDisplay(sound_state[choice] | BUTTON_PRESSED);
543       }
544     }
545   }
546   else                          /* Maustaste wieder losgelassen */
547   {
548     if (ON_SOUND_BUTTON(mx,my) && SOUND_BUTTON(mx)==choice && pressed)
549     {
550       DrawSoundDisplay(sound_state[choice] | BUTTON_RELEASED);
551       return_code = 1<<choice;
552       choice = -1;
553       pressed = FALSE;
554     }
555     else
556     {
557       choice = -1;
558       pressed = FALSE;
559     }
560   }
561
562   BackToFront();
563   return(return_code);
564 }
565
566 int CheckGameButtons(int mx, int my, int button)
567 {
568   int return_code = 0;
569   static int choice = -1;
570   static BOOL pressed = FALSE;
571   int game_state[3] =
572   {
573     BUTTON_GAME_STOP,
574     BUTTON_GAME_PAUSE,
575     BUTTON_GAME_PLAY
576   };
577
578   if (button)
579   {
580     if (!motion_status)         /* Maustaste neu gedrückt */
581     {
582       if (ON_GAME_BUTTON(mx,my))
583       {
584         choice = GAME_BUTTON(mx);
585         pressed = TRUE;
586         DrawGameButton(game_state[choice] | BUTTON_PRESSED);
587       }
588     }
589     else                        /* Mausbewegung bei gedrückter Maustaste */
590     {
591       if ((!ON_GAME_BUTTON(mx,my) || GAME_BUTTON(mx)!=choice) &&
592           choice>=0 && pressed)
593       {
594         pressed = FALSE;
595         DrawGameButton(game_state[choice] | BUTTON_RELEASED);
596       }
597       else if (ON_GAME_BUTTON(mx,my) && GAME_BUTTON(mx)==choice && !pressed)
598       {
599         pressed = TRUE;
600         DrawGameButton(game_state[choice] | BUTTON_PRESSED);
601       }
602     }
603   }
604   else                          /* Maustaste wieder losgelassen */
605   {
606     if (ON_GAME_BUTTON(mx,my) && GAME_BUTTON(mx)==choice && pressed)
607     {
608       DrawGameButton(game_state[choice] | BUTTON_RELEASED);
609       return_code = 1<<choice;
610       choice = -1;
611       pressed = FALSE;
612     }
613     else
614     {
615       choice = -1;
616       pressed = FALSE;
617     }
618   }
619
620   BackToFront();
621   return(return_code);
622 }
623
624 int CheckChooseButtons(int mx, int my, int button)
625 {
626   int return_code = 0;
627   static int choice = -1;
628   static BOOL pressed = FALSE;
629   static int choose_button[5] =
630   {
631     BUTTON_OK,
632     BUTTON_NO
633   };
634
635   if (button)
636   {
637     if (!motion_status)         /* Maustaste neu gedrückt */
638     {
639       if (ON_CHOOSE_BUTTON(mx,my))
640       {
641         choice = CHOOSE_BUTTON(mx);
642         pressed = TRUE;
643         DrawChooseButton(choose_button[choice] | BUTTON_PRESSED);
644       }
645     }
646     else                        /* Mausbewegung bei gedrückter Maustaste */
647     {
648       if ((!ON_CHOOSE_BUTTON(mx,my) || CHOOSE_BUTTON(mx)!=choice) &&
649           choice>=0 && pressed)
650       {
651         pressed = FALSE;
652         DrawChooseButton(choose_button[choice] | BUTTON_RELEASED);
653       }
654       else if (ON_CHOOSE_BUTTON(mx,my) &&CHOOSE_BUTTON(mx)==choice && !pressed)
655       {
656         pressed = TRUE;
657         DrawChooseButton(choose_button[choice] | BUTTON_PRESSED);
658       }
659     }
660   }
661   else                          /* Maustaste wieder losgelassen */
662   {
663     if (ON_CHOOSE_BUTTON(mx,my) && CHOOSE_BUTTON(mx)==choice && pressed)
664     {
665       DrawChooseButton(choose_button[choice] | BUTTON_RELEASED);
666       return_code = choice+1;
667       choice = -1;
668       pressed = FALSE;
669     }
670     else
671     {
672       choice = -1;
673       pressed = FALSE;
674     }
675   }
676
677   BackToFront();
678   return(return_code);
679 }
680
681 int CheckConfirmButton(int mx, int my, int button)
682 {
683   int return_code = 0;
684   static int choice = -1;
685   static BOOL pressed = FALSE;
686
687   if (button)
688   {
689     if (!motion_status)         /* Maustaste neu gedrückt */
690     {
691       if (ON_CONFIRM_BUTTON(mx,my))
692       {
693         choice = 0;
694         pressed = TRUE;
695         DrawConfirmButton(BUTTON_PRESSED);
696       }
697     }
698     else                        /* Mausbewegung bei gedrückter Maustaste */
699     {
700       if (!ON_CONFIRM_BUTTON(mx,my) && choice>=0 && pressed)
701       {
702         pressed = FALSE;
703         DrawConfirmButton(BUTTON_RELEASED);
704       }
705       else if (ON_CONFIRM_BUTTON(mx,my) && !pressed)
706       {
707         pressed = TRUE;
708         DrawConfirmButton(BUTTON_PRESSED);
709       }
710     }
711   }
712   else                          /* Maustaste wieder losgelassen */
713   {
714     if (ON_CONFIRM_BUTTON(mx,my) && pressed)
715     {
716       DrawConfirmButton(BUTTON_RELEASED);
717       return_code = BUTTON_CONFIRM;
718       choice = -1;
719       pressed = FALSE;
720     }
721     else
722     {
723       choice = -1;
724       pressed = FALSE;
725     }
726   }
727
728   BackToFront();
729   return(return_code);
730 }
731
732 /* several buttons in the level editor */
733
734 int CheckEditButtons(int mx, int my, int button)
735 {
736   int return_code = 0;
737   static int choice = -1;
738   static BOOL pressed = FALSE;
739   static int edit_button[6] =
740   {
741     ED_BUTTON_CTRL,
742     ED_BUTTON_FILL,
743     ED_BUTTON_LEFT,
744     ED_BUTTON_UP,
745     ED_BUTTON_DOWN,
746     ED_BUTTON_RIGHT
747   };
748
749   if (button)
750   {
751     if (!motion_status)         /* Maustaste neu gedrückt */
752     {
753       if (ON_EDIT_BUTTON(mx,my))
754       {
755         choice = EDIT_BUTTON(mx,my);
756         pressed = TRUE;
757         DrawEditButton(edit_button[choice] | ED_BUTTON_PRESSED);
758         if (edit_button[choice]!=ED_BUTTON_CTRL &&
759             edit_button[choice]!=ED_BUTTON_FILL)
760           return_code = 1<<choice;
761       }
762     }
763     else                        /* Mausbewegung bei gedrückter Maustaste */
764     {
765       if ((!ON_EDIT_BUTTON(mx,my) || EDIT_BUTTON(mx,my)!=choice) &&
766           choice>=0 && pressed)
767       {
768         pressed = FALSE;
769         DrawEditButton(edit_button[choice] | ED_BUTTON_RELEASED);
770       }
771       else if (ON_EDIT_BUTTON(mx,my) && EDIT_BUTTON(mx,my)==choice)
772       {
773         if (!pressed)
774           DrawEditButton(edit_button[choice] | ED_BUTTON_PRESSED);
775         pressed = TRUE;
776         if (edit_button[choice]!=ED_BUTTON_CTRL &&
777             edit_button[choice]!=ED_BUTTON_FILL)
778           return_code = 1<<choice;
779       }
780     }
781   }
782   else                          /* Maustaste wieder losgelassen */
783   {
784     if (ON_EDIT_BUTTON(mx,my) && EDIT_BUTTON(mx,my)==choice && pressed)
785     {
786       DrawEditButton(edit_button[choice] | ED_BUTTON_RELEASED);
787       if (edit_button[choice]==ED_BUTTON_CTRL ||
788           edit_button[choice]==ED_BUTTON_FILL)
789         return_code = 1<<choice;
790       choice = -1;
791       pressed = FALSE;
792     }
793     else
794     {
795       choice = -1;
796       pressed = FALSE;
797     }
798   }
799
800   BackToFront();
801   return(return_code);
802 }
803
804 int CheckCtrlButtons(int mx, int my, int button)
805 {
806   int return_code = 0;
807   static int choice = -1;
808   static BOOL pressed = FALSE;
809   static int ctrl_button[4] =
810   {
811     ED_BUTTON_EDIT,
812     ED_BUTTON_CLEAR,
813     ED_BUTTON_UNDO,
814     ED_BUTTON_EXIT
815   };
816
817   if (button)
818   {
819     if (!motion_status)         /* Maustaste neu gedrückt */
820     {
821       if (ON_CTRL_BUTTON(mx,my))
822       {
823         choice = CTRL_BUTTON(mx,my);
824         pressed = TRUE;
825         DrawCtrlButton(ctrl_button[choice] | ED_BUTTON_PRESSED);
826       }
827     }
828     else                        /* Mausbewegung bei gedrückter Maustaste */
829     {
830       if ((!ON_CTRL_BUTTON(mx,my) || CTRL_BUTTON(mx,my)!=choice) &&
831           choice>=0 && pressed)
832       {
833         pressed = FALSE;
834         DrawCtrlButton(ctrl_button[choice] | ED_BUTTON_RELEASED);
835       }
836       else if (ON_CTRL_BUTTON(mx,my) && CTRL_BUTTON(mx,my)==choice && !pressed)
837       {
838         pressed = TRUE;
839         DrawCtrlButton(ctrl_button[choice] | ED_BUTTON_PRESSED);
840       }
841     }
842   }
843   else                          /* Maustaste wieder losgelassen */
844   {
845     if (ON_CTRL_BUTTON(mx,my) && CTRL_BUTTON(mx,my)==choice && pressed)
846     {
847       DrawCtrlButton(ctrl_button[choice] | ED_BUTTON_RELEASED);
848       return_code = 1<<(choice+6);
849       choice = -1;
850       pressed = FALSE;
851     }
852     else
853     {
854       choice = -1;
855       pressed = FALSE;
856     }
857   }
858
859   BackToFront();
860   return(return_code);
861 }
862
863 int CheckElemButtons(int mx, int my, int button)
864 {
865   int return_code = -1;
866   static int choice = -1;
867   static BOOL pressed = FALSE;
868
869   if (button)
870   {
871     if (!motion_status)         /* Maustaste neu gedrückt */
872     {
873       if (ON_ELEM_BUTTON(mx,my))
874       {
875         choice = ELEM_BUTTON(mx,my);
876         pressed = TRUE;
877         DrawElemButton(choice,ED_BUTTON_PRESSED);
878         if (choice==ED_BUTTON_EUP ||
879             choice==ED_BUTTON_EDOWN)
880           return_code = choice;
881       }
882     }
883     else                        /* Mausbewegung bei gedrückter Maustaste */
884     {
885       if ((!ON_ELEM_BUTTON(mx,my) || ELEM_BUTTON(mx,my)!=choice) &&
886           choice>=0 && pressed)
887       {
888         pressed = FALSE;
889         DrawElemButton(choice,ED_BUTTON_RELEASED);
890       }
891       else if (ON_ELEM_BUTTON(mx,my) && ELEM_BUTTON(mx,my)==choice)
892       {
893         if (!pressed)
894           DrawElemButton(choice,ED_BUTTON_PRESSED);
895         pressed = TRUE;
896         if (choice==ED_BUTTON_EUP ||
897             choice==ED_BUTTON_EDOWN)
898           return_code = choice;
899       }
900     }
901   }
902   else                          /* Maustaste wieder losgelassen */
903   {
904     if (ON_ELEM_BUTTON(mx,my) && ELEM_BUTTON(mx,my)==choice && pressed)
905     {
906       DrawElemButton(choice,ED_BUTTON_RELEASED);
907       if (choice!=ED_BUTTON_EUP &&
908           choice!=ED_BUTTON_EDOWN)
909         return_code = choice;
910       choice = -1;
911       pressed = FALSE;
912     }
913     else
914     {
915       choice = -1;
916       pressed = FALSE;
917     }
918   }
919
920   BackToFront();
921   return(return_code);
922 }
923
924 int CheckCountButtons(int mx, int my, int button)
925 {
926   int return_code = -1;
927   static int choice = -1;
928   static BOOL pressed = FALSE;
929
930   if (button)
931   {
932     if (!motion_status)         /* Maustaste neu gedrückt */
933     {
934       if (ON_COUNT_BUTTON(mx,my))
935       {
936         choice = COUNT_BUTTON(mx,my);
937         pressed = TRUE;
938         DrawCountButton(choice,ED_BUTTON_PRESSED);
939         return_code = choice;
940       }
941     }
942     else                        /* Mausbewegung bei gedrückter Maustaste */
943     {
944       if ((!ON_COUNT_BUTTON(mx,my) || COUNT_BUTTON(mx,my)!=choice) &&
945           choice>=0 && pressed)
946       {
947         pressed = FALSE;
948         DrawCountButton(choice,ED_BUTTON_RELEASED);
949       }
950       else if (ON_COUNT_BUTTON(mx,my) && COUNT_BUTTON(mx,my)==choice)
951       {
952         if (!pressed)
953           DrawCountButton(choice,ED_BUTTON_PRESSED);
954         pressed = TRUE;
955         return_code = choice;
956       }
957     }
958   }
959   else                          /* Maustaste wieder losgelassen */
960   {
961     if (ON_COUNT_BUTTON(mx,my) && COUNT_BUTTON(mx,my)==choice && pressed)
962     {
963       DrawCountButton(choice,ED_BUTTON_RELEASED);
964       choice = -1;
965       pressed = FALSE;
966     }
967     else
968     {
969       choice = -1;
970       pressed = FALSE;
971     }
972   }
973
974   BackToFront();
975   return(return_code);
976 }