Fix bad gui after toggling fullscreen ingame

This commit is contained in:
Benau 2022-08-29 14:55:02 +08:00
parent 1f53895a25
commit 4f3dbb43a2
4 changed files with 42 additions and 15 deletions

View File

@ -358,7 +358,7 @@ namespace GE
{ return m_separate_rtt_texture; }
void handleDeletedTextures();
void addRTTPolyCount(unsigned count) { m_rtt_polycount += count; }
SDL_Window* getWindow() const { return m_window; }
SDL_Window* getSDLWindow() const { return m_window; }
private:
struct SwapChainSupportDetails
{

View File

@ -342,7 +342,7 @@ extern "C" void update_fullscreen_desktop(int val)
GE::GEVulkanDriver* gevk = GE::getVKDriver();
if (!gevk || !GE::getGEConfig()->m_vulkan_fullscreen_desktop)
return;
SDL_Window* window = gevk->getWindow();
SDL_Window* window = gevk->getSDLWindow();
int prev_width = 0;
int prev_height = 0;
@ -952,17 +952,7 @@ bool CIrrDeviceSDL::run()
{
if (SDL_event.window.event == SDL_WINDOWEVENT_SIZE_CHANGED)
{
updateNativeScale();
u32 new_width = SDL_event.window.data1 * NativeScaleX;
u32 new_height = SDL_event.window.data2 * NativeScaleY;
if (new_width != Width || new_height != Height)
{
Width = new_width;
Height = new_height;
if (VideoDriver)
VideoDriver->OnResize(core::dimension2d<u32>(Width, Height));
reset_network_body();
}
handleNewSize(SDL_event.window.data1, SDL_event.window.data2);
}
else if (SDL_event.window.event == SDL_WINDOWEVENT_MINIMIZED)
{
@ -1028,6 +1018,23 @@ bool CIrrDeviceSDL::run()
return !Close;
}
void CIrrDeviceSDL::handleNewSize(u32 width, u32 height)
{
updateNativeScale();
u32 new_width = width * NativeScaleX;
u32 new_height = height * NativeScaleY;
if (new_width != Width || new_height != Height)
{
Width = new_width;
Height = new_height;
if (VideoDriver)
VideoDriver->OnResize(core::dimension2d<u32>(Width, Height));
reset_network_body();
}
}
//! Activate any joysticks, and generate events for them.
bool CIrrDeviceSDL::activateJoysticks(core::array<SJoystickInfo> & joystickInfo)
{

View File

@ -143,6 +143,7 @@ class MoltenVK;
virtual bool isGyroscopeAvailable();
virtual void resetPaused() { clearAllTouchIds(); }
void handleNewSize(u32 width, u32 height);
//! Implementation of the linux cursor control
class CCursorControl : public gui::ICursorControl

View File

@ -45,8 +45,11 @@
#include <ge_main.hpp>
#include <ge_vulkan_driver.hpp>
#include <ge_vulkan_texture_descriptor.hpp>
#include <SDL_video.h>
#include "../../lib/irrlicht/source/Irrlicht/CIrrDeviceSDL.h"
#endif
#include <functional>
#include <iostream>
#include <sstream>
@ -736,6 +739,7 @@ void OptionsScreenVideo::updateBlurTooltip()
// --------------------------------------------------------------------------------------------
extern "C" void update_swap_interval(int swap_interval);
extern "C" void update_fullscreen_desktop(int val);
extern "C" void reset_network_body();
void OptionsScreenVideo::eventCallback(Widget* widget, const std::string& name,
const int playerID)
@ -885,11 +889,26 @@ void OptionsScreenVideo::eventCallback(Widget* widget, const std::string& name,
rememberWinpos->setActive(!fullscreen->getState());
#ifndef SERVER_ONLY
if (GE::getDriver()->getDriverType() == video::EDT_VULKAN &&
GE::getGEConfig()->m_vulkan_fullscreen_desktop)
GE::GEVulkanDriver* gevk = GE::getVKDriver();
if (gevk && GE::getGEConfig()->m_vulkan_fullscreen_desktop)
{
UserConfigParams::m_fullscreen = fullscreen->getState();
update_fullscreen_desktop(UserConfigParams::m_fullscreen);
if (StateManager::get()->getGameState() == GUIEngine::INGAME_MENU)
{
StateManager::get()->popMenu();
std::function<Screen*()> screen_function =
getNewScreenPointer();
int new_width = 0;
int new_height = 0;
SDL_GetWindowSize(gevk->getSDLWindow(), &new_width,
&new_height);
static_cast<CIrrDeviceSDL*>(gevk->getIrrlichtDevice())
->handleNewSize(new_width, new_height);
irr_driver->handleWindowResize();
Screen* new_screen = screen_function();
new_screen->push();
}
}
else
updateResolutionsList();