Borrar filtros
Borrar filtros

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

2 visualizaciones (últimos 30 días)
Jeff
Jeff el 7 de Mzo. de 2012
Comentada: KAE el 15 de Jun. de 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.

Respuestas (2)

Walter Roberson
Walter Roberson el 7 de Mzo. de 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 comentarios
Jeff
Jeff el 7 de Mzo. de 2012
drawnow did not change the result, but thanks for the idea.
KAE
KAE el 15 de Jun. de 2017
The documentation seems now to be here .

Iniciar sesión para comentar.


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

Categorías

Más información sobre Interactive Control and Callbacks en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by