Skip to content

Commit

Permalink
Enable new screen resizing code
Browse files Browse the repository at this point in the history
  • Loading branch information
CodingJellyfish committed May 5, 2024
1 parent 6e2d528 commit aba99c2
Show file tree
Hide file tree
Showing 13 changed files with 27 additions and 119 deletions.
2 changes: 1 addition & 1 deletion lib/irrlicht/source/Irrlicht/CIrrDeviceSDL.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -437,7 +437,7 @@ bool CIrrDeviceSDL::createWindow()
}
}

u32 flags = SDL_WINDOW_SHOWN;
u32 flags = SDL_WINDOW_SHOWN | SDL_WINDOW_RESIZABLE;
#if !defined(ANDROID) && !defined(__SWITCH__)
if (CreationParams.DriverType == video::EDT_OPENGL ||
CreationParams.DriverType == video::EDT_OGLES2 ||
Expand Down
16 changes: 4 additions & 12 deletions src/graphics/irr_driver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -805,7 +805,7 @@ void IrrDriver::initDevice()
}

// This remaps the window, so it has to be done before the clear to avoid flicker
m_device->setResizable(false);
//m_device->setResizable(false);

// Immediate clear to black for a nicer user loading experience
m_video_driver->beginScene(/*backBuffer clear*/true, /* Z */ false);
Expand Down Expand Up @@ -2078,14 +2078,11 @@ void IrrDriver::doScreenShot()
// ----------------------------------------------------------------------------
void IrrDriver::handleWindowResize()
{
bool dialog_exists = GUIEngine::ModalDialog::isADialogActive() ||
GUIEngine::ScreenKeyboard::isActive();

// This will allow main menu auto resize if missed a resize event
core::dimension2du current_screen_size =
m_video_driver->getCurrentRenderTargetSize();
GUIEngine::Screen* screen = GUIEngine::getCurrentScreen();
if (screen && screen->isResizable())
if (screen)
{
current_screen_size.Width = screen->getWidth();
current_screen_size.Height = screen->getHeight();
Expand All @@ -2102,8 +2099,8 @@ void IrrDriver::handleWindowResize()
current_screen_size != new_size ||
screen_orientation_changed)
{
// Don't update when dialog is opened or minimized
if (dialog_exists || new_size.getArea() == 0)
// Don't update when minimized
if (new_size.getArea() == 0)
return;

m_screen_orientation = new_orientation;
Expand All @@ -2114,11 +2111,6 @@ void IrrDriver::handleWindowResize()
UserConfigParams::m_real_height = (unsigned)((float)m_actual_screen_size.Height / m_device->getNativeScaleY());
resizeWindow();
}
// In case reset by opening options in game
if (!dialog_exists &&
StateManager::get()->getGameState() == GUIEngine::GAME &&
!m_device->isResizable())
m_device->setResizable(true);
} // handleWindowResize

// ----------------------------------------------------------------------------
Expand Down
37 changes: 0 additions & 37 deletions src/guiengine/abstract_state_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -311,40 +311,3 @@ void AbstractStateManager::resetAndSetStack(Screen* screens[])

onTopMostScreenChanged();
} // resetAndSetStack

// ----------------------------------------------------------------------------

void AbstractStateManager::onResize()
{
// Happens in the first resize in main.cpp
if (m_menu_stack.empty())
return;

// In game resizing
if (m_menu_stack[0].first == RACE_STATE_NAME)
{
if (m_menu_stack.size() == 1)
{
clearScreenCache();
m_menu_stack.emplace_back(RACE_STATE_NAME, (Screen*)NULL);
}
return;
}

// For some window manager it sends resize event when STK is not focus
// even if the screen is not resizable, prevent it from resizing if wrong
// screen
if (!m_menu_stack.back().second ||
!m_menu_stack.back().second->isResizable())
return;

std::vector<std::function<Screen*()> > screen_function;
for (auto& p : m_menu_stack)
screen_function.push_back(p.second->getNewScreenPointer());
clearScreenCache();
std::vector<Screen*> new_screen;
for (auto& screen : screen_function)
new_screen.push_back(screen());
new_screen.push_back(NULL);
resetAndSetStack(new_screen.data());
} // onResize
5 changes: 0 additions & 5 deletions src/guiengine/abstract_state_manager.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -111,11 +111,6 @@ namespace GUIEngine
*/
void resetAndSetStack(Screen* screens[]);

/**
* \brief Called when resizing of stk window
*/
void onResize();

/**
* \brief Used in no graphics STK to enter menu screen (when server is
* idle state)
Expand Down
16 changes: 14 additions & 2 deletions src/guiengine/engine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1240,7 +1240,10 @@ namespace GUIEngine
g_small_title_font->getDimension( L"X" ).Height;
Private::tiny_title_font_height =
g_tiny_title_font->getDimension( L"X" ).Height;
StateManager::get()->onResize();
if (ScreenKeyboard::isActive())
ScreenKeyboard::getCurrent()->onResize();
if (ModalDialog::isADialogActive())
ModalDialog::getCurrent()->onResize();
} // reloadForNewSize

// -----------------------------------------------------------------------
Expand Down Expand Up @@ -1283,6 +1286,16 @@ namespace GUIEngine

GameState gamestate = g_state_manager->getGameState();

core::dimension2d<u32> screen_size = irr_driver->getFrameSize();
core::dimension2d<u32> cur_screen_size;
if (getCurrentScreen())
{
cur_screen_size.Width = getCurrentScreen()->getWidth();
cur_screen_size.Height = getCurrentScreen()->getHeight();
if (screen_size != cur_screen_size)
getCurrentScreen()->onResize();
}

// ---- some menus may need updating
bool dialog_opened = false;

Expand Down Expand Up @@ -1372,7 +1385,6 @@ namespace GUIEngine

if (gamestate != GAME && !gui_messages.empty())
{
core::dimension2d<u32> screen_size = irr_driver->getFrameSize();
const int text_height = getFontHeight() + 20;
const int y_from = screen_size.Height - text_height;

Expand Down
3 changes: 0 additions & 3 deletions src/guiengine/modaldialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,6 @@ ModalDialog::ModalDialog(const float percentWidth, const float percentHeight,
m_percent_width = percentWidth;
m_percent_height = percentHeight;
m_irrlicht_window = NULL;
m_was_resizable = irr_driver->getDevice()->isResizable();
irr_driver->getDevice()->setResizable(false);
} // ModalDialog

// ----------------------------------------------------------------------------
Expand Down Expand Up @@ -191,7 +189,6 @@ ModalDialog::~ModalDialog()
// to the deleted widgets will be gone, but some widgets
// may want to perform additional cleanup at this time
elementsWereDeleted();
GUIEngine::getDevice()->setResizable(m_was_resizable);
} // ~ModalDialog

// ----------------------------------------------------------------------------
Expand Down
1 change: 0 additions & 1 deletion src/guiengine/modaldialog.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,6 @@ namespace GUIEngine

float m_percent_width, m_percent_height;
bool m_init;
bool m_was_resizable;
protected:
irr::gui::IGUIWindow* m_irrlicht_window;
irr::core::rect< irr::s32 > m_area;
Expand Down
1 change: 0 additions & 1 deletion src/guiengine/screen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,6 @@ Screen::Screen(const char* file, bool pause_race)
m_update_in_background = false;
m_width = irr_driver->getActualScreenSize().Width;
m_height = irr_driver->getActualScreenSize().Height;
m_resizable = false;
} // Screen

// -----------------------------------------------------------------------------
Expand Down
15 changes: 0 additions & 15 deletions src/guiengine/screen.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,6 @@ namespace GUIEngine
if (singleton == NULL)
{
singleton = new SCREEN();
std::function<SCREEN*()> new_screen_function = []()
{ return ScreenSingleton::getInstance(); };
singleton->setScreenPointerFunction(new_screen_function);
GUIEngine::addScreenToList(singleton);
}

Expand All @@ -95,10 +92,6 @@ namespace GUIEngine
*/
class Screen : public AbstractTopLevelContainer
{
protected:
/** True if this screen is resizable
*/
bool m_resizable;
private:
/** True if the race (if it is running) should be paused when this
* screen is shown. The RaceResultGUI uses this to leave the race
Expand Down Expand Up @@ -143,13 +136,6 @@ namespace GUIEngine
PtrVector<Widget>& append_to,
irr::gui::IGUIElement* parent = NULL);

/** Save the function before GUIEngine::clearScreenCache, call it after
* to get the new screen instance pointer
*/
std::function<Screen*()> getNewScreenPointer() const { return m_screen_func; }

void setScreenPointerFunction(const std::function<Screen*()>& f) { m_screen_func = f; }

Screen(bool pause_race=true);

Screen(const char* filename, bool pause_race=true);
Expand Down Expand Up @@ -308,7 +294,6 @@ namespace GUIEngine

virtual int getHeight() { return m_height; }

virtual bool isResizable() const { return m_resizable; }
/**
* \brief Override this if you need to be notified of player actions
* in subclasses.
Expand Down
3 changes: 0 additions & 3 deletions src/modes/world.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -129,8 +129,6 @@ World* World::m_world[PT_COUNT];
*/
World::World() : WorldStatus()
{
if (m_process_type == PT_MAIN)
GUIEngine::getDevice()->setResizable(true);
RewindManager::setEnable(NetworkConfig::get()->isNetworking());
#ifdef DEBUG
m_magic_number = 0xB01D6543;
Expand Down Expand Up @@ -614,7 +612,6 @@ World::~World()
{
if (m_process_type == PT_MAIN)
{
GUIEngine::getDevice()->setResizable(false);
material_manager->unloadAllTextures();
}

Expand Down
3 changes: 0 additions & 3 deletions src/states_screens/main_menu_screen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,6 @@ using namespace Online;

MainMenuScreen::MainMenuScreen() : Screen("main_menu.stkgui")
{
m_resizable = true;
} // MainMenuScreen

// ----------------------------------------------------------------------------
Expand Down Expand Up @@ -125,7 +124,6 @@ void MainMenuScreen::beforeAddingWidget()
//
void MainMenuScreen::init()
{
GUIEngine::getDevice()->setResizable(true);
Screen::init();

m_user_id = getWidget<ButtonWidget>("user-id");
Expand Down Expand Up @@ -612,7 +610,6 @@ void MainMenuScreen::eventCallback(Widget* widget, const std::string& name,

void MainMenuScreen::tearDown()
{
GUIEngine::getDevice()->setResizable(false);
} // tearDown

// ----------------------------------------------------------------------------
Expand Down
4 changes: 0 additions & 4 deletions src/states_screens/options/options_screen_general.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,6 @@ using namespace Online;

OptionsScreenGeneral::OptionsScreenGeneral() : Screen("options/options_general.stkgui")
{
m_resizable = true;
m_inited = false;
} // OptionsScreenVideo

Expand All @@ -81,8 +80,6 @@ void OptionsScreenGeneral::loadedFromFile()

void OptionsScreenGeneral::init()
{
GUIEngine::getDevice()->setResizable(
StateManager::get()->getGameState() == GUIEngine::MENU);
Screen::init();
RibbonWidget* ribbon = getWidget<RibbonWidget>("options_choice");
assert(ribbon != NULL);
Expand Down Expand Up @@ -283,7 +280,6 @@ void OptionsScreenGeneral::setInternetCheckboxes(bool activate)

void OptionsScreenGeneral::tearDown()
{
GUIEngine::getDevice()->setResizable(false);
Screen::tearDown();
// save changes when leaving screen
user_config->saveConfig();
Expand Down
40 changes: 8 additions & 32 deletions src/states_screens/options/options_screen_video.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,6 @@ OptionsScreenVideo::OptionsScreenVideo() : Screen("options/options_video.stkgui"
m_prev_adv_pipline(false),
m_prev_img_quality(-1)
{
m_resizable = true;
m_inited = false;
initPresets();
} // OptionsScreenVideo
Expand Down Expand Up @@ -235,8 +234,6 @@ void OptionsScreenVideo::loadedFromFile()

void OptionsScreenVideo::init()
{
GUIEngine::getDevice()->setResizable(
StateManager::get()->getGameState() == GUIEngine::MENU);
Screen::init();
m_prev_adv_pipline = UserConfigParams::m_dynamic_lights;
m_prev_img_quality = getImageQuality();
Expand Down Expand Up @@ -367,12 +364,6 @@ void OptionsScreenVideo::init()

updateResolutionsList();

if (m_fullscreen_checkbox_focus)
{
m_fullscreen_checkbox_focus = false;
getWidget("fullscreen")->setFocusForPlayer(PLAYER_ID_GAME_MASTER);
}

// If a benchmark was requested and the game had to reload
// the graphics engine, start the benchmark when the
// video settings screen is loaded back afterwards.
Expand All @@ -386,6 +377,13 @@ void OptionsScreenVideo::onResize()
{
Screen::onResize();
configResolutionsList();
if (m_fullscreen_checkbox_focus)
{
m_fullscreen_checkbox_focus = false;
Widget* full = getWidget("fullscreen");
if (full->isActivated() && full->isVisible())
full->setFocusForPlayer(PLAYER_ID_GAME_MASTER);
}
} // onResize

// --------------------------------------------------------------------------------------------
Expand Down Expand Up @@ -987,24 +985,7 @@ void OptionsScreenVideo::eventCallback(Widget* widget, const std::string& name,
{
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();
OptionsScreenVideo::m_fullscreen_checkbox_focus = true;
new_screen->push();
}
else
OptionsScreenVideo::m_fullscreen_checkbox_focus = true;
OptionsScreenVideo::m_fullscreen_checkbox_focus = true;
}
else
updateResolutionsList();
Expand Down Expand Up @@ -1034,11 +1015,6 @@ void OptionsScreenVideo::startBenchmark()

void OptionsScreenVideo::tearDown()
{
if (getWidget("fullscreen")->isVisible() &&
getWidget("fullscreen")->isFocusedForPlayer(PLAYER_ID_GAME_MASTER))
OptionsScreenVideo::m_fullscreen_checkbox_focus = true;

GUIEngine::getDevice()->setResizable(false);
#ifndef SERVER_ONLY
if (m_prev_adv_pipline != UserConfigParams::m_dynamic_lights &&
CVS->isGLSL())
Expand Down

0 comments on commit aba99c2

Please sign in to comment.