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

1 visualizzazione (ultimi 30 giorni)
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.

Risposte (2)

Walter Roberson
Walter Roberson il 7 Mar 2012
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 .

Dirk Engel
Dirk Engel il 22 Ott 2012
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.

Categorie

Scopri di più su Interactive Control and Callbacks in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by