diff options
author | Thorbjørn Lindeijer <thorbjorn@lindeijer.nl> | 2012-01-21 12:30:36 +0100 |
---|---|---|
committer | Thorbjørn Lindeijer <thorbjorn@lindeijer.nl> | 2012-01-22 11:12:17 +0100 |
commit | c4bdf324d7d464bc7fabbf88e1a6e66701c6e7cb (patch) | |
tree | d87655455c0a331c73bf5b762701fafaa5348688 /src/client.cpp | |
parent | 0d613d75b732c0d057acc3004f9b4322cf73d449 (diff) | |
download | mana-c4bdf324d7d464bc7fabbf88e1a6e66701c6e7cb.tar.gz mana-c4bdf324d7d464bc7fabbf88e1a6e66701c6e7cb.tar.bz2 mana-c4bdf324d7d464bc7fabbf88e1a6e66701c6e7cb.tar.xz mana-c4bdf324d7d464bc7fabbf88e1a6e66701c6e7cb.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
Diffstat (limited to 'src/client.cpp')
-rw-r--r-- | src/client.cpp | 53 |
1 files changed, 40 insertions, 13 deletions
diff --git a/src/client.cpp b/src/client.cpp index 768fae1e..058c113b 100644 --- a/src/client.cpp +++ b/src/client.cpp @@ -184,7 +184,7 @@ Client *Client::mInstance = 0; Client::Client(const Options &options): mOptions(options), - mRootDir(""), + mGame(0), mCurrentDialog(0), mQuitDialog(0), mDesktop(0), @@ -487,15 +487,14 @@ int Client::exec() { int lastTickTime = tick_time; - Game *game = 0; 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 { @@ -510,6 +509,10 @@ int Client::exec() case SDL_KEYDOWN: break; + + case SDL_VIDEORESIZE: + resizeVideo(event.resize.w, event.resize.h); + break; } guiInput->pushInput(event); @@ -522,8 +525,8 @@ int Client::exec() while (get_elapsed_time(lastTickTime) > 0) { gui->logic(); - if (game) - game->logic(); + if (mGame) + mGame->logic(); sound.logic(); @@ -579,10 +582,7 @@ int Client::exec() - 3, 3); top->add(mSetupButton); - int screenWidth = config.getIntValue("screenwidth"); - int screenHeight = config.getIntValue("screenheight"); - - mDesktop->setSize(screenWidth, screenHeight); + mDesktop->setSize(graphics->getWidth(), graphics->getHeight()); } if (mState == STATE_SWITCH_LOGIN && mOldState == STATE_GAME) @@ -601,8 +601,8 @@ int Client::exec() if (mOldState == STATE_GAME) { - delete game; - game = 0; + delete mGame; + mGame = 0; } mOldState = mState; @@ -866,7 +866,7 @@ int Client::exec() mCurrentDialog = NULL; logger->log("State: GAME"); - game = new Game; + mGame = new Game; break; case STATE_LOGIN_ERROR: @@ -1382,3 +1382,30 @@ void Client::accountLogin(LoginData *loginData) config.setValue("username", loginData->username); config.setValue("remember", loginData->remember); } + +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 (graphics->getWidth() == width && graphics->getHeight() == height) + return; + + if (graphics->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(); + } +} |