Hi,
What is the best way to handle mouse events inside of a view? For
example, I have an array of objects of various shape, size and location
which I draw in a view. I'll need to assign actions for mouse-overs and
clicks inside of the various objects. Does the view 'know' the
boundaries of my object when it is drawn, for example, a complex shape
with bezier curves, or do I need to write code that determines whether
a specific click-point is inside or outside of the shape? I'm mostly
interested in solving the problem in Objective-C/Cocoa. I've done this
in Java with simple shapes using contains(), though any additional
input on Java would be appreciated, too. Thanks.
Paul M.
Florian Zschocke - 23 Feb 2005 16:32 GMT
> Hi,
> What is the best way to handle mouse events inside of a view? For
[quoted text clipped - 7 lines]
> in Java with simple shapes using contains(), though any additional
> input on Java would be appreciated, too. Thanks.
First you should take a look to NSResponder Class. NSView inherits from
this class. All common mouse actions are defined there. In your custom
view you would overwrite
- (void)mouseMoved:(NSEvent *)theEvent
In this function you can ask the your objects if they contain
(NSBezierPath (BOOL)containsPoint:aPoint ) the point of your mouse
position (NSEvent mouseLocation).
Florian

Signature
This message was send with Xnntp - free Mac OSX (10.3) nntp-newsreader
Download Xnntp at http://www.edv-consulting-berlin.de/Xnntp.
David Phillip Oster - 23 Feb 2005 17:13 GMT
> What is the best way to handle mouse events inside of a view? For
> example, I have an array of objects of various shape, size and location
[quoted text clipped - 6 lines]
> in Java with simple shapes using contains(), though any additional
> input on Java would be appreciated, too. Thanks.
You might want to take a look at
<http://homepage.mac.com/mmalc/CocoaExamples/controllers.html>,
particularly
<http://homepage.mac.com/mmalc/CocoaExamples/GraphicsBindings.zip> for
some ideas.
You should also look at:
<file:///Developer/Examples/AppKit/Sketch/ToDo.txt> and the other
material in that "Sketch" folder.

Signature
David Phillip Oster
matt neuburg - 23 Feb 2005 17:25 GMT
> Hi,
> What is the best way to handle mouse events inside of a view? For
[quoted text clipped - 4 lines]
> with bezier curves, or do I need to write code that determines whether
> a specific click-point is inside or outside of the shape?
Well, both. You write the code, but if you write it in an
object-oriented fashion then the view will just "know". m.

Signature
matt neuburg, phd = matt@tidbits.com, http://www.tidbits.com/matt/
AppleScript: The Definitive Guide
http://www.amazon.com/exec/obidos/ASIN/0596005571/somethingsbymatt
Read TidBITS! It's free and smart. http://www.tidbits.com