Merge pull request #255 from lotaviods/window_size

Window GUI resizing
This commit is contained in:
Tropical 2026-03-15 23:36:48 -05:00 committed by GitHub
commit 32580ab761
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 36 additions and 4 deletions

View file

@ -2254,14 +2254,33 @@ void Minecraft::pauseGame() {
// setScreen(new PauseScreen()); // 4J - TODO put back in
}
bool Minecraft::pollResize() {
int fbw, fbh;
RenderManager.GetFramebufferSize(fbw, fbh);
if (fbw != width_phys || fbh != height_phys) {
resize(fbw, fbh);
return true;
}
return false;
}
void Minecraft::resize(int width, int height) {
if (width <= 0) width = 1;
if (height <= 0) height = 1;
this->width = width;
// 4jcraft: store physical framebuffer size and adjust logical width
// for non-widescreen aspect ratio to fix UI scaling.
this->width_phys = width;
this->height_phys = height;
if (RenderManager.IsWidescreen()) {
this->width = width;
} else {
this->width = (width * 3) / 4;
}
this->height = height;
if (screen != NULL) {
ScreenSizeCalculator ssc(options, width, height);
// 4jcraft: use adjusted logical width instead of raw width for correct screen size calculation.
ScreenSizeCalculator ssc(options, this->width, height);
int screenWidth = ssc.getWidth();
int screenHeight = ssc.getHeight();
// screen->init(this, screenWidth, screenHeight); // 4J -

View file

@ -264,6 +264,8 @@ public:
void pauseGame();
// void toggleFullScreen(); // 4J - removed
bool pollResize();
private:
void resize(int width, int height);

View file

@ -218,6 +218,7 @@ public:
// RENDERING
float getScreenWidth() { return m_fScreenWidth; }
float getScreenHeight() { return m_fScreenHeight; }
void setScreenSize(S32 w, S32 h) { m_fScreenWidth = (float)w; m_fScreenHeight = (float)h; }
virtual void render() = 0;
void getRenderDimensions(C4JRender::eViewportType viewport, S32 &width, S32 &height);

View file

@ -905,6 +905,11 @@ return -1;
app.InitialiseTips();
while (!RenderManager.ShouldClose()) {
RenderManager.StartFrame();
if (pMinecraft->pollResize()) {
int fbw, fbh;
RenderManager.GetFramebufferSize(fbw, fbh);
ui.setScreenSize(fbw, fbh);
}
app.UpdateTime();
PIXBeginNamedEvent(0, "Input manager tick");
InputManager.Tick();

View file

@ -1046,7 +1046,9 @@ void GameRenderer::render(float a, bool bFirst) {
int fbw, fbh;
RenderManager.GetFramebufferSize(fbw, fbh);
glViewport(0, 0, fbw, fbh);
ScreenSizeCalculator ssc(mc->options, mc->width, mc->height);
// 4jcraft: use framebuffer dimensions for ScreenSizeCalculator so the
// title screen GUI coordinates match the actual viewport size.
ScreenSizeCalculator ssc(mc->options, fbw, fbh);
int screenWidth = ssc.getWidth();
int screenHeight = ssc.getHeight();
int xMouse = Mouse::getX() * screenWidth / fbw;
@ -1819,7 +1821,10 @@ void GameRenderer::renderSnowAndRain(float a) {
void GameRenderer::setupGuiScreen(int forceScale /*=-1*/) {
int fbw, fbh;
RenderManager.GetFramebufferSize(fbw, fbh);
ScreenSizeCalculator ssc(mc->options, mc->width, mc->height, forceScale);
// 4jcraft: use actual framebuffer dimensions instead of mc->width/height
// to ensure GUI scales correctly after a window resize.
ScreenSizeCalculator ssc(mc->options, fbw, fbh, forceScale);
glClear(GL_DEPTH_BUFFER_BIT);
glMatrixMode(GL_PROJECTION);