mirror of
https://gitlab.com/dosowisko.net/libsuperderpy.git
synced 2024-12-05 00:38:00 +01:00
move SetupViewport to internal functions
This commit is contained in:
parent
151e11d371
commit
c7ebc51f16
4 changed files with 58 additions and 59 deletions
|
@ -702,3 +702,60 @@ SYMBOL_INTERNAL void RemoveBitmap(struct Game* game, char* filename) {
|
|||
PrintConsole(game, "Tried to remove non-existent bitmap %s!", filename);
|
||||
}
|
||||
}
|
||||
|
||||
SYMBOL_INTERNAL void SetupViewport(struct Game* game) {
|
||||
game->viewport.width = game->_priv.params.width;
|
||||
game->viewport.height = game->_priv.params.height;
|
||||
|
||||
if ((game->viewport.width == 0) || (game->viewport.height == 0)) {
|
||||
game->viewport.height = al_get_display_height(game->display);
|
||||
game->viewport.width = (int)(game->_priv.params.aspect * game->viewport.height);
|
||||
if (game->viewport.width > al_get_display_width(game->display)) {
|
||||
game->viewport.width = al_get_display_width(game->display);
|
||||
game->viewport.height = (int)(game->viewport.width / game->_priv.params.aspect);
|
||||
}
|
||||
}
|
||||
|
||||
al_set_target_backbuffer(game->display);
|
||||
al_identity_transform(&game->_priv.projection);
|
||||
al_use_transform(&game->_priv.projection);
|
||||
al_reset_clipping_rectangle();
|
||||
|
||||
float resolution = al_get_display_height(game->display) / (float)game->viewport.height;
|
||||
if (al_get_display_width(game->display) / (float)game->viewport.width < resolution) {
|
||||
resolution = al_get_display_width(game->display) / (float)game->viewport.width;
|
||||
}
|
||||
if (game->_priv.params.integer_scaling) {
|
||||
resolution = floorf(resolution);
|
||||
if (floorf(resolution) == 0) {
|
||||
resolution = 1;
|
||||
}
|
||||
}
|
||||
if ((!strtol(GetConfigOptionDefault(game, "SuperDerpy", "downscale", "1"), NULL, 10)) && (resolution < 1)) {
|
||||
resolution = 1;
|
||||
}
|
||||
if (!strtol(GetConfigOptionDefault(game, "SuperDerpy", "scaling", "1"), NULL, 10)) {
|
||||
resolution = 1;
|
||||
}
|
||||
|
||||
int clipWidth = (int)(game->viewport.width * resolution);
|
||||
int clipHeight = (int)(game->viewport.height * resolution);
|
||||
if (strtol(GetConfigOptionDefault(game, "SuperDerpy", "letterbox", "1"), NULL, 10)) {
|
||||
int clipX = (al_get_display_width(game->display) - clipWidth) / 2;
|
||||
int clipY = (al_get_display_height(game->display) - clipHeight) / 2;
|
||||
al_build_transform(&game->_priv.projection, clipX, clipY, resolution, resolution, 0.0f);
|
||||
al_set_clipping_rectangle(clipX, clipY, clipWidth, clipHeight);
|
||||
game->clip_rect.x = clipX;
|
||||
game->clip_rect.y = clipY;
|
||||
game->clip_rect.w = clipWidth;
|
||||
game->clip_rect.h = clipHeight;
|
||||
} else if (strtol(GetConfigOptionDefault(game, "SuperDerpy", "scaling", "1"), NULL, 10)) {
|
||||
al_build_transform(&game->_priv.projection, 0, 0, al_get_display_width(game->display) / (float)game->viewport.width, al_get_display_height(game->display) / (float)game->viewport.height, 0.0f);
|
||||
}
|
||||
al_use_transform(&game->_priv.projection);
|
||||
Console_Unload(game);
|
||||
Console_Load(game);
|
||||
ResizeGamestates(game);
|
||||
|
||||
PrintConsole(game, "Viewport %dx%d; display %dx%d", game->viewport.width, game->viewport.height, al_get_display_width(game->display), al_get_display_height(game->display));
|
||||
}
|
||||
|
|
|
@ -148,5 +148,6 @@ void DestroyShaders(struct Game* game);
|
|||
__attribute__((__format__(__printf__, 2, 0))) char* GetGameName(struct Game* game, const char* format);
|
||||
ALLEGRO_BITMAP* AddBitmap(struct Game* game, char* filename);
|
||||
void RemoveBitmap(struct Game* game, char* filename);
|
||||
void SetupViewport(struct Game* game);
|
||||
|
||||
#endif /* LIBSUPERDERPY_INTERNAL_H */
|
||||
|
|
57
src/utils.c
57
src/utils.c
|
@ -530,63 +530,6 @@ SYMBOL_EXPORT void PrintConsoleWithContext(struct Game* game, int line, const ch
|
|||
al_unlock_mutex(game->_priv.mutex);
|
||||
}
|
||||
|
||||
SYMBOL_EXPORT void SetupViewport(struct Game* game) {
|
||||
game->viewport.width = game->_priv.params.width;
|
||||
game->viewport.height = game->_priv.params.height;
|
||||
|
||||
if ((game->viewport.width == 0) || (game->viewport.height == 0)) {
|
||||
game->viewport.height = al_get_display_height(game->display);
|
||||
game->viewport.width = (int)(game->_priv.params.aspect * game->viewport.height);
|
||||
if (game->viewport.width > al_get_display_width(game->display)) {
|
||||
game->viewport.width = al_get_display_width(game->display);
|
||||
game->viewport.height = (int)(game->viewport.width / game->_priv.params.aspect);
|
||||
}
|
||||
}
|
||||
|
||||
al_set_target_backbuffer(game->display);
|
||||
al_identity_transform(&game->_priv.projection);
|
||||
al_use_transform(&game->_priv.projection);
|
||||
al_reset_clipping_rectangle();
|
||||
|
||||
float resolution = al_get_display_height(game->display) / (float)game->viewport.height;
|
||||
if (al_get_display_width(game->display) / (float)game->viewport.width < resolution) {
|
||||
resolution = al_get_display_width(game->display) / (float)game->viewport.width;
|
||||
}
|
||||
if (game->_priv.params.integer_scaling) {
|
||||
resolution = floorf(resolution);
|
||||
if (floorf(resolution) == 0) {
|
||||
resolution = 1;
|
||||
}
|
||||
}
|
||||
if ((!strtol(GetConfigOptionDefault(game, "SuperDerpy", "downscale", "1"), NULL, 10)) && (resolution < 1)) {
|
||||
resolution = 1;
|
||||
}
|
||||
if (!strtol(GetConfigOptionDefault(game, "SuperDerpy", "scaling", "1"), NULL, 10)) {
|
||||
resolution = 1;
|
||||
}
|
||||
|
||||
int clipWidth = (int)(game->viewport.width * resolution);
|
||||
int clipHeight = (int)(game->viewport.height * resolution);
|
||||
if (strtol(GetConfigOptionDefault(game, "SuperDerpy", "letterbox", "1"), NULL, 10)) {
|
||||
int clipX = (al_get_display_width(game->display) - clipWidth) / 2;
|
||||
int clipY = (al_get_display_height(game->display) - clipHeight) / 2;
|
||||
al_build_transform(&game->_priv.projection, clipX, clipY, resolution, resolution, 0.0f);
|
||||
al_set_clipping_rectangle(clipX, clipY, clipWidth, clipHeight);
|
||||
game->clip_rect.x = clipX;
|
||||
game->clip_rect.y = clipY;
|
||||
game->clip_rect.w = clipWidth;
|
||||
game->clip_rect.h = clipHeight;
|
||||
} else if (strtol(GetConfigOptionDefault(game, "SuperDerpy", "scaling", "1"), NULL, 10)) {
|
||||
al_build_transform(&game->_priv.projection, 0, 0, al_get_display_width(game->display) / (float)game->viewport.width, al_get_display_height(game->display) / (float)game->viewport.height, 0.0f);
|
||||
}
|
||||
al_use_transform(&game->_priv.projection);
|
||||
Console_Unload(game);
|
||||
Console_Load(game);
|
||||
ResizeGamestates(game);
|
||||
|
||||
PrintConsole(game, "Viewport %dx%d; display %dx%d", game->viewport.width, game->viewport.height, al_get_display_width(game->display), al_get_display_height(game->display));
|
||||
}
|
||||
|
||||
SYMBOL_EXPORT void WindowCoordsToViewport(struct Game* game, int* x, int* y) {
|
||||
int clipX, clipY, clipWidth, clipHeight;
|
||||
al_get_clipping_rectangle(&clipX, &clipY, &clipWidth, &clipHeight);
|
||||
|
|
|
@ -67,8 +67,6 @@ __attribute__((__format__(__printf__, 5, 6))) void PrintConsoleWithContext(struc
|
|||
__attribute__((__format__(__printf__, 6, 7))) void FatalErrorWithContext(struct Game* game, int line, const char* file, const char* func, bool exit, char* format, ...);
|
||||
#define FatalError(game, exit, format, ...) FatalErrorWithContext(game, __LINE__, __FILE__, __func__, exit, format, ##__VA_ARGS__)
|
||||
|
||||
void SetupViewport(struct Game* game);
|
||||
|
||||
void WindowCoordsToViewport(struct Game* game, int* x, int* y);
|
||||
|
||||
ALLEGRO_BITMAP* GetFramebuffer(struct Game* game);
|
||||
|
|
Loading…
Reference in a new issue