switch to next mode on "N" key press

This commit is contained in:
Josh Holtrop 2019-10-12 17:41:32 -04:00
parent 28436244da
commit 98bfeb6afa
2 changed files with 15 additions and 4 deletions

View File

@ -30,7 +30,7 @@ static SDL_Event event;
SSMain::SSMain(int width, int height, int numMonitors, SDL_Surface * sdlSurface)
: m_width (width), m_height (height),
m_numMonitors (numMonitors), m_sdlSurface (sdlSurface),
m_mode(NULL), m_drawing(false)
m_mode(NULL), m_drawing(false), m_switchmode(false)
{
/* set up some common OpenGL defaults */
glShadeModel(GL_SMOOTH);
@ -91,17 +91,27 @@ void SSMain::run()
if (elapsed_msec >= SCREENSAVER_MAX_RUNTIME)
goto RET;
#endif
if (elapsed_msec - lastChanged_msec > SSMODE_TIMEOUT_MSEC)
if (m_switchmode || (elapsed_msec - lastChanged_msec > SSMODE_TIMEOUT_MSEC))
{
delete m_mode;
m_mode = startMode();
lastChanged_msec = elapsed_msec;
m_switchmode = false;
}
switch (event.type)
{
case SDL_KEYDOWN: /* terminate screensaver upon */
case SDL_QUIT: /* key press or quit event */
case SDL_KEYDOWN:
if (event.key.keysym.sym == SDLK_n)
{
m_switchmode = true; /* switch to next mode on 'N' key */
}
else
{
goto RET; /* terminate on other key */
}
break;
case SDL_QUIT: /* terminate on quit event */
goto RET;
case SDL_MOUSEBUTTONDOWN:
if (event.button.button == 1)

View File

@ -36,6 +36,7 @@ protected:
SDL_Surface * m_sdlSurface;
SSMode * m_mode;
bool m_drawing;
bool m_switchmode;
};
#endif