From ee891c8828e7517fb80a528ed2ac2e51a96e32b6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stephan=20A=C3=9Fmus?= Date: Wed, 1 Sep 2010 13:02:30 +0000 Subject: [PATCH] Do not resize the VideoView to the scaled size of the video anymore, but tell the VideoView the video frame size. So the outside regions of the video are also painted by the VideoView. Not tested with overlays, but should work. The side effect is that the controls appear along the bottom of the screen in full-screen mode. The controls may need to be over the video, so they cannot be attached to the parent of the VideoView (this was already the case). git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@38492 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- src/apps/mediaplayer/MainWin.cpp | 13 ++++++--- src/apps/mediaplayer/VideoView.cpp | 42 +++++++++++++++++++++--------- src/apps/mediaplayer/VideoView.h | 5 +++- 3 files changed, 42 insertions(+), 18 deletions(-) diff --git a/src/apps/mediaplayer/MainWin.cpp b/src/apps/mediaplayer/MainWin.cpp index 6762bad020..1bf5a2307c 100644 --- a/src/apps/mediaplayer/MainWin.cpp +++ b/src/apps/mediaplayer/MainWin.cpp @@ -1666,11 +1666,16 @@ MainWin::_ResizeVideoView(int x, int y, int width, int height) if (renderHeight > height) renderHeight = height; - int xOffset = x + (width - renderWidth) / 2; - int yOffset = y + (height - renderHeight) / 2; + int xOffset = (width - renderWidth) / 2; + int yOffset = (height - renderHeight) / 2; - fVideoView->MoveTo(xOffset, yOffset); - fVideoView->ResizeTo(renderWidth - 1, renderHeight - 1); + fVideoView->MoveTo(x, y); + fVideoView->ResizeTo(width - 1, height - 1); + + BRect videoFrame(xOffset, yOffset, + xOffset + renderWidth - 1, yOffset + renderHeight - 1); + + fVideoView->SetVideoFrame(videoFrame); } diff --git a/src/apps/mediaplayer/VideoView.cpp b/src/apps/mediaplayer/VideoView.cpp index ff0e723eb7..6304a36451 100644 --- a/src/apps/mediaplayer/VideoView.cpp +++ b/src/apps/mediaplayer/VideoView.cpp @@ -1,5 +1,5 @@ /* - * Copyright 2006-2009 Stephan Aßmus + * Copyright 2006-2010 Stephan Aßmus * All rights reserved. Distributed under the terms of the MIT license. */ @@ -21,6 +21,7 @@ #endif #include +#include #include #include "Settings.h" @@ -30,6 +31,7 @@ VideoView::VideoView(BRect frame, const char* name, uint32 resizeMask) : BView(frame, name, resizeMask, B_WILL_DRAW | B_FULL_UPDATE_ON_RESIZE | B_PULSE_NEEDED), + fVideoFrame(Bounds()), fOverlayMode(false), fIsPlaying(false), fIsFullscreen(false), @@ -37,7 +39,6 @@ VideoView::VideoView(BRect frame, const char* name, uint32 resizeMask) fGlobalSettingsListener(this) { SetViewColor(B_TRANSPARENT_COLOR); - // might be reset to overlay key color if overlays are used SetHighColor(0, 0, 0); // create some hopefully sensible default overlay restrictions @@ -61,19 +62,21 @@ VideoView::~VideoView() void VideoView::Draw(BRect updateRect) { - bool fillBlack = true; + BRegion outSideVideoRegion(updateRect); if (LockBitmap()) { if (const BBitmap* bitmap = GetBitmap()) { - fillBlack = false; + outSideVideoRegion.Exclude(fVideoFrame); if (!fOverlayMode) _DrawBitmap(bitmap); + else + FillRect(fVideoFrame & updateRect, B_SOLID_LOW); } UnlockBitmap(); } - if (fillBlack) - FillRect(updateRect); + if (outSideVideoRegion.CountRects() > 0) + FillRegion(&outSideVideoRegion); } @@ -147,15 +150,14 @@ VideoView::SetBitmap(const BBitmap* bitmap) // init overlay rgb_color key; status_t ret = SetViewOverlay(bitmap, bitmap->Bounds(), - Bounds(), &key, B_FOLLOW_ALL, + fVideoFrame, &key, B_FOLLOW_ALL, B_OVERLAY_FILTER_HORIZONTAL | B_OVERLAY_FILTER_VERTICAL); if (ret == B_OK) { fOverlayKeyColor = key; - SetViewColor(key); SetLowColor(key); snooze(20000); - FillRect(Bounds(), B_SOLID_LOW); + FillRect(fVideoFrame, B_SOLID_LOW); Sync(); // use overlay from here on fOverlayMode = true; @@ -168,13 +170,13 @@ VideoView::SetBitmap(const BBitmap* bitmap) } else { // try again next time // synchronous draw - FillRect(Bounds()); + FillRect(fVideoFrame); Sync(); } } else { // transfer overlay channel rgb_color key; - SetViewOverlay(bitmap, bitmap->Bounds(), Bounds(), + SetViewOverlay(bitmap, bitmap->Bounds(), fVideoFrame, &key, B_FOLLOW_ALL, B_OVERLAY_FILTER_HORIZONTAL | B_OVERLAY_FILTER_VERTICAL | B_OVERLAY_TRANSFER_CHANNEL); @@ -270,6 +272,20 @@ VideoView::SetFullscreen(bool fullScreen) } +void +VideoView::SetVideoFrame(const BRect& frame) +{ + if (fVideoFrame == frame) + return; + + BRegion invalid(fVideoFrame | frame); + invalid.Exclude(frame); + Invalidate(&invalid); + + fVideoFrame = frame; +} + + // #pragma mark - @@ -278,9 +294,9 @@ VideoView::_DrawBitmap(const BBitmap* bitmap) { #ifdef __HAIKU__ uint32 options = fUseBilinearScaling ? B_FILTER_BITMAP_BILINEAR : 0; - DrawBitmap(bitmap, bitmap->Bounds(), Bounds(), options); + DrawBitmap(bitmap, bitmap->Bounds(), fVideoFrame, options); #else - DrawBitmap(bitmap, bitmap->Bounds(), Bounds()); + DrawBitmap(bitmap, bitmap->Bounds(), fVideoFrame); #endif } diff --git a/src/apps/mediaplayer/VideoView.h b/src/apps/mediaplayer/VideoView.h index a5ebc026a8..444a9549cd 100644 --- a/src/apps/mediaplayer/VideoView.h +++ b/src/apps/mediaplayer/VideoView.h @@ -1,5 +1,5 @@ /* - * Copyright 2006-2009 Stephan Aßmus + * Copyright 2006-2010 Stephan Aßmus * All rights reserved. Distributed under the terms of the MIT license. */ #ifndef VIDEO_VIEW_H @@ -46,11 +46,14 @@ public: void SetPlaying(bool playing); void SetFullscreen(bool fullScreen); + void SetVideoFrame(const BRect& frame); private: void _DrawBitmap(const BBitmap* bitmap); void _AdoptGlobalSettings(); +private: + BRect fVideoFrame; bool fOverlayMode; overlay_restrictions fOverlayRestrictions; rgb_color fOverlayKeyColor;