rnd-20070320-3-src
[rocksndiamonds.git] / src / screens.c
1 /***********************************************************
2 * Rocks'n'Diamonds -- McDuffin Strikes Back!               *
3 *----------------------------------------------------------*
4 * (c) 1995-2006 Artsoft Entertainment                      *
5 *               Holger Schemel                             *
6 *               Detmolder Strasse 189                      *
7 *               33604 Bielefeld                            *
8 *               Germany                                    *
9 *               e-mail: info@artsoft.org                   *
10 *----------------------------------------------------------*
11 * screens.c                                                *
12 ***********************************************************/
13
14 #include "libgame/libgame.h"
15
16 #include "screens.h"
17 #include "events.h"
18 #include "game.h"
19 #include "tools.h"
20 #include "editor.h"
21 #include "files.h"
22 #include "tape.h"
23 #include "cartoons.h"
24 #include "network.h"
25 #include "init.h"
26 #include "config.h"
27
28 /* screens in the setup menu */
29 #define SETUP_MODE_MAIN                 0
30 #define SETUP_MODE_GAME                 1
31 #define SETUP_MODE_CHOOSE_GAME_SPEED    2
32 #define SETUP_MODE_EDITOR               3
33 #define SETUP_MODE_INPUT                4
34 #define SETUP_MODE_SHORTCUT_1           5
35 #define SETUP_MODE_SHORTCUT_2           6
36 #define SETUP_MODE_GRAPHICS             7
37 #define SETUP_MODE_CHOOSE_SCREEN_MODE   8
38 #define SETUP_MODE_SOUND                9
39 #define SETUP_MODE_ARTWORK              10
40 #define SETUP_MODE_CHOOSE_GRAPHICS      11
41 #define SETUP_MODE_CHOOSE_SOUNDS        12
42 #define SETUP_MODE_CHOOSE_MUSIC         13
43
44 #define MAX_SETUP_MODES                 14
45
46 /* for input setup functions */
47 #define SETUPINPUT_SCREEN_POS_START     0
48 #define SETUPINPUT_SCREEN_POS_END       (SCR_FIELDY - 4)
49 #define SETUPINPUT_SCREEN_POS_EMPTY1    (SETUPINPUT_SCREEN_POS_START + 3)
50 #define SETUPINPUT_SCREEN_POS_EMPTY2    (SETUPINPUT_SCREEN_POS_END - 1)
51
52 /* screens on the info screen */
53 #define INFO_MODE_MAIN                  0
54 #define INFO_MODE_TITLE                 1
55 #define INFO_MODE_ELEMENTS              2
56 #define INFO_MODE_MUSIC                 3
57 #define INFO_MODE_CREDITS               4
58 #define INFO_MODE_PROGRAM               5
59 #define INFO_MODE_VERSION               6
60 #define INFO_MODE_LEVELSET              7
61
62 #define MAX_INFO_MODES                  8
63
64 /* for various menu stuff  */
65 #define MENU_SCREEN_START_XPOS          1
66 #define MENU_SCREEN_START_YPOS          2
67 #define MENU_SCREEN_VALUE_XPOS          14
68 #define MENU_SCREEN_MAX_XPOS            (SCR_FIELDX - 1)
69 #define MENU_TITLE1_YPOS                8
70 #define MENU_TITLE2_YPOS                46
71 #define MAX_INFO_ELEMENTS_ON_SCREEN     10
72 #define MAX_MENU_ENTRIES_ON_SCREEN      (SCR_FIELDY - MENU_SCREEN_START_YPOS)
73 #define MAX_MENU_TEXT_LENGTH_BIG        (MENU_SCREEN_VALUE_XPOS -       \
74                                          MENU_SCREEN_START_XPOS)
75 #define MAX_MENU_TEXT_LENGTH_MEDIUM     (MAX_MENU_TEXT_LENGTH_BIG * 2)
76
77 /* buttons and scrollbars identifiers */
78 #define SCREEN_CTRL_ID_PREV_LEVEL       0
79 #define SCREEN_CTRL_ID_NEXT_LEVEL       1
80 #define SCREEN_CTRL_ID_PREV_PLAYER      2
81 #define SCREEN_CTRL_ID_NEXT_PLAYER      3
82 #define SCREEN_CTRL_ID_SCROLL_UP        4
83 #define SCREEN_CTRL_ID_SCROLL_DOWN      5
84 #define SCREEN_CTRL_ID_SCROLL_VERTICAL  6
85
86 #define NUM_SCREEN_GADGETS              7
87
88 #define NUM_SCREEN_MENUBUTTONS          4
89 #define NUM_SCREEN_SCROLLBUTTONS        2
90 #define NUM_SCREEN_SCROLLBARS           1
91
92 #define SCREEN_MASK_MAIN                (1 << 0)
93 #define SCREEN_MASK_INPUT               (1 << 1)
94
95 /* graphic position and size values for buttons and scrollbars */
96 #define SC_MENUBUTTON_XSIZE             TILEX
97 #define SC_MENUBUTTON_YSIZE             TILEY
98
99 #define SC_SCROLLBUTTON_XSIZE           TILEX
100 #define SC_SCROLLBUTTON_YSIZE           TILEY
101
102 #define SC_SCROLLBAR_XPOS               (SXSIZE - SC_SCROLLBUTTON_XSIZE)
103
104 #define SC_SCROLL_VERTICAL_XSIZE        SC_SCROLLBUTTON_XSIZE
105 #define SC_SCROLL_VERTICAL_YSIZE        ((MAX_MENU_ENTRIES_ON_SCREEN - 2) * \
106                                          SC_SCROLLBUTTON_YSIZE)
107
108 #define SC_SCROLL_UP_XPOS               SC_SCROLLBAR_XPOS
109 #define SC_SCROLL_UP_YPOS               (2 * SC_SCROLLBUTTON_YSIZE)
110
111 #define SC_SCROLL_VERTICAL_XPOS         SC_SCROLLBAR_XPOS
112 #define SC_SCROLL_VERTICAL_YPOS         (SC_SCROLL_UP_YPOS + \
113                                          SC_SCROLLBUTTON_YSIZE)
114
115 #define SC_SCROLL_DOWN_XPOS             SC_SCROLLBAR_XPOS
116 #define SC_SCROLL_DOWN_YPOS             (SC_SCROLL_VERTICAL_YPOS + \
117                                          SC_SCROLL_VERTICAL_YSIZE)
118
119 #define SC_BORDER_SIZE                  14
120
121 /* other useful macro definitions */
122 #define BUTTON_GRAPHIC_ACTIVE(g)                                               \
123         (g == IMG_MENU_BUTTON_LEFT       ? IMG_MENU_BUTTON_LEFT_ACTIVE       : \
124          g == IMG_MENU_BUTTON_RIGHT      ? IMG_MENU_BUTTON_RIGHT_ACTIVE      : \
125          g == IMG_MENU_BUTTON_UP         ? IMG_MENU_BUTTON_UP_ACTIVE         : \
126          g == IMG_MENU_BUTTON_DOWN       ? IMG_MENU_BUTTON_DOWN_ACTIVE       : \
127          g == IMG_MENU_BUTTON_LEAVE_MENU ? IMG_MENU_BUTTON_LEAVE_MENU_ACTIVE : \
128          g == IMG_MENU_BUTTON_ENTER_MENU ? IMG_MENU_BUTTON_ENTER_MENU_ACTIVE : \
129          g == IMG_MENU_BUTTON_PREV_LEVEL ? IMG_MENU_BUTTON_PREV_LEVEL_ACTIVE : \
130          g == IMG_MENU_BUTTON_NEXT_LEVEL ? IMG_MENU_BUTTON_NEXT_LEVEL_ACTIVE : \
131          IMG_MENU_BUTTON_ACTIVE)
132
133
134 /* forward declarations of internal functions */
135 static void HandleScreenGadgets(struct GadgetInfo *);
136 static void HandleSetupScreen_Generic(int, int, int, int, int);
137 static void HandleSetupScreen_Input(int, int, int, int, int);
138 static void CustomizeKeyboard(int);
139 static void CalibrateJoystick(int);
140 static void execSetupGame(void);
141 static void execSetupGraphics(void);
142 static void execSetupArtwork(void);
143 static void HandleChooseTree(int, int, int, int, int, TreeInfo **);
144
145 static void DrawChooseLevel(void);
146 static void DrawInfoScreen(void);
147 static void DrawAndFadeInInfoScreen(int);
148 static void DrawSetupScreen(void);
149
150 static void DrawInfoScreenExt(int, int);
151 static void DrawInfoScreen_NotAvailable(char *, char *);
152 static void DrawInfoScreen_HelpAnim(int, int, boolean);
153 static void DrawInfoScreen_HelpText(int, int, int, int);
154 static void HandleInfoScreen_Main(int, int, int, int, int);
155 static void HandleInfoScreen_TitleScreen(int);
156 static void HandleInfoScreen_Elements(int);
157 static void HandleInfoScreen_Music(int);
158 static void HandleInfoScreen_Credits(int);
159 static void HandleInfoScreen_Program(int);
160 static void HandleInfoScreen_Version(int);
161
162 static void MapScreenMenuGadgets(int);
163 static void MapScreenTreeGadgets(TreeInfo *);
164
165 static struct GadgetInfo *screen_gadget[NUM_SCREEN_GADGETS];
166
167 static int setup_mode = SETUP_MODE_MAIN;
168 static int info_mode = INFO_MODE_MAIN;
169
170 static TreeInfo *screen_modes = NULL;
171 static TreeInfo *screen_mode_current = NULL;
172
173 static TreeInfo *game_speeds = NULL;
174 static TreeInfo *game_speed_current = NULL;
175
176 static struct
177 {
178   int value;
179   char *text;
180 } game_speeds_list[] =
181 {
182 #if 1
183   {     30,     "Very Slow"                     },
184   {     25,     "Slow"                          },
185   {     20,     "Normal"                        },
186   {     15,     "Fast"                          },
187   {     10,     "Very Fast"                     },
188 #else
189   {     1000,   "1/1s (Extremely Slow)"         },
190   {     500,    "1/2s"                          },
191   {     200,    "1/5s"                          },
192   {     100,    "1/10s"                         },
193   {     50,     "1/20s"                         },
194   {     29,     "1/35s (Original Supaplex)"     },
195   {     25,     "1/40s"                         },
196   {     20,     "1/50s (Normal Speed)"          },
197   {     14,     "1/70s (Maximum Supaplex)"      },
198   {     10,     "1/100s"                        },
199   {     5,      "1/200s"                        },
200   {     2,      "1/500s"                        },
201   {     1,      "1/1000s (Extremely Fast)"      },
202 #endif
203
204   {     -1,     NULL                            },
205 };
206
207 #define XFADE   1
208
209 #define DRAW_MODE(s)            ((s) >= GAME_MODE_MAIN &&               \
210                                  (s) <= GAME_MODE_SETUP ? (s) :         \
211                                  (s) == GAME_MODE_PSEUDO_TYPENAME ?     \
212                                  GAME_MODE_MAIN : GAME_MODE_DEFAULT)
213
214 #define DRAW_MODE_INFO(i)       ((i) >= INFO_MODE_ELEMENTS &&           \
215                                  (i) <= INFO_MODE_LEVELSET ? (i) :      \
216                                  INFO_MODE_MAIN)
217
218 #define DRAW_XOFFSET_INFO(i)    (DRAW_MODE_INFO(i) == INFO_MODE_MAIN ?  \
219                                  menu.draw_xoffset[GAME_MODE_INFO] :    \
220                                  menu.draw_xoffset_info[DRAW_MODE_INFO(i)])
221 #define DRAW_YOFFSET_INFO(i)    (DRAW_MODE_INFO(i) == INFO_MODE_MAIN ?  \
222                                  menu.draw_yoffset[GAME_MODE_INFO] :    \
223                                  menu.draw_yoffset_info[DRAW_MODE_INFO(i)])
224
225 #define DRAW_XOFFSET(s)         ((s) == GAME_MODE_INFO ?                \
226                                  DRAW_XOFFSET_INFO(info_mode) :         \
227                                  menu.draw_xoffset[DRAW_MODE(s)])
228 #define DRAW_YOFFSET(s)         ((s) == GAME_MODE_INFO ?                \
229                                  DRAW_YOFFSET_INFO(info_mode) :         \
230                                  menu.draw_yoffset[DRAW_MODE(s)])
231
232 #define mSX                     (SX + DRAW_XOFFSET(game_status))
233 #define mSY                     (SY + DRAW_YOFFSET(game_status))
234
235 #define NUM_MENU_ENTRIES_ON_SCREEN (menu.list_size[game_status] > 2 ?   \
236                                     menu.list_size[game_status] :       \
237                                     MAX_MENU_ENTRIES_ON_SCREEN)
238
239 #if defined(TARGET_X11_NATIVE_PERFORMANCE_WORKAROUND)
240 #define NUM_SCROLLBAR_BITMAPS           2
241 static Bitmap *scrollbar_bitmap[NUM_SCROLLBAR_BITMAPS];
242 #endif
243
244
245 /* title display and control definitions */
246
247 #define MAX_NUM_TITLE_SCREENS   (2 * MAX_NUM_TITLE_IMAGES +             \
248                                  2 * MAX_NUM_TITLE_MESSAGES)
249
250 static int num_title_screens = 0;
251
252 struct TitleControlInfo
253 {
254   boolean is_image;
255   boolean initial;
256   int local_nr;
257   int sort_priority;
258 };
259
260 struct TitleControlInfo title_controls[MAX_NUM_TITLE_SCREENS];
261
262 /* main menu display and control definitions */
263
264 #define MAIN_CONTROL_NAME                       0
265 #define MAIN_CONTROL_LEVELS                     1
266 #define MAIN_CONTROL_SCORES                     2
267 #define MAIN_CONTROL_EDITOR                     3
268 #define MAIN_CONTROL_INFO                       4
269 #define MAIN_CONTROL_GAME                       5
270 #define MAIN_CONTROL_SETUP                      6
271 #define MAIN_CONTROL_QUIT                       7
272 #define MAIN_CONTROL_PREV_LEVEL                 8
273 #define MAIN_CONTROL_NEXT_LEVEL                 9
274 #define MAIN_CONTROL_FIRST_LEVEL                10
275 #define MAIN_CONTROL_LAST_LEVEL                 11
276 #define MAIN_CONTROL_LEVEL_NUMBER               12
277 #define MAIN_CONTROL_LEVEL_INFO_1               13
278 #define MAIN_CONTROL_LEVEL_INFO_2               14
279 #define MAIN_CONTROL_LEVEL_NAME                 15
280 #define MAIN_CONTROL_LEVEL_AUTHOR               16
281 #define MAIN_CONTROL_LEVEL_YEAR                 17
282 #define MAIN_CONTROL_LEVEL_IMPORTED_FROM        18
283 #define MAIN_CONTROL_LEVEL_IMPORTED_BY          19
284 #define MAIN_CONTROL_LEVEL_TESTED_BY            20
285 #define MAIN_CONTROL_TITLE_1                    21
286 #define MAIN_CONTROL_TITLE_2                    22
287 #define MAIN_CONTROL_TITLE_3                    23
288
289 static char str_main_text_name[10];
290 static char str_main_text_first_level[10];
291 static char str_main_text_last_level[10];
292 static char str_main_text_level_number[10];
293
294 static char *main_text_name                     = str_main_text_name;
295 static char *main_text_first_level              = str_main_text_first_level;
296 static char *main_text_last_level               = str_main_text_last_level;
297 static char *main_text_level_number             = str_main_text_level_number;
298 static char *main_text_levels                   = "Levelset";
299 static char *main_text_scores                   = "Hall Of Fame";
300 static char *main_text_editor                   = "Level Creator";
301 static char *main_text_info                     = "Info Screen";
302 static char *main_text_game                     = "Start Game";
303 static char *main_text_setup                    = "Setup";
304 static char *main_text_quit                     = "Quit";
305 static char *main_text_level_name               = level.name;
306 static char *main_text_level_author             = level.author;
307 static char *main_text_level_year               = NULL;
308 static char *main_text_level_imported_from      = NULL;
309 static char *main_text_level_imported_by        = NULL;
310 static char *main_text_level_tested_by          = NULL;
311 static char *main_text_title_1                  = PROGRAM_TITLE_STRING;
312 static char *main_text_title_2                  = PROGRAM_COPYRIGHT_STRING;
313 static char *main_text_title_3                  = PROGRAM_GAME_BY_STRING;
314
315 struct MainControlInfo
316 {
317   int nr;
318
319   struct MenuPosInfo *pos_button;
320   int button_graphic;
321
322   struct TextPosInfo *pos_text;
323   char **text;
324
325   struct TextPosInfo *pos_input;
326   char **input;
327 };
328
329 static struct MainControlInfo main_controls[] =
330 {
331   {
332     MAIN_CONTROL_NAME,
333     &menu.main.button.name,             IMG_MENU_BUTTON,
334     &menu.main.text.name,               &main_text_name,
335     &menu.main.input.name,              &setup.player_name,
336   },
337   {
338     MAIN_CONTROL_LEVELS,
339     &menu.main.button.levels,           IMG_MENU_BUTTON_ENTER_MENU,
340     &menu.main.text.levels,             &main_text_levels,
341     NULL,                               NULL,
342   },
343   {
344     MAIN_CONTROL_SCORES,
345     &menu.main.button.scores,           IMG_MENU_BUTTON,
346     &menu.main.text.scores,             &main_text_scores,
347     NULL,                               NULL,
348   },
349   {
350     MAIN_CONTROL_EDITOR,
351     &menu.main.button.editor,           IMG_MENU_BUTTON,
352     &menu.main.text.editor,             &main_text_editor,
353     NULL,                               NULL,
354   },
355   {
356     MAIN_CONTROL_INFO,
357     &menu.main.button.info,             IMG_MENU_BUTTON_ENTER_MENU,
358     &menu.main.text.info,               &main_text_info,
359     NULL,                               NULL,
360   },
361   {
362     MAIN_CONTROL_GAME,
363     &menu.main.button.game,             IMG_MENU_BUTTON,
364     &menu.main.text.game,               &main_text_game,
365     NULL,                               NULL,
366   },
367   {
368     MAIN_CONTROL_SETUP,
369     &menu.main.button.setup,            IMG_MENU_BUTTON_ENTER_MENU,
370     &menu.main.text.setup,              &main_text_setup,
371     NULL,                               NULL,
372   },
373   {
374     MAIN_CONTROL_QUIT,
375     &menu.main.button.quit,             IMG_MENU_BUTTON,
376     &menu.main.text.quit,               &main_text_quit,
377     NULL,                               NULL,
378   },
379 #if 0
380   /* (these two buttons are real gadgets) */
381   {
382     MAIN_CONTROL_PREV_LEVEL,
383     &menu.main.button.prev_level,       IMG_MENU_BUTTON_PREV_LEVEL,
384     NULL,                               NULL,
385     NULL,                               NULL,
386   },
387   {
388     MAIN_CONTROL_NEXT_LEVEL,
389     &menu.main.button.next_level,       IMG_MENU_BUTTON_NEXT_LEVEL,
390     NULL,                               NULL,
391     NULL,                               NULL,
392   },
393 #endif
394   {
395     MAIN_CONTROL_FIRST_LEVEL,
396     NULL,                               -1,
397     &menu.main.text.first_level,        &main_text_first_level,
398     NULL,                               NULL,
399   },
400   {
401     MAIN_CONTROL_LAST_LEVEL,
402     NULL,                               -1,
403     &menu.main.text.last_level,         &main_text_last_level,
404     NULL,                               NULL,
405   },
406   {
407     MAIN_CONTROL_LEVEL_NUMBER,
408     NULL,                               -1,
409     &menu.main.text.level_number,       &main_text_level_number,
410     NULL,                               NULL,
411   },
412   {
413     MAIN_CONTROL_LEVEL_INFO_1,
414     NULL,                               -1,
415     &menu.main.text.level_info_1,       NULL,
416     NULL,                               NULL,
417   },
418   {
419     MAIN_CONTROL_LEVEL_INFO_2,
420     NULL,                               -1,
421     &menu.main.text.level_info_2,       NULL,
422     NULL,                               NULL,
423   },
424   {
425     MAIN_CONTROL_LEVEL_NAME,
426     NULL,                               -1,
427     &menu.main.text.level_name,         &main_text_level_name,
428     NULL,                               NULL,
429   },
430   {
431     MAIN_CONTROL_LEVEL_AUTHOR,
432     NULL,                               -1,
433     &menu.main.text.level_author,       &main_text_level_author,
434     NULL,                               NULL,
435   },
436   {
437     MAIN_CONTROL_LEVEL_YEAR,
438     NULL,                               -1,
439     &menu.main.text.level_year,         &main_text_level_year,
440     NULL,                               NULL,
441   },
442   {
443     MAIN_CONTROL_LEVEL_IMPORTED_FROM,
444     NULL,                               -1,
445     &menu.main.text.level_imported_from, &main_text_level_imported_from,
446     NULL,                               NULL,
447   },
448   {
449     MAIN_CONTROL_LEVEL_IMPORTED_BY,
450     NULL,                               -1,
451     &menu.main.text.level_imported_by,  &main_text_level_imported_by,
452     NULL,                               NULL,
453   },
454   {
455     MAIN_CONTROL_LEVEL_TESTED_BY,
456     NULL,                               -1,
457     &menu.main.text.level_tested_by,    &main_text_level_tested_by,
458     NULL,                               NULL,
459   },
460   {
461     MAIN_CONTROL_TITLE_1,
462     NULL,                               -1,
463     &menu.main.text.title_1,            &main_text_title_1,
464     NULL,                               NULL,
465   },
466   {
467     MAIN_CONTROL_TITLE_2,
468     NULL,                               -1,
469     &menu.main.text.title_2,            &main_text_title_2,
470     NULL,                               NULL,
471   },
472   {
473     MAIN_CONTROL_TITLE_3,
474     NULL,                               -1,
475     &menu.main.text.title_3,            &main_text_title_3,
476     NULL,                               NULL,
477   },
478
479   {
480     -1,
481     NULL,                               -1,
482     NULL,                               NULL,
483     NULL,                               NULL,
484   }
485 };
486
487
488 static int getTitleScreenGraphic(int nr, boolean initial)
489 {
490   return (initial ? IMG_TITLESCREEN_INITIAL_1 : IMG_TITLESCREEN_1) + nr;
491 }
492
493 static struct TitleMessageInfo *getTitleMessageInfo(int nr, boolean initial)
494 {
495   return (initial ? &titlemessage_initial[nr] : &titlemessage[nr]);
496 }
497
498 #if 0
499 static int getTitleScreenGameMode(boolean initial)
500 {
501   return (initial ? GAME_MODE_TITLE_INITIAL : GAME_MODE_TITLE);
502 }
503 #endif
504
505 static int getTitleMessageGameMode(boolean initial)
506 {
507   return (initial ? GAME_MODE_TITLE_INITIAL : GAME_MODE_TITLE);
508 }
509
510 #if 0
511 static int getTitleScreenBackground(boolean initial)
512 {
513   return (initial ? IMG_BACKGROUND_TITLE_INITIAL : IMG_BACKGROUND_TITLE);
514 }
515 #endif
516
517 #if 0
518 static int getTitleMessageBackground(int nr, boolean initial)
519 {
520   return (initial ? IMG_BACKGROUND_TITLE_INITIAL : IMG_BACKGROUND_TITLE);
521 }
522 #endif
523
524 static int getTitleBackground(int nr, boolean initial, boolean is_image)
525 {
526   int base = (is_image ?
527               (initial ? IMG_BACKGROUND_TITLESCREEN_INITIAL_1 :
528                          IMG_BACKGROUND_TITLESCREEN_1) :
529               (initial ? IMG_BACKGROUND_TITLEMESSAGE_INITIAL_1 :
530                          IMG_BACKGROUND_TITLEMESSAGE_1));
531   int graphic_global = (initial ? IMG_BACKGROUND_TITLE_INITIAL :
532                                   IMG_BACKGROUND_TITLE);
533   int graphic_local = base + nr;
534
535   if (graphic_info[graphic_local].bitmap != NULL)
536     return graphic_local;
537
538   if (graphic_info[graphic_global].bitmap != NULL)
539     return graphic_global;
540
541   return IMG_UNDEFINED;
542 }
543
544 static int getTitleSound(struct TitleControlInfo *tci)
545 {
546   boolean is_image = tci->is_image;
547   int initial = tci->initial;
548   int nr = tci->local_nr;
549   int mode = (initial ? GAME_MODE_TITLE_INITIAL : GAME_MODE_TITLE);
550   int base = (is_image ?
551               (initial ? SND_BACKGROUND_TITLESCREEN_INITIAL_1 :
552                          SND_BACKGROUND_TITLESCREEN_1) :
553               (initial ? SND_BACKGROUND_TITLEMESSAGE_INITIAL_1 :
554                          SND_BACKGROUND_TITLEMESSAGE_1));
555   int sound_global = menu.sound[mode];
556   int sound_local = base + nr;
557
558 #if 0
559   printf("::: %d, %d, %d: %d ['%s'], %d ['%s']\n",
560          nr, initial, is_image,
561          sound_global, getSoundListEntry(sound_global)->filename,
562          sound_local, getSoundListEntry(sound_local)->filename);
563 #endif
564
565   if (!strEqual(getSoundListEntry(sound_local)->filename, UNDEFINED_FILENAME))
566     return sound_local;
567
568   if (!strEqual(getSoundListEntry(sound_global)->filename, UNDEFINED_FILENAME))
569     return sound_global;
570
571   return SND_UNDEFINED;
572 }
573
574 static int getTitleMusic(struct TitleControlInfo *tci)
575 {
576   boolean is_image = tci->is_image;
577   int initial = tci->initial;
578   int nr = tci->local_nr;
579   int mode = (initial ? GAME_MODE_TITLE_INITIAL : GAME_MODE_TITLE);
580   int base = (is_image ?
581               (initial ? MUS_BACKGROUND_TITLESCREEN_INITIAL_1 :
582                          MUS_BACKGROUND_TITLESCREEN_1) :
583               (initial ? MUS_BACKGROUND_TITLEMESSAGE_INITIAL_1 :
584                          MUS_BACKGROUND_TITLEMESSAGE_1));
585   int music_global = menu.music[mode];
586   int music_local = base + nr;
587
588 #if 0
589   printf("::: %d, %d, %d: %d ['%s'], %d ['%s']\n",
590          nr, initial, is_image,
591          music_global, getMusicListEntry(music_global)->filename,
592          music_local, getMusicListEntry(music_local)->filename);
593 #endif
594
595   if (!strEqual(getMusicListEntry(music_local)->filename, UNDEFINED_FILENAME))
596     return music_local;
597
598   if (!strEqual(getMusicListEntry(music_global)->filename, UNDEFINED_FILENAME))
599     return music_global;
600
601   return MUS_UNDEFINED;
602 }
603
604 static struct TitleFadingInfo getTitleFading(struct TitleControlInfo *tci)
605 {
606   boolean is_image = tci->is_image;
607   int initial = tci->initial;
608   int nr = tci->local_nr;
609   struct TitleFadingInfo ti;
610
611   if (is_image)
612   {
613     int graphic = getTitleScreenGraphic(nr, initial);
614
615     /* initialize fading control values to default title config settings */
616     ti = (initial ? title_initial_default : title_default);
617
618     /* override default settings with image config settings, if defined */
619     if (graphic_info[graphic].anim_mode != ANIM_DEFAULT)
620       ti.anim_mode = graphic_info[graphic].anim_mode;
621     if (graphic_info[graphic].fade_delay > -1)
622       ti.fade_delay = graphic_info[graphic].fade_delay;
623     if (graphic_info[graphic].post_delay > -1)
624       ti.post_delay = graphic_info[graphic].post_delay;
625     if (graphic_info[graphic].auto_delay > -1)
626       ti.auto_delay = graphic_info[graphic].auto_delay;
627   }
628   else
629   {
630     if (initial)
631     {
632       ti.anim_mode  = titlemessage_initial[nr].anim_mode;
633       ti.fade_delay = titlemessage_initial[nr].fade_delay;
634       ti.post_delay = titlemessage_initial[nr].post_delay;
635       ti.auto_delay = titlemessage_initial[nr].auto_delay;
636     }
637     else
638     {
639       ti.anim_mode  = titlemessage[nr].anim_mode;
640       ti.fade_delay = titlemessage[nr].fade_delay;
641       ti.post_delay = titlemessage[nr].post_delay;
642       ti.auto_delay = titlemessage[nr].auto_delay;
643     }
644   }
645
646 #if 0
647   if (ti.anim_mode == ANIM_NONE)
648     ti.fade_delay = ti.post_delay = 0;
649 #endif
650
651   return ti;
652 }
653
654 static int compareTitleControlInfo(const void *object1, const void *object2)
655 {
656   const struct TitleControlInfo *tci1 = (struct TitleControlInfo *)object1;
657   const struct TitleControlInfo *tci2 = (struct TitleControlInfo *)object2;
658   int compare_result;
659
660   if (tci1->initial != tci2->initial)
661     compare_result = (tci1->initial ? -1 : +1);
662   else if (tci1->sort_priority != tci2->sort_priority)
663     compare_result = tci1->sort_priority - tci2->sort_priority;
664   else if (tci1->is_image != tci2->is_image)
665     compare_result = (tci1->is_image ? -1 : +1);
666   else
667     compare_result = tci1->local_nr - tci2->local_nr;
668
669   return compare_result;
670 }
671
672 static void InitializeTitleControlsExt_AddTitleInfo(boolean is_image,
673                                                     boolean initial,
674                                                     int nr, int sort_priority)
675 {
676   title_controls[num_title_screens].is_image = is_image;
677   title_controls[num_title_screens].initial = initial;
678   title_controls[num_title_screens].local_nr = nr;
679   title_controls[num_title_screens].sort_priority = sort_priority;
680
681   num_title_screens++;
682 }
683
684 static void InitializeTitleControls_CheckTitleInfo(boolean initial)
685 {
686   int i;
687
688   for (i = 0; i < MAX_NUM_TITLE_IMAGES; i++)
689   {
690     int graphic = getTitleScreenGraphic(i, initial);
691     Bitmap *bitmap = graphic_info[graphic].bitmap;
692     int sort_priority = graphic_info[graphic].sort_priority;
693
694     if (bitmap != NULL)
695       InitializeTitleControlsExt_AddTitleInfo(TRUE, initial, i, sort_priority);
696   }
697
698   for (i = 0; i < MAX_NUM_TITLE_MESSAGES; i++)
699   {
700     struct TitleMessageInfo *tmi = getTitleMessageInfo(i, initial);
701     char *filename = getLevelSetTitleMessageFilename(i, initial);
702     int sort_priority = tmi->sort_priority;
703
704     if (filename != NULL)
705       InitializeTitleControlsExt_AddTitleInfo(FALSE, initial, i, sort_priority);
706   }
707 }
708
709 static void InitializeTitleControls(boolean show_title_initial)
710 {
711   num_title_screens = 0;
712
713   if (show_title_initial)
714     InitializeTitleControls_CheckTitleInfo(TRUE);
715
716   InitializeTitleControls_CheckTitleInfo(FALSE);
717
718   /* sort title screens according to sort_priority and title number */
719   qsort(title_controls, num_title_screens, sizeof(struct TitleControlInfo),
720         compareTitleControlInfo);
721 }
722
723 static boolean visibleMenuPos(struct MenuPosInfo *pos)
724 {
725   return (pos != NULL && pos->x != -1 && pos->y != -1);
726 }
727
728 static boolean visibleTextPos(struct TextPosInfo *pos)
729 {
730   return (pos != NULL && pos->x != -1 && pos->y != -1);
731 }
732
733 static void InitializeMainControls()
734 {
735   boolean local_team_mode = (!options.network && setup.team_mode);
736   int i;
737
738   /* set main control text values to dynamically determined values */
739   sprintf(main_text_name,         "%s",   local_team_mode ? "Team:" : "Name:");
740   sprintf(main_text_first_level,  "%03d", leveldir_current->first_level);
741   sprintf(main_text_last_level,   "%03d", leveldir_current->last_level);
742   sprintf(main_text_level_number, "%s",   int2str(level_nr, 3));
743
744   main_text_level_year          = leveldir_current->year;
745   main_text_level_imported_from = leveldir_current->imported_from;
746   main_text_level_imported_by   = leveldir_current->imported_by;
747   main_text_level_tested_by     = leveldir_current->tested_by;
748
749   /* set main control screen positions to dynamically determined values */
750   for (i = 0; main_controls[i].nr != -1; i++)
751   {
752     struct MainControlInfo *mci = &main_controls[i];
753     int nr                         = mci->nr;
754     struct MenuPosInfo *pos_button = mci->pos_button;
755     struct TextPosInfo *pos_text   = mci->pos_text;
756     struct TextPosInfo *pos_input  = mci->pos_input;
757     char *text                     = (mci->text  ? *mci->text  : NULL);
758     char *input                    = (mci->input ? *mci->input : NULL);
759     int button_graphic             = mci->button_graphic;
760 #if 1
761     int font_text                  = (pos_text  ? pos_text->font  : -1);
762     int font_input                 = (pos_input ? pos_input->font : -1);
763 #else
764     int font_text                  = mci->font_text;
765     int font_input                 = mci->font_input;
766 #endif
767
768     int font_text_width   = (font_text  != -1 ? getFontWidth(font_text)   : 0);
769     int font_text_height  = (font_text  != -1 ? getFontHeight(font_text)  : 0);
770     int font_input_width  = (font_input != -1 ? getFontWidth(font_input)  : 0);
771     int font_input_height = (font_input != -1 ? getFontHeight(font_input) : 0);
772     int text_chars  = (text  != NULL ? strlen(text)  : 0);
773     int input_chars = (input != NULL ? strlen(input) : 0);
774
775     int button_width =
776       (button_graphic != -1 ? graphic_info[button_graphic].width  : 0);
777     int button_height =
778       (button_graphic != -1 ? graphic_info[button_graphic].height : 0);
779     int text_width   = font_text_width * text_chars;
780     int text_height  = font_text_height;
781     int input_width  = font_input_width * input_chars;
782     int input_height = font_input_height;
783
784     if (nr == MAIN_CONTROL_NAME)
785     {
786 #if 0
787       if (menu.main.input.name.x == -1)
788         menu.main.input.name.x = menu.main.text.name.x + text_width;
789       if (menu.main.input.name.y == -1)
790         menu.main.input.name.y = menu.main.text.name.y;
791 #endif
792
793 #if 1
794       menu.main.input.name.width  = input_width;
795       menu.main.input.name.height = input_height;
796 #else
797       menu.main.input.name.width  = font_input_width * MAX_PLAYER_NAME_LEN;
798       menu.main.input.name.height = font_input_height;
799 #endif
800     }
801
802     if (pos_button != NULL)             /* (x/y may be -1/-1 here) */
803     {
804       if (pos_button->width == 0)
805         pos_button->width = button_width;
806       if (pos_button->height == 0)
807         pos_button->height = button_height;
808     }
809
810     if (pos_text != NULL)               /* (x/y may be -1/-1 here) */
811     {
812       /* calculate width for non-clickable text -- needed for text alignment */
813       boolean calculate_text_width = (pos_button == NULL && text != NULL);
814
815       if (visibleMenuPos(pos_button))
816       {
817         if (pos_text->x == -1)
818           pos_text->x = pos_button->x + pos_button->width;
819         if (pos_text->y == -1)
820           pos_text->y = pos_button->y;
821       }
822
823       if (pos_text->width == -1 || calculate_text_width)
824         pos_text->width = text_width;
825       if (pos_text->height == -1)
826         pos_text->height = text_height;
827     }
828
829     if (pos_input != NULL)              /* (x/y may be -1/-1 here) */
830     {
831       if (visibleTextPos(pos_text))
832       {
833         if (pos_input->x == -1)
834           pos_input->x = pos_text->x + pos_text->width;
835         if (pos_input->y == -1)
836           pos_input->y = pos_text->y;
837       }
838
839       if (pos_input->width == -1)
840         pos_input->width = input_width;
841       if (pos_input->height == -1)
842         pos_input->height = input_height;
843     }
844   }
845 }
846
847 static void DrawCursorAndText_Main_Ext(int nr, boolean active_text,
848                                        boolean active_input)
849 {
850   int i;
851
852   for (i = 0; main_controls[i].nr != -1; i++)
853   {
854     struct MainControlInfo *mci = &main_controls[i];
855
856     if (mci->nr == nr || nr == -1)
857     {
858       struct MenuPosInfo *pos_button = mci->pos_button;
859       struct TextPosInfo *pos_text   = mci->pos_text;
860       struct TextPosInfo *pos_input  = mci->pos_input;
861       char *text                     = (mci->text  ? *mci->text  : NULL);
862       char *input                    = (mci->input ? *mci->input : NULL);
863       int button_graphic             = mci->button_graphic;
864 #if 1
865       int font_text                  = (pos_text  ? pos_text->font  : -1);
866       int font_input                 = (pos_input ? pos_input->font : -1);
867 #else
868       int font_text                  = mci->font_text;
869       int font_input                 = mci->font_input;
870 #endif
871
872       if (active_text)
873       {
874         button_graphic = BUTTON_GRAPHIC_ACTIVE(button_graphic);
875         font_text = FONT_ACTIVE(font_text);
876       }
877
878       if (active_input)
879       {
880         font_input = FONT_ACTIVE(font_input);
881       }
882
883       if (visibleMenuPos(pos_button))
884       {
885         struct MenuPosInfo *pos = pos_button;
886         int x = mSX + pos->x;
887         int y = mSY + pos->y;
888
889         DrawBackgroundForGraphic(x, y, pos->width, pos->height, button_graphic);
890         DrawGraphicThruMaskExt(drawto, x, y, button_graphic, 0);
891       }
892
893       if (visibleTextPos(pos_text) && text != NULL)
894       {
895         struct TextPosInfo *pos = pos_text;
896         int x = mSX + ALIGNED_TEXT_XPOS(pos);
897         int y = mSY + ALIGNED_TEXT_YPOS(pos);
898
899 #if 1
900         /* (check why/if this is needed) */
901         DrawBackgroundForFont(x, y, pos->width, pos->height, font_text);
902 #endif
903         DrawText(x, y, text, font_text);
904       }
905
906       if (visibleTextPos(pos_input) && input != NULL)
907       {
908         struct TextPosInfo *pos = pos_input;
909         int x = mSX + ALIGNED_TEXT_XPOS(pos);
910         int y = mSY + ALIGNED_TEXT_YPOS(pos);
911
912 #if 1
913         /* (check why/if this is needed) */
914         DrawBackgroundForFont(x, y, pos->width, pos->height, font_input);
915 #endif
916         DrawText(x, y, input, font_input);
917       }
918     }
919   }
920 }
921
922 static void DrawCursorAndText_Main(int nr, boolean active_text)
923 {
924   DrawCursorAndText_Main_Ext(nr, active_text, FALSE);
925 }
926
927 #if 0
928 static void DrawCursorAndText_Main_Input(int nr, boolean active_text)
929 {
930   DrawCursorAndText_Main_Ext(nr, active_text, TRUE);
931 }
932 #endif
933
934 static struct MainControlInfo *getMainControlInfo(int nr)
935 {
936   int i;
937
938   for (i = 0; main_controls[i].nr != -1; i++)
939     if (main_controls[i].nr == nr)
940       return &main_controls[i];
941
942   return NULL;
943 }
944
945 static boolean insideMenuPosRect(struct MenuPosInfo *rect, int x, int y)
946 {
947   if (rect == NULL)
948     return FALSE;
949
950   int rect_x = ALIGNED_TEXT_XPOS(rect);
951   int rect_y = ALIGNED_TEXT_YPOS(rect);
952
953   return (x >= rect_x && x < rect_x + rect->width &&
954           y >= rect_y && y < rect_y + rect->height);
955 }
956
957 static boolean insideTextPosRect(struct TextPosInfo *rect, int x, int y)
958 {
959   if (rect == NULL)
960     return FALSE;
961
962   int rect_x = ALIGNED_TEXT_XPOS(rect);
963   int rect_y = ALIGNED_TEXT_YPOS(rect);
964
965   return (x >= rect_x && x < rect_x + rect->width &&
966           y >= rect_y && y < rect_y + rect->height);
967 }
968
969 static void drawCursorExt(int xpos, int ypos, boolean active, int graphic)
970 {
971   static int cursor_array[SCR_FIELDY];
972   int x = mSX + TILEX * xpos;
973   int y = mSY + TILEY * (MENU_SCREEN_START_YPOS + ypos);
974
975   if (xpos == 0)
976   {
977     if (graphic != -1)
978       cursor_array[ypos] = graphic;
979     else
980       graphic = cursor_array[ypos];
981   }
982
983   if (active)
984     graphic = BUTTON_GRAPHIC_ACTIVE(graphic);
985
986   DrawBackgroundForGraphic(x, y, TILEX, TILEY, graphic);
987   DrawGraphicThruMaskExt(drawto, x, y, graphic, 0);
988 }
989
990 static void initCursor(int ypos, int graphic)
991 {
992   drawCursorExt(0, ypos, FALSE, graphic);
993 }
994
995 static void drawCursor(int ypos, boolean active)
996 {
997   drawCursorExt(0, ypos, active, -1);
998 }
999
1000 static void drawCursorXY(int xpos, int ypos, int graphic)
1001 {
1002   drawCursorExt(xpos, ypos, FALSE, graphic);
1003 }
1004
1005 static void drawChooseTreeCursor(int ypos, boolean active)
1006 {
1007   int last_game_status = game_status;   /* save current game status */
1008
1009   /* force LEVELS draw offset on artwork setup screen */
1010   game_status = GAME_MODE_LEVELS;
1011
1012   drawCursorExt(0, ypos, active, -1);
1013
1014   game_status = last_game_status;       /* restore current game status */
1015 }
1016
1017 void DrawHeadline()
1018 {
1019   DrawTextSCentered(MENU_TITLE1_YPOS, FONT_TITLE_1, PROGRAM_TITLE_STRING);
1020   DrawTextSCentered(MENU_TITLE2_YPOS, FONT_TITLE_2, PROGRAM_COPYRIGHT_STRING);
1021 }
1022
1023 #if 0
1024 static int getPrevlevelButtonPos()
1025 {
1026   return 10;
1027 }
1028
1029 static int getCurrentLevelTextPos()
1030 {
1031   return (getPrevlevelButtonPos() + 1);
1032 }
1033
1034 static int getNextLevelButtonPos()
1035 {
1036   return getPrevlevelButtonPos() + 3 + 1;
1037 }
1038
1039 static int getLevelRangeTextPos()
1040 {
1041   return getNextLevelButtonPos() + 1;
1042 }
1043 #endif
1044
1045 int effectiveGameStatus()
1046 {
1047   if (game_status == GAME_MODE_INFO && info_mode == INFO_MODE_TITLE)
1048     return GAME_MODE_TITLE;
1049
1050   return game_status;
1051 }
1052
1053 void DrawTitleScreenImage(int nr, boolean initial)
1054 {
1055   int graphic = getTitleScreenGraphic(nr, initial);
1056   Bitmap *bitmap = graphic_info[graphic].bitmap;
1057 #if 1
1058   int width  = graphic_info[graphic].width;
1059   int height = graphic_info[graphic].height;
1060   int src_x = graphic_info[graphic].src_x;
1061   int src_y = graphic_info[graphic].src_y;
1062 #else
1063   int width  = graphic_info[graphic].src_image_width;
1064   int height = graphic_info[graphic].src_image_height;
1065   int src_x = 0, src_y = 0;
1066 #endif
1067   int dst_x, dst_y;
1068
1069   if (bitmap == NULL)
1070     return;
1071
1072   if (width > WIN_XSIZE)
1073   {
1074     /* image width too large for window => center image horizontally */
1075     src_x = (width - WIN_XSIZE) / 2;
1076     width = WIN_XSIZE;
1077   }
1078
1079   if (height > WIN_YSIZE)
1080   {
1081     /* image height too large for window => center image vertically */
1082     src_y = (height - WIN_YSIZE) / 2;
1083     height = WIN_YSIZE;
1084   }
1085
1086   /* always display title screens centered */
1087   dst_x = (WIN_XSIZE - width) / 2;
1088   dst_y = (WIN_YSIZE - height) / 2;
1089
1090   SetDrawBackgroundMask(REDRAW_ALL);
1091   SetWindowBackgroundImage(getTitleBackground(nr, initial, TRUE));
1092
1093   ClearRectangleOnBackground(drawto, 0, 0, WIN_XSIZE, WIN_YSIZE);
1094
1095   if (DrawingOnBackground(dst_x, dst_y))
1096     BlitBitmapMasked(bitmap, drawto, src_x, src_y, width, height, dst_x, dst_y);
1097   else
1098     BlitBitmap(bitmap, drawto, src_x, src_y, width, height, dst_x, dst_y);
1099
1100   redraw_mask = REDRAW_ALL;
1101
1102   /* reset fading control values to default config settings */
1103 #if 1
1104
1105 #if 0
1106   title = getTitleFading(nr, initial, TRUE);
1107 #endif
1108
1109 #else
1110
1111   title.fade_delay_final = title.fade_delay;
1112   title.post_delay_final = title.post_delay;
1113   title.auto_delay_final = title.auto_delay;
1114
1115   /* override default settings with image config settings, if defined */
1116   if (graphic_info[graphic].anim_mode != ANIM_DEFAULT)
1117     title.anim_mode = graphic_info[graphic].anim_mode;
1118   if (graphic_info[graphic].fade_delay > -1)
1119     title.fade_delay = graphic_info[graphic].fade_delay;
1120   if (graphic_info[graphic].post_delay > -1)
1121     title.post_delay = graphic_info[graphic].post_delay;
1122   if (graphic_info[graphic].auto_delay > -1)
1123     title.auto_delay = graphic_info[graphic].auto_delay;
1124 #endif
1125 }
1126
1127 void DrawTitleScreenMessage(int nr, boolean initial)
1128 {
1129   char *filename = getLevelSetTitleMessageFilename(nr, initial);
1130   struct TitleMessageInfo *tmi = getTitleMessageInfo(nr, initial);
1131 #if 0
1132   int font_nr = FONT_TEXT_1;
1133   int font_width;
1134   int font_height;
1135   int pad_x = 16   + 4;
1136   int pad_y = 32   + 14;
1137   int sx = pad_x;
1138   int sy = pad_y;
1139   int max_chars_per_line;
1140   int max_lines_per_screen;
1141 #endif
1142   int last_game_status = game_status;   /* save current game status */
1143
1144   if (filename == NULL)
1145     return;
1146
1147   /* force TITLE font on title message screen */
1148   game_status = getTitleMessageGameMode(initial);
1149
1150   /* if chars set to "-1", automatically determine by text and font width */
1151   if (tmi->chars == -1)
1152     tmi->chars = tmi->width / getFontWidth(tmi->font);
1153   else
1154     tmi->width = tmi->chars * getFontWidth(tmi->font);
1155
1156   /* if lines set to "-1", automatically determine by text and font height */
1157   if (tmi->lines == -1)
1158     tmi->lines = tmi->height / getFontHeight(tmi->font);
1159   else
1160     tmi->height = tmi->lines * getFontHeight(tmi->font);
1161
1162   SetDrawBackgroundMask(REDRAW_ALL);
1163   SetWindowBackgroundImage(getTitleBackground(nr, initial, FALSE));
1164
1165   ClearRectangleOnBackground(drawto, 0, 0, WIN_XSIZE, WIN_YSIZE);
1166
1167 #if 0
1168   font_width = getFontWidth(font_nr);
1169   font_height = getFontHeight(font_nr);
1170   max_chars_per_line = (WIN_XSIZE - 2 * pad_x) / font_width;
1171   max_lines_per_screen = (WIN_YSIZE - pad_y) / font_height - 1;
1172 #endif
1173
1174 #if 1
1175   DrawTextFile(ALIGNED_TEXT_XPOS(tmi), ALIGNED_TEXT_YPOS(tmi),
1176                filename, tmi->font, tmi->chars, -1, tmi->lines, -1,
1177                tmi->autowrap, tmi->centered, tmi->parse_comments);
1178 #else
1179   DrawTextFile(sx, sy, filename, font_nr, max_chars_per_line, -1,
1180                max_lines_per_screen, -1, tmi->autowrap, tmi->centered,
1181                tmi->parse_comments);
1182 #endif
1183
1184   game_status = last_game_status;       /* restore current game status */
1185 }
1186
1187 void DrawTitleScreen()
1188 {
1189   KeyboardAutoRepeatOff();
1190
1191 #if 0
1192   SetMainBackgroundImage(IMG_BACKGROUND_TITLE);
1193 #endif
1194
1195   HandleTitleScreen(0, 0, 0, 0, MB_MENU_INITIALIZE);
1196
1197   StopAnimation();
1198 }
1199
1200 boolean CheckTitleScreen(boolean levelset_has_changed)
1201 {
1202   static boolean show_title_initial = TRUE;
1203   boolean show_titlescreen = FALSE;
1204
1205   /* needed to be able to skip title screen, if no image or message defined */
1206   InitializeTitleControls(show_title_initial);
1207
1208   if (setup.show_titlescreen && (show_title_initial || levelset_has_changed))
1209     show_titlescreen = TRUE;
1210
1211   /* show initial title images and messages only once at program start */
1212   show_title_initial = FALSE;
1213
1214   return (show_titlescreen && num_title_screens > 0);
1215 }
1216
1217 void DrawMainMenuExt(int redraw_mask, boolean do_fading)
1218 {
1219   static LevelDirTree *leveldir_last_valid = NULL;
1220   boolean levelset_has_changed = FALSE;
1221 #if 0
1222   boolean local_team_mode = (!options.network && setup.team_mode);
1223   char *name_text = (local_team_mode ? "Team:" : "Name:");
1224   int name_width, level_width;
1225 #endif
1226 #if 0
1227   int i;
1228 #endif
1229
1230 #if 0
1231   /* !!! CHANGE THIS !!! */
1232   title = title_default;
1233 #endif
1234
1235 #if 0
1236   printf("::: %d, %d\n", fading.anim_mode == ANIM_CROSSFADE,
1237          redraw_mask == REDRAW_ALL);
1238 #endif
1239
1240 #if 1
1241 #if XFADE
1242   if (fading.anim_mode == ANIM_CROSSFADE)
1243     FadeCrossSaveBackbuffer();
1244   else
1245     FadeOut(redraw_mask);
1246 #endif
1247 #endif
1248
1249   UnmapAllGadgets();
1250   FadeSoundsAndMusic();
1251
1252   KeyboardAutoRepeatOn();
1253   ActivateJoystick();
1254
1255   SetDrawDeactivationMask(REDRAW_NONE);
1256   SetDrawBackgroundMask(REDRAW_FIELD);
1257
1258   audio.sound_deactivated = FALSE;
1259
1260   GetPlayerConfig();
1261
1262   /* needed if last screen was the playing screen, invoked from level editor */
1263   if (level_editor_test_game)
1264   {
1265     game_status = GAME_MODE_EDITOR;
1266     DrawLevelEd();
1267
1268     return;
1269   }
1270
1271   /* needed if last screen was the editor screen */
1272   UndrawSpecialEditorDoor();
1273
1274   /* needed if last screen was the setup screen and fullscreen state changed */
1275   ToggleFullscreenIfNeeded();
1276
1277   /* leveldir_current may be invalid (level group, parent link) */
1278   if (!validLevelSeries(leveldir_current))
1279     leveldir_current = getFirstValidTreeInfoEntry(leveldir_last_valid);
1280
1281   if (leveldir_current != leveldir_last_valid)
1282     levelset_has_changed = TRUE;
1283
1284   /* store valid level series information */
1285   leveldir_last_valid = leveldir_current;
1286
1287   /* needed if last screen (level choice) changed graphics, sounds or music */
1288   ReloadCustomArtwork(0);
1289
1290 #if defined(TARGET_SDL)
1291   SetDrawtoField(DRAW_BACKBUFFER);
1292 #endif
1293
1294 #if 0
1295   if (levelset_has_changed)
1296     fading = title_default;
1297 #endif
1298
1299 #if 1
1300   if (CheckTitleScreen(levelset_has_changed))
1301   {
1302     game_status = GAME_MODE_TITLE;
1303
1304     DrawTitleScreen();
1305
1306     return;
1307   }
1308
1309 #else
1310
1311   if (setup.show_titlescreen &&
1312       ((levelset_has_changed &&
1313         (graphic_info[IMG_TITLESCREEN_1].bitmap != NULL ||
1314          getLevelSetMessageFilename(1, FALSE) != NULL)) ||
1315        (show_title_initial &&
1316         (graphic_info[IMG_TITLESCREEN_INITIAL_1].bitmap != NULL ||
1317          getLevelSetMessageFilename(1, TRUE) != NULL))))
1318   {
1319     game_status = GAME_MODE_TITLE;
1320
1321     DrawTitleScreen();
1322
1323     return;
1324   }
1325 #endif
1326
1327   /* level_nr may have been set to value over handicap with level editor */
1328   if (setup.handicap && level_nr > leveldir_current->handicap_level)
1329     level_nr = leveldir_current->handicap_level;
1330
1331   LoadLevel(level_nr);
1332
1333   SetMainBackgroundImage(IMG_BACKGROUND_MAIN);
1334
1335 #if 0
1336 #if XFADE
1337   if (fading.anim_mode == ANIM_CROSSFADE)
1338     FadeCrossSaveBackbuffer();
1339   else
1340     FadeOut(redraw_mask);
1341 #endif
1342 #endif
1343
1344 #if 1
1345   if (redraw_mask == REDRAW_ALL)
1346   {
1347     int door_state = GetDoorState();
1348
1349     RedrawBackground();
1350
1351     // OpenDoor(door_state | DOOR_NO_DELAY | DOOR_FORCE_REDRAW);
1352
1353 #if 0
1354 #if 1
1355     OpenDoor(DOOR_NO_DELAY | DOOR_FORCE_REDRAW);
1356 #else
1357     OpenDoor(DOOR_CLOSE_1 | DOOR_CLOSE_2 | DOOR_NO_DELAY | DOOR_FORCE_REDRAW);
1358 #endif
1359 #endif
1360   }
1361 #endif
1362
1363   ClearWindow();
1364
1365 #if 1
1366   InitializeMainControls();
1367
1368 #if 1
1369   DrawCursorAndText_Main(-1, FALSE);
1370 #else
1371   for (i = 0; main_controls[i].nr != -1; i++)
1372   {
1373     struct MenuPosInfo *pos_button = main_controls[i].pos_button;
1374     struct MenuPosInfo *pos_text   = main_controls[i].pos_text;
1375     struct MenuPosInfo *pos_input  = main_controls[i].pos_input;
1376     char *text                     = main_controls[i].text;
1377     char *input                    = main_controls[i].input;
1378     int button_graphic             = main_controls[i].button_graphic;
1379     int font_text                  = main_controls[i].font_text;
1380     int font_input                 = main_controls[i].font_input;
1381
1382     if (pos_button != NULL)
1383       DrawGraphicThruMaskExt(drawto, mSX + pos_button->x, mSY + pos_button->y,
1384                              button_graphic, 0);
1385
1386     if (pos_text != NULL && text != NULL)
1387       DrawText(mSX + pos_text->x, mSY + pos_text->y, text, font_text);
1388
1389     if (pos_input != NULL && input != NULL)
1390       DrawText(mSX + pos_input->x, mSY + pos_input->y, input, font_input);
1391   }
1392 #endif
1393
1394 #else
1395
1396   DrawHeadline();
1397
1398   DrawText(mSX + 32, mSY + 2 * 32, name_text,       FONT_MENU_1);
1399   DrawText(mSX + 32, mSY + 3 * 32, "Levelset",      FONT_MENU_1);
1400   DrawText(mSX + 32, mSY + 4 * 32, "Hall Of Fame",  FONT_MENU_1);
1401   DrawText(mSX + 32, mSY + 5 * 32, "Level Creator", FONT_MENU_1);
1402   DrawText(mSX + 32, mSY + 6 * 32, "Info Screen",   FONT_MENU_1);
1403   DrawText(mSX + 32, mSY + 7 * 32, "Start Game",    FONT_MENU_1);
1404   DrawText(mSX + 32, mSY + 8 * 32, "Setup",         FONT_MENU_1);
1405   DrawText(mSX + 32, mSY + 9 * 32, "Quit",          FONT_MENU_1);
1406
1407   /* calculated after (possible) reload of custom artwork */
1408   name_width  = getTextWidth(name_text,  FONT_MENU_1);
1409   level_width = 9 * 32;
1410
1411   DrawText(mSX + 32 + name_width, mSY + 2 * 32, setup.player_name,
1412            FONT_INPUT_1);
1413
1414   DrawText(mSX + getCurrentLevelTextPos() * 32, mSY + 3 * 32,
1415            int2str(level_nr, 3), FONT_VALUE_1);
1416
1417   {
1418     int text_height = getFontHeight(FONT_TEXT_3);
1419     int xpos = getLevelRangeTextPos() * 32 + 8;
1420     int ypos2 = 3 * 32 + 16;
1421     int ypos1 = ypos2 - text_height;
1422
1423     DrawTextF(mSX - SX + xpos, mSY - SY + ypos1, FONT_TEXT_3,
1424               "%03d", leveldir_current->first_level);
1425     DrawTextF(mSX - SX + xpos, mSY - SY + ypos2, FONT_TEXT_3,
1426               "%03d", leveldir_current->last_level);
1427   }
1428
1429   for (i = 0; i < 8; i++)
1430     initCursor(i, (i == 1 || i == 4 || i == 6 ? IMG_MENU_BUTTON_ENTER_MENU :
1431                    IMG_MENU_BUTTON));
1432
1433   DrawTextSCentered(326, FONT_TITLE_2, PROGRAM_GAME_BY_STRING);
1434 #endif
1435
1436   DrawPreviewLevel(TRUE);
1437
1438   HandleMainMenu(0, 0, 0, 0, MB_MENU_INITIALIZE);
1439
1440   TapeStop();
1441   if (TAPE_IS_EMPTY(tape))
1442     LoadTape(level_nr);
1443   DrawCompleteVideoDisplay();
1444
1445   PlayMenuSound();
1446   PlayMenuMusic();
1447
1448   /* create gadgets for main menu screen */
1449   FreeScreenGadgets();
1450   CreateScreenGadgets();
1451
1452 #if 0
1453   BlitBitmap(drawto, window, VX, VY, VXSIZE, VYSIZE, VX, VY);
1454   Delay(3000);
1455 #endif
1456
1457   /* map gadgets for main menu screen */
1458   MapTapeButtons();
1459   MapScreenMenuGadgets(SCREEN_MASK_MAIN);
1460
1461   DrawMaskedBorder(REDRAW_ALL);
1462
1463 #if 1
1464   if (redraw_mask == REDRAW_ALL)
1465   {
1466     int door_state = GetDoorState();
1467
1468     OpenDoor(door_state | DOOR_NO_DELAY | DOOR_FORCE_REDRAW);
1469   }
1470 #endif
1471
1472 #if XFADE
1473   if (fading.anim_mode == ANIM_CROSSFADE)
1474     FadeCross(redraw_mask);
1475   else
1476     FadeIn(redraw_mask);
1477 #else
1478 #if 1
1479   if (!do_fading)
1480     BackToFront();
1481   else if (fading.anim_mode == ANIM_CROSSFADE)
1482     FadeCross(redraw_mask);
1483   else
1484     FadeIn(redraw_mask);
1485 #else
1486   if (do_fading)
1487     FadeIn(redraw_mask);
1488   else
1489     BackToFront();
1490 #endif
1491 #endif
1492
1493 #if 1
1494   fading = menu.navigation;
1495 #else
1496   fading = title_default;
1497 #endif
1498
1499   SetMouseCursor(CURSOR_DEFAULT);
1500
1501   InitAnimation();
1502
1503   OpenDoor(DOOR_CLOSE_1 | DOOR_OPEN_2);
1504 }
1505
1506 void DrawAndFadeInMainMenu(int redraw_mask)
1507 {
1508   DrawMainMenuExt(redraw_mask, TRUE);
1509 }
1510
1511 void DrawMainMenu()
1512 {
1513   DrawMainMenuExt(REDRAW_ALL, FALSE);
1514 }
1515
1516 #if 0
1517 static void gotoTopLevelDir()
1518 {
1519   /* move upwards to top level directory */
1520   while (leveldir_current->node_parent)
1521   {
1522     /* write a "path" into level tree for easy navigation to last level */
1523     if (leveldir_current->node_parent->node_group->cl_first == -1)
1524     {
1525       int num_leveldirs = numTreeInfoInGroup(leveldir_current);
1526       int leveldir_pos = posTreeInfo(leveldir_current);
1527       int num_page_entries;
1528       int cl_first, cl_cursor;
1529
1530       if (num_leveldirs <= NUM_MENU_ENTRIES_ON_SCREEN)
1531         num_page_entries = num_leveldirs;
1532       else
1533         num_page_entries = NUM_MENU_ENTRIES_ON_SCREEN;
1534
1535       cl_first = MAX(0, leveldir_pos - num_page_entries + 1);
1536       cl_cursor = leveldir_pos - cl_first;
1537
1538       leveldir_current->node_parent->node_group->cl_first = cl_first;
1539       leveldir_current->node_parent->node_group->cl_cursor = cl_cursor;
1540     }
1541
1542     leveldir_current = leveldir_current->node_parent;
1543   }
1544 }
1545 #endif
1546
1547 void HandleTitleScreen(int mx, int my, int dx, int dy, int button)
1548 {
1549   static unsigned long title_delay = 0;
1550   static int title_screen_nr = 0;
1551   static int last_sound = -1, last_music = -1;
1552   boolean return_to_main_menu = FALSE;
1553   boolean use_fading_main_menu = TRUE;
1554 #if 0
1555 #if 1
1556   boolean use_cross_fading = FALSE;
1557 #else
1558   boolean use_cross_fading = !show_title_initial;               /* default */
1559 #endif
1560 #endif
1561   struct TitleControlInfo *tci;
1562   struct TitleFadingInfo fading_next;
1563   int sound, music;
1564
1565   if (button == MB_MENU_INITIALIZE)
1566   {
1567 #if 1
1568     boolean use_cross_fading = (fading.anim_mode == ANIM_CROSSFADE);
1569 #endif
1570
1571 #if 0
1572     int last_game_status = game_status; /* save current game status */
1573 #endif
1574
1575     title_delay = 0;
1576     title_screen_nr = 0;
1577     tci = &title_controls[title_screen_nr];
1578
1579     last_sound = SND_UNDEFINED;
1580     last_music = MUS_UNDEFINED;
1581
1582 #if 0
1583     /* determine number of title screens to display (images and messages) */
1584     InitializeTitleControls();
1585 #endif
1586
1587     if (game_status == GAME_MODE_INFO)
1588     {
1589       if (num_title_screens == 0)
1590       {
1591         DrawInfoScreen_NotAvailable("Title screen information:",
1592                                     "No title screen for this level set.");
1593
1594         /* use default settings for fading, but always disable auto delay */
1595         fading = title_default;
1596         fading.auto_delay = -1;
1597
1598         return;
1599       }
1600
1601       FadeSoundsAndMusic();
1602
1603 #if 1
1604       if (use_cross_fading)
1605         FadeCrossSaveBackbuffer();
1606       else
1607         FadeOut(REDRAW_ALL);
1608 #else
1609       FadeOut(REDRAW_ALL);
1610 #endif
1611     }
1612
1613     if (tci->is_image)
1614       DrawTitleScreenImage(tci->local_nr, tci->initial);
1615     else
1616       DrawTitleScreenMessage(tci->local_nr, tci->initial);
1617
1618     fading = getTitleFading(tci);
1619
1620 #if 1
1621     sound = getTitleSound(tci);
1622     music = getTitleMusic(tci);
1623
1624     if (sound != last_sound)
1625       PlayMenuSoundExt(sound);
1626     if (music != last_music)
1627       PlayMenuMusicExt(music);
1628
1629     last_sound = sound;
1630     last_music = music;
1631 #endif
1632
1633     SetMouseCursor(CURSOR_NONE);
1634
1635 #if 1
1636     if (use_cross_fading)
1637       FadeCross(REDRAW_ALL);
1638     else
1639       FadeIn(REDRAW_ALL);
1640 #else
1641     FadeIn(REDRAW_ALL);
1642 #endif
1643
1644     DelayReached(&title_delay, 0);      /* reset delay counter */
1645
1646     return;
1647   }
1648
1649   if (fading.auto_delay > -1 && DelayReached(&title_delay, fading.auto_delay))
1650     button = MB_MENU_CHOICE;
1651
1652   if (button == MB_MENU_LEAVE)
1653   {
1654     return_to_main_menu = TRUE;
1655     use_fading_main_menu = FALSE;
1656   }
1657   else if (button == MB_MENU_CHOICE)
1658   {
1659 #if 1
1660     boolean use_cross_fading = (fading.anim_mode == ANIM_CROSSFADE);
1661 #endif
1662
1663     if (game_status == GAME_MODE_INFO && num_title_screens == 0)
1664     {
1665 #if 0
1666 #if XFADE
1667       if (fading.anim_mode == ANIM_CROSSFADE)
1668         FadeCrossSaveBackbuffer();
1669       else
1670         FadeOut(REDRAW_FIELD);
1671 #else
1672       FadeOut(REDRAW_FIELD);
1673 #endif
1674 #endif
1675
1676       fading = menu.destination;
1677
1678       info_mode = INFO_MODE_MAIN;
1679       DrawAndFadeInInfoScreen(REDRAW_FIELD);
1680
1681       return;
1682     }
1683
1684     title_screen_nr++;
1685     tci = &title_controls[title_screen_nr];
1686
1687     if (title_screen_nr < num_title_screens)
1688     {
1689 #if 1
1690 #if 0
1691       boolean use_cross_fading = (fading.anim_mode == ANIM_CROSSFADE);
1692 #endif
1693 #else
1694       int anim_mode;
1695
1696       if (tci->is_image)
1697         anim_mode =
1698           graphic_info[getTitleScreenGraphic(tci->local_nr,
1699                                              tci->initial)].anim_mode;
1700       else
1701         anim_mode = ANIM_FADE;  /* ??? */
1702
1703       use_cross_fading = (anim_mode == ANIM_FADE ? FALSE :
1704                           anim_mode == ANIM_CROSSFADE ? TRUE :
1705                           use_cross_fading);
1706 #endif
1707
1708       sound = getTitleSound(tci);
1709       music = getTitleMusic(tci);
1710
1711       if (sound == SND_UNDEFINED || sound != last_sound)
1712         FadeSounds();
1713       if (music == MUS_UNDEFINED || music != last_music)
1714         FadeMusic();
1715
1716       if (use_cross_fading)
1717         FadeCrossSaveBackbuffer();
1718       else
1719         FadeOut(REDRAW_ALL);
1720
1721       if (tci->is_image)
1722         DrawTitleScreenImage(tci->local_nr, tci->initial);
1723       else
1724         DrawTitleScreenMessage(tci->local_nr, tci->initial);
1725
1726       fading_next = getTitleFading(tci);
1727
1728 #if 1
1729       sound = getTitleSound(tci);
1730       music = getTitleMusic(tci);
1731
1732       if (sound != last_sound)
1733         PlayMenuSoundExt(sound);
1734       if (music != last_music)
1735         PlayMenuMusicExt(music);
1736
1737       last_sound = sound;
1738       last_music = music;
1739 #endif
1740
1741       /* last screen already faded out, next screen has no animation */
1742       if (!use_cross_fading && fading_next.anim_mode == ANIM_NONE)
1743         fading = fading_next;
1744
1745       if (use_cross_fading)
1746         FadeCross(REDRAW_ALL);
1747       else
1748         FadeIn(REDRAW_ALL);
1749
1750       fading = fading_next;
1751
1752       DelayReached(&title_delay, 0);    /* reset delay counter */
1753     }
1754     else
1755     {
1756       FadeSoundsAndMusic();
1757
1758 #if 0
1759 #if 1
1760       {
1761 #if 0
1762         boolean use_cross_fading = (fading.anim_mode == ANIM_CROSSFADE);
1763 #endif
1764
1765         if (use_cross_fading)
1766           FadeCrossSaveBackbuffer();
1767         else
1768           FadeOut(REDRAW_ALL);
1769       }
1770 #else
1771       FadeOut(REDRAW_ALL);
1772 #endif
1773 #endif
1774
1775       return_to_main_menu = TRUE;
1776     }
1777   }
1778
1779   if (return_to_main_menu)
1780   {
1781 #if 0
1782     RedrawBackground();
1783 #endif
1784
1785     SetMouseCursor(CURSOR_DEFAULT);
1786
1787     if (game_status == GAME_MODE_INFO)
1788     {
1789 #if 0
1790       OpenDoor(DOOR_CLOSE_1 | DOOR_CLOSE_2 | DOOR_NO_DELAY | DOOR_FORCE_REDRAW);
1791 #endif
1792
1793       info_mode = INFO_MODE_MAIN;
1794       DrawInfoScreenExt(REDRAW_ALL, use_fading_main_menu);
1795     }
1796     else        /* default: return to main menu */
1797     {
1798 #if 0
1799       OpenDoor(DOOR_CLOSE_1 | DOOR_OPEN_2 | DOOR_NO_DELAY | DOOR_FORCE_REDRAW);
1800 #endif
1801
1802       game_status = GAME_MODE_MAIN;
1803       DrawMainMenuExt(REDRAW_ALL, use_fading_main_menu);
1804     }
1805   }
1806 }
1807
1808 void HandleMainMenu_SelectLevel(int step, int direction)
1809 {
1810   int old_level_nr = level_nr;
1811   int new_level_nr;
1812
1813   new_level_nr = old_level_nr + step * direction;
1814   if (new_level_nr < leveldir_current->first_level)
1815     new_level_nr = leveldir_current->first_level;
1816   if (new_level_nr > leveldir_current->last_level)
1817     new_level_nr = leveldir_current->last_level;
1818
1819   if (setup.handicap && new_level_nr > leveldir_current->handicap_level)
1820   {
1821     /* skipping levels is only allowed when trying to skip single level */
1822     if (setup.skip_levels && step == 1 &&
1823         Request("Level still unsolved ! Skip despite handicap ?", REQ_ASK))
1824     {
1825       leveldir_current->handicap_level++;
1826       SaveLevelSetup_SeriesInfo();
1827     }
1828
1829     new_level_nr = leveldir_current->handicap_level;
1830   }
1831
1832   if (new_level_nr != old_level_nr)
1833   {
1834     struct MainControlInfo *mci= getMainControlInfo(MAIN_CONTROL_LEVEL_NUMBER);
1835
1836     PlaySound(SND_MENU_ITEM_SELECTING);
1837
1838     level_nr = new_level_nr;
1839
1840 #if 1
1841     DrawText(mSX + mci->pos_text->x, mSY + mci->pos_text->y,
1842              int2str(level_nr, 3), mci->pos_text->font);
1843 #else
1844     DrawText(mSX + 11 * 32, mSY + 3 * 32, int2str(level_nr, 3), FONT_VALUE_1);
1845 #endif
1846
1847     LoadLevel(level_nr);
1848     DrawPreviewLevel(TRUE);
1849
1850     TapeErase();
1851     LoadTape(level_nr);
1852     DrawCompleteVideoDisplay();
1853
1854     /* needed because DrawPreviewLevel() takes some time */
1855     BackToFront();
1856     SyncDisplay();
1857   }
1858 }
1859
1860 #if 1
1861
1862 void HandleMainMenu(int mx, int my, int dx, int dy, int button)
1863 {
1864   static int choice = MAIN_CONTROL_GAME;
1865   int pos = choice;
1866   int i;
1867
1868   if (button == MB_MENU_INITIALIZE)
1869   {
1870     DrawCursorAndText_Main(choice, TRUE);
1871
1872     return;
1873   }
1874
1875   if (mx || my)         /* mouse input */
1876   {
1877     pos = -1;
1878
1879     for (i = 0; main_controls[i].nr != -1; i++)
1880     {
1881       if (insideMenuPosRect(main_controls[i].pos_button, mx - mSX, my - mSY) ||
1882           insideTextPosRect(main_controls[i].pos_text,   mx - mSX, my - mSY) ||
1883           insideTextPosRect(main_controls[i].pos_input,  mx - mSX, my - mSY))
1884       {
1885         pos = main_controls[i].nr;
1886
1887         break;
1888       }
1889     }
1890   }
1891   else if (dx || dy)    /* keyboard input */
1892   {
1893     if (dx > 0 && (choice == MAIN_CONTROL_INFO ||
1894                    choice == MAIN_CONTROL_SETUP))
1895       button = MB_MENU_CHOICE;
1896     else if (dy)
1897       pos = choice + dy;
1898   }
1899
1900   if (pos == MAIN_CONTROL_LEVELS && dx != 0 && button)
1901   {
1902     HandleMainMenu_SelectLevel(1, dx < 0 ? -1 : +1);
1903   }
1904   else if (pos >= MAIN_CONTROL_NAME && pos <= MAIN_CONTROL_QUIT)
1905   {
1906     if (button)
1907     {
1908       if (pos != choice)
1909       {
1910         PlaySound(SND_MENU_ITEM_ACTIVATING);
1911
1912         DrawCursorAndText_Main(choice, FALSE);
1913         DrawCursorAndText_Main(pos, TRUE);
1914
1915         choice = pos;
1916       }
1917     }
1918     else
1919     {
1920       PlaySound(SND_MENU_ITEM_SELECTING);
1921
1922       if (pos == MAIN_CONTROL_NAME)
1923       {
1924         game_status = GAME_MODE_PSEUDO_TYPENAME;
1925
1926         HandleTypeName(strlen(setup.player_name), 0);
1927       }
1928       else if (pos == MAIN_CONTROL_LEVELS)
1929       {
1930         if (leveldir_first)
1931         {
1932           game_status = GAME_MODE_LEVELS;
1933
1934           SaveLevelSetup_LastSeries();
1935           SaveLevelSetup_SeriesInfo();
1936
1937 #if 0
1938           gotoTopLevelDir();
1939 #endif
1940
1941           DrawChooseLevel();
1942         }
1943       }
1944       else if (pos == MAIN_CONTROL_SCORES)
1945       {
1946         game_status = GAME_MODE_SCORES;
1947
1948         DrawHallOfFame(-1);
1949       }
1950       else if (pos == MAIN_CONTROL_EDITOR)
1951       {
1952         if (leveldir_current->readonly &&
1953             !strEqual(setup.player_name, "Artsoft"))
1954           Request("This level is read only !", REQ_CONFIRM);
1955
1956         game_status = GAME_MODE_EDITOR;
1957
1958         fading = menu.destination;
1959
1960         DrawLevelEd();
1961       }
1962       else if (pos == MAIN_CONTROL_INFO)
1963       {
1964         game_status = GAME_MODE_INFO;
1965         info_mode = INFO_MODE_MAIN;
1966
1967         fading = menu.navigation;
1968
1969         DrawInfoScreen();
1970       }
1971       else if (pos == MAIN_CONTROL_GAME)
1972       {
1973         StartGameActions(options.network, setup.autorecord, NEW_RANDOMIZE);
1974       }
1975       else if (pos == MAIN_CONTROL_SETUP)
1976       {
1977         game_status = GAME_MODE_SETUP;
1978         setup_mode = SETUP_MODE_MAIN;
1979
1980         DrawSetupScreen();
1981       }
1982       else if (pos == MAIN_CONTROL_QUIT)
1983       {
1984         SaveLevelSetup_LastSeries();
1985         SaveLevelSetup_SeriesInfo();
1986
1987         if (Request("Do you really want to quit ?", REQ_ASK | REQ_STAY_CLOSED))
1988           game_status = GAME_MODE_QUIT;
1989       }
1990     }
1991   }
1992
1993   if (game_status == GAME_MODE_MAIN)
1994   {
1995     DrawPreviewLevel(FALSE);
1996     DoAnimation();
1997   }
1998 }
1999
2000 #else
2001
2002 void HandleMainMenu(int mx, int my, int dx, int dy, int button)
2003 {
2004   static int choice = 5;
2005   int x = 0;
2006   int y = choice;
2007
2008   if (button == MB_MENU_INITIALIZE)
2009   {
2010     drawCursor(choice, TRUE);
2011
2012     return;
2013   }
2014
2015   if (mx || my)         /* mouse input */
2016   {
2017     x = (mx - mSX) / 32;
2018     y = (my - mSY) / 32 - MENU_SCREEN_START_YPOS;
2019   }
2020   else if (dx || dy)    /* keyboard input */
2021   {
2022     if (dx && choice == 1)
2023       x = (dx < 0 ? 10 : 14);
2024     else if (dx > 0)
2025     {
2026       if (choice == 4 || choice == 6)
2027         button = MB_MENU_CHOICE;
2028     }
2029     else if (dy)
2030       y = choice + dy;
2031   }
2032
2033   if (y == 1 && dx != 0 && button)
2034   {
2035     HandleMainMenu_SelectLevel(1, dx < 0 ? -1 : +1);
2036   }
2037   else if (IN_VIS_FIELD(x, y) &&
2038            y >= 0 && y <= 7 && (y != 1 || x < 10))
2039   {
2040     if (button)
2041     {
2042       if (y != choice)
2043       {
2044         drawCursor(choice, FALSE);
2045         drawCursor(y, TRUE);
2046
2047         choice = y;
2048       }
2049     }
2050     else
2051     {
2052       if (y == 0)
2053       {
2054         game_status = GAME_MODE_PSEUDO_TYPENAME;
2055         HandleTypeName(strlen(setup.player_name), 0);
2056       }
2057       else if (y == 1)
2058       {
2059         if (leveldir_first)
2060         {
2061           game_status = GAME_MODE_LEVELS;
2062           SaveLevelSetup_LastSeries();
2063           SaveLevelSetup_SeriesInfo();
2064
2065 #if 0
2066           gotoTopLevelDir();
2067 #endif
2068
2069           DrawChooseLevel();
2070         }
2071       }
2072       else if (y == 2)
2073       {
2074         game_status = GAME_MODE_SCORES;
2075         DrawHallOfFame(-1);
2076       }
2077       else if (y == 3)
2078       {
2079         if (leveldir_current->readonly &&
2080             !strEqual(setup.player_name, "Artsoft"))
2081           Request("This level is read only !", REQ_CONFIRM);
2082         game_status = GAME_MODE_EDITOR;
2083         DrawLevelEd();
2084       }
2085       else if (y == 4)
2086       {
2087         game_status = GAME_MODE_INFO;
2088         info_mode = INFO_MODE_MAIN;
2089         DrawInfoScreen();
2090       }
2091       else if (y == 5)
2092       {
2093         StartGameActions(options.network, setup.autorecord, NEW_RANDOMIZE);
2094       }
2095       else if (y == 6)
2096       {
2097         game_status = GAME_MODE_SETUP;
2098         setup_mode = SETUP_MODE_MAIN;
2099
2100         DrawSetupScreen();
2101       }
2102       else if (y == 7)
2103       {
2104         SaveLevelSetup_LastSeries();
2105         SaveLevelSetup_SeriesInfo();
2106
2107         if (Request("Do you really want to quit ?", REQ_ASK | REQ_STAY_CLOSED))
2108           game_status = GAME_MODE_QUIT;
2109       }
2110     }
2111   }
2112
2113   if (game_status == GAME_MODE_MAIN)
2114   {
2115     DrawPreviewLevel(FALSE);
2116     DoAnimation();
2117   }
2118 }
2119
2120 #endif
2121
2122
2123 /* ========================================================================= */
2124 /* info screen functions                                                     */
2125 /* ========================================================================= */
2126
2127 static struct TokenInfo *info_info;
2128 static int num_info_info;
2129
2130 static void execInfoTitleScreen()
2131 {
2132   fading = menu.destination;
2133
2134   info_mode = INFO_MODE_TITLE;
2135   DrawInfoScreen();
2136 }
2137
2138 static void execInfoElements()
2139 {
2140   fading = menu.destination;
2141
2142   info_mode = INFO_MODE_ELEMENTS;
2143   DrawInfoScreen();
2144 }
2145
2146 static void execInfoMusic()
2147 {
2148   fading = menu.destination;
2149
2150   info_mode = INFO_MODE_MUSIC;
2151   DrawInfoScreen();
2152 }
2153
2154 static void execInfoCredits()
2155 {
2156   fading = menu.destination;
2157
2158   info_mode = INFO_MODE_CREDITS;
2159   DrawInfoScreen();
2160 }
2161
2162 static void execInfoProgram()
2163 {
2164   fading = menu.destination;
2165
2166   info_mode = INFO_MODE_PROGRAM;
2167   DrawInfoScreen();
2168 }
2169
2170 static void execInfoVersion()
2171 {
2172   fading = menu.destination;
2173
2174   info_mode = INFO_MODE_VERSION;
2175   DrawInfoScreen();
2176 }
2177
2178 static void execInfoLevelSet()
2179 {
2180   fading = menu.destination;
2181
2182   info_mode = INFO_MODE_LEVELSET;
2183   DrawInfoScreen();
2184 }
2185
2186 static void execExitInfo()
2187 {
2188   fading = menu.navigation;
2189
2190   game_status = GAME_MODE_MAIN;
2191 #if 1
2192   DrawMainMenuExt(REDRAW_FIELD, FALSE);
2193 #else
2194   DrawMainMenu();
2195 #endif
2196 }
2197
2198 static struct TokenInfo info_info_main[] =
2199 {
2200   { TYPE_ENTER_SCREEN,  execInfoTitleScreen,    "Title Screen"          },
2201   { TYPE_ENTER_SCREEN,  execInfoElements,       "Elements Info"         },
2202   { TYPE_ENTER_SCREEN,  execInfoMusic,          "Music Info"            },
2203   { TYPE_ENTER_SCREEN,  execInfoCredits,        "Credits"               },
2204   { TYPE_ENTER_SCREEN,  execInfoProgram,        "Program Info"          },
2205   { TYPE_ENTER_SCREEN,  execInfoVersion,        "Version Info"          },
2206   { TYPE_ENTER_SCREEN,  execInfoLevelSet,       "Level Set Info"        },
2207   { TYPE_EMPTY,         NULL,                   ""                      },
2208   { TYPE_LEAVE_MENU,    execExitInfo,           "Exit"                  },
2209
2210   { 0,                  NULL,                   NULL                    }
2211 };
2212
2213 static void DrawCursorAndText_Info(int pos, boolean active)
2214 {
2215   int xpos = MENU_SCREEN_START_XPOS;
2216   int ypos = MENU_SCREEN_START_YPOS + pos;
2217   int font_nr = FONT_MENU_1;
2218
2219   if (active)
2220     font_nr = FONT_ACTIVE(font_nr);
2221
2222   DrawText(mSX + xpos * 32, mSY + ypos * 32, info_info[pos].text, font_nr);
2223
2224   if (info_info[pos].type & ~TYPE_SKIP_ENTRY)
2225     drawCursor(pos, active);
2226 }
2227
2228 static void DrawInfoScreen_Main(int redraw_mask, boolean do_fading)
2229 {
2230   int i;
2231
2232   UnmapAllGadgets();
2233   CloseDoor(DOOR_CLOSE_2);
2234
2235 #if XFADE
2236   if (fading.anim_mode == ANIM_CROSSFADE)
2237     FadeCrossSaveBackbuffer();
2238   else
2239     FadeOut(redraw_mask);
2240 #endif
2241
2242 #if 1
2243   if (redraw_mask == REDRAW_ALL)
2244   {
2245     RedrawBackground();
2246     OpenDoor(DOOR_CLOSE_1 | DOOR_CLOSE_2 | DOOR_NO_DELAY | DOOR_FORCE_REDRAW);
2247   }
2248 #endif
2249
2250   ClearWindow();
2251
2252   DrawTextSCentered(mSY - SY + 16, FONT_TITLE_1, "Info Screen");
2253
2254   info_info = info_info_main;
2255   num_info_info = 0;
2256
2257   for (i = 0; info_info[i].type != 0 && i < NUM_MENU_ENTRIES_ON_SCREEN; i++)
2258   {
2259 #if 0
2260     int xpos = MENU_SCREEN_START_XPOS;
2261     int ypos = MENU_SCREEN_START_YPOS + i;
2262     int font_nr = FONT_MENU_1;
2263 #endif
2264
2265     if (info_info[i].type & (TYPE_ENTER_MENU|TYPE_ENTER_LIST))
2266       initCursor(i, IMG_MENU_BUTTON_ENTER_MENU);
2267     else if (info_info[i].type & (TYPE_LEAVE_MENU|TYPE_LEAVE_LIST))
2268       initCursor(i, IMG_MENU_BUTTON_LEAVE_MENU);
2269     else if (info_info[i].type & ~TYPE_SKIP_ENTRY)
2270       initCursor(i, IMG_MENU_BUTTON);
2271
2272 #if 1
2273     DrawCursorAndText_Info(i, FALSE);
2274 #else
2275     DrawText(mSX + xpos * 32, mSY + ypos * 32, info_info[i].text, font_nr);
2276 #endif
2277
2278     num_info_info++;
2279   }
2280
2281   HandleInfoScreen_Main(0, 0, 0, 0, MB_MENU_INITIALIZE);
2282
2283   PlayMenuSound();
2284   PlayMenuMusic();
2285
2286   DrawMaskedBorder(REDRAW_ALL);
2287
2288 #if XFADE
2289   if (fading.anim_mode == ANIM_CROSSFADE)
2290     FadeCross(redraw_mask);
2291   else
2292     FadeIn(redraw_mask);
2293 #else
2294 #if 1
2295   if (!do_fading)
2296     BackToFront();
2297   else if (fading.anim_mode == ANIM_CROSSFADE)
2298     FadeCross(redraw_mask);
2299   else
2300     FadeIn(redraw_mask);
2301 #else
2302   if (do_fading)
2303     FadeIn(redraw_mask);
2304   else
2305     BackToFront();
2306 #endif
2307 #endif
2308
2309   InitAnimation();
2310 }
2311
2312 void HandleInfoScreen_Main(int mx, int my, int dx, int dy, int button)
2313 {
2314   static int choice_store[MAX_INFO_MODES];
2315   int choice = choice_store[info_mode];         /* always starts with 0 */
2316   int x = 0;
2317   int y = choice;
2318
2319   if (button == MB_MENU_INITIALIZE)
2320   {
2321     /* advance to first valid menu entry */
2322     while (choice < num_info_info &&
2323            info_info[choice].type & TYPE_SKIP_ENTRY)
2324       choice++;
2325     choice_store[info_mode] = choice;
2326
2327 #if 1
2328     DrawCursorAndText_Info(choice, TRUE);
2329 #else
2330     drawCursor(choice, TRUE);
2331 #endif
2332
2333     return;
2334   }
2335   else if (button == MB_MENU_LEAVE)
2336   {
2337     for (y = 0; y < num_info_info; y++)
2338     {
2339       if (info_info[y].type & TYPE_LEAVE_MENU)
2340       {
2341         void (*menu_callback_function)(void) = info_info[y].value;
2342
2343         menu_callback_function();
2344
2345         break;  /* absolutely needed because function changes 'info_info'! */
2346       }
2347     }
2348
2349     return;
2350   }
2351
2352   if (mx || my)         /* mouse input */
2353   {
2354     x = (mx - mSX) / 32;
2355     y = (my - mSY) / 32 - MENU_SCREEN_START_YPOS;
2356   }
2357   else if (dx || dy)    /* keyboard input */
2358   {
2359     if (dx)
2360     {
2361       int menu_navigation_type = (dx < 0 ? TYPE_LEAVE : TYPE_ENTER);
2362
2363       if (info_info[choice].type & menu_navigation_type ||
2364           info_info[choice].type & TYPE_ENTER_SCREEN ||
2365           info_info[choice].type & TYPE_BOOLEAN_STYLE)
2366         button = MB_MENU_CHOICE;
2367     }
2368     else if (dy)
2369       y = choice + dy;
2370
2371     /* jump to next non-empty menu entry (up or down) */
2372     while (y > 0 && y < num_info_info - 1 &&
2373            info_info[y].type & TYPE_SKIP_ENTRY)
2374       y += dy;
2375   }
2376
2377   if (IN_VIS_FIELD(x, y) &&
2378       y >= 0 && y < num_info_info && info_info[y].type & ~TYPE_SKIP_ENTRY)
2379   {
2380     if (button)
2381     {
2382       if (y != choice)
2383       {
2384         PlaySound(SND_MENU_ITEM_ACTIVATING);
2385
2386 #if 1
2387         DrawCursorAndText_Info(choice, FALSE);
2388         DrawCursorAndText_Info(y, TRUE);
2389 #else
2390         drawCursor(choice, FALSE);
2391         drawCursor(y, TRUE);
2392 #endif
2393
2394         choice = choice_store[info_mode] = y;
2395       }
2396     }
2397     else if (!(info_info[y].type & TYPE_GHOSTED))
2398     {
2399       PlaySound(SND_MENU_ITEM_SELECTING);
2400
2401       if (info_info[y].type & TYPE_ENTER_OR_LEAVE)
2402       {
2403         void (*menu_callback_function)(void) = info_info[choice].value;
2404
2405         menu_callback_function();
2406       }
2407     }
2408   }
2409 }
2410
2411 void DrawInfoScreen_NotAvailable(char *text_title, char *text_error)
2412 {
2413 #if 1
2414   int ystart1 = mSY - SY + 100;
2415   int ystart2 = mSY - SY + 150;
2416   int ybottom = mSY - SY + SYSIZE - 20;
2417 #else
2418   int ystart1 = 100;
2419   int ystart2 = 150;
2420   int ybottom = SYSIZE - 20;
2421 #endif
2422
2423   SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_LEVELSET);
2424
2425 #if XFADE
2426   if (fading.anim_mode == ANIM_CROSSFADE)
2427     FadeCrossSaveBackbuffer();
2428   else
2429     FadeOut(REDRAW_FIELD);
2430 #else
2431   FadeOut(REDRAW_FIELD);
2432 #endif
2433
2434   ClearWindow();
2435   DrawHeadline();
2436
2437   DrawTextSCentered(ystart1, FONT_TEXT_1, text_title);
2438   DrawTextSCentered(ystart2, FONT_TEXT_2, text_error);
2439
2440   DrawTextSCentered(ybottom, FONT_TEXT_4,
2441                     "Press any key or button for info menu");
2442
2443 #if XFADE
2444   if (fading.anim_mode == ANIM_CROSSFADE)
2445     FadeCross(REDRAW_FIELD);
2446   else
2447     FadeIn(REDRAW_FIELD);
2448 #else
2449   FadeIn(REDRAW_FIELD);
2450 #endif
2451 }
2452
2453 void DrawInfoScreen_HelpAnim(int start, int max_anims, boolean init)
2454 {
2455   static int infoscreen_step[MAX_INFO_ELEMENTS_ON_SCREEN];
2456   static int infoscreen_frame[MAX_INFO_ELEMENTS_ON_SCREEN];
2457   int xstart = mSX + 16;
2458   int ystart1 = mSY - SY + 100;
2459   int ystart2 = mSY + 64 + 2 * 32;
2460   int ybottom = mSY - SY + SYSIZE - 20;
2461   int ystep = TILEY + 4;
2462   int element, action, direction;
2463   int graphic;
2464   int delay;
2465   int sync_frame;
2466   int i, j;
2467
2468   if (init)
2469   {
2470     for (i = 0; i < MAX_INFO_ELEMENTS_ON_SCREEN; i++)
2471       infoscreen_step[i] = infoscreen_frame[i] = 0;
2472
2473     ClearWindow();
2474     DrawHeadline();
2475
2476     DrawTextSCentered(ystart1, FONT_TEXT_1, "The Game Elements:");
2477
2478     DrawTextSCentered(ybottom, FONT_TEXT_4,
2479                       "Press any key or button for next page");
2480
2481     FrameCounter = 0;
2482   }
2483
2484   i = j = 0;
2485   while (helpanim_info[j].element != HELPANIM_LIST_END)
2486   {
2487     if (i >= start + MAX_INFO_ELEMENTS_ON_SCREEN ||
2488         i >= max_anims)
2489       break;
2490     else if (i < start)
2491     {
2492       while (helpanim_info[j].element != HELPANIM_LIST_NEXT)
2493         j++;
2494
2495       j++;
2496       i++;
2497
2498       continue;
2499     }
2500
2501     j += infoscreen_step[i - start];
2502
2503     element = helpanim_info[j].element;
2504     action = helpanim_info[j].action;
2505     direction = helpanim_info[j].direction;
2506
2507     if (element < 0)
2508       element = EL_UNKNOWN;
2509
2510     if (action != -1 && direction != -1)
2511       graphic = el_act_dir2img(element, action, direction);
2512     else if (action != -1)
2513       graphic = el_act2img(element, action);
2514     else if (direction != -1)
2515       graphic = el_dir2img(element, direction);
2516     else
2517       graphic = el2img(element);
2518
2519     delay = helpanim_info[j++].delay;
2520
2521     if (delay == -1)
2522       delay = 1000000;
2523
2524     if (infoscreen_frame[i - start] == 0)
2525     {
2526       sync_frame = 0;
2527       infoscreen_frame[i - start] = delay - 1;
2528     }
2529     else
2530     {
2531       sync_frame = delay - infoscreen_frame[i - start];
2532       infoscreen_frame[i - start]--;
2533     }
2534
2535     if (helpanim_info[j].element == HELPANIM_LIST_NEXT)
2536     {
2537       if (!infoscreen_frame[i - start])
2538         infoscreen_step[i - start] = 0;
2539     }
2540     else
2541     {
2542       if (!infoscreen_frame[i - start])
2543         infoscreen_step[i - start]++;
2544       while (helpanim_info[j].element != HELPANIM_LIST_NEXT)
2545         j++;
2546     }
2547
2548     j++;
2549
2550     ClearRectangleOnBackground(drawto, xstart, ystart2 + (i - start) * ystep,
2551                                TILEX, TILEY);
2552     DrawGraphicAnimationExt(drawto, xstart, ystart2 + (i - start) * ystep,
2553                             graphic, sync_frame, USE_MASKING);
2554
2555     if (init)
2556       DrawInfoScreen_HelpText(element, action, direction, i - start);
2557
2558     i++;
2559   }
2560
2561   redraw_mask |= REDRAW_FIELD;
2562
2563   FrameCounter++;
2564 }
2565
2566 static char *getHelpText(int element, int action, int direction)
2567 {
2568   char token[MAX_LINE_LEN];
2569
2570   strcpy(token, element_info[element].token_name);
2571
2572   if (action != -1)
2573     strcat(token, element_action_info[action].suffix);
2574
2575   if (direction != -1)
2576     strcat(token, element_direction_info[MV_DIR_TO_BIT(direction)].suffix);
2577
2578   return getHashEntry(helptext_info, token);
2579 }
2580
2581 void DrawInfoScreen_HelpText(int element, int action, int direction, int ypos)
2582 {
2583 #if 1
2584   int font_nr = FONT_INFO_ELEMENTS;
2585 #else
2586   int font_nr = FONT_LEVEL_NUMBER;
2587 #endif
2588   int font_width = getFontWidth(font_nr);
2589   int sx = mSX + MINI_TILEX + TILEX + MINI_TILEX;
2590   int sy = mSY + 65 + 2 * 32 + 1;
2591   int ystep = TILEY + 4;
2592   int pad_x = sx - SX;
2593   int max_chars_per_line = (SXSIZE - pad_x - MINI_TILEX) / font_width;
2594   int max_lines_per_text = 2;    
2595   char *text = NULL;
2596
2597   if (action != -1 && direction != -1)          /* element.action.direction */
2598     text = getHelpText(element, action, direction);
2599
2600   if (text == NULL && action != -1)             /* element.action */
2601     text = getHelpText(element, action, -1);
2602
2603   if (text == NULL && direction != -1)          /* element.direction */
2604     text = getHelpText(element, -1, direction);
2605
2606   if (text == NULL)                             /* base element */
2607     text = getHelpText(element, -1, -1);
2608
2609   if (text == NULL)                             /* not found */
2610     text = "No description available";
2611
2612   if (strlen(text) <= max_chars_per_line)       /* only one line of text */
2613     sy += getFontHeight(font_nr) / 2;
2614
2615 #if 1
2616   DrawTextBuffer(sx, sy + ypos * ystep, text, font_nr,
2617                  max_chars_per_line, -1, max_lines_per_text, -1,
2618                  TRUE, FALSE, FALSE);
2619 #else
2620   DrawTextWrapped(sx, sy + ypos * ystep, text, font_nr,
2621                   max_chars_per_line, max_lines_per_text);
2622 #endif
2623 }
2624
2625 void DrawInfoScreen_TitleScreen()
2626 {
2627   DrawTitleScreen();
2628 }
2629
2630 void HandleInfoScreen_TitleScreen(int button)
2631 {
2632   HandleTitleScreen(0, 0, 0, 0, button);
2633 }
2634
2635 void DrawInfoScreen_Elements()
2636 {
2637   SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_ELEMENTS);
2638
2639 #if XFADE
2640   if (fading.anim_mode == ANIM_CROSSFADE)
2641     FadeCrossSaveBackbuffer();
2642   else
2643     FadeOut(REDRAW_FIELD);
2644 #else
2645   FadeOut(REDRAW_FIELD);
2646 #endif
2647
2648   LoadHelpAnimInfo();
2649   LoadHelpTextInfo();
2650
2651   HandleInfoScreen_Elements(MB_MENU_INITIALIZE);
2652
2653 #if XFADE
2654   if (fading.anim_mode == ANIM_CROSSFADE)
2655     FadeCross(REDRAW_FIELD);
2656   else
2657     FadeIn(REDRAW_FIELD);
2658 #else
2659   FadeIn(REDRAW_FIELD);
2660 #endif
2661
2662   InitAnimation();
2663 }
2664
2665 void HandleInfoScreen_Elements(int button)
2666 {
2667   static unsigned long info_delay = 0;
2668   static int num_anims;
2669   static int num_pages;
2670   static int page;
2671   int anims_per_page = MAX_INFO_ELEMENTS_ON_SCREEN;
2672   int i;
2673
2674   if (button == MB_MENU_INITIALIZE)
2675   {
2676     boolean new_element = TRUE;
2677
2678     num_anims = 0;
2679
2680     for (i = 0; helpanim_info[i].element != HELPANIM_LIST_END; i++)
2681     {
2682       if (helpanim_info[i].element == HELPANIM_LIST_NEXT)
2683         new_element = TRUE;
2684       else if (new_element)
2685       {
2686         num_anims++;
2687         new_element = FALSE;
2688       }
2689     }
2690
2691     num_pages = (num_anims + anims_per_page - 1) / anims_per_page;
2692     page = 0;
2693   }
2694
2695   if (button == MB_MENU_LEAVE)
2696   {
2697     PlaySound(SND_MENU_ITEM_SELECTING);
2698
2699     info_mode = INFO_MODE_MAIN;
2700     DrawInfoScreen();
2701
2702     return;
2703   }
2704   else if (button == MB_MENU_CHOICE || button == MB_MENU_INITIALIZE)
2705   {
2706     if (button != MB_MENU_INITIALIZE)
2707     {
2708       PlaySound(SND_MENU_ITEM_SELECTING);
2709
2710       page++;
2711     }
2712
2713     if (page >= num_pages)
2714     {
2715       FadeSoundsAndMusic();
2716
2717 #if 0
2718 #if XFADE
2719       if (fading.anim_mode == ANIM_CROSSFADE)
2720         FadeCrossSaveBackbuffer();
2721       else
2722         FadeOut(REDRAW_FIELD);
2723 #else
2724       FadeOut(REDRAW_FIELD);
2725 #endif
2726 #endif
2727
2728       info_mode = INFO_MODE_MAIN;
2729       DrawAndFadeInInfoScreen(REDRAW_FIELD);
2730
2731       return;
2732     }
2733
2734     if (button != MB_MENU_INITIALIZE)
2735       FadeCrossSaveBackbuffer();
2736
2737     DrawInfoScreen_HelpAnim(page * anims_per_page, num_anims, TRUE);
2738
2739     if (button != MB_MENU_INITIALIZE)
2740       FadeCross(REDRAW_FIELD);
2741   }
2742   else
2743   {
2744     if (DelayReached(&info_delay, GameFrameDelay))
2745       if (page < num_pages)
2746         DrawInfoScreen_HelpAnim(page * anims_per_page, num_anims, FALSE);
2747
2748     PlayMenuSoundIfLoop();
2749   }
2750 }
2751
2752 void DrawInfoScreen_Music()
2753 {
2754   SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_MUSIC);
2755
2756 #if XFADE
2757   if (fading.anim_mode == ANIM_CROSSFADE)
2758     FadeCrossSaveBackbuffer();
2759   else
2760     FadeOut(REDRAW_FIELD);
2761 #else
2762   FadeOut(REDRAW_FIELD);
2763 #endif
2764
2765   ClearWindow();
2766   DrawHeadline();
2767
2768   LoadMusicInfo();
2769
2770   HandleInfoScreen_Music(MB_MENU_INITIALIZE);
2771
2772 #if XFADE
2773   if (fading.anim_mode == ANIM_CROSSFADE)
2774     FadeCross(REDRAW_FIELD);
2775   else
2776     FadeIn(REDRAW_FIELD);
2777 #else
2778   FadeIn(REDRAW_FIELD);
2779 #endif
2780 }
2781
2782 void HandleInfoScreen_Music(int button)
2783 {
2784   static struct MusicFileInfo *list = NULL;
2785   int ystart1 = mSY - SY + 100;
2786   int ystart2 = mSY - SY + 150;
2787   int ybottom = mSY - SY + SYSIZE - 20;
2788   int dy = 30;
2789
2790   if (button == MB_MENU_INITIALIZE)
2791   {
2792     list = music_file_info;
2793
2794     if (list == NULL)
2795     {
2796       FadeSoundsAndMusic();
2797
2798       ClearWindow();
2799       DrawHeadline();
2800
2801       DrawTextSCentered(ystart1, FONT_TEXT_1,
2802                         "No music info for this level set.");
2803
2804       DrawTextSCentered(ybottom, FONT_TEXT_4,
2805                         "Press any key or button for info menu");
2806
2807       return;
2808     }
2809   }
2810
2811   if (button == MB_MENU_LEAVE)
2812   {
2813     PlaySound(SND_MENU_ITEM_SELECTING);
2814
2815     FadeSoundsAndMusic();
2816
2817     info_mode = INFO_MODE_MAIN;
2818     DrawInfoScreen();
2819
2820     return;
2821   }
2822   else if (button == MB_MENU_CHOICE || button == MB_MENU_INITIALIZE)
2823   {
2824     int y = 0;
2825
2826     if (button != MB_MENU_INITIALIZE)
2827     {
2828       PlaySound(SND_MENU_ITEM_SELECTING);
2829
2830       if (list != NULL)
2831         list = list->next;
2832     }
2833
2834     if (list == NULL)
2835     {
2836       FadeSoundsAndMusic();
2837
2838 #if 0
2839 #if XFADE
2840       if (fading.anim_mode == ANIM_CROSSFADE)
2841         FadeCrossSaveBackbuffer();
2842       else
2843         FadeOut(REDRAW_FIELD);
2844 #else
2845       FadeOut(REDRAW_FIELD);
2846 #endif
2847 #endif
2848
2849       info_mode = INFO_MODE_MAIN;
2850       DrawAndFadeInInfoScreen(REDRAW_FIELD);
2851
2852       return;
2853     }
2854
2855     FadeSoundsAndMusic();
2856
2857     if (button != MB_MENU_INITIALIZE)
2858       FadeCrossSaveBackbuffer();
2859
2860     ClearWindow();
2861     DrawHeadline();
2862
2863     if (list->is_sound)
2864     {
2865       int sound = list->music;
2866
2867       if (sound_info[sound].loop)
2868         PlaySoundLoop(sound);
2869       else
2870         PlaySound(sound);
2871
2872       DrawTextSCentered(ystart1, FONT_TEXT_1, "The Game Background Sounds:");
2873     }
2874     else
2875     {
2876       PlayMusic(list->music);
2877
2878       DrawTextSCentered(ystart1, FONT_TEXT_1, "The Game Background Music:");
2879     }
2880
2881     if (!strEqual(list->title, UNKNOWN_NAME))
2882     {
2883       if (!strEqual(list->title_header, UNKNOWN_NAME))
2884         DrawTextSCentered(ystart2 + y++ * dy, FONT_TEXT_2, list->title_header);
2885
2886       DrawTextFCentered(ystart2 + y++ * dy, FONT_TEXT_3, "\"%s\"", list->title);
2887     }
2888
2889     if (!strEqual(list->artist, UNKNOWN_NAME))
2890     {
2891       if (!strEqual(list->artist_header, UNKNOWN_NAME))
2892         DrawTextSCentered(ystart2 + y++ * dy, FONT_TEXT_2, list->artist_header);
2893       else
2894         DrawTextSCentered(ystart2 + y++ * dy, FONT_TEXT_2, "by");
2895
2896       DrawTextFCentered(ystart2 + y++ * dy, FONT_TEXT_3, "%s", list->artist);
2897     }
2898
2899     if (!strEqual(list->album, UNKNOWN_NAME))
2900     {
2901       if (!strEqual(list->album_header, UNKNOWN_NAME))
2902         DrawTextSCentered(ystart2 + y++ * dy, FONT_TEXT_2, list->album_header);
2903       else
2904         DrawTextSCentered(ystart2 + y++ * dy, FONT_TEXT_2, "from the album");
2905
2906       DrawTextFCentered(ystart2 + y++ * dy, FONT_TEXT_3, "\"%s\"", list->album);
2907     }
2908
2909     if (!strEqual(list->year, UNKNOWN_NAME))
2910     {
2911       if (!strEqual(list->year_header, UNKNOWN_NAME))
2912         DrawTextSCentered(ystart2 + y++ * dy, FONT_TEXT_2, list->year_header);
2913       else
2914         DrawTextSCentered(ystart2 + y++ * dy, FONT_TEXT_2, "from the year");
2915
2916       DrawTextFCentered(ystart2 + y++ * dy, FONT_TEXT_3, "%s", list->year);
2917     }
2918
2919     DrawTextSCentered(ybottom, FONT_TEXT_4,
2920                       "Press any key or button for next page");
2921
2922     if (button != MB_MENU_INITIALIZE)
2923       FadeCross(REDRAW_FIELD);
2924   }
2925
2926   if (list != NULL && list->is_sound && sound_info[list->music].loop)
2927     PlaySoundLoop(list->music);
2928 }
2929
2930 static boolean DrawInfoScreen_CreditsScreen(int screen_nr)
2931 {
2932   int ystart1 = mSY - SY + 100;
2933   int ystart2 = mSY - SY + 150;
2934   int ybottom = mSY - SY + SYSIZE - 20;
2935   int ystep = 30;
2936
2937   if (screen_nr > 8)
2938     return FALSE;
2939
2940   ClearWindow();
2941   DrawHeadline();
2942
2943   DrawTextSCentered(ystart1, FONT_TEXT_1, "Credits:");
2944
2945   if (screen_nr == 0)
2946   {
2947     DrawTextSCentered(ystart2 + 0 * ystep, FONT_TEXT_2,
2948                       "Special thanks to");
2949     DrawTextSCentered(ystart2 + 1 * ystep, FONT_TEXT_3,
2950                       "Peter Liepa");
2951     DrawTextSCentered(ystart2 + 2 * ystep, FONT_TEXT_2,
2952                       "for creating");
2953     DrawTextSCentered(ystart2 + 3 * ystep, FONT_TEXT_3,
2954                       "\"Boulder Dash\"");
2955     DrawTextSCentered(ystart2 + 4 * ystep, FONT_TEXT_2,
2956                       "in the year");
2957     DrawTextSCentered(ystart2 + 5 * ystep, FONT_TEXT_3,
2958                       "1984");
2959     DrawTextSCentered(ystart2 + 6 * ystep, FONT_TEXT_2,
2960                       "published by");
2961     DrawTextSCentered(ystart2 + 7 * ystep, FONT_TEXT_3,
2962                       "First Star Software");
2963   }
2964   else if (screen_nr == 1)
2965   {
2966     DrawTextSCentered(ystart2 + 0 * ystep, FONT_TEXT_2,
2967                       "Special thanks to");
2968     DrawTextSCentered(ystart2 + 1 * ystep, FONT_TEXT_3,
2969                       "Klaus Heinz & Volker Wertich");
2970     DrawTextSCentered(ystart2 + 2 * ystep, FONT_TEXT_2,
2971                       "for creating");
2972     DrawTextSCentered(ystart2 + 3 * ystep, FONT_TEXT_3,
2973                       "\"Emerald Mine\"");
2974     DrawTextSCentered(ystart2 + 4 * ystep, FONT_TEXT_2,
2975                       "in the year");
2976     DrawTextSCentered(ystart2 + 5 * ystep, FONT_TEXT_3,
2977                       "1987");
2978     DrawTextSCentered(ystart2 + 6 * ystep, FONT_TEXT_2,
2979                       "published by");
2980     DrawTextSCentered(ystart2 + 7 * ystep, FONT_TEXT_3,
2981                       "Kingsoft");
2982   }
2983   else if (screen_nr == 2)
2984   {
2985     DrawTextSCentered(ystart2 + 0 * ystep, FONT_TEXT_2,
2986                       "Special thanks to");
2987     DrawTextSCentered(ystart2 + 1 * ystep, FONT_TEXT_3,
2988                       "Michael Stopp & Philip Jespersen");
2989     DrawTextSCentered(ystart2 + 2 * ystep, FONT_TEXT_2,
2990                       "for creating");
2991     DrawTextSCentered(ystart2 + 3 * ystep, FONT_TEXT_3,
2992                       "\"Supaplex\"");
2993     DrawTextSCentered(ystart2 + 4 * ystep, FONT_TEXT_2,
2994                       "in the year");
2995     DrawTextSCentered(ystart2 + 5 * ystep, FONT_TEXT_3,
2996                       "1991");
2997     DrawTextSCentered(ystart2 + 6 * ystep, FONT_TEXT_2,
2998                       "published by");
2999     DrawTextSCentered(ystart2 + 7 * ystep, FONT_TEXT_3,
3000                       "Digital Integration");
3001   }
3002   else if (screen_nr == 3)
3003   {
3004     DrawTextSCentered(ystart2 + 0 * ystep, FONT_TEXT_2,
3005                       "Special thanks to");
3006     DrawTextSCentered(ystart2 + 1 * ystep, FONT_TEXT_3,
3007                       "Hiroyuki Imabayashi");
3008     DrawTextSCentered(ystart2 + 2 * ystep, FONT_TEXT_2,
3009                       "for creating");
3010     DrawTextSCentered(ystart2 + 3 * ystep, FONT_TEXT_3,
3011                       "\"Sokoban\"");
3012     DrawTextSCentered(ystart2 + 4 * ystep, FONT_TEXT_2,
3013                       "in the year");
3014     DrawTextSCentered(ystart2 + 5 * ystep, FONT_TEXT_3,
3015                       "1982");
3016     DrawTextSCentered(ystart2 + 6 * ystep, FONT_TEXT_2,
3017                       "published by");
3018     DrawTextSCentered(ystart2 + 7 * ystep, FONT_TEXT_3,
3019                       "Thinking Rabbit");
3020   }
3021   else if (screen_nr == 4)
3022   {
3023     DrawTextSCentered(ystart2 + 0 * ystep, FONT_TEXT_2,
3024                       "Special thanks to");
3025     DrawTextSCentered(ystart2 + 1 * ystep, FONT_TEXT_3,
3026                       "Alan Bond");
3027     DrawTextSCentered(ystart2 + 2 * ystep, FONT_TEXT_2,
3028                       "and");
3029     DrawTextSCentered(ystart2 + 3 * ystep, FONT_TEXT_3,
3030                       "Jürgen Bonhagen");
3031     DrawTextSCentered(ystart2 + 4 * ystep, FONT_TEXT_2,
3032                       "for the continuous creation");
3033     DrawTextSCentered(ystart2 + 5 * ystep, FONT_TEXT_2,
3034                       "of outstanding level sets");
3035   }
3036   else if (screen_nr == 5)
3037   {
3038     DrawTextSCentered(ystart2 + 0 * ystep, FONT_TEXT_2,
3039                       "Thanks to");
3040     DrawTextSCentered(ystart2 + 1 * ystep, FONT_TEXT_3,
3041                       "Peter Elzner");
3042     DrawTextSCentered(ystart2 + 2 * ystep, FONT_TEXT_2,
3043                       "for ideas and inspiration by");
3044     DrawTextSCentered(ystart2 + 3 * ystep, FONT_TEXT_3,
3045                       "Diamond Caves");
3046
3047     DrawTextSCentered(ystart2 + 5 * ystep, FONT_TEXT_2,
3048                       "Thanks to");
3049     DrawTextSCentered(ystart2 + 6 * ystep, FONT_TEXT_3,
3050                       "Steffest");
3051     DrawTextSCentered(ystart2 + 7 * ystep, FONT_TEXT_2,
3052                       "for ideas and inspiration by");
3053     DrawTextSCentered(ystart2 + 8 * ystep, FONT_TEXT_3,
3054                       "DX-Boulderdash");
3055   }
3056   else if (screen_nr == 6)
3057   {
3058     DrawTextSCentered(ystart2 + 0 * ystep, FONT_TEXT_2,
3059                       "Thanks to");
3060     DrawTextSCentered(ystart2 + 1 * ystep, FONT_TEXT_3,
3061                       "David Tritscher");
3062     DrawTextSCentered(ystart2 + 2 * ystep, FONT_TEXT_2,
3063                       "for the new Emerald Mine engine");
3064   }
3065   else if (screen_nr == 7)
3066   {
3067     DrawTextSCentered(ystart2 + 0 * ystep, FONT_TEXT_2,
3068                       "Thanks to");
3069     DrawTextSCentered(ystart2 + 1 * ystep, FONT_TEXT_3,
3070                       "Guido Schulz");
3071     DrawTextSCentered(ystart2 + 2 * ystep, FONT_TEXT_2,
3072                       "for the initial DOS port");
3073
3074     DrawTextSCentered(ystart2 + 4 * ystep, FONT_TEXT_2,
3075                       "Thanks to");
3076     DrawTextSCentered(ystart2 + 5 * ystep, FONT_TEXT_3,
3077                       "Karl Hörnell");
3078     DrawTextSCentered(ystart2 + 6 * ystep, FONT_TEXT_2,
3079                       "for some additional toons");
3080   }
3081   else if (screen_nr == 8)
3082   {
3083     DrawTextSCentered(ystart2 + 0 * ystep, FONT_TEXT_2,
3084                       "And not to forget:");
3085     DrawTextSCentered(ystart2 + 1 * ystep, FONT_TEXT_2,
3086                       "Many thanks to");
3087     DrawTextSCentered(ystart2 + 2 * ystep, FONT_TEXT_3,
3088                       "All those who contributed");
3089     DrawTextSCentered(ystart2 + 3 * ystep, FONT_TEXT_3,
3090                       "levels to this game");
3091     DrawTextSCentered(ystart2 + 4 * ystep, FONT_TEXT_3,
3092                       "since 1995");
3093   }
3094 #if 0
3095   else
3096   {
3097     return FALSE;
3098   }
3099 #endif
3100
3101   DrawTextSCentered(ybottom, FONT_TEXT_4,
3102                     "Press any key or button for next page");
3103
3104   return TRUE;
3105 }
3106
3107 void DrawInfoScreen_Credits()
3108 {
3109   SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_CREDITS);
3110
3111   FadeSoundsAndMusic();
3112
3113 #if XFADE
3114   if (fading.anim_mode == ANIM_CROSSFADE)
3115     FadeCrossSaveBackbuffer();
3116   else
3117     FadeOut(REDRAW_FIELD);
3118 #else
3119   FadeOut(REDRAW_FIELD);
3120 #endif
3121
3122   HandleInfoScreen_Credits(MB_MENU_INITIALIZE);
3123
3124 #if XFADE
3125   if (fading.anim_mode == ANIM_CROSSFADE)
3126     FadeCross(REDRAW_FIELD);
3127   else
3128     FadeIn(REDRAW_FIELD);
3129 #else
3130   FadeIn(REDRAW_FIELD);
3131 #endif
3132 }
3133
3134 void HandleInfoScreen_Credits(int button)
3135 {
3136   static int screen_nr = 0;
3137
3138   if (button == MB_MENU_INITIALIZE)
3139   {
3140     screen_nr = 0;
3141
3142     DrawInfoScreen_CreditsScreen(screen_nr);
3143   }
3144   else if (button == MB_MENU_LEAVE)
3145   {
3146     PlaySound(SND_MENU_ITEM_SELECTING);
3147
3148     info_mode = INFO_MODE_MAIN;
3149     DrawInfoScreen();
3150
3151     return;
3152   }
3153   else if (button == MB_MENU_CHOICE)
3154   {
3155     boolean show_screen;
3156
3157     PlaySound(SND_MENU_ITEM_SELECTING);
3158
3159     screen_nr++;
3160
3161     FadeCrossSaveBackbuffer();
3162
3163     show_screen = DrawInfoScreen_CreditsScreen(screen_nr);
3164   
3165     if (show_screen)
3166     {
3167       FadeCross(REDRAW_FIELD);
3168     }
3169     else
3170     {
3171       FadeSoundsAndMusic();
3172
3173 #if 0
3174 #if XFADE
3175       if (fading.anim_mode == ANIM_CROSSFADE)
3176         FadeCrossSaveBackbuffer();
3177       else
3178         FadeOut(REDRAW_FIELD);
3179 #else
3180       FadeOut(REDRAW_FIELD);
3181 #endif
3182 #endif
3183
3184       info_mode = INFO_MODE_MAIN;
3185       DrawAndFadeInInfoScreen(REDRAW_FIELD);
3186     }
3187   }
3188   else
3189   {
3190     PlayMenuSoundIfLoop();
3191   }
3192 }
3193
3194 void DrawInfoScreen_Program()
3195 {
3196   int ystart1 = mSY - SY + 100;
3197   int ystart2 = mSY - SY + 150;
3198   int ybottom = mSY - SY + SYSIZE - 20;
3199   int ystep = 30;
3200
3201   SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_PROGRAM);
3202
3203 #if XFADE
3204   if (fading.anim_mode == ANIM_CROSSFADE)
3205     FadeCrossSaveBackbuffer();
3206   else
3207     FadeOut(REDRAW_FIELD);
3208 #else
3209   FadeOut(REDRAW_FIELD);
3210 #endif
3211
3212   ClearWindow();
3213   DrawHeadline();
3214
3215   DrawTextSCentered(ystart1, FONT_TEXT_1, "Program Information:");
3216
3217   DrawTextSCentered(ystart2 + 0 * ystep, FONT_TEXT_2,
3218                     "This game is Freeware!");
3219   DrawTextSCentered(ystart2 + 1 * ystep, FONT_TEXT_2,
3220                     "If you like it, send e-mail to:");
3221   DrawTextSCentered(ystart2 + 2 * ystep, FONT_TEXT_3,
3222                     PROGRAM_EMAIL_STRING);
3223   DrawTextSCentered(ystart2 + 3 * ystep, FONT_TEXT_2,
3224                     "or SnailMail to:");
3225   DrawTextSCentered(ystart2 + 4 * ystep + 0, FONT_TEXT_3,
3226                     "Holger Schemel");
3227   DrawTextSCentered(ystart2 + 4 * ystep + 20, FONT_TEXT_3,
3228                     "Detmolder Strasse 189");
3229   DrawTextSCentered(ystart2 + 4 * ystep + 40, FONT_TEXT_3,
3230                     "33604 Bielefeld");
3231   DrawTextSCentered(ystart2 + 4 * ystep + 60, FONT_TEXT_3,
3232                     "Germany");
3233   DrawTextSCentered(ystart2 + 7 * ystep, FONT_TEXT_2,
3234                     "More information and levels:");
3235   DrawTextSCentered(ystart2 + 8 * ystep, FONT_TEXT_3,
3236                     PROGRAM_WEBSITE_STRING);
3237   DrawTextSCentered(ystart2 + 9 * ystep, FONT_TEXT_2,
3238                     "If you have created new levels,");
3239   DrawTextSCentered(ystart2 + 10 * ystep, FONT_TEXT_2,
3240                     "send them to me to include them!");
3241   DrawTextSCentered(ystart2 + 11 * ystep, FONT_TEXT_2,
3242                     ":-)");
3243
3244   DrawTextSCentered(ybottom, FONT_TEXT_4,
3245                     "Press any key or button for info menu");
3246
3247 #if XFADE
3248   if (fading.anim_mode == ANIM_CROSSFADE)
3249     FadeCross(REDRAW_FIELD);
3250   else
3251     FadeIn(REDRAW_FIELD);
3252 #else
3253   FadeIn(REDRAW_FIELD);
3254 #endif
3255 }
3256
3257 void HandleInfoScreen_Program(int button)
3258 {
3259   if (button == MB_MENU_LEAVE)
3260   {
3261     PlaySound(SND_MENU_ITEM_SELECTING);
3262
3263     info_mode = INFO_MODE_MAIN;
3264     DrawInfoScreen();
3265
3266     return;
3267   }
3268   else if (button == MB_MENU_CHOICE)
3269   {
3270     PlaySound(SND_MENU_ITEM_SELECTING);
3271
3272     FadeSoundsAndMusic();
3273
3274 #if 0
3275 #if XFADE
3276     if (fading.anim_mode == ANIM_CROSSFADE)
3277       FadeCrossSaveBackbuffer();
3278     else
3279       FadeOut(REDRAW_FIELD);
3280 #else
3281     FadeOut(REDRAW_FIELD);
3282 #endif
3283 #endif
3284
3285     info_mode = INFO_MODE_MAIN;
3286     DrawAndFadeInInfoScreen(REDRAW_FIELD);
3287   }
3288   else
3289   {
3290     PlayMenuSoundIfLoop();
3291   }
3292 }
3293
3294 void DrawInfoScreen_Version()
3295 {
3296   int font_header = FONT_TEXT_3;
3297   int font_text = FONT_TEXT_2;
3298   int xstep = getFontWidth(font_text);
3299   int ystep = getFontHeight(font_text);
3300   int ystart1 = mSY - SY + 100;
3301   int ystart2 = mSY - SY + 150;
3302   int ybottom = mSY - SY + SYSIZE - 20;
3303   int xstart1 = mSX + 2 * xstep;
3304   int xstart2 = mSX + 19 * xstep;
3305 #if defined(TARGET_SDL)
3306   int xstart3 = mSX + 29 * xstep;
3307   SDL_version sdl_version_compiled;
3308   const SDL_version *sdl_version_linked;
3309   int driver_name_len = 8;
3310   char driver_name[driver_name_len];
3311 #endif
3312
3313   SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_VERSION);
3314
3315 #if XFADE
3316   if (fading.anim_mode == ANIM_CROSSFADE)
3317     FadeCrossSaveBackbuffer();
3318   else
3319     FadeOut(REDRAW_FIELD);
3320 #else
3321   FadeOut(REDRAW_FIELD);
3322 #endif
3323
3324   ClearWindow();
3325   DrawHeadline();
3326
3327   DrawTextSCentered(ystart1, FONT_TEXT_1, "Version Information:");
3328
3329   DrawTextF(xstart1, ystart2, font_header, "Name");
3330   DrawTextF(xstart2, ystart2, font_text, PROGRAM_TITLE_STRING);
3331
3332   ystart2 += ystep;
3333   DrawTextF(xstart1, ystart2, font_header, "Version");
3334   DrawTextF(xstart2, ystart2, font_text, getProgramFullVersionString());
3335
3336   ystart2 += ystep;
3337   DrawTextF(xstart1, ystart2, font_header, "Platform");
3338   DrawTextF(xstart2, ystart2, font_text, PLATFORM_STRING);
3339
3340   ystart2 += ystep;
3341   DrawTextF(xstart1, ystart2, font_header, "Target");
3342   DrawTextF(xstart2, ystart2, font_text, TARGET_STRING);
3343
3344   ystart2 += ystep;
3345   DrawTextF(xstart1, ystart2, font_header, "Compile time");
3346   DrawTextF(xstart2, ystart2, font_text, getCompileDateString());
3347
3348 #if defined(TARGET_SDL)
3349   ystart2 += 3 * ystep;
3350   DrawTextF(xstart1, ystart2, font_header, "Library");
3351   DrawTextF(xstart2, ystart2, font_header, "compiled");
3352   DrawTextF(xstart3, ystart2, font_header, "linked");
3353
3354   SDL_VERSION(&sdl_version_compiled);
3355   sdl_version_linked = SDL_Linked_Version();
3356
3357   ystart2 += 2 * ystep;
3358   DrawTextF(xstart1, ystart2, font_text, "SDL");
3359   DrawTextF(xstart2, ystart2, font_text, "%d.%d.%d",
3360             sdl_version_compiled.major,
3361             sdl_version_compiled.minor,
3362             sdl_version_compiled.patch);
3363   DrawTextF(xstart3, ystart2, font_text, "%d.%d.%d",
3364             sdl_version_linked->major,
3365             sdl_version_linked->minor,
3366             sdl_version_linked->patch);
3367
3368   SDL_IMAGE_VERSION(&sdl_version_compiled);
3369   sdl_version_linked = IMG_Linked_Version();
3370
3371   ystart2 += ystep;
3372   DrawTextF(xstart1, ystart2, font_text, "SDL_image");
3373   DrawTextF(xstart2, ystart2, font_text, "%d.%d.%d",
3374             sdl_version_compiled.major,
3375             sdl_version_compiled.minor,
3376             sdl_version_compiled.patch);
3377   DrawTextF(xstart3, ystart2, font_text, "%d.%d.%d",
3378             sdl_version_linked->major,
3379             sdl_version_linked->minor,
3380             sdl_version_linked->patch);
3381
3382   SDL_MIXER_VERSION(&sdl_version_compiled);
3383   sdl_version_linked = Mix_Linked_Version();
3384
3385   ystart2 += ystep;
3386   DrawTextF(xstart1, ystart2, font_text, "SDL_mixer");
3387   DrawTextF(xstart2, ystart2, font_text, "%d.%d.%d",
3388             sdl_version_compiled.major,
3389             sdl_version_compiled.minor,
3390             sdl_version_compiled.patch);
3391   DrawTextF(xstart3, ystart2, font_text, "%d.%d.%d",
3392             sdl_version_linked->major,
3393             sdl_version_linked->minor,
3394             sdl_version_linked->patch);
3395
3396   SDL_NET_VERSION(&sdl_version_compiled);
3397   sdl_version_linked = SDLNet_Linked_Version();
3398
3399   ystart2 += ystep;
3400   DrawTextF(xstart1, ystart2, font_text, "SDL_net");
3401   DrawTextF(xstart2, ystart2, font_text, "%d.%d.%d",
3402             sdl_version_compiled.major,
3403             sdl_version_compiled.minor,
3404             sdl_version_compiled.patch);
3405   DrawTextF(xstart3, ystart2, font_text, "%d.%d.%d",
3406             sdl_version_linked->major,
3407             sdl_version_linked->minor,
3408             sdl_version_linked->patch);
3409
3410   ystart2 += 3 * ystep;
3411   DrawTextF(xstart1, ystart2, font_header, "Driver");
3412   DrawTextF(xstart2, ystart2, font_header, "Requested");
3413   DrawTextF(xstart3, ystart2, font_header, "Used");
3414
3415   SDL_VideoDriverName(driver_name, driver_name_len);
3416
3417   ystart2 += 2 * ystep;
3418   DrawTextF(xstart1, ystart2, font_text, "SDL_VideoDriver");
3419   DrawTextF(xstart2, ystart2, font_text, "%s", setup.system.sdl_videodriver);
3420   DrawTextF(xstart3, ystart2, font_text, "%s", driver_name);
3421
3422   SDL_AudioDriverName(driver_name, driver_name_len);
3423
3424   ystart2 += ystep;
3425   DrawTextF(xstart1, ystart2, font_text, "SDL_AudioDriver");
3426   DrawTextF(xstart2, ystart2, font_text, "%s", setup.system.sdl_audiodriver);
3427   DrawTextF(xstart3, ystart2, font_text, "%s", driver_name);
3428 #endif
3429
3430   DrawTextSCentered(ybottom, FONT_TEXT_4,
3431                     "Press any key or button for info menu");
3432
3433 #if XFADE
3434   if (fading.anim_mode == ANIM_CROSSFADE)
3435     FadeCross(REDRAW_FIELD);
3436   else
3437     FadeIn(REDRAW_FIELD);
3438 #else
3439   FadeIn(REDRAW_FIELD);
3440 #endif
3441 }
3442
3443 void HandleInfoScreen_Version(int button)
3444 {
3445   if (button == MB_MENU_LEAVE)
3446   {
3447     PlaySound(SND_MENU_ITEM_SELECTING);
3448
3449     info_mode = INFO_MODE_MAIN;
3450     DrawInfoScreen();
3451
3452     return;
3453   }
3454   else if (button == MB_MENU_CHOICE)
3455   {
3456     PlaySound(SND_MENU_ITEM_SELECTING);
3457
3458     FadeSoundsAndMusic();
3459
3460 #if 0
3461 #if XFADE
3462     if (fading.anim_mode == ANIM_CROSSFADE)
3463       FadeCrossSaveBackbuffer();
3464     else
3465       FadeOut(REDRAW_FIELD);
3466 #else
3467     FadeOut(REDRAW_FIELD);
3468 #endif
3469 #endif
3470
3471     info_mode = INFO_MODE_MAIN;
3472     DrawAndFadeInInfoScreen(REDRAW_FIELD);
3473   }
3474   else
3475   {
3476     PlayMenuSoundIfLoop();
3477   }
3478 }
3479
3480 void DrawInfoScreen_LevelSet()
3481 {
3482   struct TitleMessageInfo *tmi = &readme;
3483   char *filename = getLevelSetInfoFilename();
3484
3485   /* if chars set to "-1", automatically determine by text and font width */
3486   if (tmi->chars == -1)
3487     tmi->chars = tmi->width / getFontWidth(tmi->font);
3488   else
3489     tmi->width = tmi->chars * getFontWidth(tmi->font);
3490
3491   /* if lines set to "-1", automatically determine by text and font height */
3492   if (tmi->lines == -1)
3493     tmi->lines = tmi->height / getFontHeight(tmi->font);
3494   else
3495     tmi->height = tmi->lines * getFontHeight(tmi->font);
3496
3497   SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_LEVELSET);
3498
3499 #if XFADE
3500   if (fading.anim_mode == ANIM_CROSSFADE)
3501     FadeCrossSaveBackbuffer();
3502   else
3503     FadeOut(REDRAW_FIELD);
3504 #else
3505   FadeOut(REDRAW_FIELD);
3506 #endif
3507
3508   ClearWindow();
3509   DrawHeadline();
3510
3511   DrawTextCentered(mSY + 100, FONT_TEXT_1, "Level Set Information:");
3512
3513   if (filename != NULL)
3514     DrawTextFile(mSX + ALIGNED_TEXT_XPOS(tmi), mSY + ALIGNED_TEXT_YPOS(tmi),
3515                  filename, tmi->font, tmi->chars, -1, tmi->lines, -1,
3516                  tmi->autowrap, tmi->centered, tmi->parse_comments);
3517   else
3518     DrawTextCentered(mSY + ALIGNED_TEXT_YPOS(tmi), FONT_TEXT_2,
3519                      "No information for this level set.");
3520
3521   DrawTextCentered(mSY + SYSIZE - 20, FONT_TEXT_4,
3522                    "Press any key or button for info menu");
3523
3524 #if XFADE
3525   if (fading.anim_mode == ANIM_CROSSFADE)
3526     FadeCross(REDRAW_FIELD);
3527   else
3528     FadeIn(REDRAW_FIELD);
3529 #else
3530   FadeIn(REDRAW_FIELD);
3531 #endif
3532 }
3533
3534 void HandleInfoScreen_LevelSet(int button)
3535 {
3536   if (button == MB_MENU_LEAVE)
3537   {
3538     PlaySound(SND_MENU_ITEM_SELECTING);
3539
3540     info_mode = INFO_MODE_MAIN;
3541     DrawInfoScreen();
3542
3543     return;
3544   }
3545   else if (button == MB_MENU_CHOICE)
3546   {
3547     PlaySound(SND_MENU_ITEM_SELECTING);
3548
3549     FadeSoundsAndMusic();
3550
3551 #if 0
3552 #if XFADE
3553     if (fading.anim_mode == ANIM_CROSSFADE)
3554       FadeCrossSaveBackbuffer();
3555     else
3556       FadeOut(REDRAW_FIELD);
3557 #else
3558     FadeOut(REDRAW_FIELD);
3559 #endif
3560 #endif
3561
3562     info_mode = INFO_MODE_MAIN;
3563     DrawAndFadeInInfoScreen(REDRAW_FIELD);
3564   }
3565   else
3566   {
3567     PlayMenuSoundIfLoop();
3568   }
3569 }
3570
3571 static void DrawInfoScreenExt(int redraw_mask, boolean do_fading)
3572 {
3573   SetMainBackgroundImage(IMG_BACKGROUND_INFO);
3574
3575   if (info_mode == INFO_MODE_TITLE)
3576     DrawInfoScreen_TitleScreen();
3577   else if (info_mode == INFO_MODE_ELEMENTS)
3578     DrawInfoScreen_Elements();
3579   else if (info_mode == INFO_MODE_MUSIC)
3580     DrawInfoScreen_Music();
3581   else if (info_mode == INFO_MODE_CREDITS)
3582     DrawInfoScreen_Credits();
3583   else if (info_mode == INFO_MODE_PROGRAM)
3584     DrawInfoScreen_Program();
3585   else if (info_mode == INFO_MODE_VERSION)
3586     DrawInfoScreen_Version();
3587   else if (info_mode == INFO_MODE_LEVELSET)
3588     DrawInfoScreen_LevelSet();
3589   else
3590     DrawInfoScreen_Main(redraw_mask, do_fading);
3591
3592   if (info_mode != INFO_MODE_MAIN &&
3593       info_mode != INFO_MODE_TITLE &&
3594       info_mode != INFO_MODE_MUSIC)
3595   {
3596     PlayMenuSound();
3597     PlayMenuMusic();
3598   }
3599 }
3600
3601 void DrawAndFadeInInfoScreen(int redraw_mask)
3602 {
3603   DrawInfoScreenExt(redraw_mask, TRUE);
3604 }
3605
3606 void DrawInfoScreen()
3607 {
3608   DrawInfoScreenExt(REDRAW_ALL, FALSE);
3609 }
3610
3611 void HandleInfoScreen(int mx, int my, int dx, int dy, int button)
3612 {
3613   if (info_mode == INFO_MODE_TITLE)
3614     HandleInfoScreen_TitleScreen(button);
3615   else if (info_mode == INFO_MODE_ELEMENTS)
3616     HandleInfoScreen_Elements(button);
3617   else if (info_mode == INFO_MODE_MUSIC)
3618     HandleInfoScreen_Music(button);
3619   else if (info_mode == INFO_MODE_CREDITS)
3620     HandleInfoScreen_Credits(button);
3621   else if (info_mode == INFO_MODE_PROGRAM)
3622     HandleInfoScreen_Program(button);
3623   else if (info_mode == INFO_MODE_VERSION)
3624     HandleInfoScreen_Version(button);
3625   else if (info_mode == INFO_MODE_LEVELSET)
3626     HandleInfoScreen_LevelSet(button);
3627   else
3628     HandleInfoScreen_Main(mx, my, dx, dy, button);
3629
3630   DoAnimation();
3631 }
3632
3633
3634 /* ========================================================================= */
3635 /* type name functions                                                       */
3636 /* ========================================================================= */
3637
3638 void HandleTypeName(int newxpos, Key key)
3639 {
3640   static char last_player_name[MAX_PLAYER_NAME_LEN + 1];
3641   struct MainControlInfo *mci = getMainControlInfo(MAIN_CONTROL_NAME);
3642 #if 1
3643   struct TextPosInfo *pos = mci->pos_input;
3644   int startx = mSX + ALIGNED_TEXT_XPOS(pos);
3645   int starty = mSY + ALIGNED_TEXT_YPOS(pos);
3646 #endif
3647 #if 1
3648   static int xpos = 0;
3649 #else
3650   static int xpos = 0, ypos = 2;
3651 #endif
3652   int font_nr = pos->font;
3653   int font_active_nr = FONT_ACTIVE(font_nr);
3654   int font_width = getFontWidth(font_active_nr);
3655 #if 1
3656 #if 0
3657   int startx = mSX + mci->pos_input->x;
3658   int starty = mSY + mci->pos_input->y;
3659 #endif
3660 #else
3661   int name_width = getFontWidth(FONT_MENU_1) * strlen("Name:");
3662   int startx = mSX + 32 + name_width;
3663   int starty = mSY + ypos * 32;
3664 #endif
3665   char key_char = getValidConfigValueChar(getCharFromKey(key));
3666   boolean is_valid_key_char = (key_char != 0 && (key_char != ' ' || xpos > 0));
3667   boolean is_active = TRUE;
3668
3669   DrawBackgroundForFont(startx,starty, pos->width, pos->height, font_active_nr);
3670
3671   if (newxpos)
3672   {
3673     strcpy(last_player_name, setup.player_name);
3674
3675     xpos = newxpos;
3676
3677 #if 0
3678     /* add one character width for added cursor character */
3679     pos->width += font_width;
3680     startx = mSX + ALIGNED_TEXT_XPOS(pos);
3681
3682     DrawText(startx, starty, setup.player_name, font_active_nr);
3683     DrawText(startx + xpos * font_width, starty, "_", font_active_nr);
3684 #endif
3685   }
3686   else if (is_valid_key_char && xpos < MAX_PLAYER_NAME_LEN)
3687   {
3688     setup.player_name[xpos] = key_char;
3689     setup.player_name[xpos + 1] = 0;
3690
3691     xpos++;
3692
3693 #if 0
3694     /* add one character width for added name text character */
3695     pos->width += font_width;
3696     startx = mSX + ALIGNED_TEXT_XPOS(pos);
3697
3698     DrawText(startx, starty, setup.player_name, font_active_nr);
3699     DrawText(startx + xpos * font_width, starty, "_", font_active_nr);
3700 #endif
3701   }
3702   else if ((key == KSYM_Delete || key == KSYM_BackSpace) && xpos > 0)
3703   {
3704     xpos--;
3705
3706     setup.player_name[xpos] = 0;
3707
3708 #if 0
3709     /* remove one character width for removed name text character */
3710     pos->width -= font_width;
3711     startx = mSX + ALIGNED_TEXT_XPOS(pos);
3712
3713     DrawText(startx, starty, setup.player_name, font_active_nr);
3714     DrawText(startx + xpos * font_width, starty, "_ ", font_active_nr);
3715 #endif
3716   }
3717   else if (key == KSYM_Return && xpos > 0)
3718   {
3719 #if 0
3720     /* remove one character width for removed cursor text character */
3721     pos->width -= font_width;
3722     startx = mSX + ALIGNED_TEXT_XPOS(pos);
3723
3724     DrawText(startx, starty, setup.player_name, font_nr);
3725     DrawText(startx + xpos * font_width, starty, " ", font_active_nr);
3726 #endif
3727
3728     SaveSetup();
3729
3730     is_active = FALSE;
3731
3732     game_status = GAME_MODE_MAIN;
3733   }
3734   else if (key == KSYM_Escape)
3735   {
3736     strcpy(setup.player_name, last_player_name);
3737
3738     is_active = FALSE;
3739
3740     game_status = GAME_MODE_MAIN;
3741   }
3742
3743   if (is_active)
3744   {
3745     pos->width = (strlen(setup.player_name) + 1) * font_width;
3746     startx = mSX + ALIGNED_TEXT_XPOS(pos);
3747
3748     DrawText(startx, starty, setup.player_name, font_active_nr);
3749     DrawText(startx + xpos * font_width, starty, "_", font_active_nr);
3750   }
3751   else
3752   {
3753     pos->width = strlen(setup.player_name) * font_width;
3754     startx = mSX + ALIGNED_TEXT_XPOS(pos);
3755
3756     DrawText(startx, starty, setup.player_name, font_nr);
3757   }
3758 }
3759
3760
3761 /* ========================================================================= */
3762 /* tree menu functions                                                       */
3763 /* ========================================================================= */
3764
3765 static void DrawChooseTree(TreeInfo **ti_ptr)
3766 {
3767   UnmapAllGadgets();
3768
3769   FreeScreenGadgets();
3770   CreateScreenGadgets();
3771
3772   CloseDoor(DOOR_CLOSE_2);
3773
3774 #if XFADE
3775   if (fading.anim_mode == ANIM_CROSSFADE)
3776     FadeCrossSaveBackbuffer();
3777   else
3778     FadeOut(REDRAW_FIELD);
3779 #endif
3780
3781   ClearWindow();
3782
3783   HandleChooseTree(0, 0, 0, 0, MB_MENU_INITIALIZE, ti_ptr);
3784   MapScreenTreeGadgets(*ti_ptr);
3785
3786 #if XFADE
3787   if (fading.anim_mode == ANIM_CROSSFADE)
3788     FadeCross(redraw_mask);
3789   else
3790     FadeIn(redraw_mask);
3791 #else
3792   FadeToFront();
3793 #endif
3794
3795   InitAnimation();
3796 }
3797
3798 static void AdjustChooseTreeScrollbar(int id, int first_entry, TreeInfo *ti)
3799 {
3800   struct GadgetInfo *gi = screen_gadget[id];
3801   int items_max, items_visible, item_position;
3802
3803   items_max = numTreeInfoInGroup(ti);
3804   items_visible = NUM_MENU_ENTRIES_ON_SCREEN;
3805   item_position = first_entry;
3806
3807   if (item_position > items_max - items_visible)
3808     item_position = items_max - items_visible;
3809
3810   ModifyGadget(gi, GDI_SCROLLBAR_ITEMS_MAX, items_max,
3811                GDI_SCROLLBAR_ITEMS_VISIBLE, items_visible,
3812                GDI_SCROLLBAR_ITEM_POSITION, item_position, GDI_END);
3813 }
3814
3815 static void drawChooseTreeList(int first_entry, int num_page_entries,
3816                                TreeInfo *ti)
3817 {
3818   int i;
3819   char *title_string = NULL;
3820   int yoffset_sets = MENU_TITLE1_YPOS;
3821   int yoffset_setup = 16;
3822   int yoffset = (ti->type == TREE_TYPE_LEVEL_DIR ? yoffset_sets :
3823                  yoffset_setup);
3824   int last_game_status = game_status;   /* save current game status */
3825
3826   title_string = ti->infotext;
3827
3828   DrawTextSCentered(mSY - SY + yoffset, FONT_TITLE_1, title_string);
3829
3830   /* force LEVELS font on artwork setup screen */
3831   game_status = GAME_MODE_LEVELS;
3832
3833 #if 1
3834   /* clear tree list area, but not title or scrollbar */
3835   DrawBackground(mSX, mSY + MENU_SCREEN_START_YPOS * 32,
3836                  SC_SCROLLBAR_XPOS + menu.scrollbar_xoffset,
3837                  NUM_MENU_ENTRIES_ON_SCREEN * 32);
3838 #else
3839   /* clear tree list area, but not title or scrollbar */
3840   DrawBackground(mSX, mSY + MENU_SCREEN_START_YPOS * 32,
3841                  SC_SCROLLBAR_XPOS + menu.scrollbar_xoffset,
3842                  MAX_MENU_ENTRIES_ON_SCREEN * 32);
3843 #endif
3844
3845   for (i = 0; i < num_page_entries; i++)
3846   {
3847     TreeInfo *node, *node_first;
3848     int entry_pos = first_entry + i;
3849     int xpos = MENU_SCREEN_START_XPOS;
3850     int ypos = MENU_SCREEN_START_YPOS + i;
3851     int startx = mSX + xpos * 32;
3852     int starty = mSY + ypos * 32;
3853     int font_nr = FONT_TEXT_1;
3854     int font_xoffset = getFontBitmapInfo(font_nr)->draw_xoffset;
3855     int startx_text = startx + font_xoffset;
3856     int startx_scrollbar = mSX + SC_SCROLLBAR_XPOS + menu.scrollbar_xoffset;
3857     int text_size = startx_scrollbar - startx_text;
3858     int max_buffer_len = text_size / getFontWidth(font_nr);
3859     char buffer[max_buffer_len + 1];
3860
3861     node_first = getTreeInfoFirstGroupEntry(ti);
3862     node = getTreeInfoFromPos(node_first, entry_pos);
3863
3864     strncpy(buffer, node->name, max_buffer_len);
3865     buffer[max_buffer_len] = '\0';
3866
3867     DrawText(startx, starty, buffer, font_nr + node->color);
3868
3869     if (node->parent_link)
3870       initCursor(i, IMG_MENU_BUTTON_LEAVE_MENU);
3871     else if (node->level_group)
3872       initCursor(i, IMG_MENU_BUTTON_ENTER_MENU);
3873     else
3874       initCursor(i, IMG_MENU_BUTTON);
3875   }
3876
3877   game_status = last_game_status;       /* restore current game status */
3878
3879   redraw_mask |= REDRAW_FIELD;
3880 }
3881
3882 static void drawChooseTreeInfo(int entry_pos, TreeInfo *ti)
3883 {
3884   TreeInfo *node, *node_first;
3885   int x, last_redraw_mask = redraw_mask;
3886   int ypos = MENU_TITLE2_YPOS;
3887   int font_nr = FONT_TITLE_2;
3888
3889   if (ti->type != TREE_TYPE_LEVEL_DIR)
3890     return;
3891
3892   node_first = getTreeInfoFirstGroupEntry(ti);
3893   node = getTreeInfoFromPos(node_first, entry_pos);
3894
3895   DrawBackgroundForFont(SX, SY + ypos, SXSIZE, getFontHeight(font_nr), font_nr);
3896
3897   if (node->parent_link)
3898     DrawTextFCentered(ypos, font_nr, "leave group \"%s\"",
3899                       node->class_desc);
3900   else if (node->level_group)
3901     DrawTextFCentered(ypos, font_nr, "enter group \"%s\"",
3902                       node->class_desc);
3903   else if (ti->type == TREE_TYPE_LEVEL_DIR)
3904     DrawTextFCentered(ypos, font_nr, "%3d levels (%s)",
3905                       node->levels, node->class_desc);
3906
3907   /* let BackToFront() redraw only what is needed */
3908   redraw_mask = last_redraw_mask | REDRAW_TILES;
3909   for (x = 0; x < SCR_FIELDX; x++)
3910     MarkTileDirty(x, 1);
3911 }
3912
3913 static void HandleChooseTree(int mx, int my, int dx, int dy, int button,
3914                              TreeInfo **ti_ptr)
3915 {
3916   TreeInfo *ti = *ti_ptr;
3917   int x = 0;
3918   int y = ti->cl_cursor;
3919   int step = (button == 1 ? 1 : button == 2 ? 5 : 10);
3920   int num_entries = numTreeInfoInGroup(ti);
3921   int num_page_entries;
3922   int last_game_status = game_status;   /* save current game status */
3923   boolean position_set_by_scrollbar = (dx == 999);
3924
3925   /* force LEVELS draw offset on choose level and artwork setup screen */
3926   game_status = GAME_MODE_LEVELS;
3927
3928   if (num_entries <= NUM_MENU_ENTRIES_ON_SCREEN)
3929     num_page_entries = num_entries;
3930   else
3931     num_page_entries = NUM_MENU_ENTRIES_ON_SCREEN;
3932
3933   game_status = last_game_status;       /* restore current game status */
3934
3935   if (button == MB_MENU_INITIALIZE)
3936   {
3937     int num_entries = numTreeInfoInGroup(ti);
3938     int entry_pos = posTreeInfo(ti);
3939
3940     if (ti->cl_first == -1)
3941     {
3942       /* only on initialization */
3943       ti->cl_first = MAX(0, entry_pos - num_page_entries + 1);
3944       ti->cl_cursor = entry_pos - ti->cl_first;
3945     }
3946     else if (ti->cl_cursor >= num_page_entries ||
3947              (num_entries > num_page_entries &&
3948               num_entries - ti->cl_first < num_page_entries))
3949     {
3950       /* only after change of list size (by custom graphic configuration) */
3951       ti->cl_first = MAX(0, entry_pos - num_page_entries + 1);
3952       ti->cl_cursor = entry_pos - ti->cl_first;
3953     }
3954
3955     if (position_set_by_scrollbar)
3956       ti->cl_first = dy;
3957     else
3958       AdjustChooseTreeScrollbar(SCREEN_CTRL_ID_SCROLL_VERTICAL,
3959                                 ti->cl_first, ti);
3960
3961     drawChooseTreeList(ti->cl_first, num_page_entries, ti);
3962     drawChooseTreeInfo(ti->cl_first + ti->cl_cursor, ti);
3963     drawChooseTreeCursor(ti->cl_cursor, TRUE);
3964
3965     return;
3966   }
3967   else if (button == MB_MENU_LEAVE)
3968   {
3969     PlaySound(SND_MENU_ITEM_SELECTING);
3970
3971     if (ti->node_parent)
3972     {
3973       *ti_ptr = ti->node_parent;
3974       DrawChooseTree(ti_ptr);
3975     }
3976     else if (game_status == GAME_MODE_SETUP)
3977     {
3978       if (setup_mode == SETUP_MODE_CHOOSE_GAME_SPEED)
3979         execSetupGame();
3980       else if (setup_mode == SETUP_MODE_CHOOSE_SCREEN_MODE)
3981         execSetupGraphics();
3982       else
3983         execSetupArtwork();
3984     }
3985     else
3986     {
3987       game_status = GAME_MODE_MAIN;
3988 #if 1
3989       DrawMainMenuExt(REDRAW_FIELD, FALSE);
3990 #else
3991       DrawMainMenu();
3992 #endif
3993     }
3994
3995     return;
3996   }
3997
3998   if (mx || my)         /* mouse input */
3999   {
4000     int last_game_status = game_status; /* save current game status */
4001
4002     /* force LEVELS draw offset on artwork setup screen */
4003     game_status = GAME_MODE_LEVELS;
4004
4005     x = (mx - mSX) / 32;
4006     y = (my - mSY) / 32 - MENU_SCREEN_START_YPOS;
4007
4008     game_status = last_game_status;     /* restore current game status */
4009   }
4010   else if (dx || dy)    /* keyboard or scrollbar/scrollbutton input */
4011   {
4012     /* move cursor instead of scrolling when already at start/end of list */
4013     if (dy == -1 * SCROLL_LINE && ti->cl_first == 0)
4014       dy = -1;
4015     else if (dy == +1 * SCROLL_LINE &&
4016              ti->cl_first + num_page_entries == num_entries)
4017       dy = 1;
4018
4019     /* handle scrolling screen one line or page */
4020     if (ti->cl_cursor + dy < 0 ||
4021         ti->cl_cursor + dy > num_page_entries - 1)
4022     {
4023       if (ABS(dy) == SCROLL_PAGE)
4024         step = num_page_entries - 1;
4025
4026       if (dy < 0 && ti->cl_first > 0)
4027       {
4028         /* scroll page/line up */
4029
4030         ti->cl_first -= step;
4031         if (ti->cl_first < 0)
4032           ti->cl_first = 0;
4033
4034         drawChooseTreeList(ti->cl_first, num_page_entries, ti);
4035         drawChooseTreeInfo(ti->cl_first + ti->cl_cursor, ti);
4036         drawChooseTreeCursor(ti->cl_cursor, TRUE);
4037
4038         AdjustChooseTreeScrollbar(SCREEN_CTRL_ID_SCROLL_VERTICAL,
4039                                   ti->cl_first, ti);
4040       }
4041       else if (dy > 0 && ti->cl_first + num_page_entries < num_entries)
4042       {
4043         /* scroll page/line down */
4044
4045         ti->cl_first += step;
4046         if (ti->cl_first + num_page_entries > num_entries)
4047           ti->cl_first = MAX(0, num_entries - num_page_entries);
4048
4049         drawChooseTreeList(ti->cl_first, num_page_entries, ti);
4050         drawChooseTreeInfo(ti->cl_first + ti->cl_cursor, ti);
4051         drawChooseTreeCursor(ti->cl_cursor, TRUE);
4052
4053         AdjustChooseTreeScrollbar(SCREEN_CTRL_ID_SCROLL_VERTICAL,
4054                                   ti->cl_first, ti);
4055       }
4056
4057       return;
4058     }
4059
4060     /* handle moving cursor one line */
4061     y = ti->cl_cursor + dy;
4062   }
4063
4064   if (dx == 1)
4065   {
4066     TreeInfo *node_first, *node_cursor;
4067     int entry_pos = ti->cl_first + y;
4068
4069     node_first = getTreeInfoFirstGroupEntry(ti);
4070     node_cursor = getTreeInfoFromPos(node_first, entry_pos);
4071
4072     if (node_cursor->node_group)
4073     {
4074       PlaySound(SND_MENU_ITEM_SELECTING);
4075
4076       node_cursor->cl_first = ti->cl_first;
4077       node_cursor->cl_cursor = ti->cl_cursor;
4078       *ti_ptr = node_cursor->node_group;
4079       DrawChooseTree(ti_ptr);
4080
4081       return;
4082     }
4083   }
4084   else if (dx == -1 && ti->node_parent)
4085   {
4086     PlaySound(SND_MENU_ITEM_SELECTING);
4087
4088     *ti_ptr = ti->node_parent;
4089     DrawChooseTree(ti_ptr);
4090
4091     return;
4092   }
4093
4094   if (!anyScrollbarGadgetActive() &&
4095       IN_VIS_FIELD(x, y) &&
4096       mx < screen_gadget[SCREEN_CTRL_ID_SCROLL_VERTICAL]->x &&
4097       y >= 0 && y < num_page_entries)
4098   {
4099     if (button)
4100     {
4101       if (y != ti->cl_cursor)
4102       {
4103         PlaySound(SND_MENU_ITEM_ACTIVATING);
4104
4105         drawChooseTreeCursor(ti->cl_cursor, FALSE);
4106         drawChooseTreeCursor(y, TRUE);
4107         drawChooseTreeInfo(ti->cl_first + y, ti);
4108
4109         ti->cl_cursor = y;
4110       }
4111     }
4112     else
4113     {
4114       TreeInfo *node_first, *node_cursor;
4115       int entry_pos = ti->cl_first + y;
4116
4117       PlaySound(SND_MENU_ITEM_SELECTING);
4118
4119       node_first = getTreeInfoFirstGroupEntry(ti);
4120       node_cursor = getTreeInfoFromPos(node_first, entry_pos);
4121
4122       if (node_cursor->node_group)
4123       {
4124         node_cursor->cl_first = ti->cl_first;
4125         node_cursor->cl_cursor = ti->cl_cursor;
4126         *ti_ptr = node_cursor->node_group;
4127         DrawChooseTree(ti_ptr);
4128       }
4129       else if (node_cursor->parent_link)
4130       {
4131         *ti_ptr = node_cursor->node_parent;
4132         DrawChooseTree(ti_ptr);
4133       }
4134       else
4135       {
4136         node_cursor->cl_first = ti->cl_first;
4137         node_cursor->cl_cursor = ti->cl_cursor;
4138         *ti_ptr = node_cursor;
4139
4140         if (ti->type == TREE_TYPE_LEVEL_DIR)
4141         {
4142           LoadLevelSetup_SeriesInfo();
4143
4144           SaveLevelSetup_LastSeries();
4145           SaveLevelSetup_SeriesInfo();
4146           TapeErase();
4147         }
4148
4149         if (game_status == GAME_MODE_SETUP)
4150         {
4151           if (setup_mode == SETUP_MODE_CHOOSE_GAME_SPEED)
4152             execSetupGame();
4153           else if (setup_mode == SETUP_MODE_CHOOSE_SCREEN_MODE)
4154             execSetupGraphics();
4155           else
4156             execSetupArtwork();
4157         }
4158         else
4159         {
4160           game_status = GAME_MODE_MAIN;
4161           DrawMainMenu();
4162         }
4163       }
4164     }
4165   }
4166 }
4167
4168 void DrawChooseLevel()
4169 {
4170   SetMainBackgroundImage(IMG_BACKGROUND_LEVELS);
4171
4172   DrawChooseTree(&leveldir_current);
4173
4174   PlayMenuSound();
4175   PlayMenuMusic();
4176 }
4177
4178 void HandleChooseLevel(int mx, int my, int dx, int dy, int button)
4179 {
4180   HandleChooseTree(mx, my, dx, dy, button, &leveldir_current);
4181
4182   DoAnimation();
4183 }
4184
4185 void DrawHallOfFame(int highlight_position)
4186 {
4187   UnmapAllGadgets();
4188   FadeSoundsAndMusic();
4189
4190   /* (this is needed when called from GameEnd() after winning a game) */
4191   KeyboardAutoRepeatOn();
4192   ActivateJoystick();
4193
4194   /* (this is needed when called from GameEnd() after winning a game) */
4195   SetDrawDeactivationMask(REDRAW_NONE);
4196   SetDrawBackgroundMask(REDRAW_FIELD);
4197
4198   CloseDoor(DOOR_CLOSE_2);
4199
4200   if (highlight_position < 0) 
4201     LoadScore(level_nr);
4202
4203   fading = menu.destination;
4204
4205 #if XFADE
4206   if (fading.anim_mode == ANIM_CROSSFADE)
4207     FadeCrossSaveBackbuffer();
4208   else
4209     FadeOut(REDRAW_FIELD);
4210 #else
4211   FadeOut(REDRAW_FIELD);
4212 #endif
4213
4214   InitAnimation();
4215
4216   PlayMenuSound();
4217   PlayMenuMusic();
4218
4219   HandleHallOfFame(highlight_position, 0, 0, 0, MB_MENU_INITIALIZE);
4220
4221 #if XFADE
4222   if (fading.anim_mode == ANIM_CROSSFADE)
4223     FadeCross(REDRAW_FIELD);
4224   else
4225     FadeIn(REDRAW_FIELD);
4226 #else
4227   FadeIn(REDRAW_FIELD);
4228 #endif
4229 }
4230
4231 static void drawHallOfFameList(int first_entry, int highlight_position)
4232 {
4233   int i;
4234
4235   SetMainBackgroundImage(IMG_BACKGROUND_SCORES);
4236   ClearWindow();
4237
4238   DrawTextSCentered(MENU_TITLE1_YPOS, FONT_TITLE_1, "Hall Of Fame");
4239   DrawTextFCentered(MENU_TITLE2_YPOS, FONT_TITLE_2,
4240                     "HighScores of Level %d", level_nr);
4241
4242   for (i = 0; i < NUM_MENU_ENTRIES_ON_SCREEN; i++)
4243   {
4244     int entry = first_entry + i;
4245     boolean active = (entry == highlight_position);
4246     int font_nr1 = (active ? FONT_TEXT_1_ACTIVE : FONT_TEXT_1);
4247     int font_nr2 = (active ? FONT_TEXT_2_ACTIVE : FONT_TEXT_2);
4248     int font_nr3 = (active ? FONT_TEXT_3_ACTIVE : FONT_TEXT_3);
4249     int font_nr4 = (active ? FONT_TEXT_4_ACTIVE : FONT_TEXT_4);
4250     int dx1 = 3 * getFontWidth(font_nr1);
4251     int dx2 = dx1 + getFontWidth(font_nr1);
4252     int dx3 = dx2 + 25 * getFontWidth(font_nr3);
4253     int sy = mSY + 64 + i * 32;
4254
4255     DrawText(mSX, sy, int2str(entry + 1, 3), font_nr1);
4256     DrawText(mSX + dx1, sy, ".", font_nr1);
4257     DrawText(mSX + dx2, sy, ".........................", font_nr3);
4258
4259     if (!strEqual(highscore[entry].Name, EMPTY_PLAYER_NAME))
4260       DrawText(mSX + dx2, sy, highscore[entry].Name, font_nr2);
4261
4262     DrawText(mSX + dx3, sy, int2str(highscore[entry].Score, 5), font_nr4);
4263   }
4264
4265   redraw_mask |= REDRAW_FIELD;
4266 }
4267
4268 void HandleHallOfFame(int mx, int my, int dx, int dy, int button)
4269 {
4270   static int first_entry = 0;
4271   static int highlight_position = 0;
4272   int step = (button == 1 ? 1 : button == 2 ? 5 : 10);
4273
4274   if (button == MB_MENU_INITIALIZE)
4275   {
4276     first_entry = 0;
4277     highlight_position = mx;
4278     drawHallOfFameList(first_entry, highlight_position);
4279
4280     return;
4281   }
4282
4283   if (ABS(dy) == SCROLL_PAGE)           /* handle scrolling one page */
4284     step = NUM_MENU_ENTRIES_ON_SCREEN - 1;
4285
4286   if (dy < 0)
4287   {
4288     if (first_entry > 0)
4289     {
4290       first_entry -= step;
4291       if (first_entry < 0)
4292         first_entry = 0;
4293
4294       drawHallOfFameList(first_entry, highlight_position);
4295     }
4296   }
4297   else if (dy > 0)
4298   {
4299     if (first_entry + NUM_MENU_ENTRIES_ON_SCREEN < MAX_SCORE_ENTRIES)
4300     {
4301       first_entry += step;
4302       if (first_entry + NUM_MENU_ENTRIES_ON_SCREEN > MAX_SCORE_ENTRIES)
4303         first_entry = MAX(0, MAX_SCORE_ENTRIES - NUM_MENU_ENTRIES_ON_SCREEN);
4304
4305       drawHallOfFameList(first_entry, highlight_position);
4306     }
4307   }
4308   else if (button == MB_MENU_LEAVE)
4309   {
4310     PlaySound(SND_MENU_ITEM_SELECTING);
4311
4312     FadeSound(SND_BACKGROUND_SCORES);
4313
4314     game_status = GAME_MODE_MAIN;
4315
4316     DrawMainMenu();
4317   }
4318   else if (button == MB_MENU_CHOICE)
4319   {
4320     PlaySound(SND_MENU_ITEM_SELECTING);
4321
4322     FadeSound(SND_BACKGROUND_SCORES);
4323
4324 #if 0
4325 #if XFADE
4326     if (fading.anim_mode == ANIM_CROSSFADE)
4327       FadeCrossSaveBackbuffer();
4328     else
4329       FadeOut(REDRAW_FIELD);
4330 #else
4331     FadeOut(REDRAW_FIELD);
4332 #endif
4333 #endif
4334
4335     game_status = GAME_MODE_MAIN;
4336
4337     DrawAndFadeInMainMenu(REDRAW_FIELD);
4338   }
4339
4340   if (game_status == GAME_MODE_SCORES)
4341     PlayMenuSoundIfLoop();
4342
4343   DoAnimation();
4344 }
4345
4346
4347 /* ========================================================================= */
4348 /* setup screen functions                                                    */
4349 /* ========================================================================= */
4350
4351 static struct TokenInfo *setup_info;
4352 static int num_setup_info;
4353
4354 static char *screen_mode_text;
4355 static char *game_speed_text;
4356 static char *graphics_set_name;
4357 static char *sounds_set_name;
4358 static char *music_set_name;
4359
4360 static void execSetupMain()
4361 {
4362   setup_mode = SETUP_MODE_MAIN;
4363   DrawSetupScreen();
4364 }
4365
4366 static void execSetupGame()
4367 {
4368   if (game_speeds == NULL)
4369   {
4370     int i;
4371
4372     for (i = 0; game_speeds_list[i].value != -1; i++)
4373     {
4374       TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
4375       char identifier[32], name[32];
4376       int value = game_speeds_list[i].value;
4377       char *text = game_speeds_list[i].text;
4378
4379       ti->node_top = &game_speeds;
4380       ti->sort_priority = 10000 - value;
4381
4382       sprintf(identifier, "%d", value);
4383       sprintf(name, "%s", text);
4384
4385       setString(&ti->identifier, identifier);
4386       setString(&ti->name, name);
4387       setString(&ti->name_sorting, name);
4388       setString(&ti->infotext, "Game Speed");
4389
4390       pushTreeInfo(&game_speeds, ti);
4391     }
4392
4393     /* sort game speed values to start with slowest game speed */
4394     sortTreeInfo(&game_speeds);
4395
4396     /* set current game speed to configured game speed value */
4397     game_speed_current =
4398       getTreeInfoFromIdentifier(game_speeds, i_to_a(setup.game_frame_delay));
4399
4400     /* if that fails, set current game speed to reliable default value */
4401     if (game_speed_current == NULL)
4402       game_speed_current =
4403         getTreeInfoFromIdentifier(game_speeds, i_to_a(GAME_FRAME_DELAY));
4404
4405     /* if that also fails, set current game speed to first available speed */
4406     if (game_speed_current == NULL)
4407       game_speed_current = game_speeds;
4408   }
4409
4410   setup.game_frame_delay = atoi(game_speed_current->identifier);
4411
4412   /* needed for displaying game speed text instead of identifier */
4413   game_speed_text = game_speed_current->name;
4414
4415   setup_mode = SETUP_MODE_GAME;
4416   DrawSetupScreen();
4417 }
4418
4419 static void execSetupChooseGameSpeed()
4420 {
4421   setup_mode = SETUP_MODE_CHOOSE_GAME_SPEED;
4422   DrawSetupScreen();
4423 }
4424
4425 static void execSetupEditor()
4426 {
4427   setup_mode = SETUP_MODE_EDITOR;
4428   DrawSetupScreen();
4429 }
4430
4431 static void execSetupGraphics()
4432 {
4433   if (video.fullscreen_available && screen_modes == NULL)
4434   {
4435     int i;
4436
4437     for (i = 0; video.fullscreen_modes[i].width != -1; i++)
4438     {
4439       TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
4440       char identifier[32], name[32];
4441       int x = video.fullscreen_modes[i].width;
4442       int y = video.fullscreen_modes[i].height;
4443       int xx, yy;
4444
4445       get_aspect_ratio_from_screen_mode(&video.fullscreen_modes[i], &xx, &yy);
4446
4447       ti->node_top = &screen_modes;
4448       ti->sort_priority = x * 10000 + y;
4449
4450       sprintf(identifier, "%dx%d", x, y);
4451       sprintf(name, "%d x %d [%d:%d]", x, y, xx, yy);
4452
4453       setString(&ti->identifier, identifier);
4454       setString(&ti->name, name);
4455       setString(&ti->name_sorting, name);
4456       setString(&ti->infotext, "Fullscreen Mode");
4457
4458       pushTreeInfo(&screen_modes, ti);
4459     }
4460
4461     /* sort fullscreen modes to start with lowest available screen resolution */
4462     sortTreeInfo(&screen_modes);
4463
4464     /* set current screen mode for fullscreen mode to configured setup value */
4465     screen_mode_current = getTreeInfoFromIdentifier(screen_modes,
4466                                                     setup.fullscreen_mode);
4467
4468     /* if that fails, set current screen mode to reliable default value */
4469     if (screen_mode_current == NULL)
4470       screen_mode_current = getTreeInfoFromIdentifier(screen_modes,
4471                                                       DEFAULT_FULLSCREEN_MODE);
4472
4473     /* if that also fails, set current screen mode to first available mode */
4474     if (screen_mode_current == NULL)
4475       screen_mode_current = screen_modes;
4476
4477     if (screen_mode_current == NULL)
4478       video.fullscreen_available = FALSE;
4479   }
4480
4481   if (video.fullscreen_available)
4482   {
4483     setup.fullscreen_mode = screen_mode_current->identifier;
4484
4485     /* needed for displaying screen mode name instead of identifier */
4486     screen_mode_text = screen_mode_current->name;
4487   }
4488
4489   setup_mode = SETUP_MODE_GRAPHICS;
4490   DrawSetupScreen();
4491 }
4492
4493 static void execSetupChooseScreenMode()
4494 {
4495   if (!video.fullscreen_available)
4496     return;
4497
4498   setup_mode = SETUP_MODE_CHOOSE_SCREEN_MODE;
4499   DrawSetupScreen();
4500 }
4501
4502 static void execSetupSound()
4503 {
4504   setup_mode = SETUP_MODE_SOUND;
4505   DrawSetupScreen();
4506 }
4507
4508 static void execSetupArtwork()
4509 {
4510   setup.graphics_set = artwork.gfx_current->identifier;
4511   setup.sounds_set = artwork.snd_current->identifier;
4512   setup.music_set = artwork.mus_current->identifier;
4513
4514   /* needed if last screen (setup choice) changed graphics, sounds or music */
4515   ReloadCustomArtwork(0);
4516
4517   /* needed for displaying artwork name instead of artwork identifier */
4518   graphics_set_name = artwork.gfx_current->name;
4519   sounds_set_name = artwork.snd_current->name;
4520   music_set_name = artwork.mus_current->name;
4521
4522   setup_mode = SETUP_MODE_ARTWORK;
4523   DrawSetupScreen();
4524 }
4525
4526 static void execSetupChooseGraphics()
4527 {
4528   setup_mode = SETUP_MODE_CHOOSE_GRAPHICS;
4529   DrawSetupScreen();
4530 }
4531
4532 static void execSetupChooseSounds()
4533 {
4534   setup_mode = SETUP_MODE_CHOOSE_SOUNDS;
4535   DrawSetupScreen();
4536 }
4537
4538 static void execSetupChooseMusic()
4539 {
4540   setup_mode = SETUP_MODE_CHOOSE_MUSIC;
4541   DrawSetupScreen();
4542 }
4543
4544 static void execSetupInput()
4545 {
4546   setup_mode = SETUP_MODE_INPUT;
4547   DrawSetupScreen();
4548 }
4549
4550 static void execSetupShortcut1()
4551 {
4552   setup_mode = SETUP_MODE_SHORTCUT_1;
4553   DrawSetupScreen();
4554 }
4555
4556 static void execSetupShortcut2()
4557 {
4558   setup_mode = SETUP_MODE_SHORTCUT_2;
4559   DrawSetupScreen();
4560 }
4561
4562 static void execExitSetup()
4563 {
4564   game_status = GAME_MODE_MAIN;
4565 #if 1
4566   DrawMainMenuExt(REDRAW_FIELD, FALSE);
4567 #else
4568   DrawMainMenu();
4569 #endif
4570 }
4571
4572 static void execSaveAndExitSetup()
4573 {
4574   SaveSetup();
4575   execExitSetup();
4576 }
4577
4578 static struct TokenInfo setup_info_main[] =
4579 {
4580   { TYPE_ENTER_MENU,    execSetupGame,          "Game & Menu"           },
4581   { TYPE_ENTER_MENU,    execSetupEditor,        "Editor"                },
4582   { TYPE_ENTER_MENU,    execSetupGraphics,      "Graphics"              },
4583   { TYPE_ENTER_MENU,    execSetupSound,         "Sound & Music"         },
4584   { TYPE_ENTER_MENU,    execSetupArtwork,       "Custom Artwork"        },
4585   { TYPE_ENTER_MENU,    execSetupInput,         "Input Devices"         },
4586   { TYPE_ENTER_MENU,    execSetupShortcut1,     "Key Shortcuts 1"       },
4587   { TYPE_ENTER_MENU,    execSetupShortcut2,     "Key Shortcuts 2"       },
4588   { TYPE_EMPTY,         NULL,                   ""                      },
4589   { TYPE_LEAVE_MENU,    execExitSetup,          "Exit"                  },
4590   { TYPE_LEAVE_MENU,    execSaveAndExitSetup,   "Save and Exit"         },
4591
4592   { 0,                  NULL,                   NULL                    }
4593 };
4594
4595 static struct TokenInfo setup_info_game[] =
4596 {
4597   { TYPE_SWITCH,        &setup.team_mode,       "Team-Mode (Multi-Player):" },
4598   { TYPE_YES_NO,        &setup.input_on_focus,  "Only Move Focussed Player:" },
4599   { TYPE_SWITCH,        &setup.handicap,        "Handicap:"             },
4600   { TYPE_SWITCH,        &setup.skip_levels,     "Skip Unsolved Levels:" },
4601   { TYPE_SWITCH,        &setup.time_limit,      "Time Limit:"           },
4602   { TYPE_SWITCH,        &setup.autorecord,      "Auto-Record Tapes:"    },
4603   { TYPE_ENTER_LIST,    execSetupChooseGameSpeed, "Game Speed:"         },
4604   { TYPE_STRING,        &game_speed_text,       ""                      },
4605   { TYPE_EMPTY,         NULL,                   ""                      },
4606   { TYPE_LEAVE_MENU,    execSetupMain,          "Back"                  },
4607
4608   { 0,                  NULL,                   NULL                    }
4609 };
4610
4611 static struct TokenInfo setup_info_editor[] =
4612 {
4613 #if 0
4614   { TYPE_SWITCH,        &setup.editor.el_boulderdash,   "Boulder Dash:" },
4615   { TYPE_SWITCH,        &setup.editor.el_emerald_mine,  "Emerald Mine:" },
4616   { TYPE_SWITCH, &setup.editor.el_emerald_mine_club,    "Emerald Mine Club:" },
4617   { TYPE_SWITCH,        &setup.editor.el_more,          "Rocks'n'Diamonds:" },
4618   { TYPE_SWITCH,        &setup.editor.el_sokoban,       "Sokoban:"      },
4619   { TYPE_SWITCH,        &setup.editor.el_supaplex,      "Supaplex:"     },
4620   { TYPE_SWITCH,        &setup.editor.el_diamond_caves, "Diamond Caves II:" },
4621   { TYPE_SWITCH,        &setup.editor.el_dx_boulderdash,"DX-Boulderdash:" },
4622 #endif
4623   { TYPE_SWITCH,        &setup.editor.el_chars,         "Text Characters:" },
4624   { TYPE_SWITCH, &setup.editor.el_steel_chars, "Text Characters (Steel):" },
4625   { TYPE_SWITCH,        &setup.editor.el_custom,  "Custom & Group Elements:" },
4626 #if 0
4627   { TYPE_SWITCH,        &setup.editor.el_headlines,     "Headlines:"    },
4628 #endif
4629   { TYPE_SWITCH, &setup.editor.el_user_defined, "User defined element list:" },
4630   { TYPE_SWITCH,        &setup.editor.el_dynamic,  "Dynamic level elements:" },
4631   { TYPE_EMPTY,         NULL,                   ""                      },
4632 #if 0
4633   { TYPE_SWITCH,        &setup.editor.el_by_game,   "Show elements by game:" },
4634   { TYPE_SWITCH,        &setup.editor.el_by_type,   "Show elements by type:" },
4635   { TYPE_EMPTY,         NULL,                   ""                      },
4636 #endif
4637   { TYPE_SWITCH, &setup.editor.show_element_token,      "Show element token:" },
4638   { TYPE_EMPTY,         NULL,                   ""                      },
4639   { TYPE_LEAVE_MENU,    execSetupMain,          "Back"                  },
4640
4641   { 0,                  NULL,                   NULL                    }
4642 };
4643
4644 static struct TokenInfo setup_info_graphics[] =
4645 {
4646   { TYPE_SWITCH,        &setup.fullscreen,      "Fullscreen:"           },
4647   { TYPE_ENTER_LIST,    execSetupChooseScreenMode, "Fullscreen Mode:"   },
4648   { TYPE_STRING,        &screen_mode_text,      ""                      },
4649   { TYPE_SWITCH,        &setup.scroll_delay,    "Delayed Scrolling:"    },
4650 #if 0
4651   { TYPE_SWITCH,        &setup.soft_scrolling,  "Soft Scrolling:"       },
4652   { TYPE_SWITCH,        &setup.double_buffering,"Double-Buffering:"     },
4653 #endif
4654   { TYPE_SWITCH,        &setup.fade_screens,    "Fade Screens:"         },
4655   { TYPE_SWITCH,        &setup.quick_switch,    "Quick Player Focus Switch:" },
4656   { TYPE_SWITCH,        &setup.quick_doors,     "Quick Menu Doors:"     },
4657   { TYPE_SWITCH,        &setup.show_titlescreen,"Show Title Screens:"   },
4658   { TYPE_SWITCH,        &setup.toons,           "Show Toons:"           },
4659   { TYPE_ECS_AGA,       &setup.prefer_aga_graphics,"EMC graphics preference:" },
4660   { TYPE_EMPTY,         NULL,                   ""                      },
4661   { TYPE_LEAVE_MENU,    execSetupMain,          "Back"                  },
4662
4663   { 0,                  NULL,                   NULL                    }
4664 };
4665
4666 static struct TokenInfo setup_info_sound[] =
4667 {
4668   { TYPE_SWITCH,        &setup.sound_simple,    "Sound Effects (Normal):"  },
4669   { TYPE_SWITCH,        &setup.sound_loops,     "Sound Effects (Looping):" },
4670   { TYPE_SWITCH,        &setup.sound_music,     "Music:"                },
4671   { TYPE_EMPTY,         NULL,                   ""                      },
4672   { TYPE_LEAVE_MENU,    execSetupMain,          "Back"                  },
4673
4674   { 0,                  NULL,                   NULL                    }
4675 };
4676
4677 static struct TokenInfo setup_info_artwork[] =
4678 {
4679   { TYPE_ENTER_LIST,    execSetupChooseGraphics,"Custom Graphics:"      },
4680   { TYPE_STRING,        &graphics_set_name,     ""                      },
4681   { TYPE_ENTER_LIST,    execSetupChooseSounds,  "Custom Sounds:"        },
4682   { TYPE_STRING,        &sounds_set_name,       ""                      },
4683   { TYPE_ENTER_LIST,    execSetupChooseMusic,   "Custom Music:"         },
4684   { TYPE_STRING,        &music_set_name,        ""                      },
4685   { TYPE_EMPTY,         NULL,                   ""                      },
4686 #if 1
4687   { TYPE_YES_NO, &setup.override_level_graphics,"Override Level Graphics:" },
4688   { TYPE_YES_NO, &setup.override_level_sounds,  "Override Level Sounds:"   },
4689   { TYPE_YES_NO, &setup.override_level_music,   "Override Level Music:"    },
4690 #else
4691   { TYPE_STRING,        NULL,                   "Override Level Artwork:"},
4692   { TYPE_YES_NO,        &setup.override_level_graphics, "Graphics:"     },
4693   { TYPE_YES_NO,        &setup.override_level_sounds,   "Sounds:"       },
4694   { TYPE_YES_NO,        &setup.override_level_music,    "Music:"        },
4695 #endif
4696   { TYPE_EMPTY,         NULL,                   ""                      },
4697   { TYPE_LEAVE_MENU,    execSetupMain,          "Back"                  },
4698
4699   { 0,                  NULL,                   NULL                    }
4700 };
4701
4702 static struct TokenInfo setup_info_input[] =
4703 {
4704   { TYPE_SWITCH,        NULL,                   "Player:"               },
4705   { TYPE_SWITCH,        NULL,                   "Device:"               },
4706   { TYPE_ENTER_MENU,    NULL,                   ""                      },
4707   { TYPE_EMPTY,         NULL,                   ""                      },
4708   { TYPE_EMPTY,         NULL,                   ""                      },
4709   { TYPE_EMPTY,         NULL,                   ""                      },
4710   { TYPE_EMPTY,         NULL,                   ""                      },
4711   { TYPE_EMPTY,         NULL,                   ""                      },
4712   { TYPE_EMPTY,         NULL,                   ""                      },
4713   { TYPE_EMPTY,         NULL,                   ""                      },
4714   { TYPE_EMPTY,         NULL,                   ""                      },
4715   { TYPE_EMPTY,         NULL,                   ""                      },
4716   { TYPE_EMPTY,         NULL,                   ""                      },
4717   { TYPE_LEAVE_MENU,    execSetupMain,          "Back"                  },
4718
4719   { 0,                  NULL,                   NULL                    }
4720 };
4721
4722 static struct TokenInfo setup_info_shortcut_1[] =
4723 {
4724   { TYPE_KEYTEXT,       NULL,           "Quick Save Game to Tape:",     },
4725   { TYPE_KEY,           &setup.shortcut.save_game, ""                   },
4726   { TYPE_KEYTEXT,       NULL,           "Quick Load Game from Tape:",   },
4727   { TYPE_KEY,           &setup.shortcut.load_game, ""                   },
4728   { TYPE_KEYTEXT,       NULL,           "Start Game & Toggle Pause:",   },
4729   { TYPE_KEY,           &setup.shortcut.toggle_pause, ""                },
4730   { TYPE_EMPTY,         NULL,                   ""                      },
4731   { TYPE_YES_NO,        &setup.ask_on_escape,   "Ask on 'Esc' Key:"     },
4732   { TYPE_YES_NO, &setup.ask_on_escape_editor,   "Ask on 'Esc' Key (Editor):" },
4733   { TYPE_EMPTY,         NULL,                   ""                      },
4734   { TYPE_LEAVE_MENU,    execSetupMain,          "Back"                  },
4735
4736   { 0,                  NULL,                   NULL                    }
4737 };
4738
4739 static struct TokenInfo setup_info_shortcut_2[] =
4740 {
4741   { TYPE_KEYTEXT,       NULL,           "Set Focus to Player 1:",       },
4742   { TYPE_KEY,           &setup.shortcut.focus_player[0], ""             },
4743   { TYPE_KEYTEXT,       NULL,           "Set Focus to Player 2:",       },
4744   { TYPE_KEY,           &setup.shortcut.focus_player[1], ""             },
4745   { TYPE_KEYTEXT,       NULL,           "Set Focus to Player 3:",       },
4746   { TYPE_KEY,           &setup.shortcut.focus_player[2], ""             },
4747   { TYPE_KEYTEXT,       NULL,           "Set Focus to Player 4:",       },
4748   { TYPE_KEY,           &setup.shortcut.focus_player[3], ""             },
4749   { TYPE_KEYTEXT,       NULL,           "Set Focus to All Players:",    },
4750   { TYPE_KEY,           &setup.shortcut.focus_player_all, ""            },
4751   { TYPE_EMPTY,         NULL,                   ""                      },
4752   { TYPE_LEAVE_MENU,    execSetupMain,          "Back"                  },
4753
4754   { 0,                  NULL,                   NULL                    }
4755 };
4756
4757 static Key getSetupKey()
4758 {
4759   Key key = KSYM_UNDEFINED;
4760   boolean got_key_event = FALSE;
4761
4762   while (!got_key_event)
4763   {
4764     if (PendingEvent())         /* got event */
4765     {
4766       Event event;
4767
4768       NextEvent(&event);
4769
4770       switch (event.type)
4771       {
4772         case EVENT_KEYPRESS:
4773           {
4774             key = GetEventKey((KeyEvent *)&event, TRUE);
4775
4776             /* press 'Escape' or 'Enter' to keep the existing key binding */
4777             if (key == KSYM_Escape || key == KSYM_Return)
4778               key = KSYM_UNDEFINED;     /* keep old value */
4779
4780             got_key_event = TRUE;
4781           }
4782           break;
4783
4784         case EVENT_KEYRELEASE:
4785           key_joystick_mapping = 0;
4786           break;
4787
4788         default:
4789           HandleOtherEvents(&event);
4790           break;
4791       }
4792     }
4793
4794     DoAnimation();
4795     BackToFront();
4796
4797     /* don't eat all CPU time */
4798     Delay(10);
4799   }
4800
4801   return key;
4802 }
4803
4804 static int getSetupTextFont(int type)
4805 {
4806   if (type & (TYPE_SWITCH |
4807               TYPE_YES_NO |
4808               TYPE_STRING |
4809               TYPE_ECS_AGA |
4810               TYPE_KEYTEXT |
4811               TYPE_ENTER_LIST))
4812     return FONT_MENU_2;
4813   else
4814     return FONT_MENU_1;
4815 }
4816
4817 static int getSetupValueFont(int type, void *value)
4818 {
4819   if (type & TYPE_KEY)
4820     return (type & TYPE_QUERY ? FONT_INPUT_1_ACTIVE : FONT_VALUE_1);
4821   else if (type & TYPE_STRING)
4822     return FONT_VALUE_2;
4823   else if (type & TYPE_ECS_AGA)
4824     return FONT_VALUE_1;
4825   else if (type & TYPE_BOOLEAN_STYLE)
4826     return (*(boolean *)value ? FONT_OPTION_ON : FONT_OPTION_OFF);
4827   else
4828     return FONT_VALUE_1;
4829 }
4830
4831 static void drawSetupValue(int pos)
4832 {
4833   boolean font_draw_xoffset_modified = FALSE;
4834   int font_draw_xoffset_old = -1;
4835   int xpos = MENU_SCREEN_VALUE_XPOS;
4836   int ypos = MENU_SCREEN_START_YPOS + pos;
4837   int startx = mSX + xpos * 32;
4838   int starty = mSY + ypos * 32;
4839   int font_nr, font_width;
4840   int type = setup_info[pos].type;
4841   void *value = setup_info[pos].value;
4842   char *value_string = getSetupValue(type, value);
4843   int i;
4844
4845   if (value_string == NULL)
4846     return;
4847
4848   if (type & TYPE_KEY)
4849   {
4850     xpos = MENU_SCREEN_START_XPOS;
4851
4852     if (type & TYPE_QUERY)
4853     {
4854       value_string = "<press key>";
4855     }
4856   }
4857   else if (type & TYPE_STRING)
4858   {
4859     int max_value_len = (SCR_FIELDX - 2) * 2;
4860
4861     xpos = MENU_SCREEN_START_XPOS;
4862
4863     if (strlen(value_string) > max_value_len)
4864       value_string[max_value_len] = '\0';
4865   }
4866
4867   startx = mSX + xpos * 32;
4868   starty = mSY + ypos * 32;
4869   font_nr = getSetupValueFont(type, value);
4870   font_width = getFontWidth(font_nr);
4871
4872   /* downward compatibility correction for Juergen Bonhagen's menu settings */
4873   if (setup_mode != SETUP_MODE_INPUT)
4874   {
4875     int check_font_nr = FONT_OPTION_ON; /* known font that needs correction */
4876     int font1_xoffset = getFontBitmapInfo(font_nr)->draw_xoffset;
4877     int font2_xoffset = getFontBitmapInfo(check_font_nr)->draw_xoffset;
4878     int text_startx = mSX + MENU_SCREEN_START_XPOS * 32;
4879     int text_font_nr = getSetupTextFont(FONT_MENU_2);
4880     int text_font_xoffset = getFontBitmapInfo(text_font_nr)->draw_xoffset;
4881     int text_width = MAX_MENU_TEXT_LENGTH_MEDIUM * getFontWidth(text_font_nr);
4882     boolean correct_font_draw_xoffset = FALSE;
4883
4884     if (xpos == MENU_SCREEN_START_XPOS &&
4885         startx + font1_xoffset < text_startx + text_font_xoffset)
4886       correct_font_draw_xoffset = TRUE;
4887
4888     if (xpos == MENU_SCREEN_VALUE_XPOS &&
4889         startx + font2_xoffset < text_startx + text_width + text_font_xoffset)
4890       correct_font_draw_xoffset = TRUE;
4891
4892     /* check if setup value would overlap with setup text when printed */
4893     /* (this can happen for extreme/wrong values for font draw offset) */
4894     if (correct_font_draw_xoffset)
4895     {
4896       font_draw_xoffset_old = getFontBitmapInfo(font_nr)->draw_xoffset;
4897       font_draw_xoffset_modified = TRUE;
4898
4899       if (type & TYPE_KEY)
4900         getFontBitmapInfo(font_nr)->draw_xoffset += 2 * getFontWidth(font_nr);
4901       else if (!(type & TYPE_STRING))
4902         getFontBitmapInfo(font_nr)->draw_xoffset = text_font_xoffset + 20 -
4903           MAX_MENU_TEXT_LENGTH_MEDIUM * (16 - getFontWidth(text_font_nr));
4904     }
4905   }
4906
4907   for (i = 0; i <= MENU_SCREEN_MAX_XPOS - xpos; i++)
4908     DrawText(startx + i * font_width, starty, " ", font_nr);
4909
4910   DrawText(startx, starty, value_string, font_nr);
4911
4912   if (font_draw_xoffset_modified)
4913     getFontBitmapInfo(font_nr)->draw_xoffset = font_draw_xoffset_old;
4914 }
4915
4916 static void changeSetupValue(int pos)
4917 {
4918   if (setup_info[pos].type & TYPE_BOOLEAN_STYLE)
4919   {
4920     *(boolean *)setup_info[pos].value ^= TRUE;
4921   }
4922   else if (setup_info[pos].type & TYPE_KEY)
4923   {
4924     Key key;
4925
4926     setup_info[pos].type |= TYPE_QUERY;
4927     drawSetupValue(pos);
4928     setup_info[pos].type &= ~TYPE_QUERY;
4929
4930     key = getSetupKey();
4931     if (key != KSYM_UNDEFINED)
4932       *(Key *)setup_info[pos].value = key;
4933   }
4934
4935   drawSetupValue(pos);
4936 }
4937
4938 static void DrawCursorAndText_Setup(int pos, boolean active)
4939 {
4940   int xpos = MENU_SCREEN_START_XPOS;
4941   int ypos = MENU_SCREEN_START_YPOS + pos;
4942   int font_nr = getSetupTextFont(setup_info[pos].type);
4943
4944   if (setup_info == setup_info_input)
4945     font_nr = FONT_MENU_1;
4946
4947   if (active)
4948     font_nr = FONT_ACTIVE(font_nr);
4949
4950   DrawText(mSX + xpos * 32, mSY + ypos * 32, setup_info[pos].text, font_nr);
4951
4952   if (setup_info[pos].type & ~TYPE_SKIP_ENTRY)
4953     drawCursor(pos, active);
4954 }
4955
4956 static void DrawSetupScreen_Generic()
4957 {
4958   char *title_string = NULL;
4959   int i;
4960
4961   UnmapAllGadgets();
4962   CloseDoor(DOOR_CLOSE_2);
4963
4964 #if XFADE
4965   if (fading.anim_mode == ANIM_CROSSFADE)
4966     FadeCrossSaveBackbuffer();
4967   else
4968     FadeOut(REDRAW_FIELD);
4969 #endif
4970
4971   ClearWindow();
4972
4973   if (setup_mode == SETUP_MODE_MAIN)
4974   {
4975     setup_info = setup_info_main;
4976     title_string = "Setup";
4977   }
4978   else if (setup_mode == SETUP_MODE_GAME)
4979   {
4980     setup_info = setup_info_game;
4981     title_string = "Setup Game";
4982   }
4983   else if (setup_mode == SETUP_MODE_EDITOR)
4984   {
4985     setup_info = setup_info_editor;
4986     title_string = "Setup Editor";
4987   }
4988   else if (setup_mode == SETUP_MODE_GRAPHICS)
4989   {
4990     setup_info = setup_info_graphics;
4991     title_string = "Setup Graphics";
4992   }
4993   else if (setup_mode == SETUP_MODE_SOUND)
4994   {
4995     setup_info = setup_info_sound;
4996     title_string = "Setup Sound";
4997   }
4998   else if (setup_mode == SETUP_MODE_ARTWORK)
4999   {
5000     setup_info = setup_info_artwork;
5001     title_string = "Custom Artwork";
5002   }
5003   else if (setup_mode == SETUP_MODE_SHORTCUT_1)
5004   {
5005     setup_info = setup_info_shortcut_1;
5006     title_string = "Setup Shortcuts";
5007   }
5008   else if (setup_mode == SETUP_MODE_SHORTCUT_2)
5009   {
5010     setup_info = setup_info_shortcut_2;
5011     title_string = "Setup Shortcuts";
5012   }
5013
5014   DrawTextSCentered(mSY - SY + 16, FONT_TITLE_1, title_string);
5015
5016   num_setup_info = 0;
5017   for (i = 0; setup_info[i].type != 0 && i < NUM_MENU_ENTRIES_ON_SCREEN; i++)
5018   {
5019     void *value_ptr = setup_info[i].value;
5020 #if 1
5021 #else
5022     int xpos = MENU_SCREEN_START_XPOS;
5023     int ypos = MENU_SCREEN_START_YPOS + i;
5024     int font_nr;
5025 #endif
5026
5027     /* set some entries to "unchangeable" according to other variables */
5028     if ((value_ptr == &setup.sound_simple && !audio.sound_available) ||
5029         (value_ptr == &setup.sound_loops  && !audio.loops_available) ||
5030         (value_ptr == &setup.sound_music  && !audio.music_available) ||
5031         (value_ptr == &setup.fullscreen   && !video.fullscreen_available) ||
5032         (value_ptr == &screen_mode_text   && !video.fullscreen_available))
5033       setup_info[i].type |= TYPE_GHOSTED;
5034
5035     if (setup_info[i].type & (TYPE_ENTER_MENU|TYPE_ENTER_LIST))
5036       initCursor(i, IMG_MENU_BUTTON_ENTER_MENU);
5037     else if (setup_info[i].type & (TYPE_LEAVE_MENU|TYPE_LEAVE_LIST))
5038       initCursor(i, IMG_MENU_BUTTON_LEAVE_MENU);
5039     else if (setup_info[i].type & ~TYPE_SKIP_ENTRY)
5040       initCursor(i, IMG_MENU_BUTTON);
5041
5042 #if 1
5043     DrawCursorAndText_Setup(i, FALSE);
5044 #else
5045     font_nr = getSetupTextFont(setup_info[i].type);
5046
5047     DrawText(mSX + xpos * 32, mSY + ypos * 32, setup_info[i].text, font_nr);
5048 #endif
5049
5050     if (setup_info[i].type & TYPE_VALUE)
5051       drawSetupValue(i);
5052
5053     num_setup_info++;
5054   }
5055
5056 #if 0
5057   DrawTextSCentered(SYSIZE - 20, FONT_TEXT_4,
5058                     "Joysticks deactivated in setup menu");
5059 #endif
5060
5061 #if 1
5062   HandleSetupScreen_Generic(0, 0, 0, 0, MB_MENU_INITIALIZE);
5063 #endif
5064
5065 #if XFADE
5066   if (fading.anim_mode == ANIM_CROSSFADE)
5067     FadeCross(redraw_mask);
5068   else
5069     FadeIn(redraw_mask);
5070 #else
5071   FadeToFront();
5072 #endif
5073
5074   InitAnimation();
5075 #if 0
5076   HandleSetupScreen_Generic(0, 0, 0, 0, MB_MENU_INITIALIZE);
5077 #endif
5078 }
5079
5080 void HandleSetupScreen_Generic(int mx, int my, int dx, int dy, int button)
5081 {
5082   static int choice_store[MAX_SETUP_MODES];
5083   int choice = choice_store[setup_mode];        /* always starts with 0 */
5084   int x = 0;
5085   int y = choice;
5086
5087   if (button == MB_MENU_INITIALIZE)
5088   {
5089     /* advance to first valid menu entry */
5090     while (choice < num_setup_info &&
5091            setup_info[choice].type & TYPE_SKIP_ENTRY)
5092       choice++;
5093     choice_store[setup_mode] = choice;
5094
5095 #if 1
5096     DrawCursorAndText_Setup(choice, TRUE);
5097 #else
5098     drawCursor(choice, TRUE);
5099 #endif
5100
5101     return;
5102   }
5103   else if (button == MB_MENU_LEAVE)
5104   {
5105     PlaySound(SND_MENU_ITEM_SELECTING);
5106
5107     for (y = 0; y < num_setup_info; y++)
5108     {
5109       if (setup_info[y].type & TYPE_LEAVE_MENU)
5110       {
5111         void (*menu_callback_function)(void) = setup_info[y].value;
5112
5113         menu_callback_function();
5114
5115         break;  /* absolutely needed because function changes 'setup_info'! */
5116       }
5117     }
5118
5119     return;
5120   }
5121
5122   if (mx || my)         /* mouse input */
5123   {
5124     x = (mx - mSX) / 32;
5125     y = (my - mSY) / 32 - MENU_SCREEN_START_YPOS;
5126   }
5127   else if (dx || dy)    /* keyboard input */
5128   {
5129     if (dx)
5130     {
5131       int menu_navigation_type = (dx < 0 ? TYPE_LEAVE : TYPE_ENTER);
5132
5133       if (setup_info[choice].type & menu_navigation_type ||
5134           setup_info[choice].type & TYPE_BOOLEAN_STYLE)
5135         button = MB_MENU_CHOICE;
5136     }
5137     else if (dy)
5138       y = choice + dy;
5139
5140     /* jump to next non-empty menu entry (up or down) */
5141     while (y > 0 && y < num_setup_info - 1 &&
5142            setup_info[y].type & TYPE_SKIP_ENTRY)
5143       y += dy;
5144   }
5145
5146   if (IN_VIS_FIELD(x, y) && y >= 0 && y < num_setup_info)
5147   {
5148     if (button)
5149     {
5150       if (y != choice && setup_info[y].type & ~TYPE_SKIP_ENTRY)
5151       {
5152         PlaySound(SND_MENU_ITEM_ACTIVATING);
5153
5154 #if 1
5155         DrawCursorAndText_Setup(choice, FALSE);
5156         DrawCursorAndText_Setup(y, TRUE);
5157 #else
5158         drawCursor(choice, FALSE);
5159         drawCursor(y, TRUE);
5160 #endif
5161
5162         choice = choice_store[setup_mode] = y;
5163       }
5164     }
5165     else if (!(setup_info[y].type & TYPE_GHOSTED))
5166     {
5167       PlaySound(SND_MENU_ITEM_SELECTING);
5168
5169       /* when selecting key headline, execute function for key value change */
5170       if (setup_info[y].type & TYPE_KEYTEXT &&
5171           setup_info[y + 1].type & TYPE_KEY)
5172         y++;
5173
5174       /* when selecting string value, execute function for list selection */
5175       if (setup_info[y].type & TYPE_STRING && y > 0 &&
5176           setup_info[y - 1].type & TYPE_ENTER_LIST)
5177         y--;
5178
5179       if (setup_info[y].type & TYPE_ENTER_OR_LEAVE)
5180       {
5181         void (*menu_callback_function)(void) = setup_info[y].value;
5182
5183         menu_callback_function();
5184       }
5185       else
5186       {
5187         if (setup_info[y].type & TYPE_VALUE)
5188           changeSetupValue(y);
5189       }
5190     }
5191   }
5192 }
5193
5194 void DrawSetupScreen_Input()
5195 {
5196 #if 1
5197   int i;
5198 #endif
5199
5200 #if XFADE
5201   if (fading.anim_mode == ANIM_CROSSFADE)
5202     FadeCrossSaveBackbuffer();
5203   else
5204     FadeOut(REDRAW_FIELD);
5205 #endif
5206
5207   ClearWindow();
5208
5209 #if 1
5210   setup_info = setup_info_input;
5211 #endif
5212
5213   DrawTextSCentered(mSY - SY + 16, FONT_TITLE_1, "Setup Input");
5214
5215 #if 1
5216   for (i = 0; setup_info[i].type != 0 && i < NUM_MENU_ENTRIES_ON_SCREEN; i++)
5217   {
5218     if (setup_info[i].type & (TYPE_ENTER_MENU|TYPE_ENTER_LIST))
5219       initCursor(i, IMG_MENU_BUTTON_ENTER_MENU);
5220     else if (setup_info[i].type & (TYPE_LEAVE_MENU|TYPE_LEAVE_LIST))
5221       initCursor(i, IMG_MENU_BUTTON_LEAVE_MENU);
5222     else if (setup_info[i].type & ~TYPE_SKIP_ENTRY)
5223       initCursor(i, IMG_MENU_BUTTON);
5224
5225     DrawCursorAndText_Setup(i, FALSE);
5226   }
5227 #else
5228   initCursor(0,  IMG_MENU_BUTTON);
5229   initCursor(1,  IMG_MENU_BUTTON);
5230   initCursor(2,  IMG_MENU_BUTTON_ENTER_MENU);
5231   initCursor(13, IMG_MENU_BUTTON_LEAVE_MENU);
5232
5233   DrawText(mSX + 32, mSY +  2 * 32, "Player:", FONT_MENU_1);
5234   DrawText(mSX + 32, mSY +  3 * 32, "Device:", FONT_MENU_1);
5235   DrawText(mSX + 32, mSY + 15 * 32, "Back",   FONT_MENU_1);
5236 #endif
5237
5238 #if 0
5239   DeactivateJoystickForCalibration();
5240 #endif
5241 #if 1
5242   DrawTextSCentered(SYSIZE - 20, FONT_TEXT_4,
5243                     "Joysticks deactivated on this screen");
5244 #endif
5245
5246   /* create gadgets for setup input menu screen */
5247   FreeScreenGadgets();
5248   CreateScreenGadgets();
5249
5250   /* map gadgets for setup input menu screen */
5251   MapScreenMenuGadgets(SCREEN_MASK_INPUT);
5252
5253   HandleSetupScreen_Input(0, 0, 0, 0, MB_MENU_INITIALIZE);
5254
5255 #if XFADE
5256   if (fading.anim_mode == ANIM_CROSSFADE)
5257     FadeCross(redraw_mask);
5258   else
5259     FadeIn(redraw_mask);
5260 #else
5261   FadeToFront();
5262 #endif
5263
5264   InitAnimation();
5265 }
5266
5267 static void setJoystickDeviceToNr(char *device_name, int device_nr)
5268 {
5269   if (device_name == NULL)
5270     return;
5271
5272   if (device_nr < 0 || device_nr >= MAX_PLAYERS)
5273     device_nr = 0;
5274
5275   if (strlen(device_name) > 1)
5276   {
5277     char c1 = device_name[strlen(device_name) - 1];
5278     char c2 = device_name[strlen(device_name) - 2];
5279
5280     if (c1 >= '0' && c1 <= '9' && !(c2 >= '0' && c2 <= '9'))
5281       device_name[strlen(device_name) - 1] = '0' + (char)(device_nr % 10);
5282   }
5283   else
5284     strncpy(device_name, getDeviceNameFromJoystickNr(device_nr),
5285             strlen(device_name));
5286 }
5287
5288 static void drawPlayerSetupInputInfo(int player_nr, boolean active)
5289 {
5290   int i;
5291   static struct SetupKeyboardInfo custom_key;
5292   static struct
5293   {
5294     Key *key;
5295     char *text;
5296   } custom[] =
5297   {
5298     { &custom_key.left,  "Joystick Left"  },
5299     { &custom_key.right, "Joystick Right" },
5300     { &custom_key.up,    "Joystick Up"    },
5301     { &custom_key.down,  "Joystick Down"  },
5302     { &custom_key.snap,  "Button 1"       },
5303     { &custom_key.drop,  "Button 2"       }
5304   };
5305   static char *joystick_name[MAX_PLAYERS] =
5306   {
5307     "Joystick1",
5308     "Joystick2",
5309     "Joystick3",
5310     "Joystick4"
5311   };
5312   int text_font_nr = (active ? FONT_MENU_1_ACTIVE : FONT_MENU_1);
5313
5314   InitJoysticks();
5315
5316   custom_key = setup.input[player_nr].key;
5317
5318   DrawText(mSX + 11 * 32, mSY + 2 * 32, int2str(player_nr + 1, 1),
5319            FONT_INPUT_1_ACTIVE);
5320
5321   ClearRectangleOnBackground(drawto, mSX + 8 * TILEX, mSY + 2 * TILEY,
5322                              TILEX, TILEY);
5323   DrawGraphicThruMaskExt(drawto, mSX + 8 * TILEX, mSY + 2 * TILEY,
5324                          PLAYER_NR_GFX(IMG_PLAYER_1, player_nr), 0);
5325
5326   if (setup.input[player_nr].use_joystick)
5327   {
5328     char *device_name = setup.input[player_nr].joy.device_name;
5329     char *text = joystick_name[getJoystickNrFromDeviceName(device_name)];
5330     int font_nr = (joystick.fd[player_nr] < 0 ? FONT_VALUE_OLD : FONT_VALUE_1);
5331
5332     DrawText(mSX + 8 * 32, mSY + 3 * 32, text, font_nr);
5333     DrawText(mSX + 32, mSY + 4 * 32, "Calibrate", text_font_nr);
5334   }
5335   else
5336   {
5337     DrawText(mSX + 8 * 32, mSY + 3 * 32, "Keyboard ", FONT_VALUE_1);
5338     DrawText(mSX + 1 * 32, mSY + 4 * 32, "Customize", text_font_nr);
5339   }
5340
5341   DrawText(mSX + 32, mSY + 5 * 32, "Actual Settings:", FONT_MENU_1);
5342
5343   drawCursorXY(1, 4, IMG_MENU_BUTTON_LEFT);
5344   drawCursorXY(1, 5, IMG_MENU_BUTTON_RIGHT);
5345   drawCursorXY(1, 6, IMG_MENU_BUTTON_UP);
5346   drawCursorXY(1, 7, IMG_MENU_BUTTON_DOWN);
5347
5348   DrawText(mSX + 2 * 32, mSY +  6 * 32, ":", FONT_VALUE_OLD);
5349   DrawText(mSX + 2 * 32, mSY +  7 * 32, ":", FONT_VALUE_OLD);
5350   DrawText(mSX + 2 * 32, mSY +  8 * 32, ":", FONT_VALUE_OLD);
5351   DrawText(mSX + 2 * 32, mSY +  9 * 32, ":", FONT_VALUE_OLD);
5352   DrawText(mSX + 1 * 32, mSY + 10 * 32, "Snap Field:", FONT_VALUE_OLD);
5353   DrawText(mSX + 1 * 32, mSY + 12 * 32, "Drop Element:", FONT_VALUE_OLD);
5354
5355   for (i = 0; i < 6; i++)
5356   {
5357     int ypos = 6 + i + (i > 3 ? i-3 : 0);
5358
5359     DrawText(mSX + 3 * 32, mSY + ypos * 32,
5360              "              ", FONT_VALUE_1);
5361     DrawText(mSX + 3 * 32, mSY + ypos * 32,
5362              (setup.input[player_nr].use_joystick ?
5363               custom[i].text :
5364               getKeyNameFromKey(*custom[i].key)), FONT_VALUE_1);
5365   }
5366 }
5367
5368 static int input_player_nr = 0;
5369
5370 void HandleSetupScreen_Input_Player(int step, int direction)
5371 {
5372   int old_player_nr = input_player_nr;
5373   int new_player_nr;
5374
5375   new_player_nr = old_player_nr + step * direction;
5376   if (new_player_nr < 0)
5377     new_player_nr = 0;
5378   if (new_player_nr > MAX_PLAYERS - 1)
5379     new_player_nr = MAX_PLAYERS - 1;
5380
5381   if (new_player_nr != old_player_nr)
5382   {
5383     input_player_nr = new_player_nr;
5384
5385     drawPlayerSetupInputInfo(input_player_nr, FALSE);
5386   }
5387 }
5388
5389 void HandleSetupScreen_Input(int mx, int my, int dx, int dy, int button)
5390 {
5391   static int choice = 0;
5392   int x = 0;
5393   int y = choice;
5394   int pos_start  = SETUPINPUT_SCREEN_POS_START;
5395   int pos_empty1 = SETUPINPUT_SCREEN_POS_EMPTY1;
5396   int pos_empty2 = SETUPINPUT_SCREEN_POS_EMPTY2;
5397   int pos_end    = SETUPINPUT_SCREEN_POS_END;
5398
5399   if (button == MB_MENU_INITIALIZE)
5400   {
5401     drawPlayerSetupInputInfo(input_player_nr, (choice == 2));
5402
5403 #if 1
5404     DrawCursorAndText_Setup(choice, TRUE);
5405 #else
5406     drawCursor(choice, TRUE);
5407 #endif
5408
5409     return;
5410   }
5411   else if (button == MB_MENU_LEAVE)
5412   {
5413     setup_mode = SETUP_MODE_MAIN;
5414     DrawSetupScreen();
5415     InitJoysticks();
5416
5417     return;
5418   }
5419
5420   if (mx || my)         /* mouse input */
5421   {
5422     x = (mx - mSX) / 32;
5423     y = (my - mSY) / 32 - MENU_SCREEN_START_YPOS;
5424   }
5425   else if (dx || dy)    /* keyboard input */
5426   {
5427     if (dx && choice == 0)
5428       x = (dx < 0 ? 10 : 12);
5429     else if ((dx && choice == 1) ||
5430              (dx == +1 && choice == 2) ||
5431              (dx == -1 && choice == pos_end))
5432       button = MB_MENU_CHOICE;
5433     else if (dy)
5434       y = choice + dy;
5435
5436     if (y >= pos_empty1 && y <= pos_empty2)
5437       y = (dy > 0 ? pos_empty2 + 1 : pos_empty1 - 1);
5438   }
5439
5440   if (y == 0 && dx != 0 && button)
5441   {
5442     HandleSetupScreen_Input_Player(1, dx < 0 ? -1 : +1);
5443   }
5444   else if (IN_VIS_FIELD(x, y) &&
5445            y >= pos_start && y <= pos_end &&
5446            !(y >= pos_empty1 && y <= pos_empty2))
5447   {
5448     if (button)
5449     {
5450       if (y != choice)
5451       {
5452 #if 1
5453         DrawCursorAndText_Setup(choice, FALSE);
5454         DrawCursorAndText_Setup(y, TRUE);
5455
5456         drawPlayerSetupInputInfo(input_player_nr, (y == 2));
5457 #else
5458         drawCursor(choice, FALSE);
5459         drawCursor(y, TRUE);
5460 #endif
5461
5462         choice = y;
5463       }
5464     }
5465     else
5466     {
5467       if (y == 1)
5468       {
5469         char *device_name = setup.input[input_player_nr].joy.device_name;
5470
5471         if (!setup.input[input_player_nr].use_joystick)
5472         {
5473           int new_device_nr = (dx >= 0 ? 0 : MAX_PLAYERS - 1);
5474
5475           setJoystickDeviceToNr(device_name, new_device_nr);
5476           setup.input[input_player_nr].use_joystick = TRUE;
5477         }
5478         else
5479         {
5480           int device_nr = getJoystickNrFromDeviceName(device_name);
5481           int new_device_nr = device_nr + (dx >= 0 ? +1 : -1);
5482
5483           if (new_device_nr < 0 || new_device_nr >= MAX_PLAYERS)
5484             setup.input[input_player_nr].use_joystick = FALSE;
5485           else
5486             setJoystickDeviceToNr(device_name, new_device_nr);
5487         }
5488
5489         drawPlayerSetupInputInfo(input_player_nr, FALSE);
5490       }
5491       else if (y == 2)
5492       {
5493         if (setup.input[input_player_nr].use_joystick)
5494         {
5495           InitJoysticks();
5496           CalibrateJoystick(input_player_nr);
5497         }
5498         else
5499           CustomizeKeyboard(input_player_nr);
5500       }
5501       else if (y == pos_end)
5502       {
5503         InitJoysticks();
5504
5505         setup_mode = SETUP_MODE_MAIN;
5506         DrawSetupScreen();
5507       }
5508     }
5509   }
5510 }
5511
5512 void CustomizeKeyboard(int player_nr)
5513 {
5514   int i;
5515   int step_nr;
5516   boolean finished = FALSE;
5517   static struct SetupKeyboardInfo custom_key;
5518   static struct
5519   {
5520     Key *key;
5521     char *text;
5522   } customize_step[] =
5523   {
5524     { &custom_key.left,  "Move Left"    },
5525     { &custom_key.right, "Move Right"   },
5526     { &custom_key.up,    "Move Up"      },
5527     { &custom_key.down,  "Move Down"    },
5528     { &custom_key.snap,  "Snap Field"   },
5529     { &custom_key.drop,  "Drop Element" }
5530   };
5531
5532   /* read existing key bindings from player setup */
5533   custom_key = setup.input[player_nr].key;
5534
5535   ClearWindow();
5536
5537   DrawTextSCentered(mSY - SY + 16, FONT_TITLE_1, "Keyboard Input");
5538
5539   BackToFront();
5540   InitAnimation();
5541
5542   step_nr = 0;
5543   DrawText(mSX, mSY + (2 + 2 * step_nr) * 32,
5544            customize_step[step_nr].text, FONT_INPUT_1_ACTIVE);
5545   DrawText(mSX, mSY + (2 + 2 * step_nr + 1) * 32,
5546            "Key:", FONT_INPUT_1_ACTIVE);
5547   DrawText(mSX + 4 * 32, mSY + (2 + 2 * step_nr + 1) * 32,
5548            getKeyNameFromKey(*customize_step[step_nr].key), FONT_VALUE_OLD);
5549
5550   while (!finished)
5551   {
5552     if (PendingEvent())         /* got event */
5553     {
5554       Event event;
5555
5556       NextEvent(&event);
5557
5558       switch (event.type)
5559       {
5560         case EVENT_KEYPRESS:
5561           {
5562             Key key = GetEventKey((KeyEvent *)&event, FALSE);
5563
5564             if (key == KSYM_Escape || (key == KSYM_Return && step_nr == 6))
5565             {
5566               finished = TRUE;
5567               break;
5568             }
5569
5570             /* all keys configured -- wait for "Escape" or "Return" key */
5571             if (step_nr == 6)
5572               break;
5573
5574             /* press 'Enter' to keep the existing key binding */
5575             if (key == KSYM_Return)
5576               key = *customize_step[step_nr].key;
5577
5578             /* check if key already used */
5579             for (i = 0; i < step_nr; i++)
5580               if (*customize_step[i].key == key)
5581                 break;
5582             if (i < step_nr)
5583               break;
5584
5585             /* got new key binding */
5586             *customize_step[step_nr].key = key;
5587             DrawText(mSX + 4 * 32, mSY + (2 + 2 * step_nr + 1) * 32,
5588                      "             ", FONT_VALUE_1);
5589             DrawText(mSX + 4 * 32, mSY + (2 + 2 * step_nr + 1) * 32,
5590                      getKeyNameFromKey(key), FONT_VALUE_1);
5591             step_nr++;
5592
5593             /* un-highlight last query */
5594             DrawText(mSX, mSY + (2 + 2 * (step_nr - 1)) * 32,
5595                      customize_step[step_nr - 1].text, FONT_MENU_1);
5596             DrawText(mSX, mSY + (2 + 2 * (step_nr - 1) + 1) * 32,
5597                      "Key:", FONT_MENU_1);
5598
5599             /* press 'Enter' to leave */
5600             if (step_nr == 6)
5601             {
5602               DrawText(mSX + 16, mSY + 15 * 32 + 16,
5603                        "Press Enter", FONT_TITLE_1);
5604               break;
5605             }
5606
5607             /* query next key binding */
5608             DrawText(mSX, mSY + (2 + 2 * step_nr) * 32,
5609                      customize_step[step_nr].text, FONT_INPUT_1_ACTIVE);
5610             DrawText(mSX, mSY + (2 + 2 * step_nr + 1) * 32,
5611                      "Key:", FONT_INPUT_1_ACTIVE);
5612             DrawText(mSX + 4 * 32, mSY + (2 + 2 * step_nr + 1) * 32,
5613                      getKeyNameFromKey(*customize_step[step_nr].key),
5614                      FONT_VALUE_OLD);
5615           }
5616           break;
5617
5618         case EVENT_KEYRELEASE:
5619           key_joystick_mapping = 0;
5620           break;
5621
5622         default:
5623           HandleOtherEvents(&event);
5624           break;
5625       }
5626     }
5627
5628     DoAnimation();
5629     BackToFront();
5630
5631     /* don't eat all CPU time */
5632     Delay(10);
5633   }
5634
5635   /* write new key bindings back to player setup */
5636   setup.input[player_nr].key = custom_key;
5637
5638   StopAnimation();
5639   DrawSetupScreen_Input();
5640 }
5641
5642 static boolean CalibrateJoystickMain(int player_nr)
5643 {
5644   int new_joystick_xleft = JOYSTICK_XMIDDLE;
5645   int new_joystick_xright = JOYSTICK_XMIDDLE;
5646   int new_joystick_yupper = JOYSTICK_YMIDDLE;
5647   int new_joystick_ylower = JOYSTICK_YMIDDLE;
5648   int new_joystick_xmiddle, new_joystick_ymiddle;
5649
5650   int joystick_fd = joystick.fd[player_nr];
5651   int x, y, last_x, last_y, xpos = 8, ypos = 3;
5652   boolean check[3][3];
5653   int check_remaining = 3 * 3;
5654   int joy_x, joy_y;
5655   int joy_value;
5656   int result = -1;
5657
5658   if (joystick.status == JOYSTICK_NOT_AVAILABLE)
5659     return FALSE;
5660
5661   if (joystick_fd < 0 || !setup.input[player_nr].use_joystick)
5662     return FALSE;
5663
5664   ClearWindow();
5665
5666   for (y = 0; y < 3; y++)
5667   {
5668     for (x = 0; x < 3; x++)
5669     {
5670       DrawGraphic(xpos + x - 1, ypos + y - 1, IMG_MENU_CALIBRATE_BLUE, 0);
5671       check[x][y] = FALSE;
5672     }
5673   }
5674
5675   DrawTextSCentered(mSY - SY +  6 * 32, FONT_TITLE_1, "Rotate joystick");
5676   DrawTextSCentered(mSY - SY +  7 * 32, FONT_TITLE_1, "in all directions");
5677   DrawTextSCentered(mSY - SY +  9 * 32, FONT_TITLE_1, "if all balls");
5678   DrawTextSCentered(mSY - SY + 10 * 32, FONT_TITLE_1, "are marked,");
5679   DrawTextSCentered(mSY - SY + 11 * 32, FONT_TITLE_1, "center joystick");
5680   DrawTextSCentered(mSY - SY + 12 * 32, FONT_TITLE_1, "and");
5681   DrawTextSCentered(mSY - SY + 13 * 32, FONT_TITLE_1, "press any button!");
5682
5683   joy_value = Joystick(player_nr);
5684   last_x = (joy_value & JOY_LEFT ? -1 : joy_value & JOY_RIGHT ? +1 : 0);
5685   last_y = (joy_value & JOY_UP   ? -1 : joy_value & JOY_DOWN  ? +1 : 0);
5686
5687   /* eventually uncalibrated center position (joystick could be uncentered) */
5688   if (!ReadJoystick(joystick_fd, &joy_x, &joy_y, NULL, NULL))
5689     return FALSE;
5690
5691   new_joystick_xmiddle = joy_x;
5692   new_joystick_ymiddle = joy_y;
5693
5694   DrawGraphic(xpos + last_x, ypos + last_y, IMG_MENU_CALIBRATE_RED, 0);
5695   BackToFront();
5696
5697   while (Joystick(player_nr) & JOY_BUTTON);     /* wait for released button */
5698   InitAnimation();
5699
5700   while (result < 0)
5701   {
5702     if (PendingEvent())         /* got event */
5703     {
5704       Event event;
5705
5706       NextEvent(&event);
5707
5708       switch (event.type)
5709       {
5710         case EVENT_KEYPRESS:
5711           switch (GetEventKey((KeyEvent *)&event, TRUE))
5712           {
5713             case KSYM_Return:
5714               if (check_remaining == 0)
5715                 result = 1;
5716               break;
5717
5718             case KSYM_Escape:
5719               result = 0;
5720               break;
5721
5722             default:
5723               break;
5724           }
5725           break;
5726
5727         case EVENT_KEYRELEASE:
5728           key_joystick_mapping = 0;
5729           break;
5730
5731         default:
5732           HandleOtherEvents(&event);
5733           break;
5734       }
5735     }
5736
5737     if (!ReadJoystick(joystick_fd, &joy_x, &joy_y, NULL, NULL))
5738       return FALSE;
5739
5740     new_joystick_xleft  = MIN(new_joystick_xleft,  joy_x);
5741     new_joystick_xright = MAX(new_joystick_xright, joy_x);
5742     new_joystick_yupper = MIN(new_joystick_yupper, joy_y);
5743     new_joystick_ylower = MAX(new_joystick_ylower, joy_y);
5744
5745     setup.input[player_nr].joy.xleft = new_joystick_xleft;
5746     setup.input[player_nr].joy.yupper = new_joystick_yupper;
5747     setup.input[player_nr].joy.xright = new_joystick_xright;
5748     setup.input[player_nr].joy.ylower = new_joystick_ylower;
5749     setup.input[player_nr].joy.xmiddle = new_joystick_xmiddle;
5750     setup.input[player_nr].joy.ymiddle = new_joystick_ymiddle;
5751
5752     CheckJoystickData();
5753
5754     joy_value = Joystick(player_nr);
5755
5756     if (joy_value & JOY_BUTTON && check_remaining == 0)
5757       result = 1;
5758
5759     x = (joy_value & JOY_LEFT ? -1 : joy_value & JOY_RIGHT ? +1 : 0);
5760     y = (joy_value & JOY_UP   ? -1 : joy_value & JOY_DOWN  ? +1 : 0);
5761
5762     if (x != last_x || y != last_y)
5763     {
5764       DrawGraphic(xpos + last_x, ypos + last_y, IMG_MENU_CALIBRATE_YELLOW, 0);
5765       DrawGraphic(xpos + x,      ypos + y,      IMG_MENU_CALIBRATE_RED,    0);
5766
5767       last_x = x;
5768       last_y = y;
5769
5770       if (check_remaining > 0 && !check[x+1][y+1])
5771       {
5772         check[x+1][y+1] = TRUE;
5773         check_remaining--;
5774       }
5775
5776 #if 0
5777 #ifdef DEBUG
5778       printf("LEFT / MIDDLE / RIGHT == %d / %d / %d\n",
5779              setup.input[player_nr].joy.xleft,
5780              setup.input[player_nr].joy.xmiddle,
5781              setup.input[player_nr].joy.xright);
5782       printf("UP / MIDDLE / DOWN == %d / %d / %d\n",
5783              setup.input[player_nr].joy.yupper,
5784              setup.input[player_nr].joy.ymiddle,
5785              setup.input[player_nr].joy.ylower);
5786 #endif
5787 #endif
5788
5789     }
5790
5791     DoAnimation();
5792     BackToFront();
5793
5794     /* don't eat all CPU time */
5795     Delay(10);
5796   }
5797
5798   /* calibrated center position (joystick should now be centered) */
5799   if (!ReadJoystick(joystick_fd, &joy_x, &joy_y, NULL, NULL))
5800     return FALSE;
5801
5802   new_joystick_xmiddle = joy_x;
5803   new_joystick_ymiddle = joy_y;
5804
5805   StopAnimation();
5806
5807 #if 0
5808   DrawSetupScreen_Input();
5809 #endif
5810
5811   /* wait until the last pressed button was released */
5812   while (Joystick(player_nr) & JOY_BUTTON)
5813   {
5814     if (PendingEvent())         /* got event */
5815     {
5816       Event event;
5817
5818       NextEvent(&event);
5819       HandleOtherEvents(&event);
5820
5821       Delay(10);
5822     }
5823   }
5824
5825   return TRUE;
5826 }
5827
5828 void CalibrateJoystick(int player_nr)
5829 {
5830   if (!CalibrateJoystickMain(player_nr))
5831   {
5832     char *device_name = setup.input[player_nr].joy.device_name;
5833     int nr = getJoystickNrFromDeviceName(device_name) + 1;
5834     int xpos = mSX - SX;
5835     int ypos = mSY - SY;
5836
5837     ClearWindow();
5838
5839     DrawTextF(xpos + 16, ypos + 6 * 32, FONT_TITLE_1, "   JOYSTICK %d   ", nr);
5840     DrawTextF(xpos + 16, ypos + 7 * 32, FONT_TITLE_1, " NOT AVAILABLE! ");
5841     BackToFront();
5842
5843     Delay(2000);                /* show error message for a short time */
5844
5845     ClearEventQueue();
5846   }
5847
5848 #if 1
5849   DrawSetupScreen_Input();
5850 #endif
5851 }
5852
5853 void DrawSetupScreen()
5854 {
5855   DeactivateJoystick();
5856
5857   SetMainBackgroundImage(IMG_BACKGROUND_SETUP);
5858
5859   if (setup_mode == SETUP_MODE_INPUT)
5860     DrawSetupScreen_Input();
5861   else if (setup_mode == SETUP_MODE_CHOOSE_GAME_SPEED)
5862     DrawChooseTree(&game_speed_current);
5863   else if (setup_mode == SETUP_MODE_CHOOSE_SCREEN_MODE)
5864     DrawChooseTree(&screen_mode_current);
5865   else if (setup_mode == SETUP_MODE_CHOOSE_GRAPHICS)
5866     DrawChooseTree(&artwork.gfx_current);
5867   else if (setup_mode == SETUP_MODE_CHOOSE_SOUNDS)
5868     DrawChooseTree(&artwork.snd_current);
5869   else if (setup_mode == SETUP_MODE_CHOOSE_MUSIC)
5870     DrawChooseTree(&artwork.mus_current);
5871   else
5872     DrawSetupScreen_Generic();
5873
5874   PlayMenuSound();
5875   PlayMenuMusic();
5876 }
5877
5878 void RedrawSetupScreenAfterFullscreenToggle()
5879 {
5880   if (setup_mode == SETUP_MODE_GRAPHICS)
5881     DrawSetupScreen();
5882 }
5883
5884 void HandleSetupScreen(int mx, int my, int dx, int dy, int button)
5885 {
5886   if (setup_mode == SETUP_MODE_INPUT)
5887     HandleSetupScreen_Input(mx, my, dx, dy, button);
5888   else if (setup_mode == SETUP_MODE_CHOOSE_GAME_SPEED)
5889     HandleChooseTree(mx, my, dx, dy, button, &game_speed_current);
5890   else if (setup_mode == SETUP_MODE_CHOOSE_SCREEN_MODE)
5891     HandleChooseTree(mx, my, dx, dy, button, &screen_mode_current);
5892   else if (setup_mode == SETUP_MODE_CHOOSE_GRAPHICS)
5893     HandleChooseTree(mx, my, dx, dy, button, &artwork.gfx_current);
5894   else if (setup_mode == SETUP_MODE_CHOOSE_SOUNDS)
5895     HandleChooseTree(mx, my, dx, dy, button, &artwork.snd_current);
5896   else if (setup_mode == SETUP_MODE_CHOOSE_MUSIC)
5897     HandleChooseTree(mx, my, dx, dy, button, &artwork.mus_current);
5898   else
5899     HandleSetupScreen_Generic(mx, my, dx, dy, button);
5900
5901   DoAnimation();
5902 }
5903
5904 void HandleGameActions()
5905 {
5906   if (game_status != GAME_MODE_PLAYING)
5907     return;
5908
5909   GameActions();        /* main game loop */
5910
5911   if (tape.auto_play && !tape.playing)
5912     AutoPlayTape();     /* continue automatically playing next tape */
5913 }
5914
5915
5916 /* ---------- new screen button stuff -------------------------------------- */
5917
5918 static void getScreenMenuButtonPos(int *x, int *y, int gadget_id)
5919 {
5920   switch (gadget_id)
5921   {
5922 #if 1
5923     case SCREEN_CTRL_ID_PREV_LEVEL:
5924       *x = mSX + menu.main.button.prev_level.x;
5925       *y = mSY + menu.main.button.prev_level.y;
5926       break;
5927
5928     case SCREEN_CTRL_ID_NEXT_LEVEL:
5929       *x = mSX + menu.main.button.next_level.x;
5930       *y = mSY + menu.main.button.next_level.y;
5931       break;
5932 #else
5933     case SCREEN_CTRL_ID_PREV_LEVEL:
5934       *x = mSX + TILEX * getPrevlevelButtonPos();
5935       *y = mSY + TILEY * (MENU_SCREEN_START_YPOS + 1);
5936       break;
5937
5938     case SCREEN_CTRL_ID_NEXT_LEVEL:
5939       *x = mSX + TILEX * getNextLevelButtonPos();
5940       *y = mSY + TILEY * (MENU_SCREEN_START_YPOS + 1);
5941       break;
5942 #endif
5943
5944     case SCREEN_CTRL_ID_PREV_PLAYER:
5945       *x = mSX + TILEX * 10;
5946       *y = mSY + TILEY * MENU_SCREEN_START_YPOS;
5947       break;
5948
5949     case SCREEN_CTRL_ID_NEXT_PLAYER:
5950       *x = mSX + TILEX * 12;
5951       *y = mSY + TILEY * MENU_SCREEN_START_YPOS;
5952       break;
5953
5954     default:
5955       Error(ERR_EXIT, "unknown gadget ID %d", gadget_id);
5956   }
5957 }
5958
5959 static struct
5960 {
5961   int gfx_unpressed, gfx_pressed;
5962   void (*get_gadget_position)(int *, int *, int);
5963   int gadget_id;
5964   int screen_mask;
5965   char *infotext;
5966 } menubutton_info[NUM_SCREEN_MENUBUTTONS] =
5967 {
5968   {
5969     IMG_MENU_BUTTON_PREV_LEVEL, IMG_MENU_BUTTON_PREV_LEVEL_ACTIVE,
5970     getScreenMenuButtonPos,
5971     SCREEN_CTRL_ID_PREV_LEVEL,
5972     SCREEN_MASK_MAIN,
5973     "last level"
5974   },
5975   {
5976     IMG_MENU_BUTTON_NEXT_LEVEL, IMG_MENU_BUTTON_NEXT_LEVEL_ACTIVE,
5977     getScreenMenuButtonPos,
5978     SCREEN_CTRL_ID_NEXT_LEVEL,
5979     SCREEN_MASK_MAIN,
5980     "next level"
5981   },
5982   {
5983     IMG_MENU_BUTTON_LEFT, IMG_MENU_BUTTON_LEFT_ACTIVE,
5984     getScreenMenuButtonPos,
5985     SCREEN_CTRL_ID_PREV_PLAYER,
5986     SCREEN_MASK_INPUT,
5987     "last player"
5988   },
5989   {
5990     IMG_MENU_BUTTON_RIGHT, IMG_MENU_BUTTON_RIGHT_ACTIVE,
5991     getScreenMenuButtonPos,
5992     SCREEN_CTRL_ID_NEXT_PLAYER,
5993     SCREEN_MASK_INPUT,
5994     "next player"
5995   },
5996 };
5997
5998 static struct
5999 {
6000   int gfx_unpressed, gfx_pressed;
6001   int x, y;
6002   int gadget_id;
6003   char *infotext;
6004 } scrollbutton_info[NUM_SCREEN_SCROLLBUTTONS] =
6005 {
6006   {
6007     IMG_MENU_BUTTON_UP, IMG_MENU_BUTTON_UP_ACTIVE,
6008     SC_SCROLL_UP_XPOS, SC_SCROLL_UP_YPOS,
6009     SCREEN_CTRL_ID_SCROLL_UP,
6010     "scroll up"
6011   },
6012   {
6013     IMG_MENU_BUTTON_DOWN, IMG_MENU_BUTTON_DOWN_ACTIVE,
6014     SC_SCROLL_DOWN_XPOS, SC_SCROLL_DOWN_YPOS,
6015     SCREEN_CTRL_ID_SCROLL_DOWN,
6016     "scroll down"
6017   }
6018 };
6019
6020 static struct
6021 {
6022 #if defined(TARGET_X11_NATIVE_PERFORMANCE_WORKAROUND)
6023   Bitmap **gfx_unpressed, **gfx_pressed;
6024 #else
6025   int gfx_unpressed, gfx_pressed;
6026 #endif
6027   int x, y;
6028   int width, height;
6029   int type;
6030   int gadget_id;
6031   char *infotext;
6032 } scrollbar_info[NUM_SCREEN_SCROLLBARS] =
6033 {
6034   {
6035 #if defined(TARGET_X11_NATIVE_PERFORMANCE_WORKAROUND)
6036     &scrollbar_bitmap[0], &scrollbar_bitmap[1],
6037 #else
6038     IMG_MENU_SCROLLBAR, IMG_MENU_SCROLLBAR_ACTIVE,
6039 #endif
6040     SC_SCROLL_VERTICAL_XPOS, SC_SCROLL_VERTICAL_YPOS,
6041     SC_SCROLL_VERTICAL_XSIZE, SC_SCROLL_VERTICAL_YSIZE,
6042     GD_TYPE_SCROLLBAR_VERTICAL,
6043     SCREEN_CTRL_ID_SCROLL_VERTICAL,
6044     "scroll level series vertically"
6045   }
6046 };
6047
6048 static void CreateScreenMenubuttons()
6049 {
6050   struct GadgetInfo *gi;
6051   unsigned long event_mask;
6052   int i;
6053
6054   for (i = 0; i < NUM_SCREEN_MENUBUTTONS; i++)
6055   {
6056     Bitmap *gd_bitmap_unpressed, *gd_bitmap_pressed;
6057     int gfx_unpressed, gfx_pressed;
6058     int x, y, width, height;
6059     int gd_x1, gd_x2, gd_y1, gd_y2;
6060     int id = menubutton_info[i].gadget_id;
6061
6062     event_mask = GD_EVENT_PRESSED | GD_EVENT_REPEATED;
6063
6064     menubutton_info[i].get_gadget_position(&x, &y, id);
6065
6066     width = SC_MENUBUTTON_XSIZE;
6067     height = SC_MENUBUTTON_YSIZE;
6068
6069     gfx_unpressed = menubutton_info[i].gfx_unpressed;
6070     gfx_pressed   = menubutton_info[i].gfx_pressed;
6071     gd_bitmap_unpressed = graphic_info[gfx_unpressed].bitmap;
6072     gd_bitmap_pressed   = graphic_info[gfx_pressed].bitmap;
6073     gd_x1 = graphic_info[gfx_unpressed].src_x;
6074     gd_y1 = graphic_info[gfx_unpressed].src_y;
6075     gd_x2 = graphic_info[gfx_pressed].src_x;
6076     gd_y2 = graphic_info[gfx_pressed].src_y;
6077
6078     gi = CreateGadget(GDI_CUSTOM_ID, id,
6079                       GDI_CUSTOM_TYPE_ID, i,
6080                       GDI_INFO_TEXT, menubutton_info[i].infotext,
6081                       GDI_X, x,
6082                       GDI_Y, y,
6083                       GDI_WIDTH, width,
6084                       GDI_HEIGHT, height,
6085                       GDI_TYPE, GD_TYPE_NORMAL_BUTTON,
6086                       GDI_STATE, GD_BUTTON_UNPRESSED,
6087                       GDI_DESIGN_UNPRESSED, gd_bitmap_unpressed, gd_x1, gd_y1,
6088                       GDI_DESIGN_PRESSED, gd_bitmap_pressed, gd_x2, gd_y2,
6089                       GDI_DIRECT_DRAW, FALSE,
6090                       GDI_EVENT_MASK, event_mask,
6091                       GDI_CALLBACK_ACTION, HandleScreenGadgets,
6092                       GDI_END);
6093
6094     if (gi == NULL)
6095       Error(ERR_EXIT, "cannot create gadget");
6096
6097     screen_gadget[id] = gi;
6098   }
6099 }
6100
6101 static void CreateScreenScrollbuttons()
6102 {
6103   struct GadgetInfo *gi;
6104   unsigned long event_mask;
6105   int i;
6106
6107   for (i = 0; i < NUM_SCREEN_SCROLLBUTTONS; i++)
6108   {
6109     Bitmap *gd_bitmap_unpressed, *gd_bitmap_pressed;
6110     int gfx_unpressed, gfx_pressed;
6111     int x, y, width, height;
6112     int gd_x1, gd_x2, gd_y1, gd_y2;
6113     int id = scrollbutton_info[i].gadget_id;
6114
6115     event_mask = GD_EVENT_PRESSED | GD_EVENT_REPEATED;
6116
6117     x = mSX + scrollbutton_info[i].x + menu.scrollbar_xoffset;
6118     y = mSY + scrollbutton_info[i].y;
6119     width = SC_SCROLLBUTTON_XSIZE;
6120     height = SC_SCROLLBUTTON_YSIZE;
6121
6122     if (id == SCREEN_CTRL_ID_SCROLL_DOWN)
6123       y = mSY + (SC_SCROLL_VERTICAL_YPOS +
6124                  (NUM_MENU_ENTRIES_ON_SCREEN - 2) * SC_SCROLLBUTTON_YSIZE);
6125
6126     gfx_unpressed = scrollbutton_info[i].gfx_unpressed;
6127     gfx_pressed   = scrollbutton_info[i].gfx_pressed;
6128     gd_bitmap_unpressed = graphic_info[gfx_unpressed].bitmap;
6129     gd_bitmap_pressed   = graphic_info[gfx_pressed].bitmap;
6130     gd_x1 = graphic_info[gfx_unpressed].src_x;
6131     gd_y1 = graphic_info[gfx_unpressed].src_y;
6132     gd_x2 = graphic_info[gfx_pressed].src_x;
6133     gd_y2 = graphic_info[gfx_pressed].src_y;
6134
6135     gi = CreateGadget(GDI_CUSTOM_ID, id,
6136                       GDI_CUSTOM_TYPE_ID, i,
6137                       GDI_INFO_TEXT, scrollbutton_info[i].infotext,
6138                       GDI_X, x,
6139                       GDI_Y, y,
6140                       GDI_WIDTH, width,
6141                       GDI_HEIGHT, height,
6142                       GDI_TYPE, GD_TYPE_NORMAL_BUTTON,
6143                       GDI_STATE, GD_BUTTON_UNPRESSED,
6144                       GDI_DESIGN_UNPRESSED, gd_bitmap_unpressed, gd_x1, gd_y1,
6145                       GDI_DESIGN_PRESSED, gd_bitmap_pressed, gd_x2, gd_y2,
6146                       GDI_DIRECT_DRAW, FALSE,
6147                       GDI_EVENT_MASK, event_mask,
6148                       GDI_CALLBACK_ACTION, HandleScreenGadgets,
6149                       GDI_END);
6150
6151     if (gi == NULL)
6152       Error(ERR_EXIT, "cannot create gadget");
6153
6154     screen_gadget[id] = gi;
6155   }
6156 }
6157
6158 static void CreateScreenScrollbars()
6159 {
6160   int i;
6161
6162   for (i = 0; i < NUM_SCREEN_SCROLLBARS; i++)
6163   {
6164     Bitmap *gd_bitmap_unpressed, *gd_bitmap_pressed;
6165 #if !defined(TARGET_X11_NATIVE_PERFORMANCE_WORKAROUND)
6166     int gfx_unpressed, gfx_pressed;
6167 #endif
6168     int x, y, width, height;
6169     int gd_x1, gd_x2, gd_y1, gd_y2;
6170     struct GadgetInfo *gi;
6171     int items_max, items_visible, item_position;
6172     unsigned long event_mask;
6173     int num_page_entries = NUM_MENU_ENTRIES_ON_SCREEN;
6174     int id = scrollbar_info[i].gadget_id;
6175
6176     event_mask = GD_EVENT_MOVING | GD_EVENT_OFF_BORDERS;
6177
6178     x = mSX + scrollbar_info[i].x + menu.scrollbar_xoffset;
6179     y = mSY + scrollbar_info[i].y;
6180     width  = scrollbar_info[i].width;
6181     height = scrollbar_info[i].height;
6182
6183     if (id == SCREEN_CTRL_ID_SCROLL_VERTICAL)
6184       height = (NUM_MENU_ENTRIES_ON_SCREEN - 2) * SC_SCROLLBUTTON_YSIZE;
6185
6186     items_max = num_page_entries;
6187     items_visible = num_page_entries;
6188     item_position = 0;
6189
6190 #if defined(TARGET_X11_NATIVE_PERFORMANCE_WORKAROUND)
6191     gd_bitmap_unpressed = *scrollbar_info[i].gfx_unpressed;
6192     gd_bitmap_pressed   = *scrollbar_info[i].gfx_pressed;
6193     gd_x1 = 0;
6194     gd_y1 = 0;
6195     gd_x2 = 0;
6196     gd_y2 = 0;
6197 #else
6198     gfx_unpressed = scrollbar_info[i].gfx_unpressed;
6199     gfx_pressed   = scrollbar_info[i].gfx_pressed;
6200     gd_bitmap_unpressed = graphic_info[gfx_unpressed].bitmap;
6201     gd_bitmap_pressed   = graphic_info[gfx_pressed].bitmap;
6202     gd_x1 = graphic_info[gfx_unpressed].src_x;
6203     gd_y1 = graphic_info[gfx_unpressed].src_y;
6204     gd_x2 = graphic_info[gfx_pressed].src_x;
6205     gd_y2 = graphic_info[gfx_pressed].src_y;
6206 #endif
6207
6208     gi = CreateGadget(GDI_CUSTOM_ID, id,
6209                       GDI_CUSTOM_TYPE_ID, i,
6210                       GDI_INFO_TEXT, scrollbar_info[i].infotext,
6211                       GDI_X, x,
6212                       GDI_Y, y,
6213                       GDI_WIDTH, width,
6214                       GDI_HEIGHT, height,
6215                       GDI_TYPE, scrollbar_info[i].type,
6216                       GDI_SCROLLBAR_ITEMS_MAX, items_max,
6217                       GDI_SCROLLBAR_ITEMS_VISIBLE, items_visible,
6218                       GDI_SCROLLBAR_ITEM_POSITION, item_position,
6219 #if 1
6220                       GDI_WHEEL_AREA_X, SX,
6221                       GDI_WHEEL_AREA_Y, SY,
6222                       GDI_WHEEL_AREA_WIDTH, SXSIZE,
6223                       GDI_WHEEL_AREA_HEIGHT, SYSIZE,
6224 #else
6225                       GDI_WHEEL_AREA_X, 0,
6226                       GDI_WHEEL_AREA_Y, 0,
6227                       GDI_WHEEL_AREA_WIDTH, WIN_XSIZE,
6228                       GDI_WHEEL_AREA_HEIGHT, WIN_YSIZE,
6229 #endif
6230                       GDI_STATE, GD_BUTTON_UNPRESSED,
6231                       GDI_DESIGN_UNPRESSED, gd_bitmap_unpressed, gd_x1, gd_y1,
6232                       GDI_DESIGN_PRESSED, gd_bitmap_pressed, gd_x2, gd_y2,
6233                       GDI_BORDER_SIZE, SC_BORDER_SIZE, SC_BORDER_SIZE,
6234                       GDI_DIRECT_DRAW, FALSE,
6235                       GDI_EVENT_MASK, event_mask,
6236                       GDI_CALLBACK_ACTION, HandleScreenGadgets,
6237                       GDI_END);
6238
6239     if (gi == NULL)
6240       Error(ERR_EXIT, "cannot create gadget");
6241
6242     screen_gadget[id] = gi;
6243   }
6244 }
6245
6246 void CreateScreenGadgets()
6247 {
6248   int last_game_status = game_status;   /* save current game status */
6249
6250 #if defined(TARGET_X11_NATIVE_PERFORMANCE_WORKAROUND)
6251   int i;
6252
6253   for (i = 0; i < NUM_SCROLLBAR_BITMAPS; i++)
6254   {
6255     scrollbar_bitmap[i] = CreateBitmap(TILEX, TILEY, DEFAULT_DEPTH);
6256
6257     /* copy pointers to clip mask and GC */
6258     scrollbar_bitmap[i]->clip_mask =
6259       graphic_info[IMG_MENU_SCROLLBAR + i].clip_mask;
6260     scrollbar_bitmap[i]->stored_clip_gc =
6261       graphic_info[IMG_MENU_SCROLLBAR + i].clip_gc;
6262
6263     BlitBitmap(graphic_info[IMG_MENU_SCROLLBAR + i].bitmap,
6264                scrollbar_bitmap[i],
6265                graphic_info[IMG_MENU_SCROLLBAR + i].src_x,
6266                graphic_info[IMG_MENU_SCROLLBAR + i].src_y,
6267                TILEX, TILEY, 0, 0);
6268   }
6269 #endif
6270
6271   CreateScreenMenubuttons();
6272
6273   /* force LEVELS draw offset for scrollbar / scrollbutton gadgets */
6274   game_status = GAME_MODE_LEVELS;
6275
6276   CreateScreenScrollbuttons();
6277   CreateScreenScrollbars();
6278
6279   game_status = last_game_status;       /* restore current game status */
6280 }
6281
6282 void FreeScreenGadgets()
6283 {
6284   int i;
6285
6286 #if defined(TARGET_X11_NATIVE_PERFORMANCE_WORKAROUND)
6287   for (i = 0; i < NUM_SCROLLBAR_BITMAPS; i++)
6288   {
6289     /* prevent freeing clip mask and GC twice */
6290     scrollbar_bitmap[i]->clip_mask = None;
6291     scrollbar_bitmap[i]->stored_clip_gc = None;
6292
6293     FreeBitmap(scrollbar_bitmap[i]);
6294   }
6295 #endif
6296
6297   for (i = 0; i < NUM_SCREEN_GADGETS; i++)
6298     FreeGadget(screen_gadget[i]);
6299 }
6300
6301 void MapScreenMenuGadgets(int screen_mask)
6302 {
6303   int i;
6304
6305   for (i = 0; i < NUM_SCREEN_MENUBUTTONS; i++)
6306     if (screen_mask & menubutton_info[i].screen_mask)
6307       MapGadget(screen_gadget[menubutton_info[i].gadget_id]);
6308 }
6309
6310 void MapScreenTreeGadgets(TreeInfo *ti)
6311 {
6312   int num_entries = numTreeInfoInGroup(ti);
6313   int i;
6314
6315   if (num_entries <= NUM_MENU_ENTRIES_ON_SCREEN)
6316     return;
6317
6318   for (i = 0; i < NUM_SCREEN_SCROLLBUTTONS; i++)
6319     MapGadget(screen_gadget[scrollbutton_info[i].gadget_id]);
6320
6321   for (i = 0; i < NUM_SCREEN_SCROLLBARS; i++)
6322     MapGadget(screen_gadget[scrollbar_info[i].gadget_id]);
6323 }
6324
6325 static void HandleScreenGadgets(struct GadgetInfo *gi)
6326 {
6327   int id = gi->custom_id;
6328   int button = gi->event.button;
6329   int step = (button == 1 ? 1 : button == 2 ? 5 : 10);
6330
6331   switch (id)
6332   {
6333     case SCREEN_CTRL_ID_PREV_LEVEL:
6334       HandleMainMenu_SelectLevel(step, -1);
6335       break;
6336
6337     case SCREEN_CTRL_ID_NEXT_LEVEL:
6338       HandleMainMenu_SelectLevel(step, +1);
6339       break;
6340
6341     case SCREEN_CTRL_ID_PREV_PLAYER:
6342       HandleSetupScreen_Input_Player(step, -1);
6343       break;
6344
6345     case SCREEN_CTRL_ID_NEXT_PLAYER:
6346       HandleSetupScreen_Input_Player(step, +1);
6347       break;
6348
6349     case SCREEN_CTRL_ID_SCROLL_UP:
6350       if (game_status == GAME_MODE_LEVELS)
6351         HandleChooseLevel(0,0, 0, -1 * SCROLL_LINE, MB_MENU_MARK);
6352       else if (game_status == GAME_MODE_SETUP)
6353         HandleSetupScreen(0,0, 0, -1 * SCROLL_LINE, MB_MENU_MARK);
6354       break;
6355
6356     case SCREEN_CTRL_ID_SCROLL_DOWN:
6357       if (game_status == GAME_MODE_LEVELS)
6358         HandleChooseLevel(0,0, 0, +1 * SCROLL_LINE, MB_MENU_MARK);
6359       else if (game_status == GAME_MODE_SETUP)
6360         HandleSetupScreen(0,0, 0, +1 * SCROLL_LINE, MB_MENU_MARK);
6361       break;
6362
6363     case SCREEN_CTRL_ID_SCROLL_VERTICAL:
6364       if (game_status == GAME_MODE_LEVELS)
6365         HandleChooseLevel(0,0, 999,gi->event.item_position,MB_MENU_INITIALIZE);
6366       else if (game_status == GAME_MODE_SETUP)
6367         HandleSetupScreen(0,0, 999,gi->event.item_position,MB_MENU_INITIALIZE);
6368       break;
6369
6370     default:
6371       break;
6372   }
6373 }