diff options
author | Thorbjørn Lindeijer <thorbjorn@lindeijer.nl> | 2012-01-21 12:30:36 +0100 |
---|---|---|
committer | Andrei Karas <akaras@inbox.ru> | 2012-01-30 19:53:07 +0300 |
commit | 8292b80eac900ec5dd75d184063b7b35934e800a (patch) | |
tree | 3ce68afff38d75d0cb1cdb89260f2b49f232e86a /src/client.cpp | |
parent | 502a0a0163e702af7334979a2eabfc4826a94091 (diff) | |
download | mv-8292b80eac900ec5dd75d184063b7b35934e800a.tar.gz mv-8292b80eac900ec5dd75d184063b7b35934e800a.tar.bz2 mv-8292b80eac900ec5dd75d184063b7b35934e800a.tar.xz mv-8292b80eac900ec5dd75d184063b7b35934e800a.zip |
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
Diffstat (limited to 'src/client.cpp')
-rw-r--r-- | src/client.cpp | 54 |
1 files changed, 41 insertions, 13 deletions
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(); + } +} |