From 51b08cee76e7248dbbdde9e89ec2d162978bbaa0 Mon Sep 17 00:00:00 2001 From: Sebastian Krzyszkowiak Date: Mon, 15 Aug 2016 04:41:54 +0200 Subject: [PATCH] move SetupViewport to utils --- src/internal.c | 33 --------------------------------- src/internal.h | 1 - src/utils.c | 32 ++++++++++++++++++++++++++++++++ src/utils.h | 2 ++ 4 files changed, 34 insertions(+), 34 deletions(-) diff --git a/src/internal.c b/src/internal.c index 69186de..7668ece 100644 --- a/src/internal.c +++ b/src/internal.c @@ -122,39 +122,6 @@ SYMBOL_INTERNAL void Console_Unload(struct Game *game) { al_destroy_bitmap(game->_priv.console); } - -SYMBOL_EXPORT void SetupViewport(struct Game *game) { - game->viewport.width = 320; - game->viewport.height = 180; - - al_clear_to_color(al_map_rgb(0,0,0)); - - int resolution = al_get_display_width(game->display) / 320; - if (al_get_display_height(game->display) / 180 < resolution) resolution = al_get_display_height(game->display) / 180; - if (resolution < 1) resolution = 1; - - if (atoi(GetConfigOptionDefault(game, "SuperDerpy", "letterbox", "1"))) { - int clipWidth = 320 * resolution, clipHeight = 180 * resolution; - int clipX = (al_get_display_width(game->display) - clipWidth) / 2, clipY = (al_get_display_height(game->display) - clipHeight) / 2; - al_set_clipping_rectangle(clipX, clipY, clipWidth, clipHeight); - - al_build_transform(&game->projection, clipX, clipY, resolution, resolution, 0.0f); - al_use_transform(&game->projection); - - } else if ((atoi(GetConfigOptionDefault(game, "SuperDerpy", "rotate", "1"))) && (game->viewport.height > game->viewport.width)) { - al_identity_transform(&game->projection); - al_rotate_transform(&game->projection, 0.5*ALLEGRO_PI); - al_translate_transform(&game->projection, game->viewport.width, 0); - al_scale_transform(&game->projection, resolution, resolution); - al_use_transform(&game->projection); - int temp = game->viewport.height; - game->viewport.height = game->viewport.width; - game->viewport.width = temp; - } - if (game->_priv.console) Console_Unload(game); - Console_Load(game); -} - SYMBOL_INTERNAL void GamestateProgress(struct Game *game) { struct Gamestate *tmp = game->_priv.cur_gamestate.tmp; game->_priv.cur_gamestate.p++; diff --git a/src/internal.h b/src/internal.h index f2fe190..d7026c3 100644 --- a/src/internal.h +++ b/src/internal.h @@ -46,7 +46,6 @@ void ResumeGamestates(struct Game *game); void DrawConsole(struct Game *game); void Console_Load(struct Game *game); void Console_Unload(struct Game *game); -void SetupViewport(struct Game *game); void GamestateProgress(struct Game *game); void* AddGarbage(struct Game *game, void* data); void ClearGarbage(struct Game *game); diff --git a/src/utils.c b/src/utils.c index 852ad1f..295cd4c 100644 --- a/src/utils.c +++ b/src/utils.c @@ -277,3 +277,35 @@ SYMBOL_EXPORT void PrintConsole(struct Game *game, char* format, ...) { al_set_target_bitmap(al_get_backbuffer(game->display)); al_destroy_bitmap(con); } + +SYMBOL_EXPORT void SetupViewport(struct Game *game) { + game->viewport.width = 320; + game->viewport.height = 180; + + al_clear_to_color(al_map_rgb(0,0,0)); + + int resolution = al_get_display_width(game->display) / 320; + if (al_get_display_height(game->display) / 180 < resolution) resolution = al_get_display_height(game->display) / 180; + if (resolution < 1) resolution = 1; + + if (atoi(GetConfigOptionDefault(game, "SuperDerpy", "letterbox", "1"))) { + int clipWidth = 320 * resolution, clipHeight = 180 * resolution; + int clipX = (al_get_display_width(game->display) - clipWidth) / 2, clipY = (al_get_display_height(game->display) - clipHeight) / 2; + al_set_clipping_rectangle(clipX, clipY, clipWidth, clipHeight); + + al_build_transform(&game->projection, clipX, clipY, resolution, resolution, 0.0f); + al_use_transform(&game->projection); + + } else if ((atoi(GetConfigOptionDefault(game, "SuperDerpy", "rotate", "1"))) && (game->viewport.height > game->viewport.width)) { + al_identity_transform(&game->projection); + al_rotate_transform(&game->projection, 0.5*ALLEGRO_PI); + al_translate_transform(&game->projection, game->viewport.width, 0); + al_scale_transform(&game->projection, resolution, resolution); + al_use_transform(&game->projection); + int temp = game->viewport.height; + game->viewport.height = game->viewport.width; + game->viewport.width = temp; + } + if (game->_priv.console) Console_Unload(game); + Console_Load(game); +} diff --git a/src/utils.h b/src/utils.h index d0bf179..542aff6 100644 --- a/src/utils.h +++ b/src/utils.h @@ -63,4 +63,6 @@ void PrintConsole(struct Game *game, char* format, ...); void FatalError(struct Game *game, bool exit, char* format, ...); +void SetupViewport(struct Game *game); + #endif