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>
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 mails | Author | Date |
|---|---|---|
| Hank Heijink | Feb 27, 20:40 | |
| Hank Heijink | Feb 27, 22:41 | |
| Kyle Sluder | Feb 28, 00:54 | |
| j o a r | Feb 28, 01:02 | |
| Chris Suter | Feb 28, 02:30 | |
| Hamish Allan | Feb 28, 17:45 | |
| Hank Heijink | Feb 28, 18:45 |






Cocoa mail archive

