From 628e255a647f7dc6a515ca1da04cc863bdb888aa Mon Sep 17 00:00:00 2001
From: Christophe Geuzaine <cgeuzaine@ulg.ac.be>
Date: Wed, 27 Oct 2010 15:43:19 +0000
Subject: [PATCH] new displayBorderFactor option

---
 Common/Context.h         |  2 ++
 Common/DefaultOptions.h  |  2 ++
 Common/Options.cpp       |  7 +++++++
 Common/Options.h         |  1 +
 Graphics/drawContext.cpp | 13 ++++++-------
 5 files changed, 18 insertions(+), 7 deletions(-)

diff --git a/Common/Context.h b/Common/Context.h
index 6b886fae43..2f2fc2b26f 100644
--- a/Common/Context.h
+++ b/Common/Context.h
@@ -114,6 +114,8 @@ class CTX {
   int nonModalWindows;
   // clipping plane distance factor
   double clipFactor;
+  // display border factor (0 = model fits window size exactly)
+  double displayBorderFactor;
   // do or do not use the trackball for rotations
   int useTrackball, trackballHyperbolicSheet;
   // point around which to rotate the scene
diff --git a/Common/DefaultOptions.h b/Common/DefaultOptions.h
index c07a907a18..435c93a034 100644
--- a/Common/DefaultOptions.h
+++ b/Common/DefaultOptions.h
@@ -583,6 +583,8 @@ StringXNumber GeneralOptions_Number[] = {
     "Vertical position (in pixels) of the upper left corner of the contextual "
     "windows" }, 
 
+  { F|O, "DisplayBorderFactor" , opt_general_display_border_factor , 1./3. ,
+    "Border factor for model display (0: model fits window size exactly)" },
   { F|O, "DoubleBuffer" , opt_general_double_buffer , 1. ,
     "Use a double buffered graphic window (on Unix, should be set to 0 when "
     "working on a remote host without GLX)" },
diff --git a/Common/Options.cpp b/Common/Options.cpp
index a097d632cc..7530791511 100644
--- a/Common/Options.cpp
+++ b/Common/Options.cpp
@@ -3024,6 +3024,13 @@ double opt_general_clip_factor(OPT_ARGS_NUM)
   return CTX::instance()->clipFactor;
 }
 
+double opt_general_display_border_factor(OPT_ARGS_NUM)
+{
+  if(action & GMSH_SET)
+    CTX::instance()->displayBorderFactor = val;    
+  return CTX::instance()->displayBorderFactor;
+}
+
 double opt_general_point_size(OPT_ARGS_NUM)
 {
   if(action & GMSH_SET)
diff --git a/Common/Options.h b/Common/Options.h
index f4a0813784..5d59107db4 100644
--- a/Common/Options.h
+++ b/Common/Options.h
@@ -294,6 +294,7 @@ double opt_general_scale0(OPT_ARGS_NUM);
 double opt_general_scale1(OPT_ARGS_NUM);
 double opt_general_scale2(OPT_ARGS_NUM);
 double opt_general_clip_factor(OPT_ARGS_NUM);
+double opt_general_display_border_factor(OPT_ARGS_NUM);
 double opt_general_point_size(OPT_ARGS_NUM);
 double opt_general_line_width(OPT_ARGS_NUM);
 double opt_general_shine(OPT_ARGS_NUM);
diff --git a/Graphics/drawContext.cpp b/Graphics/drawContext.cpp
index 1bb3a0464e..ff389d5614 100644
--- a/Graphics/drawContext.cpp
+++ b/Graphics/drawContext.cpp
@@ -262,7 +262,6 @@ void drawContext::draw3d()
 
 void drawContext::draw2d()
 {
-
   glDisable(GL_DEPTH_TEST);
   for(int i = 0; i < 6; i++)
     glDisable((GLenum)(GL_CLIP_PLANE0 + i));
@@ -292,14 +291,12 @@ void drawContext::draw2d()
 
 void drawContext::initProjection(int xpick, int ypick, int wpick, int hpick)
 {
-
   double Va = 
     (double) (viewport[3] - viewport[1]) /
     (double) (viewport[2] - viewport[0]);
   double Wa = (CTX::instance()->max[1] - CTX::instance()->min[1]) / 
     (CTX::instance()->max[0] - CTX::instance()->min[0]);
 
-
   // compute the viewport in World coordinates (with margins)
   if(Va > Wa) {
     vxmin = CTX::instance()->min[0];
@@ -317,10 +314,12 @@ void drawContext::initProjection(int xpick, int ypick, int wpick, int hpick)
     vymin = CTX::instance()->min[1];
     vymax = CTX::instance()->max[1];
   }
-  vxmin -= (vxmax - vxmin) / 3.;
-  vxmax += 0.25 * (vxmax - vxmin);
-  vymin -= (vymax - vymin) / 3.;
-  vymax += 0.25 * (vymax - vymin);
+  double fact = CTX::instance()->displayBorderFactor;
+  double xborder = fact * (vxmax - vxmin), yborder = fact * (vymax - vymin);
+  vxmin -= xborder;
+  vxmax += xborder;
+  vymin -= yborder;
+  vymax += yborder;
 
   // store what one pixel represents in world coordinates
   pixel_equiv_x = (vxmax - vxmin) / (viewport[2] - viewport[0]);
-- 
GitLab