Created
August 20, 2010 00:57
-
-
Save atr000/539334 to your computer and use it in GitHub Desktop.
flashscreen.m
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// flashscreen.m | |
// Command Utility | |
// | |
// Copyright Cucurbita. All rights reserved. | |
// | |
// gcc -framework AppKit flashscreen.m -o flashscreen | |
// gcc -DHAVE_WINDOW_FADE -framework AppKit flashscreen.m -o flashscreen | |
#import <AppKit/AppKit.h> | |
@interface flashscreenWindow : NSWindow { | |
} | |
@end | |
@implementation flashscreenWindow | |
- (id)initFullScreen | |
{ | |
if ((self = [super initWithContentRect:[[NSScreen mainScreen] frame] styleMask:NSBorderlessWindowMask backing:NSBackingStoreBuffered defer:NO])) { | |
[self setBackgroundColor: [NSColor whiteColor]]; | |
[self setLevel:CGShieldingWindowLevel()]; | |
#ifdef HAVE_WINDOW_FADE | |
[self setAlphaValue:0.0]; | |
#else | |
[self setAlphaValue:0.3]; | |
#endif | |
[self setOpaque:NO]; | |
[self setHasShadow:NO]; | |
} | |
return self; | |
} | |
@end | |
@interface flashscreenDelegate: NSObject { | |
flashscreenWindow *window; | |
} | |
@end | |
@implementation flashscreenDelegate | |
- (void)dealloc | |
{ | |
if (window) { | |
[window release]; | |
} | |
[super dealloc]; | |
} | |
- (void)applicationWillFinishLaunching:(NSNotification *)aNotification | |
{ | |
window = [[flashscreenWindow alloc] initFullScreen]; | |
[window makeKeyAndOrderFront:self]; | |
#ifdef HAVE_WINDOW_FADE | |
float alpha = 0.0; | |
int i = 0; | |
for (i = 0; i < 3; i++) { | |
alpha += 0.1; | |
[window setAlphaValue:alpha]; | |
[NSThread sleepForTimeInterval:0.040]; | |
} | |
for (i = 0; i < 6; i++) { | |
alpha -= 0.05; | |
[window setAlphaValue:alpha]; | |
[NSThread sleepForTimeInterval:0.020]; | |
} | |
[[NSApplication sharedApplication] terminate:self]; | |
#else | |
[NSTimer scheduledTimerWithTimeInterval:0.2 | |
target:self selector:@selector(terminateFlashScreen:) userInfo:nil repeats:NO]; | |
#endif | |
} | |
#ifndef HAVE_WINDOW_FADE | |
- (void)terminateFlashScreen:(NSTimer *)timer | |
{ | |
[timer invalidate]; | |
[[NSApplication sharedApplication] terminate:self]; | |
} | |
#endif | |
- (void)applicationWillTerminate:(NSNotification *)aNotification | |
{ | |
if (window) { | |
[window orderOut:self]; | |
} | |
} | |
@end | |
int main(int argc, const char **argv) | |
{ | |
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; | |
[[NSApplication sharedApplication] setDelegate:[flashscreenDelegate new]]; | |
[[NSApplication sharedApplication] run]; | |
[pool drain]; | |
return 0; | |
} | |
/* EOF */ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
https://github.com/cucurbita/inutero/tree/master/obj-C/FlashScreen