diff --git a/src/apps/mediaplayer/Controller.cpp b/src/apps/mediaplayer/Controller.cpp index 77982b50a2..e4504337e2 100644 --- a/src/apps/mediaplayer/Controller.cpp +++ b/src/apps/mediaplayer/Controller.cpp @@ -327,6 +327,31 @@ Controller::SetTo(const entry_ref &ref) } +void +Controller::PlayerActivated(bool active) +{ + BAutolock _(this); + + if (active) { + if (fActiveVolume != fVolume) + SetVolume(fActiveVolume); + } else { + fActiveVolume = fVolume; + switch (fBackgroundMovieVolumeMode) { + case mpSettings::BG_MOVIES_MUTED: + SetVolume(0.0); + break; + case mpSettings::BG_MOVIES_HALF_VLUME: + SetVolume(fVolume * 0.25); + break; + case mpSettings::BG_MOVIES_FULL_VOLUME: + default: + break; + } + } +} + + void Controller::GetSize(int *width, int *height) { diff --git a/src/apps/mediaplayer/Controller.h b/src/apps/mediaplayer/Controller.h index a437743c7e..66c7f711c0 100644 --- a/src/apps/mediaplayer/Controller.h +++ b/src/apps/mediaplayer/Controller.h @@ -79,6 +79,8 @@ public: // Controller status_t SetTo(const entry_ref &ref); + void PlayerActivated(bool active); + void GetSize(int *width, int *height); int AudioTrackCount(); @@ -99,7 +101,7 @@ public: bigtime_t TimeDuration(); bigtime_t TimePosition(); - virtual void SetVolume(float percent); + virtual void SetVolume(float factor); float Volume(); void VolumeUp(); void VolumeDown(); diff --git a/src/apps/mediaplayer/MainApp.cpp b/src/apps/mediaplayer/MainApp.cpp index ab746e4641..528b8125c2 100644 --- a/src/apps/mediaplayer/MainApp.cpp +++ b/src/apps/mediaplayer/MainApp.cpp @@ -32,6 +32,7 @@ #include #include "EventQueue.h" +#include "SettingsWindow.h" MainApp *gMainApp; @@ -45,6 +46,7 @@ MainApp::MainApp() : BApplication(kAppSig), fPlayerCount(0), fFirstWindow(NewWindow()), + fSettingsWindow(NULL), fMediaServerRunning(false), fMediaAddOnServerRunning(false) @@ -57,7 +59,21 @@ MainApp::~MainApp() } -BWindow * +bool +MainApp::QuitRequested() +{ + // TODO: When doing this in the destructor, the MainApp does not + // quit properly. Is this a Haiku bug? (SettingsWindow::QuitRequested() + // returns "false" always.) + if (fSettingsWindow && fSettingsWindow->Lock()) + fSettingsWindow->Quit(); + fSettingsWindow = NULL; + + return BApplication::QuitRequested(); +} + + +BWindow* MainApp::NewWindow() { BAutolock _(this); @@ -66,9 +82,25 @@ MainApp::NewWindow() } +int32 +MainApp::PlayerCount() const +{ + BAutolock _(const_cast(this)); + return fPlayerCount; +} + + +// #pragma mark - + + void MainApp::ReadyToRun() { + // setup the settings window now, we need to have it + fSettingsWindow = new SettingsWindow(BRect(150, 150, 450, 520)); + fSettingsWindow->Hide(); + fSettingsWindow->Show(); + // Now tell the application roster, that we're interested // in getting notifications of apps being launched or quit. // In this way we are going to detect a media_server restart. @@ -193,6 +225,9 @@ MainApp::MessageReceived(BMessage* message) } break; } + case M_SETTINGS: + _ShowSettingsWindow(); + break; default: BApplication::MessageReceived(message); @@ -218,6 +253,19 @@ MainApp::_BroadcastMessage(const BMessage& _message) } +void +MainApp::_ShowSettingsWindow() +{ + if (fSettingsWindow->Lock()) { + if (fSettingsWindow->IsHidden()) + fSettingsWindow->Show(); + else + fSettingsWindow->Activate(); + fSettingsWindow->Unlock(); + } +} + + // #pragma mark - diff --git a/src/apps/mediaplayer/MainApp.h b/src/apps/mediaplayer/MainApp.h index 30d49d61d7..47ab59fe4a 100644 --- a/src/apps/mediaplayer/MainApp.h +++ b/src/apps/mediaplayer/MainApp.h @@ -26,30 +26,37 @@ enum { M_PLAYER_QUIT = 'plqt', + M_SETTINGS = 'stng', M_MEDIA_SERVER_STARTED = 'msst', M_MEDIA_SERVER_QUIT = 'msqt' }; +class SettingsWindow; + class MainApp : public BApplication { public: MainApp(); virtual ~MainApp(); BWindow* NewWindow(); + int32 PlayerCount() const; private: + virtual bool QuitRequested(); virtual void ReadyToRun(); virtual void RefsReceived(BMessage* message); virtual void ArgvReceived(int32 argc, char** argv); virtual void MessageReceived(BMessage* message); virtual void AboutRequested(); +private: + void _ShowSettingsWindow(); void _BroadcastMessage(const BMessage& message); -private: int32 fPlayerCount; BWindow* fFirstWindow; + SettingsWindow* fSettingsWindow; bool fMediaServerRunning; bool fMediaAddOnServerRunning; diff --git a/src/apps/mediaplayer/MainWin.cpp b/src/apps/mediaplayer/MainWin.cpp index 99d63e84ad..b7fc65096d 100644 --- a/src/apps/mediaplayer/MainWin.cpp +++ b/src/apps/mediaplayer/MainWin.cpp @@ -48,7 +48,6 @@ #include "PlaylistObserver.h" #include "PlaylistWindow.h" #include "Settings.h" -#include "SettingsWindow.h" #define NAME "MediaPlayer" #define MIN_WIDTH 250 @@ -77,7 +76,6 @@ enum { M_TOGGLE_NO_BORDER_NO_MENU_NO_CONTROLS, M_TOGGLE_ALWAYS_ON_TOP, M_TOGGLE_KEEP_ASPECT_RATIO, - M_SETTINGS, M_VOLUME_UP, M_VOLUME_DOWN, M_SKIP_NEXT, @@ -106,7 +104,6 @@ MainWin::MainWin() fFilePanel(NULL), fInfoWin(NULL), fPlaylistWindow(NULL), - fSettingsWindow(NULL), fHasFile(false), fHasVideo(false), fHasAudio(false), @@ -184,11 +181,6 @@ MainWin::MainWin() _SetupWindow(); - // setup the settings window now, we need to have it - fSettingsWindow = new SettingsWindow(BRect(150, 150, 450, 520)); - fSettingsWindow->Hide(); - fSettingsWindow->Show(); - // setup the playlist window now, we need to have it // running for the undo/redo playlist editing fPlaylistWindow = new PlaylistWindow(BRect(150, 150, 500, 600), fPlaylist, @@ -209,6 +201,7 @@ MainWin::~MainWin() { printf("MainWin::~MainWin\n"); + Settings::Default()->RemoveListener(&fGlobalSettingsListener); fPlaylist->RemoveListener(fPlaylistObserver); fController->RemoveListener(fControllerObserver); fController->SetPeakListener(NULL); @@ -218,20 +211,12 @@ MainWin::~MainWin() fBackground->RemoveSelf(); delete fBackground; - if (fInfoWin) { - fInfoWin->Lock(); + if (fInfoWin && fInfoWin->Lock()) fInfoWin->Quit(); - } - if (fPlaylistWindow) { - fPlaylistWindow->Lock(); - fPlaylistWindow->Quit(); - } - - if (fSettingsWindow) { - fSettingsWindow->Lock(); - fSettingsWindow->Quit(); - } + if (fPlaylistWindow && fPlaylistWindow->Lock()) + fPlaylistWindow->Quit(); + delete fPlaylist; delete fFilePanel; @@ -247,56 +232,56 @@ MainWin::~MainWin() void -MainWin::FrameResized(float new_width, float new_height) +MainWin::FrameResized(float newWidth, float newHeight) { - if (new_width != Bounds().Width() || new_height != Bounds().Height()) { + if (newWidth != Bounds().Width() || newHeight != Bounds().Height()) { 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); - - int max_video_width = int(new_width) + 1; - int max_video_height = int(new_height) + 1 - - (no_menu ? 0 : fMenuBarHeight) - - (no_controls ? 0 : fControlsHeight); - ASSERT(max_video_height >= 0); - + bool noMenu = fNoMenu || fIsFullscreen; + bool noControls = fNoControls || fIsFullscreen; + + printf("FrameResized enter: newWidth %.0f, newHeight %.0f\n", + newWidth, newHeight); + + int maxVideoWidth = int(newWidth) + 1; + int maxVideoHeight = int(newHeight) + 1 + - (noMenu ? 0 : fMenuBarHeight) + - (noControls ? 0 : fControlsHeight); + + ASSERT(maxVideoHeight >= 0); + int y = 0; - - if (no_menu) { + + if (noMenu) { if (!fMenuBar->IsHidden()) fMenuBar->Hide(); } else { // fMenuBar->MoveTo(0, y); - fMenuBar->ResizeTo(new_width, fMenuBarHeight - 1); + fMenuBar->ResizeTo(newWidth, fMenuBarHeight - 1); if (fMenuBar->IsHidden()) fMenuBar->Show(); y += fMenuBarHeight; } - - if (max_video_height == 0) { - if (!fVideoView->IsHidden()) + + if (maxVideoHeight == 0) { + bool hidden = fVideoView->IsHidden(); +printf(" video view hidden: %d\n", hidden); + if (!hidden) fVideoView->Hide(); } else { -// fVideoView->MoveTo(0, y); -// fVideoView->ResizeTo(max_video_width - 1, max_video_height - 1); - _ResizeVideoView(0, y, max_video_width, max_video_height); + _ResizeVideoView(0, y, maxVideoWidth, maxVideoHeight); if (fVideoView->IsHidden()) fVideoView->Show(); - y += max_video_height; + y += maxVideoHeight; } - if (no_controls) { + if (noControls) { if (!fControls->IsHidden()) fControls->Hide(); } else { fControls->MoveTo(0, y); - fControls->ResizeTo(new_width, fControlsHeight - 1); + fControls->ResizeTo(newWidth, fControlsHeight - 1); if (fControls->IsHidden()) fControls->Show(); // y += fControlsHeight; @@ -654,9 +639,6 @@ MainWin::MessageReceived(BMessage *msg) VideoFormatChange(544, 576, 1.41176, 1.0); break; - case M_SETTINGS: - ShowSettingsWindow(); - break; /* default: if (msg->what >= M_SELECT_CHANNEL @@ -701,23 +683,25 @@ MainWin::WindowActivated(bool active) float diffX = 0.0; float diffY = 0.0; - // If the frame if off the edge of the screen at all + // If the frame is off the edge of the screen at all // we will move it so all the window is on the screen. - if (frame.left < screenFrame.left) - // Move right - diffX = screenFrame.left - frame.left; - if (frame.top < screenFrame.top) - // Move down - diffY = screenFrame.top - frame.top; if (frame.right > screenFrame.right) // Move left diffX = screenFrame.right - frame.right; if (frame.bottom > screenFrame.bottom) // Move up diffY = screenFrame.bottom - frame.bottom; + if (frame.left < screenFrame.left) + // Move right + diffX = screenFrame.left - frame.left; + if (frame.top < screenFrame.top) + // Move down + diffY = screenFrame.top - frame.top; MoveBy(diffX, diffY); } + + fController->PlayerActivated(active || gMainApp->PlayerCount() <= 1); } @@ -803,19 +787,6 @@ MainWin::ShowPlaylistWindow() } -void -MainWin::ShowSettingsWindow() -{ - if (fSettingsWindow->Lock()) { - if (fSettingsWindow->IsHidden()) - fSettingsWindow->Show(); - else - fSettingsWindow->Activate(); - fSettingsWindow->Unlock(); - } -} - - void MainWin::VideoFormatChange(int width, int height, float width_scale, float height_scale) @@ -976,8 +947,10 @@ MainWin::_CreateMenu() fSettingsMenu->AddItem(new BMenuItem("Always on Top", new BMessage(M_TOGGLE_ALWAYS_ON_TOP), 'T')); fSettingsMenu->AddSeparatorItem(); - fSettingsMenu->AddItem(new BMenuItem("Settings"B_UTF8_ELLIPSIS, - new BMessage(M_SETTINGS), 'S')); + item = new BMenuItem("Settings"B_UTF8_ELLIPSIS, + new BMessage(M_SETTINGS), 'S'); + fSettingsMenu->AddItem(item); + item->SetTarget(be_app); // fDebugMenu->AddItem(new BMenuItem("pixel aspect ratio 1.00000:1", // new BMessage(M_ASPECT_100000_1))); @@ -1056,15 +1029,15 @@ void MainWin::_ResizeWindow(int percent) { // Get required window size - int video_width = lround(fSourceWidth * fWidthScale); - int video_height = lround(fSourceHeight * fHeightScale); + int videoWidth = lround(fSourceWidth * fWidthScale); + int videoHeight = lround(fSourceHeight * fHeightScale); - video_width = (video_width * percent) / 100; - video_height = (video_height * percent) / 100; + videoWidth = (videoWidth * percent) / 100; + videoHeight = (videoHeight * percent) / 100; // Calculate and set the initial window size - int width = max_c(fControlsWidth, video_width); - int height = (fNoControls ? 0 : fControlsHeight) + video_height; + int width = max_c(fControlsWidth, videoWidth); + int height = (fNoControls ? 0 : fControlsHeight) + videoHeight; if (!fNoMenu) { width = max_c(width, fMenuBarWidth); height += fMenuBarHeight; @@ -1083,21 +1056,21 @@ MainWin::_ResizeVideoView(int x, int y, int width, int height) if (fKeepAspectRatio) { // Keep aspect ratio, place video view inside // the background area (may create black bars). - float scaled_width = fSourceWidth * fWidthScale; - float scaled_height = fSourceHeight * fHeightScale; - float factor = min_c(width / scaled_width, height / scaled_height); - int render_width = lround(scaled_width * factor); - int render_height = lround(scaled_height * factor); - if (render_width > width) - render_width = width; - if (render_height > height) - render_height = height; + float scaledWidth = fSourceWidth * fWidthScale; + float scaledHeight = fSourceHeight * fHeightScale; + float factor = min_c(width / scaledWidth, height / scaledHeight); + int renderWidth = lround(scaledWidth * factor); + int renderHeight = lround(scaledHeight * factor); + if (renderWidth > width) + renderWidth = width; + if (renderHeight > height) + renderHeight = height; - int x_ofs = x + (width - render_width) / 2; - int y_ofs = y + (height - render_height) / 2; + int xOffset = x + (width - renderWidth) / 2; + int yOffset = y + (height - renderHeight) / 2; - fVideoView->MoveTo(x_ofs, y_ofs); - fVideoView->ResizeTo(render_width - 1, render_height - 1); + fVideoView->MoveTo(xOffset, yOffset); + fVideoView->ResizeTo(renderWidth - 1, renderHeight - 1); } else { fVideoView->MoveTo(x, y); diff --git a/src/apps/mediaplayer/MainWin.h b/src/apps/mediaplayer/MainWin.h index 07ab540dad..aa14dd7d30 100644 --- a/src/apps/mediaplayer/MainWin.h +++ b/src/apps/mediaplayer/MainWin.h @@ -37,7 +37,6 @@ class ControllerObserver; class PlaylistObserver; class PlaylistWindow; -class SettingsWindow; class MainWin : public BWindow { public: @@ -106,7 +105,6 @@ private: ControllerView* fControls; InfoWin* fInfoWin; PlaylistWindow* fPlaylistWindow; - SettingsWindow* fSettingsWindow; BMenu* fFileMenu; BMenu* fAudioMenu; diff --git a/src/apps/mediaplayer/playlist/PlaylistListView.cpp b/src/apps/mediaplayer/playlist/PlaylistListView.cpp index e23b1f6273..a0a572aa24 100644 --- a/src/apps/mediaplayer/playlist/PlaylistListView.cpp +++ b/src/apps/mediaplayer/playlist/PlaylistListView.cpp @@ -1,5 +1,5 @@ /* - * Copyright 2007, Haiku. All rights reserved. + * Copyright 2007-2008, Haiku. All rights reserved. * Distributed under the terms of the MIT License. * * Authors: @@ -140,7 +140,7 @@ PlaylistItem::Draw(BView* owner, BRect frame, const font_height& fh, #else rgb_color lightGreen = tint_color(green, B_LIGHTEN_2_TINT); rgb_color darkGreen = tint_color(green, B_DARKEN_2_TINT); - owner->BeginLineArray( 6 ); + owner->BeginLineArray(6); // black outline owner->AddLine(arrow[0], arrow[1], black); owner->AddLine(BPoint(arrow[1].x + 1.0, arrow[1].y - 1.0), diff --git a/src/apps/mediaplayer/settings/SettingsWindow.cpp b/src/apps/mediaplayer/settings/SettingsWindow.cpp index 58a48a6b13..1ede9e7031 100644 --- a/src/apps/mediaplayer/settings/SettingsWindow.cpp +++ b/src/apps/mediaplayer/settings/SettingsWindow.cpp @@ -47,8 +47,8 @@ enum { #define BUTTONHEIGHT 20 SettingsWindow::SettingsWindow(BRect frame) - : BWindow(frame, "MediaPlayer Settings", B_TITLED_WINDOW_LOOK, - B_NORMAL_WINDOW_FEEL, + : BWindow(frame, "MediaPlayer Settings", B_FLOATING_WINDOW_LOOK, + B_FLOATING_APP_WINDOW_FEEL, B_ASYNCHRONOUS_CONTROLS | B_NOT_ZOOMABLE | B_NOT_RESIZABLE #ifdef __HAIKU__ | B_AUTO_UPDATE_SIZE_LIMITS) @@ -70,7 +70,7 @@ SettingsWindow::SettingsWindow(BRect frame) BStringView* viewOptionsLabel = new BStringView("stringViewViewOpions", "View options"); BStringView* bgMoviesModeLabel = new BStringView("stringViewPlayBackg", - "Play background movies at"); + "Play background clips at"); BAlignment alignment(B_ALIGN_LEFT, B_ALIGN_VERTICAL_CENTER); playModeLabel->SetExplicitAlignment(alignment); playModeLabel->SetFont(be_bold_font); @@ -105,7 +105,7 @@ SettingsWindow::SettingsWindow(BRect frame) "Full volume", new BMessage(M_START_FULL_VOLUME)); fHalfVolumeBGMoviesRB = new BRadioButton("rdbtnhalfvolume", - "Half volume", new BMessage(M_START_HALF_VOLUME)); + "Low volume", new BMessage(M_START_HALF_VOLUME)); fMutedVolumeBGMoviesRB = new BRadioButton("rdbtnfullvolume", "Muted", new BMessage(M_START_MUTE_VOLUME)); @@ -228,7 +228,7 @@ SettingsWindow::SettingsWindow(BRect frame) rect.OffsetBy(0, rect.Height() + SPACE + SPACEING); bbox->AddChild(new BStringView(rect, "stringViewPlayBackg", - "Play backgrounds movies at:")); + "Play backgrounds clips at:")); rect.OffsetBy(SPACE, rect.Height() + SPACEING); fFullVolumeBGMoviesRB = new BRadioButton(rect, "rdbtnfullvolume", @@ -237,7 +237,7 @@ SettingsWindow::SettingsWindow(BRect frame) rect.OffsetBy(0, rect.Height() + SPACEING); fHalfVolumeBGMoviesRB = new BRadioButton(rect, "rdbtnhalfvolume", - "Half Volume", new BMessage(M_START_HALF_VOLUME)); + "Low Volume", new BMessage(M_START_HALF_VOLUME)); bbox->AddChild(fHalfVolumeBGMoviesRB); rect.OffsetBy(0, rect.Height() + SPACEING); @@ -252,10 +252,6 @@ SettingsWindow::SettingsWindow(BRect frame) // disable currently unsupported features fLoopMoviesCB->SetEnabled(false); fLoopSoundsCB->SetEnabled(false); - - fFullVolumeBGMoviesRB->SetEnabled(false); - fHalfVolumeBGMoviesRB->SetEnabled(false); - fMutedVolumeBGMoviesRB->SetEnabled(false); }