• 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: force entire window redraw?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: force entire window redraw?


  • Subject: Re: force entire window redraw?
  • From: "Louis C. Sacha" <email@hidden>
  • Date: Wed, 6 Oct 2004 13:06:39 -0700


Hello...

Someone mentioned the FunkyOverlayWindow sample code from Apple in another thread, which brings to mind another solution for flashing the window.

You can attach a partially transparent overlay window to the window being flashed, and then remove it after a short delay, creating a flash effect.

Since using an extra overlay window doesn't require any sort of drawing to be done in the window that is being "flashed", this solution will work well in situations where parts of the window are being redrawn during the flash, which causes problems for the other code (caching the window, doing temporary drawing, and then restoring).

On the other hand, this code (as written) won't look right when used with a textured (metal) window with rounded corners, since the overlay window will have the normal corners instead.


#define WINDOW_FLASH_INTERVAL 0.75

- (void)flashContentsOfWindow:(NSWindow *)aWindow
{
// set up overlay window to use for "flash"
NSWindow *flashOverlay = [[[NSWindow alloc] initWithContentRect:[aWindow contentRectForFrameRect:[aWindow frame]] styleMask:NSBorderlessWindowMask backing:NSBackingStoreBuffered defer:TRUE] autorelease];
[flashOverlay setOpaque:FALSE];
[flashOverlay setHasShadow:FALSE];
[flashOverlay setLevel:[aWindow level]];
[flashOverlay setIgnoresMouseEvents:YES];
[flashOverlay setBackgroundColor:[[NSColor blackColor] colorWithAlphaComponent:0.8]];

// show the overlay window and attach to original window
[flashOverlay orderFront:self];
[aWindow addChildWindow:flashOverlay ordered:NSWindowAbove];

// set up timer to remove overlay window after delay
NSTimer *flashTimer = [NSTimer timerWithTimeInterval:WINDOW_FLASH_INTERVAL target:self selector:@selector(restoreFlashedWindowContents:) userInfo:flashOverlay repeats:FALSE];
[[NSRunLoop currentRunLoop] addTimer:flashTimer forMode:NSEventTrackingRunLoopMode];
[[NSRunLoop currentRunLoop] addTimer:flashTimer forMode:NSDefaultRunLoopMode];
}

- (void)restoreFlashedWindowContents:(NSTimer *)aTimer
{
NSWindow *flashOverlay = [aTimer userInfo];
[[flashOverlay parentWindow] removeChildWindow:flashOverlay];
[flashOverlay orderOut:self];
}


Note that the flashOverlay window is being retained by the NSTimer (since it is passed as the userInfo parameter), so it's guaranteed to last until the timer has fired and the window is ordered out to end the flash effect.


Hope that helps,

Louis

_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden
  • Prev by Date: Re: Setuid bit set, but not running as root
  • Next by Date: Re: cocoa/obj-c type daemon
  • Previous by thread: Re: force entire window redraw?
  • Next by thread: Re: Cocoa-dev Digest, Vol 1, Issue 104
  • Index(es):
    • Date
    • Thread