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
This commit is contained in:
DarkWyrm
2005-06-28 18:56:16 +00:00
parent feb8560ca9
commit f479b4974a
11 changed files with 460 additions and 92 deletions
+58 -54
View File
@@ -23,6 +23,7 @@
#include "CDButton.h" #include "CDButton.h"
#include "DrawButton.h" #include "DrawButton.h"
#include "TwoStateDrawButton.h"
#include <TranslationUtils.h> #include <TranslationUtils.h>
#include <TranslatorFormats.h> #include <TranslatorFormats.h>
#include <TranslatorRoster.h> #include <TranslatorRoster.h>
@@ -47,10 +48,6 @@ enum
CDButton::CDButton(BRect frame, const char *name, uint32 resizeMask, uint32 flags) CDButton::CDButton(BRect frame, const char *name, uint32 resizeMask, uint32 flags)
: BView(frame, name, resizeMask, flags | B_FRAME_EVENTS) : 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)); SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR));
// TODO: Support multiple CD drives // TODO: Support multiple CD drives
@@ -74,8 +71,7 @@ CDButton::CDButton(BRect frame, const char *name, uint32 resizeMask, uint32 flag
CDButton::~CDButton() CDButton::~CDButton()
{ {
if(fStopOnQuit) engine->Stop();
engine->Stop();
delete engine; delete engine;
} }
@@ -138,89 +134,89 @@ void CDButton::BuildGUI(void)
fVolume->MoveTo(5, Bounds().bottom - 10 - fVolume->Frame().Height()); fVolume->MoveTo(5, Bounds().bottom - 10 - fVolume->Frame().Height());
AddChild(fVolume); AddChild(fVolume);
fStop = new DrawButton( BRect(0,0,1,1), "Stop", BTranslationUtils::GetBitmap('PNG ',"stop_up"), fStop = new DrawButton( BRect(0,0,1,1), "Stop", BTranslationUtils::GetBitmap(B_PNG_FORMAT,"stop_up"),
BTranslationUtils::GetBitmap('PNG ',"stop_down"), new BMessage(M_STOP), BTranslationUtils::GetBitmap(B_PNG_FORMAT,"stop_down"), new BMessage(M_STOP),
B_FOLLOW_BOTTOM, B_WILL_DRAW); B_FOLLOW_BOTTOM, B_WILL_DRAW);
fStop->ResizeToPreferred(); fStop->ResizeToPreferred();
fStop->MoveTo(fVolume->Frame().right + 10, Bounds().bottom - 5 - fStop->Frame().Height()); 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); AddChild(fStop);
// TODO: Play is a special button. Implement as two-state buttons // 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"), fPlay = new DrawButton( BRect(0,0,1,1), "Play", BTranslationUtils::GetBitmap(B_PNG_FORMAT,"play_up"),
BTranslationUtils::GetBitmap('PNG ',"play_down"), new BMessage(M_PLAY), BTranslationUtils::GetBitmap(B_PNG_FORMAT,"play_down"),
B_FOLLOW_BOTTOM, B_WILL_DRAW); new BMessage(M_PLAY), B_FOLLOW_BOTTOM, B_WILL_DRAW);
fPlay->ResizeToPreferred(); fPlay->ResizeToPreferred();
fPlay->MoveTo(fStop->Frame().right + 2, Bounds().bottom - 5 - fPlay->Frame().Height()); 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); AddChild(fPlay);
fPrevTrack = new DrawButton( BRect(0,0,1,1), "PrevTrack", BTranslationUtils::GetBitmap('PNG ',"prev_up"), fPrevTrack = new DrawButton( BRect(0,0,1,1), "PrevTrack", BTranslationUtils::GetBitmap(B_PNG_FORMAT,"prev_up"),
BTranslationUtils::GetBitmap('PNG ',"prev_down"), new BMessage(M_PREV_TRACK), BTranslationUtils::GetBitmap(B_PNG_FORMAT,"prev_down"), new BMessage(M_PREV_TRACK),
B_FOLLOW_BOTTOM, B_WILL_DRAW); B_FOLLOW_BOTTOM, B_WILL_DRAW);
fPrevTrack->ResizeToPreferred(); fPrevTrack->ResizeToPreferred();
fPrevTrack->MoveTo(fPlay->Frame().right + 10, Bounds().bottom - 5 - fPrevTrack->Frame().Height()); 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); AddChild(fPrevTrack);
fNextTrack = new DrawButton( BRect(0,0,1,1), "NextTrack", BTranslationUtils::GetBitmap('PNG ',"next_up"), fNextTrack = new DrawButton( BRect(0,0,1,1), "NextTrack", BTranslationUtils::GetBitmap(B_PNG_FORMAT,"next_up"),
BTranslationUtils::GetBitmap('PNG ',"next_down"), new BMessage(M_NEXT_TRACK), BTranslationUtils::GetBitmap(B_PNG_FORMAT,"next_down"), new BMessage(M_NEXT_TRACK),
B_FOLLOW_BOTTOM, B_WILL_DRAW); B_FOLLOW_BOTTOM, B_WILL_DRAW);
fNextTrack->ResizeToPreferred(); fNextTrack->ResizeToPreferred();
fNextTrack->MoveTo(fPrevTrack->Frame().right + 2, Bounds().bottom - 5 - fNextTrack->Frame().Height()); 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); AddChild(fNextTrack);
// TODO: Fast Forward and Rewind are special buttons. Implement as two-state buttons // 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"), fRewind = new DrawButton( BRect(0,0,1,1), "Rewind", BTranslationUtils::GetBitmap(B_PNG_FORMAT,"rew_up"),
BTranslationUtils::GetBitmap('PNG ',"rew_down"), new BMessage(M_PREV_TRACK), BTranslationUtils::GetBitmap(B_PNG_FORMAT,"rew_down"), new BMessage(M_PREV_TRACK),
B_FOLLOW_BOTTOM, B_WILL_DRAW); B_FOLLOW_BOTTOM, B_WILL_DRAW);
fRewind->ResizeToPreferred(); fRewind->ResizeToPreferred();
fRewind->MoveTo(fNextTrack->Frame().right + 10, Bounds().bottom - 5 - fRewind->Frame().Height()); 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); AddChild(fRewind);
fFastFwd = new DrawButton( BRect(0,0,1,1), "FastFwd", BTranslationUtils::GetBitmap('PNG ',"ffwd_up"), fFastFwd = new DrawButton( BRect(0,0,1,1), "FastFwd", BTranslationUtils::GetBitmap(B_PNG_FORMAT,"ffwd_up"),
BTranslationUtils::GetBitmap('PNG ',"ffwd_down"), new BMessage(M_NEXT_TRACK), BTranslationUtils::GetBitmap(B_PNG_FORMAT,"ffwd_down"), new BMessage(M_NEXT_TRACK),
B_FOLLOW_BOTTOM, B_WILL_DRAW); B_FOLLOW_BOTTOM, B_WILL_DRAW);
fFastFwd->ResizeToPreferred(); fFastFwd->ResizeToPreferred();
fFastFwd->MoveTo(fRewind->Frame().right + 2, Bounds().bottom - 5 - fFastFwd->Frame().Height()); 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); AddChild(fFastFwd);
fEject = new DrawButton( BRect(0,0,1,1), "Eject", BTranslationUtils::GetBitmap('PNG ',"eject_up"), fEject = new DrawButton( BRect(0,0,1,1), "Eject", BTranslationUtils::GetBitmap(B_PNG_FORMAT,"eject_up"),
BTranslationUtils::GetBitmap('PNG ',"eject_down"), new BMessage(M_EJECT), BTranslationUtils::GetBitmap(B_PNG_FORMAT,"eject_down"), new BMessage(M_EJECT),
B_FOLLOW_BOTTOM, B_WILL_DRAW); B_FOLLOW_BOTTOM, B_WILL_DRAW);
fEject->ResizeToPreferred(); fEject->ResizeToPreferred();
fEject->MoveTo(fFastFwd->Frame().right + 20, Bounds().bottom - 5 - fEject->Frame().Height()); 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); AddChild(fEject);
fSave = new DrawButton( BRect(0,0,1,1), "Save", BTranslationUtils::GetBitmap('PNG ',"save_up"), fSave = new DrawButton( BRect(0,0,1,1), "Save", BTranslationUtils::GetBitmap(B_PNG_FORMAT,"save_up"),
BTranslationUtils::GetBitmap('PNG ',"save_down"), new BMessage(M_SAVE), BTranslationUtils::GetBitmap(B_PNG_FORMAT,"save_down"), new BMessage(M_SAVE),
B_FOLLOW_NONE, B_WILL_DRAW); B_FOLLOW_NONE, B_WILL_DRAW);
fSave->ResizeToPreferred(); fSave->ResizeToPreferred();
fSave->MoveTo(fEject->Frame().right + 20, Bounds().bottom - 5 - fSave->Frame().Height()); 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); AddChild(fSave);
fSave->SetEnabled(false); fSave->SetEnabled(false);
// TODO: Shuffle and Repeat are special buttons. Implement as two-state buttons // 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"), fShuffle = new DrawButton( BRect(0,0,1,1), "Shuffle", BTranslationUtils::GetBitmap(B_PNG_FORMAT,"shuffle_up"),
BTranslationUtils::GetBitmap('PNG ',"shuffle_down"), new BMessage(M_SHUFFLE), BTranslationUtils::GetBitmap(B_PNG_FORMAT,"shuffle_down"), new BMessage(M_SHUFFLE),
B_FOLLOW_NONE, B_WILL_DRAW); B_FOLLOW_NONE, B_WILL_DRAW);
fShuffle->ResizeToPreferred(); fShuffle->ResizeToPreferred();
fShuffle->MoveTo(fSave->Frame().right + 2, Bounds().bottom - 5 - fShuffle->Frame().Height()); 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); AddChild(fShuffle);
fShuffle->SetEnabled(false); fShuffle->SetEnabled(false);
fRepeat = new DrawButton( BRect(0,0,1,1), "Repeat", BTranslationUtils::GetBitmap('PNG ',"repeat_up"), fRepeat = new DrawButton( BRect(0,0,1,1), "Repeat", BTranslationUtils::GetBitmap(B_PNG_FORMAT,"repeat_up"),
BTranslationUtils::GetBitmap('PNG ',"repeat_down"), new BMessage(M_REPEAT), BTranslationUtils::GetBitmap(B_PNG_FORMAT,"repeat_down"), new BMessage(M_REPEAT),
B_FOLLOW_NONE, B_WILL_DRAW); B_FOLLOW_NONE, B_WILL_DRAW);
fRepeat->ResizeToPreferred(); fRepeat->ResizeToPreferred();
fRepeat->MoveTo(fShuffle->Frame().right + 2, Bounds().bottom - 5 - fRepeat->Frame().Height()); 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); AddChild(fRepeat);
fRepeat->SetEnabled(false); fRepeat->SetEnabled(false);
} }
@@ -291,17 +287,34 @@ CDButton::MessageReceived(BMessage *msg)
{ {
case M_SET_VOLUME: case M_SET_VOLUME:
{ {
// TODO: Implement
engine->SetVolume(fVolume->Value()); engine->SetVolume(fVolume->Value());
break; break;
} }
case M_STOP: 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(); engine->Stop();
break; break;
} }
case M_PLAY: 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(); engine->PlayOrPause();
break; break;
} }
@@ -468,9 +481,8 @@ CDButton::NoticeChange(Notifier *notifier)
else else
if(trs) if(trs)
{ {
// TODO: Update track count indicator once there is one
UpdateCDInfo(); UpdateCDInfo();
// TODO: Update track count indicator
} }
else else
if(tms) if(tms)
@@ -611,7 +623,8 @@ public:
}; };
CDButtonWindow::CDButtonWindow(void) 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; float wmin,wmax,hmin,hmax;
@@ -627,22 +640,13 @@ bool CDButtonWindow::QuitRequested(void)
return true; return true;
} }
CDButtonWindow *cdbwin;
CDButton *cdbutton;
CDButtonApplication::CDButtonApplication() CDButtonApplication::CDButtonApplication()
: BApplication("application/x-vnd.Haiku-CDPlayer") : BApplication("application/x-vnd.Haiku-CDPlayer")
{ {
// BWindow *window = new CDButtonWindow(); BWindow *window = new CDButtonWindow();
BView *button = new CDButton(window->Bounds(), "CD");
// BView *button = new CDButton(window->Bounds(), "CD"); window->AddChild(button);
/// window->AddChild(button); window->Show();
// window->Show();
cdbwin = new CDButtonWindow();
cdbutton = new CDButton(cdbwin->Bounds(), "CD");
cdbwin->AddChild(cdbutton);
cdbwin->Show();
} }
int int
+21 -22
View File
@@ -16,48 +16,46 @@
#include <TextControl.h> #include <TextControl.h>
#include <StringView.h> #include <StringView.h>
#include "PlayList.h"
#include "Observer.h" #include "Observer.h"
#include "CDEngine.h" #include "CDEngine.h"
class DrawButton; class DrawButton;
class TwoStateDrawButton;
class CDButton : public BView, private Observer class CDButton : public BView, private Observer
{ {
public: public:
CDButton(BRect frame, const char *name, uint32 resizeMask = B_FOLLOW_ALL, CDButton(BRect frame, const char *name,
uint32 flags = B_WILL_DRAW | B_NAVIGABLE | B_PULSE_NEEDED); uint32 resizeMask = B_FOLLOW_ALL,
uint32 flags = B_WILL_DRAW | B_NAVIGABLE |
virtual ~CDButton(); B_PULSE_NEEDED);
virtual ~CDButton();
void BuildGUI(void); void BuildGUI(void);
// misc BView overrides virtual void AttachedToWindow();
virtual void AttachedToWindow(); virtual void Pulse();
virtual void FrameResized(float new_width, float new_height);
virtual void Pulse(); virtual void MessageReceived(BMessage *);
virtual void FrameResized(float new_width, float new_height);
virtual void MessageReceived(BMessage *);
// observing overrides // observing overrides
virtual BHandler *RecipientHandler() const virtual BHandler *RecipientHandler() const
{ return (BHandler *)this; } { return (BHandler *)this; }
virtual void NoticeChange(Notifier *); virtual void NoticeChange(Notifier *);
private: private:
void UpdateCDInfo(void); void UpdateCDInfo(void);
void UpdateTimeInfo(void); void UpdateTimeInfo(void);
void SetBitmap(BBitmap *bitmap); void SetBitmap(BBitmap *bitmap);
bool fStopOnQuit; CDEngine *engine;
CDEngine *engine;
DrawButton *fStop, *fPlay, *fNextTrack, *fPrevTrack; DrawButton *fStop, *fPlay, *fNextTrack, *fPrevTrack;
DrawButton *fFastFwd, *fRewind, *fEject, *fSave, *fShuffle, *fRepeat; DrawButton *fFastFwd, *fRewind, *fEject, *fSave, *fShuffle, *fRepeat;
BSlider *fVolume; BSlider *fVolume;
BStringView *fCDTitle; BStringView *fCDTitle;
@@ -70,6 +68,7 @@ private:
BBox *fTimeBox; BBox *fTimeBox;
CDState fCDState; CDState fCDState;
PlayList fPlaylist;
}; };
+2 -2
View File
@@ -70,7 +70,7 @@ private:
}; };
class TrackState : public PeriodicWatcher { 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 // about changes in the current track
public: public:
TrackState(int devicefd); TrackState(int devicefd);
@@ -88,7 +88,7 @@ private:
}; };
class TimeState : public PeriodicWatcher { 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 // about changes in the current time
public: public:
TimeState(int devicefd) TimeState(int devicefd)
+27
View File
@@ -466,3 +466,30 @@ resource(34, "shuffle_disabled") #'PNG ' array {
$"BF43999EEF781065CBB29703877C394C0D3CBE855E4A1104D8C6E70000000049" $"BF43999EEF781065CBB29703877C394C0D3CBE855E4A1104D8C6E70000000049"
$"454E44AE426082" $"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"
};
+17 -4
View File
@@ -11,25 +11,37 @@ DrawButton::DrawButton(BRect frame, const char *name, BBitmap *up, BBitmap *down
DrawButton::~DrawButton(void) 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 fUp;
delete fDown; delete fDown;
fUp=up; fUp=up;
fDown=down; fDown=down;
if(IsEnabled())
Invalidate();
} }
void DrawButton::SetDisabled(BBitmap *disabled) void
DrawButton::SetDisabled(BBitmap *disabled)
{ {
delete fDisabled; delete fDisabled;
fDisabled=disabled; fDisabled=disabled;
if(!IsEnabled())
Invalidate();
} }
void DrawButton::Draw(BRect update) void
DrawButton::Draw(BRect update)
{ {
if(!IsEnabled()) if(!IsEnabled())
{ {
@@ -56,7 +68,8 @@ void DrawButton::Draw(BRect update)
} }
} }
void DrawButton::ResizeToPreferred(void) void
DrawButton::ResizeToPreferred(void)
{ {
if(fUp) if(fUp)
ResizeTo(fUp->Bounds().Width(),fUp->Bounds().Height()); ResizeTo(fUp->Bounds().Width(),fUp->Bounds().Height());
+12 -10
View File
@@ -12,20 +12,22 @@
class DrawButton : public BButton class DrawButton : public BButton
{ {
public: public:
DrawButton(BRect frame, const char *name, BBitmap *up, BBitmap *down, DrawButton(BRect frame, const char *name, BBitmap *up,
BMessage *msg, int32 resize, int32 flags); BBitmap *down,BMessage *msg, int32 resize,
~DrawButton(void); int32 flags);
~DrawButton(void);
void Draw(BRect update); void Draw(BRect update);
void SetBitmaps(BBitmap *up, BBitmap *down); void SetBitmaps(BBitmap *up, BBitmap *down);
void ResizeToPreferred(void); void ResizeToPreferred(void);
void SetDisabled(BBitmap *disabled); void SetDisabled(BBitmap *disabled);
private: private:
BBitmap *fUp, *fDown, *fDisabled; BBitmap *fUp,
*fDown,
*fDisabled;
}; };
#endif #endif
+2
View File
@@ -8,6 +8,8 @@ App CDPlayer :
DrawButton.cpp DrawButton.cpp
FunctionObjectMessage.cpp FunctionObjectMessage.cpp
Observer.cpp Observer.cpp
PlayList.cpp
TwoStateDrawButton.cpp
TypedList.cpp TypedList.cpp
; ;
LinkSharedOSLibs CDPlayer : be net netapi translation ; LinkSharedOSLibs CDPlayer : be net netapi translation ;
+104
View File
@@ -0,0 +1,104 @@
#include "PlayList.h"
#include <OS.h>
#include <stdlib.h>
#include <string.h>
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<fTrackCount; i++)
fTrackList[i] = i;
// There are probably *much* better ways to do this,
// but this is the only one I could think of. :(
int32 swapcount = fTrackCount * 2;
int16 temp, first, second;
for(int32 i=0; i< swapcount; i++)
{
// repeatedly pick two elements at random and swap them
// This way we are sure to not have any duplicates and still have
// all tracks eventually be played.
first = (int16)(fTrackCount * ((float)rand()/RAND_MAX));
second = (int16)(fTrackCount * ((float)rand()/RAND_MAX));
temp = fTrackList[first];
fTrackList[first] = fTrackList[second];
fTrackList[second] = temp;
}
}
void
PlayList::Unrandomize(void)
{
for(int16 i=0; i<fTrackCount; i++)
fTrackList[i] = i;
}
+38
View File
@@ -0,0 +1,38 @@
#ifndef PLAYLIST_H
#define PLAYLIST_H
#include <SupportDefs.h>
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
+138
View File
@@ -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());
}
}
}
+41
View File
@@ -0,0 +1,41 @@
#ifndef _TWOSTATE_DRAWBUTTON_H
#define _TWOSTATE_DRAWBUTTON_H
#include <Window.h>
#include <View.h>
#include <Bitmap.h>
#include <Button.h>
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