Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

More comments, better 10.6- compatibility code.

  • Loading branch information...
commit 9e020b0844284da13a92104d748cfced19309821 1 parent 2b4086d
@uliwitness authored
Showing with 54 additions and 11 deletions.
  1. +8 −4 NSWindow+ULIZoomEffect.h
  2. +46 −7 NSWindow+ULIZoomEffect.m
View
12 NSWindow+ULIZoomEffect.h
@@ -28,7 +28,11 @@
/*
This category implements a transition effect where a small thumbnail of the
window flies from the given rectangle to where the window is then shown,
- like when opening a folder window in Finder.
+ like when opening a folder window in Finder, plus a reverse variant for
+ ordering out a window.
+
+ It also implements another effect where the window just "pops", i.e. seems to
+ grow larger for a moment, like the highlight when you use the "Find" command.
*/
#import <AppKit/AppKit.h>
@@ -36,11 +40,11 @@
@interface NSWindow (ULIZoomEffect)
--(void) makeKeyAndOrderFrontWithPopEffect;
+-(void) makeKeyAndOrderFrontWithPopEffect; // Grab user's attention.
--(void) makeKeyAndOrderFrontWithZoomEffectFromRect: (NSRect)globalStartPoint;
+-(void) makeKeyAndOrderFrontWithZoomEffectFromRect: (NSRect)globalStartPoint; // Open window related to that rectangle.
-(void) orderFrontWithZoomEffectFromRect: (NSRect)globalStartPoint;
--(void) orderOutWithZoomEffectToRect: (NSRect)globalEndPoint;
+-(void) orderOutWithZoomEffectToRect: (NSRect)globalEndPoint; // Reverse of -orderFrontWithZoomEffectFromRect:
@end
View
53 NSWindow+ULIZoomEffect.m
@@ -25,16 +25,24 @@
// distribution.
//
-#import "NSWindow+ULIZoomEffect.h"
+// -----------------------------------------------------------------------------
+// Headers:
+// -----------------------------------------------------------------------------
+#import "NSWindow+ULIZoomEffect.h"
-#if MAC_OS_X_VERSION_MAX_ALLOWED <= MAC_OS_X_VERSION_10_6
// On 10.6 and lower, these 10.7 methods/symbols aren't declared, so we declare
// them here and call them conditionally when available:
// Otherwise 10.7's built-in animations get in the way of ours, which are cooler
// because they can come from a certain rectangle and thus convey information.
+#ifndef MAC_OS_X_VERSION_10_7
+#define MAC_OS_X_VERSION_10_7 1070
+#endif
+
+#if MAC_OS_X_VERSION_MAX_ALLOWED < MAC_OS_X_VERSION_10_7
+
typedef NSInteger NSWindowAnimationBehavior;
@interface NSWindow (ULITenSevenAnimationBehaviour)
@@ -44,8 +52,14 @@ -(NSWindowAnimationBehavior) animationBehavior;
@end
-#endif
+#endif // MAC_OS_X_VERSION_MAX_ALLOWED <= MAC_OS_X_VERSION_10_6
+
+
+// -----------------------------------------------------------------------------
+// ULIQuicklyAnimatingWindow:
+// -----------------------------------------------------------------------------
+// Window we use for our animations on which we can adjust the animation duration easily:
@interface ULIQuicklyAnimatingWindow : NSWindow
{
@@ -88,6 +102,8 @@ -(id) initWithContentRect:(NSRect)contentRect styleMask:(NSUInteger)aStyle backi
- (NSTimeInterval)animationResizeTime:(NSRect)newFrame
{
#if 0 && DEBUG
+ // Only turn this on temporarily for debugging. Otherwise it'll trigger for
+ // menu items that include the shift key, which is *not* what you want.
return ([[NSApp currentEvent] modifierFlags] & NSShiftKeyMask) ? (mAnimationResizeTime * 10.0) : mAnimationResizeTime;
#else
return mAnimationResizeTime;
@@ -97,8 +113,15 @@ - (NSTimeInterval)animationResizeTime:(NSRect)newFrame
@end
+// -----------------------------------------------------------------------------
+// NSWindow (ULIZoomEffect)
+// -----------------------------------------------------------------------------
+
@implementation NSWindow (ULIZoomEffect)
+// Calculate a sensible default start rect for the animation, depending on what
+// screen it is. We don't want the zoom to come from another screen by accident.
+
-(NSRect) uli_startRectForScreen: (NSScreen*)theScreen
{
NSRect screenBox = NSZeroRect;
@@ -128,6 +151,9 @@ -(NSRect) uli_startRectForScreen: (NSScreen*)theScreen
}
+// Create a "screen shot" of the given window which we use for our fake window
+// that we can animate.
+
-(NSImage*) uli_imageWithSnapshotForceActive: (BOOL)doForceActive
{
NSDisableScreenUpdates();
@@ -163,6 +189,8 @@ -(NSImage*) uli_imageWithSnapshotForceActive: (BOOL)doForceActive
}
+// Create a borderless window that shows and contains the given image:
+
-(NSWindow*) uli_animationWindowForZoomEffectWithImage: (NSImage*)snapshotImage
{
NSRect myFrame = [self frame];
@@ -190,12 +218,16 @@ -(NSWindow*) uli_animationWindowForZoomEffectWithImage: (NSImage*)snapshotImage
}
+// Effect like the "Find" highlight does, to grab user's attention (e.g when
+// bringing a window to front that was already visible but might have been
+// covered by other windows.
+
-(void) makeKeyAndOrderFrontWithPopEffect
{
BOOL haveAnimBehaviour = [NSWindow instancesRespondToSelector: @selector(animationBehavior)];
NSWindowAnimationBehavior oldAnimationBehaviour = haveAnimBehaviour ? [self animationBehavior] : 0;
if( haveAnimBehaviour )
- [self setAnimationBehavior: NSWindowAnimationBehaviorNone];
+ [self setAnimationBehavior: NSWindowAnimationBehaviorNone]; // Prevent system animations from interfering.
NSImage * snapshotImage = [self uli_imageWithSnapshotForceActive: YES];
NSRect myFrame = [self frame];
@@ -219,6 +251,9 @@ -(void) makeKeyAndOrderFrontWithPopEffect
}
+// Zoom the window out from a given rect, to indicate what it belongs to:
+// If the rect is tiny, we'll use a default starting rectangle.
+
-(void) makeKeyAndOrderFrontWithZoomEffectFromRect: (NSRect)globalStartPoint
{
if( globalStartPoint.size.width < 1 || globalStartPoint.size.height < 1 )
@@ -227,7 +262,7 @@ -(void) makeKeyAndOrderFrontWithZoomEffectFromRect: (NSRect)globalStartPoint
BOOL haveAnimBehaviour = [NSWindow instancesRespondToSelector: @selector(animationBehavior)];
NSWindowAnimationBehavior oldAnimationBehaviour = haveAnimBehaviour ? [self animationBehavior] : 0;
if( haveAnimBehaviour )
- [self setAnimationBehavior: NSWindowAnimationBehaviorNone];
+ [self setAnimationBehavior: NSWindowAnimationBehaviorNone]; // Prevent system animations from interfering.
NSImage * snapshotImage = [self uli_imageWithSnapshotForceActive: YES];
NSRect myFrame = [self frame];
@@ -248,6 +283,8 @@ -(void) makeKeyAndOrderFrontWithZoomEffectFromRect: (NSRect)globalStartPoint
}
+// Same as -makeKeyAndOrderFrontWithZoomEffectFromRect: But doesn't make the window key:
+
-(void) orderFrontWithZoomEffectFromRect: (NSRect)globalStartPoint
{
if( globalStartPoint.size.width < 1 || globalStartPoint.size.height < 1 )
@@ -256,7 +293,7 @@ -(void) orderFrontWithZoomEffectFromRect: (NSRect)globalStartPoint
BOOL haveAnimBehaviour = [NSWindow instancesRespondToSelector: @selector(animationBehavior)];
NSWindowAnimationBehavior oldAnimationBehaviour = haveAnimBehaviour ? [self animationBehavior] : 0;
if( haveAnimBehaviour )
- [self setAnimationBehavior: NSWindowAnimationBehaviorNone];
+ [self setAnimationBehavior: NSWindowAnimationBehaviorNone]; // Prevent system animations from interfering.
NSImage * snapshotImage = [self uli_imageWithSnapshotForceActive: NO];
NSRect myFrame = [self frame];
@@ -277,6 +314,8 @@ -(void) orderFrontWithZoomEffectFromRect: (NSRect)globalStartPoint
}
+// The reverse of -makeKeyAndOrderFrontWithZoomEffectFromRect:
+
-(void) orderOutWithZoomEffectToRect: (NSRect)globalEndPoint
{
if( globalEndPoint.size.width < 1 || globalEndPoint.size.height < 1 )
@@ -285,7 +324,7 @@ -(void) orderOutWithZoomEffectToRect: (NSRect)globalEndPoint
BOOL haveAnimBehaviour = [NSWindow instancesRespondToSelector: @selector(animationBehavior)];
NSWindowAnimationBehavior oldAnimationBehaviour = haveAnimBehaviour ? [self animationBehavior] : 0;
if( haveAnimBehaviour )
- [self setAnimationBehavior: NSWindowAnimationBehaviorNone];
+ [self setAnimationBehavior: NSWindowAnimationBehaviorNone]; // Prevent system animations from interfering.
NSImage * snapshotImage = [self uli_imageWithSnapshotForceActive: NO];
NSRect myFrame = [self frame];
Please sign in to comment.
Something went wrong with that request. Please try again.