forked from MrNoodle/NoodleKit
-
Notifications
You must be signed in to change notification settings - Fork 0
/
NSWindow-NoodleEffects.m
158 lines (125 loc) · 4.66 KB
/
NSWindow-NoodleEffects.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
//
// NSWindow-Zoom.m
// NoodleKit
//
// Created by Paul Kim on 6/18/07.
// Copyright 2007-2009 Noodlesoft, LLC. All rights reserved.
//
// Permission is hereby granted, free of charge, to any person
// obtaining a copy of this software and associated documentation
// files (the "Software"), to deal in the Software without
// restriction, including without limitation the rights to use,
// copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the
// Software is furnished to do so, subject to the following
// conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
// OTHER DEALINGS IN THE SOFTWARE.
//
#import "NSWindow-NoodleEffects.h"
#import <Carbon/Carbon.h>
@implementation NSWindow (NoodleEffects)
- (void)animateToFrame:(NSRect)frameRect duration:(NSTimeInterval)duration
{
NSViewAnimation *animation;
animation = [[NSViewAnimation alloc] initWithViewAnimations:
[NSArray arrayWithObject:[NSDictionary dictionaryWithObjectsAndKeys:
self, NSViewAnimationTargetKey,
[NSValue valueWithRect:frameRect], NSViewAnimationEndFrameKey, nil]]];
[animation setDuration:duration];
[animation setAnimationBlockingMode:NSAnimationBlocking];
[animation setAnimationCurve:NSAnimationLinear];
[animation startAnimation];
[animation release];
}
- (NSWindow *)_createZoomWindowWithRect:(NSRect)rect
{
NSWindow *zoomWindow;
NSImageView *imageView;
NSImage *image;
NSRect frame;
BOOL isOneShot;
frame = [self frame];
isOneShot = [self isOneShot];
if (isOneShot)
{
[self setOneShot:NO];
}
if ([self windowNumber] <= 0)
{
CGFloat alpha;
// Force creation of window device by putting it on-screen. We make it transparent to minimize the chance of
// visible flicker.
alpha = [self alphaValue];
[self setAlphaValue:0.0];
[self orderBack:self];
[self orderOut:self];
[self setAlphaValue:alpha];
}
image = [[NSImage alloc] initWithSize:frame.size];
[image lockFocus];
// Grab the window's pixels
NSCopyBits([self gState], NSMakeRect(0.0, 0.0, frame.size.width, frame.size.height), NSZeroPoint);
[image unlockFocus];
[image setDataRetained:YES];
[image setCacheMode:NSImageCacheNever];
zoomWindow = [[NSWindow alloc] initWithContentRect:rect styleMask:NSBorderlessWindowMask backing:NSBackingStoreBuffered defer:NO];
[zoomWindow setBackgroundColor:[NSColor colorWithDeviceWhite:0.0 alpha:0.0]];
[zoomWindow setHasShadow:[self hasShadow]];
[zoomWindow setLevel:[self level]];
[zoomWindow setOpaque:NO];
[zoomWindow setReleasedWhenClosed:YES];
[zoomWindow useOptimizedDrawing:YES];
imageView = [[NSImageView alloc] initWithFrame:[zoomWindow contentRectForFrameRect:frame]];
[imageView setImage:image];
[imageView setImageFrameStyle:NSImageFrameNone];
[imageView setImageScaling:NSScaleToFit];
[imageView setAutoresizingMask:NSViewWidthSizable|NSViewHeightSizable];
[zoomWindow setContentView:imageView];
[image release];
[imageView release];
// Reset one shot flag
[self setOneShot:isOneShot];
return zoomWindow;
}
- (void)zoomOnFromRect:(NSRect)startRect
{
NSRect frame;
NSWindow *zoomWindow;
if ([self isVisible])
{
return;
}
frame = [self frame];
zoomWindow = [self _createZoomWindowWithRect:startRect];
[zoomWindow orderFront:self];
[zoomWindow animateToFrame:frame duration:[zoomWindow animationResizeTime:frame] * 0.4];
[self makeKeyAndOrderFront:self];
[zoomWindow close];
}
- (void)zoomOffToRect:(NSRect)endRect
{
NSRect frame;
NSWindow *zoomWindow;
frame = [self frame];
if (![self isVisible])
{
return;
}
zoomWindow = [self _createZoomWindowWithRect:frame];
[zoomWindow orderFront:self];
[self orderOut:self];
[zoomWindow animateToFrame:endRect duration:[zoomWindow animationResizeTime:endRect] * 0.4];
[zoomWindow close];
}
@end