# HG changeset patch
# User Markus Mützel <markus.muetzel@gmx.de>
# Date 1473699149 -7200
#      Mon Sep 12 18:52:29 2016 +0200
# Node ID 22b79a53e6dfca3ef08421daf3bb96081ef3864b
# Parent  9d4cb0cf9cd2cb7aeef5f76ba1645e9b5fd9d1f3
Add support in opengl for "(xy)axislocation" "origin" (bug #48562).

* gl-render.cc: Add support for "(xy)axislocation" being set to
"origin".

diff -r 9d4cb0cf9cd2 -r 22b79a53e6df libinterp/corefcn/gl-render.cc
--- a/libinterp/corefcn/gl-render.cc	Sun Sep 11 21:08:56 2016 -0700
+++ b/libinterp/corefcn/gl-render.cc	Mon Sep 12 18:52:29 2016 +0200
@@ -1186,6 +1186,8 @@
     bool xySym = props.get_xySym ();
     bool layer2Dtop = props.get_layer2Dtop ();
     bool is2d = props.get_is2D ();
+    bool isXOrigin = props.xaxislocation_is ("origin");
+    bool isYOrigin = props.yaxislocation_is ("origin");
     bool boxFull = (props.get_boxstyle () == "full");
     double linewidth = props.get_linewidth ();
     double xPlane = props.get_xPlane ();
@@ -1214,8 +1216,12 @@
 
     // X box
     set_color (props.get_xcolor_rgb ());
-    glVertex3d (xPlaneN, ypTick, zpTick);
-    glVertex3d (xPlane, ypTick, zpTick);
+    
+    if (! isXOrigin || props.is_box() || ! is2d)
+      {
+        glVertex3d (xPlaneN, ypTick, zpTick);
+        glVertex3d (xPlane, ypTick, zpTick);
+      }
 
     if (props.is_box ())
       {
@@ -1235,8 +1241,11 @@
 
     // Y box
     set_color (props.get_ycolor_rgb ());
-    glVertex3d (xpTick, yPlaneN, zpTick);
-    glVertex3d (xpTick, yPlane, zpTick);
+    if (! isYOrigin || props.is_box() || ! is2d)
+      {
+        glVertex3d (xpTick, yPlaneN, zpTick);
+        glVertex3d (xpTick, yPlane, zpTick);
+      }
 
     if (props.is_box () && ! plotyy)
       {
@@ -1349,6 +1358,7 @@
         bool do_xminorgrid = (props.is_xminorgrid ()
                               && (minorgridstyle != "none"));
         bool do_xminortick = props.is_xminortick ();
+        bool is_origin = props.xaxislocation_is ("origin") && props.get_is2D ();
         Matrix xticks = xform.xscale (props.get_xtick ().matrix_value ());
         Matrix xmticks = xform.xscale (props.get_xmtick ().matrix_value ());
         string_vector xticklabels = props.get_xticklabel ().string_vector_value ();
@@ -1384,16 +1394,25 @@
 
         set_color (props.get_xcolor_rgb ());
 
+        // axis line
+        if (is_origin)
+          {
+            glBegin (GL_LINES);
+            glVertex3d (x_min, 0, zpTick);
+            glVertex3d (x_max, 0, zpTick);
+            glEnd ();
+          }
+
         // minor tick marks
         if (do_xminortick)
           {
             if (tick_along_z)
-              render_tickmarks (xmticks, x_min, x_max, ypTick, ypTick,
+              render_tickmarks (xmticks, x_min, x_max, (is_origin ? 0. : ypTick), ypTick,
                                 zpTick, zpTickN, 0., 0.,
                                 octave::math::signum (zpTick-zpTickN)*fz*xticklen/2,
                                 0, mirror);
             else
-              render_tickmarks (xmticks, x_min, x_max, ypTick, ypTickN,
+              render_tickmarks (xmticks, x_min, x_max, (is_origin ? 0. : ypTick), ypTickN,
                                 zpTick, zpTick, 0.,
                                 octave::math::signum (ypTick-ypTickN)*fy*xticklen/2,
                                 0., 0, mirror);
@@ -1402,14 +1421,14 @@
         // tick marks
         if (tick_along_z)
           {
-            render_tickmarks (xticks, x_min, x_max, ypTick, ypTick,
+            render_tickmarks (xticks, x_min, x_max, (is_origin ? 0. : ypTick), ypTick,
                               zpTick, zpTickN, 0., 0.,
                               octave::math::signum (zpTick-zpTickN)*fz*xticklen,
                               0, mirror);
           }
         else
           {
-            render_tickmarks (xticks, x_min, x_max, ypTick, ypTickN,
+            render_tickmarks (xticks, x_min, x_max, (is_origin ? 0. : ypTick), ypTickN,
                               zpTick, zpTick, 0.,
                               octave::math::signum (ypTick-ypTickN)*fy*xticklen,
                               0., 0, mirror);
@@ -1422,12 +1441,12 @@
             int valign = (xstate == AXE_VERT_DIR ? 1 : (x2Dtop ? 0 : 2));
 
             if (tick_along_z)
-              render_ticktexts (xticks, xticklabels, x_min, x_max, ypTick,
+              render_ticktexts (xticks, xticklabels, x_min, x_max, (is_origin ? 0. : ypTick),
                                 zpTick+octave::math::signum (zpTick-zpTickN)*fz*xtickoffset,
                                 0, halign, valign, wmax, hmax);
             else
               render_ticktexts (xticks, xticklabels, x_min, x_max,
-                                ypTick+octave::math::signum (ypTick-ypTickN)*fy*xtickoffset,
+                                (is_origin ? 0. : ypTick)+octave::math::signum (ypTick-ypTickN)*fy*xtickoffset,
                                 zpTick, 0, halign, valign, wmax, hmax);
           }
 
@@ -1477,6 +1496,7 @@
         bool do_yminorgrid = (props.is_yminorgrid ()
                               && (minorgridstyle != "none"));
         bool do_yminortick = props.is_yminortick ();
+        bool is_origin = props.yaxislocation_is ("origin") && props.get_is2D ();
         Matrix yticks = xform.yscale (props.get_ytick ().matrix_value ());
         Matrix ymticks = xform.yscale (props.get_ymtick ().matrix_value ());
         string_vector yticklabels = props.get_yticklabel ().string_vector_value ();
@@ -1513,16 +1533,25 @@
 
         set_color (props.get_ycolor_rgb ());
 
+        // axis line
+        if (is_origin)
+          {
+            glBegin (GL_LINES);
+            glVertex3d (0., y_min, zpTick);
+            glVertex3d (0., y_max, zpTick);
+            glEnd ();
+          }
+
         // minor tick marks
         if (do_yminortick)
           {
             if (tick_along_z)
-              render_tickmarks (ymticks, y_min, y_max, xpTick, xpTick,
+              render_tickmarks (ymticks, y_min, y_max, (is_origin ? 0. : xpTick), xpTick,
                                 zpTick, zpTickN, 0., 0.,
                                 octave::math::signum (zpTick-zpTickN)*fz*yticklen/2,
                                 1, mirror);
             else
-              render_tickmarks (ymticks, y_min, y_max, xpTick, xpTickN,
+              render_tickmarks (ymticks, y_min, y_max, (is_origin ? 0. : xpTick), xpTickN,
                                 zpTick, zpTick,
                                 octave::math::signum (xpTick-xpTickN)*fx*yticklen/2,
                                 0., 0., 1, mirror);
@@ -1530,12 +1559,12 @@
 
         // tick marks
         if (tick_along_z)
-          render_tickmarks (yticks, y_min, y_max, xpTick, xpTick,
+          render_tickmarks (yticks, y_min, y_max, (is_origin ? 0. : xpTick), xpTick,
                             zpTick, zpTickN, 0., 0.,
                             octave::math::signum (zpTick-zpTickN)*fz*yticklen,
                             1, mirror);
         else
-          render_tickmarks (yticks, y_min, y_max, xpTick, xpTickN,
+          render_tickmarks (yticks, y_min, y_max, (is_origin ? 0. : xpTick), xpTickN,
                             zpTick, zpTick,
                             octave::math::signum (xPlaneN-xPlane)*fx*yticklen,
                             0., 0., 1, mirror);
@@ -1548,12 +1577,12 @@
             int valign = (ystate == AXE_VERT_DIR ? 1 : 2);
 
             if (tick_along_z)
-              render_ticktexts (yticks, yticklabels, y_min, y_max, xpTick,
+              render_ticktexts (yticks, yticklabels, y_min, y_max, (is_origin ? 0. : xpTick),
                                 zpTick+octave::math::signum (zpTick-zpTickN)*fz*ytickoffset,
                                 1, halign, valign, wmax, hmax);
             else
               render_ticktexts (yticks, yticklabels, y_min, y_max,
-                                xpTick+octave::math::signum (xpTick-xpTickN)*fx*ytickoffset,
+                                (is_origin ? 0. : xpTick)+octave::math::signum (xpTick-xpTickN)*fx*ytickoffset,
                                 zpTick, 1, halign, valign, wmax, hmax);
           }
 
