* Allow dynamic screen size change on windows

This commit is contained in:
iProgramInCpp
2023-08-06 22:45:15 +03:00
parent 9ef72164bb
commit 88d68cf21e
7 changed files with 50 additions and 5 deletions

View File

@@ -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:

View File

@@ -57,3 +57,7 @@ void App::update()
{
}
void App::sizeUpdate(int newWidth, int newHeight)
{
}

View File

@@ -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:

View File

@@ -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

View File

@@ -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();

View File

@@ -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()

View File

@@ -5,4 +5,4 @@ ctrl_invertmouse|false
gfx_fancygraphics|true
mp_server_visible_default|true
gfx_smoothlighting|true
gfx_viewdistance|2
gfx_viewdistance|3