From bc5804fdb6ae0bed47d525cae60be51b2218f0e2 Mon Sep 17 00:00:00 2001 From: DarkWyrm Date: Tue, 12 Jul 2005 19:47:21 +0000 Subject: [PATCH] Implemented Fast Forward and Rewind git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@13649 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- src/apps/cdplayer/CDPlayer.cpp | 42 +++++++++++----------- src/apps/cdplayer/CDPlayer.h | 11 +++--- src/apps/cdplayer/DoubleShotDrawButton.cpp | 20 +++++++++++ src/apps/cdplayer/DoubleShotDrawButton.h | 22 ++++++++++++ src/apps/cdplayer/DrawButton.h | 12 +++---- src/apps/cdplayer/Jamfile | 1 + 6 files changed, 75 insertions(+), 33 deletions(-) create mode 100644 src/apps/cdplayer/DoubleShotDrawButton.cpp create mode 100644 src/apps/cdplayer/DoubleShotDrawButton.h diff --git a/src/apps/cdplayer/CDPlayer.cpp b/src/apps/cdplayer/CDPlayer.cpp index a5fc0c1fe1..ce029e53c6 100644 --- a/src/apps/cdplayer/CDPlayer.cpp +++ b/src/apps/cdplayer/CDPlayer.cpp @@ -23,6 +23,7 @@ #include "CDPlayer.h" #include "DrawButton.h" +#include "DoubleShotDrawButton.h" #include "TwoStateDrawButton.h" #include #include @@ -177,24 +178,23 @@ void CDPlayer::BuildGUI(void) fNextTrack->SetDisabled(BTranslationUtils::GetBitmap(B_PNG_FORMAT,"next_disabled")); AddChild(fNextTrack); - // TODO: Fast Forward and Rewind are special buttons. Implement as two-state buttons - fRewind = new DrawButton( BRect(0,0,1,1), "Rewind", BTranslationUtils::GetBitmap(B_PNG_FORMAT,"rew_up"), - BTranslationUtils::GetBitmap(B_PNG_FORMAT,"rew_down"), new BMessage(M_PREV_TRACK), - B_FOLLOW_BOTTOM, B_WILL_DRAW); + fRewind = new DoubleShotDrawButton( BRect(0,0,1,1), "Rewind", + BTranslationUtils::GetBitmap(B_PNG_FORMAT,"rew_up"), + BTranslationUtils::GetBitmap(B_PNG_FORMAT,"rew_down"), + new BMessage(M_REWIND), B_FOLLOW_BOTTOM, B_WILL_DRAW); fRewind->ResizeToPreferred(); fRewind->MoveTo(fNextTrack->Frame().right + 10, Bounds().bottom - 5 - fRewind->Frame().Height()); fRewind->SetDisabled(BTranslationUtils::GetBitmap(B_PNG_FORMAT,"rew_disabled")); AddChild(fRewind); - fRewind->SetEnabled(false); - fFastFwd = new DrawButton( BRect(0,0,1,1), "FastFwd", BTranslationUtils::GetBitmap(B_PNG_FORMAT,"ffwd_up"), - BTranslationUtils::GetBitmap(B_PNG_FORMAT,"ffwd_down"), new BMessage(M_NEXT_TRACK), - B_FOLLOW_BOTTOM, B_WILL_DRAW); + fFastFwd = new DoubleShotDrawButton( BRect(0,0,1,1), "FastFwd", + BTranslationUtils::GetBitmap(B_PNG_FORMAT,"ffwd_up"), + BTranslationUtils::GetBitmap(B_PNG_FORMAT,"ffwd_down"), + new BMessage(M_FFWD), B_FOLLOW_BOTTOM, B_WILL_DRAW); fFastFwd->ResizeToPreferred(); fFastFwd->MoveTo(fRewind->Frame().right + 2, Bounds().bottom - 5 - fFastFwd->Frame().Height()); fFastFwd->SetDisabled(BTranslationUtils::GetBitmap(B_PNG_FORMAT,"ffwd_disabled")); AddChild(fFastFwd); - fFastFwd->SetEnabled(false); fEject = new DrawButton( BRect(0,0,1,1), "Eject", BTranslationUtils::GetBitmap(B_PNG_FORMAT,"eject_up"), BTranslationUtils::GetBitmap(B_PNG_FORMAT,"eject_down"), new BMessage(M_EJECT), @@ -295,11 +295,19 @@ CDPlayer::MessageReceived(BMessage *msg) case M_FFWD: { // TODO: Implement + if(fFastFwd->Value() == B_CONTROL_ON) + engine->StartSkippingForward(); + else + engine->StopSkipping(); break; } case M_REWIND: { // TODO: Implement + if(fRewind->Value() == B_CONTROL_ON) + engine->StartSkippingBackward(); + else + engine->StopSkipping(); break; } case M_SAVE: @@ -437,8 +445,7 @@ CDPlayer::AdjustButtonStates(void) fPlay->SetEnabled(false); fNextTrack->SetEnabled(false); fPrevTrack->SetEnabled(false); - fFastFwd->SetEnabled(false); - fRewind->SetEnabled(false); + fSave->SetEnabled(false); break; } @@ -449,9 +456,6 @@ CDPlayer::AdjustButtonStates(void) fNextTrack->SetEnabled(true); fPrevTrack->SetEnabled(true); - fFastFwd->SetEnabled(false); - fRewind->SetEnabled(false); - // TODO: Enable when Save is implemented // fSave->SetEnabled(true); @@ -460,9 +464,6 @@ CDPlayer::AdjustButtonStates(void) } case kPaused: { - // We can only pause when everything is enabled, so this is all we should do. - fFastFwd->SetEnabled(false); - fRewind->SetEnabled(false); fPlay->SetState(0); break; } @@ -473,9 +474,6 @@ CDPlayer::AdjustButtonStates(void) fNextTrack->SetEnabled(true); fPrevTrack->SetEnabled(true); - fFastFwd->SetEnabled(true); - fRewind->SetEnabled(true); - // TODO: Enable when Save is implemented // fSave->SetEnabled(true); @@ -629,8 +627,8 @@ public: }; CDPlayerWindow::CDPlayerWindow(void) - : BWindow(BRect (100, 100, 610, 200), "CD Player", B_TITLED_WINDOW, B_NOT_V_RESIZABLE | - B_NOT_ZOOMABLE | B_ASYNCHRONOUS_CONTROLS) + : BWindow(BRect (100, 100, 610, 200), "CD Player", B_TITLED_WINDOW, B_NOT_V_RESIZABLE | + B_NOT_ZOOMABLE | B_ASYNCHRONOUS_CONTROLS) { float wmin,wmax,hmin,hmax; diff --git a/src/apps/cdplayer/CDPlayer.h b/src/apps/cdplayer/CDPlayer.h index 3d913dc505..0ec2031bdb 100644 --- a/src/apps/cdplayer/CDPlayer.h +++ b/src/apps/cdplayer/CDPlayer.h @@ -21,6 +21,7 @@ #include "TrackMenu.h" class DrawButton; +class DoubleShotDrawButton; class TwoStateDrawButton; class CDPlayer : public BView, private Observer @@ -40,8 +41,7 @@ public: virtual void MessageReceived(BMessage *); // observing overrides - virtual BHandler *RecipientHandler() const - { return (BHandler *)this; } + virtual BHandler *RecipientHandler() const { return (BHandler *)this; } virtual void NoticeChange(Notifier *); @@ -54,13 +54,14 @@ private: CDEngine *engine; DrawButton *fStop, -// *fPlay, *fNextTrack, *fPrevTrack, - *fFastFwd, - *fRewind, *fEject, *fSave; + + DoubleShotDrawButton + *fFastFwd, + *fRewind; TwoStateDrawButton *fShuffle, *fRepeat, diff --git a/src/apps/cdplayer/DoubleShotDrawButton.cpp b/src/apps/cdplayer/DoubleShotDrawButton.cpp new file mode 100644 index 0000000000..9f7d5b2938 --- /dev/null +++ b/src/apps/cdplayer/DoubleShotDrawButton.cpp @@ -0,0 +1,20 @@ +#include "DoubleShotDrawButton.h" +#include + +// The only difference between this class and DrawButton is the fact that it is invoked +// twice during a mousedown-mouseup cycle. It fires when pushed, and then again when +// released. + +DoubleShotDrawButton::DoubleShotDrawButton(BRect frame, const char *name, BBitmap *up, + BBitmap *down,BMessage *msg, int32 resize, + int32 flags) + : DrawButton(frame, name, up,down, msg, resize, flags) +{ +} + +void +DoubleShotDrawButton::MouseDown(BPoint point) +{ + Invoke(); + DrawButton::MouseDown(point); +} diff --git a/src/apps/cdplayer/DoubleShotDrawButton.h b/src/apps/cdplayer/DoubleShotDrawButton.h new file mode 100644 index 0000000000..0b2a6c627e --- /dev/null +++ b/src/apps/cdplayer/DoubleShotDrawButton.h @@ -0,0 +1,22 @@ +#ifndef _DOUBLESHOT_DRAW_BUTTON_H +#define _DOUBLESHOT_DRAW_BUTTON_H + +#include +#include +#include +#include +#include +#include +#include "DrawButton.h" + +class DoubleShotDrawButton : public DrawButton +{ +public: + DoubleShotDrawButton(BRect frame, const char *name, BBitmap *up, + BBitmap *down,BMessage *msg, int32 resize, + int32 flags); + + void MouseDown(BPoint point); +}; + +#endif diff --git a/src/apps/cdplayer/DrawButton.h b/src/apps/cdplayer/DrawButton.h index 764498f66e..e3c2dcf87a 100644 --- a/src/apps/cdplayer/DrawButton.h +++ b/src/apps/cdplayer/DrawButton.h @@ -12,16 +12,16 @@ class DrawButton : public BButton { public: - DrawButton(BRect frame, const char *name, BBitmap *up, + DrawButton(BRect frame, const char *name, BBitmap *up, BBitmap *down,BMessage *msg, int32 resize, int32 flags); - ~DrawButton(void); + virtual ~DrawButton(void); - void Draw(BRect update); + void Draw(BRect update); - void SetBitmaps(BBitmap *up, BBitmap *down); - void ResizeToPreferred(void); - void SetDisabled(BBitmap *disabled); + void SetBitmaps(BBitmap *up, BBitmap *down); + void ResizeToPreferred(void); + void SetDisabled(BBitmap *disabled); private: diff --git a/src/apps/cdplayer/Jamfile b/src/apps/cdplayer/Jamfile index 14361ec87e..7e80ff54e1 100644 --- a/src/apps/cdplayer/Jamfile +++ b/src/apps/cdplayer/Jamfile @@ -6,6 +6,7 @@ App CDPlayer : CDDBSupport.cpp CDEngine.cpp CDPlayer.cpp + DoubleShotDrawButton.cpp DrawButton.cpp FunctionObjectMessage.cpp Observer.cpp