+ freeSetupFileHash(setup_file_hash);
+ }
+
+ free(filename);
+}
+
+void LoadSetup_EditorCascade(void)
+{
+ char *filename = getPath2(getSetupDir(), EDITORCASCADE_FILENAME);
+ SetupFileHash *setup_file_hash = NULL;
+
+ // always start with reliable default values
+ setSetupInfoToDefaults_EditorCascade(&setup);
+
+ setup_file_hash = loadSetupFileHash(filename);
+
+ if (setup_file_hash)
+ {
+ decodeSetupFileHash_EditorCascade(setup_file_hash);
+
+ freeSetupFileHash(setup_file_hash);
+ }
+
+ free(filename);
+}
+
+static void addGameControllerMappingToHash(SetupFileHash *mappings_hash,
+ char *mapping_line)
+{
+ char mapping_guid[MAX_LINE_LEN];
+ char *mapping_start, *mapping_end;
+
+ // get GUID from game controller mapping line: copy complete line
+ strncpy(mapping_guid, mapping_line, MAX_LINE_LEN - 1);
+ mapping_guid[MAX_LINE_LEN - 1] = '\0';
+
+ // get GUID from game controller mapping line: cut after GUID part
+ mapping_start = strchr(mapping_guid, ',');
+ if (mapping_start != NULL)
+ *mapping_start = '\0';
+
+ // cut newline from game controller mapping line
+ mapping_end = strchr(mapping_line, '\n');
+ if (mapping_end != NULL)
+ *mapping_end = '\0';
+
+ // add mapping entry to game controller mappings hash
+ setHashEntry(mappings_hash, mapping_guid, mapping_line);
+}
+
+static void LoadSetup_ReadGameControllerMappings(SetupFileHash *mappings_hash,
+ char *filename)
+{
+ FILE *file;
+
+ if (!(file = fopen(filename, MODE_READ)))
+ {
+ Error(ERR_WARN, "cannot read game controller mappings file '%s'", filename);
+
+ return;
+ }
+
+ while (!feof(file))
+ {
+ char line[MAX_LINE_LEN];
+
+ if (!fgets(line, MAX_LINE_LEN, file))
+ break;
+
+ addGameControllerMappingToHash(mappings_hash, line);
+ }
+
+ fclose(file);
+}
+
+void SaveSetup(void)
+{
+ char *filename = getSetupFilename();
+ FILE *file;
+ int i, pnr;
+
+ InitUserDataDirectory();
+
+ if (!(file = fopen(filename, MODE_WRITE)))
+ {
+ Error(ERR_WARN, "cannot write setup file '%s'", filename);
+ return;
+ }
+
+ fprintFileHeader(file, SETUP_FILENAME);
+
+ // global setup
+ si = setup;
+ for (i = 0; i < ARRAY_SIZE(global_setup_tokens); i++)
+ {
+ // just to make things nicer :)
+ if (global_setup_tokens[i].value == &si.sound ||
+ global_setup_tokens[i].value == &si.graphics_set ||
+ global_setup_tokens[i].value == &si.volume_simple ||
+ global_setup_tokens[i].value == &si.network_mode ||
+ global_setup_tokens[i].value == &si.touch.control_type ||
+ global_setup_tokens[i].value == &si.touch.grid_xsize[0] ||
+ global_setup_tokens[i].value == &si.touch.grid_xsize[1])
+ fprintf(file, "\n");
+
+ fprintf(file, "%s\n", getSetupLine(global_setup_tokens, "", i));
+ }
+
+ // virtual buttons setup
+ for (i = 0; i < 2; i++)
+ {
+ int grid_xsize = setup.touch.grid_xsize[i];
+ int grid_ysize = setup.touch.grid_ysize[i];
+ int x, y;
+
+ fprintf(file, "\n");
+
+ for (y = 0; y < grid_ysize; y++)
+ {
+ char token_string[MAX_LINE_LEN];
+ char value_string[MAX_LINE_LEN];
+
+ sprintf(token_string, "touch.virtual_buttons.%d.%02d", i, y);
+
+ for (x = 0; x < grid_xsize; x++)
+ {
+ char c = setup.touch.grid_button[i][x][y];
+
+ value_string[x] = (c == CHAR_GRID_BUTTON_NONE ? '.' : c);
+ }
+
+ value_string[grid_xsize] = '\0';
+
+ fprintf(file, "%s\n", getFormattedSetupEntry(token_string, value_string));
+ }
+ }
+
+ // editor setup
+ sei = setup.editor;
+ fprintf(file, "\n");
+ for (i = 0; i < ARRAY_SIZE(editor_setup_tokens); i++)
+ fprintf(file, "%s\n", getSetupLine(editor_setup_tokens, "", i));
+
+ // shortcut setup
+ ssi = setup.shortcut;
+ fprintf(file, "\n");
+ for (i = 0; i < ARRAY_SIZE(shortcut_setup_tokens); i++)
+ fprintf(file, "%s\n", getSetupLine(shortcut_setup_tokens, "", i));
+
+ // player setup
+ for (pnr = 0; pnr < MAX_PLAYERS; pnr++)
+ {
+ char prefix[30];
+
+ sprintf(prefix, "%s%d", TOKEN_STR_PLAYER_PREFIX, pnr + 1);
+ fprintf(file, "\n");
+
+ sii = setup.input[pnr];
+ for (i = 0; i < ARRAY_SIZE(player_setup_tokens); i++)
+ fprintf(file, "%s\n", getSetupLine(player_setup_tokens, prefix, i));
+ }
+
+ // system setup
+ syi = setup.system;
+ fprintf(file, "\n");
+ for (i = 0; i < ARRAY_SIZE(system_setup_tokens); i++)
+ fprintf(file, "%s\n", getSetupLine(system_setup_tokens, "", i));
+
+ // internal setup
+ // (internal setup values not saved to user setup file)
+
+ // debug setup
+ sdi = setup.debug;
+ fprintf(file, "\n");
+ for (i = 0; i < ARRAY_SIZE(debug_setup_tokens); i++)
+ fprintf(file, "%s\n", getSetupLine(debug_setup_tokens, "", i));
+
+ // options setup
+ soi = setup.options;
+ fprintf(file, "\n");
+ for (i = 0; i < ARRAY_SIZE(options_setup_tokens); i++)
+ fprintf(file, "%s\n", getSetupLine(options_setup_tokens, "", i));
+
+ fclose(file);
+
+ SetFilePermissions(filename, PERMS_PRIVATE);
+}
+
+void SaveSetup_AutoSetup(void)
+{
+ char *filename = getPath2(getSetupDir(), AUTOSETUP_FILENAME);
+ FILE *file;
+ int i;
+
+ InitUserDataDirectory();
+
+ if (!(file = fopen(filename, MODE_WRITE)))
+ {
+ Error(ERR_WARN, "cannot write auto setup file '%s'", filename);
+ free(filename);
+ return;
+ }
+
+ fprintFileHeader(file, AUTOSETUP_FILENAME);
+
+ sasi = setup.auto_setup;
+ for (i = 0; i < ARRAY_SIZE(auto_setup_tokens); i++)
+ fprintf(file, "%s\n", getSetupLine(auto_setup_tokens, "", i));
+
+ fclose(file);
+
+ SetFilePermissions(filename, PERMS_PRIVATE);
+
+ free(filename);
+}
+
+void SaveSetup_EditorCascade(void)
+{
+ char *filename = getPath2(getSetupDir(), EDITORCASCADE_FILENAME);
+ FILE *file;
+ int i;
+
+ InitUserDataDirectory();
+
+ if (!(file = fopen(filename, MODE_WRITE)))
+ {
+ Error(ERR_WARN, "cannot write editor cascade state file '%s'", filename);
+ free(filename);
+ return;
+ }
+
+ fprintFileHeader(file, EDITORCASCADE_FILENAME);
+
+ seci = setup.editor_cascade;
+ for (i = 0; i < ARRAY_SIZE(editor_cascade_setup_tokens); i++)
+ fprintf(file, "%s\n", getSetupLine(editor_cascade_setup_tokens, "", i));
+
+ fclose(file);
+
+ SetFilePermissions(filename, PERMS_PRIVATE);
+
+ free(filename);
+}
+
+static void SaveSetup_WriteGameControllerMappings(SetupFileHash *mappings_hash,
+ char *filename)
+{
+ FILE *file;
+
+ if (!(file = fopen(filename, MODE_WRITE)))
+ {
+ Error(ERR_WARN, "cannot write game controller mappings file '%s'",filename);
+
+ return;
+ }
+
+ BEGIN_HASH_ITERATION(mappings_hash, itr)
+ {
+ fprintf(file, "%s\n", HASH_ITERATION_VALUE(itr));
+ }
+ END_HASH_ITERATION(mappings_hash, itr)
+
+ fclose(file);
+}
+
+void SaveSetup_AddGameControllerMapping(char *mapping)
+{
+ char *filename = getPath2(getSetupDir(), GAMECONTROLLER_BASENAME);
+ SetupFileHash *mappings_hash = newSetupFileHash();
+
+ InitUserDataDirectory();
+
+ // load existing personal game controller mappings
+ LoadSetup_ReadGameControllerMappings(mappings_hash, filename);
+
+ // add new mapping to personal game controller mappings
+ addGameControllerMappingToHash(mappings_hash, mapping);
+
+ // save updated personal game controller mappings
+ SaveSetup_WriteGameControllerMappings(mappings_hash, filename);
+
+ freeSetupFileHash(mappings_hash);
+ free(filename);
+}
+
+void LoadCustomElementDescriptions(void)
+{
+ char *filename = getCustomArtworkConfigFilename(ARTWORK_TYPE_GRAPHICS);
+ SetupFileHash *setup_file_hash;
+ int i;
+
+ for (i = 0; i < NUM_FILE_ELEMENTS; i++)
+ {
+ if (element_info[i].custom_description != NULL)
+ {
+ free(element_info[i].custom_description);
+ element_info[i].custom_description = NULL;
+ }
+ }
+
+ if ((setup_file_hash = loadSetupFileHash(filename)) == NULL)
+ return;
+
+ for (i = 0; i < NUM_FILE_ELEMENTS; i++)
+ {
+ char *token = getStringCat2(element_info[i].token_name, ".name");
+ char *value = getHashEntry(setup_file_hash, token);
+
+ if (value != NULL)
+ element_info[i].custom_description = getStringCopy(value);
+
+ free(token);
+ }
+
+ freeSetupFileHash(setup_file_hash);
+}
+
+static int getElementFromToken(char *token)
+{
+ char *value = getHashEntry(element_token_hash, token);
+
+ if (value != NULL)
+ return atoi(value);
+
+ Error(ERR_WARN, "unknown element token '%s'", token);
+
+ return EL_UNDEFINED;
+}
+
+static int get_token_parameter_value(char *token, char *value_raw)
+{
+ char *suffix;
+
+ if (token == NULL || value_raw == NULL)
+ return ARG_UNDEFINED_VALUE;
+
+ suffix = strrchr(token, '.');
+ if (suffix == NULL)
+ suffix = token;
+
+ if (strEqual(suffix, ".element"))
+ return getElementFromToken(value_raw);
+
+ // !!! USE CORRECT VALUE TYPE (currently works also for TYPE_BOOLEAN) !!!
+ return get_parameter_value(value_raw, suffix, TYPE_INTEGER);
+}
+
+void InitMenuDesignSettings_Static(void)
+{
+ int i;
+
+ // always start with reliable default values from static default config
+ for (i = 0; image_config_vars[i].token != NULL; i++)
+ {
+ char *value = getHashEntry(image_config_hash, image_config_vars[i].token);
+
+ if (value != NULL)
+ *image_config_vars[i].value =
+ get_token_parameter_value(image_config_vars[i].token, value);
+ }
+}
+
+static void InitMenuDesignSettings_SpecialPreProcessing(void)
+{
+ int i;
+
+ // the following initializes hierarchical values from static configuration
+
+ // special case: initialize "ARG_DEFAULT" values in static default config
+ // (e.g., initialize "[titlemessage].fade_mode" from "[title].fade_mode")
+ titlescreen_initial_first_default.fade_mode =
+ title_initial_first_default.fade_mode;
+ titlescreen_initial_first_default.fade_delay =
+ title_initial_first_default.fade_delay;
+ titlescreen_initial_first_default.post_delay =
+ title_initial_first_default.post_delay;
+ titlescreen_initial_first_default.auto_delay =
+ title_initial_first_default.auto_delay;
+ titlescreen_first_default.fade_mode = title_first_default.fade_mode;
+ titlescreen_first_default.fade_delay = title_first_default.fade_delay;
+ titlescreen_first_default.post_delay = title_first_default.post_delay;
+ titlescreen_first_default.auto_delay = title_first_default.auto_delay;
+ titlemessage_initial_first_default.fade_mode =
+ title_initial_first_default.fade_mode;
+ titlemessage_initial_first_default.fade_delay =
+ title_initial_first_default.fade_delay;
+ titlemessage_initial_first_default.post_delay =
+ title_initial_first_default.post_delay;
+ titlemessage_initial_first_default.auto_delay =
+ title_initial_first_default.auto_delay;
+ titlemessage_first_default.fade_mode = title_first_default.fade_mode;
+ titlemessage_first_default.fade_delay = title_first_default.fade_delay;
+ titlemessage_first_default.post_delay = title_first_default.post_delay;
+ titlemessage_first_default.auto_delay = title_first_default.auto_delay;
+
+ titlescreen_initial_default.fade_mode = title_initial_default.fade_mode;
+ titlescreen_initial_default.fade_delay = title_initial_default.fade_delay;
+ titlescreen_initial_default.post_delay = title_initial_default.post_delay;
+ titlescreen_initial_default.auto_delay = title_initial_default.auto_delay;
+ titlescreen_default.fade_mode = title_default.fade_mode;
+ titlescreen_default.fade_delay = title_default.fade_delay;
+ titlescreen_default.post_delay = title_default.post_delay;
+ titlescreen_default.auto_delay = title_default.auto_delay;
+ titlemessage_initial_default.fade_mode = title_initial_default.fade_mode;
+ titlemessage_initial_default.fade_delay = title_initial_default.fade_delay;
+ titlemessage_initial_default.post_delay = title_initial_default.post_delay;
+ titlemessage_initial_default.auto_delay = title_initial_default.auto_delay;
+ titlemessage_default.fade_mode = title_default.fade_mode;
+ titlemessage_default.fade_delay = title_default.fade_delay;
+ titlemessage_default.post_delay = title_default.post_delay;
+ titlemessage_default.auto_delay = title_default.auto_delay;
+
+ // special case: initialize "ARG_DEFAULT" values in static default config
+ // (e.g., init "titlemessage_1.fade_mode" from "[titlemessage].fade_mode")
+ for (i = 0; i < MAX_NUM_TITLE_MESSAGES; i++)
+ {
+ titlescreen_initial_first[i] = titlescreen_initial_first_default;
+ titlescreen_first[i] = titlescreen_first_default;
+ titlemessage_initial_first[i] = titlemessage_initial_first_default;
+ titlemessage_first[i] = titlemessage_first_default;
+
+ titlescreen_initial[i] = titlescreen_initial_default;
+ titlescreen[i] = titlescreen_default;
+ titlemessage_initial[i] = titlemessage_initial_default;
+ titlemessage[i] = titlemessage_default;
+ }
+
+ // special case: initialize "ARG_DEFAULT" values in static default config
+ // (eg, init "menu.enter_screen.SCORES.xyz" from "menu.enter_screen.xyz")
+ for (i = 0; i < NUM_SPECIAL_GFX_ARGS; i++)
+ {
+ if (i == GFX_SPECIAL_ARG_TITLE) // title values already initialized
+ continue;
+
+ menu.enter_screen[i] = menu.enter_screen[GFX_SPECIAL_ARG_DEFAULT];
+ menu.leave_screen[i] = menu.leave_screen[GFX_SPECIAL_ARG_DEFAULT];
+ menu.next_screen[i] = menu.next_screen[GFX_SPECIAL_ARG_DEFAULT];
+ }
+
+ // special case: initialize "ARG_DEFAULT" values in static default config
+ // (eg, init "viewport.door_1.MAIN.xyz" from "viewport.door_1.xyz")
+ for (i = 0; i < NUM_SPECIAL_GFX_ARGS; i++)
+ {
+ viewport.window[i] = viewport.window[GFX_SPECIAL_ARG_DEFAULT];
+ viewport.playfield[i] = viewport.playfield[GFX_SPECIAL_ARG_DEFAULT];
+ viewport.door_1[i] = viewport.door_1[GFX_SPECIAL_ARG_DEFAULT];
+
+ if (i == GFX_SPECIAL_ARG_EDITOR) // editor values already initialized
+ continue;
+
+ viewport.door_2[i] = viewport.door_2[GFX_SPECIAL_ARG_DEFAULT];
+ }
+}
+
+static void InitMenuDesignSettings_SpecialPostProcessing(void)
+{
+ static struct
+ {
+ struct XY *dst, *src;
+ }
+ game_buttons_xy[] =
+ {
+ { &game.button.save, &game.button.stop },
+ { &game.button.pause2, &game.button.pause },
+ { &game.button.load, &game.button.play },
+ { &game.button.undo, &game.button.stop },
+ { &game.button.redo, &game.button.play },
+
+ { NULL, NULL }
+ };
+ int i, j;
+
+ // special case: initialize later added SETUP list size from LEVELS value
+ if (menu.list_size[GAME_MODE_SETUP] == -1)
+ menu.list_size[GAME_MODE_SETUP] = menu.list_size[GAME_MODE_LEVELS];
+
+ // set default position for snapshot buttons to stop/pause/play buttons
+ for (i = 0; game_buttons_xy[i].dst != NULL; i++)
+ if ((*game_buttons_xy[i].dst).x == -1 &&
+ (*game_buttons_xy[i].dst).y == -1)
+ *game_buttons_xy[i].dst = *game_buttons_xy[i].src;
+
+ // --------------------------------------------------------------------------
+ // dynamic viewports (including playfield margins, borders and alignments)
+ // --------------------------------------------------------------------------
+
+ // dynamic viewports currently only supported for landscape mode
+ int display_width = MAX(video.display_width, video.display_height);
+ int display_height = MIN(video.display_width, video.display_height);
+
+ for (i = 0; i < NUM_SPECIAL_GFX_ARGS; i++)
+ {
+ struct RectWithBorder *vp_window = &viewport.window[i];
+ struct RectWithBorder *vp_playfield = &viewport.playfield[i];
+ struct RectWithBorder *vp_door_1 = &viewport.door_1[i];
+ struct RectWithBorder *vp_door_2 = &viewport.door_2[i];
+ boolean dynamic_window_width = (vp_window->min_width != -1);
+ boolean dynamic_window_height = (vp_window->min_height != -1);
+ boolean dynamic_playfield_width = (vp_playfield->min_width != -1);
+ boolean dynamic_playfield_height = (vp_playfield->min_height != -1);
+
+ // adjust window size if min/max width/height is specified
+
+ if (vp_window->min_width != -1)
+ {
+ int window_width = display_width;
+
+ // when using static window height, use aspect ratio of display
+ if (vp_window->min_height == -1)
+ window_width = vp_window->height * display_width / display_height;
+
+ vp_window->width = MAX(vp_window->min_width, window_width);
+ }
+
+ if (vp_window->min_height != -1)
+ {
+ int window_height = display_height;
+
+ // when using static window width, use aspect ratio of display
+ if (vp_window->min_width == -1)
+ window_height = vp_window->width * display_height / display_width;
+
+ vp_window->height = MAX(vp_window->min_height, window_height);
+ }
+
+ if (vp_window->max_width != -1)
+ vp_window->width = MIN(vp_window->width, vp_window->max_width);
+
+ if (vp_window->max_height != -1)
+ vp_window->height = MIN(vp_window->height, vp_window->max_height);
+
+ int playfield_width = vp_window->width;
+ int playfield_height = vp_window->height;
+
+ // adjust playfield size and position according to specified margins
+
+ playfield_width -= vp_playfield->margin_left;
+ playfield_width -= vp_playfield->margin_right;
+
+ playfield_height -= vp_playfield->margin_top;
+ playfield_height -= vp_playfield->margin_bottom;
+
+ // adjust playfield size if min/max width/height is specified
+
+ if (vp_playfield->min_width != -1)
+ vp_playfield->width = MAX(vp_playfield->min_width, playfield_width);
+
+ if (vp_playfield->min_height != -1)
+ vp_playfield->height = MAX(vp_playfield->min_height, playfield_height);
+
+ if (vp_playfield->max_width != -1)
+ vp_playfield->width = MIN(vp_playfield->width, vp_playfield->max_width);
+
+ if (vp_playfield->max_height != -1)
+ vp_playfield->height = MIN(vp_playfield->height,vp_playfield->max_height);
+
+ // adjust playfield position according to specified alignment
+
+ if (vp_playfield->align == ALIGN_LEFT || vp_playfield->x > 0)
+ vp_playfield->x = ALIGNED_VP_XPOS(vp_playfield);
+ else if (vp_playfield->align == ALIGN_CENTER)
+ vp_playfield->x = playfield_width / 2 - vp_playfield->width / 2;
+ else if (vp_playfield->align == ALIGN_RIGHT)
+ vp_playfield->x += playfield_width - vp_playfield->width;
+
+ if (vp_playfield->valign == VALIGN_TOP || vp_playfield->y > 0)
+ vp_playfield->y = ALIGNED_VP_YPOS(vp_playfield);
+ else if (vp_playfield->valign == VALIGN_MIDDLE)
+ vp_playfield->y = playfield_height / 2 - vp_playfield->height / 2;
+ else if (vp_playfield->valign == VALIGN_BOTTOM)
+ vp_playfield->y += playfield_height - vp_playfield->height;
+
+ vp_playfield->x += vp_playfield->margin_left;
+ vp_playfield->y += vp_playfield->margin_top;
+
+ // adjust individual playfield borders if only default border is specified
+
+ if (vp_playfield->border_left == -1)
+ vp_playfield->border_left = vp_playfield->border_size;
+ if (vp_playfield->border_right == -1)
+ vp_playfield->border_right = vp_playfield->border_size;
+ if (vp_playfield->border_top == -1)
+ vp_playfield->border_top = vp_playfield->border_size;
+ if (vp_playfield->border_bottom == -1)
+ vp_playfield->border_bottom = vp_playfield->border_size;
+
+ // set dynamic playfield borders if borders are specified as undefined
+ // (but only if window size was dynamic and playfield size was static)
+
+ if (dynamic_window_width && !dynamic_playfield_width)
+ {
+ if (vp_playfield->border_left == -1)
+ {
+ vp_playfield->border_left = (vp_playfield->x -
+ vp_playfield->margin_left);
+ vp_playfield->x -= vp_playfield->border_left;
+ vp_playfield->width += vp_playfield->border_left;
+ }
+
+ if (vp_playfield->border_right == -1)
+ {
+ vp_playfield->border_right = (vp_window->width -
+ vp_playfield->x -
+ vp_playfield->width -
+ vp_playfield->margin_right);
+ vp_playfield->width += vp_playfield->border_right;
+ }
+ }
+
+ if (dynamic_window_height && !dynamic_playfield_height)
+ {
+ if (vp_playfield->border_top == -1)
+ {
+ vp_playfield->border_top = (vp_playfield->y -
+ vp_playfield->margin_top);
+ vp_playfield->y -= vp_playfield->border_top;
+ vp_playfield->height += vp_playfield->border_top;
+ }
+
+ if (vp_playfield->border_bottom == -1)
+ {
+ vp_playfield->border_bottom = (vp_window->height -
+ vp_playfield->y -
+ vp_playfield->height -
+ vp_playfield->margin_bottom);
+ vp_playfield->height += vp_playfield->border_bottom;
+ }
+ }
+
+ // adjust playfield size to be a multiple of a defined alignment tile size
+
+ int align_size = vp_playfield->align_size;
+ int playfield_xtiles = vp_playfield->width / align_size;
+ int playfield_ytiles = vp_playfield->height / align_size;
+ int playfield_width_corrected = playfield_xtiles * align_size;
+ int playfield_height_corrected = playfield_ytiles * align_size;
+ boolean is_playfield_mode = (i == GFX_SPECIAL_ARG_PLAYING ||
+ i == GFX_SPECIAL_ARG_EDITOR);
+
+ if (is_playfield_mode &&
+ dynamic_playfield_width &&
+ vp_playfield->width != playfield_width_corrected)
+ {
+ int playfield_xdiff = vp_playfield->width - playfield_width_corrected;
+
+ vp_playfield->width = playfield_width_corrected;
+
+ if (vp_playfield->align == ALIGN_LEFT)
+ {
+ vp_playfield->border_left += playfield_xdiff;
+ }
+ else if (vp_playfield->align == ALIGN_RIGHT)
+ {
+ vp_playfield->border_right += playfield_xdiff;
+ }
+ else if (vp_playfield->align == ALIGN_CENTER)
+ {
+ int border_left_diff = playfield_xdiff / 2;
+ int border_right_diff = playfield_xdiff - border_left_diff;
+
+ vp_playfield->border_left += border_left_diff;
+ vp_playfield->border_right += border_right_diff;
+ }
+ }
+
+ if (is_playfield_mode &&
+ dynamic_playfield_height &&
+ vp_playfield->height != playfield_height_corrected)
+ {
+ int playfield_ydiff = vp_playfield->height - playfield_height_corrected;
+
+ vp_playfield->height = playfield_height_corrected;
+
+ if (vp_playfield->valign == VALIGN_TOP)
+ {
+ vp_playfield->border_top += playfield_ydiff;
+ }
+ else if (vp_playfield->align == VALIGN_BOTTOM)
+ {
+ vp_playfield->border_right += playfield_ydiff;
+ }
+ else if (vp_playfield->align == VALIGN_MIDDLE)
+ {
+ int border_top_diff = playfield_ydiff / 2;
+ int border_bottom_diff = playfield_ydiff - border_top_diff;
+
+ vp_playfield->border_top += border_top_diff;
+ vp_playfield->border_bottom += border_bottom_diff;
+ }
+ }
+
+ // adjust door positions according to specified alignment
+
+ for (j = 0; j < 2; j++)
+ {
+ struct RectWithBorder *vp_door = (j == 0 ? vp_door_1 : vp_door_2);
+
+ if (vp_door->align == ALIGN_LEFT || vp_door->x > 0)
+ vp_door->x = ALIGNED_VP_XPOS(vp_door);
+ else if (vp_door->align == ALIGN_CENTER)
+ vp_door->x = vp_window->width / 2 - vp_door->width / 2;
+ else if (vp_door->align == ALIGN_RIGHT)
+ vp_door->x += vp_window->width - vp_door->width;
+
+ if (vp_door->valign == VALIGN_TOP || vp_door->y > 0)
+ vp_door->y = ALIGNED_VP_YPOS(vp_door);
+ else if (vp_door->valign == VALIGN_MIDDLE)
+ vp_door->y = vp_window->height / 2 - vp_door->height / 2;
+ else if (vp_door->valign == VALIGN_BOTTOM)
+ vp_door->y += vp_window->height - vp_door->height;
+ }
+ }
+}
+
+static void InitMenuDesignSettings_SpecialPostProcessing_AfterGraphics(void)
+{
+ static struct
+ {
+ struct XYTileSize *dst, *src;
+ int graphic;
+ }
+ editor_buttons_xy[] =
+ {
+ {
+ &editor.button.element_left, &editor.palette.element_left,
+ IMG_GFX_EDITOR_BUTTON_ELEMENT_LEFT
+ },
+ {
+ &editor.button.element_middle, &editor.palette.element_middle,
+ IMG_GFX_EDITOR_BUTTON_ELEMENT_MIDDLE
+ },
+ {
+ &editor.button.element_right, &editor.palette.element_right,
+ IMG_GFX_EDITOR_BUTTON_ELEMENT_RIGHT
+ },
+
+ { NULL, NULL }
+ };
+ int i;
+
+ // set default position for element buttons to element graphics
+ for (i = 0; editor_buttons_xy[i].dst != NULL; i++)
+ {
+ if ((*editor_buttons_xy[i].dst).x == -1 &&
+ (*editor_buttons_xy[i].dst).y == -1)
+ {
+ struct GraphicInfo *gd = &graphic_info[editor_buttons_xy[i].graphic];
+
+ gd->width = gd->height = editor_buttons_xy[i].src->tile_size;
+
+ *editor_buttons_xy[i].dst = *editor_buttons_xy[i].src;
+ }
+ }
+
+ // adjust editor palette rows and columns if specified to be dynamic
+
+ if (editor.palette.cols == -1)
+ {
+ int vp_width = viewport.playfield[GFX_SPECIAL_ARG_EDITOR].width;
+ int bt_width = graphic_info[IMG_EDITOR_PALETTE_BUTTON].width;
+ int sc_width = graphic_info[IMG_EDITOR_PALETTE_SCROLLBAR].width;
+
+ editor.palette.cols = (vp_width - sc_width) / bt_width;
+
+ if (editor.palette.x == -1)
+ {
+ int palette_width = editor.palette.cols * bt_width + sc_width;
+
+ editor.palette.x = (vp_width - palette_width) / 2;
+ }
+ }
+
+ if (editor.palette.rows == -1)
+ {
+ int vp_height = viewport.playfield[GFX_SPECIAL_ARG_EDITOR].height;
+ int bt_height = graphic_info[IMG_EDITOR_PALETTE_BUTTON].height;
+ int tx_height = getFontHeight(FONT_TEXT_2);