Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
ButtonDownFcn Callback for Axes Objects

Subject: ButtonDownFcn Callback for Axes Objects

From: Thiago

Date: 25 Nov, 2008 07:33:04

Message: 1 of 12

For some reason, my ButtonDownFcn callback for an axes object is not responsive; no matter which mouse button I use. I'm running MATLAB 7 (R14). That feature should work the same way as it does with push buttons, don't you think? Your assistance is highly appreciated.

Thiago

Subject: ButtonDownFcn Callback for Axes Objects

From: Bruno Luong

Date: 25 Nov, 2008 07:51:04

Message: 2 of 12

"Thiago " <thiago@mathworks.com> wrote in message <ggg9ng$c4m$1@fred.mathworks.com>...
> For some reason, my ButtonDownFcn callback for an axes object is not responsive; no matter which mouse button I use. I'm running MATLAB 7 (R14). That feature should work the same way as it does with push buttons, don't you think? Your assistance is highly appreciated.
>
> Thiago

I believe because axes mouse might be hidden since figure mouse superimpose. Please check Parent figure properties.

Bruno

Subject: ButtonDownFcn Callback for Axes Objects

From: Steven Lord

Date: 25 Nov, 2008 16:55:57

Message: 3 of 12


"Thiago " <thiago@mathworks.com> wrote in message
news:ggg9ng$c4m$1@fred.mathworks.com...
> For some reason, my ButtonDownFcn callback for an axes object is not
> responsive; no matter which mouse button I use. I'm running MATLAB 7
> (R14). That feature should work the same way as it does with push buttons,
> don't you think? Your assistance is highly appreciated.

Do you have something else (like an image) on your axes? If so, change the
HitTest property of the image.

http://www.mathworks.com/support/solutions/data/1-1B03X.html?solution=1-1B03X

Did you PLOT on your axes between setting the ButtonDownFcn and attempting
to trigger it? If so, that would clear your ButtonDownFcn unless you used
HOLD ON to prevent it.

http://www.mathworks.com/support/solutions/data/1-3K8R2L.html?solution=1-3K8R2L

--
Steve Lord
slord@mathworks.com

Subject: ButtonDownFcn Callback for Axes Objects

From: Thiago

Date: 26 Nov, 2008 00:52:02

Message: 4 of 12

Steve,

Yes, I have images on my axes. Thank you for the suggestions, by the way. Unfortunately the problem is not completely resolved. I have results with set(gcf,'WindowButtonDownFcn', '...callback goes here....') inside the CreateFcn of an axis object. However, I can't do this for more than one axis object. For this reason, I may use push buttons instead.

PS: If you know a way to overcome this problem, please let me know.

Subject: ButtonDownFcn Callback for Axes Objects

From: Thiago

Date: 26 Nov, 2008 15:18:03

Message: 5 of 12

To make it clear, this is just about replacing buttons by graphics (while retaining the callback capability). It's because of the fact that every GUI may change appearance once you test it in different systems. If anyone knows how to do it, please let me know.

Subject: ButtonDownFcn Callback for Axes Objects

From: Malcolm Lidierth

Date: 26 Nov, 2008 17:02:02

Message: 6 of 12

Could you not test for what has been clicked upon in the WindowButtonDownFcn, e.g. using gca which should change when you click on a specific axes. Also there is the hittest() function - undocumented but returns the handle of the last object clicked on.
ML

Subject: ButtonDownFcn Callback for Axes Objects

From: Ryan Ollos

Date: 28 Nov, 2008 22:22:02

Message: 7 of 12

"Thiago " <thiago@mathworks.com> wrote in message <ggi6ji$n95$1@fred.mathworks.com>...
> Steve,
>
> Yes, I have images on my axes. Thank you for the suggestions, by the way. Unfortunately the problem is not completely resolved. I have results with set(gcf,'WindowButtonDownFcn', '...callback goes here....') inside the CreateFcn of an axis object. However, I can't do this for more than one axis object. For this reason, I may use push buttons instead.
>
> PS: If you know a way to overcome this problem, please let me know.

Get the position of the button click,
cp = get(gcf, 'CurrentPoint')
Get the Position properties of all of the the axes objects
Test if cp is within an axes object and execute code accordingly.

Subject: ButtonDownFcn Callback for Axes Objects

From: Ryan Ollos

Date: 30 Nov, 2008 11:49:02

Message: 8 of 12

"Malcolm Lidierth" <ku.ca.lck@htreidil.mloclam> wrote in message <ggjvea$sfh$1@fred.mathworks.com>...
> Could you not test for what has been clicked upon in the WindowButtonDownFcn, e.g. using gca which should change when you click on a specific axes. Also there is the hittest() function - undocumented but returns the handle of the last object clicked on.
> ML

I don't find that there is a hittest function (in r2008b), and the hittest property is different than what you are referring to, as someone mentioned earlier in this thread.

I think what you are referring to is: get(handle_figure, 'CurrentObject')

There is a thorough discussion and example of how to implement what Thiago describes (i.e. replacing buttons by graphics) in this book: http://www.mathworks.com/support/books/book13266.html.

Subject: ButtonDownFcn Callback for Axes Objects

From: Malcolm Lidierth

Date: 1 Dec, 2008 18:15:03

Message: 9 of 12

Ryan
The hittest() command is present in R2008b. It has been around for a long time although it is still undocumented. How it differs, if at all, from
get(gcf, 'CurrentObject') I do not know.
ML

Subject: ButtonDownFcn Callback for Axes Objects

From: Yair Altman

Date: 1 Dec, 2008 19:58:02

Message: 10 of 12

"Malcolm Lidierth" <ku.ca.lck@htreidil.mloclam> wrote in message <gh19j7$2o0$1@fred.mathworks.com>...
> Ryan
> The hittest() command is present in R2008b. It has been around for a long time although it is still undocumented. How it differs, if at all, from
> get(gcf, 'CurrentObject') I do not know.
> ML

If memory serves me and I'm not mistaken, the difference is that get(gcf, 'CurrentObject') returns the latest object selected, whereas hittest (and the semi-documented overobj function) return the topmost object beneath the mouse cursor, even if it has not been selected.

If you're interested in checking the current position in the WindowButtonMotionFcn callback, you should use either overobj() (which has some severe limitations, but is outside the scope here), hittest(), or get(gcf,'CurrentPoint') (note: CurrentPoint, not CurrentObject).

Yair Altman
UndocumentedMatlab.com (actual content sometime in the future...)

Subject: ButtonDownFcn Callback for Axes Objects

From: Jiro Doke

Date: 1 Dec, 2008 22:54:01

Message: 11 of 12

"Thiago " <thiago@mathworks.com> wrote in message <ggi6ji$n95$1@fred.mathworks.com>...
> Steve,
>
> Yes, I have images on my axes. Thank you for the suggestions, by the way. Unfortunately the problem is not completely resolved. I have results with set(gcf,'WindowButtonDownFcn', '...callback goes here....') inside the CreateFcn of an axis object. However, I can't do this for more than one axis object. For this reason, I may use push buttons instead.
>
> PS: If you know a way to overcome this problem, please let me know.

Why not use the ButtonDownFcn property for the axes, not the figure. Then each axes can have its own ButtonDownFcn behavior. Also, as Steve suggested, be sure to set the HitTest property of the images to 'off'.

jiro

Subject: ButtonDownFcn Callback for Axes Objects

From: Kenneth Eaton

Date: 2 Dec, 2008 01:55:03

Message: 12 of 12

"Thiago " <thiago@mathworks.com> wrote in message <ggjpbb$c5d$1@fred.mathworks.com>...
> To make it clear, this is just about replacing buttons by graphics (while retaining the callback capability). It's because of the fact that every GUI may change appearance once you test it in different systems. If anyone knows how to do it, please let me know.

Thiago,

I'm not totally sure of what you want, but it may be like what I did for rotating the camera in a game I posted to the FEX ("Staker"). The idea was this... I designed the WindowButtonDownFcn to look for clicks in the figure. I didn't use the ButtonDownFcn of the axes since the axes was actually not visible (and I don't remember it working in that case). It then checked the position of the mouse click relative to the position of the axes to see if it was inside it, and if so it took the appropriate action (left click = rotate, right click = pan, middle click = zoom). It could be expanded to work with multiple axes in the same figure if you needed it to. You can peek into the code for the game (although it is long) and in particular check out a couple key functions. I believe "mouse_game" may be one of them, but I don't remember offhand the naming convention I had for that older version since I've been working on a newer one.

If this sounds like the sort of behavior you want, check it out and I can give you more info about it as needed.

Ken

Tags for this Thread

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us