Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Background of the station name now matches the color of the list item #3

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 20 additions & 20 deletions StationListView.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
/*
* File: StationListView.cpp
* Author: user
*
*
* Created on 26.02.2013, 09:22
*/
#include <Application.h>
Expand Down Expand Up @@ -34,25 +34,25 @@ StationListViewItem::~StationListViewItem() {
}

StreamPlayer::PlayState
StationListViewItem::State() {
return (fPlayer) ?
fPlayer->State()
:
StationListViewItem::State() {
return (fPlayer) ?
fPlayer->State()
:
fStation->Flags(STATION_URI_VALID) ?
StreamPlayer::Stopped
:
StreamPlayer::InActive;
}
}

void StationListViewItem::DrawItem(BView* owner, BRect frame, bool complete) {
int index = ((BListView*)owner)->IndexOf(this);
StationListView* ownerList = (StationListView*)owner;
ownerList->SetHighColor(ui_color(IsSelected() ? B_MENU_SELECTION_BACKGROUND_COLOR :
ownerList->SetHighColor(ui_color(IsSelected() ? B_MENU_SELECTION_BACKGROUND_COLOR :
((index % 2) ? B_MENU_BACKGROUND_COLOR : B_DOCUMENT_BACKGROUND_COLOR)));
ownerList->FillRect(frame);

owner->SetHighColor(ui_color(IsSelected() ? B_MENU_SELECTED_ITEM_TEXT_COLOR : B_MENU_ITEM_TEXT_COLOR));
owner->SetLowColor(ui_color(IsSelected() ? B_MENU_SELECTION_BACKGROUND_COLOR : B_MENU_BACKGROUND_COLOR));
owner->SetLowColor(ui_color(IsSelected() ? B_MENU_SELECTION_BACKGROUND_COLOR : ((index % 2) ? B_MENU_BACKGROUND_COLOR : B_DOCUMENT_BACKGROUND_COLOR)));
if (BBitmap* logo = fStation->Logo()) {
BRect target(SLV_INSET, SLV_INSET, SLV_HEIGHT - 2 * SLV_INSET, SLV_HEIGHT - 2 * SLV_INSET);
target.OffsetBy(frame.LeftTop());
Expand All @@ -63,15 +63,15 @@ void StationListViewItem::DrawItem(BView* owner, BRect frame, bool complete) {
owner->GetFontHeight(&fontHeight);
float baseline = SLV_INSET + fontHeight.ascent + fontHeight.leading;
owner->DrawString(fStation->Name()->String(), frame.LeftTop() + BPoint(SLV_HEIGHT - SLV_INSET + SLV_PADDING, SLV_INSET + baseline));

owner->SetFontSize(SLV_SMALL_FONT_SIZE);
owner->GetFontHeight(&fontHeight);
baseline += fontHeight.ascent + fontHeight.descent + fontHeight.leading;
owner->DrawString(fStation->StreamUrl().UrlString(), frame.LeftTop() + BPoint(SLV_HEIGHT - SLV_INSET + SLV_PADDING, baseline));
baseline += fontHeight.ascent + fontHeight.descent + fontHeight.leading;

owner->DrawString(BString("") << fStation->BitRate()/1000.0 << " kbps " << fStation->Mime()->Type(), frame.LeftTop() + BPoint(SLV_HEIGHT - SLV_INSET + SLV_PADDING, baseline));

frame = ownerList->ItemFrame(ownerList->StationIndex(fStation));
if (ownerList->CanPlay() && fStation->Flags(STATION_URI_VALID)) {
BBitmap* bnBitmap = getButtonBitmap(State());
Expand All @@ -81,7 +81,7 @@ void StationListViewItem::DrawItem(BView* owner, BRect frame, bool complete) {
owner->SetDrawingMode(B_OP_COPY);
}
}

}

void StationListViewItem::DrawBufferFillBar(BView* owner, BRect frame) {
Expand All @@ -102,25 +102,25 @@ void StationListViewItem::Update(BView* owner, const BFont* font) {
SetHeight(SLV_HEIGHT);
}

void
void
StationListViewItem::StateChanged(StreamPlayer::PlayState newState) {
if (fList && fList->LockLooperWithTimeout(0) == B_OK) {
fList->InvalidateItem(fList->IndexOf(this));
fList->UnlockLooper();
}
}

BBitmap*
BBitmap*
StationListViewItem::getButtonBitmap(StreamPlayer::PlayState state) {
if (state < 0) return NULL;
if (buttonBitmap[state] == NULL)
if (buttonBitmap[state] == NULL)
buttonBitmap[state] = Utils::ResourceBitmap(RES_BN_STOPPED + state);
return buttonBitmap[state];
}

BBitmap* StationListViewItem::buttonBitmap[3] = { NULL, NULL, NULL };

void
void
StationListViewItem::SetFillRatio(float fillRatio) {
fFillRatio = fillRatio;
if (fList->LockLooperWithTimeout(0) == B_OK) {
Expand All @@ -131,7 +131,7 @@ StationListViewItem::SetFillRatio(float fillRatio) {
}


StationListView::StationListView(bool canPlay)
StationListView::StationListView(bool canPlay)
: BListView("Stations", B_SINGLE_SELECTION_LIST),
fCanPlay(canPlay)
{
Expand All @@ -144,7 +144,7 @@ StationListView::~StationListView() {
delete playMsg;
}

bool
bool
StationListView::AddItem(StationListViewItem* item) {
item->fList = this;
return BListView::AddItem(item);
Expand Down Expand Up @@ -190,7 +190,7 @@ void StationListView::Sync(StationsList* stations) {
delete stationItem;
}
}

for (int32 i = 0; i < stations->CountItems(); i++) {
Station* station = stations->ItemAt(i);
if (Item(station) == NULL) {
Expand Down