From 8292b80eac900ec5dd75d184063b7b35934e800a Mon Sep 17 00:00:00 2001 From: Thorbjørn Lindeijer Date: Sat, 21 Jan 2012 12:30:36 +0100 Subject: Allow resizing of the game in windowed mode Window positions are semi-smartly corrected as a result of the resize. Not supported when using OpenGL on Windows for now. Reviewed-by: Yohann Ferreira Conflicts: src/client.cpp src/client.h src/game.cpp src/gui/gui.cpp src/gui/widgets/window.cpp --- src/client.cpp | 54 +++++++++++++++++++++++++++++++++++++++++------------- 1 file changed, 41 insertions(+), 13 deletions(-) (limited to 'src/client.cpp') diff --git a/src/client.cpp b/src/client.cpp index 017bcadb4..de874c8a8 100644 --- a/src/client.cpp +++ b/src/client.cpp @@ -251,7 +251,7 @@ Client::Client(const Options &options): mServerConfigDir(""), mUsersDir(""), mNpcsDir(""), - mRootDir(""), + mGame(0), mCurrentDialog(nullptr), mQuitDialog(nullptr), mDesktop(nullptr), @@ -816,15 +816,14 @@ int Client::gameExec() if (!mumbleManager) mumbleManager = new MumbleManager(); - Game *game = nullptr; SDL_Event event; while (mState != STATE_EXIT) { - if (game) + if (mGame) { // Let the game handle the events while it is active - game->handleInput(); + mGame->handleInput(); } else { @@ -840,6 +839,10 @@ int Client::gameExec() case SDL_KEYDOWN: default: break; + + case SDL_VIDEORESIZE: + resizeVideo(event.resize.w, event.resize.h); + break; } guiInput->pushInput(event); @@ -858,8 +861,8 @@ int Client::gameExec() { if (gui) gui->logic(); - if (game) - game->logic(); + if (mGame) + mGame->logic(); sound.logic(); @@ -967,10 +970,8 @@ int Client::gameExec() top->add(mThemesButton); #endif - int screenWidth = config.getIntValue("screenwidth"); - int screenHeight = config.getIntValue("screenheight"); - - mDesktop->setSize(screenWidth, screenHeight); + mDesktop->setSize(mainGraphics->getWidth(), + mainGraphics->getHeight()); } if (mState == STATE_SWITCH_LOGIN && mOldState == STATE_GAME) @@ -985,8 +986,8 @@ int Client::gameExec() if (mOldState == STATE_GAME) { - delete game; - game = nullptr; + delete mGame; + mGame = nullptr; Game::clearInstance(); ResourceManager *resman = ResourceManager::getInstance(); if (resman) @@ -1291,7 +1292,7 @@ int Client::gameExec() logger->log1("State: GAME"); if (Net::getGeneralHandler()) Net::getGeneralHandler()->reloadPartially(); - game = new Game; + mGame = new Game; break; case STATE_LOGIN_ERROR: @@ -2354,3 +2355,30 @@ bool Client::isTmw() } return false; } + +void Client::resizeVideo(int width, int height) +{ + // Keep a minimum size. This isn't adhered to by the actual window, but + // it keeps some window positions from getting messed up. + width = std::max(640, width); + height = std::max(480, height); + + if (mainGraphics->mWidth == width && mainGraphics->mHeight == height) + return; + + if (mainGraphics->resize(width, height)) + { + gui->videoResized(); + + if (mDesktop) + mDesktop->setSize(width, height); + + if (mSetupButton) + mSetupButton->setPosition(width - mSetupButton->getWidth() - 3, 3); + + if (mGame) + mGame->videoResized(width, height); + + gui->draw(); + } +} -- cgit v1.2.3-70-g09d2