mirror of
https://gitlab.com/dosowisko.net/libsuperderpy.git
synced 2025-02-01 11:06:44 +01:00
move SetupViewport to utils
This commit is contained in:
parent
6bf5fc493b
commit
51b08cee76
4 changed files with 34 additions and 34 deletions
|
@ -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++;
|
||||
|
|
|
@ -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);
|
||||
|
|
32
src/utils.c
32
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);
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue