I'm going through a tutorial on drawing a custom [shaped] window with cocoa by subclassing NSWindow.
The tutorial states that in initializer developer should do the following:
[self setOpaque:NO];
[self setBackgroundColor:[NSColor clearColor]];
So i'm wondering what is the differnce between these two messages and why are they needed both since their result is the same.
References: tutorial can be found here.
I guess that the first message is required because the drawing system needs to know whether it should bother updating views that lie behind yours. For example, if a window in another application (behind your window) updates (say text appears etc) the windowing system would not normally need to redraw it, but since your window is transparent it does in this case.
So i'm wondering what is the differnce between these two messages and why are they needed both since their result is the same.
They're not the same.
Look at the documentation for the opaque
property: It's how you tell NSView that you're going to draw in your entire bounds, completely covering anything below your view.
If you don't cover the entire bounds, or you don't always draw at 100% opacity, then your view is not opaque, and you should leave that property set to NO
.
If you set your view's background color to clearColor
(which is simply a color with 0% opacity), and don't draw at 100% opacity over the entire background, then your view is not opaque.
On the other hand, it is possible to have clearColor
as your background and then completely draw over it, in which case your view is opaque and should set itself as such.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With