필터 지우기
필터 지우기

'CurrentPoint' fails in GUI when function is called by 'ButtonDownFcn'

조회 수: 2 (최근 30일)
Jeff
Jeff 2012년 3월 7일
댓글: KAE 2017년 6월 15일
I have a GUI with an axis. I would like to be able to click and drag on the axis and have the start and end points detected in the units of the axis.
For a blank GUI with axes1 placed:
Code in OpeningFcn
% --- Executes just before currentpointtest is made visible.
function currentpointtest_OpeningFcn(hObject, eventdata, handles, varargin)
% Choose default command line output for currentpointtest
handles.output = hObject;
% Update handles structure
guidata(hObject, handles);
I = imread('cameraman.tif');
h = imshow(I, 'Parent', handles.axes1);
set(h, 'ButtonDownFcn', @getClicks)
Code in Callback:
function getClicks(~,~)
point1 = get(gca,'CurrentPoint') % button down detected
finalRect = rbbox; % return figure units
point2 = get(gca,'CurrentPoint') % button up detected
point1 is correct, but point2 returns the same value as point1. I need the values relative to the axes, so 'PointerLocation' doesn't seem like an option. Also as a side note, if the getClicks function is called from a push button everything works fine.
Does anyone know what is happening here and how I can get both point1 and point2?
Update(2012-03-07): I also tried the following:
function getClicks(~,~)
point1 = get(gca,'CurrentPoint') % button down detected
set(gcf, 'WindowButtonUpFcn', @upCall)
finalRect = rbbox; % return figure units
set(gcf, 'WindowButtonUpFcn', '')
point2 = get(gca,'CurrentPoint') % button up detected
function upCall(~,~)
upPoint = get(gca,'CurrentPoint')
This returns point1, then point2 (which is the same as point1) and finally upPoint (which is correct), in that order.

답변 (2개)

Walter Roberson
Walter Roberson 2012년 3월 7일
Read the section "CurrentPoint and Cursor Motion".
axes ButtonDownFcn is not one of the events that triggers CurrentPoint update.
You might be able to improve the situation by adding a drawnow() call after the rbbox .
  댓글 수: 2
Jeff
Jeff 2012년 3월 7일
drawnow did not change the result, but thanks for the idea.
KAE
KAE 2017년 6월 15일
The documentation seems now to be here .

댓글을 달려면 로그인하십시오.


Dirk Engel
Dirk Engel 2012년 10월 22일
Maybe the "Interruptible" property of the ancestor figure is set to "off". This was responsible for a missing update of the CurrentPoint in my case.

카테고리

Help CenterFile Exchange에서 Interactive Control and Callbacks에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by