From 6da40f2e247227ce72833cc1b5d3b5c7708e9e49 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stephan=20A=C3=9Fmus?= Date: Tue, 14 Jul 2009 12:50:38 +0000 Subject: [PATCH] Fixed more bugs with re-layouting when switching clips: * In full screen mode, make sure to relayout the video view if size and/or aspect change. Also adjust the window size limits (for later). * Add optional code to _ResizeWindow() to make sure the window is fully on screen. When it is out on one side, move it back in, when it is too large, scale and center it so all the border is visible. This code is used when switching clips if not in full screen mode. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@31559 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- src/apps/mediaplayer/MainWin.cpp | 79 ++++++++++++++++++++++++++++---- src/apps/mediaplayer/MainWin.h | 3 +- 2 files changed, 71 insertions(+), 11 deletions(-) diff --git a/src/apps/mediaplayer/MainWin.cpp b/src/apps/mediaplayer/MainWin.cpp index 8b44e4f25f..895866dd89 100644 --- a/src/apps/mediaplayer/MainWin.cpp +++ b/src/apps/mediaplayer/MainWin.cpp @@ -888,13 +888,21 @@ MainWin::_SetupWindow() } _UpdateControlsEnabledStatus(); - // adopt the size and window layout if necessary - if (!fIsFullscreen && (previousSourceWidth != fSourceWidth - || previousSourceHeight != fSourceHeight - || previousWidthAspect != fWidthAspect - || previousHeightAspect != fHeightAspect)) { + // Adopt the size and window layout if necessary + if (previousSourceWidth != fSourceWidth + || previousSourceHeight != fSourceHeight + || previousWidthAspect != fWidthAspect + || previousHeightAspect != fHeightAspect) { + _SetWindowSizeLimits(); - _ResizeWindow(100); + + if (!fIsFullscreen) { + // Resize to 100% but stay on screen + _ResizeWindow(100, true); + } else { + // Make sure we relayout the video view when in full screen mode + FrameResized(Frame().Width(), Frame().Height()); + } } fVideoView->MakeFocus(); @@ -1154,7 +1162,7 @@ MainWin::_CurrentVideoSizeInPercent() const void -MainWin::_ResizeWindow(int percent) +MainWin::_ResizeWindow(int percent, bool stayOnScreen) { // Get required window size int videoWidth; @@ -1169,9 +1177,60 @@ MainWin::_ResizeWindow(int percent) int height; _GetMinimumWindowSize(width, height); - width = max_c(width, videoWidth); - height = height + videoHeight; - ResizeTo(width - 1, height - 1); + width = max_c(width, videoWidth) - 1; + height = height + videoHeight - 1; + + if (stayOnScreen) { + BRect screenFrame(BScreen(this).Frame()); + BRect frame(Frame()); + BRect decoratorFrame(DecoratorFrame()); + + // Shrink the screen frame by the window border size + screenFrame.top += frame.top - decoratorFrame.top; + screenFrame.left += frame.left - decoratorFrame.left; + screenFrame.right += frame.right - decoratorFrame.right; + screenFrame.bottom += frame.bottom - decoratorFrame.bottom; + + // Update frame to what the new size would be + frame.right = frame.left + width; + frame.bottom = frame.top + height; + + if (!screenFrame.Contains(frame)) { + // Resize the window so it doesn't extend outside the current + // screen frame. + if (frame.Width() > screenFrame.Width() + || frame.Height() > screenFrame.Height()) { + // too large + int widthDiff = frame.Width() - screenFrame.Width(); + int heightDiff = frame.Height() - screenFrame.Height(); + float shrinkScale; + if (widthDiff > heightDiff) + shrinkScale = (float)(width - widthDiff) / width; + else + shrinkScale = (float)(height - heightDiff) / height; + // Resize width/height and center window + width = lround(width * shrinkScale); + height = lround(height * shrinkScale); + MoveTo((screenFrame.left + screenFrame.right - width) / 2, + (screenFrame.top + screenFrame.bottom - height) / 2); + } else { + // just off-screen on one or more sides + int offsetX = 0; + int offsetY = 0; + if (frame.left < screenFrame.left) + offsetX = screenFrame.left - frame.left; + else if (frame.right > screenFrame.right) + offsetX = screenFrame.right - frame.right; + if (frame.top < screenFrame.top) + offsetX = screenFrame.top - frame.top; + else if (frame.bottom > screenFrame.bottom) + offsetX = screenFrame.bottom - frame.bottom; + MoveBy(offsetX, offsetY); + } + } + } + + ResizeTo(width, height); } diff --git a/src/apps/mediaplayer/MainWin.h b/src/apps/mediaplayer/MainWin.h index 6a2697cffd..8af4a529b3 100644 --- a/src/apps/mediaplayer/MainWin.h +++ b/src/apps/mediaplayer/MainWin.h @@ -82,7 +82,8 @@ private: void _GetUnscaledVideoSize(int& videoWidth, int& videoHeight) const; int _CurrentVideoSizeInPercent() const; - void _ResizeWindow(int percent); + void _ResizeWindow(int percent, + bool stayOnScreen = false); void _ResizeVideoView(int x, int y, int width, int height);