How to update mouse position when button is pressed in gui.

조회 수: 3 (최근 30일)
Brian
Brian 2017년 8월 7일
답변: Brian 2017년 8월 11일
I'm trying to write a function for a gui, pretty much my own zoom function. I have most of it worked out aside from bounding it to the axis. I start it with an if so that it will only run when the mouse clicks inside the axis. The only problem is that when I press a button or checkbox, the mouse position isn't updated, so it senses the click but thinks that the mouse coordinates are inside the axis and it runs the function again. How can I fix this so that the function will only be run when I click inside the axis.
  댓글 수: 2
Adam
Adam 2017년 8월 7일
If you are using the 'CurrentPoint' property of the axes then this should return a value that is outside of the axes limits if the mouse is not on the axes when pressed.
Brian
Brian 2017년 8월 7일
I'm using the CurrentPoint property of the figure and comparing it to the position of the axes in the figure. I've tried using the CurrentPoint property of the axes, but I still have the same problem. If I click one of the checkboxes or a button, it calls the function because I clicked, but it doesn't update the CurrentPoint, instead, it returns the last value it found.

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

답변 (4개)

Walter Roberson
Walter Roberson 2017년 8월 7일
You might be able to take advantage of overobj()
  댓글 수: 1
Brian
Brian 2017년 8월 8일
I messed around with that but I can't get it to work with overobj

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


Akhilesh Thakur
Akhilesh Thakur 2017년 8월 8일
편집: Adam 2017년 8월 9일
Yes this problem happens it wont be updated as you are going through the callbacks of the button. The solution to this problem is update your mouse position in the callbacks itself. Also if you want to refer how to retreive the positions manually go through these links https://www.mathworks.com/matlabcentral/answers/142488-matlab-get-function-and-detecting-user-mouse-click https://www.mathworks.com/matlabcentral/newsreader/view_thread/22261
Hope this helps

Jan
Jan 2017년 8월 9일
You can try to determine the mouse position by Java:
MouseInfo = java.awt.MouseInfo.getPointerInfo();
Pos = MouseInfo.getLocation();
x = int32(Pos.getX());
y = int32(Pos.getY());
This is in screen coordinates and the conversion to the coordinates of the axes is not trivial. But the problems to identify the clicks on the uicontrol's reveals a general problem with your approach: It seems to be a design mistake, that the zoom function reacts to clicks on buttons. Either zooming is triggered by the ButtonDownFcn of the axes only, or it is unintuitive, because the user cannot know, which parts of the figure are allowed to start the zooming. Think twice if your current approach (using the WindowsButtonDownFcn ?) is really the direct solution of the job.

Brian
Brian 2017년 8월 11일
I figured out a good way to do it. I used 'gco' to get the handles of the object being called and used that to ignore clicks coming from any other objects.

카테고리

Help CenterFile Exchange에서 Migrate GUIDE Apps에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by