Path: news.mathworks.com!not-for-mail
From: "Steven Lord" <slord@mathworks.com>
Newsgroups: comp.soft-sys.matlab
Subject: Re: Axes tools in GUI
Date: Tue, 1 Jul 2008 17:22:44 -0400
Organization: The MathWorks, Inc.
Lines: 94
Message-ID: <g4e775$pgn$1@fred.mathworks.com>
References: <g414n2$no7$1@fred.mathworks.com> <e432d979-f637-4ab4-aca0-cffe9372ee6e@g16g2000pri.googlegroups.com> <g4dmdi$a0u$1@fred.mathworks.com> <g4dmtv$h8f$1@fred.mathworks.com> <g4dp9g$l9p$1@fred.mathworks.com>
Reply-To: "Steven Lord" <slord@mathworks.com>
NNTP-Posting-Host: lords.dhcp.mathworks.com
X-Trace: fred.mathworks.com 1214947365 26135 144.212.105.187 (1 Jul 2008 21:22:45 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Tue, 1 Jul 2008 21:22:45 +0000 (UTC)
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 6.00.2900.3138
X-RFC2646: Format=Flowed; Original
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.3198
Xref: news.mathworks.com comp.soft-sys.matlab:476984




"David " <daviddoria@gmail.com> wrote in message 
news:g4dp9g$l9p$1@fred.mathworks.com...
> I'm not getting the "Invalid object handle" error.
>
> I set the 'HitTest' property of the things in the figure to
> 'off'.
>

I assume you set the axes ButtonDownFcn here, before the IMSHOW call?

> p = imshow(all my stuff);
> set(p, 'HitTest', 'off');
> cb = colorbar;
> set(cb, 'HitTest', 'off');
>
> but the axes1_ButtonDownFcm that guide made still does not
> get called.

The IMSHOW call, because the NextPlot property of the axes was set to the 
default value of 'replace', cleared most of the properties of the axes, 
including the ButtonDownFcn property.  That's the documented behavior of 
that property:

http://www.mathworks.com/access/helpdesk/help/techdoc/ref/axes_props.html#NextPlot

Look at this:

>> ax = gca;
>> set(ax, 'ButtonDownFcn', @(h, ev) disp('ButtonDownFcn invoked'))

% I clicked the axes twice
ButtonDownFcn invoked
ButtonDownFcn invoked

% I'll display a sample image from Image Processing Toolbox
l>> imshow('eight.tif');

% I clicked the axes several times, no display
>> get(ax, 'ButtonDownFcn')

ans =

     ''

Either set the NextPlot property of your axes to 'replacechildren' before 
calling IMSHOW or set your axes ButtonDownFcn after you call IMSHOW.

> I then tried setting the WindowButtonDownFcn. I had a bit
> more success. It was actually called, but then I have to
> manually handle whether or not the click was inside or
> outside the plot.  This seems to be more of a "hack" way to
> do it.
>
> To set the ButtonDownFcn of the object itself, what do I do?
> %my_plot_function.m
> p = imshow(stuff);
> set(p,'ButtonDownFcn', @GetClick(p.CurrentPoint) )
>
> where
> GetClick.m is simply
>
> function GetClick(MyPoint)
> disp(MyPoint)
>
> It says first "Invalid syntax" on the ( before
> p.CurrentPoint.  It also says "Too many input arguments
> using GetClick".

Correct, that's not valid syntax.  You tried using a combination of a 
regular function call and a function handle.  Instead, you can write your 
ButtonDownFcn as an anonymous function wrapper around a call to your 
function, if you want its signature to be different from the signature 
MATLAB expects for the ButtonDownFcn:

http://www.mathworks.com/access/helpdesk/help/techdoc/ref/axes_props.html#ButtonDownFcn

set(myAxes, 'ButtonDownFcn', @(h, eventdata) GetClick(p.CurrentPoint))

You can passthrough the h and eventdata input arguments with which MATLAB 
calls your ButtonDownFcn to the GetClick function, or you can ignore them. 
Those input arguments must be accepted by the function that gets called by 
MATLAB (in this case, the anonymous function accepts them, then ignores them 
and calls GetClick instead.)

For more information on these two arguments, take a look at:

http://www.mathworks.com/access/helpdesk/help/techdoc/creating_plots/f7-55506.html

-- 
Steve Lord
slord@mathworks.com