Cocoa Drawing Problems.
-
Hello,
Okay my first programming week with Cocoa is over. Everything works
very well except the drawing code i have to port. The Cocoa Layer
seems to be really huge, especially if you want to output just
a few ISO-8859-1 strings and some rectangles.
When i draw Text strings with "NSString drawAtPoint:" this is not
drawn in the same coordinate space as the bezier paths, subviews.
How can i convert this coordinates?
I also worry a little about using a NSBezierPath object for every
single line i draw. Can i reuse the object after a stroke/fill?
And i couldn't get a single pixel line. Setting line width argument
to 0 for a bezier path seem to not work (X11 and Win32 use the
smallest phyiscal line width - one pixel - when setting it to 0).
My only requirement is to draw a few lines, rectangles and text
strings without any eye candy 2D stuff what ist the best Technology.
I'm really considering to use very old Carbon code for the drawing
and use Coca for all the other stuff. The frustration about the text
system made me think about Cairo but this is even more overhead.
--
Best regards,
Lothar mailto:<llothar...> -
On Sat, 3 Jan 2009 22:07:39 +0100, Lothar Scholz wrote:
> And i couldn't get a single pixel line. Setting line width argument
> to 0 for a bezier path seem to not work (X11 and Win32 use the
Bezier paths are drawn on grid lines, not at the center of pixels.
So make sure you are drawing from .5 to 1.5 for one pixel line.
There is some discussion about this at:
<http://www.cocoadev.com/index.pl?NSBezierPath>
HTH
W. -
On 3 Jan 2009, at 10:07 PM, Lothar Scholz wrote:
> Hello,
>
> Okay my first programming week with Cocoa is over. Everything works
> very well except the drawing code i have to port. The Cocoa Layer
> seems to be really huge, especially if you want to output just
> a few ISO-8859-1 strings and some rectangles.
>
> When i draw Text strings with "NSString drawAtPoint:" this is not
> drawn in the same coordinate space as the bezier paths, subviews.
> How can i convert this coordinates?
>
It /is/ using the same coordinate system. Of course only when you're
drawing in the same view, because each view has its own coordinate
system. But string drawing is also affected by layout options you pass
to it, which may cause it to be drawn in a bit different place than
you may naively expect.
> I also worry a little about using a NSBezierPath object for every
> single line i draw. Can i reuse the object after a stroke/fill?
>
You can reuse an NSBezierPath. Of course being the same path, it will
be drawn in the same place, so that may be not so useful. Though you
can move the path using NSAffineTransform.
> And i couldn't get a single pixel line. Setting line width argument
> to 0 for a bezier path seem to not work (X11 and Win32 use the
> smallest phyiscal line width - one pixel - when setting it to 0).
>
> My only requirement is to draw a few lines, rectangles and text
> strings without any eye candy 2D stuff what ist the best Technology.
> I'm really considering to use very old Carbon code for the drawing
> and use Coca for all the other stuff. The frustration about the text
> system made me think about Cairo but this is even more overhead.
>
If you're in Cocoa you should use Cocoa code for drawing, especially
for such relatively simple and standard drawing as lines and text.
Text drawing in Cocoa is (more or less) consistent, while Carbon will
probably use slightly different layout options. Also, I fail to see
why Carbon drawing is easier, quite the opposite IMHO.
Christiaan
> --
> Best regards,
> Lothar mailto:<llothar...>
>
> _______________________________________________
> MacOSX-dev mailing list
> <MacOSX-dev...>
> http://www.omnigroup.com/mailman/listinfo/macosx-dev
-
On 03.01.2009, at 22:07, Lothar Scholz wrote:
> When i draw Text strings with "NSString drawAtPoint:" this is not
> drawn in the same coordinate space as the bezier paths, subviews.
> How can i convert this coordinates?
Tell us what you're doing. Everything you draw from the same view
uses the same coordinate system. What you're saying doesn't make
sense, so there's probably something you aren't telling us that you're
doing to bring this pain upon yourself.
> I also worry a little about using a NSBezierPath object for every
> single line i draw. Can i reuse the object after a stroke/fill?
You're aware that NSBezierPath has some primitive methods for
drawing a line with the strokeLineFromPoint:toPoint: class method,
right? I don't know whether it's implemented that way, but at least it
doesn't include the hassle of writing the code to create a new object
each time.
That said, don't worry about that part now. Write the code with
NSBezierPath, then if that doesn't give the necessary peformance
*after* profiling, it's a simple regex search-and-replace to change
the code to use the lower-level (and slightly more complicated)
CoreGraphics API calls.
> And i couldn't get a single pixel line. Setting line width argument
> to 0 for a bezier path seem to not work (X11 and Win32 use the
> smallest phyiscal line width - one pixel - when setting it to 0).
You're drawing between pixels instead of on pixels, common mistake.
> I'm really considering to use very old Carbon code for the drawing
> and use Coca for all the other stuff.
Text in Cocoa is easy if you do it right, you don't want to try
using the Carbon code. For one thing, QuickDraw's been deprecated and
Apple may kill it off soon, and second Classic-style text drawing has
some gaps that will bite you later if you ever go to localize to non-
Roman languages. Quartz text drawing has its own issues. The only
thing that might save you some pain might be CoreText, but really,
start with Cocoa, I'm sure you'll like it after a while.
That said, this assumes you have a typical use-case. Unless you tell
us what you're planning to do with the lines, boxes and text, it's
hard to give a good recommendation. If this is for an FPS game, OpenGL
might be better, or for 2D games CoreAnimation can help. And you may
get better or worse results by using text views, custom views that
draw lines and boxes, or by doing it all in one or a few big views
(setNeedsDisplayInRect: and the dirty rect parameter passed to
drawRect: are your friends).
Cheers,
-- Uli Kusterer
"The Witnesses of TeachText are everywhere..."
http://www.zathras.de



