Fix crashes when changing toggling fullscreen/windowed mode.

- Only allow such changes when in emulation mode, or a few other common ones (launcher, debugger)
  The idea is here that some dialogs have to be resized/repositioned when such a mode change occurs, and the UI core doesn't currently support that.
- Only render surfaces when they are visible (sounds logical enough, but the code didn't check for it).
This commit is contained in:
Stephen Anthony 2018-08-15 13:33:08 -02:30
parent c2ce29ed78
commit 31acc92bbe
3 changed files with 25 additions and 15 deletions

View File

@ -652,6 +652,22 @@ void FrameBuffer::stateChanged(EventHandlerState state)
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void FrameBuffer::setFullscreen(bool enable)
{
// Switching between fullscreen and windowed modes will invariably mean
// that the 'window' resolution changes. Currently, dialogs are not
// able to resize themselves when they are actively being shown
// (they would have to be closed and then re-opened, etc).
// For now, we simply disallow screen switches in such modes
switch(myOSystem.eventHandler().state())
{
case EventHandlerState::EMULATION:
case EventHandlerState::LAUNCHER:
case EventHandlerState::DEBUGGER:
case EventHandlerState::PAUSE:
break; // continue with processing (aka, allow a mode switch)
default:
return;
}
const VideoMode& mode = getSavedVidMode(enable);
if(setVideoMode(myScreenTitle, mode))
{

View File

@ -142,19 +142,16 @@ void Dialog::setTitle(const string& title)
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void Dialog::center()
{
if(_surface)
{
const GUI::Size& screen = instance().frameBuffer().screenSize();
const GUI::Rect& dst = _surface->dstRect();
_surface->setDstPos((screen.w - dst.width()) >> 1, (screen.h - dst.height()) >> 1);
}
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
bool Dialog::render()
{
if(!_dirty)
if(!_dirty || !isVisible())
return false;
// Draw this dialog

View File

@ -110,15 +110,12 @@ struct Rect
uInt32 top, left; //!< The point at the top left of the rectangle (part of the rect).
uInt32 bottom, right; //!< The point at the bottom right of the rectangle (not part of the rect).
Rect() : top(0), left(0), bottom(0), right(0) { }
Rect(const Rect& s) : top(s.top), left(s.left), bottom(s.bottom), right(s.right) { }
Rect() : top(0), left(0), bottom(0), right(0) { assert(valid()); }
Rect(const Rect& s) : top(s.top), left(s.left), bottom(s.bottom), right(s.right) { assert(valid()); }
Rect& operator=(const Rect&) = default;
Rect(uInt32 w, uInt32 h) : top(0), left(0), bottom(h), right(w) { }
Rect(const Point& p, uInt32 w, uInt32 h) : top(p.y), left(p.x), bottom(h), right(w) { }
Rect(uInt32 x1, uInt32 y1, uInt32 x2, uInt32 y2) : top(y1), left(x1), bottom(y2), right(x2)
{
assert(valid());
}
Rect(uInt32 w, uInt32 h) : top(0), left(0), bottom(h), right(w) { assert(valid()); }
Rect(const Point& p, uInt32 w, uInt32 h) : top(p.y), left(p.x), bottom(h), right(w) { assert(valid()); }
Rect(uInt32 x1, uInt32 y1, uInt32 x2, uInt32 y2) : top(y1), left(x1), bottom(y2), right(x2) { assert(valid()); }
uInt32 x() const { return left; }
uInt32 y() const { return top; }