diff --git a/platforms/windows/main.cpp b/platforms/windows/main.cpp index c43a134..a4e76c9 100644 --- a/platforms/windows/main.cpp +++ b/platforms/windows/main.cpp @@ -158,6 +158,9 @@ LRESULT CALLBACK WndProc(HWND hWnd, UINT iMsg, WPARAM wParam, LPARAM lParam) g_AppPlatform.setScreenSize(width, height); + if (g_pApp) + g_pApp->sizeUpdate(width, height); + break; } case WM_KEYDOWN: diff --git a/source/App.cpp b/source/App.cpp index be55031..7ab7082 100644 --- a/source/App.cpp +++ b/source/App.cpp @@ -57,3 +57,7 @@ void App::update() { } + +void App::sizeUpdate(int newWidth, int newHeight) +{ +} diff --git a/source/App.hpp b/source/App.hpp index 1828e7a..94241a3 100644 --- a/source/App.hpp +++ b/source/App.hpp @@ -14,15 +14,17 @@ class App { public: - void destroy(); - void draw(); virtual bool handleBack(bool); virtual void init(); + virtual void update(); + virtual void sizeUpdate(int newWidth, int newHeight); + + void destroy(); + void draw(); void loadState(void*, int); AppPlatform* platform(); void quit(); void saveState(void**, int); - virtual void update(); bool wantToQuit(); public: diff --git a/source/Minecraft.cpp b/source/Minecraft.cpp index 8d8f778..d70cf40 100644 --- a/source/Minecraft.cpp +++ b/source/Minecraft.cpp @@ -773,6 +773,35 @@ void Minecraft::prepareLevel(const std::string& unused) // " - prepr: "; } +void Minecraft::sizeUpdate(int newWidth, int newHeight) +{ + // re-calculate the GUI scale. + Gui::InvGuiScale = getBestScaleForThisScreenSize(newWidth, newHeight); + + if (m_pScreen) + m_pScreen->setSize(int(newWidth * Gui::InvGuiScale), int(newHeight * Gui::InvGuiScale)); +} + +float Minecraft::getBestScaleForThisScreenSize(int width, int height) +{ + // phones only +#if !defined(_WIN32) && !defined(USE_SDL2) + if (width > 1000) + return 1.0f / 4.0f; + + if (width > 800) + return 1.0f / 3.0f; +#else + if (width > 1000) + return 1.0f / 3.0f; +#endif + + if (width > 400) + return 1.0f / 2.0f; + + return 1.0f; +} + void Minecraft::generateLevel(const std::string& unused, Level* pLevel) { float time = getTimeS(); //@UNUSED diff --git a/source/Minecraft.hpp b/source/Minecraft.hpp index 3e56f7d..1d9eb21 100644 --- a/source/Minecraft.hpp +++ b/source/Minecraft.hpp @@ -60,13 +60,15 @@ public: virtual void onGraphicsReset(); virtual void update() override; virtual void init() override; + virtual void sizeUpdate(int newWidth, int newHeight) override; - static void* prepareLevel_tspawn(void* pMinecraft); + float getBestScaleForThisScreenSize(int width, int height); void generateLevel(const std::string& unused, Level* pLevel); void prepareLevel(const std::string& unused); void _levelGenerated(); bool isOnline(); bool isOnlineClient(); + static void* prepareLevel_tspawn(void* pMinecraft); const char* getProgressMessage(); LevelStorageSource* getLevelSource(); diff --git a/source/client/gui/Screen.cpp b/source/client/gui/Screen.cpp index b90a255..3b49edb 100644 --- a/source/client/gui/Screen.cpp +++ b/source/client/gui/Screen.cpp @@ -173,6 +173,11 @@ void Screen::setSize(int width, int height) { m_width = width; m_height = height; + + // not original code. Will need to re-init again + m_buttons.clear(); + m_textInputs.clear(); + init(); } void Screen::updateEvents() diff --git a/windows_vs/options.txt b/windows_vs/options.txt index 3e1ff83..48fe585 100644 --- a/windows_vs/options.txt +++ b/windows_vs/options.txt @@ -5,4 +5,4 @@ ctrl_invertmouse|false gfx_fancygraphics|true mp_server_visible_default|true gfx_smoothlighting|true -gfx_viewdistance|2 +gfx_viewdistance|3