Re: Drawing complex vector shapes
Re: Drawing complex vector shapes
- Subject: Re: Drawing complex vector shapes
- From: Shawn Erickson <email@hidden>
- Date: Mon, 1 Dec 2003 13:05:30 -0800
On Dec 1, 2003, at 12:05 PM, Matt Budd wrote:
Hi..
We're creating a vector drawing program, but we want to able to do
some pretty cool stuff with the vector paths (like gradients,
transparent fills, outlines, shadows). We got a prototype with the
complex drawing of all these shapes (using NSBezierPaths), but I was
wondering if anyone had information on the best way to do the specific
effects we're confronting right now:
Gradients: Seems like CGShading has what I need, but can I use this
to fill a NSBezierPath, or just a rect?
They can be used to fill any path. It uses the current clipping path
for a given graphics context. You can adjust the clipping path as
needed (hint CGContextClip or NSBezierPath's addClip / setClip) and
then use CGContextDrawShading (you can get the context, assuming one is
locked and focused, using [[NSGraphicsContext currentContext]
graphicsPort]).
The web doesn't have much in the way of sample code, so if anyone can
point me in the right direction (or some sample code), that'd be
great...
http://developer.apple.com/samplecode/Sample_Code/Graphics_2D/
Cocoa_CG_shading_demo.htm
...but I assume you saw that. It looks like it takes the simple route
of use rects for clipping.
Anyway the second half of the following page talks about how to clip
with a path, mix the two and cook at 350 for 20 minutes.
http://developer.apple.com/documentation/GraphicsImaging/Conceptual/
drawingwithquartz2d/dq_paths/index.html
Shadowing: Seems like an iterative repeating of the outline with a
shift of each iteration down and to the right and reduce it's opacity.
However, this would mean that for each shape, I'd fill it once, but
stroke it 6 times...inherent performance hit?
It is more likely that shadowing is done using shading between two
translated paths or some such thing, it obviously incurs some
additional processing but I doubt as bad as you outline. Note that come
10.3 NSShadow is now available in AppKit, if you didn't already know.
Much of the above has been discussed at WWDC (past and present). I
suggest viewing the sessions on ADC or grab a copy of the DVDs (sorry I
don't know the appropriate sessions off the top of my head).
Also, we're looking at possibly using cross-platform Qt
(http://www.trolltech.com) with OpenGL for the graphics (Qt's internal
graphic stuff is quite lacking). I was wondering if anyone had gone
down the route of using OpenGL for its 2D drawing effects, and if they
thought that was comparable to Cocoa/Quartz graphics (which I think
look amazing for the amount of code you have to write).
If you are targeting Mac OS X I would use Cocoa and Quartz because
their optimization (for various CPUs/GPUs), enhancement, etc. are at
the top of Apple's list. I would only use OpenGL is you know you have
performance issues and OpenGL addresses those... others would have to
answer that... I don't have experience in this area myself.
-Shawn
_______________________________________________
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.