hittest no longer works in 2015a with impoly

4 views (last 30 days)
Dan on 1 Jul 2015
Edited: Walter Roberson on 27 Mar 2016
I had developed some code that works fine in version 2013 but not in 2015a.
My code allowed the user to draw a polygon using impoly and associate this polygon with some text (that I added using the "text" function and placed in the center of the polygon). I was annoyed to find that if the user wanted to move the polygon, they had to avoid clicking on the text since doing so would effectively block the call to the underlying polygon. HOWEVER... this was easily solved by setting the "hittest" property of text object" to "off". It worked GREAT! Until..... a new version of Matlab was released (not sure which one) but now my workaround no longer works! To be clear: executing the code below works fine in version 2013 (you can click on the word "DOH" and dragging it causes the polygon to move as well) but not in 2015.
  1 Comment
Dan on 2 Jul 2015
Edited: Walter Roberson on 27 Mar 2016
This was answered by The Mathworks so I thought I'd pass this along:
A “PickableParts” property was added to the “text” function in MATLAB R2015a. This property now has the ability to capture mouse clicks, while 'HitTest' handles the response to a click. In order to avoid capturing the mouse click on the text, set the “PickableParts” property of “text” to 'none' so that the click passes to the object (polygon).
Refer to the following code snippet with the required edit. Please note the added property “PickableParts” in the “text” function.
%%%%Code snippet start %%%%
I = imread('pout.tif');
hImage = imshow(I);
hImpoly = impoly;
a_iImpolyXY = getPosition(hImpoly);
a_fCentroid = mean(a_iImpolyXY);
hText = text(a_fCentroid(1), a_fCentroid(2), 'DOH', 'color', 'red', 'fontsize', 24, ...
'fontweight', 'bold', 'parent', gca, 'hittest', 'off', 'PickableParts', 'none');
%%%%Code snippet end %%%%

Sign in to comment.

Answers (0)


Find more on Environment and Settings in Help Center and File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!