On Jan 2, 2011, at 10:36, Michael McLaughlin wrote:
> With Xcode 3.2.5 and the corresponding IB, I have a custom NSView into which
> I want to draw.
What you describe below doesn't entirely make sense, so perhaps you can clarify
a bit.
> This view has 15 static text views in front of it, in the contentView only,
> all of which are filled in before the custom drawing and none of which draw
> their own backgrounds.
In 10.5 and above, overlapping views that are non-opaque (return NO from
'isOpaque') will draw in back-to-front order. Opaque views can presumably draw
in any order (suitably clipped) -- so if they don't actually draw their
backgrounds you can expect oddities in the result. If the text views are
getting drawn *before* the custom view behind them, you probably need to
investigate why.
> The code for the custom drawing is
>
> -(void)drawRect:(NSRect)rect
> {
> [[NSColor blackColor] setStroke];
> [[NSColor whiteColor] setFill];
> [NSBezierPath fillRect:rect];
Code like this is almost certainly wrong (unless it's just for debugging
purposes). The 'rect' parameter can be any part of the view that needs
redrawing, so stroking the border of it will basically draw random rectangles
in your view.
> if (phase3) { // draw line
> NSBezierPath *path = [NSBezierPath bezierPath];
> [path moveToPoint:NSMakePoint(0, 0)];
> [path lineToPoint:NSMakePoint(520, 240)];
> [path stroke];
> }
> }
>
> This method is called three times during a complete rendering.
>
> Without the conditional (if statement), the result is as expected but, with
> it, the final (third) call to this method references a rect that does not
> correspond to anything in the window and the final window shows only a small
> portion of the line even though all of the superimposed text items should be
> transparent apart from their text.
It's not clear whether you mean you're deliberately arranging for the drawing
to be done 3 times (or what the 'phases' mean, or how 'phase3' is maintained).
It's also not clear, if 'rect' "does not correspond to anything in the window"
why you'd expect anything at all to appear, even disregarding the text views.
If in fact 'rect' is some part of the window, then it's not that surprising
that the line is clipped to the exterior of the text views, if the text views
are in fact logically opaque.
Putting this the other way round, if the text views are regarded by the drawing
system as opaque views, regardless of whether they *actually* draw their
backgrounds, the result would much as you've described.
_______________________________________________
Cocoa-dev mailing list ([email protected])
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]