Re: JComponent-like functionality in Cocoa/Obj-C
Re: JComponent-like functionality in Cocoa/Obj-C
- Subject: Re: JComponent-like functionality in Cocoa/Obj-C
- From: Kyle Moffett <email@hidden>
- Date: Tue, 20 Aug 2002 10:55:32 -0400
On Tuesday, August 20, 2002, at 02:45 AM, James Farwell wrote:
Greetings all,
Sorry if this has already been covered but I didn't really have any
luck searching for it in the archives.
I want to write a custom view that is somewhat similar to those in
Sketch or OmniGraffle in that the user can manipulate objects in the
view by clicking them, dragging them around, etc. I have looked at the
Sketch example code which is very informative, but I was a little
miffed as to the way the actual event handling was done. In Sketch it
seems that the View catches all the mouse events, and then iterates
through the entire list of "graphics" until it finds one that
intersects with the click. This isn't terribly hard to understand, but
it seems a little tedious, almost like something that one would expect
"for free" with Cocoa. I was hoping to find some sort of interface
sort of like JComponent in Java/Swing whereby I could add an objects to
the view and things such as mouse events would automatically get passed
on to the object itself rather than me having to write my own little
event pump in the View. I was thinking that it might be possible to do
something like this using NSCell, but I'm still sort of new to Cocoa
and a little vague on some of these concepts. Does anybody have any
suggestions, or is the way Sketch does it basically the easiest way?
You could create MyDrawingView, then programmatically add other objects
as subviews, but because of the overhead associated NSViews and with
such a procedure, I would recommend that you take the time to create
your own DrawingObject class and just maintain an NSArray of them, then
iterate through. Try to come up with efficient bounds checking
operations though, especially if you are going to have lots of
DrawingObjects in the view.
HTH,
Kyle Moffett
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.