From f479b4974aaa765b518a6b022ecdae318ed6550c Mon Sep 17 00:00:00 2001 From: DarkWyrm Date: Tue, 28 Jun 2005 18:56:16 +0000 Subject: [PATCH] Added a 2-state BBitmap button for later usage in Shuffle and Loop buttons Added a playlist class which will be later used for handling tracks CD music will stop on quit to avoid confusing users Added pause up/down images to resource file Style tweaks to some files git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@13324 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- src/apps/cdplayer/CDButton.cpp | 112 +++++++++--------- src/apps/cdplayer/CDButton.h | 43 ++++--- src/apps/cdplayer/CDEngine.h | 4 +- src/apps/cdplayer/CDPlayer.rdef | 27 +++++ src/apps/cdplayer/DrawButton.cpp | 21 +++- src/apps/cdplayer/DrawButton.h | 22 ++-- src/apps/cdplayer/Jamfile | 2 + src/apps/cdplayer/PlayList.cpp | 104 +++++++++++++++++ src/apps/cdplayer/PlayList.h | 38 +++++++ src/apps/cdplayer/TwoStateDrawButton.cpp | 138 +++++++++++++++++++++++ src/apps/cdplayer/TwoStateDrawButton.h | 41 +++++++ 11 files changed, 460 insertions(+), 92 deletions(-) create mode 100644 src/apps/cdplayer/PlayList.cpp create mode 100644 src/apps/cdplayer/PlayList.h create mode 100644 src/apps/cdplayer/TwoStateDrawButton.cpp create mode 100644 src/apps/cdplayer/TwoStateDrawButton.h diff --git a/src/apps/cdplayer/CDButton.cpp b/src/apps/cdplayer/CDButton.cpp index e1be29e955..008e7cda53 100644 --- a/src/apps/cdplayer/CDButton.cpp +++ b/src/apps/cdplayer/CDButton.cpp @@ -23,6 +23,7 @@ #include "CDButton.h" #include "DrawButton.h" +#include "TwoStateDrawButton.h" #include #include #include @@ -47,10 +48,6 @@ enum CDButton::CDButton(BRect frame, const char *name, uint32 resizeMask, uint32 flags) : BView(frame, name, resizeMask, flags | B_FRAME_EVENTS) { - // This will eventually one of a few preferences - to stop playing music - // when the app is closed - fStopOnQuit = false; - SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR)); // TODO: Support multiple CD drives @@ -74,8 +71,7 @@ CDButton::CDButton(BRect frame, const char *name, uint32 resizeMask, uint32 flag CDButton::~CDButton() { - if(fStopOnQuit) - engine->Stop(); + engine->Stop(); delete engine; } @@ -138,89 +134,89 @@ void CDButton::BuildGUI(void) fVolume->MoveTo(5, Bounds().bottom - 10 - fVolume->Frame().Height()); AddChild(fVolume); - fStop = new DrawButton( BRect(0,0,1,1), "Stop", BTranslationUtils::GetBitmap('PNG ',"stop_up"), - BTranslationUtils::GetBitmap('PNG ',"stop_down"), new BMessage(M_STOP), + fStop = new DrawButton( BRect(0,0,1,1), "Stop", BTranslationUtils::GetBitmap(B_PNG_FORMAT,"stop_up"), + BTranslationUtils::GetBitmap(B_PNG_FORMAT,"stop_down"), new BMessage(M_STOP), B_FOLLOW_BOTTOM, B_WILL_DRAW); fStop->ResizeToPreferred(); fStop->MoveTo(fVolume->Frame().right + 10, Bounds().bottom - 5 - fStop->Frame().Height()); - fStop->SetDisabled(BTranslationUtils::GetBitmap('PNG ',"stop_disabled")); + fStop->SetDisabled(BTranslationUtils::GetBitmap(B_PNG_FORMAT,"stop_disabled")); AddChild(fStop); // TODO: Play is a special button. Implement as two-state buttons - fPlay = new DrawButton( BRect(0,0,1,1), "Play", BTranslationUtils::GetBitmap('PNG ',"play_up"), - BTranslationUtils::GetBitmap('PNG ',"play_down"), new BMessage(M_PLAY), - B_FOLLOW_BOTTOM, B_WILL_DRAW); + fPlay = new DrawButton( BRect(0,0,1,1), "Play", BTranslationUtils::GetBitmap(B_PNG_FORMAT,"play_up"), + BTranslationUtils::GetBitmap(B_PNG_FORMAT,"play_down"), + new BMessage(M_PLAY), B_FOLLOW_BOTTOM, B_WILL_DRAW); fPlay->ResizeToPreferred(); fPlay->MoveTo(fStop->Frame().right + 2, Bounds().bottom - 5 - fPlay->Frame().Height()); - fPlay->SetDisabled(BTranslationUtils::GetBitmap('PNG ',"play_disabled")); + fPlay->SetDisabled(BTranslationUtils::GetBitmap(B_PNG_FORMAT,"play_disabled")); AddChild(fPlay); - fPrevTrack = new DrawButton( BRect(0,0,1,1), "PrevTrack", BTranslationUtils::GetBitmap('PNG ',"prev_up"), - BTranslationUtils::GetBitmap('PNG ',"prev_down"), new BMessage(M_PREV_TRACK), + fPrevTrack = new DrawButton( BRect(0,0,1,1), "PrevTrack", BTranslationUtils::GetBitmap(B_PNG_FORMAT,"prev_up"), + BTranslationUtils::GetBitmap(B_PNG_FORMAT,"prev_down"), new BMessage(M_PREV_TRACK), B_FOLLOW_BOTTOM, B_WILL_DRAW); fPrevTrack->ResizeToPreferred(); fPrevTrack->MoveTo(fPlay->Frame().right + 10, Bounds().bottom - 5 - fPrevTrack->Frame().Height()); - fPrevTrack->SetDisabled(BTranslationUtils::GetBitmap('PNG ',"prev_disabled")); + fPrevTrack->SetDisabled(BTranslationUtils::GetBitmap(B_PNG_FORMAT,"prev_disabled")); AddChild(fPrevTrack); - fNextTrack = new DrawButton( BRect(0,0,1,1), "NextTrack", BTranslationUtils::GetBitmap('PNG ',"next_up"), - BTranslationUtils::GetBitmap('PNG ',"next_down"), new BMessage(M_NEXT_TRACK), + fNextTrack = new DrawButton( BRect(0,0,1,1), "NextTrack", BTranslationUtils::GetBitmap(B_PNG_FORMAT,"next_up"), + BTranslationUtils::GetBitmap(B_PNG_FORMAT,"next_down"), new BMessage(M_NEXT_TRACK), B_FOLLOW_BOTTOM, B_WILL_DRAW); fNextTrack->ResizeToPreferred(); fNextTrack->MoveTo(fPrevTrack->Frame().right + 2, Bounds().bottom - 5 - fNextTrack->Frame().Height()); - fNextTrack->SetDisabled(BTranslationUtils::GetBitmap('PNG ',"next_disabled")); + 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('PNG ',"rew_up"), - BTranslationUtils::GetBitmap('PNG ',"rew_down"), new BMessage(M_PREV_TRACK), + 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->ResizeToPreferred(); fRewind->MoveTo(fNextTrack->Frame().right + 10, Bounds().bottom - 5 - fRewind->Frame().Height()); - fRewind->SetDisabled(BTranslationUtils::GetBitmap('PNG ',"rew_disabled")); + fRewind->SetDisabled(BTranslationUtils::GetBitmap(B_PNG_FORMAT,"rew_disabled")); AddChild(fRewind); - fFastFwd = new DrawButton( BRect(0,0,1,1), "FastFwd", BTranslationUtils::GetBitmap('PNG ',"ffwd_up"), - BTranslationUtils::GetBitmap('PNG ',"ffwd_down"), new BMessage(M_NEXT_TRACK), + 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->ResizeToPreferred(); fFastFwd->MoveTo(fRewind->Frame().right + 2, Bounds().bottom - 5 - fFastFwd->Frame().Height()); - fFastFwd->SetDisabled(BTranslationUtils::GetBitmap('PNG ',"ffwd_disabled")); + fFastFwd->SetDisabled(BTranslationUtils::GetBitmap(B_PNG_FORMAT,"ffwd_disabled")); AddChild(fFastFwd); - fEject = new DrawButton( BRect(0,0,1,1), "Eject", BTranslationUtils::GetBitmap('PNG ',"eject_up"), - BTranslationUtils::GetBitmap('PNG ',"eject_down"), new BMessage(M_EJECT), + 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), B_FOLLOW_BOTTOM, B_WILL_DRAW); fEject->ResizeToPreferred(); fEject->MoveTo(fFastFwd->Frame().right + 20, Bounds().bottom - 5 - fEject->Frame().Height()); - fEject->SetDisabled(BTranslationUtils::GetBitmap('PNG ',"eject_disabled")); + fEject->SetDisabled(BTranslationUtils::GetBitmap(B_PNG_FORMAT,"eject_disabled")); AddChild(fEject); - fSave = new DrawButton( BRect(0,0,1,1), "Save", BTranslationUtils::GetBitmap('PNG ',"save_up"), - BTranslationUtils::GetBitmap('PNG ',"save_down"), new BMessage(M_SAVE), + fSave = new DrawButton( BRect(0,0,1,1), "Save", BTranslationUtils::GetBitmap(B_PNG_FORMAT,"save_up"), + BTranslationUtils::GetBitmap(B_PNG_FORMAT,"save_down"), new BMessage(M_SAVE), B_FOLLOW_NONE, B_WILL_DRAW); fSave->ResizeToPreferred(); fSave->MoveTo(fEject->Frame().right + 20, Bounds().bottom - 5 - fSave->Frame().Height()); - fSave->SetDisabled(BTranslationUtils::GetBitmap('PNG ',"save_disabled")); + fSave->SetDisabled(BTranslationUtils::GetBitmap(B_PNG_FORMAT,"save_disabled")); AddChild(fSave); fSave->SetEnabled(false); // TODO: Shuffle and Repeat are special buttons. Implement as two-state buttons - fShuffle = new DrawButton( BRect(0,0,1,1), "Shuffle", BTranslationUtils::GetBitmap('PNG ',"shuffle_up"), - BTranslationUtils::GetBitmap('PNG ',"shuffle_down"), new BMessage(M_SHUFFLE), + fShuffle = new DrawButton( BRect(0,0,1,1), "Shuffle", BTranslationUtils::GetBitmap(B_PNG_FORMAT,"shuffle_up"), + BTranslationUtils::GetBitmap(B_PNG_FORMAT,"shuffle_down"), new BMessage(M_SHUFFLE), B_FOLLOW_NONE, B_WILL_DRAW); fShuffle->ResizeToPreferred(); fShuffle->MoveTo(fSave->Frame().right + 2, Bounds().bottom - 5 - fShuffle->Frame().Height()); - fShuffle->SetDisabled(BTranslationUtils::GetBitmap('PNG ',"shuffle_disabled")); + fShuffle->SetDisabled(BTranslationUtils::GetBitmap(B_PNG_FORMAT,"shuffle_disabled")); AddChild(fShuffle); fShuffle->SetEnabled(false); - fRepeat = new DrawButton( BRect(0,0,1,1), "Repeat", BTranslationUtils::GetBitmap('PNG ',"repeat_up"), - BTranslationUtils::GetBitmap('PNG ',"repeat_down"), new BMessage(M_REPEAT), + fRepeat = new DrawButton( BRect(0,0,1,1), "Repeat", BTranslationUtils::GetBitmap(B_PNG_FORMAT,"repeat_up"), + BTranslationUtils::GetBitmap(B_PNG_FORMAT,"repeat_down"), new BMessage(M_REPEAT), B_FOLLOW_NONE, B_WILL_DRAW); fRepeat->ResizeToPreferred(); fRepeat->MoveTo(fShuffle->Frame().right + 2, Bounds().bottom - 5 - fRepeat->Frame().Height()); - fRepeat->SetDisabled(BTranslationUtils::GetBitmap('PNG ',"repeat_disabled")); + fRepeat->SetDisabled(BTranslationUtils::GetBitmap(B_PNG_FORMAT,"repeat_disabled")); AddChild(fRepeat); fRepeat->SetEnabled(false); } @@ -291,17 +287,34 @@ CDButton::MessageReceived(BMessage *msg) { case M_SET_VOLUME: { - // TODO: Implement engine->SetVolume(fVolume->Value()); break; } case M_STOP: { + if(engine->PlayStateWatcher()->GetState()==kPlaying) + { + fPlay->SetBitmaps(BTranslationUtils::GetBitmap(B_PNG_FORMAT,"play_up"), + BTranslationUtils::GetBitmap(B_PNG_FORMAT,"play_down")); + } engine->Stop(); break; } case M_PLAY: { + // If we are currently playing, then we will be showing + // the pause images and will want to switch back to the play images + if(engine->PlayStateWatcher()->GetState()==kPlaying) + { + fPlay->SetBitmaps(BTranslationUtils::GetBitmap(B_PNG_FORMAT,"play_up"), + BTranslationUtils::GetBitmap(B_PNG_FORMAT,"play_down")); + } + else + { + // Currently not playing and going to be playing, so show pause icons + fPlay->SetBitmaps(BTranslationUtils::GetBitmap(B_PNG_FORMAT,"pause_up"), + BTranslationUtils::GetBitmap(B_PNG_FORMAT,"pause_down")); + } engine->PlayOrPause(); break; } @@ -468,9 +481,8 @@ CDButton::NoticeChange(Notifier *notifier) else if(trs) { + // TODO: Update track count indicator once there is one UpdateCDInfo(); - - // TODO: Update track count indicator } else if(tms) @@ -611,7 +623,8 @@ public: }; CDButtonWindow::CDButtonWindow(void) - : BWindow(BRect (100, 100, 610, 200), "CD Player", B_TITLED_WINDOW, B_NOT_V_RESIZABLE) + : 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; @@ -627,22 +640,13 @@ bool CDButtonWindow::QuitRequested(void) return true; } -CDButtonWindow *cdbwin; -CDButton *cdbutton; - CDButtonApplication::CDButtonApplication() : BApplication("application/x-vnd.Haiku-CDPlayer") { -// BWindow *window = new CDButtonWindow(); - -// BView *button = new CDButton(window->Bounds(), "CD"); -/// window->AddChild(button); -// window->Show(); - cdbwin = new CDButtonWindow(); - - cdbutton = new CDButton(cdbwin->Bounds(), "CD"); - cdbwin->AddChild(cdbutton); - cdbwin->Show(); + BWindow *window = new CDButtonWindow(); + BView *button = new CDButton(window->Bounds(), "CD"); + window->AddChild(button); + window->Show(); } int diff --git a/src/apps/cdplayer/CDButton.h b/src/apps/cdplayer/CDButton.h index d8ca408d08..38e00506f8 100644 --- a/src/apps/cdplayer/CDButton.h +++ b/src/apps/cdplayer/CDButton.h @@ -16,48 +16,46 @@ #include #include +#include "PlayList.h" #include "Observer.h" #include "CDEngine.h" class DrawButton; +class TwoStateDrawButton; class CDButton : public BView, private Observer { public: - CDButton(BRect frame, const char *name, uint32 resizeMask = B_FOLLOW_ALL, - uint32 flags = B_WILL_DRAW | B_NAVIGABLE | B_PULSE_NEEDED); - - virtual ~CDButton(); + CDButton(BRect frame, const char *name, + uint32 resizeMask = B_FOLLOW_ALL, + uint32 flags = B_WILL_DRAW | B_NAVIGABLE | + B_PULSE_NEEDED); + virtual ~CDButton(); - void BuildGUI(void); + void BuildGUI(void); - // misc BView overrides - virtual void AttachedToWindow(); - - virtual void Pulse(); - - virtual void FrameResized(float new_width, float new_height); - - virtual void MessageReceived(BMessage *); + virtual void AttachedToWindow(); + virtual void Pulse(); + virtual void FrameResized(float new_width, float new_height); + virtual void MessageReceived(BMessage *); // observing overrides - virtual BHandler *RecipientHandler() const + virtual BHandler *RecipientHandler() const { return (BHandler *)this; } - - virtual void NoticeChange(Notifier *); + + virtual void NoticeChange(Notifier *); private: - void UpdateCDInfo(void); - void UpdateTimeInfo(void); - void SetBitmap(BBitmap *bitmap); + void UpdateCDInfo(void); + void UpdateTimeInfo(void); + void SetBitmap(BBitmap *bitmap); - bool fStopOnQuit; - - CDEngine *engine; + CDEngine *engine; DrawButton *fStop, *fPlay, *fNextTrack, *fPrevTrack; DrawButton *fFastFwd, *fRewind, *fEject, *fSave, *fShuffle, *fRepeat; + BSlider *fVolume; BStringView *fCDTitle; @@ -70,6 +68,7 @@ private: BBox *fTimeBox; CDState fCDState; + PlayList fPlaylist; }; diff --git a/src/apps/cdplayer/CDEngine.h b/src/apps/cdplayer/CDEngine.h index e6073db3a7..0ba2a2924d 100644 --- a/src/apps/cdplayer/CDEngine.h +++ b/src/apps/cdplayer/CDEngine.h @@ -70,7 +70,7 @@ private: }; class TrackState : public PeriodicWatcher { - // this watcher sends notices to observers that are interrested + // this watcher sends notices to observers that are interested // about changes in the current track public: TrackState(int devicefd); @@ -88,7 +88,7 @@ private: }; class TimeState : public PeriodicWatcher { - // this watcher sends notices to observers that are interrested + // this watcher sends notices to observers that are interested // about changes in the current time public: TimeState(int devicefd) diff --git a/src/apps/cdplayer/CDPlayer.rdef b/src/apps/cdplayer/CDPlayer.rdef index bec65b8299..dac5556f25 100644 --- a/src/apps/cdplayer/CDPlayer.rdef +++ b/src/apps/cdplayer/CDPlayer.rdef @@ -466,3 +466,30 @@ resource(34, "shuffle_disabled") #'PNG ' array { $"BF43999EEF781065CBB29703877C394C0D3CBE855E4A1104D8C6E70000000049" $"454E44AE426082" }; + +resource(35, "pause_up") #'PNG ' array { + $"89504E470D0A1A0A0000000D49484452000000230000001308060000001AA3B4" + $"F40000007349444154789CEDD6310E80200C40D15FC351382BA764E706AC7530" + $"2A2636461DDA813711C2F0C3D05454550940444800AD35D790520AC01603D07B" + $"778BD92DDE01A3F4FCE42AE77C9C6BADE6DD17A17E66C658668C65C658668CE5" + $"F504BE9BB07FA6EE28D4CF848A4970EE13DE0408B1E901AC69F9191025EE76CE" + $"0000000049454E44AE426082" +}; + +resource(36, "pause_down") #'PNG ' array { + $"89504E470D0A1A0A0000000D49484452000000230000001308060000001AA3B4" + $"F40000007B49444154789CEDD6C10D80200C40D1AF6109D66104E6600286631C" + $"D6A807A3C1C4C6A887F6C03F11C2E1A5878605101C24220480528A29A4D60AB0" + $"630072CE6698A3D51A30169E9F5C4B299DE7D69A7AF72557939918AD89D19A18" + $"AD89D17ABD81EF36EC9FAD3BE66A32AE300B20BD776B07314682888B8F1E001B" + $"026A19408271DF2C0000000049454E44AE426082" +}; + +resource(37, "pause_disabled") #'PNG ' array { + $"89504E470D0A1A0A0000000D49484452000000230000001308060000001AA3B4" + $"F40000007449444154789CEDD6310E80200C40D15FC3B1381F27E32EDC80B50E" + $"46C5C4C6A8433BF02642187E189A8AAA2A01880809A0B5E61A524A01D862007A" + $"EF6E31BBC53B60949E9F5CD55A8F73CED9BCFB22D4CFCC18CB8CB1CC18CB8CB1" + $"BC9EC07713F6CFD41D85FA99503109CE7DC29B0021363D801523B21550831E27" + $"7A0000000049454E44AE426082" +}; diff --git a/src/apps/cdplayer/DrawButton.cpp b/src/apps/cdplayer/DrawButton.cpp index db51f8692f..7c116ec2d5 100644 --- a/src/apps/cdplayer/DrawButton.cpp +++ b/src/apps/cdplayer/DrawButton.cpp @@ -11,25 +11,37 @@ DrawButton::DrawButton(BRect frame, const char *name, BBitmap *up, BBitmap *down DrawButton::~DrawButton(void) { + delete fUp; + delete fDown; + delete fDisabled; } -void DrawButton::SetBitmaps(BBitmap *up, BBitmap *down) +void +DrawButton::SetBitmaps(BBitmap *up, BBitmap *down) { delete fUp; delete fDown; fUp=up; fDown=down; + + if(IsEnabled()) + Invalidate(); } -void DrawButton::SetDisabled(BBitmap *disabled) +void +DrawButton::SetDisabled(BBitmap *disabled) { delete fDisabled; fDisabled=disabled; + + if(!IsEnabled()) + Invalidate(); } -void DrawButton::Draw(BRect update) +void +DrawButton::Draw(BRect update) { if(!IsEnabled()) { @@ -56,7 +68,8 @@ void DrawButton::Draw(BRect update) } } -void DrawButton::ResizeToPreferred(void) +void +DrawButton::ResizeToPreferred(void) { if(fUp) ResizeTo(fUp->Bounds().Width(),fUp->Bounds().Height()); diff --git a/src/apps/cdplayer/DrawButton.h b/src/apps/cdplayer/DrawButton.h index af907b91af..764498f66e 100644 --- a/src/apps/cdplayer/DrawButton.h +++ b/src/apps/cdplayer/DrawButton.h @@ -12,20 +12,22 @@ class DrawButton : public BButton { public: - DrawButton(BRect frame, const char *name, BBitmap *up, BBitmap *down, - BMessage *msg, int32 resize, int32 flags); - ~DrawButton(void); + DrawButton(BRect frame, const char *name, BBitmap *up, + BBitmap *down,BMessage *msg, int32 resize, + int32 flags); + ~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: - BBitmap *fUp, *fDown, *fDisabled; - + BBitmap *fUp, + *fDown, + *fDisabled; }; -#endif \ No newline at end of file +#endif diff --git a/src/apps/cdplayer/Jamfile b/src/apps/cdplayer/Jamfile index aa21aa5959..c6a4d85997 100644 --- a/src/apps/cdplayer/Jamfile +++ b/src/apps/cdplayer/Jamfile @@ -8,6 +8,8 @@ App CDPlayer : DrawButton.cpp FunctionObjectMessage.cpp Observer.cpp + PlayList.cpp + TwoStateDrawButton.cpp TypedList.cpp ; LinkSharedOSLibs CDPlayer : be net netapi translation ; diff --git a/src/apps/cdplayer/PlayList.cpp b/src/apps/cdplayer/PlayList.cpp new file mode 100644 index 0000000000..1f02a73373 --- /dev/null +++ b/src/apps/cdplayer/PlayList.cpp @@ -0,0 +1,104 @@ +#include "PlayList.h" +#include +#include +#include + +PlayList::PlayList(int16 tracks) + : fTrackCount(0), + fTrackIndex(0), + fRandom(false), + fLoop(false) +{ + srand(real_time_clock_usecs()); + + SetTrackCount(tracks); +} + +void +PlayList::SetTrackCount(const int16 &count) +{ + if(count < 0) + fTrackCount = 0; + else + if(count > 500) + fTrackCount = 500; + else + fTrackCount = count; + + memset(fTrackList,-1,500); + SetShuffle(IsShuffled()); +} + +void +PlayList::Rewind(void) +{ + fTrackIndex = 0; +} + +void +PlayList::SetShuffle(const bool &random) +{ + if(random) + Randomize(); + else + Unrandomize(); +} + +void +PlayList::SetLoop(const bool &loop) +{ + fLoop = loop; +} + +int16 +PlayList::GetNextTrack(void) +{ + if(fTrackCount < 1) + return -1; + + if(fTrackIndex == fTrackCount) + { + if(fLoop) + fTrackIndex = 0; + else + return -1; + } + + return fTrackList[fTrackIndex++]; +} + +void +PlayList::Randomize(void) +{ + // Reinitialize the count + for(int16 i=0; i + +class PlayList +{ +public: + PlayList(int16 tracks = 0); + + void SetTrackCount(const int16 &count); + int16 TrackCount(void) const { return fTrackCount; } + + void Rewind(void); + + void SetShuffle(const bool &random); + bool IsShuffled(void) const { return fRandom; } + + void SetLoop(const bool &loop); + bool IsLoop(void) const { return fLoop; } + + int16 GetNextTrack(void); + +private: + void Randomize(void); + void Unrandomize(void); + + int16 fTrackCount; + int16 fTrackIndex; + int16 fTrackList[500]; // This should be big enough. :) + + bool fRandom; + bool fLoop; + + +}; + +#endif diff --git a/src/apps/cdplayer/TwoStateDrawButton.cpp b/src/apps/cdplayer/TwoStateDrawButton.cpp new file mode 100644 index 0000000000..39ae02ee2d --- /dev/null +++ b/src/apps/cdplayer/TwoStateDrawButton.cpp @@ -0,0 +1,138 @@ +#include "TwoStateDrawButton.h" + +TwoStateDrawButton::TwoStateDrawButton(BRect frame, const char *name, BBitmap *upone, + BBitmap *downone, BBitmap *uptwo, + BBitmap *downtwo, BMessage *msg, + const int32 &resize, const int32 &flags) + : BButton(frame, name, "", msg, resize, flags), + fUpOne(upone), + fDownOne(downone), + fUpTwo(uptwo), + fDownTwo(downtwo), + fDisabledOne(NULL), + fDisabledTwo(NULL), + fButtonState(true) + +{ + fButtonState=false; +} + +TwoStateDrawButton::~TwoStateDrawButton(void) +{ + delete fUpOne; + delete fDownOne; + delete fUpTwo; + delete fDownTwo; + delete fDisabledOne; + delete fDisabledTwo; +} + +void +TwoStateDrawButton::ResizeToPreferred(void) +{ + if(fUpOne) + ResizeTo(fUpOne->Bounds().Width(),fUpOne->Bounds().Height()); + else + if(fDownOne) + ResizeTo(fDownOne->Bounds().Width(),fDownOne->Bounds().Height()); + else + if(fUpTwo) + ResizeTo(fUpTwo->Bounds().Width(),fUpTwo->Bounds().Height()); + else + if(fDownTwo) + ResizeTo(fDownTwo->Bounds().Width(),fDownTwo->Bounds().Height()); + else + if(fDisabledOne) + ResizeTo(fDisabledOne->Bounds().Width(),fDisabledOne->Bounds().Height()); + else + if(fDisabledTwo) + ResizeTo(fDisabledTwo->Bounds().Width(),fDisabledTwo->Bounds().Height()); +} + +void +TwoStateDrawButton::SetBitmaps(BBitmap *upone, BBitmap *downone, BBitmap *uptwo, + BBitmap *downtwo) +{ + delete fUpOne; + delete fDownOne; + delete fUpTwo; + delete fDownTwo; + + fUpOne = upone; + fDownOne = downone; + fUpTwo = uptwo; + fDownTwo = downtwo; +} + +void TwoStateDrawButton::SetDisabled(BBitmap *disabledone, BBitmap *disabledtwo) +{ + delete fDisabledOne; + delete fDisabledTwo; + + fDisabledOne = disabledone; + fDisabledTwo = disabledtwo; +} + +void TwoStateDrawButton::MouseUp(BPoint pt) +{ + BButton::MouseUp(pt); + fButtonState = fButtonState ? false : true; + Invalidate(); +} + +void TwoStateDrawButton::Draw(BRect update) +{ + if(fButtonState) + { + if(!IsEnabled()) + { + if(fDisabledTwo) + DrawBitmap(fDisabledTwo, BPoint(0,0)); + else + StrokeRect(Bounds()); + return; + } + + if(Value() == B_CONTROL_ON) + { + if(fDownTwo) + DrawBitmap(fDownTwo, BPoint(0,0)); + else + StrokeRect(Bounds()); + } + else + { + if(fUpTwo) + DrawBitmap(fUpTwo, BPoint(0,0)); + else + StrokeRect(Bounds()); + } + } + else + { + if(!IsEnabled()) + { + if(fDisabledOne) + DrawBitmap(fDisabledOne, BPoint(0,0)); + else + StrokeRect(Bounds()); + return; + } + + if(Value() == B_CONTROL_ON) + { + if(fDownOne) + DrawBitmap(fDownOne, BPoint(0,0)); + else + StrokeRect(Bounds()); + } + else + { + if(fUpOne) + DrawBitmap(fUpOne, BPoint(0,0)); + else + StrokeRect(Bounds()); + } + } +} + diff --git a/src/apps/cdplayer/TwoStateDrawButton.h b/src/apps/cdplayer/TwoStateDrawButton.h new file mode 100644 index 0000000000..8910ba50b6 --- /dev/null +++ b/src/apps/cdplayer/TwoStateDrawButton.h @@ -0,0 +1,41 @@ +#ifndef _TWOSTATE_DRAWBUTTON_H +#define _TWOSTATE_DRAWBUTTON_H + +#include +#include +#include +#include + + +class TwoStateDrawButton : public BButton +{ +public: + TwoStateDrawButton(BRect frame, const char *name, BBitmap *upone, + BBitmap *downone, BBitmap *uptwo, BBitmap *downtwo, + BMessage *msg, const int32 &resize, + const int32 &flags); + ~TwoStateDrawButton(void); + + void Draw(BRect update); + + void SetBitmaps(BBitmap *upone, BBitmap *downone, BBitmap *uptwo, + BBitmap *downtwo); + void ResizeToPreferred(void); + void SetDisabled(BBitmap *disabledone, BBitmap *disabledtwo); + void MouseUp(BPoint pt); +// void MessageReceived(BMessage *msg); + +private: + + BBitmap *fUpOne, + *fDownOne, + *fUpTwo, + *fDownTwo, + *fDisabledOne, + *fDisabledTwo; + + // true if in state two + bool fButtonState; +}; + +#endif \ No newline at end of file