From e88a0a107774a5e4493b5ba5f33a4e5396f414e5 Mon Sep 17 00:00:00 2001 From: casey Date: Mon, 27 Jun 2016 21:22:33 -0700 Subject: [PATCH] - Fixed bug where sometimes list wasn't reset when changing categories - Updated Colors.cpp to use custom colors where available. --- src/musikbox/Main.cpp | 4 +- src/musikbox/app/layout/BrowseLayout.cpp | 6 +- src/musikbox/app/layout/ConsoleLayout.cpp | 8 +-- src/musikbox/app/layout/IndexerLayout.cpp | 8 +-- src/musikbox/app/layout/SearchLayout.cpp | 2 +- src/musikbox/app/layout/TrackSearchLayout.cpp | 2 +- src/musikbox/app/window/CategoryListView.cpp | 8 +-- src/musikbox/app/window/LogWindow.cpp | 8 +-- src/musikbox/app/window/OutputWindow.cpp | 2 +- src/musikbox/app/window/TrackListView.cpp | 11 ++-- src/musikbox/app/window/TransportWindow.cpp | 8 +-- src/musikbox/cursespp/Checkbox.cpp | 2 +- src/musikbox/cursespp/Colors.cpp | 55 ++++++++++++++----- src/musikbox/cursespp/Colors.h | 26 ++++----- src/musikbox/cursespp/LayoutBase.cpp | 4 +- 15 files changed, 91 insertions(+), 63 deletions(-) diff --git a/src/musikbox/Main.cpp b/src/musikbox/Main.cpp index 92c498e25..dad25ebc8 100644 --- a/src/musikbox/Main.cpp +++ b/src/musikbox/Main.cpp @@ -243,8 +243,6 @@ int main(int argc, char* argv[]) cbreak(); noecho(); keypad(stdscr, TRUE); - start_color(); - use_default_colors(); refresh(); curs_set(0); @@ -303,7 +301,7 @@ int main(int argc, char* argv[]) else if (kn == "^D") { /* ctrl+d quits */ quit = true; } - else if (kn == "ALT_R" || kn == "M-r") { + else if (kn == "M-r") { Window::Invalidate(); } else if (kn == "KEY_RESIZE") { diff --git a/src/musikbox/app/layout/BrowseLayout.cpp b/src/musikbox/app/layout/BrowseLayout.cpp index cb7f0dc8f..3f8b556dd 100755 --- a/src/musikbox/app/layout/BrowseLayout.cpp +++ b/src/musikbox/app/layout/BrowseLayout.cpp @@ -159,15 +159,15 @@ bool BrowseLayout::KeyPress(const std::string& key) { this->categoryList->Requery(); return true; } - else if (key == "ALT_1" || key == "M-1") { + else if (key == "M-1") { this->categoryList->SetFieldName(constants::Track::ARTIST); return true; } - else if (key == "ALT_2" || key == "M-2") { + else if (key == "M-2") { this->categoryList->SetFieldName(constants::Track::ALBUM); return true; } - else if (key == "ALT_3" || key == "M-3") { + else if (key == "M-3") { this->categoryList->SetFieldName(constants::Track::GENRE); return true; } diff --git a/src/musikbox/app/layout/ConsoleLayout.cpp b/src/musikbox/app/layout/ConsoleLayout.cpp index 19f4561dc..933aa1784 100755 --- a/src/musikbox/app/layout/ConsoleLayout.cpp +++ b/src/musikbox/app/layout/ConsoleLayout.cpp @@ -72,7 +72,7 @@ ConsoleLayout::ConsoleLayout(ITransport& transport, LibraryPtr library) this->AddWindow(this->output); this->AddWindow(this->resources); - this->commands->SetContentColor(BOX_COLOR_WHITE_ON_BLACK); + this->commands->SetContentColor(CURSESPP_WHITE_ON_TRANSPARENT); this->commands->EnterPressed.connect(this, &ConsoleLayout::OnEnterPressed); this->Help(); @@ -133,14 +133,14 @@ void ConsoleLayout::OnEnterPressed(TextInput *input) { std::string command = this->commands->GetText(); this->commands->SetText(""); - output->WriteLine("> " + command + "\n", COLOR_PAIR(BOX_COLOR_BLACK_ON_GREY)); + output->WriteLine("> " + command + "\n", COLOR_PAIR(CURSESPP_BLACK_ON_GREY)); if (!this->ProcessCommand(command)) { if (command.size()) { output->WriteLine( "illegal command: '" + command + - "'\n", COLOR_PAIR(BOX_COLOR_RED_ON_GREY)); + "'\n", COLOR_PAIR(CURSESPP_RED_ON_GREY)); } } } @@ -311,6 +311,6 @@ void ConsoleLayout::ListPlugins() const { "v" + std::string((*it)->Version()) + "\n" " by " + std::string((*it)->Author()) + "\n"; - this->output->WriteLine(format, BOX_COLOR_RED_ON_BLUE); + this->output->WriteLine(format, CURSESPP_RED_ON_BLUE); } } diff --git a/src/musikbox/app/layout/IndexerLayout.cpp b/src/musikbox/app/layout/IndexerLayout.cpp index 412ec985a..f100439ea 100755 --- a/src/musikbox/app/layout/IndexerLayout.cpp +++ b/src/musikbox/app/layout/IndexerLayout.cpp @@ -136,14 +136,14 @@ int64 IndexerLayout::ListItemDecorator( { ListWindow* lw = static_cast(scrollable); if (lw->GetSelectedIndex() == index) { - return COLOR_PAIR(BOX_COLOR_BLACK_ON_GREEN); + return COLOR_PAIR(CURSESPP_BLACK_ON_GREEN); } } return -1; } void IndexerLayout::InitializeWindows() { - this->SetContentColor(BOX_COLOR_WHITE_ON_BLACK); + this->SetContentColor(CURSESPP_WHITE_ON_TRANSPARENT); this->title.reset(new TextLabel()); this->title->SetText("settings", TextLabel::AlignCenter); @@ -155,9 +155,9 @@ void IndexerLayout::InitializeWindows() { this->addedPathsLabel->SetText("indexed paths (BACKSPACE to remove)", TextLabel::AlignLeft); this->addedPathsList.reset(new cursespp::ListWindow(&this->addedPathsAdapter)); - this->addedPathsList->SetContentColor(BOX_COLOR_WHITE_ON_BLACK); + this->addedPathsList->SetContentColor(CURSESPP_WHITE_ON_TRANSPARENT); this->browseList.reset(new cursespp::ListWindow(&this->browseAdapter)); - this->browseList->SetContentColor(BOX_COLOR_WHITE_ON_BLACK); + this->browseList->SetContentColor(CURSESPP_WHITE_ON_TRANSPARENT); ScrollAdapterBase::ItemDecorator decorator = std::bind( diff --git a/src/musikbox/app/layout/SearchLayout.cpp b/src/musikbox/app/layout/SearchLayout.cpp index de2cb02dd..2a14fc6ef 100755 --- a/src/musikbox/app/layout/SearchLayout.cpp +++ b/src/musikbox/app/layout/SearchLayout.cpp @@ -105,7 +105,7 @@ void SearchLayout::Layout() { void SearchLayout::InitializeWindows(PlaybackService& playback) { this->input.reset(new cursespp::TextInput()); this->input->TextChanged.connect(this, &SearchLayout::OnInputChanged); - this->input->SetContentColor(BOX_COLOR_WHITE_ON_BLACK); + this->input->SetContentColor(CURSESPP_WHITE_ON_TRANSPARENT); this->input->SetFocusOrder(0); this->AddWindow(this->input); diff --git a/src/musikbox/app/layout/TrackSearchLayout.cpp b/src/musikbox/app/layout/TrackSearchLayout.cpp index 47a8d61d1..dff21a740 100755 --- a/src/musikbox/app/layout/TrackSearchLayout.cpp +++ b/src/musikbox/app/layout/TrackSearchLayout.cpp @@ -93,7 +93,7 @@ void TrackSearchLayout::Layout() { void TrackSearchLayout::InitializeWindows() { this->input.reset(new cursespp::TextInput()); this->input->TextChanged.connect(this, &TrackSearchLayout::OnInputChanged); - this->input->SetContentColor(BOX_COLOR_WHITE_ON_BLACK); + this->input->SetContentColor(CURSESPP_WHITE_ON_TRANSPARENT); this->input->SetFocusOrder(0); this->AddWindow(this->input); diff --git a/src/musikbox/app/window/CategoryListView.cpp b/src/musikbox/app/window/CategoryListView.cpp index 22b25d6c7..ffb4e4075 100755 --- a/src/musikbox/app/window/CategoryListView.cpp +++ b/src/musikbox/app/window/CategoryListView.cpp @@ -62,7 +62,7 @@ CategoryListView::CategoryListView( const std::string& fieldName) : ListWindow(NULL) , playback(playback) { - this->SetContentColor(BOX_COLOR_WHITE_ON_BLACK); + this->SetContentColor(CURSESPP_WHITE_ON_TRANSPARENT); this->selectAfterQuery = 0; this->library = library; this->library->QueryCompleted.connect(this, &CategoryListView::OnQueryCompleted); @@ -207,14 +207,14 @@ IScrollAdapter::EntryPtr CategoryListView::Adapter::GetEntry(size_t index) { bool selected = index == parent.GetSelectedIndex(); - int64 attrs = selected ? COLOR_PAIR(BOX_COLOR_BLACK_ON_GREEN) : -1LL; + int64 attrs = selected ? COLOR_PAIR(CURSESPP_BLACK_ON_GREEN) : -1LL; if (playing) { if (selected) { - attrs = COLOR_PAIR(BOX_COLOR_BLACK_ON_YELLOW); + attrs = COLOR_PAIR(CURSESPP_BLACK_ON_YELLOW); } else { - attrs = COLOR_PAIR(BOX_COLOR_YELLOW_ON_BLACK) | A_BOLD; + attrs = COLOR_PAIR(CURSESPP_YELLOW_ON_TRANSPARENT) | A_BOLD; } } diff --git a/src/musikbox/app/window/LogWindow.cpp b/src/musikbox/app/window/LogWindow.cpp index 3b67da363..c5abd1371 100755 --- a/src/musikbox/app/window/LogWindow.cpp +++ b/src/musikbox/app/window/LogWindow.cpp @@ -47,7 +47,7 @@ typedef IScrollAdapter::IEntry IEntry; LogWindow::LogWindow(IWindow *parent) : ScrollableWindow(parent) { - this->SetContentColor(BOX_COLOR_WHITE_ON_BLACK); + this->SetContentColor(CURSESPP_WHITE_ON_TRANSPARENT); this->adapter = new SimpleScrollAdapter(); this->adapter->SetMaxEntries(500); @@ -78,18 +78,18 @@ void LogWindow::Update() { WINDOW* contents = this->GetContent(); for (size_t i = 0; i < pending.size(); i++) { - int64 attrs = COLOR_PAIR(BOX_COLOR_WHITE_ON_BLACK); + int64 attrs = COLOR_PAIR(CURSESPP_WHITE_ON_TRANSPARENT); LogEntry* entry = pending[i]; switch (entry->level) { case musik::debug::level_error: { - attrs = COLOR_PAIR(BOX_COLOR_RED_ON_BLACK) | A_BOLD; + attrs = COLOR_PAIR(CURSESPP_RED_ON_TRANSPARENT) | A_BOLD; break; } case musik::debug::level_warning: { - attrs = COLOR_PAIR(BOX_COLOR_YELLOW_ON_BLACK) | A_BOLD; + attrs = COLOR_PAIR(CURSESPP_YELLOW_ON_TRANSPARENT) | A_BOLD; break; } } diff --git a/src/musikbox/app/window/OutputWindow.cpp b/src/musikbox/app/window/OutputWindow.cpp index 8281613ea..3c5d17315 100755 --- a/src/musikbox/app/window/OutputWindow.cpp +++ b/src/musikbox/app/window/OutputWindow.cpp @@ -47,7 +47,7 @@ typedef IScrollAdapter::EntryPtr EntryPtr; OutputWindow::OutputWindow(IWindow *parent) : ScrollableWindow(parent) { - this->SetContentColor(BOX_COLOR_BLACK_ON_GREY); + this->SetContentColor(CURSESPP_BLACK_ON_GREY); this->adapter = new SimpleScrollAdapter(); this->adapter->SetDisplaySize(this->GetContentWidth(), this->GetContentHeight()); this->adapter->SetMaxEntries(500); diff --git a/src/musikbox/app/window/TrackListView.cpp b/src/musikbox/app/window/TrackListView.cpp index f960afdef..04eda654f 100755 --- a/src/musikbox/app/window/TrackListView.cpp +++ b/src/musikbox/app/window/TrackListView.cpp @@ -67,7 +67,7 @@ using std::setiosflags; TrackListView::TrackListView(PlaybackService& playback, LibraryPtr library) : ListWindow(NULL) , playback(playback) { - this->SetContentColor(BOX_COLOR_WHITE_ON_BLACK); + this->SetContentColor(CURSESPP_WHITE_ON_TRANSPARENT); this->library = library; this->library->QueryCompleted.connect(this, &TrackListView::OnQueryCompleted); this->playback.TrackChanged.connect(this, &TrackListView::OnTrackChanged); @@ -111,6 +111,7 @@ void TrackListView::ProcessMessage(IMessage &message) { mess with the selected index */ if (this->lastQueryHash != query->GetQueryHash()) { this->SetSelectedIndex(0); + this->ScrollToTop(); } this->lastQueryHash = this->query->GetQueryHash(); @@ -153,7 +154,7 @@ constants) */ IScrollAdapter::EntryPtr TrackListView::Adapter::GetEntry(size_t index) { bool selected = index == parent.GetSelectedIndex(); - int64 attrs = selected ? COLOR_PAIR(BOX_COLOR_BLACK_ON_GREEN) : -1LL; + int64 attrs = selected ? COLOR_PAIR(CURSESPP_BLACK_ON_GREEN) : -1LL; TrackPtr track = parent.metadata->Get(index); @@ -163,10 +164,10 @@ IScrollAdapter::EntryPtr TrackListView::Adapter::GetEntry(size_t index) { playing->LibraryId() == track->LibraryId()) { if (selected) { - attrs = COLOR_PAIR(BOX_COLOR_BLACK_ON_YELLOW); + attrs = COLOR_PAIR(CURSESPP_BLACK_ON_YELLOW); } else { - attrs = COLOR_PAIR(BOX_COLOR_YELLOW_ON_BLACK) | A_BOLD; + attrs = COLOR_PAIR(CURSESPP_YELLOW_ON_TRANSPARENT) | A_BOLD; } } @@ -207,7 +208,7 @@ IScrollAdapter::EntryPtr TrackListView::Adapter::GetEntry(size_t index) { if (this->parent.headers->find(index) != this->parent.headers->end()) { std::string album = track->GetValue(constants::Track::ALBUM); std::shared_ptr entry(new EntryWithHeader(album, text)); - entry->SetAttrs(COLOR_PAIR(BOX_COLOR_GREEN_ON_BLACK), attrs); + entry->SetAttrs(COLOR_PAIR(CURSESPP_GREEN_ON_TRANSPARENT), attrs); return entry; } else { diff --git a/src/musikbox/app/window/TransportWindow.cpp b/src/musikbox/app/window/TransportWindow.cpp index 36a391e97..c428602fe 100755 --- a/src/musikbox/app/window/TransportWindow.cpp +++ b/src/musikbox/app/window/TransportWindow.cpp @@ -130,7 +130,7 @@ size_t writePlayingFormat( TokenList tokens; tokenize(playingFormat, tokens); - int64 gb = COLOR_PAIR(BOX_COLOR_GREEN_ON_BLACK); + int64 gb = COLOR_PAIR(CURSESPP_GREEN_ON_TRANSPARENT); size_t remaining = width; auto it = tokens.begin(); @@ -182,7 +182,7 @@ TransportWindow::TransportWindow(musik::box::PlaybackService& playback) , playback(playback) , transport(playback.GetTransport()) { - this->SetContentColor(BOX_COLOR_WHITE_ON_BLACK); + this->SetContentColor(CURSESPP_WHITE_ON_TRANSPARENT); this->SetFrameVisible(false); this->playback.TrackChanged.connect(this, &TransportWindow::OnPlaybackServiceTrackChanged); this->playback.ModeChanged.connect(this, &TransportWindow::OnPlaybackModeChanged); @@ -241,7 +241,7 @@ void TransportWindow::Update() { bool paused = (transport.GetPlaybackState() == ITransport::PlaybackPaused); bool stopped = (transport.GetPlaybackState() == ITransport::PlaybackStopped); - int64 gb = COLOR_PAIR(BOX_COLOR_GREEN_ON_BLACK); + int64 gb = COLOR_PAIR(CURSESPP_GREEN_ON_TRANSPARENT); /* playing SONG TITLE from ALBUM NAME */ std::string duration = "0"; @@ -326,7 +326,7 @@ void TransportWindow::Update() { system_clock::now().time_since_epoch()).count(); if (now % 2 == 0) { - timerAttrs = COLOR_PAIR(BOX_COLOR_BLACK_ON_BLACK); + timerAttrs = COLOR_PAIR(CURSESPP_BLACK_ON_TRANSPARENT); } } diff --git a/src/musikbox/cursespp/Checkbox.cpp b/src/musikbox/cursespp/Checkbox.cpp index 277dfdf48..ce6f0e741 100755 --- a/src/musikbox/cursespp/Checkbox.cpp +++ b/src/musikbox/cursespp/Checkbox.cpp @@ -98,7 +98,7 @@ void Checkbox::Redraw() { std::string ellipsized = symbol + " " + this->buffer; text::Ellipsize(ellipsized, cx); - int64 attrs = this->focused ? BOX_COLOR_RED_ON_BLACK : -1LL; + int64 attrs = this->focused ? CURSESPP_RED_ON_TRANSPARENT : -1LL; if (attrs != -1) { wattron(c, COLOR_PAIR(attrs)); diff --git a/src/musikbox/cursespp/Colors.cpp b/src/musikbox/cursespp/Colors.cpp index 34377a17b..02ed13140 100755 --- a/src/musikbox/cursespp/Colors.cpp +++ b/src/musikbox/cursespp/Colors.cpp @@ -37,21 +37,50 @@ using namespace cursespp; +static int white = COLOR_WHITE; +static int blue = COLOR_BLUE; +static int red = COLOR_RED; +static int yellow = COLOR_YELLOW; +static int green = COLOR_GREEN; +static int black = COLOR_BLACK; +static int background = -1; + +#define COLOR_CUSTOM_WHITE 9 +#define COLOR_CUSTOM_BLUE 10 +#define COLOR_CUSTOM_RED 11 +#define COLOR_CUSTOM_YELLOW 12 +#define COLOR_CUSTOM_GREEN 13 +#define COLOR_CUSTOM_BLACK 14 + Colors::Colors() { } void Colors::Init() { - init_pair(BOX_COLOR_WHITE_ON_BLUE, COLOR_WHITE, COLOR_BLUE); - init_pair(BOX_COLOR_RED_ON_BLUE, COLOR_RED, COLOR_BLUE); - init_pair(BOX_COLOR_YELLOW_ON_BLUE, COLOR_YELLOW, COLOR_BLUE); - init_pair(BOX_COLOR_BLACK_ON_GREY, COLOR_BLACK, COLOR_WHITE); - init_pair(BOX_COLOR_BLACK_ON_GREEN, COLOR_BLACK, COLOR_GREEN); - init_pair(BOX_COLOR_YELLOW_ON_BLACK, COLOR_YELLOW, -1); - init_pair(BOX_COLOR_WHITE_ON_BLACK, COLOR_WHITE, -1); - init_pair(BOX_COLOR_RED_ON_BLACK, COLOR_RED, -1); - init_pair(BOX_COLOR_RED_ON_GREY, COLOR_RED, COLOR_WHITE); - init_pair(BOX_COLOR_GREEN_ON_BLACK, COLOR_GREEN, -1); - init_pair(BOX_COLOR_BLACK_ON_BLACK, COLOR_BLACK, -1); - init_pair(BOX_COLOR_RED_ON_GREEN, COLOR_RED, COLOR_GREEN); - init_pair(BOX_COLOR_BLACK_ON_YELLOW, COLOR_BLACK, COLOR_YELLOW); + start_color(); + use_default_colors(); + + /* the default colors are a bit harsh for my taste, so + let's use custom colors if the terminal supports it. in + the future we'll allow users to configure this via setting */ + if (COLORS > 8) { + init_color(COLOR_CUSTOM_RED, 1000, 431, 392); + red = COLOR_CUSTOM_RED; + + init_color(COLOR_CUSTOM_GREEN, 373, 980, 392); + green = COLOR_CUSTOM_GREEN; + } + + init_pair(CURSESPP_WHITE_ON_BLUE, white, blue); + init_pair(CURSESPP_RED_ON_BLUE, red, blue); + init_pair(CURSESPP_YELLOW_ON_BLUE, yellow, blue); + init_pair(CURSESPP_BLACK_ON_GREY, black, white); + init_pair(CURSESPP_BLACK_ON_GREEN, black, green); + init_pair(CURSESPP_YELLOW_ON_TRANSPARENT, yellow, background); + init_pair(CURSESPP_WHITE_ON_TRANSPARENT, white, background); + init_pair(CURSESPP_RED_ON_TRANSPARENT, red, background); + init_pair(CURSESPP_RED_ON_GREY, red, white); + init_pair(CURSESPP_GREEN_ON_TRANSPARENT, green, background); + init_pair(CURSESPP_BLACK_ON_TRANSPARENT, black, background); + init_pair(CURSESPP_RED_ON_GREEN, red, green); + init_pair(CURSESPP_BLACK_ON_YELLOW, black, yellow); } diff --git a/src/musikbox/cursespp/Colors.h b/src/musikbox/cursespp/Colors.h index e5e3960ff..b03291151 100755 --- a/src/musikbox/cursespp/Colors.h +++ b/src/musikbox/cursespp/Colors.h @@ -36,19 +36,19 @@ #include "curses_config.h" -#define BOX_COLOR_WHITE_ON_BLUE 1 -#define BOX_COLOR_RED_ON_BLUE 2 -#define BOX_COLOR_YELLOW_ON_BLUE 3 -#define BOX_COLOR_BLACK_ON_GREY 4 -#define BOX_COLOR_BLACK_ON_GREEN 5 -#define BOX_COLOR_YELLOW_ON_BLACK 6 -#define BOX_COLOR_WHITE_ON_BLACK 7 -#define BOX_COLOR_RED_ON_BLACK 8 -#define BOX_COLOR_RED_ON_GREY 9 -#define BOX_COLOR_GREEN_ON_BLACK 10 -#define BOX_COLOR_BLACK_ON_BLACK 11 -#define BOX_COLOR_RED_ON_GREEN 12 -#define BOX_COLOR_BLACK_ON_YELLOW 13 +#define CURSESPP_WHITE_ON_BLUE 1 +#define CURSESPP_RED_ON_BLUE 2 +#define CURSESPP_YELLOW_ON_BLUE 3 +#define CURSESPP_BLACK_ON_GREY 4 +#define CURSESPP_BLACK_ON_GREEN 5 +#define CURSESPP_YELLOW_ON_TRANSPARENT 6 +#define CURSESPP_WHITE_ON_TRANSPARENT 7 +#define CURSESPP_RED_ON_TRANSPARENT 8 +#define CURSESPP_RED_ON_GREY 9 +#define CURSESPP_GREEN_ON_TRANSPARENT 10 +#define CURSESPP_BLACK_ON_TRANSPARENT 11 +#define CURSESPP_RED_ON_GREEN 12 +#define CURSESPP_BLACK_ON_YELLOW 13 namespace cursespp { class Colors { diff --git a/src/musikbox/cursespp/LayoutBase.cpp b/src/musikbox/cursespp/LayoutBase.cpp index 22de1cc79..625fe403f 100755 --- a/src/musikbox/cursespp/LayoutBase.cpp +++ b/src/musikbox/cursespp/LayoutBase.cpp @@ -64,12 +64,12 @@ bool sortByFocusOrder(IWindowPtr a, IWindowPtr b) { static inline IWindowPtr adjustFocus(IWindowPtr oldFocus, IWindowPtr newFocus) { if (oldFocus) { - oldFocus->SetFrameColor(BOX_COLOR_WHITE_ON_BLACK); + oldFocus->SetFrameColor(CURSESPP_WHITE_ON_TRANSPARENT); oldFocus->Blur(); } if (newFocus) { - newFocus->SetFrameColor(BOX_COLOR_RED_ON_BLACK); + newFocus->SetFrameColor(CURSESPP_RED_ON_TRANSPARENT); newFocus->Focus(); }