GUI: real-time color setting preview

This commit is contained in:
tildearrow 2022-04-11 02:53:21 -05:00
parent 7905b813e0
commit ac286fc8d1
3 changed files with 116 additions and 106 deletions

View file

@ -2928,6 +2928,7 @@ bool FurnaceGUI::loop() {
break; break;
case GUI_WARN_RESET_COLORS: case GUI_WARN_RESET_COLORS:
resetColors(); resetColors();
applyUISettings(false);
break; break;
case GUI_WARN_GENERIC: case GUI_WARN_GENERIC:
break; break;

View file

@ -1126,7 +1126,7 @@ class FurnaceGUI {
int load(String path); int load(String path);
void exportAudio(String path, DivAudioExportModes mode); void exportAudio(String path, DivAudioExportModes mode);
void applyUISettings(); void applyUISettings(bool updateFonts=true);
void initSystemPresets(); void initSystemPresets();
void encodeMMLStr(String& target, int* macro, int macroLen, int macroLoop, int macroRel, bool hex=false); void encodeMMLStr(String& target, int* macro, int macroLen, int macroLoop, int macroRel, bool hex=false);

View file

@ -148,7 +148,9 @@ const char* specificControls[18]={
} }
#define UI_COLOR_CONFIG(what,label) \ #define UI_COLOR_CONFIG(what,label) \
ImGui::ColorEdit4(label "##CC_" #what,(float*)&uiColors[what]); if (ImGui::ColorEdit4(label "##CC_" #what,(float*)&uiColors[what])) { \
applyUISettings(false); \
}
#define KEYBIND_CONFIG_BEGIN(id) \ #define KEYBIND_CONFIG_BEGIN(id) \
if (ImGui::BeginTable(id,2)) { if (ImGui::BeginTable(id,2)) {
@ -1702,6 +1704,7 @@ bool FurnaceGUI::importColors(String path) {
} }
} }
fclose(f); fclose(f);
applyUISettings(false);
return true; return true;
} }
@ -1945,7 +1948,7 @@ void FurnaceGUI::parseKeybinds() {
#define SYSTEM_PAT_FONT_PATH_3 "/usr/share/fonts/ubuntu/UbuntuMono-R.ttf" #define SYSTEM_PAT_FONT_PATH_3 "/usr/share/fonts/ubuntu/UbuntuMono-R.ttf"
#endif #endif
void FurnaceGUI::applyUISettings() { void FurnaceGUI::applyUISettings(bool updateFonts) {
ImGuiStyle sty; ImGuiStyle sty;
if (settings.guiColorsBase) { if (settings.guiColorsBase) {
ImGui::StyleColorsLight(&sty); ImGui::StyleColorsLight(&sty);
@ -1956,9 +1959,11 @@ void FurnaceGUI::applyUISettings() {
if (settings.dpiScale>=0.5f) dpiScale=settings.dpiScale; if (settings.dpiScale>=0.5f) dpiScale=settings.dpiScale;
// colors // colors
if (updateFonts) {
for (int i=0; i<GUI_COLOR_MAX; i++) { for (int i=0; i<GUI_COLOR_MAX; i++) {
uiColors[i]=ImGui::ColorConvertU32ToFloat4(e->getConfInt(guiColors[i].name,guiColors[i].defaultColor)); uiColors[i]=ImGui::ColorConvertU32ToFloat4(e->getConfInt(guiColors[i].name,guiColors[i].defaultColor));
} }
}
for (int i=0; i<64; i++) { for (int i=0; i<64; i++) {
ImVec4 col1=uiColors[GUI_COLOR_PATTERN_VOLUME_MIN]; ImVec4 col1=uiColors[GUI_COLOR_PATTERN_VOLUME_MIN];
@ -2085,6 +2090,7 @@ void FurnaceGUI::applyUISettings() {
sysCmd2Grad[i]=ImGui::GetColorU32(ImVec4(base.x,base.y,base.z,((float)i/255.0f)*base.w)); sysCmd2Grad[i]=ImGui::GetColorU32(ImVec4(base.x,base.y,base.z,((float)i/255.0f)*base.w));
} }
if (updateFonts) {
// set to 800 for now due to problems with unifont // set to 800 for now due to problems with unifont
static const ImWchar upTo800[]={0x20,0x7e,0xa0,0x800,0}; static const ImWchar upTo800[]={0x20,0x7e,0xa0,0x800,0};
ImFontGlyphRangesBuilder range; ImFontGlyphRangesBuilder range;
@ -2199,6 +2205,7 @@ void FurnaceGUI::applyUISettings() {
mainFont->FallbackChar='?'; mainFont->FallbackChar='?';
mainFont->DotChar='.'; mainFont->DotChar='.';
}
// TODO: allow changing these colors. // TODO: allow changing these colors.
ImGuiFileDialog::Instance()->SetFileStyle(IGFD_FileStyleByTypeDir,"",uiColors[GUI_COLOR_FILE_DIR],ICON_FA_FOLDER_O); ImGuiFileDialog::Instance()->SetFileStyle(IGFD_FileStyleByTypeDir,"",uiColors[GUI_COLOR_FILE_DIR],ICON_FA_FOLDER_O);
@ -2224,6 +2231,8 @@ void FurnaceGUI::applyUISettings() {
ImGuiFileDialog::Instance()->SetFileStyle(IGFD_FileStyleByExtension,".fti",uiColors[GUI_COLOR_FILE_INSTR],ICON_FA_FILE); ImGuiFileDialog::Instance()->SetFileStyle(IGFD_FileStyleByExtension,".fti",uiColors[GUI_COLOR_FILE_INSTR],ICON_FA_FILE);
ImGuiFileDialog::Instance()->SetFileStyle(IGFD_FileStyleByExtension,".bti",uiColors[GUI_COLOR_FILE_INSTR],ICON_FA_FILE); ImGuiFileDialog::Instance()->SetFileStyle(IGFD_FileStyleByExtension,".bti",uiColors[GUI_COLOR_FILE_INSTR],ICON_FA_FILE);
if (updateFonts) {
if (fileDialog!=NULL) delete fileDialog; if (fileDialog!=NULL) delete fileDialog;
fileDialog=new FurnaceGUIFileDialog(settings.sysFileDialog); fileDialog=new FurnaceGUIFileDialog(settings.sysFileDialog);
} }
}