Re: erase then draw image?
Re: erase then draw image?
- Subject: Re: erase then draw image?
- From: Brock Brandenberg <email@hidden>
- Date: Thu, 24 Oct 2002 08:37:40 -0500
Hi Matt.
>
> I'm trying to do something very simple - draw a watermark
>
> (some transparent text, slightly rotated) into an NSView.
>
>
>
> My approach is to set up the text beforehand by drawing it
>
> into an NSImage. My NSView's coordinate system is slightly
>
> rotated. In my NSView's drawRect I then say simply:
>
>
>
> [image drawInRect: dest fromRect: wholeThing operation:
>
> NSCompositeSourceOver fraction:0.2];
>
>
>
> This works great except that every time drawInRect is
>
> called, my watermark gets darker and darker until finally
>
> it is opaque. It seems what I need to do is somehow flush
>
> or clear my NSView each time before I draw. But I can't
>
> find a command to do this: NSEraseRect fills it with
>
> white; drawing with clearColor fills it with black! How do
>
> I do it?
>
>
I never got an answer to this. I ended up doing it a completely different way
>
- using NSGraphicsContext, NSAffineTransform (to do the rotation), and a
>
transparent text color. But this does not explain, and I do not understand,
>
why my first way cannot be made to work. m.
You need to make sure that you override the isOpaque: method properly in
your view. This is the source of the problem. It is possible for you to have
a view that looks transparent and draws nothing but the text in the
drawwRect: method, but you need to have isOpaque: method overridden to
return NO so that Cocoa will trace down to the lowest object in the view
hierarchy and start drawing from there. What's happening is that Cocoa
thinks that your view is opaque and it's relying on you to draw every pixel.
If you want to keep doing this and simply draw what looks like a clear
background, use the [NSColor windowBackgroundColor]
Another thing to watch out for is overlapping views. If your views are not
completely contained within one another in the coordinate system, the view
hierarchy gets confused and drawing doesn't occur properly. This used to be
a problem but may not be anymore in Jag (haven't tested it again). I'm still
in the habit of making sure it never happens to start with in my code :)
Brock Brandenberg
----- industrial design @ www.bergdesign.com ------
_______________________________________________
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.