- Updated code to use a couple constants (ListWindow::NO_SELECTION and

CURSESPP_DEFAULT_COLOR) instead of a bunch of inline (size_t)-1 and -1LL
  values throughout the code.
- Updated win32 project files.
This commit is contained in:
casey langen 2017-01-25 21:19:29 -08:00
parent 9b7a078348
commit 85eb56b74e
13 changed files with 59 additions and 30 deletions

View File

@ -84,7 +84,11 @@ NowPlayingLayout::~NowPlayingLayout() {
int64 NowPlayingLayout::RowDecorator(musik::core::TrackPtr track, size_t index) {
bool selected = index == trackListView->GetSelectedIndex();
int64 attrs = selected ? COLOR_PAIR(CURSESPP_HIGHLIGHTED_LIST_ITEM) : -1LL;
int64 attrs = selected
? COLOR_PAIR(CURSESPP_HIGHLIGHTED_LIST_ITEM)
: CURSESPP_DEFAULT_COLOR;
size_t playingIndex = playback.GetIndex();
if (index == playingIndex) {
@ -151,7 +155,7 @@ void NowPlayingLayout::OnTrackListRequeried(musik::glue::TrackListQueryBase* que
if (this->reselectIndex == -1) {
size_t index = playback.GetIndex();
if (index == (size_t)-1) { /* not playing? */
if (index == ListWindow::NO_SELECTION) { /* not playing? */
this->trackListView->SetSelectedIndex(0);
this->trackListView->ScrollTo(0);
}
@ -175,7 +179,7 @@ void NowPlayingLayout::OnTrackListRequeried(musik::glue::TrackListQueryBase* que
/* if after a bunch of monkeying around there's still nothing
selected, but we have contents, let's just select the first item */
auto sel = this->trackListView->GetSelectedIndex();
if (sel == (size_t)-1 || sel >= this->trackListView->Count()) {
if (sel == ListWindow::NO_SELECTION || sel >= this->trackListView->Count()) {
this->trackListView->SetSelectedIndex(0);
this->trackListView->ScrollTo(0);
}
@ -201,7 +205,7 @@ void NowPlayingLayout::OnPlaylistQueryStart(std::shared_ptr<musik::glue::TrackLi
bool NowPlayingLayout::KeyPress(const std::string& key) {
if (key == "KEY_ENTER") {
size_t index = this->trackListView->GetSelectedIndex();
if (index != (size_t)-1) {
if (index != ListWindow::NO_SELECTION) {
this->playback.Play(index);
return true;
}

View File

@ -357,7 +357,7 @@ void SettingsLayout::LoadPreferences() {
void SettingsLayout::AddSelectedDirectory() {
size_t index = this->browseList->GetSelectedIndex();
if (index != (size_t) -1) {
if (index != ListWindow::NO_SELECTION) {
std::string path = this->browseAdapter->GetFullPathAt(index);
if (path.size()) {
@ -369,9 +369,9 @@ void SettingsLayout::AddSelectedDirectory() {
void SettingsLayout::RemoveSelectedDirectory() {
std::vector<std::string> paths;
this->indexer->GetPaths(paths);
size_t index = this->addedPathsList->GetSelectedIndex();
if (index > (size_t) -1) {
if (index != ListWindow::NO_SELECTION) {
this->indexer->RemovePath(paths.at(index));
}
}

View File

@ -75,7 +75,7 @@ void PlayQueueOverlays::ShowAddTrackOverlay(
{
size_t selectedIndex = trackList.GetSelectedIndex();
if (selectedIndex == (size_t)-1) {
if (selectedIndex == ListWindow::NO_SELECTION) {
return;
}
@ -96,7 +96,7 @@ void PlayQueueOverlays::ShowAddTrackOverlay(
}
else { /* next */
size_t position = playback.GetIndex();
if (position == (size_t)-1) {
if (position == ListWindow::NO_SELECTION) {
editor.Add(trackId);
}
else {
@ -124,7 +124,7 @@ void PlayQueueOverlays::ShowAddCategoryOverlay(
.SetItemSelectedCallback(
[&playback, library, fieldColumn, fieldId]
(cursespp::IScrollAdapterPtr adapter, size_t index) {
if (index == (size_t)-1) {
if (index == ListWindow::NO_SELECTION) {
return;
}
@ -141,7 +141,7 @@ void PlayQueueOverlays::ShowAddCategoryOverlay(
auto tracks = query->GetResult();
size_t position = playback.GetIndex();
if (index == 0 || position == (size_t)-1) { /* end */
if (index == 0 || position == ListWindow::NO_SELECTION) { /* end */
for (size_t i = 0; i < tracks->Count(); i++) {
editor.Add(tracks->GetId(i));
}
@ -189,7 +189,7 @@ void PlayQueueOverlays::ShowLoadPlaylistOverlay(
.SetItemSelectedCallback(
[&playback, library, result, callback]
(cursespp::IScrollAdapterPtr adapter, size_t index) {
if (index != (size_t) -1 && callback) {
if (index != ListWindow::NO_SELECTION && callback) {
DBID playlistId = (*result)[index]->id;
callback(std::shared_ptr<GetPlaylistQuery>(

View File

@ -69,7 +69,7 @@ CategoryListView::CategoryListView(
this->playback.TrackChanged.connect(this, &CategoryListView::OnTrackChanged);
size_t index = playback.GetIndex();
if (index != (size_t) -1) {
if (index != ListWindow::NO_SELECTION) {
this->playing = playback.GetTrackAtIndex(index);
}
}
@ -219,7 +219,9 @@ IScrollAdapter::EntryPtr CategoryListView::Adapter::GetEntry(cursespp::Scrollabl
bool selected = index == parent.GetSelectedIndex();
int64 attrs = selected ? COLOR_PAIR(CURSESPP_HIGHLIGHTED_LIST_ITEM) : -1LL;
int64 attrs = selected
? COLOR_PAIR(CURSESPP_HIGHLIGHTED_LIST_ITEM)
: CURSESPP_DEFAULT_COLOR;
if (playing) {
if (selected) {

View File

@ -260,14 +260,17 @@ IScrollAdapter::EntryPtr TrackListView::Adapter::GetEntry(cursespp::ScrollableWi
return MISSING_ENTRY;
}
int64 attrs = -1LL;
int64 attrs = CURSESPP_DEFAULT_COLOR;
if (parent.decorator) {
attrs = parent.decorator(track, index);
}
else {
bool selected = index == parent.GetSelectedIndex();
attrs = selected ? COLOR_PAIR(CURSESPP_HIGHLIGHTED_LIST_ITEM) : -1LL;
attrs = selected
? COLOR_PAIR(CURSESPP_HIGHLIGHTED_LIST_ITEM)
: CURSESPP_DEFAULT_COLOR;
TrackPtr playing = parent.playing;
if (playing &&

View File

@ -79,8 +79,8 @@ using namespace cursespp;
this->RemoveMessage(REFRESH_TRANSPORT_READOUT); \
this->PostMessage(REFRESH_TRANSPORT_READOUT, (int64) mode, 0, delay);
#define ON(w, a) if (a != -1LL) { wattron(w, a); }
#define OFF(w, a) if (a != -1LL) { wattroff(w, a); }
#define ON(w, a) if (a != CURSESPP_DEFAULT_COLOR) { wattron(w, a); }
#define OFF(w, a) if (a != CURSESPP_DEFAULT_COLOR) { wattroff(w, a); }
static std::string playingFormat = "playing $title by $artist from $album";
@ -429,7 +429,7 @@ void TransportWindow::Update(TimeMode timeMode) {
int64 gb = COLOR_PAIR(CURSESPP_TEXT_ACTIVE);
int64 disabled = COLOR_PAIR(CURSESPP_TEXT_DISABLED);
int64 volumeAttrs = -1LL;
int64 volumeAttrs = CURSESPP_DEFAULT_COLOR;
if (this->focus == FocusVolume) {
volumeAttrs = COLOR_PAIR(CURSESPP_TEXT_FOCUSED);
}
@ -438,7 +438,7 @@ void TransportWindow::Update(TimeMode timeMode) {
}
int64 timerAttrs = (this->focus == FocusTime)
? COLOR_PAIR(CURSESPP_TEXT_FOCUSED) : -1LL;
? COLOR_PAIR(CURSESPP_TEXT_FOCUSED) : CURSESPP_DEFAULT_COLOR;
/* prepare the "shuffle" label */
@ -491,7 +491,7 @@ void TransportWindow::Update(TimeMode timeMode) {
RepeatMode mode = this->playback.GetRepeatMode();
std::string repeatModeLabel = " repeat ";
int64 repeatAttrs = -1LL;
int64 repeatAttrs = CURSESPP_DEFAULT_COLOR;
switch (mode) {
case RepeatList:
repeatModeLabel += "list";

View File

@ -81,7 +81,7 @@ void Checkbox::OnRedraw() {
std::string symbol = (this->checked ? CHECKED : UNCHECKED);
std::string ellipsized = text::Ellipsize(symbol + " " + this->buffer, cx);
int64 attrs = this->IsFocused() ? CURSESPP_TEXT_FOCUSED : -1LL;
int64 attrs = this->IsFocused() ? CURSESPP_TEXT_FOCUSED : CURSESPP_DEFAULT_COLOR;
if (attrs != -1) {
wattron(c, COLOR_PAIR(attrs));

View File

@ -97,7 +97,7 @@ static bool canChangeColors() {
}
return can_change_color();
#else
return can_change_color();
return !!can_change_color();
#endif
}

View File

@ -79,7 +79,7 @@ EntryPtr SimpleScrollAdapter::GetEntry(cursespp::ScrollableWindow* window, size_
if (window && selectable) {
SingleLineEntry* single = dynamic_cast<SingleLineEntry*>(entry.get());
if (single) {
single->SetAttrs(-1LL);
single->SetAttrs(CURSESPP_DEFAULT_COLOR);
if (index == window->GetScrollPosition().logicalIndex) {
single->SetAttrs(COLOR_PAIR(CURSESPP_HIGHLIGHTED_LIST_ITEM));

View File

@ -65,7 +65,7 @@ void TextLabel::OnRedraw() {
werase(c);
}
attrs = this->IsFocused() ? CURSESPP_TEXT_FOCUSED : -1LL;
attrs = this->IsFocused() ? CURSESPP_TEXT_FOCUSED : CURSESPP_DEFAULT_COLOR;
if (attrs != -1) {
wattron(c, COLOR_PAIR(attrs));

View File

@ -311,27 +311,39 @@ int Window::GetY() const {
}
void Window::SetContentColor(int64 color) {
this->contentColor = (color == -1LL ? CURSESPP_DEFAULT_CONTENT_COLOR : color);
this->contentColor = (color == CURSESPP_DEFAULT_COLOR)
? CURSESPP_DEFAULT_CONTENT_COLOR : color;
this->RepaintBackground();
}
void Window::SetFocusedContentColor(int64 color) {
this->focusedContentColor = (color == -1LL) ? CURSESPP_DEFAULT_CONTENT_COLOR : color;
this->focusedContentColor = (color == CURSESPP_DEFAULT_COLOR)
? CURSESPP_DEFAULT_CONTENT_COLOR : color;
this->RepaintBackground();
}
void Window::SetFrameColor(int64 color) {
this->frameColor = (color == -1LL ? CURSESPP_DEFAULT_FRAME_COLOR : color);
this->frameColor = (color == CURSESPP_DEFAULT_COLOR)
? CURSESPP_DEFAULT_FRAME_COLOR : color;
this->RepaintBackground();
}
void Window::SetFocusedFrameColor(int64 color) {
this->focusedFrameColor = (color == -1LL) ? CURSESPP_FOCUSED_FRAME_COLOR : color;
this->focusedFrameColor = (color == CURSESPP_DEFAULT_COLOR)
? CURSESPP_FOCUSED_FRAME_COLOR : color;
this->RepaintBackground();
}
void Window::RepaintBackground() {
if (this->drawFrame && this->frameColor != -1LL && this->frame && this->content != this->frame) {
if (this->drawFrame &&
this->frameColor != CURSESPP_DEFAULT_COLOR &&
this->frame &&
this->content != this->frame)
{
wbkgd(this->frame, COLOR_PAIR(IsFocused()
? this->focusedFrameColor : this->frameColor));
}

View File

@ -148,6 +148,7 @@
<ClCompile Include="cursespp\Checkbox.cpp" />
<ClCompile Include="cursespp\Colors.cpp" />
<ClCompile Include="cursespp\DialogOverlay.cpp" />
<ClCompile Include="cursespp\InputOverlay.cpp" />
<ClCompile Include="cursespp\LayoutBase.cpp" />
<ClCompile Include="cursespp\ListOverlay.cpp" />
<ClCompile Include="cursespp\ListWindow.cpp" />
@ -203,6 +204,7 @@
<ClInclude Include="cursespp\IInput.h" />
<ClInclude Include="cursespp\IKeyHandler.h" />
<ClInclude Include="cursespp\ILayout.h" />
<ClInclude Include="cursespp\InputOverlay.h" />
<ClInclude Include="cursespp\IOrderable.h" />
<ClInclude Include="cursespp\IOverlay.h" />
<ClInclude Include="cursespp\IScrollable.h" />

View File

@ -126,6 +126,9 @@
<ClCompile Include="app\overlay\PlayQueueOverlays.cpp">
<Filter>app\overlay</Filter>
</ClCompile>
<ClCompile Include="cursespp\InputOverlay.cpp">
<Filter>cursespp</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="stdafx.h" />
@ -297,6 +300,9 @@
<ClInclude Include="app\overlay\PlayQueueOverlays.h">
<Filter>app\overlay</Filter>
</ClInclude>
<ClInclude Include="cursespp\InputOverlay.h">
<Filter>cursespp</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<Filter Include="cursespp">