Issues with CurrentPoint in R2021b
25 次查看(过去 30 天)
显示 更早的评论
I am trying to track some user clicks within an axes that lives within a uifigure.
I was originally using CurrentPoint from the axes object, but I started to notice that in certain scenarios, the coordinates of CurrentPoint did not seem to be correct for where the mouse event happened. I did as much investigating as I could and found a possible solution in looking at the event IntersectionPoint property.
I can effectively use the IntersectionPoint property of the event for mouse down and up events and I get coordiantes that very closely match where I was trying to click.
I need something like IntersectionPoint that can be used withn mouse motion callbacks because CurrentPoint is off by a significant amount.
Here is what I have in all of my callbacks:
cp = get(obj.Axes,'CurrentPoint');
ip = evt.IntersectionPoint;
fprintf('Current Point: (%g,%g)\nIntersection Point: (%g,%g)\n\n',cp(1,1),cp(1,2),ip(1,1),ip(1,2));
Then when I execute clicks, attempting to click near (11,1200) on the axes, I get the follwing:
Current Point: (10.9365,1376.74)
Intersection Point: (10.9782,1196.9)
8 个评论
Bruno Luong
2021-12-16
What if you call drawnow on top of your callback function? Also make sure the axes handle is the one you see on the screen, and not some hidden axes.
回答(1 个)
Benjamin Kraus
2021-12-16
We've seen issues in the past with CurrentPoint being slightly off, and we are investigating them. Can you provide a little more information about your particular setup and I'll add it to our internal report about this issue? Specifically:
- You said "CurrentPoint is off by a significant amount" but your reproduction steps show off by ~1 pixel. Have you experienced errors that are larger than 1 pixel before?
- In the code you posted you have an axes directly in a uifigure. Are you using anything else in the figure, like tabs, panels, uigridlayout, etc.? Is the axes always directly in the uifigure, or is it in another container inside the uifigure?
- Any reproduction code you have, with as much detail as you can include, will be helpful.
- Are you using the "Scrollable" feature of the uifigures?
- What platform are you using? Windows? Mac? Linux?
- What is the output from rendererinfo run on your axes?
- What is your screen resolution and pixel density?
7 个评论
Bruno Luong
2021-12-17
编辑:Bruno Luong
2021-12-17
FWIW, I test to plot both coordinates returned by CurrentPoint and IntersectionPoint on the same axes and in all the cases CurrentPoint can correctly follow the mouse and IntersectionPoint cannnot. That is fine with me as I use CurrentPoint currently. I'm in the opposite situation than you Matt.
Here is the function with plot. In my case the difference is 3 pixels for uifigure and 0.7 pixel for figure. CurrentPoint returns correct values as stated ealier.
function checkcperror(uiflag)
% uiflag: true to check uifigure; false old figure
if nargin < 1
uiflag = true;
end
close all
if uiflag
name = 'uifigure';
fig = uifigure('Name', name);
ax = uiaxes('Parent',fig);
else
name = 'figure';
fig = figure('Name', name);
ax = axes('Parent',fig);
end
fprintf('*** Check for %s ***\n', name)
h = plot(ax,nan(3,2),nan(3,2));
legend(h, 'IntersectionPoint', 'CurrentPoint');
axis(ax,[0 1 0 1]);
set(ax, 'Units','normalize', 'innerposition',[0 0 1 1]);
set(ax,'ButtonDownFcn',@(ax,event) chekerrorcb(ax,event,h));
text(ax,0.5,0.5,sprintf('%s click on the axes', name), ...
'HorizontalAlignment','center');
end
function chekerrorcb(ax, event, h)
drawnow
ip = event.IntersectionPoint(1,1:2);
cp = ax.CurrentPoint(1,1:2);
d = ip-cp;
ax.Units = 'pixel';
pos = get(ax,'innerposition');
dx = pos(3);
dy = pos(4);
dpxl = d.*[dx dy];
fprintf('error = %g pixel\n',norm(dpxl));
set(h(1),'XData',[get(h(1),'XData') ip(1)]);
set(h(1),'YData',[get(h(1),'YData') ip(2)]);
set(h(2),'XData',[get(h(2),'XData') cp(1)]);
set(h(2),'YData',[get(h(2),'YData') cp(2)]);
set(ax, 'Units','normalize', 'innerposition', [0 0 1 1]);
axis(ax,[0 1 0 1]);
drawnow
end
Stephane Lagace
2023-7-12
Hello I have the same problem only when the uiaxes is in a couple nested gridlayouts
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Develop uifigure-Based Apps 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!