• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
clearing (not erasing) when drawing from a thread
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

clearing (not erasing) when drawing from a thread


  • Subject: clearing (not erasing) when drawing from a thread
  • From: m <email@hidden>
  • Date: Sun, 25 Nov 2007 15:57:10 -0800

Apologies in advance if this has already been answered. While questions similar to mine have been posted, I wasn't able to locate actual working answers.

On Tiger, when repeatedly drawing to a view from a thread, how do I "clear out" what I drew before? NSEraseRect() won't work as it erases to white. NSRectFillUsingOperation() with [NSColor clearColor] results in a black rect. Tricks like erasing to the background color won't work for me as there is no "the" background color (my drawing will be placed over an arbitrary and possibly changing background).

More details:

I'm trying to implement a busy indicator, much like the indeterminate version of NSProgressIndicator. I have a sequence of images that I draw from a thread thusly (this is a method of my NSView subclass and is called off the main thread):

- (void) animatorThreadWithImages:(NSArray*)images
{
   NSAutoreleasePool* pool = [[NSAutoreleasePool alloc]init];

while (animate)
{
if ([self lockFocusIfCanDraw])
{
NSImage* tiffImage = [images objectAtIndex:frameNumber]; // This is an image with transparency.
[tiffImage drawAtPoint:NSMakePoint(0, 0) fromRect:NSZeroRect operation:NSCompositeSourceOver fraction:1.0];


           [[NSGraphicsContext currentContext] flushGraphics];
           [self unlockFocus];
       }

       frameNumber = (frameNumber+1)%sFrameCount;

[NSThread sleepUntilDate:[NSDate dateWithTimeIntervalSinceNow: 0.05]];
}


   animating = NO;
   [pool release];
}

The problem is that successive frames of my image get composited on top of each other. Note that my busy indicator will be positioned over an arbitrary display, so tricks like erasing to the "background" color won't work.

_murat
_______________________________________________

Cocoa-dev mailing list (email@hidden)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden


  • Follow-Ups:
    • Re: clearing (not erasing) when drawing from a thread
      • From: Alastair Houghton <email@hidden>
  • Prev by Date: Re: NSWindow - Sheets - background alpha value
  • Next by Date: IKImageBrowser performance issues
  • Previous by thread: Re: [ABRecord setValue:forProperty:] with custom property?
  • Next by thread: Re: clearing (not erasing) when drawing from a thread
  • Index(es):
    • Date
    • Thread