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: Roarke Lynch <email@hidden>
- Date: Thu, 31 Aug 2000 07:42:41 -0400
On Tuesday, August 20, 2002, at 02:45 AM, James Farwell wrote:
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?
Thanks!
- James
It would seem to me that it would be beneficial to have the
containing view have this power and not just the objects within said
view. If your sketch objects were sub-classed NSViews I believe that you
could have them handle mouse events by adding them to the responder
chain though. But I don't think it's something that will really be that
useful, selecting more than one object at time is one thing that comes
to mind. Plus it would complicate the role of the view's objects. The
way I was looking at this when I recently did something similar was that
the objects themselves really don't need to know whether or not they are
selected/moved/etc... they should only need to know how to draw
themselves/minipulate how they draw/etc.... I would let their container
handle it's role of object layout, and the objects handle only what
concerns them directly.
Roarke Lynch
-------------------------------
email@hidden
_______________________________________________
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.