mirror of
https://github.com/clangen/musikcube.git
synced 2024-10-02 13:02:35 +00:00
Added an option to enable/disable 256 color mode in *nix and macOS
platforms with a dialog explaining the tradeoffs.
This commit is contained in:
parent
3d7f36a975
commit
3c4e1002d1
@ -78,6 +78,12 @@ using namespace musik::core::db::local;
|
|||||||
using namespace musik::box;
|
using namespace musik::box;
|
||||||
using namespace cursespp;
|
using namespace cursespp;
|
||||||
|
|
||||||
|
#ifdef WIN32
|
||||||
|
#define DEFAULT_COLOR_MODE Colors::RGB
|
||||||
|
#else
|
||||||
|
#define DEFAULT_COLOR_MODE Colors::Palette
|
||||||
|
#endif
|
||||||
|
|
||||||
#define MIN_WIDTH 48
|
#define MIN_WIDTH 48
|
||||||
#define MIN_HEIGHT 12
|
#define MIN_HEIGHT 12
|
||||||
|
|
||||||
@ -137,13 +143,25 @@ int main(int argc, char* argv[])
|
|||||||
auto prefs = Preferences::ForComponent(
|
auto prefs = Preferences::ForComponent(
|
||||||
musik::core::prefs::components::Settings);
|
musik::core::prefs::components::Settings);
|
||||||
|
|
||||||
app.SetCustomColorsDisabled(prefs->GetBool(
|
/* set color mode (basic, palette, rgb) */
|
||||||
musik::box::prefs::keys::DisableCustomColors.c_str(), false));
|
Colors::Mode colorMode = DEFAULT_COLOR_MODE;
|
||||||
|
|
||||||
std::string theme = prefs->GetString(musik::box::prefs::keys::ColorTheme);
|
if (prefs->GetBool(musik::box::prefs::keys::DisableCustomColors.c_str(), false)) {
|
||||||
if (theme.size()) {
|
colorMode = Colors::Basic;
|
||||||
theme = GetApplicationDirectory() + "/themes/" + theme + ".json";
|
}
|
||||||
app.SetColorTheme(theme);
|
#ifndef WIN32
|
||||||
|
else if (prefs->GetBool(musik::box::prefs::keys::UsePaletteColors.c_str(), true)) {
|
||||||
|
colorMode = Colors::Palette;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
app.SetColorMode(colorMode);
|
||||||
|
|
||||||
|
/* set color theme */
|
||||||
|
std::string colorTheme = prefs->GetString(musik::box::prefs::keys::ColorTheme);
|
||||||
|
if (colorTheme.size()) {
|
||||||
|
colorTheme = GetApplicationDirectory() + "/themes/" + colorTheme + ".json";
|
||||||
|
app.SetColorTheme(colorTheme);
|
||||||
}
|
}
|
||||||
|
|
||||||
app.SetMinimumSize(MIN_WIDTH, MIN_HEIGHT);
|
app.SetMinimumSize(MIN_WIDTH, MIN_HEIGHT);
|
||||||
|
@ -66,6 +66,10 @@ using namespace musik::glue::audio;
|
|||||||
using namespace cursespp;
|
using namespace cursespp;
|
||||||
using namespace std::placeholders;
|
using namespace std::placeholders;
|
||||||
|
|
||||||
|
#ifndef WIN32
|
||||||
|
#define ENABLE_256_COLOR_OPTION
|
||||||
|
#endif
|
||||||
|
|
||||||
#define LABEL_HEIGHT 1
|
#define LABEL_HEIGHT 1
|
||||||
#define INPUT_HEIGHT 3
|
#define INPUT_HEIGHT 3
|
||||||
#define HOTKEY_INPUT_WIDTH 20
|
#define HOTKEY_INPUT_WIDTH 20
|
||||||
@ -116,6 +120,13 @@ void SettingsLayout::OnCheckboxChanged(cursespp::Checkbox* cb, bool checked) {
|
|||||||
this->browseAdapter->SetDotfilesVisible(showDotfiles);
|
this->browseAdapter->SetDotfilesVisible(showDotfiles);
|
||||||
this->browseList->OnAdapterChanged();
|
this->browseList->OnAdapterChanged();
|
||||||
}
|
}
|
||||||
|
#ifdef ENABLE_256_COLOR_OPTION
|
||||||
|
else if (cb == paletteCheckbox.get()) {
|
||||||
|
this->libraryPrefs->SetBool(box::prefs::keys::UsePaletteColors, checked);
|
||||||
|
this->libraryPrefs->Save();
|
||||||
|
ColorThemeOverlay::Show256ColorsInfo(checked);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
void SettingsLayout::OnOutputDropdownActivated(cursespp::TextLabel* label) {
|
void SettingsLayout::OnOutputDropdownActivated(cursespp::TextLabel* label) {
|
||||||
@ -188,6 +199,9 @@ void SettingsLayout::OnLayout() {
|
|||||||
this->transportDropdown->MoveAndResize(1, y++, cx - 1, LABEL_HEIGHT);
|
this->transportDropdown->MoveAndResize(1, y++, cx - 1, LABEL_HEIGHT);
|
||||||
this->pluginsDropdown->MoveAndResize(1, y++, cx - 1, LABEL_HEIGHT);
|
this->pluginsDropdown->MoveAndResize(1, y++, cx - 1, LABEL_HEIGHT);
|
||||||
this->themeDropdown->MoveAndResize(1, y++, cx - 1, LABEL_HEIGHT);
|
this->themeDropdown->MoveAndResize(1, y++, cx - 1, LABEL_HEIGHT);
|
||||||
|
#ifdef ENABLE_256_COLOR_OPTION
|
||||||
|
this->paletteCheckbox->MoveAndResize(1, y++, cx - 1, LABEL_HEIGHT);
|
||||||
|
#endif
|
||||||
this->hotkeyDropdown->MoveAndResize(1, y++, cx - 1, LABEL_HEIGHT);
|
this->hotkeyDropdown->MoveAndResize(1, y++, cx - 1, LABEL_HEIGHT);
|
||||||
this->dotfileCheckbox->MoveAndResize(1, y++, cx - 1, LABEL_HEIGHT);
|
this->dotfileCheckbox->MoveAndResize(1, y++, cx - 1, LABEL_HEIGHT);
|
||||||
this->syncOnStartupCheckbox->MoveAndResize(1, y++, cx - 1, LABEL_HEIGHT);
|
this->syncOnStartupCheckbox->MoveAndResize(1, y++, cx - 1, LABEL_HEIGHT);
|
||||||
@ -263,6 +277,9 @@ void SettingsLayout::InitializeWindows() {
|
|||||||
this->themeDropdown.reset(new TextLabel());
|
this->themeDropdown.reset(new TextLabel());
|
||||||
this->themeDropdown->SetText(arrow + " color theme: default");
|
this->themeDropdown->SetText(arrow + " color theme: default");
|
||||||
this->themeDropdown->Activated.connect(this, &SettingsLayout::OnThemeDropdownActivate);
|
this->themeDropdown->Activated.connect(this, &SettingsLayout::OnThemeDropdownActivate);
|
||||||
|
#ifdef ENABLE_256_COLOR_OPTION
|
||||||
|
CREATE_CHECKBOX(this->paletteCheckbox, "use 256 color palette");
|
||||||
|
#endif
|
||||||
|
|
||||||
this->hotkeyDropdown.reset(new TextLabel());
|
this->hotkeyDropdown.reset(new TextLabel());
|
||||||
this->hotkeyDropdown->SetText(arrow + " hotkey tester");
|
this->hotkeyDropdown->SetText(arrow + " hotkey tester");
|
||||||
@ -272,16 +289,20 @@ void SettingsLayout::InitializeWindows() {
|
|||||||
CREATE_CHECKBOX(this->syncOnStartupCheckbox, "sync metadata on startup");
|
CREATE_CHECKBOX(this->syncOnStartupCheckbox, "sync metadata on startup");
|
||||||
CREATE_CHECKBOX(this->removeCheckbox, "remove missing files from library");
|
CREATE_CHECKBOX(this->removeCheckbox, "remove missing files from library");
|
||||||
|
|
||||||
this->browseList->SetFocusOrder(0);
|
int order = 0;
|
||||||
this->addedPathsList->SetFocusOrder(1);
|
this->browseList->SetFocusOrder(order++);
|
||||||
this->outputDropdown->SetFocusOrder(2);
|
this->addedPathsList->SetFocusOrder(order++);
|
||||||
this->transportDropdown->SetFocusOrder(3);
|
this->outputDropdown->SetFocusOrder(order++);
|
||||||
this->pluginsDropdown->SetFocusOrder(4);
|
this->transportDropdown->SetFocusOrder(order++);
|
||||||
this->themeDropdown->SetFocusOrder(5);
|
this->pluginsDropdown->SetFocusOrder(order++);
|
||||||
this->hotkeyDropdown->SetFocusOrder(6);
|
this->themeDropdown->SetFocusOrder(order++);
|
||||||
this->dotfileCheckbox->SetFocusOrder(7);
|
#ifdef ENABLE_256_COLOR_OPTION
|
||||||
this->syncOnStartupCheckbox->SetFocusOrder(8);
|
this->paletteCheckbox->SetFocusOrder(order++);
|
||||||
this->removeCheckbox->SetFocusOrder(9);
|
#endif
|
||||||
|
this->hotkeyDropdown->SetFocusOrder(order++);
|
||||||
|
this->dotfileCheckbox->SetFocusOrder(order++);
|
||||||
|
this->syncOnStartupCheckbox->SetFocusOrder(order++);
|
||||||
|
this->removeCheckbox->SetFocusOrder(order++);
|
||||||
|
|
||||||
this->AddWindow(this->browseLabel);
|
this->AddWindow(this->browseLabel);
|
||||||
this->AddWindow(this->addedPathsLabel);
|
this->AddWindow(this->addedPathsLabel);
|
||||||
@ -291,6 +312,9 @@ void SettingsLayout::InitializeWindows() {
|
|||||||
this->AddWindow(this->transportDropdown);
|
this->AddWindow(this->transportDropdown);
|
||||||
this->AddWindow(this->pluginsDropdown);
|
this->AddWindow(this->pluginsDropdown);
|
||||||
this->AddWindow(this->themeDropdown);
|
this->AddWindow(this->themeDropdown);
|
||||||
|
#ifdef ENABLE_256_COLOR_OPTION
|
||||||
|
this->AddWindow(this->paletteCheckbox);
|
||||||
|
#endif
|
||||||
this->AddWindow(this->hotkeyDropdown);
|
this->AddWindow(this->hotkeyDropdown);
|
||||||
this->AddWindow(this->dotfileCheckbox);
|
this->AddWindow(this->dotfileCheckbox);
|
||||||
this->AddWindow(this->syncOnStartupCheckbox);
|
this->AddWindow(this->syncOnStartupCheckbox);
|
||||||
@ -365,6 +389,13 @@ void SettingsLayout::LoadPreferences() {
|
|||||||
|
|
||||||
this->themeDropdown->SetText(arrow + " color theme: " + colorTheme);
|
this->themeDropdown->SetText(arrow + " color theme: " + colorTheme);
|
||||||
|
|
||||||
|
#ifdef ENABLE_256_COLOR_OPTION
|
||||||
|
this->paletteCheckbox->CheckChanged.disconnect(this);
|
||||||
|
this->paletteCheckbox->SetChecked(
|
||||||
|
this->libraryPrefs->GetBool(box::prefs::keys::UsePaletteColors, true));
|
||||||
|
this->paletteCheckbox->CheckChanged.connect(this, &SettingsLayout::OnCheckboxChanged);
|
||||||
|
#endif
|
||||||
|
|
||||||
/* output plugin */
|
/* output plugin */
|
||||||
std::shared_ptr<IOutput> output = outputs::SelectedOutput();
|
std::shared_ptr<IOutput> output = outputs::SelectedOutput();
|
||||||
if (output) {
|
if (output) {
|
||||||
|
@ -117,7 +117,9 @@ namespace musik {
|
|||||||
std::shared_ptr<cursespp::TextLabel> transportDropdown;
|
std::shared_ptr<cursespp::TextLabel> transportDropdown;
|
||||||
std::shared_ptr<cursespp::TextLabel> pluginsDropdown;
|
std::shared_ptr<cursespp::TextLabel> pluginsDropdown;
|
||||||
std::shared_ptr<cursespp::TextLabel> hotkeyDropdown;
|
std::shared_ptr<cursespp::TextLabel> hotkeyDropdown;
|
||||||
|
|
||||||
std::shared_ptr<cursespp::TextLabel> themeDropdown;
|
std::shared_ptr<cursespp::TextLabel> themeDropdown;
|
||||||
|
std::shared_ptr<cursespp::Checkbox> paletteCheckbox;
|
||||||
|
|
||||||
std::shared_ptr<cursespp::Checkbox> dotfileCheckbox;
|
std::shared_ptr<cursespp::Checkbox> dotfileCheckbox;
|
||||||
std::shared_ptr<cursespp::Checkbox> syncOnStartupCheckbox;
|
std::shared_ptr<cursespp::Checkbox> syncOnStartupCheckbox;
|
||||||
|
@ -174,3 +174,26 @@ void ColorThemeOverlay::Show(std::function<void()> callback) {
|
|||||||
|
|
||||||
cursespp::App::Overlays().Push(dialog);
|
cursespp::App::Overlays().Push(dialog);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ColorThemeOverlay::Show256ColorsInfo(bool enabled) {
|
||||||
|
if (enabled) {
|
||||||
|
showNeedsRestart();
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
std::shared_ptr<DialogOverlay> dialog(new DialogOverlay());
|
||||||
|
|
||||||
|
(*dialog)
|
||||||
|
.SetTitle("musikbox")
|
||||||
|
.SetMessage(
|
||||||
|
"disabling 256 color mode will enable RGB color mode, which will replace colors in the stock "
|
||||||
|
"palette. disabling this option results in higher fidelity themes, but it may cause display "
|
||||||
|
"issues in other applications until the terminal is reset.\n\n"
|
||||||
|
"you will need to restart musikbox for this change to take effect.")
|
||||||
|
.AddButton(
|
||||||
|
"KEY_ENTER",
|
||||||
|
"ENTER",
|
||||||
|
"ok");
|
||||||
|
|
||||||
|
App::Overlays().Push(dialog);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -41,6 +41,7 @@ namespace musik {
|
|||||||
class ColorThemeOverlay {
|
class ColorThemeOverlay {
|
||||||
public:
|
public:
|
||||||
static void Show(std::function<void()> callback);
|
static void Show(std::function<void()> callback);
|
||||||
|
static void Show256ColorsInfo(bool enabled);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
ColorThemeOverlay();
|
ColorThemeOverlay();
|
||||||
|
@ -38,6 +38,7 @@
|
|||||||
namespace musik { namespace box { namespace prefs {
|
namespace musik { namespace box { namespace prefs {
|
||||||
|
|
||||||
const std::string keys::DisableCustomColors = "DisableCustomColors";
|
const std::string keys::DisableCustomColors = "DisableCustomColors";
|
||||||
|
const std::string keys::UsePaletteColors = "UsePaletteColors";
|
||||||
const std::string keys::FirstRunSettingsDisplayed = "FirstRunSettingsDisplayed";
|
const std::string keys::FirstRunSettingsDisplayed = "FirstRunSettingsDisplayed";
|
||||||
const std::string keys::ColorTheme = "ColorTheme";
|
const std::string keys::ColorTheme = "ColorTheme";
|
||||||
|
|
||||||
|
@ -40,6 +40,7 @@ namespace musik { namespace box { namespace prefs {
|
|||||||
|
|
||||||
namespace keys {
|
namespace keys {
|
||||||
extern const std::string DisableCustomColors;
|
extern const std::string DisableCustomColors;
|
||||||
|
extern const std::string UsePaletteColors;
|
||||||
extern const std::string FirstRunSettingsDisplayed;
|
extern const std::string FirstRunSettingsDisplayed;
|
||||||
extern const std::string ColorTheme;
|
extern const std::string ColorTheme;
|
||||||
}
|
}
|
||||||
|
@ -115,8 +115,8 @@ void App::SetResizeHandler(ResizeHandler handler) {
|
|||||||
this->resizeHandler = handler;
|
this->resizeHandler = handler;
|
||||||
}
|
}
|
||||||
|
|
||||||
void App::SetCustomColorsDisabled(bool disabled) {
|
void App::SetColorMode(Colors::Mode mode) {
|
||||||
this->disableCustomColors = disabled;
|
this->colorMode = mode;
|
||||||
}
|
}
|
||||||
|
|
||||||
void App::SetColorTheme(const std::string& colorTheme) {
|
void App::SetColorTheme(const std::string& colorTheme) {
|
||||||
@ -163,7 +163,7 @@ void App::OnResized() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void App::Run(ILayoutPtr layout) {
|
void App::Run(ILayoutPtr layout) {
|
||||||
Colors::Init(this->disableCustomColors);
|
Colors::Init(this->colorMode);
|
||||||
|
|
||||||
if (this->colorTheme.size()) {
|
if (this->colorTheme.size()) {
|
||||||
Colors::SetTheme(this->colorTheme);
|
Colors::SetTheme(this->colorTheme);
|
||||||
|
@ -39,6 +39,7 @@
|
|||||||
#include "IInput.h"
|
#include "IInput.h"
|
||||||
#include "IKeyHandler.h"
|
#include "IKeyHandler.h"
|
||||||
#include "OverlayStack.h"
|
#include "OverlayStack.h"
|
||||||
|
#include "Colors.h"
|
||||||
|
|
||||||
namespace cursespp {
|
namespace cursespp {
|
||||||
class App {
|
class App {
|
||||||
@ -51,7 +52,7 @@ namespace cursespp {
|
|||||||
|
|
||||||
void SetKeyHandler(MainKeyHandler handler);
|
void SetKeyHandler(MainKeyHandler handler);
|
||||||
void SetResizeHandler(ResizeHandler handler);
|
void SetResizeHandler(ResizeHandler handler);
|
||||||
void SetCustomColorsDisabled(bool disable);
|
void SetColorMode(Colors::Mode mode);
|
||||||
void SetColorTheme(const std::string& fn);
|
void SetColorTheme(const std::string& fn);
|
||||||
void SetMinimumSize(int width, int height);
|
void SetMinimumSize(int width, int height);
|
||||||
bool IsOverlayVisible() { return this->state.overlay != nullptr; }
|
bool IsOverlayVisible() { return this->state.overlay != nullptr; }
|
||||||
@ -100,7 +101,7 @@ namespace cursespp {
|
|||||||
WindowState state;
|
WindowState state;
|
||||||
MainKeyHandler keyHandler;
|
MainKeyHandler keyHandler;
|
||||||
ResizeHandler resizeHandler;
|
ResizeHandler resizeHandler;
|
||||||
bool disableCustomColors;
|
Colors::Mode colorMode;
|
||||||
std::string colorTheme;
|
std::string colorTheme;
|
||||||
int minWidth, minHeight;
|
int minWidth, minHeight;
|
||||||
|
|
||||||
|
@ -126,8 +126,6 @@ palette, use ones that most closely match our desired colors */
|
|||||||
|
|
||||||
struct Theme {
|
struct Theme {
|
||||||
struct Color {
|
struct Color {
|
||||||
enum Mode { Standard, Palette, Custom };
|
|
||||||
|
|
||||||
Color() {
|
Color() {
|
||||||
Set(0, 0, 0, 0, 0);
|
Set(0, 0, 0, 0, 0);
|
||||||
}
|
}
|
||||||
@ -157,11 +155,11 @@ struct Theme {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int Id(Mode mode, int defaultValue) {
|
int Id(Colors::Mode mode, int defaultValue) {
|
||||||
if (mode == Standard) {
|
if (mode == Colors::Basic) {
|
||||||
return defaultValue;
|
return defaultValue;
|
||||||
}
|
}
|
||||||
else if (mode == Palette) {
|
else if (mode == Colors::Palette) {
|
||||||
return this->palette;
|
return this->palette;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -311,7 +309,7 @@ struct Theme {
|
|||||||
|
|
||||||
/* initializes all of the color pairs from the specified colors, then applies them
|
/* initializes all of the color pairs from the specified colors, then applies them
|
||||||
to the current session! */
|
to the current session! */
|
||||||
void Apply(Color::Mode mode) {
|
void Apply(Colors::Mode mode) {
|
||||||
int backgroundId = background.Id(mode, -1);
|
int backgroundId = background.Id(mode, -1);
|
||||||
int foregroundId = foreground.Id(mode, -1);
|
int foregroundId = foreground.Id(mode, -1);
|
||||||
|
|
||||||
@ -451,15 +449,21 @@ Colors::Colors() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static Theme theme;
|
static Theme theme;
|
||||||
static Theme::Color::Mode colorMode = Theme::Color::Standard;
|
static Colors::Mode colorMode = Colors::Basic;
|
||||||
|
|
||||||
void Colors::Init(bool disableCustomColors) {
|
void Colors::Init(Colors::Mode mode) {
|
||||||
start_color();
|
start_color();
|
||||||
use_default_colors();
|
use_default_colors();
|
||||||
|
|
||||||
if (!disableCustomColors && COLORS > 8) {
|
colorMode = Colors::Basic;
|
||||||
colorMode = canChangeColors()
|
|
||||||
? Theme::Color::Custom : Theme::Color::Palette;
|
if (mode != Colors::Basic && COLORS > 8) {
|
||||||
|
if (mode == Colors::RGB && canChangeColors()) {
|
||||||
|
colorMode = Colors::RGB;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
colorMode = Colors::Palette;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
theme.Apply(colorMode);
|
theme.Apply(colorMode);
|
||||||
|
@ -73,7 +73,13 @@ namespace cursespp {
|
|||||||
Colors();
|
Colors();
|
||||||
|
|
||||||
public:
|
public:
|
||||||
static void Init(bool disableCustomColors = false);
|
enum Mode {
|
||||||
|
RGB,
|
||||||
|
Palette,
|
||||||
|
Basic
|
||||||
|
};
|
||||||
|
|
||||||
|
static void Init(Mode mode = Mode::Basic);
|
||||||
static void SetTheme(const std::string& fn);
|
static void SetTheme(const std::string& fn);
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user