• 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
Re: Custom images with NSProgressIndicator
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Custom images with NSProgressIndicator


  • Subject: Re: Custom images with NSProgressIndicator
  • From: Chas Spillar <email@hidden>
  • Date: Tue, 21 Nov 2006 13:56:53 -0800
  • Thread-topic: Custom images with NSProgressIndicator

Thanks Alan,

I just ended up with the following (which is basically the same idea):

Created a class overriding NSView, since NSProgressIndicator didn't provide
for the functionality I needed.

After loading the images into an array "images" and setting index to 0, here
are the interesting parts:

- (void) changeImage:(id) sender
{
    if (animating) {
        [[self class] cancelPreviousPerformRequestsWithTarget:self
selector:@selector(changeImage:) object:nil];
        if (index < [images count] - 1) {
            index++;
        } else {
            index = 0;
        }
        [self performSelector:@selector(changeImage:) withObject:nil
afterDelay:0.1f];
        [self display];
    }
}

- (void)startAnimation:(id)sender
{
    if (!animating) {
        animating = YES;
        [self performSelector:@selector(changeImage:) withObject:nil
afterDelay:0.1f];
    }
}

- (void)stopAnimation:(id)sender
{
    if (animating) {
        animating = NO;
        [[self class] cancelPreviousPerformRequestsWithTarget:self
selector:@selector(changeImage:) object:nil];
    }
}

- (void) drawRect:(NSRect) aRect
{
    NSImage *image = [images objectAtIndex:index];
    [image drawInRect:aRect fromRect:NSMakeRect(0.0f, 0.0f, [image
size].width, [image size].height) operation:NSCompositeSourceOver
fraction:1.0f];
}

There is probably a simpler way to do this, but this seems to work for what
I needed.

Hey Cocoa Framework folks (Ali are you listening? ;->):
It is really unfortunate that NSProgressIndicator doesn't have a method
like:

- (void) setImages:(NSArray *) images;

Where you could just replace the images used in the animation.  Seems like a
trivial change in the framework that would enable this stuff easily without
any sub-classing.

Chas.


> From: Alan Smith <email@hidden>
> Date: Tue, 21 Nov 2006 16:37:38 -0500
> To: Chas Spillar <email@hidden>
> Cc: Cocoa Dev List <email@hidden>
> Subject: Re: Custom images with NSProgressIndicator
>
> It's simple. I'm making a theme kit (a framework to skin apps) and
> I've overriden NSProgressIndicator so I know how to help you. Here is
> the code:
>
> - (void)drawRect:(NSRect)rect
> {
> rect = [self bounds];
>
> // Do some spiffy drawing!
> }
>
> - (void)redrawWithTimer:(NSTimer*)timer
> {
> [self drawRect: NSZeroRect];
> }
>
> - (void)startAnimation:(id)sender
> {
> animationTimer = [[NSTimer scheduledTimerWithTimeInterval: 0.5
> target: self selector: @selector(redrawWithTimer:) userInfo: nil
> repeats: YES] retain];
> [animationTimer fire];
> }
> - (void)stopAnimation:(id)sender
> {
> [animationTimer invalidate];
> [animationTimer release];
> }
>
> There you go. And if you want to help me with my SkinKit let me know,
> I'd love help.
>
> Peace, Alan
>
> --
> // Quotes from yours truly -------------------------
> "You don't forget, you just don't remember."
> "Maturity resides in the mind."
> "Silence is the Universe's greatest gift."
> "When the World realizes that religion really is unnecessary, then it
> shall evolve."


 _______________________________________________

Cocoa-dev mailing list      (email@hidden)

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

References: 
 >Re: Custom images with NSProgressIndicator (From: "Alan Smith" <email@hidden>)

  • Prev by Date: Re: External kill of an NSThread?
  • Next by Date: Re: External kill of an NSThread?
  • Previous by thread: Re: Custom images with NSProgressIndicator
  • Next by thread: "-(BOOL)copyPath:(NSString *)source toPath:(NSString *)destination handler:(id)handler" doesnt work properly when file copied across network.
  • Index(es):
    • Date
    • Thread