Updates to the 256 color palette warning dialogs

This commit is contained in:
casey langen 2017-03-13 19:21:25 -07:00
parent e943d840c5
commit 37ba672d77
5 changed files with 48 additions and 18 deletions

View File

@ -117,6 +117,8 @@ void MainLayout::Initialize() {
this->syncing.reset(new TextLabel());
this->syncing->SetContentColor(CURSESPP_BANNER);
this->syncing->MoveAndResize(0, 0, 1, 1);
this->syncing->Hide();
this->AddWindow(this->syncing);
}

View File

@ -122,9 +122,11 @@ void SettingsLayout::OnCheckboxChanged(cursespp::Checkbox* cb, bool checked) {
}
#ifdef ENABLE_256_COLOR_OPTION
else if (cb == paletteCheckbox.get()) {
this->libraryPrefs->SetBool(box::prefs::keys::UsePaletteColors, checked);
this->libraryPrefs->Save();
ColorThemeOverlay::Show256ColorsInfo(checked);
ColorThemeOverlay::Show256ColorsInfo(
checked,
[this]() {
this->LoadPreferences();
});
}
#endif
}

View File

@ -56,16 +56,19 @@ using namespace musik::box;
using namespace cursespp;
using namespace boost::filesystem;
static void showNeedsRestart() {
using Callback = std::function<void()>;
static void showNeedsRestart(Callback cb = Callback()) {
std::shared_ptr<DialogOverlay> dialog(new DialogOverlay());
(*dialog)
.SetTitle("musikbox")
.SetMessage("you will need to restart musikbox for this change to take effect.")
.AddButton(
"KEY_ENTER",
"ENTER",
"ok");
.AddButton("KEY_ENTER", "ENTER", "ok", [cb](std::string key) {
if (cb) {
cb();
}
});
App::Overlays().Push(dialog);
}
@ -168,9 +171,18 @@ void ColorThemeOverlay::Show(std::function<void()> callback) {
cursespp::App::Overlays().Push(dialog);
}
void ColorThemeOverlay::Show256ColorsInfo(bool enabled) {
void ColorThemeOverlay::Show256ColorsInfo(bool enabled, std::function<void()> callback) {
auto prefs = core::Preferences::
ForComponent(core::prefs::components::Settings);
if (enabled) {
prefs->SetBool(box::prefs::keys::UsePaletteColors, enabled);
prefs->Save();
showNeedsRestart();
if (callback) {
callback();
}
}
else {
std::shared_ptr<DialogOverlay> dialog(new DialogOverlay());
@ -181,12 +193,20 @@ void ColorThemeOverlay::Show256ColorsInfo(bool enabled) {
"disabling 256 color degradation 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.")
"are you sure you want to disable 256 color degradation?")
.AddButton(
"KEY_ENTER",
"ENTER",
"ok");
"y", "y", "yes", [prefs, callback](std::string key) {
prefs->SetBool(box::prefs::keys::UsePaletteColors, false);
prefs->Save();
showNeedsRestart(callback);
})
.AddButton(
"n", "n", "no", [callback](std::string key) {
if (callback) {
callback();
}
});
App::Overlays().Push(dialog);
App::Overlays().Push(dialog);
}
}

View File

@ -41,7 +41,7 @@ namespace musik {
class ColorThemeOverlay {
public:
static void Show(std::function<void()> callback);
static void Show256ColorsInfo(bool enabled);
static void Show256ColorsInfo(bool enabled, std::function<void()> callback);
private:
ColorThemeOverlay();

View File

@ -166,9 +166,11 @@ struct Theme {
else if (mode == Colors::Palette) {
return this->palette;
}
init_color(this->colorId, SCALE(this->r), SCALE(this->g), SCALE(this->b));
return this->colorId;
else if (this->r >= 0 && this->g >= 0 && this->b >= 0) {
init_color(this->colorId, SCALE(this->r), SCALE(this->g), SCALE(this->b));
return this->colorId;
}
return -1;
}
int colorId;
@ -228,6 +230,10 @@ struct Theme {
}
bool LoadFromFile(const std::string& fn) {
if (!fn.size()) {
return false;
}
#ifdef WIN32
std::wstring u16fn = u8to16(fn);
FILE* file = _wfopen(u16fn.c_str(), L"rb");