changeset 7855:f317f14516cb

Add zoom stack facility in axes object.
author Michael Goffioul <michael.goffioul@gmail.com>
date Tue, 04 Mar 2008 15:34:38 +0100
parents 228858e69bd1
children cf672485be43
files src/ChangeLog src/graphics.cc src/graphics.h.in
diffstat 3 files changed, 76 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/src/ChangeLog	Sun Mar 02 06:38:27 2008 +0200
+++ b/src/ChangeLog	Tue Mar 04 15:34:38 2008 +0100
@@ -31,6 +31,18 @@
 
 2008-06-04  Michael Goffioul <michael.goffioul@gmail.com>
 
+	* graphics.h.in (axes::properties::pixel2coord): Center Z coordinate
+	on x_zlim instead of 0.
+	(axes::properties::zoom, axes::properties::unzoom,
+	axes::properties::clear_zoom_stack): New methods to handle zoom stack.
+	(axes::properties::zoom_stack): New field to hold zoom stack.
+	(axes::properties::update_xlim, axes::properites::update_ylim):
+	Additional do_clr_zoom argument to control whether the zoom stack will
+	be cleared.
+	(axes::properties::update_zlim): Clear zoom stack.
+	* graphics.cc (axes::properties::zoom, axes::properties::unzoom,
+	axes::properties::clear_zoom_stack): New methods to handle zoom stack.
+
 	* genprops.awk (emit_source): Use all properties in factory defaults.
 
 	* graphics.h.in (base_property::base_property): Set internal counter
--- a/src/graphics.cc	Sun Mar 02 06:38:27 2008 +0200
+++ b/src/graphics.cc	Tue Mar 04 15:34:38 2008 +0100
@@ -2893,6 +2893,53 @@
   unwind_protect::run ();
 }
 
+void
+axes::properties::zoom (const Matrix& xl, const Matrix& yl)
+{
+  zoom_stack.push_front (xlimmode.get ());
+  zoom_stack.push_front (xlim.get ());
+  zoom_stack.push_front (ylimmode.get ());
+  zoom_stack.push_front (ylim.get ());
+
+  xlim = xl;
+  xlimmode = "manual";
+  ylim = yl;
+  ylimmode = "manual";
+
+  update_transform ();
+  update_xlim (false);
+  update_ylim (false);
+}
+
+void
+axes::properties::unzoom (void)
+{
+  if (zoom_stack.size () >= 4)
+    {
+      ylim = zoom_stack.front ();
+      zoom_stack.pop_front ();
+      ylimmode = zoom_stack.front ();
+      zoom_stack.pop_front ();
+      xlim = zoom_stack.front ();
+      zoom_stack.pop_front ();
+      xlimmode = zoom_stack.front ();
+      zoom_stack.pop_front ();
+
+      update_transform ();
+      update_xlim (false);
+      update_ylim (false);
+    }
+}
+
+void
+axes::properties::clear_zoom_stack (void)
+{
+  while (zoom_stack.size () > 4)
+    zoom_stack.pop_front ();
+
+  unzoom ();
+}
+
 // ---------------------------------------------------------------------
 
 // Note: "line" code is entirely auto-generated
--- a/src/graphics.h.in	Sun Mar 02 06:38:27 2008 +0200
+++ b/src/graphics.h.in	Tue Mar 04 15:34:38 2008 +0100
@@ -2546,17 +2546,21 @@
     Matrix get_transform_zlim (void) const { return x_zlim; }
 
     ColumnVector pixel2coord (double px, double py) const
-    { return get_transform ().untransform (px, py, 0); }
+    { return get_transform ().untransform (px, py, (x_zlim(0)+x_zlim(1))/2); }
 
     ColumnVector coord2pixel (double x, double y, double z) const
     { return get_transform ().transform (x, y, z); }
 
+    void zoom (const Matrix& xl, const Matrix& yl);
+    void unzoom (void);
+    void clear_zoom_stack (void);
 
   private:
     scaler sx, sy, sz;
     Matrix x_render, x_render_inv;
     Matrix x_gl_mat1, x_gl_mat2;
     Matrix x_zlim;
+    std::list<octave_value> zoom_stack;
 
     // See the genprops.awk script for an explanation of the
     // properties declarations.
@@ -2733,19 +2737,27 @@
 
   public:
     Matrix get_axis_limits (double xmin, double xmax, double min_pos, bool logscale);
-    void update_xlim (void)
+    
+    void update_xlim (bool do_clr_zoom = true)
     {
       if (xtickmode.is ("auto"))
 	calc_ticks_and_lims (xlim, xtick, xlimmode.is ("auto"));
+
       fix_limits (xlim);
+
+      if (do_clr_zoom)
+	zoom_stack.clear ();
     }
 
-    void update_ylim (void)
+    void update_ylim (bool do_clr_zoom = true)
     {
       if (ytickmode.is ("auto"))
 	calc_ticks_and_lims (ylim, ytick, ylimmode.is ("auto"));
 
       fix_limits (ylim);
+
+      if (do_clr_zoom)
+	zoom_stack.clear ();
     }
 
     void update_zlim (void)
@@ -2754,6 +2766,8 @@
 	calc_ticks_and_lims (zlim, ztick, zlimmode.is ("auto"));
 
       fix_limits (zlim);
+
+      zoom_stack.clear ();
     }
     
   };