changeset 20097:e1d7bd38b82b

make pan, rotate3d, and zoom properly toggle state * pan.m (update_mouse_mode): New subfunction. Also set __mouse_mode__ property when toggling state. * rotate3d.m: Likewise. * zoom.m: Likewise.
author John W. Eaton <jwe@octave.org>
date Mon, 02 Mar 2015 21:00:13 -0500
parents 966a1933f3fa
children 00c3f2021cad
files scripts/plot/util/pan.m scripts/plot/util/rotate3d.m scripts/plot/util/zoom.m
diffstat 3 files changed, 42 insertions(+), 35 deletions(-) [+]
line wrap: on
line diff
--- a/scripts/plot/util/pan.m
+++ b/scripts/plot/util/pan.m
@@ -76,6 +76,7 @@
       pm.Enable = "on";
     endif
     set (hfig, "__pan_mode__", pm);
+    update_mouse_mode (hfig, pm.Enable);
   elseif (nargs == 1)
     arg = varargin{1};
     if (ischar (arg))
@@ -94,17 +95,7 @@
               pm.Motion = "vertical";
           endswitch
           set (hfig, "__pan_mode__", pm);
-          if (strcmp (arg, "off"))
-            set (hfig, "__mouse_mode__", "none");
-          else
-            ## FIXME: Is there a better way other than calling these
-            ## functions to set the other mouse mode Enable fields to
-            ## "off"?
-            rotate3d ("off");
-            zoom ("off");
-            set (hfig, "__mouse_mode__", "pan");
-          endif
-
+          update_mouse_mode (hfig, arg);
         otherwise
           error ("pan: unrecognized option '%s'", arg);
       endswitch
@@ -115,3 +106,15 @@
 
 endfunction
 
+function update_mouse_mode (hfig, arg)
+  if (strcmp (arg, "off"))
+    set (hfig, "__mouse_mode__", "none");
+  else
+    ## FIXME: Is there a better way other than calling these
+    ## functions to set the other mouse mode Enable fields to
+    ## "off"?
+    rotate3d ("off");
+    zoom ("off");
+    set (hfig, "__mouse_mode__", "pan");
+  endif
+endfunction
--- a/scripts/plot/util/rotate3d.m
+++ b/scripts/plot/util/rotate3d.m
@@ -71,6 +71,7 @@
       rm.Enable = "on";
     endif
     set (hfig, "__rotate_mode__", rm);
+    update_mouse_mode (hfig, rm.Enable);
   elseif (nargs == 1)
     arg = varargin{1};
     if (ischar (arg))
@@ -83,17 +84,7 @@
               rm.Motion = "both";
           endswitch
           set (hfig, "__rotate_mode__", rm);
-          if (strcmp (arg, "off"))
-            set (hfig, "__mouse_mode__", "none");
-          else
-            ## FIXME: Is there a better way other than calling these
-            ## functions to set the other mouse mode Enable fields to
-            ## "off"?
-            pan ("off");
-            zoom ("off");
-            set (hfig, "__mouse_mode__", "rotate");
-          endif
-
+          update_mouse_mode (hfig, arg);
         otherwise
           error ("rotate3d: unrecognized option '%s'", arg);
       endswitch
@@ -104,3 +95,15 @@
 
 endfunction
 
+function update_mouse_mode (hfig, arg)
+  if (strcmp (arg, "off"))
+    set (hfig, "__mouse_mode__", "none");
+  else
+    ## FIXME: Is there a better way other than calling these
+    ## functions to set the other mouse mode Enable fields to
+    ## "off"?
+    pan ("off");
+    zoom ("off");
+    set (hfig, "__mouse_mode__", "rotate");
+  endif
+endfunction
--- a/scripts/plot/util/zoom.m
+++ b/scripts/plot/util/zoom.m
@@ -92,6 +92,7 @@
       zm.Enable = "on";
     endif
     set (hfig, "__zoom_mode__", zm);
+    update_mouse_mode (hfig, zm.Enable);
   elseif (nargs == 1)
     arg = varargin{1};
     if (isnumeric (arg))
@@ -141,29 +142,17 @@
               zm.Motion = "vertical";
           endswitch
           set (hfig, "__zoom_mode__", zm);
-          if (strcmp (arg, "off"))
-            set (hfig, "__mouse_mode__", "none");
-          else
-            ## FIXME: Is there a better way other than calling these
-            ## functions to set the other mouse mode Enable fields to
-            ## "off"?
-            pan ("off");
-            rotate3d ("off");
-            set (hfig, "__mouse_mode__", "zoom");
-          endif
-
+          update_mouse_mode (hfig, arg);
         case "out"
           cax = get (hfig, "currentaxes");
           if (! isempty (cax))
             __zoom__ (cax, "out");
           endif
-
         case "reset"
           cax = get (hfig, "currentaxes");
           if (! isempty (cax))
             __zoom__ (cax, "reset");
           endif
-
         otherwise
           error ("zoom: unrecognized option '%s'", arg);
       endswitch
@@ -174,6 +163,18 @@
 
 endfunction
 
+function update_mouse_mode (hfig, arg)
+  if (strcmp (arg, "off"))
+    set (hfig, "__mouse_mode__", "none");
+  else
+    ## FIXME: Is there a better way other than calling these
+    ## functions to set the other mouse mode Enable fields to
+    ## "off"?
+    pan ("off");
+    rotate3d ("off");
+    set (hfig, "__mouse_mode__", "zoom");
+  endif
+endfunction
 
 %!demo
 %! clf;