Right now I have two windows. One of them has an NSView, which acts as a background color and the other one has a colorwell that changes a color variable in a shared instance.
My program sort of works. I can open my colorwell window and select a color, but the background color only updates if I manually resize the window.
I tried to get past this issue by having a thread in the background looping:
[self setNeedsDisplay:YES];
[self updateLayer];
[self display];
I'm not completely sure that those 3 lines are necessary, but I am sure that they are re-calling my drawRect method.
I even threw an NSLog into the drawRect method to test. I saw in the console that it was getting called over-and-over again.
Here is my drawRect method:
- (void)drawRect:(NSRect)dirtyRect{
[theDATA.main_frame_background_color setFill];
[NSBezierPath fillRect:dirtyRect];
}
theDATA.main_frame_background_color
is an NSColor from a shared instance. I am positive that the value is changing because my NSView updates when I resize the window.
I'm completely clueless on why this is not working. Hope you can help.
display
method manually. Have you triedNSRectFill
instead of[NSBezierPath fillRect:]
? Have you checked if the color is really changed? – Sega-ZerolayerContentsRedrawPolicy
property toNSViewLayerContentsRedrawOnSetNeedsDisplay
? The default value isNSViewLayerContentsRedrawNever
. – Sega-ZerolayerContentsRedrawPolicy
was a start. I found out thatsetNeedsDisplay
wasn't thread safe for some crazy reason so I used an auxiliary method(as seen in my answer to this question). – Doug BeneyCALayer
's propertybackgroundColor
=) – Sega-Zero