mirror of
https://gitlab.com/dosowisko.net/libsuperderpy.git
synced 2024-12-05 00:38:00 +01:00
fix a case where SetupViewport wasn't called when it should after a display resize
This commit is contained in:
parent
a309b8cb2b
commit
d54b311a3c
4 changed files with 13 additions and 4 deletions
|
@ -710,6 +710,9 @@ SYMBOL_INTERNAL void SetupViewport(struct Game* game) {
|
|||
game->viewport.width = game->_priv.params.width;
|
||||
game->viewport.height = game->_priv.params.height;
|
||||
|
||||
game->_priv.window_width = al_get_display_width(game->display);
|
||||
game->_priv.window_height = al_get_display_height(game->display);
|
||||
|
||||
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);
|
||||
|
|
|
@ -109,6 +109,9 @@ SYMBOL_EXPORT struct Game* libsuperderpy_init(int argc, char** argv, const char*
|
|||
game->_priv.transforms = NULL;
|
||||
game->_priv.transforms_no = 0;
|
||||
|
||||
game->_priv.window_width = 0;
|
||||
game->_priv.window_height = 0;
|
||||
|
||||
game->_priv.mutex = al_create_mutex();
|
||||
|
||||
game->config.fullscreen = strtol(GetConfigOptionDefault(game, "SuperDerpy", "fullscreen", "1"), NULL, 10);
|
||||
|
|
|
@ -252,6 +252,8 @@ struct Game {
|
|||
ALLEGRO_TRANSFORM* transforms;
|
||||
int transforms_no, transforms_alloc;
|
||||
|
||||
int window_width, window_height;
|
||||
|
||||
#ifdef ALLEGRO_MACOSX
|
||||
char cwd[MAXPATHLEN];
|
||||
#endif
|
||||
|
|
|
@ -48,8 +48,8 @@ static inline void HandleEvent(struct Game* game, ALLEGRO_EVENT* ev) {
|
|||
}
|
||||
break;
|
||||
|
||||
case ALLEGRO_EVENT_DISPLAY_RESIZE: {
|
||||
bool changed = (ev->display.width != al_get_display_width(game->display)) || (ev->display.height != al_get_display_height(game->display));
|
||||
case ALLEGRO_EVENT_DISPLAY_RESIZE:
|
||||
PrintConsole(game, "Resize event: %dx%d", ev->display.width, ev->display.height);
|
||||
|
||||
#ifdef LIBSUPERDERPY_IMGUI
|
||||
ImGui_ImplAllegro5_InvalidateDeviceObjects();
|
||||
|
@ -58,13 +58,14 @@ static inline void HandleEvent(struct Game* game, ALLEGRO_EVENT* ev) {
|
|||
#ifdef LIBSUPERDERPY_IMGUI
|
||||
ImGui_ImplAllegro5_CreateDeviceObjects();
|
||||
#endif
|
||||
|
||||
// SetupViewport can be expensive, so don't do it when the resize event is already outdated or doesn't change anything
|
||||
if (changed && ((ev->display.width == al_get_display_width(game->display)) || (ev->display.height == al_get_display_height(game->display)))) {
|
||||
if (((ev->display.width != game->_priv.window_width) || (ev->display.height != game->_priv.window_height)) &&
|
||||
(ev->display.width == al_get_display_width(game->display)) && (ev->display.height == al_get_display_height(game->display))) {
|
||||
SetupViewport(game);
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
case ALLEGRO_EVENT_KEY_DOWN:
|
||||
#ifdef ALLEGRO_ANDROID
|
||||
if ((ev->keyboard.keycode == ALLEGRO_KEY_MENU) || (ev->keyboard.keycode == ALLEGRO_KEY_TILDE) || (ev->keyboard.keycode == ALLEGRO_KEY_BACKQUOTE)) {
|
||||
|
|
Loading…
Reference in a new issue