From 3630484e4cee7dc4403553a17399482dfb507907 Mon Sep 17 00:00:00 2001
From: Christophe Geuzaine <cgeuzaine@ulg.ac.be>
Date: Wed, 25 Mar 2015 13:42:13 +0000
Subject: [PATCH] simpler

---
 Common/Options.cpp |  2 +-
 Fltk/FlGui.cpp     | 31 ++++++++++++++++++-------------
 2 files changed, 19 insertions(+), 14 deletions(-)

diff --git a/Common/Options.cpp b/Common/Options.cpp
index c0a4a93e9b..bae9b5935b 100644
--- a/Common/Options.cpp
+++ b/Common/Options.cpp
@@ -1951,7 +1951,7 @@ double opt_general_gui_color_scheme(OPT_ARGS_NUM)
     FlGui::instance()->options->general.butt[21]->value
       (CTX::instance()->guiColorScheme);
   }
-  if(FlGui::available()){
+  if(action & GMSH_SET && FlGui::available()){
     FlGui::instance()->applyColorScheme();
   }
 #endif
diff --git a/Fltk/FlGui.cpp b/Fltk/FlGui.cpp
index 8e7511f18e..21fca1b461 100644
--- a/Fltk/FlGui.cpp
+++ b/Fltk/FlGui.cpp
@@ -251,40 +251,41 @@ void FlGui::applyColorScheme()
 
   if(first){
     // store default (OS-dependent) interface colors:
+    Fl::get_system_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++) {
+    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 == 1){ // dark mode
-    Fl::background(50, 50, 50);
-    Fl::background2(120, 120, 120);
-    Fl::foreground(240, 240, 240);
+    Fl::set_color(FL_BACKGROUND_COLOR, 50, 50, 50);
+    Fl::set_color(FL_BACKGROUND2_COLOR, 120, 120, 120);
+    Fl::set_color(FL_FOREGROUND_COLOR, 240, 240, 240);
     for (int i = 0; i < FL_NUM_GRAY; i++) {
       double min = 0., max = 135.;
       int d = (int)(min + i * (max - min) / (FL_NUM_GRAY - 1.));
       Fl::set_color(fl_gray_ramp(i), d, d, d);
     }
-    Fl::reload_scheme();
+    if(available()) 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]);
+  else if(!first && available() && CTX::instance()->guiColorScheme == 0){
+    // retore default colors (only if not calling the routine from the
+    // constructor)
+    Fl::set_color(FL_BACKGROUND_COLOR, r[0], g[0], b[0]);
+    Fl::set_color(FL_BACKGROUND2_COLOR, r[1], g[1], b[1]);
+    Fl::set_color(FL_FOREGROUND_COLOR, 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);
+    updateViews(true, true);
   }
 
   first = false;
@@ -299,6 +300,9 @@ FlGui::FlGui(int argc, char **argv)
   if(CTX::instance()->display.size())
     Fl::display(CTX::instance()->display.c_str());
 
+  // apply color scheme (noop if default color scheme is selected)
+  applyColorScheme();
+
   // 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);
@@ -385,7 +389,8 @@ FlGui::FlGui(int argc, char **argv)
   graph[0]->getWindow()->show(argc >0 ? 1 : 0, argv);
   if(graph[0]->getMenuWindow()) graph[0]->getMenuWindow()->show();
 
-  // apply color scheme (noop if default color scheme is selected)
+  // apply color scheme (noop if default color scheme is selected); need to be
+  // called a second time one all the widgets are created
   applyColorScheme();
 
   // graphic window should have the initial focus (so we can e.g. directly loop
-- 
GitLab