changeset 24636:9d01ce02d5cb

Make selection and "HitTest" compatible with Matlab (bug #52795). * GLCanvas.cc (GLCanvas::selectFromAxes): Don't take "HitTest" into account during selection. * Canvas.cc (Canvas::canvasMousePressEvent): If the selected object has "HitTest"->"off" then replace it with the first ancestor with "HitTest"->"on" or fallback to empty matrix. * NEWS: Announce that HitTest property is now fully implemented.
author Pantxo Diribarne <pantxo.diribarne@gmail.com>
date Mon, 22 Jan 2018 16:46:59 +0100
parents b708857d634e
children 3d78a7eb5aa4
files NEWS libgui/graphics/Canvas.cc libgui/graphics/GLCanvas.cc
diffstat 3 files changed, 24 insertions(+), 5 deletions(-) [+]
line wrap: on
line diff
--- a/NEWS	Tue Jan 23 10:45:23 2018 +0100
+++ b/NEWS	Mon Jan 22 16:46:59 2018 +0100
@@ -74,7 +74,10 @@
 
  ** The graphic object property "Interruptible" has been fully
     implemented which controls whether a running callback function can
-    be interrupted by another callback function. 
+    be interrupted by another callback function.
+
+ ** The graphic object property "HitTest" has been updated to be fully
+    compatible with Matlab.
 
  ** Text objects now implement the properties "BackgroundColor",
     "EdgeColor", "LineStyle", "LineWidth", and "Margin".
--- a/libgui/graphics/Canvas.cc	Tue Jan 23 10:45:23 2018 +0100
+++ b/libgui/graphics/Canvas.cc	Mon Jan 22 16:46:59 2018 +0100
@@ -636,6 +636,20 @@
         // clicks.
         if (! currentObj.valid_object ())
           currentObj = figObj;
+        else if (! currentObj.get_properties ().is_hittest ())
+          {
+            // Objects with "hittest"->"off" pass the mouse event to their 
+            // parent and so on.
+            graphics_object tmpgo;
+            tmpgo = gh_manager::get_object (currentObj.get_parent ());
+            while (tmpgo && ! tmpgo.get_properties ().is_hittest ())
+              tmpgo = gh_manager::get_object (tmpgo.get_parent ());
+
+            if (tmpgo && tmpgo.get_handle () != 0.0)
+              currentObj = tmpgo;
+            else
+              currentObj = graphics_object ();
+          }
 
         if (axesObj)
           {
@@ -660,7 +674,8 @@
               // Update the figure "currentobject"
               auto& fprop = Utils::properties<figure> (figObj);
 
-              if (currentObj.get_properties ().handlevisibility_is ("on"))
+              if (currentObj 
+                  && currentObj.get_properties ().handlevisibility_is ("on"))
                 fprop.set_currentobject (currentObj.get_handle ()
                                          .as_octave_value ());
               else
@@ -678,13 +693,13 @@
                                          button_number (event));
 
               // Execute the "buttondownfcn" of the selected object
-              if (! currentObj.get ("buttondownfcn").isempty ())
+              if (currentObj && ! currentObj.get ("buttondownfcn").isempty ())
                 gh_manager::post_callback (currentObj.get_handle (),
                                            "buttondownfcn",
                                            button_number (event));
 
               // Show context menu of the selected object
-              if (event->button () == Qt::RightButton)
+              if (currentObj && event->button () == Qt::RightButton)
                 ContextMenu::executeAt (currentObj.get_properties (),
                                         event->globalPos ());
             }
--- a/libgui/graphics/GLCanvas.cc	Tue Jan 23 10:45:23 2018 +0100
+++ b/libgui/graphics/GLCanvas.cc	Mon Jan 22 16:46:59 2018 +0100
@@ -117,7 +117,8 @@
         octave::opengl_selector s;
 
         s.set_viewport (width (), height ());
-        return s.select (ax, pt.x (), height () - pt.y ());
+        return s.select (ax, pt.x (), height () - pt.y (), 
+                         octave::select_ignore_hittest);
       }
 
     return graphics_object ();