X-Git-Url: https://git.artsoft.org/?a=blobdiff_plain;f=src%2Flibgame%2Fmisc.c;h=0d19ff9c16eadf9844d3ada6371c35e685cb3748;hb=22f539028eb272b70d339e1f37552a2a89f37dd6;hp=ea5ed01a06a8898b9a60bd6a667fee291a9b8c1d;hpb=8e17da8cdff134bfa0e766a50f408a3c06428f54;p=rocksndiamonds.git diff --git a/src/libgame/misc.c b/src/libgame/misc.c index ea5ed01a..0d19ff9c 100644 --- a/src/libgame/misc.c +++ b/src/libgame/misc.c @@ -1900,6 +1900,48 @@ int get_auto_parameter_value(char *token, char *value_raw) return get_parameter_value(value_raw, suffix, TYPE_INTEGER); } +struct ScreenModeInfo *get_screen_mode_from_string(char *screen_mode_string) +{ + static struct ScreenModeInfo screen_mode; + char *screen_mode_string_x = strchr(screen_mode_string, 'x'); + char *screen_mode_string_copy; + char *screen_mode_string_pos_w; + char *screen_mode_string_pos_h; + + if (screen_mode_string_x == NULL) /* invalid screen mode format */ + return NULL; + + screen_mode_string_copy = getStringCopy(screen_mode_string); + + screen_mode_string_pos_w = screen_mode_string_copy; + screen_mode_string_pos_h = strchr(screen_mode_string_copy, 'x'); + *screen_mode_string_pos_h++ = '\0'; + + screen_mode.width = atoi(screen_mode_string_pos_w); + screen_mode.height = atoi(screen_mode_string_pos_h); + + return &screen_mode; +} + +void get_aspect_ratio_from_screen_mode(struct ScreenModeInfo *screen_mode, + int *x, int *y) +{ + float aspect_ratio = (float)screen_mode->width / (float)screen_mode->height; + float aspect_ratio_new; + int i = 1; + + do + { + *x = i * aspect_ratio; + *y = i; + + aspect_ratio_new = (float)*x / (float)*y; + + i++; + } + while (aspect_ratio_new != aspect_ratio && *x < screen_mode->width); +} + static void FreeCustomArtworkList(struct ArtworkListInfo *, struct ListNodeInfo ***, int *);