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

1 vue (au cours des 30 derniers jours)
Jeff
Jeff le 7 Mar 2012
Commenté : KAE le 15 Juin 2017
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.

Réponses (2)

Walter Roberson
Walter Roberson le 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 .
  2 commentaires
Jeff
Jeff le 7 Mar 2012
drawnow did not change the result, but thanks for the idea.
KAE
KAE le 15 Juin 2017
The documentation seems now to be here .

Connectez-vous pour commenter.


Dirk Engel
Dirk Engel le 22 Oct 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.

Catégories

En savoir plus sur Interactive Control and Callbacks dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by