Re: force entire window redraw?
Re: force entire window redraw?
- Subject: Re: force entire window redraw?
- From: "Louis C. Sacha" <email@hidden>
- Date: Wed, 6 Oct 2004 03:45:04 -0700
Hello...
There are a couple of issues with your code that might be causing the problem.
The first problem was probably just a cut/paste/edit issue when you
were writing up the email, but in the doSignal method you seem to be
using both flashTimer and theTimer to refer to the NSTimer used for
the delay.
The second problem also has to do with the timer (and might also be
an editing issue), but your darkenDelay method should be darkenDelay:
and take the calling NSTimer as the argument. Otherwise your method
to restore the window will never be called (although as views are
redrawn they would appear to make the flash go away). You have the
selector correct in the line where you create the timer, but the
implemented method is incorrect.
- (void)darkenDelay:(NSTimer *)aTimer {...}
Also, you probably don't want to include the line where you send the
setViewsNeedsDisplay:TRUE message to the window in the doSignal
method where you are starting the flash since it may cause portions
of the window to redraw before the flash is completed.
Finally, you're doing a lot of extra work with getting the PDF data,
making the NSImage, compositing it, etc... that doesn't really seem
to be accomplishing anything. Essentially you are just causing the
whole window to redraw before the flash, and assuming there isn't
something else going on somewhere in your other code that is
preventing the window from being updated normally, it shouldn't be
necessary.
So, based on the code you had posted, you could do it something like this:
#define WINDOW_FLASH_INTERVAL 0.75
-(void)doSignal
{
/* ... */
if([defaults boolForKey:TAOFlashWindowKey] == YES)
{
[self flashContentsOfWindow:myWindow];
}
}
- (void)flashContentsOfWindow:(NSWindow *)aWindow
{
NSView *contentView = [aWindow contentView];
NSRect bounds = [contentView bounds];
[aWindow cacheImageInRect:bounds];
[contentView lockFocus];
[[[NSColor blackColor] colorWithAlphaComponent:0.8] set];
NSRectFillUsingOperation(bounds, NSCompositeSourceOver);
[contentView unlockFocus];
[aWindow flushWindow];
NSTimer *flashTimer = [NSTimer
timerWithTimeInterval:WINDOW_FLASH_INTERVAL target:self
selector:@selector(restoreFlashedWindowContents:) userInfo:aWindow
repeats:FALSE];
[[NSRunLoop currentRunLoop] addTimer:flashTimer
forMode:NSEventTrackingRunLoopMode];
[[NSRunLoop currentRunLoop] addTimer:flashTimer
forMode:NSDefaultRunLoopMode];
}
- (void)restoreFlashedWindowContents:(NSTimer *)aTimer
{
NSWindow *flashedWindow = [aTimer userInfo];
[flashedWindow restoreCachedImage];
[flashedWindow flushWindow];
/* uncomment the next line if you still have problems with
artifacts (see below) */
// [[flashedWindow contentView] setNeedsDisplay:TRUE];
}
Using this code to flash the window may still result in visual
artifacts if parts of the window are being redrawn while the flash is
taking place, although this seems to depend on how the offending
objects draw themselves. For example, one of the windows I was
testing the code with had a NSTextView, and the flashing cursor would
sometimes result in a few extra black pixels being left behind at the
cursor location, but otherwise all of the window's contents would be
returned to its original image.
The cause of the problem with the flashing cursor may also be the
cause of what is happening in the black areas of your window that
remain darkened after the flash. You can probably fix it by forcing
the content of the window to redraw after the flash has completed,
which you can do by sending the window's contentView a
setNeedsDisplay:TRUE message.
Hope that helps,
Louis
Hi, I'm performing a short dark "flash" on my NSWindow, but when I
restore the original cached image, it doesn't completely return to
its original state:
http://www.siddha.ca/~tao/darkened.jpg
any ideas on how to force it to return completely?
--
Louis C. Sacha
<email@hidden>
or <email@hidden>
_______________________________________________
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