cleaned up resizing
git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@17215 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
parent
99cd5eeb92
commit
399b0e8ab8
@ -33,10 +33,15 @@
|
|||||||
#include <PopUpMenu.h>
|
#include <PopUpMenu.h>
|
||||||
#include <String.h>
|
#include <String.h>
|
||||||
#include <Debug.h>
|
#include <Debug.h>
|
||||||
|
#include <math.h>
|
||||||
|
|
||||||
#define NAME "MediaPlayer"
|
#define NAME "MediaPlayer"
|
||||||
#define MIN_WIDTH 250
|
#define MIN_WIDTH 250
|
||||||
|
|
||||||
|
|
||||||
|
// XXX TODO: why is lround not defined?
|
||||||
|
#define lround(a) ((int)(0.99999 + (a)))
|
||||||
|
|
||||||
enum
|
enum
|
||||||
{
|
{
|
||||||
M_DUMMY = 0x100,
|
M_DUMMY = 0x100,
|
||||||
@ -81,7 +86,7 @@ enum
|
|||||||
|
|
||||||
|
|
||||||
MainWin::MainWin()
|
MainWin::MainWin()
|
||||||
: BWindow(BRect(200,200,450,400), NAME, B_TITLED_WINDOW, B_ASYNCHRONOUS_CONTROLS /* | B_WILL_ACCEPT_FIRST_CLICK */)
|
: BWindow(BRect(100,100,350,300), NAME, B_TITLED_WINDOW, B_ASYNCHRONOUS_CONTROLS /* | B_WILL_ACCEPT_FIRST_CLICK */)
|
||||||
, fFilePanel(NULL)
|
, fFilePanel(NULL)
|
||||||
, fHasFile(false)
|
, fHasFile(false)
|
||||||
, fHasVideo(false)
|
, fHasVideo(false)
|
||||||
@ -101,6 +106,10 @@ MainWin::MainWin()
|
|||||||
, fIgnoreFrameResized(false)
|
, fIgnoreFrameResized(false)
|
||||||
, fFrameResizedCalled(true)
|
, fFrameResizedCalled(true)
|
||||||
{
|
{
|
||||||
|
static int pos = 0;
|
||||||
|
MoveBy(pos * 25, pos * 25);
|
||||||
|
pos = (pos + 1) % 15;
|
||||||
|
|
||||||
BRect rect = Bounds();
|
BRect rect = Bounds();
|
||||||
|
|
||||||
// background
|
// background
|
||||||
@ -114,11 +123,11 @@ MainWin::MainWin()
|
|||||||
fBackground->AddChild(fMenuBar);
|
fBackground->AddChild(fMenuBar);
|
||||||
fMenuBar->ResizeToPreferred();
|
fMenuBar->ResizeToPreferred();
|
||||||
fMenuBarHeight = (int)fMenuBar->Frame().Height() + 1;
|
fMenuBarHeight = (int)fMenuBar->Frame().Height() + 1;
|
||||||
fMenuBar->SetResizingMode(B_FOLLOW_TOP | B_FOLLOW_LEFT_RIGHT);
|
fMenuBar->SetResizingMode(B_FOLLOW_NONE);
|
||||||
|
|
||||||
// video view
|
// video view
|
||||||
rect = BRect(0, fMenuBarHeight, fBackground->Bounds().right, fMenuBarHeight + 10);
|
rect = BRect(0, fMenuBarHeight, fBackground->Bounds().right, fMenuBarHeight + 10);
|
||||||
fVideoView = new VideoView(rect, "video display", B_FOLLOW_ALL, B_WILL_DRAW | B_FULL_UPDATE_ON_RESIZE);
|
fVideoView = new VideoView(rect, "video display", B_FOLLOW_NONE, B_WILL_DRAW | B_FULL_UPDATE_ON_RESIZE);
|
||||||
fBackground->AddChild(fVideoView);
|
fBackground->AddChild(fVideoView);
|
||||||
|
|
||||||
// controls
|
// controls
|
||||||
@ -128,10 +137,10 @@ MainWin::MainWin()
|
|||||||
fControls->ResizeToPreferred();
|
fControls->ResizeToPreferred();
|
||||||
fControlsHeight = (int)fControls->Frame().Height() + 1;
|
fControlsHeight = (int)fControls->Frame().Height() + 1;
|
||||||
fControlsWidth = (int)fControls->Frame().Width() + 1;
|
fControlsWidth = (int)fControls->Frame().Width() + 1;
|
||||||
fControls->SetResizingMode(B_FOLLOW_BOTTOM | B_FOLLOW_LEFT_RIGHT);
|
fControls->SetResizingMode(B_FOLLOW_NONE);
|
||||||
fControls->MoveTo(0, fBackground->Bounds().bottom - fControlsHeight + 1);
|
// fControls->MoveTo(0, fBackground->Bounds().bottom - fControlsHeight + 1);
|
||||||
|
|
||||||
fVideoView->ResizeTo(fBackground->Bounds().Width(), fBackground->Bounds().Height() - fMenuBarHeight - fControlsHeight);
|
// fVideoView->ResizeTo(fBackground->Bounds().Width(), fBackground->Bounds().Height() - fMenuBarHeight - fControlsHeight);
|
||||||
|
|
||||||
fController->SetVideoView(fVideoView);
|
fController->SetVideoView(fVideoView);
|
||||||
fVideoView->IsOverlaySupported();
|
fVideoView->IsOverlaySupported();
|
||||||
@ -197,23 +206,18 @@ MainWin::SetupWindow()
|
|||||||
fWidthScale = 1.24;
|
fWidthScale = 1.24;
|
||||||
fHeightScale = 1.35;
|
fHeightScale = 1.35;
|
||||||
} else {
|
} else {
|
||||||
fSourceWidth = 320;
|
fSourceWidth = 0;
|
||||||
fSourceHeight = 240;
|
fSourceHeight = 0;
|
||||||
fWidthScale = 1.24;
|
fWidthScale = 1.0;
|
||||||
fHeightScale = 1.35;
|
fHeightScale = 1.0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int video_width;
|
int video_width;
|
||||||
int video_height;
|
int video_height;
|
||||||
|
|
||||||
// get required window size
|
// get required window size
|
||||||
if (fHasVideo) {
|
video_width = lround(fSourceWidth * fWidthScale);
|
||||||
video_width = 400;
|
video_height = lround(fSourceHeight * fHeightScale);
|
||||||
video_height = 300;
|
|
||||||
} else {
|
|
||||||
video_width = 0;
|
|
||||||
video_height = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Calculate and set the initial window size
|
// Calculate and set the initial window size
|
||||||
int width = max_c(fControlsWidth, video_width);
|
int width = max_c(fControlsWidth, video_width);
|
||||||
@ -503,18 +507,9 @@ MainWin::VideoFormatChange(int width, int height, float width_scale, float heigh
|
|||||||
fWidthScale = width_scale;
|
fWidthScale = width_scale;
|
||||||
fHeightScale = height_scale;
|
fHeightScale = height_scale;
|
||||||
|
|
||||||
/*
|
FrameResized(Bounds().Width(), Bounds().Height());
|
||||||
// ResizeWindow(Bounds().Width() + 1, Bounds().Height() + 1, true);
|
|
||||||
|
|
||||||
if (fIsFullscreen) {
|
|
||||||
AdjustFullscreenRenderer();
|
|
||||||
} else {
|
|
||||||
AdjustWindowedRenderer(false);
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
|
|
||||||
printf("VideoFormatChange leave\n");
|
printf("VideoFormatChange leave\n");
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -532,63 +527,51 @@ MainWin::FrameResized(float new_width, float new_height)
|
|||||||
debugger("size wrong\n");
|
debugger("size wrong\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool no_menu = fNoMenu || fIsFullscreen;
|
||||||
|
bool no_controls = fNoControls || fIsFullscreen;
|
||||||
|
|
||||||
printf("FrameResized enter: new_width %.0f, new_height %.0f\n", new_width, new_height);
|
printf("FrameResized enter: new_width %.0f, new_height %.0f\n", new_width, new_height);
|
||||||
|
|
||||||
int max_video_width = new_width + 1;
|
int max_video_width = int(new_width) + 1;
|
||||||
int max_video_height = new_height + 1;
|
int max_video_height = int(new_height) + 1 - (no_menu ? 0 : fMenuBarHeight) - (no_controls ? 0 : fControlsHeight);
|
||||||
if (!fNoMenu)
|
|
||||||
max_video_height -= fMenuBarHeight;
|
|
||||||
if (!fNoControls)
|
|
||||||
max_video_height -= fControlsHeight;
|
|
||||||
|
|
||||||
ASSERT(max_video_height >= 0);
|
ASSERT(max_video_height >= 0);
|
||||||
|
|
||||||
if (max_video_height == 0 && !fVideoView->IsHidden())
|
int y = 0;
|
||||||
fVideoView->Hide();
|
|
||||||
if (max_video_height != 0 && fVideoView->IsHidden())
|
|
||||||
fVideoView->Show();
|
|
||||||
|
|
||||||
fVideoViewBounds = BRect(0, fNoMenu ? 0 : fMenuBarHeight, max_video_width - 1, max_video_height - 1);
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
return;
|
|
||||||
|
|
||||||
printf("FrameResized enter: new_width %.0f, new_height %.0f, bounds width %.0f, bounds height %.0f\n", new_width, new_height, Bounds().Width(), Bounds().Height());
|
|
||||||
|
|
||||||
if (fIsFullscreen) {
|
|
||||||
|
|
||||||
printf("FrameResized in fullscreen mode\n");
|
|
||||||
|
|
||||||
fIgnoreFrameResized = false;
|
|
||||||
AdjustFullscreenRenderer();
|
|
||||||
|
|
||||||
|
if (no_menu) {
|
||||||
|
if (!fMenuBar->IsHidden())
|
||||||
|
fMenuBar->Hide();
|
||||||
} else {
|
} else {
|
||||||
|
// fMenuBar->MoveTo(0, y);
|
||||||
if (fFrameResizedTriggeredAutomatically) {
|
fMenuBar->ResizeTo(new_width, fMenuBarHeight - 1);
|
||||||
fFrameResizedTriggeredAutomatically = false;
|
if (fMenuBar->IsHidden())
|
||||||
printf("FrameResized triggered automatically\n");
|
fMenuBar->Show();
|
||||||
|
y += fMenuBarHeight;
|
||||||
fIgnoreFrameResized = false;
|
}
|
||||||
|
|
||||||
AdjustWindowedRenderer(false);
|
if (max_video_height == 0) {
|
||||||
} else {
|
if (!fVideoView->IsHidden())
|
||||||
printf("FrameResized by user in window mode\n");
|
fVideoView->Hide();
|
||||||
|
} else {
|
||||||
if (fIgnoreFrameResized) {
|
// fVideoView->MoveTo(0, y);
|
||||||
fIgnoreFrameResized = false;
|
// fVideoView->ResizeTo(max_video_width - 1, max_video_height - 1);
|
||||||
printf("FrameResized ignored\n");
|
ResizeVideoView(0, y, max_video_width, max_video_height);
|
||||||
return;
|
if (fVideoView->IsHidden())
|
||||||
}
|
fVideoView->Show();
|
||||||
|
y += max_video_height;
|
||||||
AdjustWindowedRenderer(true);
|
}
|
||||||
}
|
|
||||||
|
if (no_controls) {
|
||||||
|
if (!fControls->IsHidden())
|
||||||
|
fControls->Hide();
|
||||||
|
} else {
|
||||||
|
fControls->MoveTo(0, y);
|
||||||
|
fControls->ResizeTo(new_width, fControlsHeight - 1);
|
||||||
|
if (fControls->IsHidden())
|
||||||
|
fControls->Show();
|
||||||
|
// y += fControlsHeight;
|
||||||
}
|
}
|
||||||
*/
|
|
||||||
|
|
||||||
printf("FrameResized leave\n");
|
printf("FrameResized leave\n");
|
||||||
}
|
}
|
||||||
@ -608,95 +591,38 @@ MainWin::UpdateWindowTitle()
|
|||||||
SetTitle(buf);
|
SetTitle(buf);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
void
|
void
|
||||||
MainWin::AdjustFullscreenRenderer()
|
MainWin::ResizeVideoView(int x, int y, int width, int height)
|
||||||
{
|
{
|
||||||
// n.b. we don't have a menu in fullscreen mode!
|
printf("ResizeVideoView: %d,%d, width %d, height %d\n", x, y, width, height);
|
||||||
|
|
||||||
if (fKeepAspectRatio) {
|
if (fKeepAspectRatio) {
|
||||||
|
// Keep aspect ratio, place video view inside
|
||||||
// Keep aspect ratio, place render inside
|
|
||||||
// the background area (may create black bars).
|
// the background area (may create black bars).
|
||||||
float max_width = fBackground->Bounds().Width() + 1.0f;
|
|
||||||
float max_height = fBackground->Bounds().Height() + 1.0f;
|
|
||||||
float scaled_width = fSourceWidth * fWidthScale;
|
float scaled_width = fSourceWidth * fWidthScale;
|
||||||
float scaled_height = fSourceHeight * fHeightScale;
|
float scaled_height = fSourceHeight * fHeightScale;
|
||||||
float factor = min_c(max_width / scaled_width, max_height / scaled_height);
|
float factor = min_c(width / scaled_width, height / scaled_height);
|
||||||
int render_width = int(scaled_width * factor);
|
int render_width = lround(scaled_width * factor);
|
||||||
int render_height = int(scaled_height * factor);
|
int render_height = lround(scaled_height * factor);
|
||||||
int x_ofs = (int(max_width) - render_width) / 2;
|
if (render_width > width)
|
||||||
int y_ofs = (int(max_height) - render_height) / 2;
|
render_width = width;
|
||||||
|
if (render_height > height)
|
||||||
|
render_height = height;
|
||||||
|
|
||||||
printf("AdjustFullscreenRenderer: background %.1f x %.1f, src video %d x %d, "
|
int x_ofs = x + (width - render_width) / 2;
|
||||||
"scaled video %.3f x %.3f, factor %.3f, render %d x %d, x-ofs %d, y-ofs %d\n",
|
int y_ofs = y + (height - render_height) / 2;
|
||||||
max_width, max_height, fSourceWidth, fSourceHeight, scaled_width, scaled_height,
|
|
||||||
factor, render_width, render_height, x_ofs, y_ofs);
|
|
||||||
|
|
||||||
fVideoView->MoveTo(x_ofs, y_ofs);
|
fVideoView->MoveTo(x_ofs, y_ofs);
|
||||||
fVideoView->ResizeTo(render_width - 1, render_height - 1);
|
fVideoView->ResizeTo(render_width - 1, render_height - 1);
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
|
fVideoView->MoveTo(x, y);
|
||||||
printf("AdjustFullscreenRenderer: using whole background area\n");
|
fVideoView->ResizeTo(width - 1, height - 1);
|
||||||
|
|
||||||
// no need to keep aspect ratio, make
|
|
||||||
// render cover the whole background
|
|
||||||
fVideoView->MoveTo(0, 0);
|
|
||||||
fVideoView->ResizeTo(fBackground->Bounds().Width(), fBackground->Bounds().Height());
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void
|
|
||||||
MainWin::AdjustWindowedRenderer(bool user_resized)
|
|
||||||
{
|
|
||||||
printf("AdjustWindowedRenderer enter - user_resized %d\n", user_resized);
|
|
||||||
|
|
||||||
// In windowed mode, the renderer always covers the
|
|
||||||
// whole background, accounting for the menu
|
|
||||||
fVideoView->MoveTo(0, fNoMenu ? 0 : fMenuBarHeight);
|
|
||||||
fVideoView->ResizeTo(fBackground->Bounds().Width(), fBackground->Bounds().Height() - (fNoMenu ? 0 : fMenuBarHeight));
|
|
||||||
|
|
||||||
if (fKeepAspectRatio) {
|
|
||||||
// To keep the aspect ratio correct, we
|
|
||||||
// do resize the window as required
|
|
||||||
|
|
||||||
float max_width = Bounds().Width() + 1.0f;
|
|
||||||
float max_height = Bounds().Height() + 1.0f - (fNoMenu ? 0 : fMenuBarHeight);
|
|
||||||
float scaled_width = fSourceWidth * fWidthScale;
|
|
||||||
float scaled_height = fSourceHeight * fHeightScale;
|
|
||||||
|
|
||||||
if (!user_resized && (scaled_width > max_width || scaled_height > max_height)) {
|
|
||||||
// A format switch occured, and the window was
|
|
||||||
// smaller then the video source. As it was not
|
|
||||||
// initiated by the user resizing the window, we
|
|
||||||
// enlarge the window to fit the video.
|
|
||||||
fIgnoreFrameResized = true;
|
|
||||||
ResizeTo(scaled_width - 1, scaled_height - 1 + (fNoMenu ? 0 : fMenuBarHeight));
|
|
||||||
// Sync();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
float display_aspect_ratio = scaled_width / scaled_height;
|
|
||||||
int new_width = int(max_width);
|
|
||||||
int new_height = int(max_width / display_aspect_ratio + 0.5);
|
|
||||||
|
|
||||||
printf("AdjustWindowedRenderer: old display %d x %d, src video %d x %d, "
|
|
||||||
"scaled video %.3f x %.3f, aspect ratio %.3f, new display %d x %d\n",
|
|
||||||
int(max_width), int(max_height), fSourceWidth, fSourceHeight, scaled_width, scaled_height,
|
|
||||||
display_aspect_ratio, new_width, new_height);
|
|
||||||
|
|
||||||
fIgnoreFrameResized = true;
|
|
||||||
ResizeTo(new_width - 1, new_height - 1 + (fNoMenu ? 0 : fMenuBarHeight));
|
|
||||||
// Sync();
|
|
||||||
}
|
|
||||||
|
|
||||||
printf("AdjustWindowedRenderer leave\n");
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
|
|
||||||
void
|
void
|
||||||
MainWin::ToggleNoBorderNoMenu()
|
MainWin::ToggleNoBorderNoMenu()
|
||||||
{
|
{
|
||||||
@ -725,13 +651,6 @@ MainWin::ToggleFullscreen()
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!fFrameResizedCalled) {
|
|
||||||
printf("ToggleFullscreen - ignoring, as FrameResized wasn't called since last switch\n");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
fFrameResizedCalled = false;
|
|
||||||
|
|
||||||
|
|
||||||
fIsFullscreen = !fIsFullscreen;
|
fIsFullscreen = !fIsFullscreen;
|
||||||
|
|
||||||
if (fIsFullscreen) {
|
if (fIsFullscreen) {
|
||||||
@ -743,11 +662,6 @@ MainWin::ToggleFullscreen()
|
|||||||
BRect rect(screen.Frame());
|
BRect rect(screen.Frame());
|
||||||
|
|
||||||
Hide();
|
Hide();
|
||||||
if (!fNoMenu) {
|
|
||||||
// if we have a menu, remove it now
|
|
||||||
fMenuBar->Hide();
|
|
||||||
}
|
|
||||||
fFrameResizedTriggeredAutomatically = true;
|
|
||||||
MoveTo(rect.left, rect.top);
|
MoveTo(rect.left, rect.top);
|
||||||
ResizeTo(rect.Width(), rect.Height());
|
ResizeTo(rect.Width(), rect.Height());
|
||||||
Show();
|
Show();
|
||||||
@ -756,19 +670,11 @@ MainWin::ToggleFullscreen()
|
|||||||
// switch back from full screen mode
|
// switch back from full screen mode
|
||||||
|
|
||||||
Hide();
|
Hide();
|
||||||
// if we need a menu, show it now
|
|
||||||
if (!fNoMenu) {
|
|
||||||
fMenuBar->Show();
|
|
||||||
}
|
|
||||||
fFrameResizedTriggeredAutomatically = true;
|
|
||||||
MoveTo(fSavedFrame.left, fSavedFrame.top);
|
MoveTo(fSavedFrame.left, fSavedFrame.top);
|
||||||
ResizeTo(fSavedFrame.Width(), fSavedFrame.Height());
|
ResizeTo(fSavedFrame.Width(), fSavedFrame.Height());
|
||||||
Show();
|
Show();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// FrameResized() will do the required adjustments
|
|
||||||
|
|
||||||
printf("ToggleFullscreen leave\n");
|
printf("ToggleFullscreen leave\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -787,10 +693,8 @@ MainWin::ToggleNoControls()
|
|||||||
SetWindowSizeLimits();
|
SetWindowSizeLimits();
|
||||||
|
|
||||||
if (fNoControls) {
|
if (fNoControls) {
|
||||||
fControls->Hide();
|
|
||||||
ResizeBy(0, - fControlsHeight);
|
ResizeBy(0, - fControlsHeight);
|
||||||
} else {
|
} else {
|
||||||
fControls->Show();
|
|
||||||
ResizeBy(0, fControlsHeight);
|
ResizeBy(0, fControlsHeight);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -812,15 +716,9 @@ MainWin::ToggleNoMenu()
|
|||||||
SetWindowSizeLimits();
|
SetWindowSizeLimits();
|
||||||
|
|
||||||
if (fNoMenu) {
|
if (fNoMenu) {
|
||||||
fMenuBar->Hide();
|
|
||||||
fVideoView->MoveTo(0, 0);
|
|
||||||
fVideoView->ResizeBy(0, fMenuBarHeight);
|
|
||||||
MoveBy(0, fMenuBarHeight);
|
MoveBy(0, fMenuBarHeight);
|
||||||
ResizeBy(0, - fMenuBarHeight);
|
ResizeBy(0, - fMenuBarHeight);
|
||||||
} else {
|
} else {
|
||||||
fMenuBar->Show();
|
|
||||||
fVideoView->MoveTo(0, fMenuBarHeight);
|
|
||||||
fVideoView->ResizeBy(0, - fMenuBarHeight);
|
|
||||||
MoveBy(0, - fMenuBarHeight);
|
MoveBy(0, - fMenuBarHeight);
|
||||||
ResizeBy(0, fMenuBarHeight);
|
ResizeBy(0, fMenuBarHeight);
|
||||||
}
|
}
|
||||||
|
@ -52,6 +52,7 @@ public:
|
|||||||
void SetupWindow();
|
void SetupWindow();
|
||||||
void SetupTrackMenus();
|
void SetupTrackMenus();
|
||||||
void SetWindowSizeLimits();
|
void SetWindowSizeLimits();
|
||||||
|
void ResizeVideoView(int x, int y, int width, int height);
|
||||||
|
|
||||||
void ShowFileInfo();
|
void ShowFileInfo();
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user