From 5a418268d9baeff3cce9a32d819ceef9392c8749 Mon Sep 17 00:00:00 2001
From: Christophe Geuzaine <cgeuzaine@ulg.ac.be>
Date: Tue, 9 Mar 2010 07:30:22 +0000
Subject: [PATCH] - print time step + total num of steps in scale label by
 default - new option to set other font for title - constify drawString

---
 Common/Context.h        |  4 ++--
 Common/DefaultOptions.h | 10 +++++++---
 Common/Options.cpp      | 29 +++++++++++++++++++++++++++++
 Common/Options.h        |  2 ++
 Fltk/optionWindow.cpp   | 21 +++++++++++++++++----
 Graphics/drawContext.h  | 10 +++++-----
 Graphics/drawGlyph.cpp  | 12 ++++++------
 Graphics/drawScales.cpp | 11 ++++++++---
 8 files changed, 76 insertions(+), 23 deletions(-)

diff --git a/Common/Context.h b/Common/Context.h
index 6064141bc7..9d22f18bd4 100644
--- a/Common/Context.h
+++ b/Common/Context.h
@@ -151,8 +151,8 @@ class CTX {
   // fltk font size (and delta for palette windows)
   int fontSize, deltaFontSize;
   // font name, FLTK enum and size for opengl graphics
-  std::string glFont;
-  int glFontEnum, glFontSize;
+  std::string glFont, glFontTitle;
+  int glFontEnum, glFontEnumTitle, glFontSize, glFontSizeTitle;
   // point/line widths
   double pointSize, lineWidth;
   // light options
diff --git a/Common/DefaultOptions.h b/Common/DefaultOptions.h
index 9184fa1542..6afa974de0 100644
--- a/Common/DefaultOptions.h
+++ b/Common/DefaultOptions.h
@@ -56,6 +56,8 @@ StringXString GeneralOptions_String[] = {
 
   { F|O, "GraphicsFont" , opt_general_graphics_font , "Helvetica" ,
     "Font used in the graphic window" }, 
+  { F|O, "GraphicsFontTitle" , opt_general_graphics_font_title , "Helvetica" ,
+    "Font used in the graphic window for titles" }, 
 
   { F|S, "OptionsFileName" , opt_general_options_filename , ".gmsh-options" ,
     "Option file created with `Tools->Options->Save'; automatically read on startup" },
@@ -601,6 +603,8 @@ StringXNumber GeneralOptions_Number[] = {
 
   { F|O, "GraphicsFontSize" , opt_general_graphics_fontsize , 17. ,
     "Size of the font in the graphic window" }, 
+  { F|O, "GraphicsFontSizeTitle" , opt_general_graphics_fontsize_title , 19. ,
+    "Size of the font in the graphic window for titles" }, 
   { F|S, "GraphicsHeight" , opt_general_graphics_size1 , 600. , 
     "Height (in pixels) of the graphic window" }, 
   { F|S, "GraphicsPositionX" , opt_general_graphics_position0 , 50. , 
@@ -1533,9 +1537,9 @@ StringXNumber ViewOptions_Number[] = {
     "Show element boundaries?" },
   { F|O, "ShowScale" , opt_view_show_scale , 1. ,
     "Show value scale?" },
-  { F|O, "ShowTime" , opt_view_show_time , 1. ,
-    "Time display mode (0=hidden, 1=value if multi-step, 2=value always, "
-    "3=step if multi-step, 4=step always)" },
+  { F|O, "ShowTime" , opt_view_show_time , 3. ,
+    "Time display mode (0=hidden, 1=time value if multi-step, 2=time value always, "
+    "3=time step if multi-step, 4=time step always)" },
   { F|O, "SmoothNormals" , opt_view_smooth_normals , 0. ,
     "Smooth the normals?" },
   { F|O, "Stipple" , opt_view_use_stipple , 0. ,
diff --git a/Common/Options.cpp b/Common/Options.cpp
index 16b5729e41..b5b07f57a7 100644
--- a/Common/Options.cpp
+++ b/Common/Options.cpp
@@ -1077,6 +1077,23 @@ std::string opt_general_graphics_font(OPT_ARGS_STR)
   return CTX::instance()->glFont;
 }
 
+std::string opt_general_graphics_font_title(OPT_ARGS_STR)
+{
+  if(action & GMSH_SET)
+    CTX::instance()->glFontTitle = val;
+#if defined(HAVE_FLTK)
+  int index = drawContext::global()->getFontIndex(CTX::instance()->glFontTitle.c_str());
+  if(action & GMSH_SET){
+    CTX::instance()->glFontTitle = drawContext::global()->getFontName(index);
+    CTX::instance()->glFontEnumTitle = drawContext::global()->getFontEnum(index);
+  }
+  if(FlGui::available() && (action & GMSH_GUI)){
+    FlGui::instance()->options->general.choice[6]->value(index);
+  }
+#endif
+  return CTX::instance()->glFontTitle;
+}
+
 std::string opt_solver_socket_name(OPT_ARGS_STR)
 {
   if(action & GMSH_SET)
@@ -2347,6 +2364,18 @@ double opt_general_graphics_fontsize(OPT_ARGS_NUM)
   return CTX::instance()->glFontSize;
 }
 
+double opt_general_graphics_fontsize_title(OPT_ARGS_NUM)
+{
+  if(action & GMSH_SET)
+    CTX::instance()->glFontSizeTitle = (int)val;
+#if defined(HAVE_FLTK)
+  if(FlGui::available() && (action & GMSH_GUI))
+    FlGui::instance()->options->general.value[28]->value
+      (CTX::instance()->glFontSizeTitle);
+#endif
+  return CTX::instance()->glFontSizeTitle;
+}
+
 double opt_general_polygon_offset_always(OPT_ARGS_NUM)
 {
   if(action & GMSH_SET)
diff --git a/Common/Options.h b/Common/Options.h
index 834d029a7a..87b58a6691 100644
--- a/Common/Options.h
+++ b/Common/Options.h
@@ -49,6 +49,7 @@ std::string opt_general_web_browser(OPT_ARGS_STR);
 std::string opt_general_watch_file_pattern(OPT_ARGS_STR);
 std::string opt_general_gui_theme(OPT_ARGS_STR);
 std::string opt_general_graphics_font(OPT_ARGS_STR);
+std::string opt_general_graphics_font_title(OPT_ARGS_STR);
 std::string opt_solver_socket_name(OPT_ARGS_STR);
 std::string opt_solver_name(OPT_ARGS_STR);
 std::string opt_solver_name0(OPT_ARGS_STR);
@@ -228,6 +229,7 @@ std::string opt_view_stipple9(OPT_ARGS_STR);
 double opt_general_initial_context(OPT_ARGS_NUM);
 double opt_general_fontsize(OPT_ARGS_NUM);
 double opt_general_graphics_fontsize(OPT_ARGS_NUM);
+double opt_general_graphics_fontsize_title(OPT_ARGS_NUM);
 double opt_general_graphics_position0(OPT_ARGS_NUM);
 double opt_general_graphics_position1(OPT_ARGS_NUM);
 double opt_general_graphics_size0(OPT_ARGS_NUM);
diff --git a/Fltk/optionWindow.cpp b/Fltk/optionWindow.cpp
index f5e119c983..c7042a7334 100644
--- a/Fltk/optionWindow.cpp
+++ b/Fltk/optionWindow.cpp
@@ -276,6 +276,7 @@ static void general_options_ok_cb(Fl_Widget *w, void *data)
   opt_general_rotation_center2(0, GMSH_SET, o->general.value[10]->value());
   opt_general_quadric_subdivisions(0, GMSH_SET, o->general.value[11]->value());
   opt_general_graphics_fontsize(0, GMSH_SET, o->general.value[12]->value());
+  opt_general_graphics_fontsize_title(0, GMSH_SET, o->general.value[28]->value());
   opt_general_clip_factor(0, GMSH_SET, o->general.value[14]->value());
   opt_general_polygon_offset_factor(0, GMSH_SET, o->general.value[15]->value());
   opt_general_polygon_offset_units(0, GMSH_SET, o->general.value[16]->value());
@@ -303,6 +304,7 @@ static void general_options_ok_cb(Fl_Widget *w, void *data)
 
   opt_general_vector_type(0, GMSH_SET, o->general.choice[0]->value() + 1);
   opt_general_graphics_font(0, GMSH_SET, o->general.choice[1]->text());
+  opt_general_graphics_font_title(0, GMSH_SET, o->general.choice[6]->text());
   opt_general_orthographic(0, GMSH_SET, !o->general.choice[2]->value());
   opt_general_axes(0, GMSH_SET, o->general.choice[4]->value());
   opt_general_background_gradient(0, GMSH_SET, o->general.choice[5]->value());
@@ -1543,20 +1545,31 @@ optionWindow::optionWindow(int deltaFontSize)
         (L + 2 * IW - 2 * WB, 2 * WB + 8 * BH, BB, BH, "Edit arrow");
       b->callback(general_arrow_param_cb);
 
-      general.choice[1] = new Fl_Choice
-        (L + 2 * WB, 2 * WB + 9 * BH, IW, BH, "Font");
+      int w1 = (int)(4. * IW / 5.), w2 = IW - w1;
+      general.choice[1] = new Fl_Choice(L + 2 * WB, 2 * WB + 9 * BH, w1, BH);
       general.choice[1]->menu(menu_font_names);
       general.choice[1]->align(FL_ALIGN_RIGHT);
       general.choice[1]->callback(general_options_ok_cb);
-
       general.value[12] = new Fl_Value_Input
-        (L + 2 * WB, 2 * WB + 10 * BH, IW, BH, "Font size");
+        (L + 2 * WB + w1, 2 * WB + 9 * BH, w2, BH, "Default font");
       general.value[12]->minimum(5);
       general.value[12]->maximum(40);
       general.value[12]->step(1);
       general.value[12]->align(FL_ALIGN_RIGHT);
       general.value[12]->callback(general_options_ok_cb);
 
+      general.choice[6] = new Fl_Choice(L + 2 * WB, 2 * WB + 10 * BH, w1, BH);
+      general.choice[6]->menu(menu_font_names);
+      general.choice[6]->align(FL_ALIGN_RIGHT);
+      general.choice[6]->callback(general_options_ok_cb);
+      general.value[28] = new Fl_Value_Input
+        (L + 2 * WB + w1, 2 * WB + 10 * BH, w2, BH, "Title font");
+      general.value[28]->minimum(5);
+      general.value[28]->maximum(40);
+      general.value[28]->step(1);
+      general.value[28]->align(FL_ALIGN_RIGHT);
+      general.value[28]->callback(general_options_ok_cb);
+
       o->end();
     }
     {
diff --git a/Graphics/drawContext.h b/Graphics/drawContext.h
index e9c53c541f..750e25c254 100644
--- a/Graphics/drawContext.h
+++ b/Graphics/drawContext.h
@@ -191,12 +191,12 @@ class drawContext {
   void drawAxes();
   void drawSmallAxes();
   void drawScales();
-  void drawString(std::string s, std::string &font_name, int font_enum, 
+  void drawString(const std::string &s, const std::string &font_name, int font_enum, 
                   int font_size, int align);
-  void drawString(std::string s);
-  void drawStringCenter(std::string s);
-  void drawStringRight(std::string s);
-  void drawString(std::string s, double style);
+  void drawString(const std::string &s);
+  void drawStringCenter(const std::string &s);
+  void drawStringRight(const std::string &s);
+  void drawString(const std::string &s, double style);
   void drawSphere(double R, double x, double y, double z, int n1, int n2, int light);
   void drawSphere(double size, double x, double y, double z, int light);
   void drawCylinder(double width, double *x, double *y, double *z, int light);
diff --git a/Graphics/drawGlyph.cpp b/Graphics/drawGlyph.cpp
index 7820468aac..e4a7437968 100644
--- a/Graphics/drawGlyph.cpp
+++ b/Graphics/drawGlyph.cpp
@@ -12,8 +12,8 @@
 #include "gl2ps.h"
 #include "SVector3.h"
 
-void drawContext::drawString(std::string s, std::string &font_name, int font_enum, 
-                             int font_size, int align)
+void drawContext::drawString(const std::string &s, const std::string &font_name,
+                             int font_enum, int font_size, int align)
 {
   if(CTX::instance()->printing && !CTX::instance()->print.text) return;
 
@@ -81,25 +81,25 @@ void drawContext::drawString(std::string s, std::string &font_name, int font_enu
   }
 }
 
-void drawContext::drawString(std::string s)
+void drawContext::drawString(const std::string &s)
 {
   drawString(s, CTX::instance()->glFont, CTX::instance()->glFontEnum, 
              CTX::instance()->glFontSize, 0);
 }
 
-void drawContext::drawStringCenter(std::string s)
+void drawContext::drawStringCenter(const std::string &s)
 {
   drawString(s, CTX::instance()->glFont, CTX::instance()->glFontEnum,
              CTX::instance()->glFontSize, 1);
 }
 
-void drawContext::drawStringRight(std::string s)
+void drawContext::drawStringRight(const std::string &s)
 {
   drawString(s, CTX::instance()->glFont, CTX::instance()->glFontEnum,
              CTX::instance()->glFontSize, 2);
 }
 
-void drawContext::drawString(std::string s, double style)
+void drawContext::drawString(const std::string &s, double style)
 {
   unsigned int bits = (unsigned int)style;
 
diff --git a/Graphics/drawScales.cpp b/Graphics/drawScales.cpp
index 7c7d1c178c..a3e70592c9 100644
--- a/Graphics/drawScales.cpp
+++ b/Graphics/drawScales.cpp
@@ -178,18 +178,23 @@ static void drawScaleLabel(drawContext *ctx, PView *p, double xmin, double ymin,
     sprintf(label, "%s (%s)", data->getName().c_str(), tmp);
   }
   else if((opt->showTime == 3 && nt > 1) || opt->showTime == 4){
-    sprintf(label, "%s (%d)", data->getName().c_str(), opt->timeStep);
+    sprintf(label, "%s (%d/%d)", data->getName().c_str(), opt->timeStep, 
+            data->getNumTimeSteps() - 1);
   }
   else
     sprintf(label, "%s", data->getName().c_str());
  
   if(horizontal){
     glRasterPos2d(xmin + width / 2., ymin + height + tic + 1.4 * font_h);
-    ctx->drawStringCenter(label);
+    ctx->drawString(label, CTX::instance()->glFontTitle, 
+                    CTX::instance()->glFontEnumTitle,
+                    CTX::instance()->glFontSizeTitle, 1);
   }
   else{
     glRasterPos2d(xmin, ymin - 2 * font_h);
-    ctx->drawString(label);
+    ctx->drawString(label, CTX::instance()->glFontTitle, 
+                    CTX::instance()->glFontEnumTitle, 
+                    CTX::instance()->glFontSizeTitle, 0);
   }
 }
 
-- 
GitLab