Send resolution change notification when window is resized.
This commit is contained in:
parent
0c6275f41c
commit
b627b69221
3 changed files with 20 additions and 3 deletions
|
@ -31,7 +31,7 @@ namespace cloonel {
|
|||
namespace {
|
||||
///---------------------------------------------------------------------
|
||||
///---------------------------------------------------------------------
|
||||
bool DoEvents (InputBag& parInput) {
|
||||
bool DoEvents (InputBag& parInput, SDLMain* parSdlMain) {
|
||||
SDL_Event eve;
|
||||
while (SDL_PollEvent(&eve)) {
|
||||
switch (eve.type) {
|
||||
|
@ -46,6 +46,15 @@ namespace cloonel {
|
|||
|
||||
case SDL_QUIT:
|
||||
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;
|
||||
|
@ -82,7 +91,7 @@ namespace cloonel {
|
|||
OnRender();
|
||||
SDL_RenderPresent(ren);
|
||||
|
||||
m_wantsToQuit = DoEvents(*m_input);
|
||||
m_wantsToQuit = DoEvents(*m_input, m_sdlmain);
|
||||
m_input->KeyStateUpdateFinished();
|
||||
|
||||
return delta;
|
||||
|
|
|
@ -75,7 +75,7 @@ namespace cloonel {
|
|||
throw std::runtime_error(SDL_GetError());
|
||||
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)
|
||||
throw std::runtime_error(SDL_GetError());
|
||||
parInitSDL.window = win;
|
||||
|
@ -105,4 +105,11 @@ namespace cloonel {
|
|||
else
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
///------------------------------------------------------------------------
|
||||
///------------------------------------------------------------------------
|
||||
void SDLMain::SetResolution (ushort2 parRes) {
|
||||
m_WHScaling = GetScaling(parRes, m_WHRef);
|
||||
m_WH = parRes;
|
||||
}
|
||||
} //namespace cloonel
|
||||
|
|
|
@ -35,6 +35,7 @@ namespace cloonel {
|
|||
SDL_Renderer* GetRenderer ( void );
|
||||
const ushort2& WidthHeight ( void ) const { return m_WH; }
|
||||
const float2& WHScaling ( void ) const { return m_WHScaling; }
|
||||
void SetResolution ( ushort2 parRes );
|
||||
|
||||
private:
|
||||
struct LocalData;
|
||||
|
|
Loading…
Reference in a new issue