From 63a77a61b4ecd0c0c91375e71e0757cad2432d0f Mon Sep 17 00:00:00 2001 From: "arthur.jamet" Date: Thu, 17 Jun 2021 14:37:16 +0200 Subject: [PATCH] fix fullscreen resolution --- lib/Ray/sources/Window.cpp | 20 +++++++++++++++++++- lib/Ray/sources/Window.hpp | 9 +++++++++ sources/Runner/SettingsMenuScene.cpp | 9 +++------ sources/System/Renderer/RenderSystem.cpp | 2 +- 4 files changed, 32 insertions(+), 8 deletions(-) diff --git a/lib/Ray/sources/Window.cpp b/lib/Ray/sources/Window.cpp index 151cd615..ec856fca 100644 --- a/lib/Ray/sources/Window.cpp +++ b/lib/Ray/sources/Window.cpp @@ -80,7 +80,8 @@ const RAY::Vector2 &RAY::Window::getDimensions(void) RAY::Window &RAY::Window::setDimensions(const Vector2 &dims) { this->_dimensions = dims; - SetWindowSize(dims.x, dims.y); + if (this->_isOpen) + SetWindowSize(dims.x, dims.y); return *this; } @@ -200,6 +201,11 @@ unsigned RAY::Window::getConfigFlags(void) const return this->_flags; } +bool RAY::Window::isFullscreen(void) const +{ + return IsWindowFullscreen(); +} + RAY::Window &RAY::Window::setConfigFlags(unsigned flags) { if (this->_isOpen) @@ -212,4 +218,16 @@ RAY::Window &RAY::Window::toggleFullscreen() { ToggleFullscreen(); return *this; +} + +RAY::Window &RAY::Window::maximize() +{ + MaximizeWindow(); + return *this; +} + +RAY::Window &RAY::Window::restore() +{ + RestoreWindow(); + return *this; } \ No newline at end of file diff --git a/lib/Ray/sources/Window.hpp b/lib/Ray/sources/Window.hpp index 81d4b1e4..b8370719 100644 --- a/lib/Ray/sources/Window.hpp +++ b/lib/Ray/sources/Window.hpp @@ -148,6 +148,15 @@ namespace RAY { //! @brief set window to fullscreen RAY::Window &toggleFullscreen(); + //! @return true if the window is fullscreen + bool isFullscreen(void) const; + + //! @brief set window to max size + RAY::Window &maximize(); + + //! @brief reset window size + RAY::Window &restore(); + private: //! @brief Creates window, and opens it if openNow is set to true Window(int width, int height, std::string title, unsigned flags = 0, bool openNow = true); diff --git a/sources/Runner/SettingsMenuScene.cpp b/sources/Runner/SettingsMenuScene.cpp index 88241d36..1fd24c48 100644 --- a/sources/Runner/SettingsMenuScene.cpp +++ b/sources/Runner/SettingsMenuScene.cpp @@ -184,18 +184,15 @@ namespace BBM { RAY2D::Text *text = dynamic_cast(entity.getComponent().drawable.get()); RAY::Window &window = RAY::Window::getInstance(); - unsigned oldFlags = window.getConfigFlags(); - - if (oldFlags == FLAG_WINDOW_RESIZABLE) - window.toggleFullscreen(); - else - window.setConfigFlags(FLAG_WINDOW_RESIZABLE); if (text->getString().find("Off") != std::string::npos) { text->setText("Fullscreen: On"); + window.setDimensions(RAY::Vector2(1920, 1080)); } else { text->setText("Fullscreen: Off"); + window.setDimensions(RAY::Vector2(1280, 720)); } + window.toggleFullscreen(); }) .addComponent([](WAL::Entity &entity, WAL::Wal &) { diff --git a/sources/System/Renderer/RenderSystem.cpp b/sources/System/Renderer/RenderSystem.cpp index 4d6a3043..47cda76c 100644 --- a/sources/System/Renderer/RenderSystem.cpp +++ b/sources/System/Renderer/RenderSystem.cpp @@ -94,7 +94,7 @@ namespace BBM void RenderSystem::resizeWindow(Vector2f &newDims) { newDims.y = (newDims.x * 720) / 1280; - if (newDims.y < 720 || newDims.x < 1280) { + if ((newDims.y < 720 || newDims.x < 1280)) { newDims.y = 720; newDims.x = 1280; }