Skip to content
Snippets Groups Projects
Commit 3be9922b authored by Oliver Behnke's avatar Oliver Behnke
Browse files

Completed fullscreen mode and window resizing

parent 467e3bf3
No related branches found
No related tags found
1 merge request!1Move macOS build to 64 bit
/*************************************************************************** /***************************************************************************
* Copyright (C) 2008 by Oliver Bock * * Copyright (C) 2008-2020 by Oliver Bock *
* oliver.bock[AT]aei.mpg.de * * oliver.bock[AT]aei.mpg.de *
* * * *
* This file is part of Einstein@Home. * * This file is part of Einstein@Home. *
...@@ -73,11 +73,12 @@ bool WindowManager::initialize(const int width, const int height, const int fram ...@@ -73,11 +73,12 @@ bool WindowManager::initialize(const int width, const int height, const int fram
*/ */
// set common video flags // set common video flags
// (for OpenGL nothing more than SDL_WINDOW_OPENGL and SDL_WINDOW_FULLSCREEN should be used) m_VideoModeFlags = SDL_WINDOW_OPENGL | SDL_WINDOW_RESIZABLE;
m_VideoModeFlags = SDL_WINDOW_OPENGL; // enable HDPI (retina) support
// m_VideoModeFlags |= SDL_WINDOW_ALLOW_HIGHDPI;
// // check fullscreen video mode // check fullscreen video mode
// m_FullscreenModeAvailable = true; m_FullscreenModeAvailable = true;
// Uint32 bitPerPixel = SDL_VideoModeOK( // Uint32 bitPerPixel = SDL_VideoModeOK(
// m_DesktopWidth, // m_DesktopWidth,
// m_DesktopHeight, // m_DesktopHeight,
...@@ -89,8 +90,8 @@ bool WindowManager::initialize(const int width, const int height, const int fram ...@@ -89,8 +90,8 @@ bool WindowManager::initialize(const int width, const int height, const int fram
// m_FullscreenModeAvailable = false; // m_FullscreenModeAvailable = false;
// } // }
// //
// // check initial windowed video mode // check initial windowed video mode
// m_WindowedModeAvailable = true; m_WindowedModeAvailable = true;
// bitPerPixel = SDL_VideoModeOK( // bitPerPixel = SDL_VideoModeOK(
// m_WindowedWidth, // m_WindowedWidth,
// m_WindowedHeight, // m_WindowedHeight,
...@@ -133,7 +134,6 @@ bool WindowManager::initialize(const int width, const int height, const int fram ...@@ -133,7 +134,6 @@ bool WindowManager::initialize(const int width, const int height, const int fram
// we always start in windowed mode (starting in fullscreen fails with high CPU load!) // we always start in windowed mode (starting in fullscreen fails with high CPU load!)
m_CurrentWidth = m_WindowedWidth; m_CurrentWidth = m_WindowedWidth;
m_CurrentHeight = m_WindowedHeight; m_CurrentHeight = m_WindowedHeight;
m_VideoModeFlags |= SDL_WINDOW_RESIZABLE;
// finally, get window // finally, get window
m_Window = SDL_CreateWindow( m_Window = SDL_CreateWindow(
...@@ -204,7 +204,7 @@ void WindowManager::eventLoop() ...@@ -204,7 +204,7 @@ void WindowManager::eventLoop()
//SDL_EventState(SDL_KEYDOWN, SDL_IGNORE); //SDL_EventState(SDL_KEYDOWN, SDL_IGNORE);
//SDL_EventState(SDL_MOUSEMOTION, SDL_IGNORE); //SDL_EventState(SDL_MOUSEMOTION, SDL_IGNORE);
//SDL_EventState(SDL_MOUSEBUTTONDOWN, SDL_IGNORE); //SDL_EventState(SDL_MOUSEBUTTONDOWN, SDL_IGNORE);
//SDL_EventState(SDL_VIDEORESIZE, SDL_IGNORE); //SDL_EventState(SDL_WINDOWEVENT_SIZE_CHANGED, SDL_IGNORE);
//SDL_EventState(SDL_USEREVENT, SDL_IGNORE); //SDL_EventState(SDL_USEREVENT, SDL_IGNORE);
// events we ignore // events we ignore
...@@ -251,6 +251,8 @@ void WindowManager::eventLoop() ...@@ -251,6 +251,8 @@ void WindowManager::eventLoop()
event.type == SDL_KEYDOWN)) { event.type == SDL_KEYDOWN)) {
// we're in screensaver mode so exit on user input // we're in screensaver mode so exit on user input
SDL_GL_DeleteContext(m_GLContext);
SDL_DestroyWindow(m_Window);
SDL_Quit(); SDL_Quit();
} }
else if (event.motion.state & (SDL_BUTTON(1) | SDL_BUTTON(3)) && else if (event.motion.state & (SDL_BUTTON(1) | SDL_BUTTON(3)) &&
...@@ -275,17 +277,6 @@ void WindowManager::eventLoop() ...@@ -275,17 +277,6 @@ void WindowManager::eventLoop()
m_CurrentWidth = m_WindowedWidth = event.window.data1; m_CurrentWidth = m_WindowedWidth = event.window.data1;
m_CurrentHeight = m_WindowedHeight = event.window.data2; m_CurrentHeight = m_WindowedHeight = event.window.data2;
// update video mode
// FIXME: reuse old title/position
SDL_DestroyWindow(m_Window);
m_Window = SDL_CreateWindow(
"Einstein@Home",
SDL_WINDOWPOS_UNDEFINED,
SDL_WINDOWPOS_UNDEFINED,
m_CurrentWidth,
m_CurrentHeight,
m_VideoModeFlags);
// notify our observers (currently exactly one, hence front()) // notify our observers (currently exactly one, hence front())
// (windoze needs to be reinitialized instead of just resized, oh well) // (windoze needs to be reinitialized instead of just resized, oh well)
/// \todo Can we determine the host OS? On X11 a resize() is sufficient! /// \todo Can we determine the host OS? On X11 a resize() is sufficient!
...@@ -440,51 +431,27 @@ void WindowManager::setWindowIcon(const unsigned char *data, const int size) con ...@@ -440,51 +431,27 @@ void WindowManager::setWindowIcon(const unsigned char *data, const int size) con
void WindowManager::toggleFullscreen() void WindowManager::toggleFullscreen()
{ {
// toggle fullscreen bit and reset video mode
if(m_WindowedModeAvailable && (m_VideoModeFlags & SDL_WINDOW_FULLSCREEN)) { if(m_WindowedModeAvailable && (m_VideoModeFlags & SDL_WINDOW_FULLSCREEN)) {
// set new dimensions // restore windowed mode
m_CurrentWidth = m_WindowedWidth; SDL_SetWindowFullscreen(m_Window, 0);
m_CurrentHeight = m_WindowedHeight;
// (un)set video mode flags
m_VideoModeFlags &= ~SDL_WINDOW_FULLSCREEN;
m_VideoModeFlags |= SDL_WINDOW_RESIZABLE;
// show cursor in fullscreen mode // show cursor
SDL_ShowCursor(SDL_ENABLE); SDL_ShowCursor(SDL_ENABLE);
// store state
m_VideoModeFlags &= ~SDL_WINDOW_FULLSCREEN;
} }
else if(m_FullscreenModeAvailable && !(m_VideoModeFlags & SDL_WINDOW_FULLSCREEN)) { else if(m_FullscreenModeAvailable && !(m_VideoModeFlags & SDL_WINDOW_FULLSCREEN)) {
// set new dimensions // enable fullscreen mode
m_CurrentWidth = m_DesktopWidth; // (not using real SDL_WINDOW_FULLSCREEN which triggers a SDL_MOUSEMOTION event)
m_CurrentHeight = m_DesktopHeight; SDL_SetWindowFullscreen(m_Window, SDL_WINDOW_FULLSCREEN_DESKTOP);
// (un)set video mode flags
#ifdef __APPLE__
if (m_ScreensaverMode) {
m_CurrentWidth = m_DesktopWidth;
m_CurrentHeight = m_DesktopHeight;
m_VideoModeFlags |= SDL_WINDOW_BORDERLESS;
} else
#endif
{
m_VideoModeFlags |= SDL_WINDOW_FULLSCREEN;
}
m_VideoModeFlags &= ~SDL_WINDOW_RESIZABLE;
// hide cursor // hide cursor
SDL_ShowCursor(SDL_DISABLE); SDL_ShowCursor(SDL_DISABLE);
}
// reset video mode // store state
// FIXME: reuse old title/position m_VideoModeFlags |= SDL_WINDOW_FULLSCREEN;
SDL_DestroyWindow(m_Window); }
m_Window = SDL_CreateWindow(
"Einstein@Home",
SDL_WINDOWPOS_UNDEFINED,
SDL_WINDOWPOS_UNDEFINED,
m_CurrentWidth,
m_CurrentHeight,
m_VideoModeFlags);
// notify our observers (currently exactly one, hence front()) // notify our observers (currently exactly one, hence front())
// (windoze needs to be reinitialized instead of just resized, oh well) // (windoze needs to be reinitialized instead of just resized, oh well)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment