hittest no longer works in 2015a with impoly

2 ビュー (過去 30 日間)
Dan
Dan 2015 年 7 月 1 日
編集済み: Walter Roberson 2016 年 3 月 27 日
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 Center および File ExchangeImages についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by