Minor ITTStatusWindow changes.
[ITKit.git] / ITTransientStatusWindow.m
index 4182d57..ed587ff 100755 (executable)
@@ -5,6 +5,9 @@
 #import "ITGrayRoundedView.h"
 
 
+#define EFFECT_FPS 30.0
+
+
 /*************************************************************************/
 #pragma mark -
 #pragma mark EVIL HACKERY
            backgroundType:(ITTransientStatusWindowBackgroundType)backgroundType;
 - (void)rebuildWindow;
 - (void)performEffect;
-- (void)dissolveEffect:(BOOL)entering;
-- (void)slideVerticalEffect:(BOOL)entering;
-- (void)slideHorizontalEffect:(BOOL)entering;
+- (void)dissolveEffect;
+- (void)slideVerticalEffect;
+- (void)slideHorizontalEffect;
+- (void)pivotEffect;
+- (void)pivotStep;
+- (void)pivotFinish;
+- (void)setPivot:(float)angle;
 @end
 
 
@@ -69,10 +76,7 @@ static ITTransientStatusWindow *staticWindow = nil;
 {
     NSRect contentRect;
     
-    CGSValueObj         key;
-    CGSValueObj         ignore;
-
-    // If no Content View was provided, use a generic NSImageView with the app icon.
+    // If no Content View was provided, use a generic NSView with the app icon.
     if ( ! (contentView) ) {
         contentView = [[[NSView alloc] initWithFrame:
             NSMakeRect(100.0, 100.0, 200.0, 200.0)] autorelease];
@@ -86,17 +90,20 @@ static ITTransientStatusWindow *staticWindow = nil;
                                      backing:NSBackingStoreBuffered
                                        defer:NO] ) ) {
                                     
-        _visibilityState    = ITTransientStatusWindowHiddenState;
-        _exitMode           = exitMode;
-        _exitDelay          = DEFAULT_EXIT_DELAY;
-        _backgroundType     = backgroundType;
-        _verticalPosition   = ITTransientStatusWindowPositionBottom;
-        _horizontalPosition = ITTransientStatusWindowPositionLeft;
-        _entryEffect        = ITTransientStatusWindowEffectNone;
-        _exitEffect         = ITTransientStatusWindowEffectDissolve;
-        
-        _delayTimer = nil;
-        _fadeTimer  = nil;
+        _visibilityState     = ITTransientStatusWindowHiddenState;
+        _exitMode            = exitMode;
+        _exitDelay           = DEFAULT_EXIT_DELAY;
+        _backgroundType      = backgroundType;
+        _verticalPosition    = ITTransientStatusWindowPositionBottom;
+        _horizontalPosition  = ITTransientStatusWindowPositionLeft;
+//      _entryEffect         = ITTransientStatusWindowEffectNone;
+        _entryEffect         = ITTransientStatusWindowEffectPivot;
+        _exitEffect          = ITTransientStatusWindowEffectDissolve;
+        _effectTime          = DEFAULT_EFFECT_TIME;
+        _effectProgress      = 0.00;
+        _reallyIgnoresEvents = YES;
+        _delayTimer          = nil;
+        _effectTimer         = nil;
 
 //        if ( _backgroundType == ITTransientStatusWindowRounded ) {
 //            _contentSubView = contentView;
@@ -104,16 +111,7 @@ static ITTransientStatusWindow *staticWindow = nil;
 //            [self setContentView:contentView];
 //        }
 
-//      [self setIgnoresMouseEvents:YES];
-
-        key = CGSCreateCString("IgnoreForEvents");
-        ignore = CGSCreateBoolean(kCGSTrue);
-        
-        CGSSetWindowProperty([NSApp contextID], (CGSWindowID)[self windowNumber], key, ignore);
-
-        CGSReleaseObj(key);
-        CGSReleaseObj(ignore);
-        
+        [self setIgnoresMouseEvents:YES];
         [self setLevel:NSScreenSaverWindowLevel];
         [self setContentView:contentView];
         [self rebuildWindow];
@@ -127,27 +125,47 @@ static ITTransientStatusWindow *staticWindow = nil;
 #pragma mark INSTANCE METHODS
 /*************************************************************************/
 
-- (void)orderFront:(id)sender
+- (BOOL)ignoresMouseEvents
 {
-    if ( _exitMode = ITTransientStatusWindowExitAfterDelay ) {
-        // set the timer, and orderOut: when it lapses.
-    }
+    return _reallyIgnoresEvents;
+}
+
+- (void)setIgnoresMouseEvents:(BOOL)flag
+{
+    CGSValueObj         key;
+    CGSValueObj         ignore;
+
+    key = CGSCreateCString("IgnoreForEvents");
+    ignore = CGSCreateBoolean( (flag ? kCGSTrue : kCGSFalse) );
+    CGSSetWindowProperty([NSApp contextID], (CGSWindowID)[self windowNumber], key, ignore);
+    CGSReleaseObj(key);
+    CGSReleaseObj(ignore);
 
+    _reallyIgnoresEvents = flag;
+}
+
+- (void)orderFront:(id)sender
+{
     if ( _entryEffect == ITTransientStatusWindowEffectNone ) {
         [super orderFront:sender];
+        _visibilityState = ITTransientStatusWindowVisibleState;
     } else {
         [self performEffect];
     }
+    if ( _exitMode == ITTransientStatusWindowExitAfterDelay ) {
+        // set the timer, and orderOut: when it lapses.
+    }
 }
 
 - (void)makeKeyAndOrderFront:(id)sender
 {
-    if ( _exitMode = ITTransientStatusWindowExitAfterDelay ) {
+    if ( _exitMode == ITTransientStatusWindowExitAfterDelay ) {
         // set the timer, and orderOut: when it lapses.
     }
 
     if ( _entryEffect == ITTransientStatusWindowEffectNone ) {
         [super makeKeyAndOrderFront:sender];
+        _visibilityState = ITTransientStatusWindowVisibleState;
     } else {
         [self performEffect];
         [self makeKeyWindow];
@@ -158,11 +176,17 @@ static ITTransientStatusWindow *staticWindow = nil;
 {
     if ( _entryEffect == ITTransientStatusWindowEffectNone ) {
         [super orderOut:sender];
+        _visibilityState = ITTransientStatusWindowHiddenState;
     } else {
         [self performEffect];
     }
 }
 
+- (NSTimeInterval)animationResizeTime:(NSRect)newFrame
+{
+    return _effectTime;
+}
+
 /*
 
 - (id)contentView
@@ -194,7 +218,7 @@ static ITTransientStatusWindow *staticWindow = nil;
     return _visibilityState;
 }
 
-- (ITTransientStatusWindowExitMode)ExitMode
+- (ITTransientStatusWindowExitMode)exitMode
 {
     return _exitMode;
 }
@@ -294,39 +318,116 @@ static ITTransientStatusWindow *staticWindow = nil;
 - (void)performEffect
 {
     if ( _visibilityState == ITTransientStatusWindowHiddenState ) {
-        if ( _entryEffect == ITTransientStatusWindowEffectDissolve ) {
-            [self dissolveEffect:YES];
-        } else if ( _entryEffect == ITTransientStatusWindowEffectSlideVertically ) {
-            [self slideEffect:YES];
-        } else if ( _entryEffect == ITTransientStatusWindowEffectSlideHorizontally ) {
-            [self slideEffect:YES];
-        }
+        _visibilityState = ITTransientStatusWindowEnteringState;
     } else if ( _visibilityState == ITTransientStatusWindowVisibleState ) {
-        if ( _exitEffect == ITTransientStatusWindowEffectDissolve ) {
-            [self dissolveEffect:NO];
-        } else if ( _exitEffect == ITTransientStatusWindowEffectSlideVertically ) {
-            [self slideEffect:NO];
-        } else if ( _exitEffect == ITTransientStatusWindowEffectSlideHorizontally ) {
-            [self slideEffect:NO];
-        }
+        _visibilityState = ITTransientStatusWindowExitingState;
+    } else {
+        return;
+    }
+        
+    if ( _entryEffect == ITTransientStatusWindowEffectDissolve ) {
+        [self dissolveEffect];
+    } else if ( _entryEffect == ITTransientStatusWindowEffectSlideVertically ) {
+        [self slideVerticalEffect];
+    } else if ( _entryEffect == ITTransientStatusWindowEffectSlideHorizontally ) {
+        [self slideHorizontalEffect];
+    } else if ( _entryEffect == ITTransientStatusWindowEffectPivot ) {
+        [self pivotEffect];
     }
 }
 
-- (void)dissolveEffect:(BOOL)entering
+- (void)dissolveEffect
 {
-    
-    [super orderFront:self];
+    if ( _visibilityState == ITTransientStatusWindowEnteringState ) {
+        [super orderFront:self];
+        _visibilityState = ITTransientStatusWindowVisibleState;
+    } else {
+        [super orderOut:self];
+        _visibilityState = ITTransientStatusWindowHiddenState;
+    }
 }
 
-- (void)slideVerticalEffect:(BOOL)entering
+- (void)slideVerticalEffect
 {
-    [super orderFront:self];
+    if ( _visibilityState == ITTransientStatusWindowEnteringState ) {
+        [super orderFront:self];
+        _visibilityState = ITTransientStatusWindowVisibleState;
+    } else {
+        [super orderOut:self];
+        _visibilityState = ITTransientStatusWindowHiddenState;
+    }
 }
 
-- (void)slideHorizontalEffect:(BOOL)entering
+- (void)slideHorizontalEffect
 {
-    [super orderFront:self];
+    if ( _visibilityState == ITTransientStatusWindowEnteringState ) {
+        [super orderFront:self];
+        _visibilityState = ITTransientStatusWindowVisibleState;
+    } else {
+        [super orderOut:self];
+        _visibilityState = ITTransientStatusWindowHiddenState;
+    }
+}
+
+- (void)pivotEffect
+{
+    if ( _visibilityState == ITTransientStatusWindowEnteringState ) {
+        [self setPivot:315.0];
+        _effectProgress = 0.0;
+        [self setAlphaValue:0.0];
+        [super orderFront:self];
+        _effectTimer = [NSTimer scheduledTimerWithTimeInterval:(1.0 / EFFECT_FPS)
+                                                        target:self
+                                                      selector:@selector(pivotStep)
+                                                      userInfo:nil
+                                                       repeats:YES];
+    } else {
+        [super orderOut:self];
+        _visibilityState = ITTransientStatusWindowHiddenState;
+    }
 }
 
+- (void)pivotStep
+{
+    if ( _visibilityState == ITTransientStatusWindowEnteringState ) {
+        float interPivot = 0.0;
+        _effectProgress += (1.0 / (EFFECT_FPS * _effectTime));
+        _effectProgress = (_effectProgress < 1.0 ? _effectProgress : 1.0);
+        interPivot = (( sin((_effectProgress * pi) - (pi / 2)) + 1 ) / 2);
+        [self setPivot:((interPivot * 45) + 315)];
+        [self setAlphaValue:interPivot];
+        if ( _effectProgress >= 1.0 ) {
+            [self pivotFinish];
+        }
+    } else {
+        //backwards
+    }
+}
+
+- (void)pivotFinish
+{
+    if ( _visibilityState == ITTransientStatusWindowEnteringState ) {
+        [_effectTimer invalidate];
+        _effectTimer = nil;
+        _effectProgress = 0.0;
+        _visibilityState = ITTransientStatusWindowVisibleState;
+    } else {
+        //backwards
+    }
+}
+
+
+- (void)setPivot:(float)angle
+{
+    float degAngle = (angle * (pi / 180));
+    CGAffineTransform transform = CGAffineTransformMakeRotation(degAngle);
+    transform.tx = -32.0;
+    transform.ty = [self frame].size.height + 32.0;
+    CGSSetWindowTransform([NSApp contextID],
+                          (CGSWindowID)[self windowNumber],
+                          CGAffineTransformTranslate(transform,
+                                                     (([self frame].origin.x - 32.0) * -1),
+                                                     (([[self screen] frame].size.height - ([self frame].origin.y) + 32.0) * -1) ));
+}
 
 @end