On 1 Jul 2008, at 04:23, Matt Orr wrote:

Hi guys!
I am very new to Cocoa, but not new to UNIX development. GUI programming is
new to me, and I am tackling it heavily ;)

I have a little assignment at work to create a simple application which
charts a bunch of processes, much like OmniGraffle (
http://www.omnigroup.com/applications/omnigraffle/). I was wondering how such graphing was implemented, and more importantly, where to read. I went through the 3rd edition of Cocoa Programming for Mac OS X, but I still dont
have any ideas on how to start implementing such a beast.
Can you please point me to potential topics and aspects of Cocoa I should
research? I have played a little bit with quartz, but it seems too
complicated (or is it?) of a solution for the simple thing I am trying to
achieve.

Any input is much appreciated!


Hi,

First, I totally recommend looking at DrawKit, which is a brilliant framework for interactive graphics.
I wish it had been around when I started writing SQLEditor.

Another thing to look at is the Apple Sketch example.

It might also be worth looking at whether you can use Graphviz code and display the result in a window as an image of some kind.


I have some thoughts, which may or may not prove useful:

Conceptually you have an application that might consist of a document window with a view that is a subclass of NSView in it. That view draws shapes (like rectangles and circles) and joins them together with lines.

You can implement the drawRect: method of your subclass and draw the objects there, which is fairly easy to do. (http://developer.apple.com/documentation/Cocoa/Conceptual/CocoaDrawingGuide )

If you just want to display the diagram and you don't need any interaction with your objects you could probably stop there.

Allowing interaction with the objects makes everything more complicated.

If you have interaction you will want to allow dragging (detect whether the mouse click is in the drag region of an object and move it with the mouse) and resizing (detect if the mouse is in the resize handle and then resize the object)

NSView (via its superclass NSResponder) has mouseDown: and mouseUp: methods that may help here. There are also methods for detecting mouse dragging.


The way that I structured my app was to have a canvas class (a subclass of NSView) and then "object views" which are drawn into the canvas, an object view knows how to draw itself into a suitable canvas object and the canvas object asks each object that is visible to draw itself when it gets a drawRect message.

If you have connectable objects you also need a mechanism to notify connectors that the objects they connect between have moved, so the connectors can update. An easy way of doing this is just to store pointers to the connected objects and send them messages directly, but notifications might work as well.

If you want to write code, the sketch sample may give some more examples

hope the project goes well!

Angus


--
Angus Hardie
[EMAIL PROTECTED]




_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to [EMAIL PROTECTED]

Reply via email to