diff --git a/Common/Options.cpp b/Common/Options.cpp index 557639ca669ddf10060aa2ce0424fb8676c57a7c..c0a4a93e9b8a54c5defd038cd43c8dcd83a03755 100644 --- a/Common/Options.cpp +++ b/Common/Options.cpp @@ -1947,9 +1947,13 @@ double opt_general_gui_color_scheme(OPT_ARGS_NUM) if(action & GMSH_SET) CTX::instance()->guiColorScheme = (int)val; #if defined(HAVE_FLTK) - if(FlGui::available() && (action & GMSH_GUI)) + if(FlGui::available() && (action & GMSH_GUI)){ FlGui::instance()->options->general.butt[21]->value (CTX::instance()->guiColorScheme); + } + if(FlGui::available()){ + FlGui::instance()->applyColorScheme(); + } #endif return CTX::instance()->guiColorScheme; } diff --git a/Fltk/FlGui.cpp b/Fltk/FlGui.cpp index 1068d9bf78e924fc8547433d4a36d2411a50c15b..8e7511f18e64c1eced8928bb076690bb92d21f2a 100644 --- a/Fltk/FlGui.cpp +++ b/Fltk/FlGui.cpp @@ -243,16 +243,24 @@ static void fatal_error_handler(const char *fmt, ...) Msg::Fatal("%s (FLTK internal error)", str); } -FlGui::FlGui(int argc, char **argv) +void FlGui::applyColorScheme() { - Fl::error = error_handler; - Fl::fatal = fatal_error_handler; - - // set X display - if(CTX::instance()->display.size()) - Fl::display(CTX::instance()->display.c_str()); + static int first = true; + int N = 4 + FL_NUM_GRAY; + static std::vector<unsigned char> r(N, 0), g(N, 0), b(N, 0); + + if(first){ + // store default (OS-dependent) interface colors: + Fl::get_color(FL_BACKGROUND_COLOR, r[0], g[0], b[0]); + Fl::get_color(FL_BACKGROUND2_COLOR, r[1], g[1], b[1]); + Fl::get_color(FL_FOREGROUND_COLOR, r[2], g[2], b[2]); + Fl::get_color(FL_SELECTION_COLOR, r[3], g[3], b[3]); + for (int i = 0; i < FL_NUM_GRAY; i++) { + Fl::get_color(fl_gray_ramp(i), r[4 + i], g[4 + i], b[4 + i]); + } + } - if(CTX::instance()->guiColorScheme){ // dark mode + if(CTX::instance()->guiColorScheme == 1){ // dark mode Fl::background(50, 50, 50); Fl::background2(120, 120, 120); Fl::foreground(240, 240, 240); @@ -261,8 +269,36 @@ FlGui::FlGui(int argc, char **argv) int d = (int)(min + i * (max - min) / (FL_NUM_GRAY - 1.)); Fl::set_color(fl_gray_ramp(i), d, d, d); } + Fl::reload_scheme(); + Fl::set_color(FL_SELECTION_COLOR, 200, 200, 200); + if(available()) updateViews(true, true); + } + else if(!first && CTX::instance()->guiColorScheme == 0){ + // retore default colors (only if not calling the routine for the first + // time) + Fl::background(r[0], g[0], b[0]); + Fl::background2(r[1], g[1], b[1]); + Fl::foreground(r[2], g[2], b[2]); + for (int i = 0; i < FL_NUM_GRAY; i++) { + Fl::set_color(fl_gray_ramp(i), r[4 + i], g[4 + i], b[4 + i]); + } + Fl::reload_scheme(); + Fl::set_color(FL_SELECTION_COLOR, r[3], g[3], b[3]); + if(available()) updateViews(true, true); } + first = false; +} + +FlGui::FlGui(int argc, char **argv) +{ + Fl::error = error_handler; + Fl::fatal = fatal_error_handler; + + // set X display + if(CTX::instance()->display.size()) + Fl::display(CTX::instance()->display.c_str()); + // add new box types (dx dy dw dh) Fl::set_boxtype(GMSH_SIMPLE_RIGHT_BOX, simple_right_box_draw, 0, 0, 1, 0); Fl::set_boxtype(GMSH_SIMPLE_TOP_BOX, simple_top_box_draw, 0, 1, 0, 1); @@ -286,10 +322,6 @@ FlGui::FlGui(int argc, char **argv) Fl::scheme(CTX::instance()->guiTheme.c_str()); Fl_Tooltip::size(FL_NORMAL_SIZE); Fl_Tooltip::delay(0.5); -#if defined(__APPLE__) - if(!CTX::instance()->guiColorScheme) - Fl_Tooltip::color(FL_LIGHT2); -#endif // use retina resolution if available #if (FL_MAJOR_VERSION == 1) && (FL_MINOR_VERSION == 3) && (FL_PATCH_VERSION >= 4) @@ -353,8 +385,8 @@ FlGui::FlGui(int argc, char **argv) graph[0]->getWindow()->show(argc >0 ? 1 : 0, argv); if(graph[0]->getMenuWindow()) graph[0]->getMenuWindow()->show(); - if(CTX::instance()->guiColorScheme) - Fl::set_color(FL_SELECTION_COLOR, 200, 200, 200); + // apply color scheme (noop if default color scheme is selected) + applyColorScheme(); // graphic window should have the initial focus (so we can e.g. directly loop // through time steps with the keyboard) diff --git a/Fltk/FlGui.h b/Fltk/FlGui.h index cd37b4d728d32dc1112bc9203b2778d72e177cae..31ac2ad35d5ce5dae8179500228de1c7077b6f1f 100644 --- a/Fltk/FlGui.h +++ b/Fltk/FlGui.h @@ -133,6 +133,8 @@ class FlGui{ void rebuildTree(bool deleteWidgets); // open module in tree void openModule(const std::string &name); + // apply color scheme to widgets + void applyColorScheme(); }; void redraw_cb(Fl_Widget *w, void *data); diff --git a/Fltk/optionWindow.cpp b/Fltk/optionWindow.cpp index 070ed0f00b34fdca7c5498261eaa2b3eadced9d8..83a7f83f8a78cc5868fd756e4da66eeb0230d388 100644 --- a/Fltk/optionWindow.cpp +++ b/Fltk/optionWindow.cpp @@ -1374,7 +1374,7 @@ optionWindow::optionWindow(int deltaFontSize) general.butt[10]->callback(general_options_ok_cb); general.butt[21] = new Fl_Check_Button - (L + 2 * WB, 2 * WB + 2 * BH, BW, BH, "Use dark interface (requires restart)"); + (L + 2 * WB, 2 * WB + 2 * BH, BW, BH, "Use dark interface"); general.butt[21]->type(FL_TOGGLE_BUTTON); general.butt[21]->callback(general_options_ok_cb);