added support for (normal and adaptive) vertical sync (vsync)
[rocksndiamonds.git] / src / screens.c
1 // ============================================================================
2 // Rocks'n'Diamonds - McDuffin Strikes Back!
3 // ----------------------------------------------------------------------------
4 // (c) 1995-2014 by Artsoft Entertainment
5 //                  Holger Schemel
6 //                  info@artsoft.org
7 //                  http://www.artsoft.org/
8 // ----------------------------------------------------------------------------
9 // screens.c
10 // ============================================================================
11
12 #include "libgame/libgame.h"
13
14 #include "screens.h"
15 #include "events.h"
16 #include "game.h"
17 #include "tools.h"
18 #include "editor.h"
19 #include "files.h"
20 #include "tape.h"
21 #include "anim.h"
22 #include "network.h"
23 #include "init.h"
24 #include "config.h"
25
26
27 #define DEBUG_JOYSTICKS         0
28
29
30 /* screens on the info screen */
31 #define INFO_MODE_MAIN                  0
32 #define INFO_MODE_TITLE                 1
33 #define INFO_MODE_ELEMENTS              2
34 #define INFO_MODE_MUSIC                 3
35 #define INFO_MODE_CREDITS               4
36 #define INFO_MODE_PROGRAM               5
37 #define INFO_MODE_VERSION               6
38 #define INFO_MODE_LEVELSET              7
39
40 #define MAX_INFO_MODES                  8
41
42 /* screens on the setup screen */
43 /* (must match GFX_SPECIAL_ARG_SETUP_* values as defined in src/main.h) */
44 /* (should also match corresponding entries in src/conf_gfx.c) */
45 #define SETUP_MODE_MAIN                 0
46 #define SETUP_MODE_GAME                 1
47 #define SETUP_MODE_EDITOR               2
48 #define SETUP_MODE_GRAPHICS             3
49 #define SETUP_MODE_SOUND                4
50 #define SETUP_MODE_ARTWORK              5
51 #define SETUP_MODE_INPUT                6
52 #define SETUP_MODE_TOUCH                7
53 #define SETUP_MODE_SHORTCUTS            8
54 #define SETUP_MODE_SHORTCUTS_1          9
55 #define SETUP_MODE_SHORTCUTS_2          10
56 #define SETUP_MODE_SHORTCUTS_3          11
57 #define SETUP_MODE_SHORTCUTS_4          12
58 #define SETUP_MODE_SHORTCUTS_5          13
59
60 /* sub-screens on the setup screen (generic) */
61 #define SETUP_MODE_CHOOSE_ARTWORK       14
62 #define SETUP_MODE_CHOOSE_OTHER         15
63
64 /* sub-screens on the setup screen (specific) */
65 #define SETUP_MODE_CHOOSE_GAME_SPEED    16
66 #define SETUP_MODE_CHOOSE_SCROLL_DELAY  17
67 #define SETUP_MODE_CHOOSE_SNAPSHOT_MODE 18
68 #define SETUP_MODE_CHOOSE_WINDOW_SIZE   19
69 #define SETUP_MODE_CHOOSE_SCALING_TYPE  20
70 #define SETUP_MODE_CHOOSE_RENDERING     21
71 #define SETUP_MODE_CHOOSE_VSYNC         22
72 #define SETUP_MODE_CHOOSE_GRAPHICS      23
73 #define SETUP_MODE_CHOOSE_SOUNDS        24
74 #define SETUP_MODE_CHOOSE_MUSIC         25
75 #define SETUP_MODE_CHOOSE_VOLUME_SIMPLE 26
76 #define SETUP_MODE_CHOOSE_VOLUME_LOOPS  27
77 #define SETUP_MODE_CHOOSE_VOLUME_MUSIC  28
78 #define SETUP_MODE_CHOOSE_TOUCH_CONTROL 29
79 #define SETUP_MODE_CHOOSE_MOVE_DISTANCE 30
80 #define SETUP_MODE_CHOOSE_DROP_DISTANCE 31
81 #define SETUP_MODE_CHOOSE_TRANSPARENCY  32
82 #define SETUP_MODE_CHOOSE_GRID_XSIZE_0  33
83 #define SETUP_MODE_CHOOSE_GRID_YSIZE_0  34
84 #define SETUP_MODE_CHOOSE_GRID_XSIZE_1  35
85 #define SETUP_MODE_CHOOSE_GRID_YSIZE_1  36
86 #define SETUP_MODE_CONFIG_VIRT_BUTTONS  37
87
88 #define MAX_SETUP_MODES                 38
89
90 #define MAX_MENU_MODES                  MAX(MAX_INFO_MODES, MAX_SETUP_MODES)
91
92 /* setup screen titles */
93 #define STR_SETUP_MAIN                  "Setup"
94 #define STR_SETUP_GAME                  "Game & Menu"
95 #define STR_SETUP_EDITOR                "Editor"
96 #define STR_SETUP_GRAPHICS              "Graphics"
97 #define STR_SETUP_SOUND                 "Sound & Music"
98 #define STR_SETUP_ARTWORK               "Custom Artwork"
99 #define STR_SETUP_INPUT                 "Input Devices"
100 #define STR_SETUP_TOUCH                 "Touch Controls"
101 #define STR_SETUP_SHORTCUTS             "Key Shortcuts"
102 #define STR_SETUP_EXIT                  "Exit"
103 #define STR_SETUP_SAVE_AND_EXIT         "Save and Exit"
104
105 #define STR_SETUP_CHOOSE_GAME_SPEED     "Game Speed"
106 #define STR_SETUP_CHOOSE_SCROLL_DELAY   "Scroll Delay"
107 #define STR_SETUP_CHOOSE_SNAPSHOT_MODE  "Snapshot Mode"
108 #define STR_SETUP_CHOOSE_WINDOW_SIZE    "Window Scaling"
109 #define STR_SETUP_CHOOSE_SCALING_TYPE   "Anti-Aliasing"
110 #define STR_SETUP_CHOOSE_RENDERING      "Rendering Mode"
111 #define STR_SETUP_CHOOSE_VSYNC          "VSync Mode"
112 #define STR_SETUP_CHOOSE_VOLUME_SIMPLE  "Sound Volume"
113 #define STR_SETUP_CHOOSE_VOLUME_LOOPS   "Loops Volume"
114 #define STR_SETUP_CHOOSE_VOLUME_MUSIC   "Music Volume"
115 #define STR_SETUP_CHOOSE_TOUCH_CONTROL  "Control Type"
116 #define STR_SETUP_CHOOSE_MOVE_DISTANCE  "Move Distance"
117 #define STR_SETUP_CHOOSE_DROP_DISTANCE  "Drop Distance"
118 #define STR_SETUP_CHOOSE_TRANSPARENCY   "Transparency"
119 #define STR_SETUP_CHOOSE_GRID_XSIZE_0   "Horiz. Buttons"
120 #define STR_SETUP_CHOOSE_GRID_YSIZE_0   "Vert. Buttons"
121 #define STR_SETUP_CHOOSE_GRID_XSIZE_1   "Horiz. Buttons"
122 #define STR_SETUP_CHOOSE_GRID_YSIZE_1   "Vert. Buttons"
123
124 /* for input setup functions */
125 #define SETUPINPUT_SCREEN_POS_START     0
126 #define SETUPINPUT_SCREEN_POS_EMPTY1    3
127 #define SETUPINPUT_SCREEN_POS_EMPTY2    12
128 #define SETUPINPUT_SCREEN_POS_END       13
129
130 #define MENU_SETUP_FONT_TITLE           FONT_TEXT_1
131 #define MENU_SETUP_FONT_TEXT            FONT_TITLE_2
132
133 /* for various menu stuff  */
134 #define MENU_SCREEN_START_XPOS          1
135 #define MENU_SCREEN_START_YPOS          2
136 #define MENU_SCREEN_VALUE_XPOS          (SCR_FIELDX - 3)
137 #define MENU_SCREEN_MAX_XPOS            (SCR_FIELDX - 1)
138 #define MENU_TITLE1_YPOS                8
139 #define MENU_TITLE2_YPOS                46
140 #define MENU_INFO_FONT_TITLE            FONT_TEXT_1
141 #define MENU_INFO_FONT_HEAD             FONT_TEXT_2
142 #define MENU_INFO_FONT_TEXT             FONT_TEXT_3
143 #define MENU_INFO_FONT_FOOT             FONT_TEXT_4
144 #define MENU_INFO_SPACE_HEAD            (menu.headline2_spacing_info[info_mode])
145 #define MENU_SCREEN_INFO_SPACE_LEFT     (menu.left_spacing_info[info_mode])
146 #define MENU_SCREEN_INFO_SPACE_RIGHT    (menu.right_spacing_info[info_mode])
147 #define MENU_SCREEN_INFO_SPACE_TOP      (menu.top_spacing_info[info_mode])
148 #define MENU_SCREEN_INFO_SPACE_BOTTOM   (menu.bottom_spacing_info[info_mode])
149 #define MENU_SCREEN_INFO_YSTART1        MENU_SCREEN_INFO_SPACE_TOP
150 #define MENU_SCREEN_INFO_YSTART2        (MENU_SCREEN_INFO_YSTART1 +            \
151                                          getMenuTextStep(MENU_INFO_SPACE_HEAD, \
152                                                          MENU_INFO_FONT_TITLE))
153 #define MENU_SCREEN_INFO_YSTEP          (TILEY + 4)
154 #define MENU_SCREEN_INFO_YBOTTOM        (SYSIZE - MENU_SCREEN_INFO_SPACE_BOTTOM)
155 #define MENU_SCREEN_INFO_YSIZE          (MENU_SCREEN_INFO_YBOTTOM -     \
156                                          MENU_SCREEN_INFO_YSTART2 -     \
157                                          TILEY / 2)
158 #define MAX_INFO_ELEMENTS_ON_SCREEN     128
159 #define STD_INFO_ELEMENTS_ON_SCREEN     (MENU_SCREEN_INFO_YSIZE /       \
160                                          MENU_SCREEN_INFO_YSTEP)
161 #define NUM_INFO_ELEMENTS_FROM_CONF     \
162   (menu.list_size_info[GFX_SPECIAL_ARG_INFO_ELEMENTS] > 0 ?             \
163    menu.list_size_info[GFX_SPECIAL_ARG_INFO_ELEMENTS] :                 \
164    MAX_MENU_ENTRIES_ON_SCREEN)
165 #define NUM_INFO_ELEMENTS_ON_SCREEN     MIN(MIN(STD_INFO_ELEMENTS_ON_SCREEN, \
166                                                 MAX_INFO_ELEMENTS_ON_SCREEN), \
167                                             NUM_INFO_ELEMENTS_FROM_CONF)
168 #define MAX_MENU_ENTRIES_ON_SCREEN      (SCR_FIELDY - MENU_SCREEN_START_YPOS)
169 #define MAX_MENU_TEXT_LENGTH_BIG        13
170 #define MAX_MENU_TEXT_LENGTH_MEDIUM     (MAX_MENU_TEXT_LENGTH_BIG * 2)
171
172 /* buttons and scrollbars identifiers */
173 #define SCREEN_CTRL_ID_PREV_LEVEL       0
174 #define SCREEN_CTRL_ID_NEXT_LEVEL       1
175 #define SCREEN_CTRL_ID_PREV_PLAYER      2
176 #define SCREEN_CTRL_ID_NEXT_PLAYER      3
177 #define SCREEN_CTRL_ID_INSERT_SOLUTION  4
178 #define SCREEN_CTRL_ID_PLAY_SOLUTION    5
179 #define SCREEN_CTRL_ID_SCROLL_UP        6
180 #define SCREEN_CTRL_ID_SCROLL_DOWN      7
181 #define SCREEN_CTRL_ID_SCROLL_VERTICAL  8
182
183 #define NUM_SCREEN_GADGETS              9
184
185 #define NUM_SCREEN_MENUBUTTONS          6
186 #define NUM_SCREEN_SCROLLBUTTONS        2
187 #define NUM_SCREEN_SCROLLBARS           1
188
189 #define SCREEN_MASK_MAIN                (1 << 0)
190 #define SCREEN_MASK_MAIN_HAS_SOLUTION   (1 << 1)
191 #define SCREEN_MASK_INPUT               (1 << 2)
192
193 /* graphic position and size values for buttons and scrollbars */
194 #define SC_MENUBUTTON_XSIZE             TILEX
195 #define SC_MENUBUTTON_YSIZE             TILEY
196
197 #define SC_SCROLLBUTTON_XSIZE           TILEX
198 #define SC_SCROLLBUTTON_YSIZE           TILEY
199
200 #define SC_SCROLLBAR_XPOS               (SXSIZE - SC_SCROLLBUTTON_XSIZE)
201
202 #define SC_SCROLL_VERTICAL_XSIZE        SC_SCROLLBUTTON_XSIZE
203 #define SC_SCROLL_VERTICAL_YSIZE        ((MAX_MENU_ENTRIES_ON_SCREEN - 2) * \
204                                          SC_SCROLLBUTTON_YSIZE)
205
206 #define SC_SCROLL_UP_XPOS               SC_SCROLLBAR_XPOS
207 #define SC_SCROLL_UP_YPOS               (2 * SC_SCROLLBUTTON_YSIZE)
208
209 #define SC_SCROLL_VERTICAL_XPOS         SC_SCROLLBAR_XPOS
210 #define SC_SCROLL_VERTICAL_YPOS         (SC_SCROLL_UP_YPOS + \
211                                          SC_SCROLLBUTTON_YSIZE)
212
213 #define SC_SCROLL_DOWN_XPOS             SC_SCROLLBAR_XPOS
214 #define SC_SCROLL_DOWN_YPOS             (SC_SCROLL_VERTICAL_YPOS + \
215                                          SC_SCROLL_VERTICAL_YSIZE)
216
217 #define SC_BORDER_SIZE                  14
218
219
220 /* forward declarations of internal functions */
221 static void HandleScreenGadgets(struct GadgetInfo *);
222 static void HandleSetupScreen_Generic(int, int, int, int, int);
223 static void HandleSetupScreen_Input(int, int, int, int, int);
224 static void CustomizeKeyboard(int);
225 static void ConfigureJoystick(int);
226 static void ConfigureVirtualButtons(void);
227 static void execSetupGame(void);
228 static void execSetupGraphics(void);
229 static void execSetupSound(void);
230 static void execSetupTouch(void);
231 static void execSetupArtwork(void);
232 static void HandleChooseTree(int, int, int, int, int, TreeInfo **);
233
234 static void DrawChooseLevelSet(void);
235 static void DrawChooseLevelNr(void);
236 static void DrawInfoScreen(void);
237 static void DrawSetupScreen(void);
238
239 static void DrawInfoScreen_NotAvailable(char *, char *);
240 static void DrawInfoScreen_HelpAnim(int, int, boolean);
241 static void DrawInfoScreen_HelpText(int, int, int, int);
242 static void HandleInfoScreen_Main(int, int, int, int, int);
243 static void HandleInfoScreen_TitleScreen(int);
244 static void HandleInfoScreen_Elements(int);
245 static void HandleInfoScreen_Music(int);
246 static void HandleInfoScreen_Credits(int);
247 static void HandleInfoScreen_Program(int);
248 static void HandleInfoScreen_Version(int);
249
250 static void MapScreenMenuGadgets(int);
251 static void MapScreenGadgets(int);
252 static void MapScreenTreeGadgets(TreeInfo *);
253
254 static void UpdateScreenMenuGadgets(int, boolean);
255
256 static struct GadgetInfo *screen_gadget[NUM_SCREEN_GADGETS];
257
258 static int info_mode = INFO_MODE_MAIN;
259 static int setup_mode = SETUP_MODE_MAIN;
260
261 static TreeInfo *window_sizes = NULL;
262 static TreeInfo *window_size_current = NULL;
263
264 static TreeInfo *scaling_types = NULL;
265 static TreeInfo *scaling_type_current = NULL;
266
267 static TreeInfo *rendering_modes = NULL;
268 static TreeInfo *rendering_mode_current = NULL;
269
270 static TreeInfo *vsync_modes = NULL;
271 static TreeInfo *vsync_mode_current = NULL;
272
273 static TreeInfo *scroll_delays = NULL;
274 static TreeInfo *scroll_delay_current = NULL;
275
276 static TreeInfo *snapshot_modes = NULL;
277 static TreeInfo *snapshot_mode_current = NULL;
278
279 static TreeInfo *game_speeds = NULL;
280 static TreeInfo *game_speed_current = NULL;
281
282 static TreeInfo *volumes_simple = NULL;
283 static TreeInfo *volume_simple_current = NULL;
284
285 static TreeInfo *volumes_loops = NULL;
286 static TreeInfo *volume_loops_current = NULL;
287
288 static TreeInfo *volumes_music = NULL;
289 static TreeInfo *volume_music_current = NULL;
290
291 static TreeInfo *touch_controls = NULL;
292 static TreeInfo *touch_control_current = NULL;
293
294 static TreeInfo *move_distances = NULL;
295 static TreeInfo *move_distance_current = NULL;
296
297 static TreeInfo *drop_distances = NULL;
298 static TreeInfo *drop_distance_current = NULL;
299
300 static TreeInfo *transparencies = NULL;
301 static TreeInfo *transparency_current = NULL;
302
303 static TreeInfo *grid_sizes[2][2] = { { NULL, NULL }, { NULL, NULL } };
304 static TreeInfo *grid_size_current[2][2] = { { NULL, NULL }, { NULL, NULL } };
305
306 static TreeInfo *level_number = NULL;
307 static TreeInfo *level_number_current = NULL;
308
309 static struct
310 {
311   int value;
312   char *text;
313 } window_sizes_list[] =
314 {
315   {     50,     "50 %"                          },
316   {     80,     "80 %"                          },
317   {     90,     "90 %"                          },
318   {     100,    "100 % (Default)"               },
319   {     110,    "110 %"                         },
320   {     120,    "120 %"                         },
321   {     130,    "130 %"                         },
322   {     140,    "140 %"                         },
323   {     150,    "150 %"                         },
324   {     200,    "200 %"                         },
325   {     250,    "250 %"                         },
326   {     300,    "300 %"                         },
327
328   {     -1,     NULL                            },
329 };
330
331 static struct
332 {
333   char *value;
334   char *text;
335 } scaling_types_list[] =
336 {
337   {     SCALING_QUALITY_NEAREST, "Off"          },
338   {     SCALING_QUALITY_LINEAR,  "Linear"       },
339   {     SCALING_QUALITY_BEST,    "Anisotropic"  },
340
341   {     NULL,                    NULL           },
342 };
343
344 static struct
345 {
346   char *value;
347   char *text;
348 } rendering_modes_list[] =
349 {
350   {     STR_SPECIAL_RENDERING_OFF,      "Off (May show artifacts, fast)" },
351   {     STR_SPECIAL_RENDERING_BITMAP,   "Bitmap/Texture mode (slower)"   },
352 #if DEBUG
353   // this mode may work under certain conditions, but does not work on Windows
354   {     STR_SPECIAL_RENDERING_TARGET,   "Target Texture mode (slower)"   },
355 #endif
356   {     STR_SPECIAL_RENDERING_DOUBLE,   "Double Texture mode (slower)"   },
357
358   {     NULL,                            NULL                            },
359 };
360
361 static struct
362 {
363   char *value;
364   char *text;
365 } vsync_modes_list[] =
366 {
367   {     STR_VSYNC_MODE_OFF,             "Off"           },
368   {     STR_VSYNC_MODE_NORMAL,          "Normal"        },
369   {     STR_VSYNC_MODE_ADAPTIVE,        "Adaptive"      },
370
371   {     NULL,                            NULL           },
372 };
373
374 static struct
375 {
376   int value;
377   char *text;
378 } game_speeds_list[] =
379 {
380 #if 1
381   {     30,     "Very Slow"                     },
382   {     25,     "Slow"                          },
383   {     20,     "Normal"                        },
384   {     15,     "Fast"                          },
385   {     10,     "Very Fast"                     },
386 #else
387   {     1000,   "1/1s (Extremely Slow)"         },
388   {     500,    "1/2s"                          },
389   {     200,    "1/5s"                          },
390   {     100,    "1/10s"                         },
391   {     50,     "1/20s"                         },
392   {     29,     "1/35s (Original Supaplex)"     },
393   {     25,     "1/40s"                         },
394   {     20,     "1/50s (Normal Speed)"          },
395   {     14,     "1/70s (Maximum Supaplex)"      },
396   {     10,     "1/100s"                        },
397   {     5,      "1/200s"                        },
398   {     2,      "1/500s"                        },
399   {     1,      "1/1000s (Extremely Fast)"      },
400 #endif
401
402   {     -1,     NULL                            },
403 };
404
405 static struct
406 {
407   int value;
408   char *text;
409 } scroll_delays_list[] =
410 {
411   {     0,      "0 Tiles (No Scroll Delay)"     },
412   {     1,      "1 Tile"                        },
413   {     2,      "2 Tiles"                       },
414   {     3,      "3 Tiles (Default)"             },
415   {     4,      "4 Tiles"                       },
416   {     5,      "5 Tiles"                       },
417   {     6,      "6 Tiles"                       },
418   {     7,      "7 Tiles"                       },
419   {     8,      "8 Tiles (Maximum Scroll Delay)"},
420
421   {     -1,     NULL                            },
422 };
423
424 static struct
425 {
426   char *value;
427   char *text;
428 } snapshot_modes_list[] =
429 {
430   {     STR_SNAPSHOT_MODE_OFF,                  "Off"           },
431   {     STR_SNAPSHOT_MODE_EVERY_STEP,           "Every Step"    },
432   {     STR_SNAPSHOT_MODE_EVERY_MOVE,           "Every Move"    },
433   {     STR_SNAPSHOT_MODE_EVERY_COLLECT,        "Every Collect" },
434
435   {     NULL,                                   NULL            },
436 };
437
438 static struct
439 {
440   int value;
441   char *text;
442 } volumes_list[] =
443 {
444   {     0,      "0 %"                           },
445   {     1,      "1 %"                           },
446   {     2,      "2 %"                           },
447   {     5,      "5 %"                           },
448   {     10,     "10 %"                          },
449   {     20,     "20 %"                          },
450   {     30,     "30 %"                          },
451   {     40,     "40 %"                          },
452   {     50,     "50 %"                          },
453   {     60,     "60 %"                          },
454   {     70,     "70 %"                          },
455   {     80,     "80 %"                          },
456   {     90,     "90 %"                          },
457   {     100,    "100 %"                         },
458
459   {     -1,     NULL                            },
460 };
461
462 static struct
463 {
464   char *value;
465   char *text;
466 } touch_controls_list[] =
467 {
468   {     TOUCH_CONTROL_OFF,              "Off"                   },
469   {     TOUCH_CONTROL_VIRTUAL_BUTTONS,  "Virtual Buttons"       },
470   {     TOUCH_CONTROL_WIPE_GESTURES,    "Wipe Gestures"         },
471   {     TOUCH_CONTROL_FOLLOW_FINGER,    "Follow Finger"         },
472
473   {     NULL,                           NULL                    },
474 };
475
476 static struct
477 {
478   int value;
479   char *text;
480 } distances_list[] =
481 {
482   {     1,      "1 %"                           },
483   {     2,      "2 %"                           },
484   {     3,      "3 %"                           },
485   {     4,      "4 %"                           },
486   {     5,      "5 %"                           },
487   {     10,     "10 %"                          },
488   {     15,     "15 %"                          },
489   {     20,     "20 %"                          },
490   {     25,     "25 %"                          },
491
492   {     -1,     NULL                            },
493 };
494
495 static struct
496 {
497   int value;
498   char *text;
499 } transparencies_list[] =
500 {
501   {     0,      "0 % (Opaque)"                  },
502   {     10,     "10 %"                          },
503   {     20,     "20 %"                          },
504   {     30,     "30 %"                          },
505   {     40,     "40 %"                          },
506   {     50,     "50 %"                          },
507   {     60,     "60 %"                          },
508   {     70,     "70 %"                          },
509   {     80,     "80 %"                          },
510   {     90,     "90 %"                          },
511   {     100,    "100 % (Invisible)"             },
512
513   {     -1,     NULL                            },
514 };
515
516 static struct
517 {
518   int value;
519   char *text;
520 } grid_sizes_list[] =
521 {
522   {     3,      "3"                             },
523   {     4,      "4"                             },
524   {     5,      "5"                             },
525   {     6,      "6"                             },
526   {     7,      "7"                             },
527   {     8,      "8"                             },
528   {     9,      "9"                             },
529   {     10,     "10"                            },
530   {     11,     "11"                            },
531   {     12,     "12"                            },
532   {     13,     "13"                            },
533   {     14,     "14"                            },
534   {     15,     "15"                            },
535   {     16,     "16"                            },
536   {     17,     "17"                            },
537   {     18,     "18"                            },
538   {     19,     "19"                            },
539   {     20,     "20"                            },
540   {     21,     "21"                            },
541   {     22,     "22"                            },
542   {     23,     "23"                            },
543   {     24,     "24"                            },
544   {     25,     "25"                            },
545   {     26,     "26"                            },
546   {     27,     "27"                            },
547   {     28,     "28"                            },
548   {     29,     "29"                            },
549   {     30,     "30"                            },
550   {     31,     "31"                            },
551   {     32,     "32"                            },
552
553   {     -1,     NULL                            },
554 };
555
556 #define DRAW_MODE(s)            ((s) >= GAME_MODE_MAIN &&               \
557                                  (s) <= GAME_MODE_SETUP ? (s) :         \
558                                  (s) == GAME_MODE_PSEUDO_TYPENAME ?     \
559                                  GAME_MODE_MAIN : GAME_MODE_DEFAULT)
560
561 /* (there are no draw offset definitions needed for INFO_MODE_TITLE) */
562 #define DRAW_MODE_INFO(i)       ((i) >= INFO_MODE_TITLE &&              \
563                                  (i) <= INFO_MODE_LEVELSET ? (i) :      \
564                                  INFO_MODE_MAIN)
565
566 #define DRAW_MODE_SETUP(i)      ((i) >= SETUP_MODE_MAIN &&              \
567                                  (i) <= SETUP_MODE_SHORTCUTS_5 ? (i) :  \
568                                  (i) >= SETUP_MODE_CHOOSE_GRAPHICS &&   \
569                                  (i) <= SETUP_MODE_CHOOSE_MUSIC ?       \
570                                  SETUP_MODE_CHOOSE_ARTWORK :            \
571                                  SETUP_MODE_CHOOSE_OTHER)
572
573 #define DRAW_XOFFSET_INFO(i)    (DRAW_MODE_INFO(i) == INFO_MODE_MAIN ?  \
574                                  menu.draw_xoffset[GAME_MODE_INFO] :    \
575                                  menu.draw_xoffset_info[DRAW_MODE_INFO(i)])
576 #define DRAW_YOFFSET_INFO(i)    (DRAW_MODE_INFO(i) == INFO_MODE_MAIN ?  \
577                                  menu.draw_yoffset[GAME_MODE_INFO] :    \
578                                  menu.draw_yoffset_info[DRAW_MODE_INFO(i)])
579 #define EXTRA_SPACING_INFO(i)   (DRAW_MODE_INFO(i) == INFO_MODE_MAIN ? \
580                                  menu.extra_spacing[GAME_MODE_INFO] :   \
581                                  menu.extra_spacing_info[DRAW_MODE_INFO(i)])
582
583 #define DRAW_XOFFSET_SETUP(i)   (DRAW_MODE_SETUP(i) == SETUP_MODE_MAIN ? \
584                                  menu.draw_xoffset[GAME_MODE_SETUP] :   \
585                                  menu.draw_xoffset_setup[DRAW_MODE_SETUP(i)])
586 #define DRAW_YOFFSET_SETUP(i)   (DRAW_MODE_SETUP(i) == SETUP_MODE_MAIN ? \
587                                  menu.draw_yoffset[GAME_MODE_SETUP] :   \
588                                  menu.draw_yoffset_setup[DRAW_MODE_SETUP(i)])
589 #define EXTRA_SPACING_SETUP(i)  (DRAW_MODE_SETUP(i) == SETUP_MODE_MAIN ? \
590                                  menu.extra_spacing[GAME_MODE_SETUP] :  \
591                                  menu.extra_spacing_setup[DRAW_MODE_SETUP(i)])
592
593 #define DRAW_XOFFSET(s)         ((s) == GAME_MODE_INFO ?                \
594                                  DRAW_XOFFSET_INFO(info_mode) :         \
595                                  (s) == GAME_MODE_SETUP ?               \
596                                  DRAW_XOFFSET_SETUP(setup_mode) :       \
597                                  menu.draw_xoffset[DRAW_MODE(s)])
598 #define DRAW_YOFFSET(s)         ((s) == GAME_MODE_INFO ?                \
599                                  DRAW_YOFFSET_INFO(info_mode) :         \
600                                  (s) == GAME_MODE_SETUP ?               \
601                                  DRAW_YOFFSET_SETUP(setup_mode) :       \
602                                  menu.draw_yoffset[DRAW_MODE(s)])
603 #define EXTRA_SPACING(s)        ((s) == GAME_MODE_INFO ?                \
604                                  EXTRA_SPACING_INFO(info_mode) :        \
605                                  (s) == GAME_MODE_SETUP ?               \
606                                  EXTRA_SPACING_SETUP(setup_mode) :      \
607                                  menu.extra_spacing[DRAW_MODE(s)])
608
609 #define mSX                     (SX + DRAW_XOFFSET(game_status))
610 #define mSY                     (SY + DRAW_YOFFSET(game_status))
611
612 #define NUM_MENU_ENTRIES_ON_SCREEN (menu.list_size[game_status] > 2 ?   \
613                                     menu.list_size[game_status] :       \
614                                     MAX_MENU_ENTRIES_ON_SCREEN)
615
616 #define IN_VIS_MENU(x, y)       IN_FIELD(x, y, SCR_FIELDX,              \
617                                          NUM_MENU_ENTRIES_ON_SCREEN)
618
619
620 /* title display and control definitions */
621
622 #define MAX_NUM_TITLE_SCREENS   (2 * MAX_NUM_TITLE_IMAGES +             \
623                                  2 * MAX_NUM_TITLE_MESSAGES)
624
625 #define NO_DIRECT_LEVEL_SELECT  (-1)
626
627
628 static int num_title_screens = 0;
629
630 struct TitleControlInfo
631 {
632   boolean is_image;
633   boolean initial;
634   boolean first;
635   int local_nr;
636   int sort_priority;
637 };
638
639 struct TitleControlInfo title_controls[MAX_NUM_TITLE_SCREENS];
640
641 /* main menu display and control definitions */
642
643 #define MAIN_CONTROL_NAME                       0
644 #define MAIN_CONTROL_LEVELS                     1
645 #define MAIN_CONTROL_SCORES                     2
646 #define MAIN_CONTROL_EDITOR                     3
647 #define MAIN_CONTROL_INFO                       4
648 #define MAIN_CONTROL_GAME                       5
649 #define MAIN_CONTROL_SETUP                      6
650 #define MAIN_CONTROL_QUIT                       7
651 #define MAIN_CONTROL_PREV_LEVEL                 8
652 #define MAIN_CONTROL_NEXT_LEVEL                 9
653 #define MAIN_CONTROL_FIRST_LEVEL                10
654 #define MAIN_CONTROL_LAST_LEVEL                 11
655 #define MAIN_CONTROL_LEVEL_NUMBER               12
656 #define MAIN_CONTROL_LEVEL_INFO_1               13
657 #define MAIN_CONTROL_LEVEL_INFO_2               14
658 #define MAIN_CONTROL_LEVEL_NAME                 15
659 #define MAIN_CONTROL_LEVEL_AUTHOR               16
660 #define MAIN_CONTROL_LEVEL_YEAR                 17
661 #define MAIN_CONTROL_LEVEL_IMPORTED_FROM        18
662 #define MAIN_CONTROL_LEVEL_IMPORTED_BY          19
663 #define MAIN_CONTROL_LEVEL_TESTED_BY            20
664 #define MAIN_CONTROL_TITLE_1                    21
665 #define MAIN_CONTROL_TITLE_2                    22
666 #define MAIN_CONTROL_TITLE_3                    23
667
668 static char str_main_text_name[10];
669 static char str_main_text_first_level[10];
670 static char str_main_text_last_level[10];
671 static char str_main_text_level_number[10];
672
673 static char *main_text_name                     = str_main_text_name;
674 static char *main_text_first_level              = str_main_text_first_level;
675 static char *main_text_last_level               = str_main_text_last_level;
676 static char *main_text_level_number             = str_main_text_level_number;
677 static char *main_text_levels                   = "Levelset";
678 static char *main_text_scores                   = "Hall Of Fame";
679 static char *main_text_editor                   = "Level Creator";
680 static char *main_text_info                     = "Info Screen";
681 static char *main_text_game                     = "Start Game";
682 static char *main_text_setup                    = "Setup";
683 static char *main_text_quit                     = "Quit";
684 static char *main_text_level_name               = level.name;
685 static char *main_text_level_author             = level.author;
686 static char *main_text_level_year               = NULL;
687 static char *main_text_level_imported_from      = NULL;
688 static char *main_text_level_imported_by        = NULL;
689 static char *main_text_level_tested_by          = NULL;
690 static char *main_text_title_1                  = NULL;
691 static char *main_text_title_2                  = NULL;
692 static char *main_text_title_3                  = NULL;
693
694 struct MainControlInfo
695 {
696   int nr;
697
698   struct MenuPosInfo *pos_button;
699   int button_graphic;
700
701   struct TextPosInfo *pos_text;
702   char **text;
703
704   struct TextPosInfo *pos_input;
705   char **input;
706 };
707
708 static struct MainControlInfo main_controls[] =
709 {
710   {
711     MAIN_CONTROL_NAME,
712     &menu.main.button.name,             IMG_MENU_BUTTON_NAME,
713     &menu.main.text.name,               &main_text_name,
714     &menu.main.input.name,              &setup.player_name,
715   },
716   {
717     MAIN_CONTROL_LEVELS,
718     &menu.main.button.levels,           IMG_MENU_BUTTON_LEVELS,
719     &menu.main.text.levels,             &main_text_levels,
720     NULL,                               NULL,
721   },
722   {
723     MAIN_CONTROL_SCORES,
724     &menu.main.button.scores,           IMG_MENU_BUTTON_SCORES,
725     &menu.main.text.scores,             &main_text_scores,
726     NULL,                               NULL,
727   },
728   {
729     MAIN_CONTROL_EDITOR,
730     &menu.main.button.editor,           IMG_MENU_BUTTON_EDITOR,
731     &menu.main.text.editor,             &main_text_editor,
732     NULL,                               NULL,
733   },
734   {
735     MAIN_CONTROL_INFO,
736     &menu.main.button.info,             IMG_MENU_BUTTON_INFO,
737     &menu.main.text.info,               &main_text_info,
738     NULL,                               NULL,
739   },
740   {
741     MAIN_CONTROL_GAME,
742     &menu.main.button.game,             IMG_MENU_BUTTON_GAME,
743     &menu.main.text.game,               &main_text_game,
744     NULL,                               NULL,
745   },
746   {
747     MAIN_CONTROL_SETUP,
748     &menu.main.button.setup,            IMG_MENU_BUTTON_SETUP,
749     &menu.main.text.setup,              &main_text_setup,
750     NULL,                               NULL,
751   },
752   {
753     MAIN_CONTROL_QUIT,
754     &menu.main.button.quit,             IMG_MENU_BUTTON_QUIT,
755     &menu.main.text.quit,               &main_text_quit,
756     NULL,                               NULL,
757   },
758 #if 0
759   /* (these two buttons are real gadgets) */
760   {
761     MAIN_CONTROL_PREV_LEVEL,
762     &menu.main.button.prev_level,       IMG_MENU_BUTTON_PREV_LEVEL,
763     NULL,                               NULL,
764     NULL,                               NULL,
765   },
766   {
767     MAIN_CONTROL_NEXT_LEVEL,
768     &menu.main.button.next_level,       IMG_MENU_BUTTON_NEXT_LEVEL,
769     NULL,                               NULL,
770     NULL,                               NULL,
771   },
772 #endif
773   {
774     MAIN_CONTROL_FIRST_LEVEL,
775     &menu.main.button.first_level,      IMG_MENU_BUTTON_FIRST_LEVEL,
776     &menu.main.text.first_level,        &main_text_first_level,
777     NULL,                               NULL,
778   },
779   {
780     MAIN_CONTROL_LAST_LEVEL,
781     &menu.main.button.last_level,       IMG_MENU_BUTTON_LAST_LEVEL,
782     &menu.main.text.last_level,         &main_text_last_level,
783     NULL,                               NULL,
784   },
785   {
786     MAIN_CONTROL_LEVEL_NUMBER,
787     &menu.main.button.level_number,     IMG_MENU_BUTTON_LEVEL_NUMBER,
788     &menu.main.text.level_number,       &main_text_level_number,
789     NULL,                               NULL,
790   },
791   {
792     MAIN_CONTROL_LEVEL_INFO_1,
793     NULL,                               -1,
794     &menu.main.text.level_info_1,       NULL,
795     NULL,                               NULL,
796   },
797   {
798     MAIN_CONTROL_LEVEL_INFO_2,
799     NULL,                               -1,
800     &menu.main.text.level_info_2,       NULL,
801     NULL,                               NULL,
802   },
803   {
804     MAIN_CONTROL_LEVEL_NAME,
805     NULL,                               -1,
806     &menu.main.text.level_name,         &main_text_level_name,
807     NULL,                               NULL,
808   },
809   {
810     MAIN_CONTROL_LEVEL_AUTHOR,
811     NULL,                               -1,
812     &menu.main.text.level_author,       &main_text_level_author,
813     NULL,                               NULL,
814   },
815   {
816     MAIN_CONTROL_LEVEL_YEAR,
817     NULL,                               -1,
818     &menu.main.text.level_year,         &main_text_level_year,
819     NULL,                               NULL,
820   },
821   {
822     MAIN_CONTROL_LEVEL_IMPORTED_FROM,
823     NULL,                               -1,
824     &menu.main.text.level_imported_from, &main_text_level_imported_from,
825     NULL,                               NULL,
826   },
827   {
828     MAIN_CONTROL_LEVEL_IMPORTED_BY,
829     NULL,                               -1,
830     &menu.main.text.level_imported_by,  &main_text_level_imported_by,
831     NULL,                               NULL,
832   },
833   {
834     MAIN_CONTROL_LEVEL_TESTED_BY,
835     NULL,                               -1,
836     &menu.main.text.level_tested_by,    &main_text_level_tested_by,
837     NULL,                               NULL,
838   },
839   {
840     MAIN_CONTROL_TITLE_1,
841     NULL,                               -1,
842     &menu.main.text.title_1,            &main_text_title_1,
843     NULL,                               NULL,
844   },
845   {
846     MAIN_CONTROL_TITLE_2,
847     NULL,                               -1,
848     &menu.main.text.title_2,            &main_text_title_2,
849     NULL,                               NULL,
850   },
851   {
852     MAIN_CONTROL_TITLE_3,
853     NULL,                               -1,
854     &menu.main.text.title_3,            &main_text_title_3,
855     NULL,                               NULL,
856   },
857
858   {
859     -1,
860     NULL,                               -1,
861     NULL,                               NULL,
862     NULL,                               NULL,
863   }
864 };
865
866
867 static int getTitleScreenGraphic(int nr, boolean initial)
868 {
869   return (initial ? IMG_TITLESCREEN_INITIAL_1 : IMG_TITLESCREEN_1) + nr;
870 }
871
872 static struct TitleMessageInfo *getTitleMessageInfo(int nr, boolean initial)
873 {
874   return (initial ? &titlemessage_initial[nr] : &titlemessage[nr]);
875 }
876
877 #if 0
878 static int getTitleScreenGameMode(boolean initial)
879 {
880   return (initial ? GAME_MODE_TITLE_INITIAL : GAME_MODE_TITLE);
881 }
882 #endif
883
884 static int getTitleMessageGameMode(boolean initial)
885 {
886   return (initial ? GAME_MODE_TITLE_INITIAL : GAME_MODE_TITLE);
887 }
888
889 static int getTitleAnimMode(struct TitleControlInfo *tci)
890 {
891   int base = (tci->initial ? GAME_MODE_TITLE_INITIAL_1 : GAME_MODE_TITLE_1);
892
893   return base + tci->local_nr;
894 }
895
896 #if 0
897 static int getTitleScreenBackground(boolean initial)
898 {
899   return (initial ? IMG_BACKGROUND_TITLE_INITIAL : IMG_BACKGROUND_TITLE);
900 }
901 #endif
902
903 #if 0
904 static int getTitleMessageBackground(int nr, boolean initial)
905 {
906   return (initial ? IMG_BACKGROUND_TITLE_INITIAL : IMG_BACKGROUND_TITLE);
907 }
908 #endif
909
910 static int getTitleBackground(int nr, boolean initial, boolean is_image)
911 {
912   int base = (is_image ?
913               (initial ? IMG_BACKGROUND_TITLESCREEN_INITIAL_1 :
914                          IMG_BACKGROUND_TITLESCREEN_1) :
915               (initial ? IMG_BACKGROUND_TITLEMESSAGE_INITIAL_1 :
916                          IMG_BACKGROUND_TITLEMESSAGE_1));
917   int graphic_global = (initial ? IMG_BACKGROUND_TITLE_INITIAL :
918                                   IMG_BACKGROUND_TITLE);
919   int graphic_local = base + nr;
920
921   if (graphic_info[graphic_local].bitmap != NULL)
922     return graphic_local;
923
924   if (graphic_info[graphic_global].bitmap != NULL)
925     return graphic_global;
926
927   return IMG_UNDEFINED;
928 }
929
930 static int getTitleSound(struct TitleControlInfo *tci)
931 {
932   boolean is_image = tci->is_image;
933   int initial = tci->initial;
934   int nr = tci->local_nr;
935   int mode = (initial ? GAME_MODE_TITLE_INITIAL : GAME_MODE_TITLE);
936   int base = (is_image ?
937               (initial ? SND_BACKGROUND_TITLESCREEN_INITIAL_1 :
938                          SND_BACKGROUND_TITLESCREEN_1) :
939               (initial ? SND_BACKGROUND_TITLEMESSAGE_INITIAL_1 :
940                          SND_BACKGROUND_TITLEMESSAGE_1));
941   int sound_global = menu.sound[mode];
942   int sound_local = base + nr;
943
944 #if 0
945   printf("::: %d, %d, %d: %d ['%s'], %d ['%s']\n",
946          nr, initial, is_image,
947          sound_global, getSoundListEntry(sound_global)->filename,
948          sound_local, getSoundListEntry(sound_local)->filename);
949 #endif
950
951   if (!strEqual(getSoundListEntry(sound_local)->filename, UNDEFINED_FILENAME))
952     return sound_local;
953
954   if (!strEqual(getSoundListEntry(sound_global)->filename, UNDEFINED_FILENAME))
955     return sound_global;
956
957   return SND_UNDEFINED;
958 }
959
960 static int getTitleMusic(struct TitleControlInfo *tci)
961 {
962   boolean is_image = tci->is_image;
963   int initial = tci->initial;
964   int nr = tci->local_nr;
965   int mode = (initial ? GAME_MODE_TITLE_INITIAL : GAME_MODE_TITLE);
966   int base = (is_image ?
967               (initial ? MUS_BACKGROUND_TITLESCREEN_INITIAL_1 :
968                          MUS_BACKGROUND_TITLESCREEN_1) :
969               (initial ? MUS_BACKGROUND_TITLEMESSAGE_INITIAL_1 :
970                          MUS_BACKGROUND_TITLEMESSAGE_1));
971   int music_global = menu.music[mode];
972   int music_local = base + nr;
973
974 #if 0
975   printf("::: %d, %d, %d: %d ['%s'], %d ['%s']\n",
976          nr, initial, is_image,
977          music_global, getMusicListEntry(music_global)->filename,
978          music_local, getMusicListEntry(music_local)->filename);
979 #endif
980
981   if (!strEqual(getMusicListEntry(music_local)->filename, UNDEFINED_FILENAME))
982     return music_local;
983
984   if (!strEqual(getMusicListEntry(music_global)->filename, UNDEFINED_FILENAME))
985     return music_global;
986
987   return MUS_UNDEFINED;
988 }
989
990 static struct TitleFadingInfo getTitleFading(struct TitleControlInfo *tci)
991 {
992   boolean is_image = tci->is_image;
993   boolean initial = tci->initial;
994   boolean first = tci->first;
995   int nr = tci->local_nr;
996   struct TitleMessageInfo tmi;
997   struct TitleFadingInfo ti;
998
999   tmi = (is_image ? (initial ? (first ?
1000                                 titlescreen_initial_first[nr] :
1001                                 titlescreen_initial[nr])
1002                              : (first ?
1003                                 titlescreen_first[nr] :
1004                                 titlescreen[nr]))
1005                   : (initial ? (first ?
1006                                 titlemessage_initial_first[nr] :
1007                                 titlemessage_initial[nr])
1008                              : (first ?
1009                                 titlemessage_first[nr] :
1010                                 titlemessage[nr])));
1011
1012   ti.fade_mode  = tmi.fade_mode;
1013   ti.fade_delay = tmi.fade_delay;
1014   ti.post_delay = tmi.post_delay;
1015   ti.auto_delay = tmi.auto_delay;
1016
1017   return ti;
1018 }
1019
1020 static int compareTitleControlInfo(const void *object1, const void *object2)
1021 {
1022   const struct TitleControlInfo *tci1 = (struct TitleControlInfo *)object1;
1023   const struct TitleControlInfo *tci2 = (struct TitleControlInfo *)object2;
1024   int compare_result;
1025
1026   if (tci1->initial != tci2->initial)
1027     compare_result = (tci1->initial ? -1 : +1);
1028   else if (tci1->sort_priority != tci2->sort_priority)
1029     compare_result = tci1->sort_priority - tci2->sort_priority;
1030   else if (tci1->is_image != tci2->is_image)
1031     compare_result = (tci1->is_image ? -1 : +1);
1032   else
1033     compare_result = tci1->local_nr - tci2->local_nr;
1034
1035   return compare_result;
1036 }
1037
1038 static void InitializeTitleControlsExt_AddTitleInfo(boolean is_image,
1039                                                     boolean initial,
1040                                                     int nr, int sort_priority)
1041 {
1042   title_controls[num_title_screens].is_image = is_image;
1043   title_controls[num_title_screens].initial = initial;
1044   title_controls[num_title_screens].local_nr = nr;
1045   title_controls[num_title_screens].sort_priority = sort_priority;
1046
1047   title_controls[num_title_screens].first = FALSE;      /* will be set later */
1048
1049   num_title_screens++;
1050 }
1051
1052 static void InitializeTitleControls_CheckTitleInfo(boolean initial)
1053 {
1054   int i;
1055
1056   for (i = 0; i < MAX_NUM_TITLE_IMAGES; i++)
1057   {
1058     int graphic = getTitleScreenGraphic(i, initial);
1059     Bitmap *bitmap = graphic_info[graphic].bitmap;
1060     int sort_priority = graphic_info[graphic].sort_priority;
1061
1062     if (bitmap != NULL)
1063       InitializeTitleControlsExt_AddTitleInfo(TRUE, initial, i, sort_priority);
1064   }
1065
1066   for (i = 0; i < MAX_NUM_TITLE_MESSAGES; i++)
1067   {
1068     struct TitleMessageInfo *tmi = getTitleMessageInfo(i, initial);
1069     char *filename = getLevelSetTitleMessageFilename(i, initial);
1070     int sort_priority = tmi->sort_priority;
1071
1072     if (filename != NULL)
1073       InitializeTitleControlsExt_AddTitleInfo(FALSE, initial, i, sort_priority);
1074   }
1075 }
1076
1077 static void InitializeTitleControls(boolean show_title_initial)
1078 {
1079   num_title_screens = 0;
1080
1081   /* 1st step: initialize title screens for game start (only when starting) */
1082   if (show_title_initial)
1083     InitializeTitleControls_CheckTitleInfo(TRUE);
1084
1085   /* 2nd step: initialize title screens for current level set */
1086   InitializeTitleControls_CheckTitleInfo(FALSE);
1087
1088   /* sort title screens according to sort_priority and title number */
1089   qsort(title_controls, num_title_screens, sizeof(struct TitleControlInfo),
1090         compareTitleControlInfo);
1091
1092   /* mark first title screen */
1093   title_controls[0].first = TRUE;
1094 }
1095
1096 static boolean visibleMenuPos(struct MenuPosInfo *pos)
1097 {
1098   return (pos != NULL && pos->x != -1 && pos->y != -1);
1099 }
1100
1101 static boolean visibleTextPos(struct TextPosInfo *pos)
1102 {
1103   return (pos != NULL && pos->x != -1 && pos->y != -1);
1104 }
1105
1106 static void InitializeMainControls(void)
1107 {
1108   boolean local_team_mode = (!network.enabled && setup.team_mode);
1109   int i;
1110
1111   /* set main control text values to dynamically determined values */
1112   sprintf(main_text_name,         "%s",   local_team_mode ? "Team:" : "Name:");
1113
1114   strcpy(main_text_first_level,  int2str(leveldir_current->first_level,
1115                                          menu.main.text.first_level.size));
1116   strcpy(main_text_last_level,   int2str(leveldir_current->last_level,
1117                                          menu.main.text.last_level.size));
1118   strcpy(main_text_level_number, int2str(level_nr,
1119                                          menu.main.text.level_number.size));
1120
1121   main_text_level_year          = leveldir_current->year;
1122   main_text_level_imported_from = leveldir_current->imported_from;
1123   main_text_level_imported_by   = leveldir_current->imported_by;
1124   main_text_level_tested_by     = leveldir_current->tested_by;
1125
1126   main_text_title_1 = getConfigProgramTitleString();
1127   main_text_title_2 = getConfigProgramCopyrightString();
1128   main_text_title_3 = getConfigProgramCompanyString();
1129
1130   /* set main control screen positions to dynamically determined values */
1131   for (i = 0; main_controls[i].nr != -1; i++)
1132   {
1133     struct MainControlInfo *mci = &main_controls[i];
1134     int nr                         = mci->nr;
1135     struct MenuPosInfo *pos_button = mci->pos_button;
1136     struct TextPosInfo *pos_text   = mci->pos_text;
1137     struct TextPosInfo *pos_input  = mci->pos_input;
1138     char *text                     = (mci->text  ? *mci->text  : NULL);
1139     char *input                    = (mci->input ? *mci->input : NULL);
1140     int button_graphic             = mci->button_graphic;
1141     int font_text                  = (pos_text  ? pos_text->font  : -1);
1142     int font_input                 = (pos_input ? pos_input->font : -1);
1143
1144     int font_text_width   = (font_text  != -1 ? getFontWidth(font_text)   : 0);
1145     int font_text_height  = (font_text  != -1 ? getFontHeight(font_text)  : 0);
1146     int font_input_width  = (font_input != -1 ? getFontWidth(font_input)  : 0);
1147     int font_input_height = (font_input != -1 ? getFontHeight(font_input) : 0);
1148     int text_chars  = (text  != NULL ? strlen(text)  : 0);
1149     int input_chars = (input != NULL ? strlen(input) : 0);
1150
1151     int button_width =
1152       (button_graphic != -1 ? graphic_info[button_graphic].width  : 0);
1153     int button_height =
1154       (button_graphic != -1 ? graphic_info[button_graphic].height : 0);
1155     int text_width   = font_text_width * text_chars;
1156     int text_height  = font_text_height;
1157     int input_width  = font_input_width * input_chars;
1158     int input_height = font_input_height;
1159
1160     if (nr == MAIN_CONTROL_NAME)
1161     {
1162       menu.main.input.name.width  = input_width;
1163       menu.main.input.name.height = input_height;
1164     }
1165
1166     if (pos_button != NULL)             /* (x/y may be -1/-1 here) */
1167     {
1168       pos_button->width  = button_width;
1169       pos_button->height = button_height;
1170     }
1171
1172     if (pos_text != NULL)               /* (x/y may be -1/-1 here) */
1173     {
1174       /* calculate text size -- needed for text alignment */
1175       boolean calculate_text_size = (text != NULL);
1176
1177       if (pos_text->width == -1 || calculate_text_size)
1178         pos_text->width = text_width;
1179       if (pos_text->height == -1 || calculate_text_size)
1180         pos_text->height = text_height;
1181
1182       if (visibleMenuPos(pos_button))
1183       {
1184         if (pos_text->x == -1)
1185           pos_text->x = pos_button->x + pos_button->width;
1186         if (pos_text->y == -1)
1187           pos_text->y =
1188             pos_button->y + (pos_button->height - pos_text->height) / 2;
1189       }
1190     }
1191
1192     if (pos_input != NULL)              /* (x/y may be -1/-1 here) */
1193     {
1194       if (visibleTextPos(pos_text))
1195       {
1196         if (pos_input->x == -1)
1197           pos_input->x = pos_text->x + pos_text->width;
1198         if (pos_input->y == -1)
1199           pos_input->y = pos_text->y;
1200       }
1201
1202       if (pos_input->width == -1)
1203         pos_input->width = input_width;
1204       if (pos_input->height == -1)
1205         pos_input->height = input_height;
1206     }
1207   }
1208 }
1209
1210 static void DrawPressedGraphicThruMask(int dst_x, int dst_y,
1211                                        int graphic, boolean pressed)
1212 {
1213   struct GraphicInfo *g = &graphic_info[graphic];
1214   Bitmap *src_bitmap;
1215   int src_x, src_y;
1216   int xoffset = (pressed ? g->pressed_xoffset : 0);
1217   int yoffset = (pressed ? g->pressed_yoffset : 0);
1218
1219   getFixedGraphicSource(graphic, 0, &src_bitmap, &src_x, &src_y);
1220
1221   BlitBitmapMasked(src_bitmap, drawto, src_x + xoffset, src_y + yoffset,
1222                    g->width, g->height, dst_x, dst_y);
1223 }
1224
1225 static void DrawCursorAndText_Main_Ext(int nr, boolean active_text,
1226                                        boolean active_input,
1227                                        boolean pressed_button)
1228 {
1229   int i;
1230
1231   for (i = 0; main_controls[i].nr != -1; i++)
1232   {
1233     struct MainControlInfo *mci = &main_controls[i];
1234
1235     if (mci->nr == nr || nr == -1)
1236     {
1237       struct MenuPosInfo *pos_button = mci->pos_button;
1238       struct TextPosInfo *pos_text   = mci->pos_text;
1239       struct TextPosInfo *pos_input  = mci->pos_input;
1240       char *text                     = (mci->text  ? *mci->text  : NULL);
1241       char *input                    = (mci->input ? *mci->input : NULL);
1242       int button_graphic             = mci->button_graphic;
1243       int font_text                  = (pos_text  ? pos_text->font  : -1);
1244       int font_input                 = (pos_input ? pos_input->font : -1);
1245
1246       if (active_text)
1247       {
1248         button_graphic = BUTTON_ACTIVE(button_graphic);
1249         font_text = FONT_ACTIVE(font_text);
1250       }
1251
1252       if (active_input)
1253       {
1254         font_input = FONT_ACTIVE(font_input);
1255       }
1256
1257       if (visibleMenuPos(pos_button))
1258       {
1259         struct MenuPosInfo *pos = pos_button;
1260         int x = mSX + pos->x;
1261         int y = mSY + pos->y;
1262
1263         DrawBackgroundForGraphic(x, y, pos->width, pos->height, button_graphic);
1264         DrawPressedGraphicThruMask(x, y, button_graphic, pressed_button);
1265       }
1266
1267       if (visibleTextPos(pos_text) && text != NULL)
1268       {
1269         struct TextPosInfo *pos = pos_text;
1270         int x = mSX + ALIGNED_TEXT_XPOS(pos);
1271         int y = mSY + ALIGNED_TEXT_YPOS(pos);
1272
1273 #if 1
1274         /* (check why/if this is needed) */
1275         DrawBackgroundForFont(x, y, pos->width, pos->height, font_text);
1276 #endif
1277         DrawText(x, y, text, font_text);
1278       }
1279
1280       if (visibleTextPos(pos_input) && input != NULL)
1281       {
1282         struct TextPosInfo *pos = pos_input;
1283         int x = mSX + ALIGNED_TEXT_XPOS(pos);
1284         int y = mSY + ALIGNED_TEXT_YPOS(pos);
1285
1286 #if 1
1287         /* (check why/if this is needed) */
1288         DrawBackgroundForFont(x, y, pos->width, pos->height, font_input);
1289 #endif
1290         DrawText(x, y, input, font_input);
1291       }
1292     }
1293   }
1294 }
1295
1296 static void DrawCursorAndText_Main(int nr, boolean active_text,
1297                                    boolean pressed_button)
1298 {
1299   DrawCursorAndText_Main_Ext(nr, active_text, FALSE, pressed_button);
1300 }
1301
1302 #if 0
1303 static void DrawCursorAndText_Main_Input(int nr, boolean active_text,
1304                                          boolean pressed_button)
1305 {
1306   DrawCursorAndText_Main_Ext(nr, active_text, TRUE, pressed_button);
1307 }
1308 #endif
1309
1310 static struct MainControlInfo *getMainControlInfo(int nr)
1311 {
1312   int i;
1313
1314   for (i = 0; main_controls[i].nr != -1; i++)
1315     if (main_controls[i].nr == nr)
1316       return &main_controls[i];
1317
1318   return NULL;
1319 }
1320
1321 static boolean insideMenuPosRect(struct MenuPosInfo *rect, int x, int y)
1322 {
1323   if (rect == NULL)
1324     return FALSE;
1325
1326   int rect_x = ALIGNED_TEXT_XPOS(rect);
1327   int rect_y = ALIGNED_TEXT_YPOS(rect);
1328
1329   return (x >= rect_x && x < rect_x + rect->width &&
1330           y >= rect_y && y < rect_y + rect->height);
1331 }
1332
1333 static boolean insideTextPosRect(struct TextPosInfo *rect, int x, int y)
1334 {
1335   if (rect == NULL)
1336     return FALSE;
1337
1338   int rect_x = ALIGNED_TEXT_XPOS(rect);
1339   int rect_y = ALIGNED_TEXT_YPOS(rect);
1340
1341 #if 0
1342   printf("::: insideTextPosRect: (%d, %d), (%d, %d) [%d, %d] (%d, %d) => %d\n",
1343          x, y, rect_x, rect_y, rect->x, rect->y, rect->width, rect->height,
1344          (x >= rect_x && x < rect_x + rect->width &&
1345           y >= rect_y && y < rect_y + rect->height));
1346 #endif
1347
1348   return (x >= rect_x && x < rect_x + rect->width &&
1349           y >= rect_y && y < rect_y + rect->height);
1350 }
1351
1352 static boolean insidePreviewRect(struct PreviewInfo *preview, int x, int y)
1353 {
1354   int rect_width  = preview->xsize * preview->tile_size;
1355   int rect_height = preview->ysize * preview->tile_size;
1356   int rect_x = ALIGNED_XPOS(preview->x, rect_width,  preview->align);
1357   int rect_y = ALIGNED_YPOS(preview->y, rect_height, preview->valign);
1358
1359   return (x >= rect_x && x < rect_x + rect_width &&
1360           y >= rect_y && y < rect_y + rect_height);
1361 }
1362
1363 static void AdjustScrollbar(int id, int items_max, int items_visible,
1364                             int item_position)
1365 {
1366   struct GadgetInfo *gi = screen_gadget[id];
1367
1368   if (item_position > items_max - items_visible)
1369     item_position = items_max - items_visible;
1370
1371   ModifyGadget(gi, GDI_SCROLLBAR_ITEMS_MAX, items_max,
1372                GDI_SCROLLBAR_ITEMS_VISIBLE, items_visible,
1373                GDI_SCROLLBAR_ITEM_POSITION, item_position, GDI_END);
1374 }
1375
1376 static void AdjustChooseTreeScrollbar(int id, int first_entry, TreeInfo *ti)
1377 {
1378   AdjustScrollbar(id, numTreeInfoInGroup(ti), NUM_MENU_ENTRIES_ON_SCREEN,
1379                   first_entry);
1380 }
1381
1382 static void clearMenuListArea(void)
1383 {
1384   int scrollbar_xpos = mSX + SC_SCROLLBAR_XPOS + menu.scrollbar_xoffset;
1385
1386   /* correct scrollbar position if placed outside menu (playfield) area */
1387   if (scrollbar_xpos > SX + SC_SCROLLBAR_XPOS)
1388     scrollbar_xpos = SX + SC_SCROLLBAR_XPOS;
1389
1390   /* clear menu list area, but not title or scrollbar */
1391   DrawBackground(mSX, mSY + MENU_SCREEN_START_YPOS * 32,
1392                  scrollbar_xpos - mSX, NUM_MENU_ENTRIES_ON_SCREEN * 32);
1393 }
1394
1395 static void drawCursorExt(int xpos, int ypos, boolean active, int graphic)
1396 {
1397   static int cursor_array[MAX_LEV_FIELDY];
1398   int x = mSX + TILEX * xpos;
1399   int y = mSY + TILEY * (MENU_SCREEN_START_YPOS + ypos);
1400
1401   if (xpos == 0)
1402   {
1403     if (graphic != -1)
1404       cursor_array[ypos] = graphic;
1405     else
1406       graphic = cursor_array[ypos];
1407   }
1408
1409   if (active)
1410     graphic = BUTTON_ACTIVE(graphic);
1411
1412   DrawBackgroundForGraphic(x, y, TILEX, TILEY, graphic);
1413   DrawFixedGraphicThruMaskExt(drawto, x, y, graphic, 0);
1414 }
1415
1416 static void initCursor(int ypos, int graphic)
1417 {
1418   drawCursorExt(0, ypos, FALSE, graphic);
1419 }
1420
1421 static void drawCursor(int ypos, boolean active)
1422 {
1423   drawCursorExt(0, ypos, active, -1);
1424 }
1425
1426 static void drawCursorXY(int xpos, int ypos, int graphic)
1427 {
1428   drawCursorExt(xpos, ypos, FALSE, graphic);
1429 }
1430
1431 static void drawChooseTreeCursor(int ypos, boolean active)
1432 {
1433   drawCursorExt(0, ypos, active, -1);
1434 }
1435
1436 static void DrawHeadline(void)
1437 {
1438   DrawTextSCentered(MENU_TITLE1_YPOS, FONT_TITLE_1, main_text_title_1);
1439   DrawTextSCentered(MENU_TITLE2_YPOS, FONT_TITLE_2, main_text_title_2);
1440 }
1441
1442 static void DrawTitleScreenImage(int nr, boolean initial)
1443 {
1444   int graphic = getTitleScreenGraphic(nr, initial);
1445   Bitmap *bitmap = graphic_info[graphic].bitmap;
1446   int width  = graphic_info[graphic].width;
1447   int height = graphic_info[graphic].height;
1448   int src_x = graphic_info[graphic].src_x;
1449   int src_y = graphic_info[graphic].src_y;
1450   int dst_x, dst_y;
1451
1452   if (bitmap == NULL)
1453     return;
1454
1455   if (width > WIN_XSIZE)
1456   {
1457     /* image width too large for window => center image horizontally */
1458     src_x = (width - WIN_XSIZE) / 2;
1459     width = WIN_XSIZE;
1460   }
1461
1462   if (height > WIN_YSIZE)
1463   {
1464     /* image height too large for window => center image vertically */
1465     src_y = (height - WIN_YSIZE) / 2;
1466     height = WIN_YSIZE;
1467   }
1468
1469   /* always display title screens centered */
1470   dst_x = (WIN_XSIZE - width) / 2;
1471   dst_y = (WIN_YSIZE - height) / 2;
1472
1473   SetDrawBackgroundMask(REDRAW_ALL);
1474   SetWindowBackgroundImage(getTitleBackground(nr, initial, TRUE));
1475
1476   ClearRectangleOnBackground(drawto, 0, 0, WIN_XSIZE, WIN_YSIZE);
1477
1478   if (DrawingOnBackground(dst_x, dst_y))
1479     BlitBitmapMasked(bitmap, drawto, src_x, src_y, width, height, dst_x, dst_y);
1480   else
1481     BlitBitmap(bitmap, drawto, src_x, src_y, width, height, dst_x, dst_y);
1482
1483   redraw_mask = REDRAW_ALL;
1484 }
1485
1486 static void DrawTitleScreenMessage(int nr, boolean initial)
1487 {
1488   char *filename = getLevelSetTitleMessageFilename(nr, initial);
1489   struct TitleMessageInfo *tmi = getTitleMessageInfo(nr, initial);
1490
1491   if (filename == NULL)
1492     return;
1493
1494   /* force TITLE font on title message screen */
1495   SetFontStatus(getTitleMessageGameMode(initial));
1496
1497   /* if chars *and* width set to "-1", automatically determine width */
1498   if (tmi->chars == -1 && tmi->width == -1)
1499     tmi->width = viewport.window[game_status].width;
1500
1501   /* if lines *and* height set to "-1", automatically determine height */
1502   if (tmi->lines == -1 && tmi->height == -1)
1503     tmi->height = viewport.window[game_status].height;
1504
1505   /* if chars set to "-1", automatically determine by text and font width */
1506   if (tmi->chars == -1)
1507     tmi->chars = tmi->width / getFontWidth(tmi->font);
1508   else
1509     tmi->width = tmi->chars * getFontWidth(tmi->font);
1510
1511   /* if lines set to "-1", automatically determine by text and font height */
1512   if (tmi->lines == -1)
1513     tmi->lines = tmi->height / getFontHeight(tmi->font);
1514   else
1515     tmi->height = tmi->lines * getFontHeight(tmi->font);
1516
1517   /* if x set to "-1", automatically determine by width and alignment */
1518   if (tmi->x == -1)
1519     tmi->x = -1 * ALIGNED_XPOS(0, tmi->width, tmi->align);
1520
1521   /* if y set to "-1", automatically determine by height and alignment */
1522   if (tmi->y == -1)
1523     tmi->y = -1 * ALIGNED_YPOS(0, tmi->height, tmi->valign);
1524
1525   SetDrawBackgroundMask(REDRAW_ALL);
1526   SetWindowBackgroundImage(getTitleBackground(nr, initial, FALSE));
1527
1528   ClearRectangleOnBackground(drawto, 0, 0, WIN_XSIZE, WIN_YSIZE);
1529
1530   DrawTextFile(ALIGNED_TEXT_XPOS(tmi), ALIGNED_TEXT_YPOS(tmi),
1531                filename, tmi->font, tmi->chars, -1, tmi->lines, 0, -1,
1532                tmi->autowrap, tmi->centered, tmi->parse_comments);
1533
1534   ResetFontStatus();
1535 }
1536
1537 static void DrawTitleScreen(void)
1538 {
1539   KeyboardAutoRepeatOff();
1540
1541   HandleTitleScreen(0, 0, 0, 0, MB_MENU_INITIALIZE);
1542 }
1543
1544 static boolean CheckTitleScreen(boolean levelset_has_changed)
1545 {
1546   static boolean show_title_initial = TRUE;
1547   boolean show_titlescreen = FALSE;
1548
1549   /* needed to be able to skip title screen, if no image or message defined */
1550   InitializeTitleControls(show_title_initial);
1551
1552   if (setup.show_titlescreen && (show_title_initial || levelset_has_changed))
1553     show_titlescreen = TRUE;
1554
1555   /* show initial title images and messages only once at program start */
1556   show_title_initial = FALSE;
1557
1558   return (show_titlescreen && num_title_screens > 0);
1559 }
1560
1561 void DrawMainMenu(void)
1562 {
1563   static LevelDirTree *leveldir_last_valid = NULL;
1564   boolean levelset_has_changed = FALSE;
1565   int fade_mask = REDRAW_FIELD;
1566
1567   LimitScreenUpdates(FALSE);
1568
1569   FadeSetLeaveScreen();
1570
1571   /* do not fade out here -- function may continue and fade on editor screen */
1572
1573   UnmapAllGadgets();
1574   FadeMenuSoundsAndMusic();
1575
1576   ExpireSoundLoops(FALSE);
1577
1578   KeyboardAutoRepeatOn();
1579
1580   audio.sound_deactivated = FALSE;
1581
1582   GetPlayerConfig();
1583
1584   /* needed if last screen was the playing screen, invoked from level editor */
1585   if (level_editor_test_game)
1586   {
1587     CloseDoor(DOOR_CLOSE_ALL);
1588
1589     SetGameStatus(GAME_MODE_EDITOR);
1590
1591     DrawLevelEd();
1592
1593     return;
1594   }
1595
1596   /* needed if last screen was the setup screen and fullscreen state changed */
1597   // (moved to "execSetupGraphics()" to change fullscreen state directly)
1598   // ToggleFullscreenOrChangeWindowScalingIfNeeded();
1599
1600   /* leveldir_current may be invalid (level group, parent link) */
1601   if (!validLevelSeries(leveldir_current))
1602     leveldir_current = getFirstValidTreeInfoEntry(leveldir_last_valid);
1603
1604   if (leveldir_current != leveldir_last_valid)
1605     levelset_has_changed = TRUE;
1606
1607   /* store valid level series information */
1608   leveldir_last_valid = leveldir_current;
1609
1610   init_last = init;                     /* switch to new busy animation */
1611
1612   /* needed if last screen (level choice) changed graphics, sounds or music */
1613   ReloadCustomArtwork(0);
1614
1615   if (CheckTitleScreen(levelset_has_changed))
1616   {
1617     SetGameStatus(GAME_MODE_TITLE);
1618
1619     DrawTitleScreen();
1620
1621     return;
1622   }
1623
1624   if (redraw_mask & REDRAW_ALL)
1625     fade_mask = REDRAW_ALL;
1626
1627   if (CheckIfGlobalBorderOrPlayfieldViewportHasChanged())
1628     fade_mask = REDRAW_ALL;
1629
1630   FadeOut(fade_mask);
1631
1632   /* needed if different viewport properties defined for menues */
1633   ChangeViewportPropertiesIfNeeded();
1634
1635   SetDrawtoField(DRAW_TO_BACKBUFFER);
1636
1637   /* level_nr may have been set to value over handicap with level editor */
1638   if (setup.handicap && level_nr > leveldir_current->handicap_level)
1639     level_nr = leveldir_current->handicap_level;
1640
1641   LoadLevel(level_nr);
1642   LoadScore(level_nr);
1643
1644   SaveLevelSetup_SeriesInfo();
1645
1646   // set this after "ChangeViewportPropertiesIfNeeded()" (which may reset it)
1647   SetDrawDeactivationMask(REDRAW_NONE);
1648   SetDrawBackgroundMask(REDRAW_FIELD);
1649
1650   SetMainBackgroundImage(IMG_BACKGROUND_MAIN);
1651
1652 #if 0
1653   if (fade_mask == REDRAW_ALL)
1654     RedrawGlobalBorder();
1655 #endif
1656
1657   ClearField();
1658
1659   InitializeMainControls();
1660
1661   DrawCursorAndText_Main(-1, FALSE, FALSE);
1662   DrawPreviewLevelInitial();
1663   DrawNetworkPlayers();
1664
1665   HandleMainMenu(0, 0, 0, 0, MB_MENU_INITIALIZE);
1666
1667   TapeStop();
1668   if (TAPE_IS_EMPTY(tape))
1669     LoadTape(level_nr);
1670   DrawCompleteVideoDisplay();
1671
1672   PlayMenuSoundsAndMusic();
1673
1674   /* create gadgets for main menu screen */
1675   FreeScreenGadgets();
1676   CreateScreenGadgets();
1677
1678   /* may be required if audio buttons shown on tape and changed in setup menu */
1679   FreeGameButtons();
1680   CreateGameButtons();
1681
1682   /* map gadgets for main menu screen */
1683   MapTapeButtons();
1684   MapScreenMenuGadgets(SCREEN_MASK_MAIN);
1685   UpdateScreenMenuGadgets(SCREEN_MASK_MAIN_HAS_SOLUTION, hasSolutionTape());
1686
1687   /* copy actual game door content to door double buffer for OpenDoor() */
1688   BlitBitmap(drawto, bitmap_db_door_1, DX, DY, DXSIZE, DYSIZE, 0, 0);
1689   BlitBitmap(drawto, bitmap_db_door_2, VX, VY, VXSIZE, VYSIZE, 0, 0);
1690
1691   OpenDoor(GetDoorState() | DOOR_NO_DELAY | DOOR_FORCE_REDRAW);
1692
1693   DrawMaskedBorder(fade_mask);
1694
1695   FadeIn(fade_mask);
1696   FadeSetEnterMenu();
1697
1698   /* update screen area with special editor door */
1699   redraw_mask |= REDRAW_ALL;
1700   BackToFront();
1701
1702   SetMouseCursor(CURSOR_DEFAULT);
1703
1704   OpenDoor(DOOR_CLOSE_1 | DOOR_OPEN_2);
1705 }
1706
1707 static void gotoTopLevelDir(void)
1708 {
1709   /* move upwards until inside (but not above) top level directory */
1710   while (leveldir_current->node_parent &&
1711          !strEqual(leveldir_current->node_parent->subdir, STRING_TOP_DIRECTORY))
1712   {
1713     /* write a "path" into level tree for easy navigation to last level */
1714     if (leveldir_current->node_parent->node_group->cl_first == -1)
1715     {
1716       int num_leveldirs = numTreeInfoInGroup(leveldir_current);
1717       int leveldir_pos = posTreeInfo(leveldir_current);
1718       int num_page_entries;
1719       int cl_first, cl_cursor;
1720
1721       if (num_leveldirs <= NUM_MENU_ENTRIES_ON_SCREEN)
1722         num_page_entries = num_leveldirs;
1723       else
1724         num_page_entries = NUM_MENU_ENTRIES_ON_SCREEN;
1725
1726       cl_first = MAX(0, leveldir_pos - num_page_entries + 1);
1727       cl_cursor = leveldir_pos - cl_first;
1728
1729       leveldir_current->node_parent->node_group->cl_first = cl_first;
1730       leveldir_current->node_parent->node_group->cl_cursor = cl_cursor;
1731     }
1732
1733     leveldir_current = leveldir_current->node_parent;
1734   }
1735 }
1736
1737 void HandleTitleScreen(int mx, int my, int dx, int dy, int button)
1738 {
1739   static unsigned int title_delay = 0;
1740   static int title_screen_nr = 0;
1741   static int last_sound = -1, last_music = -1;
1742   boolean return_to_main_menu = FALSE;
1743   struct TitleControlInfo *tci;
1744   int sound, music;
1745
1746   if (button == MB_MENU_INITIALIZE)
1747   {
1748     title_delay = 0;
1749     title_screen_nr = 0;
1750     tci = &title_controls[title_screen_nr];
1751
1752     SetAnimStatus(getTitleAnimMode(tci));
1753
1754     last_sound = SND_UNDEFINED;
1755     last_music = MUS_UNDEFINED;
1756
1757     if (num_title_screens != 0)
1758     {
1759       FadeSetEnterScreen();
1760
1761       /* use individual title fading instead of global "enter screen" fading */
1762       fading = getTitleFading(tci);
1763     }
1764
1765     if (game_status_last_screen == GAME_MODE_INFO)
1766     {
1767       if (num_title_screens == 0)
1768       {
1769         /* switch game mode from title screen mode back to info screen mode */
1770         SetGameStatus(GAME_MODE_INFO);
1771
1772         /* store that last screen was info screen, not main menu screen */
1773         game_status_last_screen = GAME_MODE_INFO;
1774
1775         DrawInfoScreen_NotAvailable("Title screen information:",
1776                                     "No title screen for this level set.");
1777         return;
1778       }
1779
1780       FadeMenuSoundsAndMusic();
1781     }
1782
1783     FadeOut(REDRAW_ALL);
1784
1785     /* title screens may have different window size */
1786     ChangeViewportPropertiesIfNeeded();
1787
1788     /* only required to update logic for redrawing global border */
1789     ClearField();
1790
1791     if (tci->is_image)
1792       DrawTitleScreenImage(tci->local_nr, tci->initial);
1793     else
1794       DrawTitleScreenMessage(tci->local_nr, tci->initial);
1795
1796     sound = getTitleSound(tci);
1797     music = getTitleMusic(tci);
1798
1799     if (sound != last_sound)
1800       PlayMenuSoundExt(sound);
1801     if (music != last_music)
1802       PlayMenuMusicExt(music);
1803
1804     last_sound = sound;
1805     last_music = music;
1806
1807     SetMouseCursor(CURSOR_NONE);
1808
1809     FadeIn(REDRAW_ALL);
1810
1811     DelayReached(&title_delay, 0);      /* reset delay counter */
1812
1813     return;
1814   }
1815
1816   if (fading.auto_delay > 0 && DelayReached(&title_delay, fading.auto_delay))
1817     button = MB_MENU_CHOICE;
1818
1819   if (button == MB_MENU_LEAVE)
1820   {
1821     return_to_main_menu = TRUE;
1822   }
1823   else if (button == MB_MENU_CHOICE)
1824   {
1825     if (game_status_last_screen == GAME_MODE_INFO && num_title_screens == 0)
1826     {
1827       SetGameStatus(GAME_MODE_INFO);
1828
1829       info_mode = INFO_MODE_MAIN;
1830
1831       DrawInfoScreen();
1832
1833       return;
1834     }
1835
1836     title_screen_nr++;
1837
1838     if (title_screen_nr < num_title_screens)
1839     {
1840       tci = &title_controls[title_screen_nr];
1841
1842       SetAnimStatus(getTitleAnimMode(tci));
1843
1844       sound = getTitleSound(tci);
1845       music = getTitleMusic(tci);
1846
1847       if (last_sound != SND_UNDEFINED && sound != last_sound)
1848         FadeSound(last_sound);
1849       if (last_music != MUS_UNDEFINED && music != last_music)
1850         FadeMusic();
1851
1852       fading = getTitleFading(tci);
1853
1854       FadeOut(REDRAW_ALL);
1855
1856       if (tci->is_image)
1857         DrawTitleScreenImage(tci->local_nr, tci->initial);
1858       else
1859         DrawTitleScreenMessage(tci->local_nr, tci->initial);
1860
1861       sound = getTitleSound(tci);
1862       music = getTitleMusic(tci);
1863
1864       if (sound != last_sound)
1865         PlayMenuSoundExt(sound);
1866       if (music != last_music)
1867         PlayMenuMusicExt(music);
1868
1869       last_sound = sound;
1870       last_music = music;
1871
1872       FadeIn(REDRAW_ALL);
1873
1874       DelayReached(&title_delay, 0);    /* reset delay counter */
1875     }
1876     else
1877     {
1878       FadeMenuSoundsAndMusic();
1879
1880       return_to_main_menu = TRUE;
1881     }
1882   }
1883
1884   if (return_to_main_menu)
1885   {
1886     SetMouseCursor(CURSOR_DEFAULT);
1887
1888     /* force full menu screen redraw after displaying title screens */
1889     redraw_mask = REDRAW_ALL;
1890
1891     if (game_status_last_screen == GAME_MODE_INFO)
1892     {
1893       SetGameStatus(GAME_MODE_INFO);
1894
1895       info_mode = INFO_MODE_MAIN;
1896
1897       DrawInfoScreen();
1898     }
1899     else        /* default: return to main menu */
1900     {
1901       SetGameStatus(GAME_MODE_MAIN);
1902
1903       DrawMainMenu();
1904     }
1905   }
1906 }
1907
1908 static void HandleMainMenu_SelectLevel(int step, int direction,
1909                                        int selected_level_nr)
1910 {
1911   int old_level_nr = level_nr;
1912   int new_level_nr;
1913
1914   if (selected_level_nr != NO_DIRECT_LEVEL_SELECT)
1915     new_level_nr = selected_level_nr;
1916   else
1917     new_level_nr = old_level_nr + step * direction;
1918
1919   if (new_level_nr < leveldir_current->first_level)
1920     new_level_nr = leveldir_current->first_level;
1921   if (new_level_nr > leveldir_current->last_level)
1922     new_level_nr = leveldir_current->last_level;
1923
1924   if (setup.handicap && new_level_nr > leveldir_current->handicap_level)
1925   {
1926     /* skipping levels is only allowed when trying to skip single level */
1927     if (setup.skip_levels && new_level_nr == old_level_nr + 1 &&
1928         Request("Level still unsolved! Skip despite handicap?", REQ_ASK))
1929     {
1930       leveldir_current->handicap_level++;
1931       SaveLevelSetup_SeriesInfo();
1932     }
1933
1934     new_level_nr = leveldir_current->handicap_level;
1935   }
1936
1937   if (new_level_nr != old_level_nr)
1938   {
1939     struct MainControlInfo *mci= getMainControlInfo(MAIN_CONTROL_LEVEL_NUMBER);
1940
1941     PlaySound(SND_MENU_ITEM_SELECTING);
1942
1943     level_nr = new_level_nr;
1944
1945     DrawText(mSX + mci->pos_text->x, mSY + mci->pos_text->y,
1946              int2str(level_nr, menu.main.text.level_number.size),
1947              mci->pos_text->font);
1948
1949     LoadLevel(level_nr);
1950     DrawPreviewLevelInitial();
1951
1952     TapeErase();
1953     LoadTape(level_nr);
1954     DrawCompleteVideoDisplay();
1955
1956     SaveLevelSetup_SeriesInfo();
1957
1958     UpdateScreenMenuGadgets(SCREEN_MASK_MAIN_HAS_SOLUTION, hasSolutionTape());
1959
1960     /* needed because DrawPreviewLevelInitial() takes some time */
1961     BackToFront();
1962     /* SyncDisplay(); */
1963   }
1964 }
1965
1966 void HandleMainMenu(int mx, int my, int dx, int dy, int button)
1967 {
1968   static int choice = MAIN_CONTROL_GAME;
1969   static boolean button_pressed_last = FALSE;
1970   boolean button_pressed = FALSE;
1971   int pos = choice;
1972   int i;
1973
1974   if (button == MB_MENU_INITIALIZE)
1975   {
1976     DrawCursorAndText_Main(choice, TRUE, FALSE);
1977
1978     return;
1979   }
1980
1981   if (mx || my)         /* mouse input */
1982   {
1983     pos = -1;
1984
1985     for (i = 0; main_controls[i].nr != -1; i++)
1986     {
1987       if (insideMenuPosRect(main_controls[i].pos_button, mx - mSX, my - mSY) ||
1988           insideTextPosRect(main_controls[i].pos_text,   mx - mSX, my - mSY) ||
1989           insideTextPosRect(main_controls[i].pos_input,  mx - mSX, my - mSY))
1990       {
1991         pos = main_controls[i].nr;
1992
1993         break;
1994       }
1995     }
1996
1997     /* check if level preview was clicked */
1998     if (insidePreviewRect(&preview, mx - SX, my - SY))
1999       pos = MAIN_CONTROL_GAME;
2000
2001     // handle pressed/unpressed state for active/inactive menu buttons
2002     // (if pos != -1, "i" contains index position corresponding to "pos")
2003     if (button &&
2004         pos >= MAIN_CONTROL_NAME && pos <= MAIN_CONTROL_QUIT &&
2005         insideMenuPosRect(main_controls[i].pos_button, mx - mSX, my - mSY))
2006       button_pressed = TRUE;
2007
2008     if (button_pressed != button_pressed_last)
2009     {
2010       DrawCursorAndText_Main(choice, TRUE, button_pressed);
2011
2012       if (button_pressed)
2013         PlaySound(SND_MENU_BUTTON_PRESSING);
2014       else
2015         PlaySound(SND_MENU_BUTTON_RELEASING);
2016     }
2017   }
2018   else if (dx || dy)    /* keyboard input */
2019   {
2020     if (dx > 0 && (choice == MAIN_CONTROL_INFO ||
2021                    choice == MAIN_CONTROL_SETUP))
2022       button = MB_MENU_CHOICE;
2023     else if (dy)
2024       pos = choice + dy;
2025   }
2026
2027   if (pos == MAIN_CONTROL_FIRST_LEVEL && !button)
2028   {
2029     HandleMainMenu_SelectLevel(MAX_LEVELS, -1, NO_DIRECT_LEVEL_SELECT);
2030   }
2031   else if (pos == MAIN_CONTROL_LAST_LEVEL && !button)
2032   {
2033     HandleMainMenu_SelectLevel(MAX_LEVELS, +1, NO_DIRECT_LEVEL_SELECT);
2034   }
2035   else if (pos == MAIN_CONTROL_LEVEL_NUMBER && !button)
2036   {
2037     CloseDoor(DOOR_CLOSE_2);
2038
2039     SetGameStatus(GAME_MODE_LEVELNR);
2040
2041     DrawChooseLevelNr();
2042   }
2043   else if (pos >= MAIN_CONTROL_NAME && pos <= MAIN_CONTROL_QUIT)
2044   {
2045     if (button)
2046     {
2047       if (pos != choice)
2048       {
2049         PlaySound(SND_MENU_ITEM_ACTIVATING);
2050
2051         DrawCursorAndText_Main(choice, FALSE, FALSE);
2052         DrawCursorAndText_Main(pos, TRUE, button_pressed);
2053
2054         choice = pos;
2055       }
2056       else if (dx != 0)
2057       {
2058         if (choice != MAIN_CONTROL_INFO &&
2059             choice != MAIN_CONTROL_SETUP)
2060           HandleMainMenu_SelectLevel(1, dx, NO_DIRECT_LEVEL_SELECT);
2061       }
2062     }
2063     else
2064     {
2065       PlaySound(SND_MENU_ITEM_SELECTING);
2066
2067       if (pos == MAIN_CONTROL_NAME)
2068       {
2069         SetGameStatus(GAME_MODE_PSEUDO_TYPENAME);
2070
2071         HandleTypeName(strlen(setup.player_name), 0);
2072       }
2073       else if (pos == MAIN_CONTROL_LEVELS)
2074       {
2075         if (leveldir_first)
2076         {
2077           CloseDoor(DOOR_CLOSE_2);
2078
2079           SetGameStatus(GAME_MODE_LEVELS);
2080
2081           SaveLevelSetup_LastSeries();
2082           SaveLevelSetup_SeriesInfo();
2083
2084           if (setup.internal.choose_from_top_leveldir)
2085             gotoTopLevelDir();
2086
2087           DrawChooseLevelSet();
2088         }
2089       }
2090       else if (pos == MAIN_CONTROL_SCORES)
2091       {
2092         CloseDoor(DOOR_CLOSE_2);
2093
2094         SetGameStatus(GAME_MODE_SCORES);
2095
2096         DrawHallOfFame(level_nr, -1);
2097       }
2098       else if (pos == MAIN_CONTROL_EDITOR)
2099       {
2100         if (leveldir_current->readonly &&
2101             !strEqual(setup.player_name, "Artsoft"))
2102           Request("This level is read only!", REQ_CONFIRM);
2103
2104         CloseDoor(DOOR_CLOSE_2);
2105
2106         SetGameStatus(GAME_MODE_EDITOR);
2107
2108         FadeSetEnterScreen();
2109
2110         DrawLevelEd();
2111       }
2112       else if (pos == MAIN_CONTROL_INFO)
2113       {
2114         CloseDoor(DOOR_CLOSE_2);
2115
2116         SetGameStatus(GAME_MODE_INFO);
2117
2118         info_mode = INFO_MODE_MAIN;
2119
2120         DrawInfoScreen();
2121       }
2122       else if (pos == MAIN_CONTROL_GAME)
2123       {
2124         StartGameActions(network.enabled, setup.autorecord, level.random_seed);
2125       }
2126       else if (pos == MAIN_CONTROL_SETUP)
2127       {
2128         CloseDoor(DOOR_CLOSE_2);
2129
2130         SetGameStatus(GAME_MODE_SETUP);
2131
2132         setup_mode = SETUP_MODE_MAIN;
2133
2134         DrawSetupScreen();
2135       }
2136       else if (pos == MAIN_CONTROL_QUIT)
2137       {
2138         SaveLevelSetup_LastSeries();
2139         SaveLevelSetup_SeriesInfo();
2140
2141         if (Request("Do you really want to quit?", REQ_ASK | REQ_STAY_CLOSED))
2142           SetGameStatus(GAME_MODE_QUIT);
2143       }
2144     }
2145   }
2146
2147   button_pressed_last = button_pressed;
2148 }
2149
2150
2151 /* ========================================================================= */
2152 /* info screen functions                                                     */
2153 /* ========================================================================= */
2154
2155 static struct TokenInfo *info_info;
2156 static int num_info_info;       /* number of info entries shown on screen */
2157 static int max_info_info;       /* total number of info entries in list */
2158
2159 static void execInfoTitleScreen(void)
2160 {
2161   info_mode = INFO_MODE_TITLE;
2162
2163   DrawInfoScreen();
2164 }
2165
2166 static void execInfoElements(void)
2167 {
2168   info_mode = INFO_MODE_ELEMENTS;
2169
2170   DrawInfoScreen();
2171 }
2172
2173 static void execInfoMusic(void)
2174 {
2175   info_mode = INFO_MODE_MUSIC;
2176
2177   DrawInfoScreen();
2178 }
2179
2180 static void execInfoCredits(void)
2181 {
2182   info_mode = INFO_MODE_CREDITS;
2183
2184   DrawInfoScreen();
2185 }
2186
2187 static void execInfoProgram(void)
2188 {
2189   info_mode = INFO_MODE_PROGRAM;
2190
2191   DrawInfoScreen();
2192 }
2193
2194 static void execInfoVersion(void)
2195 {
2196   info_mode = INFO_MODE_VERSION;
2197
2198   DrawInfoScreen();
2199 }
2200
2201 static void execInfoLevelSet(void)
2202 {
2203   info_mode = INFO_MODE_LEVELSET;
2204
2205   DrawInfoScreen();
2206 }
2207
2208 static void execExitInfo(void)
2209 {
2210   SetGameStatus(GAME_MODE_MAIN);
2211
2212   DrawMainMenu();
2213 }
2214
2215 static struct TokenInfo info_info_main[] =
2216 {
2217   { TYPE_ENTER_SCREEN,  execInfoTitleScreen,    "Title Screen"          },
2218   { TYPE_ENTER_SCREEN,  execInfoElements,       "Elements Info"         },
2219   { TYPE_ENTER_SCREEN,  execInfoMusic,          "Music Info"            },
2220   { TYPE_ENTER_SCREEN,  execInfoCredits,        "Credits"               },
2221   { TYPE_ENTER_SCREEN,  execInfoProgram,        "Program Info"          },
2222   { TYPE_ENTER_SCREEN,  execInfoVersion,        "Version Info"          },
2223   { TYPE_ENTER_SCREEN,  execInfoLevelSet,       "Level Set Info"        },
2224   { TYPE_EMPTY,         NULL,                   ""                      },
2225   { TYPE_LEAVE_MENU,    execExitInfo,           "Exit"                  },
2226
2227   { 0,                  NULL,                   NULL                    }
2228 };
2229
2230 static int getMenuTextFont(int type)
2231 {
2232   if (type & (TYPE_SWITCH       |
2233               TYPE_YES_NO       |
2234               TYPE_YES_NO_AUTO  |
2235               TYPE_STRING       |
2236               TYPE_PLAYER       |
2237               TYPE_ECS_AGA      |
2238               TYPE_KEYTEXT      |
2239               TYPE_ENTER_LIST))
2240     return FONT_MENU_2;
2241   else
2242     return FONT_MENU_1;
2243 }
2244
2245 static struct TokenInfo *setup_info;
2246 static struct TokenInfo setup_info_input[];
2247
2248 static struct TokenInfo *menu_info;
2249
2250 static void DrawCursorAndText_Menu_Ext(struct TokenInfo *token_info,
2251                                        int screen_pos, int menu_info_pos_raw,
2252                                        boolean active)
2253 {
2254   int pos = (menu_info_pos_raw < 0 ? screen_pos : menu_info_pos_raw);
2255   struct TokenInfo *ti = &token_info[pos];
2256   int xpos = MENU_SCREEN_START_XPOS;
2257   int ypos = MENU_SCREEN_START_YPOS + screen_pos;
2258   int font_nr = getMenuTextFont(ti->type);
2259
2260   if (setup_mode == SETUP_MODE_INPUT)
2261     font_nr = FONT_MENU_1;
2262
2263   if (active)
2264     font_nr = FONT_ACTIVE(font_nr);
2265
2266   DrawText(mSX + xpos * 32, mSY + ypos * 32, ti->text, font_nr);
2267
2268   if (ti->type & ~TYPE_SKIP_ENTRY)
2269     drawCursor(screen_pos, active);
2270 }
2271
2272 static void DrawCursorAndText_Menu(int screen_pos, int menu_info_pos_raw,
2273                                    boolean active)
2274 {
2275   DrawCursorAndText_Menu_Ext(menu_info, screen_pos, menu_info_pos_raw, active);
2276 }
2277
2278 static void DrawCursorAndText_Setup(int screen_pos, int menu_info_pos_raw,
2279                                     boolean active)
2280 {
2281   DrawCursorAndText_Menu_Ext(setup_info, screen_pos, menu_info_pos_raw, active);
2282 }
2283
2284 static char *window_size_text;
2285 static char *scaling_type_text;
2286
2287 static void drawSetupValue(int, int);
2288
2289 static void drawMenuInfoList(int first_entry, int num_page_entries,
2290                              int max_page_entries)
2291 {
2292   int i;
2293
2294   if (first_entry + num_page_entries > max_page_entries)
2295     first_entry = 0;
2296
2297   clearMenuListArea();
2298
2299   for (i = 0; i < num_page_entries; i++)
2300   {
2301     int menu_info_pos = first_entry + i;
2302     struct TokenInfo *si = &menu_info[menu_info_pos];
2303     void *value_ptr = si->value;
2304
2305     /* set some entries to "unchangeable" according to other variables */
2306     if ((value_ptr == &setup.sound_simple && !audio.sound_available) ||
2307         (value_ptr == &setup.sound_loops  && !audio.loops_available) ||
2308         (value_ptr == &setup.sound_music  && !audio.music_available) ||
2309         (value_ptr == &setup.fullscreen   && !video.fullscreen_available) ||
2310         (value_ptr == &window_size_text   && !video.window_scaling_available) ||
2311         (value_ptr == &scaling_type_text  && !video.window_scaling_available))
2312       si->type |= TYPE_GHOSTED;
2313
2314     if (si->type & (TYPE_ENTER_MENU|TYPE_ENTER_LIST))
2315       initCursor(i, IMG_MENU_BUTTON_ENTER_MENU);
2316     else if (si->type & (TYPE_LEAVE_MENU|TYPE_LEAVE_LIST))
2317       initCursor(i, IMG_MENU_BUTTON_LEAVE_MENU);
2318     else if (si->type & ~TYPE_SKIP_ENTRY)
2319       initCursor(i, IMG_MENU_BUTTON);
2320
2321     DrawCursorAndText_Menu(i, menu_info_pos, FALSE);
2322
2323     if (si->type & TYPE_VALUE &&
2324         menu_info == setup_info)
2325       drawSetupValue(i, menu_info_pos);
2326   }
2327 }
2328
2329 static void DrawInfoScreen_Main(void)
2330 {
2331   int fade_mask = REDRAW_FIELD;
2332   int i;
2333
2334   if (redraw_mask & REDRAW_ALL)
2335     fade_mask = REDRAW_ALL;
2336
2337   if (CheckIfGlobalBorderOrPlayfieldViewportHasChanged())
2338     fade_mask = REDRAW_ALL;
2339
2340   UnmapAllGadgets();
2341   FadeMenuSoundsAndMusic();
2342
2343   FreeScreenGadgets();
2344   CreateScreenGadgets();
2345
2346   /* (needed after displaying title screens which disable auto repeat) */
2347   KeyboardAutoRepeatOn();
2348
2349   FadeSetLeaveScreen();
2350
2351   FadeOut(fade_mask);
2352
2353   /* needed if different viewport properties defined for info screen */
2354   ChangeViewportPropertiesIfNeeded();
2355
2356   SetMainBackgroundImage(IMG_BACKGROUND_INFO);
2357
2358   ClearField();
2359
2360   OpenDoor(GetDoorState() | DOOR_NO_DELAY | DOOR_FORCE_REDRAW);
2361
2362   DrawTextSCentered(mSY - SY + 16, FONT_TITLE_1, "Info Screen");
2363
2364   info_info = info_info_main;
2365
2366   // determine maximal number of info entries that can be displayed on screen
2367   num_info_info = 0;
2368   for (i = 0; info_info[i].type != 0 && i < NUM_MENU_ENTRIES_ON_SCREEN; i++)
2369     num_info_info++;
2370
2371   // determine maximal number of info entries available for menu of info screen
2372   max_info_info = 0;
2373   for (i = 0; info_info[i].type != 0; i++)
2374     max_info_info++;
2375
2376   HandleInfoScreen_Main(0, 0, 0, 0, MB_MENU_INITIALIZE);
2377
2378   MapScreenGadgets(max_info_info);
2379
2380   PlayMenuSoundsAndMusic();
2381
2382   DrawMaskedBorder(fade_mask);
2383
2384   FadeIn(fade_mask);
2385 }
2386
2387 static void changeSetupValue(int, int, int);
2388
2389 static void HandleMenuScreen(int mx, int my, int dx, int dy, int button,
2390                              int mode, int num_page_entries,
2391                              int max_page_entries)
2392 {
2393   static int num_page_entries_all_last[NUM_SPECIAL_GFX_ARGS][MAX_MENU_MODES];
2394   static int choice_stores[NUM_SPECIAL_GFX_ARGS][MAX_MENU_MODES];
2395   static int first_entry_stores[NUM_SPECIAL_GFX_ARGS][MAX_MENU_MODES];
2396   int *num_page_entries_last = num_page_entries_all_last[game_status];
2397   int *choice_store = choice_stores[game_status];
2398   int *first_entry_store = first_entry_stores[game_status];
2399   int choice = choice_store[mode];              /* starts with 0 */
2400   int first_entry = first_entry_store[mode];    /* starts with 0 */
2401   int x = 0;
2402   int y = choice - first_entry;
2403   int y_old = y;
2404   boolean position_set_by_scrollbar = (dx == 999);
2405   int step = (button == 1 ? 1 : button == 2 ? 5 : 10);
2406   int i;
2407
2408   if (button == MB_MENU_INITIALIZE)
2409   {
2410     // check if number of menu page entries has changed (may happen by change
2411     // of custom artwork definition value for 'list_size' for this menu screen)
2412     // (in this case, the last menu position most probably has to be corrected)
2413     if (num_page_entries != num_page_entries_last[mode])
2414     {
2415       choice_store[mode] = first_entry_store[mode] = 0;
2416
2417       choice = first_entry = 0;
2418       y = y_old = 0;
2419
2420       num_page_entries_last[mode] = num_page_entries;
2421     }
2422
2423     /* advance to first valid menu entry */
2424     while (choice < num_page_entries &&
2425            menu_info[choice].type & TYPE_SKIP_ENTRY)
2426       choice++;
2427
2428     if (position_set_by_scrollbar)
2429       first_entry = first_entry_store[mode] = dy;
2430     else
2431       AdjustScrollbar(SCREEN_CTRL_ID_SCROLL_VERTICAL, max_page_entries,
2432                       NUM_MENU_ENTRIES_ON_SCREEN, first_entry);
2433
2434     drawMenuInfoList(first_entry, num_page_entries, max_page_entries);
2435
2436     if (choice < first_entry)
2437     {
2438       choice = first_entry;
2439
2440       if (menu_info[choice].type & TYPE_SKIP_ENTRY)
2441         choice++;
2442     }
2443     else if (choice > first_entry + num_page_entries - 1)
2444     {
2445       choice = first_entry + num_page_entries - 1;
2446
2447       if (menu_info[choice].type & TYPE_SKIP_ENTRY)
2448         choice--;
2449     }
2450
2451     choice_store[mode] = choice;
2452
2453     DrawCursorAndText_Menu(choice - first_entry, choice, TRUE);
2454
2455     return;
2456   }
2457   else if (button == MB_MENU_LEAVE)
2458   {
2459     PlaySound(SND_MENU_ITEM_SELECTING);
2460
2461     for (i = 0; i < max_page_entries; i++)
2462     {
2463       if (menu_info[i].type & TYPE_LEAVE_MENU)
2464       {
2465         void (*menu_callback_function)(void) = menu_info[i].value;
2466
2467         FadeSetLeaveMenu();
2468
2469         menu_callback_function();
2470
2471         break;  /* absolutely needed because function changes 'menu_info'! */
2472       }
2473     }
2474
2475     return;
2476   }
2477
2478   if (mx || my)         /* mouse input */
2479   {
2480     x = (mx - mSX) / 32;
2481     y = (my - mSY) / 32 - MENU_SCREEN_START_YPOS;
2482   }
2483   else if (dx || dy)    /* keyboard or scrollbar/scrollbutton input */
2484   {
2485     /* move cursor instead of scrolling when already at start/end of list */
2486     if (dy == -1 * SCROLL_LINE && first_entry == 0)
2487       dy = -1;
2488     else if (dy == +1 * SCROLL_LINE &&
2489              first_entry + num_page_entries == max_page_entries)
2490       dy = 1;
2491
2492     /* handle scrolling screen one line or page */
2493     if (y + dy < 0 ||
2494         y + dy > num_page_entries - 1)
2495     {
2496       boolean redraw = FALSE;
2497
2498       if (ABS(dy) == SCROLL_PAGE)
2499         step = num_page_entries - 1;
2500
2501       if (dy < 0 && first_entry > 0)
2502       {
2503         /* scroll page/line up */
2504
2505         first_entry -= step;
2506         if (first_entry < 0)
2507           first_entry = 0;
2508
2509         redraw = TRUE;
2510       }
2511       else if (dy > 0 && first_entry + num_page_entries < max_page_entries)
2512       {
2513         /* scroll page/line down */
2514
2515         first_entry += step;
2516         if (first_entry + num_page_entries > max_page_entries)
2517           first_entry = MAX(0, max_page_entries - num_page_entries);
2518
2519         redraw = TRUE;
2520       }
2521
2522       if (redraw)
2523       {
2524         choice += first_entry - first_entry_store[mode];
2525
2526         if (choice < first_entry)
2527         {
2528           choice = first_entry;
2529
2530           if (menu_info[choice].type & TYPE_SKIP_ENTRY)
2531             choice++;
2532         }
2533         else if (choice > first_entry + num_page_entries - 1)
2534         {
2535           choice = first_entry + num_page_entries - 1;
2536
2537           if (menu_info[choice].type & TYPE_SKIP_ENTRY)
2538             choice--;
2539         }
2540         else if (menu_info[choice].type & TYPE_SKIP_ENTRY)
2541         {
2542           choice += SIGN(dy);
2543
2544           if (choice < first_entry ||
2545               choice > first_entry + num_page_entries - 1)
2546           first_entry += SIGN(dy);
2547         }
2548
2549         first_entry_store[mode] = first_entry;
2550         choice_store[mode] = choice;
2551
2552         drawMenuInfoList(first_entry, num_page_entries, max_page_entries);
2553
2554         DrawCursorAndText_Menu(choice - first_entry, choice, TRUE);
2555
2556         AdjustScrollbar(SCREEN_CTRL_ID_SCROLL_VERTICAL, max_page_entries,
2557                         NUM_MENU_ENTRIES_ON_SCREEN, first_entry);
2558       }
2559
2560       return;
2561     }
2562
2563     if (dx)
2564     {
2565       int menu_navigation_type = (dx < 0 ? TYPE_LEAVE : TYPE_ENTER);
2566
2567       if (menu_info[choice].type & menu_navigation_type ||
2568           menu_info[choice].type & TYPE_BOOLEAN_STYLE ||
2569           menu_info[choice].type & TYPE_YES_NO_AUTO ||
2570           menu_info[choice].type & TYPE_PLAYER)
2571         button = MB_MENU_CHOICE;
2572     }
2573     else if (dy)
2574       y += dy;
2575
2576     /* jump to next non-empty menu entry (up or down) */
2577     while (first_entry + y > 0 &&
2578            first_entry + y < max_page_entries - 1 &&
2579            menu_info[first_entry + y].type & TYPE_SKIP_ENTRY)
2580       y += dy;
2581
2582     if (!IN_VIS_MENU(x, y))
2583     {
2584       choice += y - y_old;
2585
2586       if (choice < first_entry)
2587         first_entry = choice;
2588       else if (choice > first_entry + num_page_entries - 1)
2589         first_entry = choice - num_page_entries + 1;
2590
2591       if (first_entry >= 0 &&
2592           first_entry + num_page_entries <= max_page_entries)
2593       {
2594         first_entry_store[mode] = first_entry;
2595
2596         if (choice < first_entry)
2597           choice = first_entry;
2598         else if (choice > first_entry + num_page_entries - 1)
2599           choice = first_entry + num_page_entries - 1;
2600
2601         choice_store[mode] = choice;
2602
2603         drawMenuInfoList(first_entry, num_page_entries, max_page_entries);
2604
2605         DrawCursorAndText_Menu(choice - first_entry, choice, TRUE);
2606
2607         AdjustScrollbar(SCREEN_CTRL_ID_SCROLL_VERTICAL, max_page_entries,
2608                         NUM_MENU_ENTRIES_ON_SCREEN, first_entry);
2609       }
2610
2611       return;
2612     }
2613   }
2614
2615   if (!anyScrollbarGadgetActive() &&
2616       IN_VIS_MENU(x, y) &&
2617       mx < screen_gadget[SCREEN_CTRL_ID_SCROLL_VERTICAL]->x &&
2618       y >= 0 && y < num_page_entries)
2619   {
2620     if (button)
2621     {
2622       if (first_entry + y != choice &&
2623           menu_info[first_entry + y].type & ~TYPE_SKIP_ENTRY)
2624       {
2625         PlaySound(SND_MENU_ITEM_ACTIVATING);
2626
2627         DrawCursorAndText_Menu(choice - first_entry, choice, FALSE);
2628         DrawCursorAndText_Menu(y, first_entry + y, TRUE);
2629
2630         choice = choice_store[mode] = first_entry + y;
2631       }
2632       else if (dx < 0)
2633       {
2634         PlaySound(SND_MENU_ITEM_SELECTING);
2635
2636         for (i = 0; menu_info[i].type != 0; i++)
2637         {
2638           if (menu_info[i].type & TYPE_LEAVE_MENU)
2639           {
2640             void (*menu_callback_function)(void) = menu_info[i].value;
2641
2642             FadeSetLeaveMenu();
2643
2644             menu_callback_function();
2645
2646             /* absolutely needed because function changes 'menu_info'! */
2647             break;
2648           }
2649         }
2650
2651         return;
2652       }
2653     }
2654     else if (!(menu_info[first_entry + y].type & TYPE_GHOSTED))
2655     {
2656       PlaySound(SND_MENU_ITEM_SELECTING);
2657
2658       /* when selecting key headline, execute function for key value change */
2659       if (menu_info[first_entry + y].type & TYPE_KEYTEXT &&
2660           menu_info[first_entry + y + 1].type & TYPE_KEY)
2661         y++;
2662
2663       /* when selecting string value, execute function for list selection */
2664       if (menu_info[first_entry + y].type & TYPE_STRING && y > 0 &&
2665           menu_info[first_entry + y - 1].type & TYPE_ENTER_LIST)
2666         y--;
2667
2668       if (menu_info[first_entry + y].type & TYPE_ENTER_OR_LEAVE)
2669       {
2670         void (*menu_callback_function)(void) =
2671           menu_info[first_entry + y].value;
2672
2673         FadeSetFromType(menu_info[first_entry + y].type);
2674
2675         menu_callback_function();
2676       }
2677       else if (menu_info[first_entry + y].type & TYPE_VALUE &&
2678                menu_info == setup_info)
2679       {
2680         changeSetupValue(y, first_entry + y, dx);
2681       }
2682     }
2683   }
2684 }
2685
2686 void HandleInfoScreen_Main(int mx, int my, int dx, int dy, int button)
2687 {
2688   menu_info = info_info;
2689
2690   HandleMenuScreen(mx, my, dx, dy, button,
2691                    info_mode, num_info_info, max_info_info);
2692 }
2693
2694 static int getMenuFontSpacing(int spacing_height, int font_nr)
2695 {
2696   int font_spacing = getFontHeight(font_nr) + EXTRA_SPACING(game_status);
2697
2698   return (spacing_height < 0 ? ABS(spacing_height) * font_spacing :
2699           spacing_height);
2700 }
2701
2702 static int getMenuTextSpacing(int spacing_height, int font_nr)
2703 {
2704   return (getMenuFontSpacing(spacing_height, font_nr) +
2705           EXTRA_SPACING(game_status));
2706 }
2707
2708 static int getMenuTextStep(int spacing_height, int font_nr)
2709 {
2710   return getFontHeight(font_nr) + getMenuTextSpacing(spacing_height, font_nr);
2711 }
2712
2713 void DrawInfoScreen_NotAvailable(char *text_title, char *text_error)
2714 {
2715   int font_title = MENU_INFO_FONT_TITLE;
2716   int font_error = FONT_TEXT_2;
2717   int font_foot  = MENU_INFO_FONT_FOOT;
2718   int spacing_title = menu.headline1_spacing_info[info_mode];
2719   int ystep_title = getMenuTextStep(spacing_title, font_title);
2720   int ystart1 = mSY - SY + MENU_SCREEN_INFO_YSTART1;
2721   int ystart2 = ystart1 + ystep_title;
2722   int ybottom = mSY - SY + MENU_SCREEN_INFO_YBOTTOM;
2723
2724   SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO);
2725
2726   FadeOut(REDRAW_FIELD);
2727
2728   ClearField();
2729   DrawHeadline();
2730
2731   DrawTextSCentered(ystart1, font_title, text_title);
2732   DrawTextSCentered(ystart2, font_error, text_error);
2733
2734   DrawTextSCentered(ybottom, font_foot,
2735                     "Press any key or button for info menu");
2736
2737   FadeIn(REDRAW_FIELD);
2738 }
2739
2740 void DrawInfoScreen_HelpAnim(int start, int max_anims, boolean init)
2741 {
2742   static int infoscreen_step[MAX_INFO_ELEMENTS_ON_SCREEN];
2743   static int infoscreen_frame[MAX_INFO_ELEMENTS_ON_SCREEN];
2744   int font_title = MENU_INFO_FONT_TITLE;
2745   int font_foot  = MENU_INFO_FONT_FOOT;
2746   int xstart  = mSX + MENU_SCREEN_INFO_SPACE_LEFT;
2747   int ystart1 = mSY - SY + MENU_SCREEN_INFO_YSTART1;
2748   int ystart2 = mSY + MENU_SCREEN_INFO_YSTART2;
2749   int ybottom = mSY - SY + MENU_SCREEN_INFO_YBOTTOM;
2750   int ystep = MENU_SCREEN_INFO_YSTEP;
2751   int element, action, direction;
2752   int graphic;
2753   int delay;
2754   int sync_frame;
2755   int i, j;
2756
2757   if (init)
2758   {
2759     for (i = 0; i < NUM_INFO_ELEMENTS_ON_SCREEN; i++)
2760       infoscreen_step[i] = infoscreen_frame[i] = 0;
2761
2762     ClearField();
2763     DrawHeadline();
2764
2765     DrawTextSCentered(ystart1, font_title, "The Game Elements:");
2766
2767     DrawTextSCentered(ybottom, font_foot,
2768                       "Press any key or button for next page");
2769
2770     FrameCounter = 0;
2771   }
2772
2773   i = j = 0;
2774   while (helpanim_info[j].element != HELPANIM_LIST_END)
2775   {
2776     if (i >= start + NUM_INFO_ELEMENTS_ON_SCREEN ||
2777         i >= max_anims)
2778       break;
2779     else if (i < start)
2780     {
2781       while (helpanim_info[j].element != HELPANIM_LIST_NEXT)
2782         j++;
2783
2784       j++;
2785       i++;
2786
2787       continue;
2788     }
2789
2790     j += infoscreen_step[i - start];
2791
2792     element = helpanim_info[j].element;
2793     action = helpanim_info[j].action;
2794     direction = helpanim_info[j].direction;
2795
2796     if (element < 0)
2797       element = EL_UNKNOWN;
2798
2799     if (action != -1 && direction != -1)
2800       graphic = el_act_dir2img(element, action, direction);
2801     else if (action != -1)
2802       graphic = el_act2img(element, action);
2803     else if (direction != -1)
2804       graphic = el_dir2img(element, direction);
2805     else
2806       graphic = el2img(element);
2807
2808     delay = helpanim_info[j++].delay;
2809
2810     if (delay == -1)
2811       delay = 1000000;
2812
2813     if (infoscreen_frame[i - start] == 0)
2814     {
2815       sync_frame = 0;
2816       infoscreen_frame[i - start] = delay - 1;
2817     }
2818     else
2819     {
2820       sync_frame = delay - infoscreen_frame[i - start];
2821       infoscreen_frame[i - start]--;
2822     }
2823
2824     if (helpanim_info[j].element == HELPANIM_LIST_NEXT)
2825     {
2826       if (!infoscreen_frame[i - start])
2827         infoscreen_step[i - start] = 0;
2828     }
2829     else
2830     {
2831       if (!infoscreen_frame[i - start])
2832         infoscreen_step[i - start]++;
2833       while (helpanim_info[j].element != HELPANIM_LIST_NEXT)
2834         j++;
2835     }
2836
2837     j++;
2838
2839     ClearRectangleOnBackground(drawto, xstart, ystart2 + (i - start) * ystep,
2840                                TILEX, TILEY);
2841     DrawFixedGraphicAnimationExt(drawto, xstart, ystart2 + (i - start) * ystep,
2842                                  graphic, sync_frame, USE_MASKING);
2843
2844     if (init)
2845       DrawInfoScreen_HelpText(element, action, direction, i - start);
2846
2847     i++;
2848   }
2849
2850   redraw_mask |= REDRAW_FIELD;
2851
2852   FrameCounter++;
2853 }
2854
2855 static char *getHelpText(int element, int action, int direction)
2856 {
2857   char token[MAX_LINE_LEN];
2858
2859   strcpy(token, element_info[element].token_name);
2860
2861   if (action != -1)
2862     strcat(token, element_action_info[action].suffix);
2863
2864   if (direction != -1)
2865     strcat(token, element_direction_info[MV_DIR_TO_BIT(direction)].suffix);
2866
2867   return getHashEntry(helptext_info, token);
2868 }
2869
2870 void DrawInfoScreen_HelpText(int element, int action, int direction, int ypos)
2871 {
2872   int font_nr = FONT_INFO_ELEMENTS;
2873   int font_width = getFontWidth(font_nr);
2874   int font_height = getFontHeight(font_nr);
2875   int yoffset = (TILEX - 2 * font_height) / 2;
2876   int xstart = mSX + MENU_SCREEN_INFO_SPACE_LEFT + TILEX + MINI_TILEX;
2877   int ystart = mSY + MENU_SCREEN_INFO_YSTART2 + yoffset;
2878   int ystep = TILEY + 4;
2879   int pad_left = xstart - SX;
2880   int pad_right = MENU_SCREEN_INFO_SPACE_RIGHT;
2881   int max_chars_per_line = (SXSIZE - pad_left - pad_right) / font_width;
2882   int max_lines_per_text = 2;    
2883   char *text = NULL;
2884
2885   if (action != -1 && direction != -1)          /* element.action.direction */
2886     text = getHelpText(element, action, direction);
2887
2888   if (text == NULL && action != -1)             /* element.action */
2889     text = getHelpText(element, action, -1);
2890
2891   if (text == NULL && direction != -1)          /* element.direction */
2892     text = getHelpText(element, -1, direction);
2893
2894   if (text == NULL)                             /* base element */
2895     text = getHelpText(element, -1, -1);
2896
2897   if (text == NULL)                             /* not found */
2898     text = "No description available";
2899
2900   if (strlen(text) <= max_chars_per_line)       /* only one line of text */
2901     ystart += getFontHeight(font_nr) / 2;
2902
2903   DrawTextBuffer(xstart, ystart + ypos * ystep, text, font_nr,
2904                  max_chars_per_line, -1, max_lines_per_text, 0, -1,
2905                  TRUE, FALSE, FALSE);
2906 }
2907
2908 static void DrawInfoScreen_TitleScreen(void)
2909 {
2910   SetGameStatus(GAME_MODE_TITLE);
2911
2912   DrawTitleScreen();
2913 }
2914
2915 void HandleInfoScreen_TitleScreen(int button)
2916 {
2917   HandleTitleScreen(0, 0, 0, 0, button);
2918 }
2919
2920 static void DrawInfoScreen_Elements(void)
2921 {
2922   SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_ELEMENTS);
2923
2924   FadeOut(REDRAW_FIELD);
2925
2926   LoadHelpAnimInfo();
2927   LoadHelpTextInfo();
2928
2929   HandleInfoScreen_Elements(MB_MENU_INITIALIZE);
2930
2931   FadeIn(REDRAW_FIELD);
2932 }
2933
2934 void HandleInfoScreen_Elements(int button)
2935 {
2936   static unsigned int info_delay = 0;
2937   static int num_anims;
2938   static int num_pages;
2939   static int page;
2940   int anims_per_page = NUM_INFO_ELEMENTS_ON_SCREEN;
2941   int i;
2942
2943   if (button == MB_MENU_INITIALIZE)
2944   {
2945     boolean new_element = TRUE;
2946
2947     num_anims = 0;
2948
2949     for (i = 0; helpanim_info[i].element != HELPANIM_LIST_END; i++)
2950     {
2951       if (helpanim_info[i].element == HELPANIM_LIST_NEXT)
2952         new_element = TRUE;
2953       else if (new_element)
2954       {
2955         num_anims++;
2956         new_element = FALSE;
2957       }
2958     }
2959
2960     num_pages = (num_anims + anims_per_page - 1) / anims_per_page;
2961     page = 0;
2962   }
2963
2964   if (button == MB_MENU_LEAVE)
2965   {
2966     PlaySound(SND_MENU_ITEM_SELECTING);
2967
2968     info_mode = INFO_MODE_MAIN;
2969     DrawInfoScreen();
2970
2971     return;
2972   }
2973   else if (button == MB_MENU_CHOICE || button == MB_MENU_INITIALIZE)
2974   {
2975     if (button != MB_MENU_INITIALIZE)
2976     {
2977       PlaySound(SND_MENU_ITEM_SELECTING);
2978
2979       page++;
2980     }
2981
2982     if (page >= num_pages)
2983     {
2984       FadeMenuSoundsAndMusic();
2985
2986       info_mode = INFO_MODE_MAIN;
2987       DrawInfoScreen();
2988
2989       return;
2990     }
2991
2992     if (page > 0)
2993       FadeSetNextScreen();
2994
2995     if (button != MB_MENU_INITIALIZE)
2996       FadeOut(REDRAW_FIELD);
2997
2998     DrawInfoScreen_HelpAnim(page * anims_per_page, num_anims, TRUE);
2999
3000     if (button != MB_MENU_INITIALIZE)
3001       FadeIn(REDRAW_FIELD);
3002   }
3003   else
3004   {
3005     if (DelayReached(&info_delay, GameFrameDelay))
3006       if (page < num_pages)
3007         DrawInfoScreen_HelpAnim(page * anims_per_page, num_anims, FALSE);
3008
3009     PlayMenuSoundIfLoop();
3010   }
3011 }
3012
3013 static void DrawInfoScreen_Music(void)
3014 {
3015   SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_MUSIC);
3016
3017   FadeOut(REDRAW_FIELD);
3018
3019   ClearField();
3020   DrawHeadline();
3021
3022   LoadMusicInfo();
3023
3024   HandleInfoScreen_Music(MB_MENU_INITIALIZE);
3025
3026   FadeIn(REDRAW_FIELD);
3027 }
3028
3029 void HandleInfoScreen_Music(int button)
3030 {
3031   static struct MusicFileInfo *list = NULL;
3032   int font_title = MENU_INFO_FONT_TITLE;
3033   int font_head  = MENU_INFO_FONT_HEAD;
3034   int font_text  = MENU_INFO_FONT_TEXT;
3035   int font_foot  = MENU_INFO_FONT_FOOT;
3036   int spacing_title = menu.headline1_spacing_info[info_mode];
3037   int spacing_head  = menu.headline2_spacing_info[info_mode];
3038   int ystep_title = getMenuTextStep(spacing_title, font_title);
3039   int ystep_head  = getMenuTextStep(spacing_head,  font_head);
3040   int ystart  = mSY - SY + MENU_SCREEN_INFO_YSTART1;
3041   int ybottom = mSY - SY + MENU_SCREEN_INFO_YBOTTOM;
3042
3043   if (button == MB_MENU_INITIALIZE)
3044   {
3045     list = music_file_info;
3046
3047     if (list == NULL)
3048     {
3049       FadeMenuSoundsAndMusic();
3050
3051       ClearField();
3052       DrawHeadline();
3053
3054       DrawTextSCentered(ystart, font_title,
3055                         "No music info for this level set.");
3056
3057       DrawTextSCentered(ybottom, font_foot,
3058                         "Press any key or button for info menu");
3059
3060       return;
3061     }
3062   }
3063
3064   if (button == MB_MENU_LEAVE)
3065   {
3066     PlaySound(SND_MENU_ITEM_SELECTING);
3067
3068     FadeMenuSoundsAndMusic();
3069
3070     info_mode = INFO_MODE_MAIN;
3071     DrawInfoScreen();
3072
3073     return;
3074   }
3075   else if (button == MB_MENU_CHOICE || button == MB_MENU_INITIALIZE)
3076   {
3077     if (button != MB_MENU_INITIALIZE)
3078     {
3079       PlaySound(SND_MENU_ITEM_SELECTING);
3080
3081       if (list != NULL)
3082         list = list->next;
3083     }
3084
3085     if (list == NULL)
3086     {
3087       FadeMenuSoundsAndMusic();
3088
3089       info_mode = INFO_MODE_MAIN;
3090       DrawInfoScreen();
3091
3092       return;
3093     }
3094
3095     FadeMenuSoundsAndMusic();
3096
3097     if (list != music_file_info)
3098       FadeSetNextScreen();
3099
3100     if (button != MB_MENU_INITIALIZE)
3101       FadeOut(REDRAW_FIELD);
3102
3103     ClearField();
3104     DrawHeadline();
3105
3106     if (list->is_sound)
3107     {
3108       int sound = list->music;
3109
3110       if (sound_info[sound].loop)
3111         PlaySoundLoop(sound);
3112       else
3113         PlaySound(sound);
3114
3115       DrawTextSCentered(ystart, font_title, "The Game Background Sounds:");
3116     }
3117     else
3118     {
3119       int music = list->music;
3120
3121       if (music_info[music].loop)
3122         PlayMusicLoop(music);
3123       else
3124         PlayMusic(music);
3125
3126       DrawTextSCentered(ystart, font_title, "The Game Background Music:");
3127     }
3128
3129     ystart += ystep_title;
3130
3131     if (!strEqual(list->title, UNKNOWN_NAME))
3132     {
3133       if (!strEqual(list->title_header, UNKNOWN_NAME))
3134       {
3135         DrawTextSCentered(ystart, font_head, list->title_header);
3136         ystart += ystep_head;
3137       }
3138
3139       DrawTextFCentered(ystart, font_text, "\"%s\"", list->title);
3140       ystart += ystep_head;
3141     }
3142
3143     if (!strEqual(list->artist, UNKNOWN_NAME))
3144     {
3145       if (!strEqual(list->artist_header, UNKNOWN_NAME))
3146         DrawTextSCentered(ystart, font_head, list->artist_header);
3147       else
3148         DrawTextSCentered(ystart, font_head, "by");
3149
3150       ystart += ystep_head;
3151
3152       DrawTextFCentered(ystart, font_text, "%s", list->artist);
3153       ystart += ystep_head;
3154     }
3155
3156     if (!strEqual(list->album, UNKNOWN_NAME))
3157     {
3158       if (!strEqual(list->album_header, UNKNOWN_NAME))
3159         DrawTextSCentered(ystart, font_head, list->album_header);
3160       else
3161         DrawTextSCentered(ystart, font_head, "from the album");
3162
3163       ystart += ystep_head;
3164
3165       DrawTextFCentered(ystart, font_text, "\"%s\"", list->album);
3166       ystart += ystep_head;
3167     }
3168
3169     if (!strEqual(list->year, UNKNOWN_NAME))
3170     {
3171       if (!strEqual(list->year_header, UNKNOWN_NAME))
3172         DrawTextSCentered(ystart, font_head, list->year_header);
3173       else
3174         DrawTextSCentered(ystart, font_head, "from the year");
3175
3176       ystart += ystep_head;
3177
3178       DrawTextFCentered(ystart, font_text, "%s", list->year);
3179       ystart += ystep_head;
3180     }
3181
3182     DrawTextSCentered(ybottom, FONT_TEXT_4,
3183                       "Press any key or button for next page");
3184
3185     if (button != MB_MENU_INITIALIZE)
3186       FadeIn(REDRAW_FIELD);
3187   }
3188
3189   if (list != NULL && list->is_sound && sound_info[list->music].loop)
3190     PlaySoundLoop(list->music);
3191 }
3192
3193 static void DrawInfoScreen_CreditsScreen(int screen_nr)
3194 {
3195   int font_title = MENU_INFO_FONT_TITLE;
3196   int font_head  = MENU_INFO_FONT_HEAD;
3197   int font_text  = MENU_INFO_FONT_TEXT;
3198   int font_foot  = MENU_INFO_FONT_FOOT;
3199   int spacing_title = menu.headline1_spacing_info[info_mode];
3200   int spacing_head  = menu.headline2_spacing_info[info_mode];
3201   int spacing_para  = menu.paragraph_spacing_info[info_mode];
3202   int spacing_line  = menu.line_spacing_info[info_mode];
3203   int ystep_title = getMenuTextStep(spacing_title, font_title);
3204   int ystep_head  = getMenuTextStep(spacing_head,  font_head);
3205   int ystep_para  = getMenuTextStep(spacing_para,  font_text);
3206   int ystep_line  = getMenuTextStep(spacing_line,  font_text);
3207   int ystart  = mSY - SY + MENU_SCREEN_INFO_YSTART1;
3208   int ybottom = mSY - SY + MENU_SCREEN_INFO_YBOTTOM;
3209
3210   ClearField();
3211   DrawHeadline();
3212
3213   DrawTextSCentered(ystart, font_title, "Credits:");
3214   ystart += ystep_title;
3215
3216   if (screen_nr == 0)
3217   {
3218     DrawTextSCentered(ystart, font_head,
3219                       "Special thanks to");
3220     ystart += ystep_head;
3221     DrawTextSCentered(ystart, font_text,
3222                       "Peter Liepa");
3223     ystart += ystep_head;
3224     DrawTextSCentered(ystart, font_head,
3225                       "for creating");
3226     ystart += ystep_head;
3227     DrawTextSCentered(ystart, font_text,
3228                       "\"Boulder Dash\"");
3229     ystart += ystep_head;
3230     DrawTextSCentered(ystart, font_head,
3231                       "in the year");
3232     ystart += ystep_head;
3233     DrawTextSCentered(ystart, font_text,
3234                       "1984");
3235     ystart += ystep_head;
3236     DrawTextSCentered(ystart, font_head,
3237                       "published by");
3238     ystart += ystep_head;
3239     DrawTextSCentered(ystart, font_text,
3240                       "First Star Software");
3241   }
3242   else if (screen_nr == 1)
3243   {
3244     DrawTextSCentered(ystart, font_head,
3245                       "Special thanks to");
3246     ystart += ystep_head;
3247     DrawTextSCentered(ystart, font_text,
3248                       "Klaus Heinz & Volker Wertich");
3249     ystart += ystep_head;
3250     DrawTextSCentered(ystart, font_head,
3251                       "for creating");
3252     ystart += ystep_head;
3253     DrawTextSCentered(ystart, font_text,
3254                       "\"Emerald Mine\"");
3255     ystart += ystep_head;
3256     DrawTextSCentered(ystart, font_head,
3257                       "in the year");
3258     ystart += ystep_head;
3259     DrawTextSCentered(ystart, font_text,
3260                       "1987");
3261     ystart += ystep_head;
3262     DrawTextSCentered(ystart, font_head,
3263                       "published by");
3264     ystart += ystep_head;
3265     DrawTextSCentered(ystart, font_text,
3266                       "Kingsoft");
3267   }
3268   else if (screen_nr == 2)
3269   {
3270     DrawTextSCentered(ystart, font_head,
3271                       "Special thanks to");
3272     ystart += ystep_head;
3273     DrawTextSCentered(ystart, font_text,
3274                       "Michael Stopp & Philip Jespersen");
3275     ystart += ystep_head;
3276     DrawTextSCentered(ystart, font_head,
3277                       "for creating");
3278     ystart += ystep_head;
3279     DrawTextSCentered(ystart, font_text,
3280                       "\"Supaplex\"");
3281     ystart += ystep_head;
3282     DrawTextSCentered(ystart, font_head,
3283                       "in the year");
3284     ystart += ystep_head;
3285     DrawTextSCentered(ystart, font_text,
3286                       "1991");
3287     ystart += ystep_head;
3288     DrawTextSCentered(ystart, font_head,
3289                       "published by");
3290     ystart += ystep_head;
3291     DrawTextSCentered(ystart, font_text,
3292                       "Digital Integration");
3293   }
3294   else if (screen_nr == 3)
3295   {
3296     DrawTextSCentered(ystart, font_head,
3297                       "Special thanks to");
3298     ystart += ystep_head;
3299     DrawTextSCentered(ystart, font_text,
3300                       "Hiroyuki Imabayashi");
3301     ystart += ystep_head;
3302     DrawTextSCentered(ystart, font_head,
3303                       "for creating");
3304     ystart += ystep_head;
3305     DrawTextSCentered(ystart, font_text,
3306                       "\"Sokoban\"");
3307     ystart += ystep_head;
3308     DrawTextSCentered(ystart, font_head,
3309                       "in the year");
3310     ystart += ystep_head;
3311     DrawTextSCentered(ystart, font_text,
3312                       "1982");
3313     ystart += ystep_head;
3314     DrawTextSCentered(ystart, font_head,
3315                       "published by");
3316     ystart += ystep_head;
3317     DrawTextSCentered(ystart, font_text,
3318                       "Thinking Rabbit");
3319   }
3320   else if (screen_nr == 4)
3321   {
3322     DrawTextSCentered(ystart, font_head,
3323                       "Special thanks to");
3324     ystart += ystep_head;
3325     DrawTextSCentered(ystart, font_text,
3326                       "Alan Bond");
3327     ystart += ystep_head;
3328     DrawTextSCentered(ystart, font_head,
3329                       "and");
3330     ystart += ystep_head;
3331     DrawTextSCentered(ystart, font_text,
3332                       "J\xfcrgen Bonhagen");
3333     ystart += ystep_head;
3334     DrawTextSCentered(ystart, font_head,
3335                       "for the continuous creation");
3336     ystart += ystep_line;
3337     DrawTextSCentered(ystart, font_head,
3338                       "of outstanding level sets");
3339   }
3340   else if (screen_nr == 5)
3341   {
3342     DrawTextSCentered(ystart, font_head,
3343                       "Thanks to");
3344     ystart += ystep_head;
3345     DrawTextSCentered(ystart, font_text,
3346                       "Peter Elzner");
3347     ystart += ystep_head;
3348     DrawTextSCentered(ystart, font_head,
3349                       "for ideas and inspiration by");
3350     ystart += ystep_head;
3351     DrawTextSCentered(ystart, font_text,
3352                       "Diamond Caves");
3353     ystart += ystep_para;
3354
3355     DrawTextSCentered(ystart, font_head,
3356                       "Thanks to");
3357     ystart += ystep_head;
3358     DrawTextSCentered(ystart, font_text,
3359                       "Steffest");
3360     ystart += ystep_head;
3361     DrawTextSCentered(ystart, font_head,
3362                       "for ideas and inspiration by");
3363     ystart += ystep_head;
3364     DrawTextSCentered(ystart, font_text,
3365                       "DX-Boulderdash");
3366   }
3367   else if (screen_nr == 6)
3368   {
3369     DrawTextSCentered(ystart, font_head,
3370                       "Thanks to");
3371     ystart += ystep_head;
3372     DrawTextSCentered(ystart, font_text,
3373                       "David Tritscher");
3374     ystart += ystep_head;
3375     DrawTextSCentered(ystart, font_head,
3376                       "for the code base used for the");
3377     ystart += ystep_line;
3378     DrawTextSCentered(ystart, font_head,
3379                       "native Emerald Mine engine");
3380   }
3381   else if (screen_nr == 7)
3382   {
3383     DrawTextSCentered(ystart, font_head,
3384                       "Thanks to");
3385     ystart += ystep_head;
3386     DrawTextSCentered(ystart, font_text,
3387                       "Guido Schulz");
3388     ystart += ystep_head;
3389     DrawTextSCentered(ystart, font_head,
3390                       "for the initial DOS port");
3391     ystart += ystep_para;
3392
3393     DrawTextSCentered(ystart, font_head,
3394                       "Thanks to");
3395     ystart += ystep_head;
3396     DrawTextSCentered(ystart, font_text,
3397                       "Karl H\xf6rnell");
3398     ystart += ystep_head;
3399     DrawTextSCentered(ystart, font_head,
3400                       "for some additional toons");
3401   }
3402   else if (screen_nr == 8)
3403   {
3404     DrawTextSCentered(ystart, font_head,
3405                       "And not to forget:");
3406     ystart += ystep_head;
3407     DrawTextSCentered(ystart, font_head,
3408                       "Many thanks to");
3409     ystart += ystep_head;
3410     DrawTextSCentered(ystart, font_text,
3411                       "All those who contributed");
3412     ystart += ystep_line;
3413     DrawTextSCentered(ystart, font_text,
3414                       "levels to this game");
3415     ystart += ystep_line;
3416     DrawTextSCentered(ystart, font_text,
3417                       "since 1995");
3418   }
3419
3420   DrawTextSCentered(ybottom, font_foot,
3421                     "Press any key or button for next page");
3422 }
3423
3424 static void DrawInfoScreen_Credits(void)
3425 {
3426   SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_CREDITS);
3427
3428   FadeMenuSoundsAndMusic();
3429
3430   FadeOut(REDRAW_FIELD);
3431
3432   HandleInfoScreen_Credits(MB_MENU_INITIALIZE);
3433
3434   FadeIn(REDRAW_FIELD);
3435 }
3436
3437 void HandleInfoScreen_Credits(int button)
3438 {
3439   static int screen_nr = 0;
3440   int num_screens = 9;
3441
3442   if (button == MB_MENU_INITIALIZE)
3443   {
3444     screen_nr = 0;
3445
3446     // DrawInfoScreen_CreditsScreen(screen_nr);
3447   }
3448
3449   if (button == MB_MENU_LEAVE)
3450   {
3451     PlaySound(SND_MENU_ITEM_SELECTING);
3452
3453     info_mode = INFO_MODE_MAIN;
3454     DrawInfoScreen();
3455
3456     return;
3457   }
3458   else if (button == MB_MENU_CHOICE || button == MB_MENU_INITIALIZE)
3459   {
3460     if (button != MB_MENU_INITIALIZE)
3461     {
3462       PlaySound(SND_MENU_ITEM_SELECTING);
3463
3464       screen_nr++;
3465     }
3466
3467     if (screen_nr >= num_screens)
3468     {
3469       FadeMenuSoundsAndMusic();
3470
3471       info_mode = INFO_MODE_MAIN;
3472       DrawInfoScreen();
3473
3474       return;
3475     }
3476
3477     if (screen_nr > 0)
3478       FadeSetNextScreen();
3479
3480     if (button != MB_MENU_INITIALIZE)
3481       FadeOut(REDRAW_FIELD);
3482
3483     DrawInfoScreen_CreditsScreen(screen_nr);
3484
3485     if (button != MB_MENU_INITIALIZE)
3486       FadeIn(REDRAW_FIELD);
3487   }
3488   else
3489   {
3490     PlayMenuSoundIfLoop();
3491   }
3492 }
3493
3494 static void DrawInfoScreen_Program(void)
3495 {
3496   int font_title = MENU_INFO_FONT_TITLE;
3497   int font_head  = MENU_INFO_FONT_HEAD;
3498   int font_text  = MENU_INFO_FONT_TEXT;
3499   int font_foot  = MENU_INFO_FONT_FOOT;
3500   int spacing_title = menu.headline1_spacing_info[info_mode];
3501   int spacing_head  = menu.headline2_spacing_info[info_mode];
3502   int spacing_para  = menu.paragraph_spacing_info[info_mode];
3503   int spacing_line  = menu.line_spacing_info[info_mode];
3504   int ystep_title = getMenuTextStep(spacing_title, font_title);
3505   int ystep_head  = getMenuTextStep(spacing_head,  font_head);
3506   int ystep_para  = getMenuTextStep(spacing_para,  font_text);
3507   int ystep_line  = getMenuTextStep(spacing_line,  font_text);
3508   int ystart  = mSY - SY + MENU_SCREEN_INFO_YSTART1;
3509   int ybottom = mSY - SY + MENU_SCREEN_INFO_YBOTTOM;
3510
3511   SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_PROGRAM);
3512
3513   FadeOut(REDRAW_FIELD);
3514
3515   ClearField();
3516   DrawHeadline();
3517
3518   DrawTextSCentered(ystart, font_title, "Program Information:");
3519   ystart += ystep_title;
3520
3521   DrawTextSCentered(ystart, font_head,
3522                     "This game is Freeware!");
3523   ystart += ystep_head;
3524   DrawTextSCentered(ystart, font_head,
3525                     "If you like it, send e-mail to:");
3526   ystart += ystep_head;
3527   DrawTextSCentered(ystart, font_text,
3528                     setup.internal.program_email);
3529   ystart += ystep_para;
3530
3531   DrawTextSCentered(ystart, font_head,
3532                     "More information and levels:");
3533   ystart += ystep_head;
3534   DrawTextSCentered(ystart, font_text,
3535                     setup.internal.program_website);
3536   ystart += ystep_para;
3537
3538   DrawTextSCentered(ystart, font_head,
3539                     "If you have created new levels,");
3540   ystart += ystep_line;
3541   DrawTextSCentered(ystart, font_head,
3542                     "send them to me to include them!");
3543   ystart += ystep_head;
3544   DrawTextSCentered(ystart, font_head,
3545                     ":-)");
3546
3547   DrawTextSCentered(ybottom, font_foot,
3548                     "Press any key or button for info menu");
3549
3550   FadeIn(REDRAW_FIELD);
3551 }
3552
3553 void HandleInfoScreen_Program(int button)
3554 {
3555   if (button == MB_MENU_LEAVE)
3556   {
3557     PlaySound(SND_MENU_ITEM_SELECTING);
3558
3559     info_mode = INFO_MODE_MAIN;
3560     DrawInfoScreen();
3561
3562     return;
3563   }
3564   else if (button == MB_MENU_CHOICE)
3565   {
3566     PlaySound(SND_MENU_ITEM_SELECTING);
3567
3568     FadeMenuSoundsAndMusic();
3569
3570     info_mode = INFO_MODE_MAIN;
3571     DrawInfoScreen();
3572   }
3573   else
3574   {
3575     PlayMenuSoundIfLoop();
3576   }
3577 }
3578
3579 static void DrawInfoScreen_Version(void)
3580 {
3581   int font_title = MENU_INFO_FONT_TITLE;
3582   int font_head  = MENU_INFO_FONT_HEAD;
3583   int font_text  = MENU_INFO_FONT_TEXT;
3584   int font_foot  = MENU_INFO_FONT_FOOT;
3585   int spacing_title = menu.headline1_spacing_info[info_mode];
3586   int spacing_head  = menu.headline2_spacing_info[info_mode];
3587   int spacing_para  = menu.paragraph_spacing_info[info_mode];
3588   int spacing_line  = menu.line_spacing_info[info_mode];
3589   int xstep = getFontWidth(font_text);
3590   int ystep_title = getMenuTextStep(spacing_title, font_title);
3591   int ystep_head  = getMenuTextStep(spacing_head,  font_head);
3592   int ystep_para  = getMenuTextStep(spacing_para,  font_text);
3593   int ystep_line  = getMenuTextStep(spacing_line,  font_text);
3594   int ystart  = mSY - SY + MENU_SCREEN_INFO_YSTART1;
3595   int ybottom = mSY - SY + MENU_SCREEN_INFO_YBOTTOM;
3596   int xstart1 = mSX - SX + 2 * xstep;
3597   int xstart2 = mSX - SX + 18 * xstep;
3598   int xstart3 = mSX - SX + 28 * xstep;
3599   SDL_version sdl_version_compiled;
3600   const SDL_version *sdl_version_linked;
3601   int driver_name_len = 10;
3602 #if defined(TARGET_SDL2)
3603   SDL_version sdl_version_linked_ext;
3604   const char *driver_name = NULL;
3605 #else
3606   char driver_name[driver_name_len];
3607 #endif
3608
3609   SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_VERSION);
3610
3611   FadeOut(REDRAW_FIELD);
3612
3613   ClearField();
3614   DrawHeadline();
3615
3616   DrawTextSCentered(ystart, font_title, "Version Information:");
3617   ystart += ystep_title;
3618
3619   DrawTextF(xstart1, ystart, font_head, "Name");
3620   DrawTextF(xstart2, ystart, font_text, getProgramTitleString());
3621   ystart += ystep_line;
3622
3623   if (!strEqual(getProgramVersionString(), getProgramRealVersionString()))
3624   {
3625     DrawTextF(xstart1, ystart, font_head, "Version (fake)");
3626     DrawTextF(xstart2, ystart, font_text, getProgramVersionString());
3627     ystart += ystep_line;
3628
3629     DrawTextF(xstart1, ystart, font_head, "Version (real)");
3630     DrawTextF(xstart2, ystart, font_text, getProgramRealVersionString());
3631     ystart += ystep_line;
3632   }
3633   else
3634   {
3635     DrawTextF(xstart1, ystart, font_head, "Version");
3636     DrawTextF(xstart2, ystart, font_text, getProgramVersionString());
3637     ystart += ystep_line;
3638   }
3639
3640   DrawTextF(xstart1, ystart, font_head, "Platform");
3641   DrawTextF(xstart2, ystart, font_text, PLATFORM_STRING);
3642   ystart += ystep_line;
3643
3644   DrawTextF(xstart1, ystart, font_head, "Target");
3645   DrawTextF(xstart2, ystart, font_text, TARGET_STRING);
3646   ystart += ystep_line;
3647
3648   DrawTextF(xstart1, ystart, font_head, "Source date");
3649   DrawTextF(xstart2, ystart, font_text, getSourceDateString());
3650   ystart += ystep_para;
3651
3652   DrawTextF(xstart1, ystart, font_head, "Library");
3653   DrawTextF(xstart2, ystart, font_head, "compiled");
3654   DrawTextF(xstart3, ystart, font_head, "linked");
3655   ystart += ystep_head;
3656
3657   SDL_VERSION(&sdl_version_compiled);
3658 #if defined(TARGET_SDL2)
3659   SDL_GetVersion(&sdl_version_linked_ext);
3660   sdl_version_linked = &sdl_version_linked_ext;
3661 #else
3662   sdl_version_linked = SDL_Linked_Version();
3663 #endif
3664
3665   DrawTextF(xstart1, ystart, font_text, "SDL");
3666   DrawTextF(xstart2, ystart, font_text, "%d.%d.%d",
3667             sdl_version_compiled.major,
3668             sdl_version_compiled.minor,
3669             sdl_version_compiled.patch);
3670   DrawTextF(xstart3, ystart, font_text, "%d.%d.%d",
3671             sdl_version_linked->major,
3672             sdl_version_linked->minor,
3673             sdl_version_linked->patch);
3674   ystart += ystep_line;
3675
3676   SDL_IMAGE_VERSION(&sdl_version_compiled);
3677   sdl_version_linked = IMG_Linked_Version();
3678
3679   DrawTextF(xstart1, ystart, font_text, "SDL_image");
3680   DrawTextF(xstart2, ystart, font_text, "%d.%d.%d",
3681             sdl_version_compiled.major,
3682             sdl_version_compiled.minor,
3683             sdl_version_compiled.patch);
3684   DrawTextF(xstart3, ystart, font_text, "%d.%d.%d",
3685             sdl_version_linked->major,
3686             sdl_version_linked->minor,
3687             sdl_version_linked->patch);
3688   ystart += ystep_line;
3689
3690   SDL_MIXER_VERSION(&sdl_version_compiled);
3691   sdl_version_linked = Mix_Linked_Version();
3692
3693   DrawTextF(xstart1, ystart, font_text, "SDL_mixer");
3694   DrawTextF(xstart2, ystart, font_text, "%d.%d.%d",
3695             sdl_version_compiled.major,
3696             sdl_version_compiled.minor,
3697             sdl_version_compiled.patch);
3698   DrawTextF(xstart3, ystart, font_text, "%d.%d.%d",
3699             sdl_version_linked->major,
3700             sdl_version_linked->minor,
3701             sdl_version_linked->patch);
3702   ystart += ystep_line;
3703
3704   SDL_NET_VERSION(&sdl_version_compiled);
3705   sdl_version_linked = SDLNet_Linked_Version();
3706
3707   DrawTextF(xstart1, ystart, font_text, "SDL_net");
3708   DrawTextF(xstart2, ystart, font_text, "%d.%d.%d",
3709             sdl_version_compiled.major,
3710             sdl_version_compiled.minor,
3711             sdl_version_compiled.patch);
3712   DrawTextF(xstart3, ystart, font_text, "%d.%d.%d",
3713             sdl_version_linked->major,
3714             sdl_version_linked->minor,
3715             sdl_version_linked->patch);
3716   ystart += ystep_para;
3717
3718   DrawTextF(xstart1, ystart, font_head, "Driver");
3719   DrawTextF(xstart2, ystart, font_head, "Requested");
3720   DrawTextF(xstart3, ystart, font_head, "Used");
3721   ystart += ystep_head;
3722
3723 #if defined(TARGET_SDL2)
3724   driver_name = getStringCopyNStatic(SDL_GetVideoDriver(0), driver_name_len);
3725 #else
3726   SDL_VideoDriverName(driver_name, driver_name_len);
3727 #endif
3728
3729   DrawTextF(xstart1, ystart, font_text, "SDL_VideoDriver");
3730   DrawTextF(xstart2, ystart, font_text, "%s", setup.system.sdl_videodriver);
3731   DrawTextF(xstart3, ystart, font_text, "%s", driver_name);
3732   ystart += ystep_line;
3733
3734 #if defined(TARGET_SDL2)
3735   driver_name = getStringCopyNStatic(SDL_GetAudioDriver(0), driver_name_len);
3736 #else
3737   SDL_AudioDriverName(driver_name, driver_name_len);
3738 #endif
3739
3740   DrawTextF(xstart1, ystart, font_text, "SDL_AudioDriver");
3741   DrawTextF(xstart2, ystart, font_text, "%s", setup.system.sdl_audiodriver);
3742   DrawTextF(xstart3, ystart, font_text, "%s", driver_name);
3743
3744   DrawTextSCentered(ybottom, font_foot,
3745                     "Press any key or button for info menu");
3746
3747   FadeIn(REDRAW_FIELD);
3748 }
3749
3750 void HandleInfoScreen_Version(int button)
3751 {
3752   if (button == MB_MENU_LEAVE)
3753   {
3754     PlaySound(SND_MENU_ITEM_SELECTING);
3755
3756     info_mode = INFO_MODE_MAIN;
3757     DrawInfoScreen();
3758
3759     return;