Send resolution change notification when window is resized.

This commit is contained in:
King_DuckZ 2014-03-12 20:27:11 +01:00
parent 0c6275f41c
commit b627b69221
3 changed files with 20 additions and 3 deletions

View file

@ -31,7 +31,7 @@ namespace cloonel {
namespace { namespace {
///--------------------------------------------------------------------- ///---------------------------------------------------------------------
///--------------------------------------------------------------------- ///---------------------------------------------------------------------
bool DoEvents (InputBag& parInput) { bool DoEvents (InputBag& parInput, SDLMain* parSdlMain) {
SDL_Event eve; SDL_Event eve;
while (SDL_PollEvent(&eve)) { while (SDL_PollEvent(&eve)) {
switch (eve.type) { switch (eve.type) {
@ -46,6 +46,15 @@ namespace cloonel {
case SDL_QUIT: case SDL_QUIT:
return true; return true;
case SDL_WINDOWEVENT:
if (SDL_WINDOWEVENT_RESIZED == eve.window.event) {
parSdlMain->SetResolution(ushort2(static_cast<uint16_t>(eve.window.data1), static_cast<uint16_t>(eve.window.data2)));
}
else if (SDL_WINDOWEVENT_CLOSE == eve.window.event) {
return true;
}
break;
} }
} }
return false; return false;
@ -82,7 +91,7 @@ namespace cloonel {
OnRender(); OnRender();
SDL_RenderPresent(ren); SDL_RenderPresent(ren);
m_wantsToQuit = DoEvents(*m_input); m_wantsToQuit = DoEvents(*m_input, m_sdlmain);
m_input->KeyStateUpdateFinished(); m_input->KeyStateUpdateFinished();
return delta; return delta;

View file

@ -75,7 +75,7 @@ namespace cloonel {
throw std::runtime_error(SDL_GetError()); throw std::runtime_error(SDL_GetError());
parInitSDL.initialized = true; parInitSDL.initialized = true;
SDL_Window* const win = SDL_CreateWindow(m_gameName.c_str(), 100, 100, m_WH.x(), m_WH.y(), SDL_WINDOW_SHOWN); SDL_Window* const win = SDL_CreateWindow(m_gameName.c_str(), 100, 100, m_WH.x(), m_WH.y(), SDL_WINDOW_SHOWN | SDL_WINDOW_RESIZABLE);
if (!win) if (!win)
throw std::runtime_error(SDL_GetError()); throw std::runtime_error(SDL_GetError());
parInitSDL.window = win; parInitSDL.window = win;
@ -105,4 +105,11 @@ namespace cloonel {
else else
return nullptr; return nullptr;
} }
///------------------------------------------------------------------------
///------------------------------------------------------------------------
void SDLMain::SetResolution (ushort2 parRes) {
m_WHScaling = GetScaling(parRes, m_WHRef);
m_WH = parRes;
}
} //namespace cloonel } //namespace cloonel

View file

@ -35,6 +35,7 @@ namespace cloonel {
SDL_Renderer* GetRenderer ( void ); SDL_Renderer* GetRenderer ( void );
const ushort2& WidthHeight ( void ) const { return m_WH; } const ushort2& WidthHeight ( void ) const { return m_WH; }
const float2& WHScaling ( void ) const { return m_WHScaling; } const float2& WHScaling ( void ) const { return m_WHScaling; }
void SetResolution ( ushort2 parRes );
private: private:
struct LocalData; struct LocalData;