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

View File

@ -1,5 +1,7 @@
#include "PlayList.h"
#include <OS.h>
#include <stdlib.h>
#include <string.h>
@ -12,34 +14,36 @@
#define STRACE(x) /* nothing */
#endif
PlayList::PlayList(int16 count, int16 start)
: fTrackCount(count),
fTrackIndex(0),
fStartingTrack(start),
fRandom(false),
fLoop(false)
:
fTrackCount(count),
fTrackIndex(0),
fStartingTrack(start),
fRandom(false),
fLoop(false)
{
STRACE(("PlayList(count=%d,start=%d)\n",count,start));
srand(real_time_clock_usecs());
if(fTrackCount < 0)
if (fTrackCount < 0)
fTrackCount = 0;
else
if(fTrackCount > 500)
else if (fTrackCount > 500)
fTrackCount = 500;
if(fStartingTrack >= fTrackCount)
if (fStartingTrack >= fTrackCount)
fStartingTrack = fTrackCount - 1;
if(fStartingTrack < 1)
if (fStartingTrack < 1)
fStartingTrack = 1;
memset(fTrackList,-1,500);
memset(fTrackList, -1, 500);
Unrandomize();
}
void
PlayList::SetTrackCount(const int16 &count)
{
@ -47,23 +51,22 @@ PlayList::SetTrackCount(const int16 &count)
STRACE(("PlayList::SetTrackCount(%d)\n",count));
if(count <= 0)
{
if (count <= 0) {
fTrackCount = 0;
fTrackIndex = 0;
}
else
if(count > 500)
else if (count > 500)
fTrackCount = 500;
else
fTrackCount = count;
memset(fTrackList,-1,500);
memset(fTrackList, -1, 500);
SetShuffle(IsShuffled());
fLocker.Unlock();
}
void
PlayList::SetStartingTrack(const int16 &start)
{
@ -76,8 +79,9 @@ PlayList::SetStartingTrack(const int16 &start)
fLocker.Unlock();
}
void
PlayList::Rewind(void)
PlayList::Rewind()
{
STRACE(("PlayList::Rewind()\n"));
fLocker.Lock();
@ -87,13 +91,14 @@ PlayList::Rewind(void)
fLocker.Unlock();
}
void
PlayList::SetShuffle(const bool &random)
{
STRACE(("PlayList::SetShuffle(%s)\n",random ? "random" : "sequential"));
STRACE(("PlayList::SetShuffle(%s)\n", random ? "random" : "sequential"));
fLocker.Lock();
if(random)
if (random)
Randomize();
else
Unrandomize();
@ -103,69 +108,68 @@ PlayList::SetShuffle(const bool &random)
fLocker.Unlock();
}
void
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();
fLoop = loop;
fLocker.Unlock();
}
void
PlayList::SetCurrentTrack(const int16 &track)
{
STRACE(("PlayList::SetCurrentTrack(%d)\n",track));
if(track < 0 || track > fTrackCount)
if (track < 0 || track > fTrackCount)
return;
fLocker.Lock();
for(int16 i=0; i<fTrackCount; i++)
{
if(fTrackList[i] == track)
{
for (int16 i = 0; i < fTrackCount; i++) {
if (fTrackList[i] == track) {
fTrackIndex = i;
break;
}
}
fLocker.Unlock();
}
int16
PlayList::GetCurrentTrack(void)
PlayList::GetCurrentTrack()
{
fLocker.Lock();
int16 value = fTrackList[fTrackIndex];
// STRACE(("PlayList::GetCurrentTrack()=%d\n",value));
fLocker.Unlock();
return value;
}
int16
PlayList::GetNextTrack(void)
PlayList::GetNextTrack()
{
fLocker.Lock();
if(fTrackCount < 1)
{
if (fTrackCount < 1) {
fLocker.Unlock();
STRACE(("PlayList::GetNextTrack()=-1 (no tracks)\n"));
return -1;
}
if(fTrackIndex > (fTrackCount - fStartingTrack))
{
if(fLoop)
if (fTrackIndex > (fTrackCount - fStartingTrack)) {
if (fLoop)
fTrackIndex = 0;
else
{
else {
fLocker.Unlock();
STRACE(("PlayList::GetNextTrack()=-1 (track index out of range)\n"));
return -1;
@ -181,24 +185,22 @@ PlayList::GetNextTrack(void)
return value;
}
int16
PlayList::GetPreviousTrack(void)
PlayList::GetPreviousTrack()
{
fLocker.Lock();
if(fTrackCount < 1)
{
if (fTrackCount < 1) {
fLocker.Unlock();
STRACE(("PlayList::GetPreviousTrack()=-1 (no tracks)\n"));
return -1;
}
if(fTrackIndex == 0)
{
if(fLoop)
if (fTrackIndex == 0) {
if (fLoop)
fTrackIndex = (fTrackCount - fStartingTrack);
else
{
else {
fLocker.Unlock();
STRACE(("PlayList::GetPreviousTrack()=-1 (track index out of range)\n"));
return -1;
@ -213,18 +215,18 @@ PlayList::GetPreviousTrack(void)
return value;
}
int16
PlayList::GetLastTrack(void)
PlayList::GetLastTrack()
{
fLocker.Lock();
if(fTrackCount < 1)
{
if (fTrackCount < 1) {
fLocker.Unlock();
STRACE(("PlayList::GetLastTrack()=-1 (no tracks)\n"));
return -1;
}
fTrackIndex = fTrackCount - 1;
int16 value = fTrackList[fTrackIndex];
STRACE(("PlayList::GetLastTrack()=%d\n",value));
@ -232,13 +234,13 @@ PlayList::GetLastTrack(void)
return value;
}
int16
PlayList::GetFirstTrack(void)
PlayList::GetFirstTrack()
{
fLocker.Lock();
if(fTrackCount < 1)
{
if (fTrackCount < 1) {
fLocker.Unlock();
STRACE(("PlayList::GetFirstTrack()=-1 (no tracks)\n"));
return -1;
@ -251,47 +253,47 @@ PlayList::GetFirstTrack(void)
return value;
}
void
PlayList::Randomize(void)
PlayList::Randomize()
{
STRACE(("PlayList::Randomize()\n"));
// Reinitialize the count
for(int16 i=fStartingTrack; i<=fTrackCount; i++)
for (int16 i = fStartingTrack; i <= fTrackCount; i++)
fTrackList[i - fStartingTrack] = i;
// There are probably *much* better ways to do this,
// but this is the only one I could think of. :(
int32 listcount = (fTrackCount - fStartingTrack);
int32 swapcount = listcount* 2;
int32 swapcount = listcount * 2;
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
// This way we are sure to not have any duplicates and still have
// all tracks eventually be played.
first = (int16)(listcount * ((float)rand()/RAND_MAX));
second = (int16)(listcount * ((float)rand()/RAND_MAX));
first = (int16)(listcount * ((float)rand() / RAND_MAX));
second = (int16)(listcount * ((float)rand() / RAND_MAX));
temp = fTrackList[first];
fTrackList[first] = fTrackList[second];
fTrackList[second] = temp;
}
#ifdef DEBUG_PLAYLIST
for(int16 i=fStartingTrack; i<=fTrackCount; i++)
printf("\tSlot %d: track %d\n",i,fTrackList[i]);
for (int16 i = fStartingTrack; i <= fTrackCount; i++)
printf("\tSlot %d: track %d\n", i, fTrackList[i]);
#endif
}
void
PlayList::Unrandomize(void)
PlayList::Unrandomize()
{
STRACE(("PlayList::Unrandomize()\n"));
for(int16 i=fStartingTrack; i<=fTrackCount; i++)
for (int16 i = fStartingTrack; i <= fTrackCount; i++)
fTrackList[i - fStartingTrack] = i;
}

View File

@ -1,50 +1,49 @@
#ifndef PLAYLIST_H
#define PLAYLIST_H
#include <SupportDefs.h>
#include <Locker.h>
#include <SupportDefs.h>
class PlayList
{
public:
PlayList(int16 tracks = 0, int16 startingtrack = 1);
void SetTrackCount(const int16 &count);
int16 TrackCount(void) const { return fTrackCount; }
class PlayList {
public:
PlayList(int16 tracks = 0, int16 startingtrack = 1);
void SetStartingTrack(const int16 &start);
int16 StartingTrack(void) const { return fStartingTrack; }
void SetTrackCount(const int16 &count);
int16 TrackCount() const { return fTrackCount; }
void SetStartingTrack(const int16 &start);
int16 StartingTrack() const { return fStartingTrack; }
void Rewind();
void SetShuffle(const bool &random);
bool IsShuffled() const { return fRandom; }
void SetLoop(const bool &loop);
bool IsLoop() const { return fLoop; }
void Rewind(void);
void SetCurrentTrack(const int16 &track);
int16 GetCurrentTrack();
void SetShuffle(const bool &random);
bool IsShuffled(void) const { return fRandom; }
void SetLoop(const bool &loop);
bool IsLoop(void) const { return fLoop; }
void SetCurrentTrack(const int16 &track);
int16 GetCurrentTrack(void);
int16 GetNextTrack(void);
int16 GetPreviousTrack(void);
int16 GetFirstTrack(void);
int16 GetLastTrack(void);
private:
void Randomize(void);
void Unrandomize(void);
int16 fTrackCount;
int16 fTrackIndex;
int16 fStartingTrack;
int16 fTrackList[500]; // This should be big enough. :)
bool fRandom;
bool fLoop;
BLocker fLocker;
int16 GetNextTrack();
int16 GetPreviousTrack();
int16 GetFirstTrack();
int16 GetLastTrack();
private:
void Randomize();
void Unrandomize();
int16 fTrackCount;
int16 fTrackIndex;
int16 fStartingTrack;
int16 fTrackList[500]; // This should be big enough. :)
bool fRandom;
bool fLoop;
BLocker fLocker;
};
#endif
#endif // PLAYLIST_H

View File

@ -1,22 +1,24 @@
#include "TrackMenu.h"
#include <Font.h>
#include <Message.h>
#include <Region.h>
#include <Window.h>
#include <String.h>
#include <Font.h>
#include "TrackMenu.h"
#include <Window.h>
#include <stdio.h>
TrackMenu::TrackMenu(const BRect &frame, const char *name, BMessage *msg,
const int32 &resize, const int32 &flags)
: BView(frame,name,resize,flags),
BInvoker(msg,NULL),
const int32 &resize, const int32 &flags)
: BView(frame, name, resize, flags), BInvoker(msg, NULL),
fCurrentItem(-1),
fCount(0),
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;
font.SetSize(11);
@ -29,254 +31,241 @@ TrackMenu::TrackMenu(const BRect &frame, const char *name, BMessage *msg,
fFontHeight = fh.ascent + fh.descent + fh.leading;
}
TrackMenu::~TrackMenu(void)
TrackMenu::~TrackMenu()
{
}
void
TrackMenu::AttachedToWindow(void)
TrackMenu::AttachedToWindow()
{
if (!Messenger().IsValid())
SetTarget(Window());
BView::AttachedToWindow();
}
void
TrackMenu::MessageReceived(BMessage *msg)
{
switch(msg->what)
{
switch (msg->what) {
default:
{
BView::MessageReceived(msg);
break;
}
}
}
void
TrackMenu::SetItemCount(const int32 &count)
{
if(count < 0)
{
if (count < 0) {
fCount = 0;
fCurrentItem = -1;
Invalidate();
return;
}
fCount = count;
if(fCurrentItem > fCount - 1)
if (fCurrentItem > fCount - 1)
fCurrentItem = fCount - 1;
else
if(fCurrentItem < 0)
else if(fCurrentItem < 0)
fCurrentItem = 0;
Invalidate();
}
void
TrackMenu::SetValue(const int32 &value)
{
if(value < 0 || value > fCount)
if (value < 0 || value > fCount)
return;
if(value != Value())
{
if (value != Value()) {
fCurrentItem = value;
Invalidate();
}
}
int32
TrackMenu::ItemAt(const BPoint &pt)
{
// TODO: Optimize. This is simple, but costly in performance
BRect r(fItemRect);
for(int32 i=0; i<fCount; i++)
{
if(r.Contains(pt))
for (int32 i = 0; i < fCount; i++) {
if (r.Contains(pt))
return i;
r.OffsetBy(r.Width()+1,0);
}
return -1;
}
void
TrackMenu::MouseDown(BPoint point)
{
BPoint pt(point);
int32 saveditem = fCurrentItem;
int32 item = ItemAt(pt);
if(item >= 0)
{
if (item >= 0) {
fCurrentItem = item;
Invalidate();
// 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);
fIsTracking = true;
} else
{
} else {
uint32 buttons;
do
{
do {
Window()->UpdateIfNeeded();
snooze(40000);
GetMouse(&pt, &buttons, true);
int32 mouseitem = ItemAt(pt);
if(mouseitem > -1)
{
if (mouseitem > -1) {
fCurrentItem = mouseitem;
Draw(Bounds());
}
} while (buttons != 0);
if(fCurrentItem != saveditem)
if (fCurrentItem != saveditem)
Invoke();
}
}
}
void
TrackMenu::MouseUp(BPoint pt)
{
if(!fIsTracking)
if (!fIsTracking)
return;
int32 item = ItemAt(pt);
if(item >= 0)
if (item >= 0)
Invoke();
fIsTracking = false;
}
void
TrackMenu::MouseMoved(BPoint pt, uint32 transit, const BMessage *msg)
{
if(!fIsTracking)
if (!fIsTracking)
return;
int32 item = ItemAt(pt);
if(item >= 0)
{
if (item >= 0) {
fCurrentItem = item;
Invalidate();
}
}
void
TrackMenu::Draw(BRect update)
{
rgb_color dark = {20,20,20,255};
rgb_color light = {200,200,200,255};
BPoint pt1,pt2;
rgb_color dark = {20, 20, 20, 255};
rgb_color light = {200, 200, 200, 255};
BPoint pt1, pt2;
// Draw the frame
SetHighColor(dark);
pt1.Set(0,0);
pt1.Set(0, 0);
pt2 = Bounds().RightTop();
StrokeLine(pt1,pt2);
pt2.Set(0,Bounds().bottom);
StrokeLine(pt1,pt2);
StrokeLine(pt1, pt2);
pt2.Set(0, Bounds().bottom);
StrokeLine(pt1, pt2);
SetHighColor(255,255,255);
pt1 = Bounds().RightBottom();
pt2.Set(Bounds().right, 1);
StrokeLine(pt1,pt2);
StrokeLine(pt1, pt2);
pt2.Set(1,Bounds().bottom);
StrokeLine(pt1,pt2);
StrokeLine(pt1, pt2);
// Draw the items
BRect r(fItemRect);
for(int32 i=0; i<fCount; i++)
{
for (int32 i = 0; i < fCount; i++) {
// Draw the item's frame
if(i == fCurrentItem)
if (i == fCurrentItem)
SetHighColor(dark);
else
SetHighColor(light);
pt1.Set(r.left,r.top);
pt2.Set(r.right,r.top);
StrokeLine(pt1,pt2);
pt2.Set(r.left,r.bottom);
StrokeLine(pt1,pt2);
if(i == fCurrentItem)
{
pt1.Set(r.left, r.top);
pt2.Set(r.right, r.top);
StrokeLine(pt1, pt2);
pt2.Set(r.left, r.bottom);
StrokeLine(pt1, pt2);
if (i == fCurrentItem) {
SetHighColor(light);
pt1.Set(r.right,r.bottom);
pt1.Set(r.right, r.bottom);
pt2.Set(r.right, r.top + 1);
StrokeLine(pt1,pt2);
pt2.Set(r.left + 1,r.bottom);
StrokeLine(pt1,pt2);
StrokeLine(pt1, pt2);
pt2.Set(r.left + 1, r.bottom);
StrokeLine(pt1, pt2);
SetHighColor(light);
FillRect(r.InsetByCopy(1,1));
FillRect(r.InsetByCopy(1, 1));
SetHighColor(dark);
}
else
if(i == fCount - 1)
{
else if (i == fCount - 1) {
SetHighColor(light);
pt1.Set(r.right,r.bottom);
pt1.Set(r.right, r.bottom);
pt2.Set(r.right, r.top + 1);
StrokeLine(pt1,pt2);
StrokeLine(pt1, pt2);
}
// Draw the label, center justified
BString label;
label << (i + 1);
BPoint labelpt;
labelpt.x = r.left + (r.Width() - StringWidth(label.String()))/2 + 2;
labelpt.y = r.bottom - (r.Height() - fFontHeight + 4)/2;
if(i == fCurrentItem)
{
labelpt.x = r.left + (r.Width() - StringWidth(label.String())) / 2 + 2;
labelpt.y = r.bottom - (r.Height() - fFontHeight + 4) / 2;
if (i == fCurrentItem) {
SetHighColor(dark);
SetLowColor(light);
}
else
{
} else {
SetHighColor(light);
SetLowColor(dark);
}
DrawString(label.String(),labelpt);
DrawString(label.String(), labelpt);
// Setup for next iteration
r.OffsetBy(r.Width()+1,0);
if(r.left > Bounds().right - 2)
{
r.OffsetBy(r.Width() + 1, 0);
if (r.left > Bounds().right - 2) {
ConstrainClippingRegion(NULL);
break;
}
if(r.right > Bounds().right - 2)
{
if (r.right > Bounds().right - 2) {
r.right = Bounds().right - 2;
BRegion reg(r);
ConstrainClippingRegion(&reg);

View File

@ -1,40 +1,39 @@
#ifndef TRACKMENU_H
#define TRACKMENU_H
#include <View.h>
#include <Invoker.h>
#include <View.h>
class TrackMenu : public BView, public BInvoker
{
public:
TrackMenu(const BRect &frame, const char *name, BMessage *msg,
const int32 &resize = B_FOLLOW_LEFT | B_FOLLOW_TOP,
const int32 &flags = B_WILL_DRAW);
~TrackMenu(void);
class TrackMenu : public BView, public BInvoker {
public:
TrackMenu(const BRect &frame, const char *name, BMessage *msg,
const int32 &resize = B_FOLLOW_LEFT | B_FOLLOW_TOP,
const int32 &flags = B_WILL_DRAW);
~TrackMenu();
void AttachedToWindow(void);
void MessageReceived(BMessage *msg);
void Draw(BRect update);
void MouseDown(BPoint pt);
void MouseUp(BPoint pt);
void MouseMoved(BPoint pt, uint32 transit, const BMessage *msg);
int32 CountItems(void) const { return fCount; }
void SetItemCount(const int32 &count);
int32 Value(void) const { return fCurrentItem; }
void SetValue(const int32 &value);
private:
int32 ItemAt(const BPoint &pt);
int32 fCurrentItem;
int32 fCount;
BRect fItemRect;
bool fIsTracking;
float fFontHeight;
void AttachedToWindow();
void MessageReceived(BMessage *msg);
void Draw(BRect update);
void MouseDown(BPoint pt);
void MouseUp(BPoint pt);
void MouseMoved(BPoint pt, uint32 transit, const BMessage *msg);
int32 CountItems() const { return fCount; }
void SetItemCount(const int32 &count);
int32 Value() const { return fCurrentItem; }
void SetValue(const int32 &value);
private:
int32 ItemAt(const BPoint &pt);
int32 fCurrentItem;
int32 fCount;
BRect fItemRect;
bool fIsTracking;
float fFontHeight;
};
#endif
#endif // TRACKMENU_H

View File

@ -3,15 +3,17 @@
* Distributed under the terms of the MIT license.
*
* Author:
* DarkWyrm <bpmagic@columbus.rr.com>
* DarkWyrm, bpmagic@columbus.rr.com
*/
#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),
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),
@ -25,7 +27,7 @@ TwoStateDrawButton::TwoStateDrawButton(BRect frame, const char *name, BBitmap *u
}
TwoStateDrawButton::~TwoStateDrawButton(void)
TwoStateDrawButton::~TwoStateDrawButton()
{
delete fUpOne;
delete fDownOne;
@ -37,37 +39,32 @@ TwoStateDrawButton::~TwoStateDrawButton(void)
void
TwoStateDrawButton::ResizeToPreferred(void)
TwoStateDrawButton::ResizeToPreferred()
{
if(fUpOne)
ResizeTo(fUpOne->Bounds().Width(),fUpOne->Bounds().Height());
else
if(fDownOne)
ResizeTo(fDownOne->Bounds().Width(),fDownOne->Bounds().Height());
else
if(fUpTwo)
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());
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)
BBitmap *downtwo)
{
delete fUpOne;
delete fDownOne;
delete fUpTwo;
delete fDownTwo;
fUpOne = upone;
fDownOne = downone;
fUpTwo = uptwo;
@ -115,7 +112,7 @@ TwoStateDrawButton::MouseUp(BPoint pt)
void
TwoStateDrawButton::SetState(int32 value)
{
if(fButtonState != value) {
if (fButtonState != value) {
fButtonState = (value == 0) ? false : true;
Invalidate();
}
@ -125,46 +122,45 @@ TwoStateDrawButton::SetState(int32 value)
void
TwoStateDrawButton::Draw(BRect update)
{
if(fButtonState) {
if(!IsEnabled()) {
if(fDisabledTwo)
if (fButtonState) {
if (!IsEnabled()) {
if (fDisabledTwo)
DrawBitmap(fDisabledTwo, BPoint(0,0));
else
StrokeRect(Bounds());
return;
}
if(Value() == B_CONTROL_ON) {
if(fDownTwo)
if (Value() == B_CONTROL_ON) {
if (fDownTwo)
DrawBitmap(fDownTwo, BPoint(0,0));
else
StrokeRect(Bounds());
} else {
if(fUpTwo)
if (fUpTwo)
DrawBitmap(fUpTwo, BPoint(0,0));
else
StrokeRect(Bounds());
}
} else {
if(!IsEnabled()) {
if(fDisabledOne)
if (!IsEnabled()) {
if (fDisabledOne)
DrawBitmap(fDisabledOne, BPoint(0,0));
else
StrokeRect(Bounds());
return;
}
if(Value() == B_CONTROL_ON) {
if(fDownOne)
if (Value() == B_CONTROL_ON) {
if (fDownOne)
DrawBitmap(fDownOne, BPoint(0,0));
else
StrokeRect(Bounds());
} else {
if(fUpOne)
} else {
if (fUpOne)
DrawBitmap(fUpOne, BPoint(0,0));
else
StrokeRect(Bounds());
}
}
}

View File

@ -8,44 +8,44 @@
#ifndef _TWOSTATE_DRAWBUTTON_H
#define _TWOSTATE_DRAWBUTTON_H
#include <Window.h>
#include <View.h>
#include <Bitmap.h>
#include <Button.h>
#include <View.h>
#include <Window.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);
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);
void Draw(BRect update);
~TwoStateDrawButton();
void SetBitmaps(BBitmap *upone, BBitmap *downone, BBitmap *uptwo,
BBitmap *downtwo);
void SetBitmaps(const int32 state, BBitmap *up, BBitmap *down);
void ResizeToPreferred(void);
void SetDisabled(BBitmap *disabledone, BBitmap *disabledtwo);
void MouseUp(BPoint pt);
int32 GetState(void) { return fButtonState ? 1 : 0; };
void SetState(int32 value);
private:
BBitmap *fUpOne,
*fDownOne,
*fUpTwo,
*fDownTwo,
*fDisabledOne,
*fDisabledTwo;
void Draw(BRect update);
void SetBitmaps(BBitmap *upone, BBitmap *downone, BBitmap *uptwo,
BBitmap *downtwo);
void SetBitmaps(const int32 state, BBitmap *up, BBitmap *down);
void ResizeToPreferred();
void SetDisabled(BBitmap *disabledone, BBitmap *disabledtwo);
void MouseUp(BPoint pt);
int32 GetState() { return fButtonState ? 1 : 0; };
void SetState(int32 value);
private:
BBitmap *fUpOne,
*fDownOne,
*fUpTwo,
*fDownTwo,
*fDisabledOne,
*fDisabledTwo;
bool fButtonState;
// true if in state two
bool fButtonState;
};
#endif
#endif // _TWOSTATE_DRAWBUTTON_H