Re: Drawing complex vector shapes
Re: Drawing complex vector shapes
- Subject: Re: Drawing complex vector shapes
- From: Matt Budd <email@hidden>
- Date: Mon, 1 Dec 2003 14:36:24 -0700
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]).
I figured as much, but couldn't find the sample code, and was getting
frustrated by a web search.
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
Perfect...thanks for the link, it was exactly what I was looking for...
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).
I'll take a look at that class -- NSShadow -- (and thanks for the link
C. Cox) and see what it has to offer. We have a line getting a copy of
the DVDs for this years WWDC, so hopefully they'll continue to point me
in the right direction.
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
I kinda agree. The Cocoa/Quartz stuff should work on all Macs with no
special hardware (like graphics cards). I was looking a bit into
OpenGL, and it seems a bit of an overkill for 2D shapes. It's like
trying to fit a really cool and powerful square into the same round
hole...
Thanks for your help. It totally helps to have people that not only
have the knowledge, but are willing to take the time to share it.
- Matt
_______________________________________________
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.