Style changes courtesy of Vasilis Kaoutsis - thanks!

git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@21507 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Axel Dörfler
2007-06-26 14:13:05 +00:00
parent d2d8f91af5
commit cba2053487
6 changed files with 331 additions and 346 deletions
+58 -56
View File
@@ -1,5 +1,7 @@
#include "PlayList.h" #include "PlayList.h"
#include <OS.h> #include <OS.h>
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
@@ -12,8 +14,10 @@
#define STRACE(x) /* nothing */ #define STRACE(x) /* nothing */
#endif #endif
PlayList::PlayList(int16 count, int16 start) PlayList::PlayList(int16 count, int16 start)
: fTrackCount(count), :
fTrackCount(count),
fTrackIndex(0), fTrackIndex(0),
fStartingTrack(start), fStartingTrack(start),
fRandom(false), fRandom(false),
@@ -23,23 +27,23 @@ PlayList::PlayList(int16 count, int16 start)
srand(real_time_clock_usecs()); srand(real_time_clock_usecs());
if(fTrackCount < 0) if (fTrackCount < 0)
fTrackCount = 0; fTrackCount = 0;
else else if (fTrackCount > 500)
if(fTrackCount > 500)
fTrackCount = 500; fTrackCount = 500;
if(fStartingTrack >= fTrackCount) if (fStartingTrack >= fTrackCount)
fStartingTrack = fTrackCount - 1; fStartingTrack = fTrackCount - 1;
if(fStartingTrack < 1) if (fStartingTrack < 1)
fStartingTrack = 1; fStartingTrack = 1;
memset(fTrackList,-1,500); memset(fTrackList, -1, 500);
Unrandomize(); Unrandomize();
} }
void void
PlayList::SetTrackCount(const int16 &count) PlayList::SetTrackCount(const int16 &count)
{ {
@@ -47,23 +51,22 @@ PlayList::SetTrackCount(const int16 &count)
STRACE(("PlayList::SetTrackCount(%d)\n",count)); STRACE(("PlayList::SetTrackCount(%d)\n",count));
if(count <= 0) if (count <= 0) {
{
fTrackCount = 0; fTrackCount = 0;
fTrackIndex = 0; fTrackIndex = 0;
} }
else else if (count > 500)
if(count > 500)
fTrackCount = 500; fTrackCount = 500;
else else
fTrackCount = count; fTrackCount = count;
memset(fTrackList,-1,500); memset(fTrackList, -1, 500);
SetShuffle(IsShuffled()); SetShuffle(IsShuffled());
fLocker.Unlock(); fLocker.Unlock();
} }
void void
PlayList::SetStartingTrack(const int16 &start) PlayList::SetStartingTrack(const int16 &start)
{ {
@@ -76,8 +79,9 @@ PlayList::SetStartingTrack(const int16 &start)
fLocker.Unlock(); fLocker.Unlock();
} }
void void
PlayList::Rewind(void) PlayList::Rewind()
{ {
STRACE(("PlayList::Rewind()\n")); STRACE(("PlayList::Rewind()\n"));
fLocker.Lock(); fLocker.Lock();
@@ -87,13 +91,14 @@ PlayList::Rewind(void)
fLocker.Unlock(); fLocker.Unlock();
} }
void void
PlayList::SetShuffle(const bool &random) PlayList::SetShuffle(const bool &random)
{ {
STRACE(("PlayList::SetShuffle(%s)\n",random ? "random" : "sequential")); STRACE(("PlayList::SetShuffle(%s)\n", random ? "random" : "sequential"));
fLocker.Lock(); fLocker.Lock();
if(random) if (random)
Randomize(); Randomize();
else else
Unrandomize(); Unrandomize();
@@ -103,10 +108,11 @@ PlayList::SetShuffle(const bool &random)
fLocker.Unlock(); fLocker.Unlock();
} }
void void
PlayList::SetLoop(const bool &loop) PlayList::SetLoop(const bool &loop)
{ {
STRACE(("PlayList::SetLoop(%s)\n",loop ? "loop" : "non-loop")); STRACE(("PlayList::SetLoop(%s)\n", loop ? "loop" : "non-loop"));
fLocker.Lock(); fLocker.Lock();
fLoop = loop; fLoop = loop;
@@ -114,20 +120,19 @@ PlayList::SetLoop(const bool &loop)
fLocker.Unlock(); fLocker.Unlock();
} }
void void
PlayList::SetCurrentTrack(const int16 &track) PlayList::SetCurrentTrack(const int16 &track)
{ {
STRACE(("PlayList::SetCurrentTrack(%d)\n",track)); STRACE(("PlayList::SetCurrentTrack(%d)\n",track));
if(track < 0 || track > fTrackCount) if (track < 0 || track > fTrackCount)
return; return;
fLocker.Lock(); fLocker.Lock();
for(int16 i=0; i<fTrackCount; i++) for (int16 i = 0; i < fTrackCount; i++) {
{ if (fTrackList[i] == track) {
if(fTrackList[i] == track)
{
fTrackIndex = i; fTrackIndex = i;
break; break;
} }
@@ -136,8 +141,9 @@ PlayList::SetCurrentTrack(const int16 &track)
fLocker.Unlock(); fLocker.Unlock();
} }
int16 int16
PlayList::GetCurrentTrack(void) PlayList::GetCurrentTrack()
{ {
fLocker.Lock(); fLocker.Lock();
@@ -148,24 +154,22 @@ PlayList::GetCurrentTrack(void)
return value; return value;
} }
int16 int16
PlayList::GetNextTrack(void) PlayList::GetNextTrack()
{ {
fLocker.Lock(); fLocker.Lock();
if(fTrackCount < 1) if (fTrackCount < 1) {
{
fLocker.Unlock(); fLocker.Unlock();
STRACE(("PlayList::GetNextTrack()=-1 (no tracks)\n")); STRACE(("PlayList::GetNextTrack()=-1 (no tracks)\n"));
return -1; return -1;
} }
if(fTrackIndex > (fTrackCount - fStartingTrack)) if (fTrackIndex > (fTrackCount - fStartingTrack)) {
{ if (fLoop)
if(fLoop)
fTrackIndex = 0; fTrackIndex = 0;
else else {
{
fLocker.Unlock(); fLocker.Unlock();
STRACE(("PlayList::GetNextTrack()=-1 (track index out of range)\n")); STRACE(("PlayList::GetNextTrack()=-1 (track index out of range)\n"));
return -1; return -1;
@@ -181,24 +185,22 @@ PlayList::GetNextTrack(void)
return value; return value;
} }
int16 int16
PlayList::GetPreviousTrack(void) PlayList::GetPreviousTrack()
{ {
fLocker.Lock(); fLocker.Lock();
if(fTrackCount < 1) if (fTrackCount < 1) {
{
fLocker.Unlock(); fLocker.Unlock();
STRACE(("PlayList::GetPreviousTrack()=-1 (no tracks)\n")); STRACE(("PlayList::GetPreviousTrack()=-1 (no tracks)\n"));
return -1; return -1;
} }
if(fTrackIndex == 0) if (fTrackIndex == 0) {
{ if (fLoop)
if(fLoop)
fTrackIndex = (fTrackCount - fStartingTrack); fTrackIndex = (fTrackCount - fStartingTrack);
else else {
{
fLocker.Unlock(); fLocker.Unlock();
STRACE(("PlayList::GetPreviousTrack()=-1 (track index out of range)\n")); STRACE(("PlayList::GetPreviousTrack()=-1 (track index out of range)\n"));
return -1; return -1;
@@ -213,13 +215,13 @@ PlayList::GetPreviousTrack(void)
return value; return value;
} }
int16 int16
PlayList::GetLastTrack(void) PlayList::GetLastTrack()
{ {
fLocker.Lock(); fLocker.Lock();
if(fTrackCount < 1) if (fTrackCount < 1) {
{
fLocker.Unlock(); fLocker.Unlock();
STRACE(("PlayList::GetLastTrack()=-1 (no tracks)\n")); STRACE(("PlayList::GetLastTrack()=-1 (no tracks)\n"));
return -1; return -1;
@@ -232,13 +234,13 @@ PlayList::GetLastTrack(void)
return value; return value;
} }
int16 int16
PlayList::GetFirstTrack(void) PlayList::GetFirstTrack()
{ {
fLocker.Lock(); fLocker.Lock();
if(fTrackCount < 1) if (fTrackCount < 1) {
{
fLocker.Unlock(); fLocker.Unlock();
STRACE(("PlayList::GetFirstTrack()=-1 (no tracks)\n")); STRACE(("PlayList::GetFirstTrack()=-1 (no tracks)\n"));
return -1; return -1;
@@ -251,30 +253,30 @@ PlayList::GetFirstTrack(void)
return value; return value;
} }
void void
PlayList::Randomize(void) PlayList::Randomize()
{ {
STRACE(("PlayList::Randomize()\n")); STRACE(("PlayList::Randomize()\n"));
// Reinitialize the count // Reinitialize the count
for(int16 i=fStartingTrack; i<=fTrackCount; i++) for (int16 i = fStartingTrack; i <= fTrackCount; i++)
fTrackList[i - fStartingTrack] = i; fTrackList[i - fStartingTrack] = i;
// There are probably *much* better ways to do this, // There are probably *much* better ways to do this,
// but this is the only one I could think of. :( // but this is the only one I could think of. :(
int32 listcount = (fTrackCount - fStartingTrack); int32 listcount = (fTrackCount - fStartingTrack);
int32 swapcount = listcount* 2; int32 swapcount = listcount * 2;
int16 temp, first, second; int16 temp, first, second;
for(int32 i=0; i< swapcount; i++) for (int32 i = 0; i < swapcount; i++) {
{
// repeatedly pick two elements at random and swap them // repeatedly pick two elements at random and swap them
// This way we are sure to not have any duplicates and still have // This way we are sure to not have any duplicates and still have
// all tracks eventually be played. // all tracks eventually be played.
first = (int16)(listcount * ((float)rand()/RAND_MAX)); first = (int16)(listcount * ((float)rand() / RAND_MAX));
second = (int16)(listcount * ((float)rand()/RAND_MAX)); second = (int16)(listcount * ((float)rand() / RAND_MAX));
temp = fTrackList[first]; temp = fTrackList[first];
fTrackList[first] = fTrackList[second]; fTrackList[first] = fTrackList[second];
@@ -282,16 +284,16 @@ PlayList::Randomize(void)
} }
#ifdef DEBUG_PLAYLIST #ifdef DEBUG_PLAYLIST
for(int16 i=fStartingTrack; i<=fTrackCount; i++) for (int16 i = fStartingTrack; i <= fTrackCount; i++)
printf("\tSlot %d: track %d\n",i,fTrackList[i]); printf("\tSlot %d: track %d\n", i, fTrackList[i]);
#endif #endif
} }
void void
PlayList::Unrandomize(void) PlayList::Unrandomize()
{ {
STRACE(("PlayList::Unrandomize()\n")); STRACE(("PlayList::Unrandomize()\n"));
for(int16 i=fStartingTrack; i<=fTrackCount; i++) for (int16 i = fStartingTrack; i <= fTrackCount; i++)
fTrackList[i - fStartingTrack] = i; fTrackList[i - fStartingTrack] = i;
} }
+17 -18
View File
@@ -1,40 +1,39 @@
#ifndef PLAYLIST_H #ifndef PLAYLIST_H
#define PLAYLIST_H #define PLAYLIST_H
#include <SupportDefs.h>
#include <Locker.h> #include <Locker.h>
#include <SupportDefs.h>
class PlayList class PlayList {
{ public:
public:
PlayList(int16 tracks = 0, int16 startingtrack = 1); PlayList(int16 tracks = 0, int16 startingtrack = 1);
void SetTrackCount(const int16 &count); void SetTrackCount(const int16 &count);
int16 TrackCount(void) const { return fTrackCount; } int16 TrackCount() const { return fTrackCount; }
void SetStartingTrack(const int16 &start); void SetStartingTrack(const int16 &start);
int16 StartingTrack(void) const { return fStartingTrack; } int16 StartingTrack() const { return fStartingTrack; }
void Rewind(void); void Rewind();
void SetShuffle(const bool &random); void SetShuffle(const bool &random);
bool IsShuffled(void) const { return fRandom; } bool IsShuffled() const { return fRandom; }
void SetLoop(const bool &loop); void SetLoop(const bool &loop);
bool IsLoop(void) const { return fLoop; } bool IsLoop() const { return fLoop; }
void SetCurrentTrack(const int16 &track); void SetCurrentTrack(const int16 &track);
int16 GetCurrentTrack(void); int16 GetCurrentTrack();
int16 GetNextTrack(void); int16 GetNextTrack();
int16 GetPreviousTrack(void); int16 GetPreviousTrack();
int16 GetFirstTrack(void); int16 GetFirstTrack();
int16 GetLastTrack(void); int16 GetLastTrack();
private: private:
void Randomize(void); void Randomize();
void Unrandomize(void); void Unrandomize();
int16 fTrackCount; int16 fTrackCount;
int16 fTrackIndex; int16 fTrackIndex;
@@ -47,4 +46,4 @@ private:
BLocker fLocker; BLocker fLocker;
}; };
#endif #endif // PLAYLIST_H
+72 -83
View File
@@ -1,22 +1,24 @@
#include "TrackMenu.h"
#include <Font.h>
#include <Message.h> #include <Message.h>
#include <Region.h> #include <Region.h>
#include <Window.h>
#include <String.h> #include <String.h>
#include <Font.h> #include <Window.h>
#include "TrackMenu.h"
#include <stdio.h> #include <stdio.h>
TrackMenu::TrackMenu(const BRect &frame, const char *name, BMessage *msg, TrackMenu::TrackMenu(const BRect &frame, const char *name, BMessage *msg,
const int32 &resize, const int32 &flags) const int32 &resize, const int32 &flags)
: BView(frame,name,resize,flags), : BView(frame, name, resize, flags), BInvoker(msg, NULL),
BInvoker(msg,NULL),
fCurrentItem(-1), fCurrentItem(-1),
fCount(0), fCount(0),
fIsTracking(false) fIsTracking(false)
{ {
SetViewColor(20,20,20); SetViewColor(20, 20, 20);
fItemRect.Set(1,1,1 + StringWidth("00") + 3, Bounds().bottom - 1); fItemRect.Set(1, 1, 1 + StringWidth("00") + 3, Bounds().bottom - 1);
BFont font; BFont font;
font.SetSize(11); font.SetSize(11);
@@ -29,12 +31,14 @@ TrackMenu::TrackMenu(const BRect &frame, const char *name, BMessage *msg,
fFontHeight = fh.ascent + fh.descent + fh.leading; fFontHeight = fh.ascent + fh.descent + fh.leading;
} }
TrackMenu::~TrackMenu(void)
TrackMenu::~TrackMenu()
{ {
} }
void void
TrackMenu::AttachedToWindow(void) TrackMenu::AttachedToWindow()
{ {
if (!Messenger().IsValid()) if (!Messenger().IsValid())
SetTarget(Window()); SetTarget(Window());
@@ -42,24 +46,22 @@ TrackMenu::AttachedToWindow(void)
BView::AttachedToWindow(); BView::AttachedToWindow();
} }
void void
TrackMenu::MessageReceived(BMessage *msg) TrackMenu::MessageReceived(BMessage *msg)
{ {
switch(msg->what) switch (msg->what) {
{
default: default:
{
BView::MessageReceived(msg); BView::MessageReceived(msg);
break; break;
} }
}
} }
void void
TrackMenu::SetItemCount(const int32 &count) TrackMenu::SetItemCount(const int32 &count)
{ {
if(count < 0) if (count < 0) {
{
fCount = 0; fCount = 0;
fCurrentItem = -1; fCurrentItem = -1;
Invalidate(); Invalidate();
@@ -68,36 +70,35 @@ TrackMenu::SetItemCount(const int32 &count)
fCount = count; fCount = count;
if(fCurrentItem > fCount - 1) if (fCurrentItem > fCount - 1)
fCurrentItem = fCount - 1; fCurrentItem = fCount - 1;
else else if(fCurrentItem < 0)
if(fCurrentItem < 0)
fCurrentItem = 0; fCurrentItem = 0;
Invalidate(); Invalidate();
} }
void void
TrackMenu::SetValue(const int32 &value) TrackMenu::SetValue(const int32 &value)
{ {
if(value < 0 || value > fCount) if (value < 0 || value > fCount)
return; return;
if(value != Value()) if (value != Value()) {
{
fCurrentItem = value; fCurrentItem = value;
Invalidate(); Invalidate();
} }
} }
int32 int32
TrackMenu::ItemAt(const BPoint &pt) TrackMenu::ItemAt(const BPoint &pt)
{ {
// TODO: Optimize. This is simple, but costly in performance // TODO: Optimize. This is simple, but costly in performance
BRect r(fItemRect); BRect r(fItemRect);
for(int32 i=0; i<fCount; i++) for (int32 i = 0; i < fCount; i++) {
{ if (r.Contains(pt))
if(r.Contains(pt))
return i; return i;
r.OffsetBy(r.Width()+1,0); r.OffsetBy(r.Width()+1,0);
} }
@@ -105,6 +106,7 @@ TrackMenu::ItemAt(const BPoint &pt)
return -1; return -1;
} }
void void
TrackMenu::MouseDown(BPoint point) TrackMenu::MouseDown(BPoint point)
{ {
@@ -112,23 +114,19 @@ TrackMenu::MouseDown(BPoint point)
int32 saveditem = fCurrentItem; int32 saveditem = fCurrentItem;
int32 item = ItemAt(pt); int32 item = ItemAt(pt);
if(item >= 0) if (item >= 0) {
{
fCurrentItem = item; fCurrentItem = item;
Invalidate(); Invalidate();
// Shamelessly stolen from BButton. :D // Shamelessly stolen from BButton. :D
if (Window()->Flags() & B_ASYNCHRONOUS_CONTROLS) if (Window()->Flags() & B_ASYNCHRONOUS_CONTROLS) {
{
SetMouseEventMask(B_POINTER_EVENTS, B_LOCK_WINDOW_FOCUS); SetMouseEventMask(B_POINTER_EVENTS, B_LOCK_WINDOW_FOCUS);
fIsTracking = true; fIsTracking = true;
} else } else {
{
uint32 buttons; uint32 buttons;
do do {
{
Window()->UpdateIfNeeded(); Window()->UpdateIfNeeded();
snooze(40000); snooze(40000);
@@ -136,112 +134,109 @@ TrackMenu::MouseDown(BPoint point)
GetMouse(&pt, &buttons, true); GetMouse(&pt, &buttons, true);
int32 mouseitem = ItemAt(pt); int32 mouseitem = ItemAt(pt);
if(mouseitem > -1) if (mouseitem > -1) {
{
fCurrentItem = mouseitem; fCurrentItem = mouseitem;
Draw(Bounds()); Draw(Bounds());
} }
} while (buttons != 0); } while (buttons != 0);
if(fCurrentItem != saveditem) if (fCurrentItem != saveditem)
Invoke(); Invoke();
} }
} }
} }
void void
TrackMenu::MouseUp(BPoint pt) TrackMenu::MouseUp(BPoint pt)
{ {
if(!fIsTracking) if (!fIsTracking)
return; return;
int32 item = ItemAt(pt); int32 item = ItemAt(pt);
if(item >= 0) if (item >= 0)
Invoke(); Invoke();
fIsTracking = false; fIsTracking = false;
} }
void void
TrackMenu::MouseMoved(BPoint pt, uint32 transit, const BMessage *msg) TrackMenu::MouseMoved(BPoint pt, uint32 transit, const BMessage *msg)
{ {
if(!fIsTracking) if (!fIsTracking)
return; return;
int32 item = ItemAt(pt); int32 item = ItemAt(pt);
if(item >= 0) if (item >= 0) {
{
fCurrentItem = item; fCurrentItem = item;
Invalidate(); Invalidate();
} }
} }
void void
TrackMenu::Draw(BRect update) TrackMenu::Draw(BRect update)
{ {
rgb_color dark = {20,20,20,255}; rgb_color dark = {20, 20, 20, 255};
rgb_color light = {200,200,200,255}; rgb_color light = {200, 200, 200, 255};
BPoint pt1,pt2; BPoint pt1, pt2;
// Draw the frame // Draw the frame
SetHighColor(dark); SetHighColor(dark);
pt1.Set(0,0); pt1.Set(0, 0);
pt2 = Bounds().RightTop(); pt2 = Bounds().RightTop();
StrokeLine(pt1,pt2); StrokeLine(pt1, pt2);
pt2.Set(0,Bounds().bottom); pt2.Set(0, Bounds().bottom);
StrokeLine(pt1,pt2); StrokeLine(pt1, pt2);
SetHighColor(255,255,255); SetHighColor(255,255,255);
pt1 = Bounds().RightBottom(); pt1 = Bounds().RightBottom();
pt2.Set(Bounds().right, 1); pt2.Set(Bounds().right, 1);
StrokeLine(pt1,pt2); StrokeLine(pt1, pt2);
pt2.Set(1,Bounds().bottom); pt2.Set(1,Bounds().bottom);
StrokeLine(pt1,pt2); StrokeLine(pt1, pt2);
// Draw the items // Draw the items
BRect r(fItemRect); BRect r(fItemRect);
for(int32 i=0; i<fCount; i++) for (int32 i = 0; i < fCount; i++) {
{
// Draw the item's frame // Draw the item's frame
if(i == fCurrentItem) if (i == fCurrentItem)
SetHighColor(dark); SetHighColor(dark);
else else
SetHighColor(light); SetHighColor(light);
pt1.Set(r.left,r.top); pt1.Set(r.left, r.top);
pt2.Set(r.right,r.top); pt2.Set(r.right, r.top);
StrokeLine(pt1,pt2); StrokeLine(pt1, pt2);
pt2.Set(r.left,r.bottom); pt2.Set(r.left, r.bottom);
StrokeLine(pt1,pt2); StrokeLine(pt1, pt2);
if(i == fCurrentItem) if (i == fCurrentItem) {
{
SetHighColor(light); SetHighColor(light);
pt1.Set(r.right,r.bottom); pt1.Set(r.right, r.bottom);
pt2.Set(r.right, r.top + 1); pt2.Set(r.right, r.top + 1);
StrokeLine(pt1,pt2); StrokeLine(pt1, pt2);
pt2.Set(r.left + 1,r.bottom); pt2.Set(r.left + 1, r.bottom);
StrokeLine(pt1,pt2); StrokeLine(pt1, pt2);
SetHighColor(light); SetHighColor(light);
FillRect(r.InsetByCopy(1,1)); FillRect(r.InsetByCopy(1, 1));
SetHighColor(dark); SetHighColor(dark);
} }
else else if (i == fCount - 1) {
if(i == fCount - 1)
{
SetHighColor(light); SetHighColor(light);
pt1.Set(r.right,r.bottom); pt1.Set(r.right, r.bottom);
pt2.Set(r.right, r.top + 1); pt2.Set(r.right, r.top + 1);
StrokeLine(pt1,pt2); StrokeLine(pt1, pt2);
} }
// Draw the label, center justified // Draw the label, center justified
@@ -250,33 +245,27 @@ TrackMenu::Draw(BRect update)
label << (i + 1); label << (i + 1);
BPoint labelpt; BPoint labelpt;
labelpt.x = r.left + (r.Width() - StringWidth(label.String()))/2 + 2; labelpt.x = r.left + (r.Width() - StringWidth(label.String())) / 2 + 2;
labelpt.y = r.bottom - (r.Height() - fFontHeight + 4)/2; labelpt.y = r.bottom - (r.Height() - fFontHeight + 4) / 2;
if(i == fCurrentItem) if (i == fCurrentItem) {
{
SetHighColor(dark); SetHighColor(dark);
SetLowColor(light); SetLowColor(light);
} } else {
else
{
SetHighColor(light); SetHighColor(light);
SetLowColor(dark); SetLowColor(dark);
} }
DrawString(label.String(),labelpt); DrawString(label.String(), labelpt);
// Setup for next iteration // Setup for next iteration
r.OffsetBy(r.Width()+1,0); r.OffsetBy(r.Width() + 1, 0);
if(r.left > Bounds().right - 2) if (r.left > Bounds().right - 2) {
{
ConstrainClippingRegion(NULL); ConstrainClippingRegion(NULL);
break; break;
} }
if(r.right > Bounds().right - 2) if (r.right > Bounds().right - 2) {
{
r.right = Bounds().right - 2; r.right = Bounds().right - 2;
BRegion reg(r); BRegion reg(r);
ConstrainClippingRegion(&reg); ConstrainClippingRegion(&reg);
+9 -10
View File
@@ -1,31 +1,30 @@
#ifndef TRACKMENU_H #ifndef TRACKMENU_H
#define TRACKMENU_H #define TRACKMENU_H
#include <View.h>
#include <Invoker.h> #include <Invoker.h>
#include <View.h>
class TrackMenu : public BView, public BInvoker class TrackMenu : public BView, public BInvoker {
{ public:
public:
TrackMenu(const BRect &frame, const char *name, BMessage *msg, TrackMenu(const BRect &frame, const char *name, BMessage *msg,
const int32 &resize = B_FOLLOW_LEFT | B_FOLLOW_TOP, const int32 &resize = B_FOLLOW_LEFT | B_FOLLOW_TOP,
const int32 &flags = B_WILL_DRAW); const int32 &flags = B_WILL_DRAW);
~TrackMenu(void); ~TrackMenu();
void AttachedToWindow(void); void AttachedToWindow();
void MessageReceived(BMessage *msg); void MessageReceived(BMessage *msg);
void Draw(BRect update); void Draw(BRect update);
void MouseDown(BPoint pt); void MouseDown(BPoint pt);
void MouseUp(BPoint pt); void MouseUp(BPoint pt);
void MouseMoved(BPoint pt, uint32 transit, const BMessage *msg); void MouseMoved(BPoint pt, uint32 transit, const BMessage *msg);
int32 CountItems(void) const { return fCount; } int32 CountItems() const { return fCount; }
void SetItemCount(const int32 &count); void SetItemCount(const int32 &count);
int32 Value(void) const { return fCurrentItem; } int32 Value() const { return fCurrentItem; }
void SetValue(const int32 &value); void SetValue(const int32 &value);
private: private:
int32 ItemAt(const BPoint &pt); int32 ItemAt(const BPoint &pt);
int32 fCurrentItem; int32 fCurrentItem;
@@ -37,4 +36,4 @@ private:
float fFontHeight; float fFontHeight;
}; };
#endif #endif // TRACKMENU_H
+30 -34
View File
@@ -3,13 +3,15 @@
* Distributed under the terms of the MIT license. * Distributed under the terms of the MIT license.
* *
* Author: * Author:
* DarkWyrm <[email protected]> * DarkWyrm, [email protected]
*/ */
#include "TwoStateDrawButton.h" #include "TwoStateDrawButton.h"
TwoStateDrawButton::TwoStateDrawButton(BRect frame, const char *name, BBitmap *upone, TwoStateDrawButton::TwoStateDrawButton(BRect frame, const char *name, BBitmap *upone,
BBitmap *downone, BBitmap *uptwo, BBitmap *downone, BBitmap *uptwo, BBitmap *downtwo, BMessage *msg,
BBitmap *downtwo, BMessage *msg,
const int32 &resize, const int32 &flags) const int32 &resize, const int32 &flags)
: BButton(frame, name, "", msg, resize, flags), : BButton(frame, name, "", msg, resize, flags),
fUpOne(upone), fUpOne(upone),
@@ -25,7 +27,7 @@ TwoStateDrawButton::TwoStateDrawButton(BRect frame, const char *name, BBitmap *u
} }
TwoStateDrawButton::~TwoStateDrawButton(void) TwoStateDrawButton::~TwoStateDrawButton()
{ {
delete fUpOne; delete fUpOne;
delete fDownOne; delete fDownOne;
@@ -37,25 +39,20 @@ TwoStateDrawButton::~TwoStateDrawButton(void)
void void
TwoStateDrawButton::ResizeToPreferred(void) TwoStateDrawButton::ResizeToPreferred()
{ {
if(fUpOne) if (fUpOne)
ResizeTo(fUpOne->Bounds().Width(),fUpOne->Bounds().Height()); ResizeTo(fUpOne->Bounds().Width(), fUpOne->Bounds().Height());
else else if (fDownOne)
if(fDownOne) ResizeTo(fDownOne->Bounds().Width(), fDownOne->Bounds().Height());
ResizeTo(fDownOne->Bounds().Width(),fDownOne->Bounds().Height()); else if (fUpTwo)
else
if(fUpTwo)
ResizeTo(fUpTwo->Bounds().Width(),fUpTwo->Bounds().Height()); ResizeTo(fUpTwo->Bounds().Width(),fUpTwo->Bounds().Height());
else else if (fDownTwo)
if(fDownTwo) ResizeTo(fDownTwo->Bounds().Width(), fDownTwo->Bounds().Height());
ResizeTo(fDownTwo->Bounds().Width(),fDownTwo->Bounds().Height()); else if (fDisabledOne)
else ResizeTo(fDisabledOne->Bounds().Width(), fDisabledOne->Bounds().Height());
if(fDisabledOne) else if(fDisabledTwo)
ResizeTo(fDisabledOne->Bounds().Width(),fDisabledOne->Bounds().Height()); ResizeTo(fDisabledTwo->Bounds().Width(), fDisabledTwo->Bounds().Height());
else
if(fDisabledTwo)
ResizeTo(fDisabledTwo->Bounds().Width(),fDisabledTwo->Bounds().Height());
} }
@@ -115,7 +112,7 @@ TwoStateDrawButton::MouseUp(BPoint pt)
void void
TwoStateDrawButton::SetState(int32 value) TwoStateDrawButton::SetState(int32 value)
{ {
if(fButtonState != value) { if (fButtonState != value) {
fButtonState = (value == 0) ? false : true; fButtonState = (value == 0) ? false : true;
Invalidate(); Invalidate();
} }
@@ -125,46 +122,45 @@ TwoStateDrawButton::SetState(int32 value)
void void
TwoStateDrawButton::Draw(BRect update) TwoStateDrawButton::Draw(BRect update)
{ {
if(fButtonState) { if (fButtonState) {
if(!IsEnabled()) { if (!IsEnabled()) {
if(fDisabledTwo) if (fDisabledTwo)
DrawBitmap(fDisabledTwo, BPoint(0,0)); DrawBitmap(fDisabledTwo, BPoint(0,0));
else else
StrokeRect(Bounds()); StrokeRect(Bounds());
return; return;
} }
if(Value() == B_CONTROL_ON) { if (Value() == B_CONTROL_ON) {
if(fDownTwo) if (fDownTwo)
DrawBitmap(fDownTwo, BPoint(0,0)); DrawBitmap(fDownTwo, BPoint(0,0));
else else
StrokeRect(Bounds()); StrokeRect(Bounds());
} else { } else {
if(fUpTwo) if (fUpTwo)
DrawBitmap(fUpTwo, BPoint(0,0)); DrawBitmap(fUpTwo, BPoint(0,0));
else else
StrokeRect(Bounds()); StrokeRect(Bounds());
} }
} else { } else {
if(!IsEnabled()) { if (!IsEnabled()) {
if(fDisabledOne) if (fDisabledOne)
DrawBitmap(fDisabledOne, BPoint(0,0)); DrawBitmap(fDisabledOne, BPoint(0,0));
else else
StrokeRect(Bounds()); StrokeRect(Bounds());
return; return;
} }
if(Value() == B_CONTROL_ON) { if (Value() == B_CONTROL_ON) {
if(fDownOne) if (fDownOne)
DrawBitmap(fDownOne, BPoint(0,0)); DrawBitmap(fDownOne, BPoint(0,0));
else else
StrokeRect(Bounds()); StrokeRect(Bounds());
} else { } else {
if(fUpOne) if (fUpOne)
DrawBitmap(fUpOne, BPoint(0,0)); DrawBitmap(fUpOne, BPoint(0,0));
else else
StrokeRect(Bounds()); StrokeRect(Bounds());
} }
} }
} }
+14 -14
View File
@@ -8,35 +8,35 @@
#ifndef _TWOSTATE_DRAWBUTTON_H #ifndef _TWOSTATE_DRAWBUTTON_H
#define _TWOSTATE_DRAWBUTTON_H #define _TWOSTATE_DRAWBUTTON_H
#include <Window.h>
#include <View.h>
#include <Bitmap.h> #include <Bitmap.h>
#include <Button.h> #include <Button.h>
#include <View.h>
#include <Window.h>
class TwoStateDrawButton : public BButton class TwoStateDrawButton : public BButton {
{ public:
public:
TwoStateDrawButton(BRect frame, const char *name, BBitmap *upone, TwoStateDrawButton(BRect frame, const char *name, BBitmap *upone,
BBitmap *downone, BBitmap *uptwo, BBitmap *downtwo, BBitmap *downone, BBitmap *uptwo, BBitmap *downtwo,
BMessage *msg, const int32 &resize, BMessage *msg, const int32 &resize, const int32 &flags);
const int32 &flags);
~TwoStateDrawButton(void); ~TwoStateDrawButton();
void Draw(BRect update); void Draw(BRect update);
void SetBitmaps(BBitmap *upone, BBitmap *downone, BBitmap *uptwo, void SetBitmaps(BBitmap *upone, BBitmap *downone, BBitmap *uptwo,
BBitmap *downtwo); BBitmap *downtwo);
void SetBitmaps(const int32 state, BBitmap *up, BBitmap *down); void SetBitmaps(const int32 state, BBitmap *up, BBitmap *down);
void ResizeToPreferred(void); void ResizeToPreferred();
void SetDisabled(BBitmap *disabledone, BBitmap *disabledtwo); void SetDisabled(BBitmap *disabledone, BBitmap *disabledtwo);
void MouseUp(BPoint pt); void MouseUp(BPoint pt);
int32 GetState(void) { return fButtonState ? 1 : 0; }; int32 GetState() { return fButtonState ? 1 : 0; };
void SetState(int32 value); void SetState(int32 value);
private: private:
BBitmap *fUpOne, BBitmap *fUpOne,
*fDownOne, *fDownOne,
*fUpTwo, *fUpTwo,
@@ -44,8 +44,8 @@ private:
*fDisabledOne, *fDisabledOne,
*fDisabledTwo; *fDisabledTwo;
// true if in state two
bool fButtonState; bool fButtonState;
// true if in state two
}; };
#endif #endif // _TWOSTATE_DRAWBUTTON_H