diff libinterp/corefcn/graphics.cc @ 19901:6ba3d0f7c6e8

improve mouse zooming for Qt plotting (bug #44302) * Figure.h (enum MouseMode): Split ZoomMode into ZoomInMode and ZoomOutMode. Change all uses. * Canvas.cc (Canvas::canvasMouseReleaseEvent, Canvas::canvasWheelEvent): Make meaning of zoom factor consistent with zoom function. Make direction of wheel event consistent with other programs. * __init_fltk__.cc (plot_window::handle): Make meaning of zoom factor consistent with zoom function. * MouseModeActionGroup.cc (MouseModeActionGroup::MouseModeActionGroup): Provide buttons for zooming in and out. * graphics.cc (figure::properties::set_toolkit): Handle zoom direction. (do_zoom): Make factor > 1 zoom in.
author John W. Eaton <jwe@octave.org>
date Thu, 26 Feb 2015 19:24:59 -0500
parents 726df008104d
children 60fe3ef12bb0
line wrap: on
line diff
--- a/libinterp/corefcn/graphics.cc	Thu Feb 26 13:54:11 2015 -0500
+++ b/libinterp/corefcn/graphics.cc	Thu Feb 26 19:24:59 2015 -0500
@@ -1810,27 +1810,62 @@
 }
 
 void
-figure::properties::set___mouse_mode__ (const octave_value& val)
+figure::properties::set___mouse_mode__ (const octave_value& val_arg)
 {
   if (! error_state)
     {
-      if (__mouse_mode__.set (val, true))
-        {
-          std::string mode = __mouse_mode__.current_value ();
-
-          octave_scalar_map pm = get___pan_mode__ ().scalar_map_value ();
-          pm.setfield ("Enable", mode == "pan" ? "on" : "off");
-          set___pan_mode__ (pm);
-
-          octave_scalar_map rm = get___rotate_mode__ ().scalar_map_value ();
-          rm.setfield ("Enable", mode == "rotate" ? "on" : "off");
-          set___rotate_mode__ (rm);
-
-          octave_scalar_map zm = get___zoom_mode__ ().scalar_map_value ();
-          zm.setfield ("Enable", mode == "zoom" ? "on" : "off");
-          set___zoom_mode__ (zm);
-
-          mark_modified ();
+      std::string direction = "in";
+
+      octave_value val = val_arg;
+
+      if (val.is_string ())
+        {
+          std::string modestr = val.string_value ();
+
+          if (modestr == "zoom in")
+            {
+              val = modestr = "zoom";
+              direction = "in";
+            }
+          else if (modestr == "zoom out")
+            {
+              val = modestr = "zoom";
+              direction = "out";
+            }
+
+          if (__mouse_mode__.set (val, true))
+            {
+              std::string mode = __mouse_mode__.current_value ();
+
+              octave_scalar_map pm = get___pan_mode__ ().scalar_map_value ();
+              pm.setfield ("Enable", mode == "pan" ? "on" : "off");
+              set___pan_mode__ (pm);
+
+              octave_scalar_map rm = get___rotate_mode__ ().scalar_map_value ();
+              rm.setfield ("Enable", mode == "rotate" ? "on" : "off");
+              set___rotate_mode__ (rm);
+
+              octave_scalar_map zm = get___zoom_mode__ ().scalar_map_value ();
+              zm.setfield ("Enable", mode == "zoom" ? "on" : "off");
+              zm.setfield ("Direction", direction);
+              set___zoom_mode__ (zm);
+
+              mark_modified ();
+            }
+          else if (modestr == "zoom")
+            {
+              octave_scalar_map zm = get___zoom_mode__ ().scalar_map_value ();
+              std::string curr_direction
+                = zm.getfield ("Direction").string_value ();
+
+              if (direction != curr_direction)
+                {
+                  zm.setfield ("Direction", direction);
+                  set___zoom_mode__ (zm);
+
+                  mark_modified ();
+                }
+            }
         }
     }
 }
@@ -7572,8 +7607,8 @@
     }
 
   // Perform the zooming
-  lo = val + factor * (lo - val);
-  hi = val + factor * (hi - val);
+  lo = val + (lo - val) / factor;
+  hi = val + (hi - val) / factor;
 
   if (is_logscale)
     {