hittest no longer works in 2015a with impoly

2 次查看(过去 30 天)
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.
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');
  1 个评论
Dan
Dan 2015-7-2
编辑:Walter Roberson 2016-3-27
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 %%%%

请先登录,再进行评论。

回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Images 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by