+ if (active_text)
+ {
+ button_graphic = BUTTON_GRAPHIC_ACTIVE(button_graphic);
+ font_text = FONT_ACTIVE(font_text);
+ }
+
+ if (active_input)
+ {
+ font_input = FONT_ACTIVE(font_input);
+ }
+
+ if (visibleMenuPos(pos_button))
+ {
+ struct MenuPosInfo *pos = pos_button;
+ int x = mSX + pos->x;
+ int y = mSY + pos->y;
+
+ DrawBackgroundForGraphic(x, y, pos->width, pos->height, button_graphic);
+ DrawGraphicThruMaskExt(drawto, x, y, button_graphic, 0);
+ }
+
+ if (visibleTextPos(pos_text) && text != NULL)
+ {
+ struct TextPosInfo *pos = pos_text;
+ int x = mSX + ALIGNED_TEXT_XPOS(pos);
+ int y = mSY + ALIGNED_TEXT_YPOS(pos);
+
+#if 1
+ /* (check why/if this is needed) */
+ DrawBackgroundForFont(x, y, pos->width, pos->height, font_text);
+#endif
+ DrawText(x, y, text, font_text);
+ }
+
+ if (visibleTextPos(pos_input) && input != NULL)
+ {
+ struct TextPosInfo *pos = pos_input;
+ int x = mSX + ALIGNED_TEXT_XPOS(pos);
+ int y = mSY + ALIGNED_TEXT_YPOS(pos);
+
+#if 1
+ /* (check why/if this is needed) */
+ DrawBackgroundForFont(x, y, pos->width, pos->height, font_input);
+#endif
+ DrawText(x, y, input, font_input);
+ }
+ }
+ }
+}
+
+static void DrawCursorAndText_Main(int nr, boolean active_text)
+{
+ DrawCursorAndText_Main_Ext(nr, active_text, FALSE);
+}
+
+#if 0
+static void DrawCursorAndText_Main_Input(int nr, boolean active_text)
+{
+ DrawCursorAndText_Main_Ext(nr, active_text, TRUE);
+}
+#endif
+
+static struct MainControlInfo *getMainControlInfo(int nr)
+{
+ int i;
+
+ for (i = 0; main_controls[i].nr != -1; i++)
+ if (main_controls[i].nr == nr)
+ return &main_controls[i];
+
+ return NULL;
+}
+
+static boolean insideMenuPosRect(struct MenuPosInfo *rect, int x, int y)
+{
+ if (rect == NULL)
+ return FALSE;
+
+ int rect_x = ALIGNED_TEXT_XPOS(rect);
+ int rect_y = ALIGNED_TEXT_YPOS(rect);
+
+ return (x >= rect_x && x < rect_x + rect->width &&
+ y >= rect_y && y < rect_y + rect->height);
+}
+
+static boolean insideTextPosRect(struct TextPosInfo *rect, int x, int y)
+{
+ if (rect == NULL)
+ return FALSE;
+
+ int rect_x = ALIGNED_TEXT_XPOS(rect);
+ int rect_y = ALIGNED_TEXT_YPOS(rect);
+
+ return (x >= rect_x && x < rect_x + rect->width &&
+ y >= rect_y && y < rect_y + rect->height);
+}
+
+static void drawCursorExt(int xpos, int ypos, boolean active, int graphic)
+{
+ static int cursor_array[SCR_FIELDY];
+ int x = mSX + TILEX * xpos;
+ int y = mSY + TILEY * (MENU_SCREEN_START_YPOS + ypos);
+
+ if (xpos == 0)
+ {
+ if (graphic != -1)
+ cursor_array[ypos] = graphic;
+ else
+ graphic = cursor_array[ypos];
+ }
+
+ if (active)
+ graphic = BUTTON_GRAPHIC_ACTIVE(graphic);
+
+ DrawBackgroundForGraphic(x, y, TILEX, TILEY, graphic);
+ DrawGraphicThruMaskExt(drawto, x, y, graphic, 0);
+}
+
+static void initCursor(int ypos, int graphic)
+{
+ drawCursorExt(0, ypos, FALSE, graphic);
+}
+
+static void drawCursor(int ypos, boolean active)
+{
+ drawCursorExt(0, ypos, active, -1);
+}
+
+static void drawCursorXY(int xpos, int ypos, int graphic)
+{
+ drawCursorExt(xpos, ypos, FALSE, graphic);
+}
+
+static void drawChooseTreeCursor(int ypos, boolean active)
+{
+ int last_game_status = game_status; /* save current game status */
+
+ /* force LEVELS draw offset on artwork setup screen */
+ game_status = GAME_MODE_LEVELS;
+
+ drawCursorExt(0, ypos, active, -1);
+
+ game_status = last_game_status; /* restore current game status */
+}
+
+void DrawHeadline()
+{
+ DrawTextSCentered(MENU_TITLE1_YPOS, FONT_TITLE_1, PROGRAM_TITLE_STRING);
+ DrawTextSCentered(MENU_TITLE2_YPOS, FONT_TITLE_2, PROGRAM_COPYRIGHT_STRING);
+}
+
+#if 0
+static int getPrevlevelButtonPos()
+{
+ return 10;
+}
+
+static int getCurrentLevelTextPos()
+{
+ return (getPrevlevelButtonPos() + 1);
+}
+
+static int getNextLevelButtonPos()
+{
+ return getPrevlevelButtonPos() + 3 + 1;
+}
+
+static int getLevelRangeTextPos()
+{
+ return getNextLevelButtonPos() + 1;
+}
+#endif
+
+int effectiveGameStatus()
+{
+ if (game_status == GAME_MODE_INFO && info_mode == INFO_MODE_TITLE)
+ return GAME_MODE_TITLE;
+
+ return game_status;
+}
+
+void DrawTitleScreenImage(int nr, boolean initial)
+{
+ int graphic = getTitleScreenGraphic(nr, initial);
+ Bitmap *bitmap = graphic_info[graphic].bitmap;
+#if 1
+ int width = graphic_info[graphic].width;
+ int height = graphic_info[graphic].height;
+ int src_x = graphic_info[graphic].src_x;
+ int src_y = graphic_info[graphic].src_y;
+#else
+ int width = graphic_info[graphic].src_image_width;
+ int height = graphic_info[graphic].src_image_height;
+ int src_x = 0, src_y = 0;
+#endif
+ int dst_x, dst_y;
+
+ if (bitmap == NULL)
+ return;
+
+ if (width > WIN_XSIZE)
+ {
+ /* image width too large for window => center image horizontally */
+ src_x = (width - WIN_XSIZE) / 2;
+ width = WIN_XSIZE;
+ }
+
+ if (height > WIN_YSIZE)
+ {
+ /* image height too large for window => center image vertically */
+ src_y = (height - WIN_YSIZE) / 2;
+ height = WIN_YSIZE;
+ }
+
+ /* always display title screens centered */
+ dst_x = (WIN_XSIZE - width) / 2;
+ dst_y = (WIN_YSIZE - height) / 2;
+
+ SetDrawBackgroundMask(REDRAW_ALL);
+ SetWindowBackgroundImage(getTitleBackground(nr, initial, TRUE));
+
+ ClearRectangleOnBackground(drawto, 0, 0, WIN_XSIZE, WIN_YSIZE);
+
+ if (DrawingOnBackground(dst_x, dst_y))
+ BlitBitmapMasked(bitmap, drawto, src_x, src_y, width, height, dst_x, dst_y);
+ else
+ BlitBitmap(bitmap, drawto, src_x, src_y, width, height, dst_x, dst_y);
+
+ redraw_mask = REDRAW_ALL;
+
+ /* reset fading control values to default config settings */
+#if 1
+
+#if 0
+ title = getTitleFading(nr, initial, TRUE);
+#endif
+
+#else
+
+ title.fade_delay_final = title.fade_delay;
+ title.post_delay_final = title.post_delay;
+ title.auto_delay_final = title.auto_delay;
+
+ /* override default settings with image config settings, if defined */
+ if (graphic_info[graphic].anim_mode != ANIM_DEFAULT)
+ title.anim_mode = graphic_info[graphic].anim_mode;
+ if (graphic_info[graphic].fade_delay > -1)
+ title.fade_delay = graphic_info[graphic].fade_delay;
+ if (graphic_info[graphic].post_delay > -1)
+ title.post_delay = graphic_info[graphic].post_delay;
+ if (graphic_info[graphic].auto_delay > -1)
+ title.auto_delay = graphic_info[graphic].auto_delay;
+#endif
+}
+
+void DrawTitleScreenMessage(int nr, boolean initial)
+{
+ char *filename = getLevelSetTitleMessageFilename(nr, initial);
+ struct TitleMessageInfo *tmi = getTitleMessageInfo(nr, initial);
+#if 0
+ int font_nr = FONT_TEXT_1;
+ int font_width;
+ int font_height;
+ int pad_x = 16 + 4;
+ int pad_y = 32 + 14;
+ int sx = pad_x;
+ int sy = pad_y;
+ int max_chars_per_line;
+ int max_lines_per_screen;
+#endif
+ int last_game_status = game_status; /* save current game status */
+
+ if (filename == NULL)
+ return;
+
+ /* force TITLE font on title message screen */
+ game_status = getTitleMessageGameMode(initial);
+
+ /* if chars set to "-1", automatically determine by text and font width */
+ if (tmi->chars == -1)
+ tmi->chars = tmi->width / getFontWidth(tmi->font);
+ else
+ tmi->width = tmi->chars * getFontWidth(tmi->font);
+
+ /* if lines set to "-1", automatically determine by text and font height */
+ if (tmi->lines == -1)
+ tmi->lines = tmi->height / getFontHeight(tmi->font);
+ else
+ tmi->height = tmi->lines * getFontHeight(tmi->font);
+
+ SetDrawBackgroundMask(REDRAW_ALL);
+ SetWindowBackgroundImage(getTitleBackground(nr, initial, FALSE));
+
+ ClearRectangleOnBackground(drawto, 0, 0, WIN_XSIZE, WIN_YSIZE);
+
+#if 0
+ font_width = getFontWidth(font_nr);
+ font_height = getFontHeight(font_nr);
+ max_chars_per_line = (WIN_XSIZE - 2 * pad_x) / font_width;
+ max_lines_per_screen = (WIN_YSIZE - pad_y) / font_height - 1;
+#endif
+
+#if 1
+ DrawTextFile(ALIGNED_TEXT_XPOS(tmi), ALIGNED_TEXT_YPOS(tmi),
+ filename, tmi->font, tmi->chars, -1, tmi->lines, -1,
+ tmi->autowrap, tmi->centered, tmi->parse_comments);
+#else
+ DrawTextFile(sx, sy, filename, font_nr, max_chars_per_line, -1,
+ max_lines_per_screen, -1, tmi->autowrap, tmi->centered,
+ tmi->parse_comments);
+#endif
+
+ game_status = last_game_status; /* restore current game status */
+}
+
+void DrawTitleScreen()
+{
+ KeyboardAutoRepeatOff();
+
+#if 0
+ SetMainBackgroundImage(IMG_BACKGROUND_TITLE);
+#endif
+
+ HandleTitleScreen(0, 0, 0, 0, MB_MENU_INITIALIZE);
+
+ StopAnimation();
+}
+
+boolean CheckTitleScreen(boolean levelset_has_changed)
+{
+ static boolean show_title_initial = TRUE;
+ boolean show_titlescreen = FALSE;
+
+ /* needed to be able to skip title screen, if no image or message defined */
+ InitializeTitleControls(show_title_initial);
+
+ if (setup.show_titlescreen && (show_title_initial || levelset_has_changed))
+ show_titlescreen = TRUE;
+
+ /* show initial title images and messages only once at program start */
+ show_title_initial = FALSE;
+
+ return (show_titlescreen && num_title_screens > 0);
+}
+
+void DrawMainMenuExt(int redraw_mask, boolean do_fading)
+{
+ static LevelDirTree *leveldir_last_valid = NULL;
+ boolean levelset_has_changed = FALSE;
+#if 0
+ boolean local_team_mode = (!options.network && setup.team_mode);
+ char *name_text = (local_team_mode ? "Team:" : "Name:");
+ int name_width, level_width;
+#endif
+#if 0
+ int i;
+#endif
+
+#if 0
+ /* !!! CHANGE THIS !!! */
+ title = title_default;
+#endif
+
+#if 0
+ printf("::: %d, %d\n", fading.anim_mode == ANIM_CROSSFADE,
+ redraw_mask == REDRAW_ALL);
+#endif
+
+ FadeSetLeaveScreen();
+
+#if 1
+ FadeOut(redraw_mask);
+#endif
+
+ UnmapAllGadgets();
+ FadeSoundsAndMusic();
+
+ KeyboardAutoRepeatOn();
+ ActivateJoystick();
+
+ SetDrawDeactivationMask(REDRAW_NONE);
+ SetDrawBackgroundMask(REDRAW_FIELD);
+
+ audio.sound_deactivated = FALSE;
+
+ GetPlayerConfig();
+
+ /* needed if last screen was the playing screen, invoked from level editor */
+ if (level_editor_test_game)
+ {
+ game_status = GAME_MODE_EDITOR;
+ DrawLevelEd();
+
+ return;
+ }
+
+ /* needed if last screen was the editor screen */
+ UndrawSpecialEditorDoor();
+
+ /* needed if last screen was the setup screen and fullscreen state changed */
+ ToggleFullscreenIfNeeded();
+
+ /* leveldir_current may be invalid (level group, parent link) */
+ if (!validLevelSeries(leveldir_current))
+ leveldir_current = getFirstValidTreeInfoEntry(leveldir_last_valid);
+
+ if (leveldir_current != leveldir_last_valid)
+ levelset_has_changed = TRUE;
+
+ /* store valid level series information */
+ leveldir_last_valid = leveldir_current;
+
+ /* needed if last screen (level choice) changed graphics, sounds or music */
+ ReloadCustomArtwork(0);
+
+#if defined(TARGET_SDL)
+ SetDrawtoField(DRAW_BACKBUFFER);
+#endif
+
+#if 0
+ if (levelset_has_changed)
+ fading = title_default;
+#endif
+
+#if 1
+ if (CheckTitleScreen(levelset_has_changed))
+ {
+ game_status = GAME_MODE_TITLE;
+
+ DrawTitleScreen();
+
+ return;
+ }
+
+#else
+
+ if (setup.show_titlescreen &&
+ ((levelset_has_changed &&
+ (graphic_info[IMG_TITLESCREEN_1].bitmap != NULL ||
+ getLevelSetMessageFilename(1, FALSE) != NULL)) ||
+ (show_title_initial &&
+ (graphic_info[IMG_TITLESCREEN_INITIAL_1].bitmap != NULL ||
+ getLevelSetMessageFilename(1, TRUE) != NULL))))
+ {
+ game_status = GAME_MODE_TITLE;
+
+ DrawTitleScreen();
+
+ return;
+ }
+#endif
+
+ /* level_nr may have been set to value over handicap with level editor */
+ if (setup.handicap && level_nr > leveldir_current->handicap_level)
+ level_nr = leveldir_current->handicap_level;
+
+ LoadLevel(level_nr);
+
+ SetMainBackgroundImage(IMG_BACKGROUND_MAIN);
+
+#if 0
+ FadeOut(redraw_mask);
+#endif
+
+#if 1
+ if (redraw_mask == REDRAW_ALL)
+ {
+#if 0
+ int door_state = GetDoorState();
+#endif
+
+ RedrawBackground();
+
+ // OpenDoor(door_state | DOOR_NO_DELAY | DOOR_FORCE_REDRAW);
+
+#if 0
+#if 1
+ OpenDoor(DOOR_NO_DELAY | DOOR_FORCE_REDRAW);
+#else
+ OpenDoor(DOOR_CLOSE_1 | DOOR_CLOSE_2 | DOOR_NO_DELAY | DOOR_FORCE_REDRAW);
+#endif
+#endif
+ }
+#endif
+
+ ClearWindow();
+
+#if 1
+ InitializeMainControls();
+
+#if 1
+ DrawCursorAndText_Main(-1, FALSE);
+#else
+ for (i = 0; main_controls[i].nr != -1; i++)
+ {
+ struct MenuPosInfo *pos_button = main_controls[i].pos_button;
+ struct MenuPosInfo *pos_text = main_controls[i].pos_text;
+ struct MenuPosInfo *pos_input = main_controls[i].pos_input;
+ char *text = main_controls[i].text;
+ char *input = main_controls[i].input;
+ int button_graphic = main_controls[i].button_graphic;
+ int font_text = main_controls[i].font_text;
+ int font_input = main_controls[i].font_input;
+
+ if (pos_button != NULL)
+ DrawGraphicThruMaskExt(drawto, mSX + pos_button->x, mSY + pos_button->y,
+ button_graphic, 0);
+
+ if (pos_text != NULL && text != NULL)
+ DrawText(mSX + pos_text->x, mSY + pos_text->y, text, font_text);
+
+ if (pos_input != NULL && input != NULL)
+ DrawText(mSX + pos_input->x, mSY + pos_input->y, input, font_input);
+ }
+#endif
+
+#else
+
+ DrawHeadline();