Implemented Fast Forward and Rewind

git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@13649 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
DarkWyrm 2005-07-12 19:47:21 +00:00
parent b8673e4300
commit bc5804fdb6
6 changed files with 75 additions and 33 deletions

View File

@ -23,6 +23,7 @@
#include "CDPlayer.h"
#include "DrawButton.h"
#include "DoubleShotDrawButton.h"
#include "TwoStateDrawButton.h"
#include <TranslationUtils.h>
#include <TranslatorFormats.h>
@ -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;

View File

@ -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,

View File

@ -0,0 +1,20 @@
#include "DoubleShotDrawButton.h"
#include <stdio.h>
// 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);
}

View File

@ -0,0 +1,22 @@
#ifndef _DOUBLESHOT_DRAW_BUTTON_H
#define _DOUBLESHOT_DRAW_BUTTON_H
#include <Looper.h>
#include <Application.h>
#include <Window.h>
#include <Button.h>
#include <Bitmap.h>
#include <Rect.h>
#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

View File

@ -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:

View File

@ -6,6 +6,7 @@ App CDPlayer :
CDDBSupport.cpp
CDEngine.cpp
CDPlayer.cpp
DoubleShotDrawButton.cpp
DrawButton.cpp
FunctionObjectMessage.cpp
Observer.cpp