Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion Groups
General
GeneralPortable MacsHardwareNetworking
Applications
Mac ApplicationsEudoraFirefox / MozillaInternet ExplorerOutlook ExpressMS OfficeEntourageExcelPowerPointWordVirtual PCMedia PlayerOther MS Products
Programming
Mac ProgrammingCodeWarriorPerl
Country Specific
Australian Mac GroupUK Mac Group

Mac Forum / Programming / Mac Programming / February 2005



Tip: Looking for answers? Try searching our database.

Handling mouse events in a view

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Snoopy Dogg - 23 Feb 2005 14:23 GMT
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

 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.