CurrentPoint in UIFigure as a ginput workaround for App Designer

조회 수: 5 (최근 30일)
Matt_Z
Matt_Z 2018년 12월 12일
편집: Carl Lindquist 2019년 4월 18일
I trying to create a workaround to the lack of ginput functionality in the new App Designer UIFigure. The idea is to do the following:
  1. Use the CurrentPoint callback to register the pixel location
  2. Use pixel bounding box of axes InnerPosition and inpolygon to first confirm that click was within axes
  3. Convert CurrentPoint position to axes position based on scaling coordinates within axes and Xlim/Ylim properties
The issue I run into is the axes itself in the UIfigure appears to corrupt the CurrentPoint parameter. Using the image below to highlight the issue, for the UIFigure (with Position property = [312 336 1284 653]) I get the following 'CurrentPoint' results for the four locations shown:
  1. [191 140]
  2. [319 210]
  3. [1342 210]
  4. [911 152]
So it seems that Points 1 and 4, outside the UIAxes, are fine (i.e. line up well with the UIFigure Position property) but 2 and 3 are seemingly 'corrupted' (or rescaled).
Has anyone experienced this or knows that I might have wrong?
I am using Matlab 2018b
  댓글 수: 1
Carl Lindquist
Carl Lindquist 2019년 4월 18일
편집: Carl Lindquist 2019년 4월 18일
Sorry for being late to the party, ju might already have solved this...? In that case, how did you do it? If not, here as a suggestion!
Answer
I have a similar experience! I encountered this in a complied Web App, where it seems as if CurrentPoint returns the mouse position relative to the browser window only when inside the UIAxes, but relative the the lower left corner of the UIFigure elsewhere. I digged around in the undocumented properties for a while, but wasn't able to locate the size of the actual browser window. I'm sure it's in there somewhere though...
Do you experience this in an uncomplied app...? In that case, the following works for me. I set the WindowButtonMotionFcn callback and then poll the event.Source.CurrentPoint inside the callback to get the location of the pointer.
To just record the mouse click inside a UIAxes, one can do
ax = struct(app.UIAxes).Axes;
ax.ButtonDownFcn = @(h, e) click_selection(app);
...where click_selection is some callback function that one can define. Using struct() on an object might cause MATLAB to complain a bit, so if the warning annoys you, you can set
warning off MATLAB:structOnObject
to shut it up.

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

답변 (0개)

카테고리

Help CenterFile Exchange에서 Develop uifigure-Based Apps에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by