Allow main menu auto resize if missed a resize event

This commit is contained in:
Benau 2020-07-12 12:14:46 +08:00
parent cef6eb0558
commit d8beb5bdb6
9 changed files with 43 additions and 36 deletions

View File

@ -1978,7 +1978,19 @@ void IrrDriver::handleWindowResize()
{
bool dialog_exists = GUIEngine::ModalDialog::isADialogActive() ||
GUIEngine::ScreenKeyboard::isActive();
if (m_actual_screen_size != m_video_driver->getCurrentRenderTargetSize())
// 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())
{
current_screen_size.Width = screen->getWidth();
current_screen_size.Height = screen->getHeight();
}
if (m_actual_screen_size != m_video_driver->getCurrentRenderTargetSize() ||
current_screen_size != m_video_driver->getCurrentRenderTargetSize())
{
// Don't update when dialog is opened
if (dialog_exists)

View File

@ -331,14 +331,11 @@ void AbstractStateManager::onResize()
return;
}
const std::string& last_menu = m_menu_stack.back().first;
// 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
// Hardcoded list of menu allowed to be resized for now
if (last_menu != "main_menu.stkgui" &&
last_menu != "options_general.stkgui" &&
last_menu != "options_video.stkgui")
if (!m_menu_stack.back().second ||
!m_menu_stack.back().second->isResizable())
return;
std::vector<std::function<Screen*()> > screen_function;

View File

@ -1491,6 +1491,11 @@ namespace GUIEngine
//pause the timer during loading
story_mode_timer->pauseTimer(true);
}
else
{
// The screen size may change when loading
irr_driver->handleWindowResize();
}
#endif
} // renderLoading

View File

@ -59,6 +59,9 @@ Screen::Screen(const char* file, bool pause_race)
m_loaded = false;
m_pause_race = pause_race;
m_update_in_background = false;
m_width = irr_driver->getActualScreenSize().Width;
m_height = irr_driver->getActualScreenSize().Height;
m_resizable = false;
} // Screen
// -----------------------------------------------------------------------------
@ -236,19 +239,3 @@ void Screen::manualRemoveWidget(Widget* w)
#pragma mark Getters
#endif
// -----------------------------------------------------------------------------
/** \brief Implementing method from AbstractTopLevelContainer */
int Screen::getWidth()
{
return irr_driver->getActualScreenSize().Width;
}
// -----------------------------------------------------------------------------
/** \brief Implementing method from AbstractTopLevelContainer */
int Screen::getHeight()
{
return irr_driver->getActualScreenSize().Height;
}
// -----------------------------------------------------------------------------

View File

@ -95,36 +95,40 @@ namespace GUIEngine
*/
class Screen : public AbstractTopLevelContainer
{
protected:
/** True if this screen is resizable
*/
bool m_resizable;
bool m_throttle_FPS;
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
* running while it is being shown. */
bool m_pause_race;
friend class Skin;
bool m_loaded;
std::string m_filename;
/** Will be called to determine if the 3D scene must be rendered when
* at this screen.
*/
bool m_render_3d;
/** to catch errors as early as possible, for debugging purposes only */
unsigned int m_magic_number;
/** When set to true it updates the screen even if modal dialog is
* opened
*/
bool m_update_in_background;
/** to catch errors as early as possible, for debugging purposes only */
unsigned int m_magic_number;
unsigned m_width, m_height;
friend class Skin;
std::string m_filename;
/** For runtime screen reloading without template */
std::function<Screen*()> m_screen_func;
protected:
bool m_throttle_FPS;
public:
LEAK_CHECK()
@ -299,10 +303,11 @@ namespace GUIEngine
*/
virtual MusicInformation* getInGameMenuMusic() const { return NULL; }
virtual int getWidth();
virtual int getWidth() { return m_width; }
virtual int getHeight();
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.

View File

@ -2154,8 +2154,6 @@ int main(int argc, char *argv[])
#ifndef SERVER_ONLY
if (!GUIEngine::isNoGraphics())
{
// The screen size may change after loading
irr_driver->handleWindowResize();
// Some Android devices have only 320x240 and height >= 480 is bare
// minimum to make the GUI working as expected.
if (irr_driver->getActualScreenSize().Height < 480)

View File

@ -74,6 +74,7 @@ using namespace Online;
MainMenuScreen::MainMenuScreen() : Screen("main_menu.stkgui")
{
m_resizable = true;
} // MainMenuScreen
// ----------------------------------------------------------------------------

View File

@ -64,6 +64,7 @@ using namespace Online;
OptionsScreenGeneral::OptionsScreenGeneral() : Screen("options_general.stkgui")
{
m_resizable = true;
m_inited = false;
} // OptionsScreenVideo

View File

@ -163,6 +163,7 @@ OptionsScreenVideo::OptionsScreenVideo() : Screen("options_video.stkgui"),
m_prev_adv_pipline(false),
m_prev_img_quality(-1)
{
m_resizable = true;
m_inited = false;
initPresets();
} // OptionsScreenVideo