Skip navigation.
 
mlDrawing from secondary thread erases resize corner in window?
FROM : Hank Heijink
DATE : Wed Feb 27 20:40:40 2008

Hi list,

I have a window with a custom view that occupies the entire window, so 
the little resize corner in the lower right is within the bounds of 
the view. I noticed that when I draw into the window from the main 
thread (i.e. the usual way) that resize corner is redrawn when the 
view is redrawn. However, when I update the view from another thread, 
that doesn't happen. What am I missing?

I made a test app that just draws a black background in a custom view 
(MyCustomView) to show the problem. Here's the relevant code in the 
custom view:

- (void)drawFromSecondaryThread:(NSRect)rect
{
   [NSGraphicsContext saveGraphicsState];
   NSRectClip(rect);
   [[NSColor blackColor] set];
   NSRectFill(rect);
   [NSGraphicsContext restoreGraphicsState];
}

And in the object that has the view as an instance variable 
(MyCustomView *view). The method updateView is called from a repeating 
NSTimer that's attached to the run loop of the secondary thread.

- (void)updateView
{
   if (useSecondaryThread) {
       if ([view lockFocusIfCanDraw]) {
           [view drawFromSecondaryThread:view.bounds];
           [[view window] flushWindow];
           [view unlockFocus];
       }
   } else {
       [view setNeedsDisplay:YES];
   }
}

Thanks for any help!
Hank

Hank Heijink
hank.<email_removed>

Related mailsAuthorDate
mlDrawing from secondary thread erases resize corner in window? Hank Heijink Feb 27, 20:40
mlRe: Drawing from secondary thread erases resize corner in window? Hank Heijink Feb 27, 22:41
mlRe: Drawing from secondary thread erases resize corner in window? Kyle Sluder Feb 28, 00:54
mlRe: Drawing from secondary thread erases resize corner in window? j o a r Feb 28, 01:02
mlRe: Drawing from secondary thread erases resize corner in window? Chris Suter Feb 28, 02:30
mlRe: Drawing from secondary thread erases resize corner in window? Hamish Allan Feb 28, 17:45
mlRe: Drawing from secondary thread erases resize corner in window? [solved, for now] Hank Heijink Feb 28, 18:45