-
Notifications
You must be signed in to change notification settings - Fork 54
/
Copy pathFullScreener_Transition.m
353 lines (301 loc) · 11.4 KB
/
FullScreener_Transition.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
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
//
// Movist
//
// Copyright 2006 ~ 2008 Yong-Hoe Kim. All rights reserved.
// Yong-Hoe Kim <[email protected]>
//
// This file is part of Movist.
//
// Movist is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 3 of the License, or
// (at your option) any later version.
//
// Movist is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
//
#import "FullScreener.h"
#import "MMovie.h"
#import "MMovieView.h"
#import "MainWindow.h"
#import "FullWindow.h"
@implementation FullScreener (Transition)
- (void)showMainMenuAndDock
{
if (_mainMenuAndDockIsHidden) {
SetSystemUIMode(_normalSystemUIMode, _normalSystemUIOptions);
_mainMenuAndDockIsHidden = FALSE;
}
}
- (void)hideMainMenuAndDock
{
// if currently in menu-bar-screen, hide system UI elements(main-menu, dock)
NSScreen* menuBarScreen = [[NSScreen screens] objectAtIndex:0];
if (_blackScreenFader || [[_mainWindow screen] isEqualTo:menuBarScreen]) {
// if cursor is in dock, move cursor out of dock area to hide dock.
NSRect rc = [menuBarScreen visibleFrame];
NSPoint p = [NSEvent mouseLocation];
if (!NSPointInRect(p, rc)) {
float margin = 20; // some margin needed
if (p.x < NSMinX(rc)) { // left-side dock
p.x = NSMinX(rc) + margin;
}
else if (NSMaxX(rc) <= p.x) { // right-side dock
p.x = NSMaxX(rc) - margin;
}
else if (p.y < NSMinY(rc)) { // bottom-side dock
p.y = NSMinY(rc) + margin;
}
// TODO: fix
// CGDisplayMoveCursorToPoint([_movieView displayID],
// CGPointMake(p.x, NSMaxY(rc) - p.y));
}
GetSystemUIMode(&_normalSystemUIMode, &_normalSystemUIOptions);
if (_autoShowDock) {
SetSystemUIMode(kUIModeAllSuppressed, 0);
}
else {
SetSystemUIMode(kUIModeAllHidden, kUIOptionAutoShowMenuBar);
}
_mainMenuAndDockIsHidden = TRUE;
}
}
- (void)attachMovieViewToFullWindow
{
[_movieView removeFromSuperviewWithoutNeedingDisplay];
[_fullWindow setMovieView:_movieView];
if ([_fullWindow level] == DesktopWindowLevel) {
[_fullWindow orderBack:nil];
[_fullWindow makeKeyWindow];
}
else {
[_fullWindow makeKeyAndOrderFront:nil];
}
}
- (void)detachMovieViewFromFullWindow
{
// move _movieView to _mainWindow from _fullWindow
[_movieView removeFromSuperviewWithoutNeedingDisplay];
[[_mainWindow contentView] addSubview:_movieView];
[_movieView setFrame:_movieViewRect];
[_movieView updateMovieRect:FALSE];
[_mainWindow makeFirstResponder:_movieView];
[_mainWindow makeKeyAndOrderFront:nil];
[_mainWindow setHasShadow:TRUE];
}
- (void)beginFullScreenFromDesktopBackground
{
[self hideMainMenuAndDock];
[NSCursor setHiddenUntilMouseMoves:TRUE];
[_fullWindow setLevel:NSNormalWindowLevel];
[_fullWindow makeKeyAndOrderFront:nil];
}
- (void)endFullScreenToDesktopBackground
{
[_fullWindow setLevel:DesktopWindowLevel];
[_fullWindow orderBack:nil];
[_fullWindow makeKeyWindow];
[NSCursor setHiddenUntilMouseMoves:FALSE];
[self showMainMenuAndDock];
}
@end
////////////////////////////////////////////////////////////////////////////////
#pragma mark -
@implementation FullScreener (NoEffectTransition)
- (void)beginNoEffectTransition
{
[self hideMainMenuAndDock];
[NSCursor setHiddenUntilMouseMoves:TRUE];
[self attachMovieViewToFullWindow];
[_fullWindow addChildWindow:_mainWindow ordered:NSWindowBelow];
}
- (void)endNoEffectTransition
{
[_fullWindow removeChildWindow:_mainWindow];
[self detachMovieViewFromFullWindow];
[self showMainMenuAndDock];
[NSCursor setHiddenUntilMouseMoves:FALSE];
}
@end
////////////////////////////////////////////////////////////////////////////////
#pragma mark -
@implementation FullScreener (FadeTransition)
- (void)beginFadeTransition:(float)fadeDuration
{
[NSCursor setHiddenUntilMouseMoves:TRUE];
float rate = [[_movieView movie] rate];
[[_movieView movie] setRate:0.0];
ScreenFader* fader = [ScreenFader screenFaderWithScreen:[_mainWindow screen]];
[fader fadeOut:fadeDuration];
[self hideMainMenuAndDock];
[self attachMovieViewToFullWindow];
[_fullWindow setFrame:[[_fullWindow screen] frame] display:TRUE];
[_fullWindow addChildWindow:_mainWindow ordered:NSWindowBelow];
[fader fadeIn:fadeDuration];
[[_movieView movie] setRate:rate];
}
- (void)endFadeTransition:(float)fadeDuration
{
float rate = [[_movieView movie] rate];
[[_movieView movie] setRate:0.0];
ScreenFader* fader = [ScreenFader screenFaderWithScreen:[_mainWindow screen]];
[fader fadeOut:fadeDuration];
[_fullWindow removeChildWindow:_mainWindow];
[self detachMovieViewFromFullWindow];
[self showMainMenuAndDock];
[NSCursor setHiddenUntilMouseMoves:FALSE];
[fader fadeIn:fadeDuration];
[[_movieView movie] setRate:rate];
}
@end
////////////////////////////////////////////////////////////////////////////////
#pragma mark -
@implementation FullScreener (AnimationTransition)
//#define _USE_NSViewAnimation
- (void)animatedResizeForBegin:(BOOL)forBegin
{
//TRACE(@"%s %@", __PRETTY_FUNCTION__, forBegin ? @"begin" : @"end");
[[NSNotificationCenter defaultCenter]
addObserver:self selector:@selector(fullWindowResized:)
name:NSWindowDidResizeNotification object:_fullWindow];
#if defined(_USE_NSViewAnimation)
NSRect fullWindowRect;
NSString* blackWindowEffect;
if (forBegin) {
fullWindowRect = _fullMovieRect;
blackWindowEffect = NSViewAnimationFadeInEffect;
}
else {
fullWindowRect = _restoreRect;
blackWindowEffect = NSViewAnimationFadeOutEffect;
}
NSArray* array = [NSArray arrayWithObjects:
[NSDictionary dictionaryWithObjectsAndKeys:
_fullWindow, NSViewAnimationTargetKey,
[NSValue valueWithRect:fullWindowRect], NSViewAnimationEndFrameKey,
nil],
[NSDictionary dictionaryWithObjectsAndKeys:
_blackWindow, NSViewAnimationTargetKey,
blackWindowEffect, NSViewAnimationEffectKey,
nil],
nil];
NSViewAnimation* animation = [[NSViewAnimation alloc] initWithViewAnimations:array];
[animation setAnimationBlockingMode:NSAnimationBlocking];
[animation setDuration:0.2];
[animation startAnimation];
[animation release];
#else // !_USE_NSViewAnimation
float beginAlpha, endAlpha;
if (forBegin) { beginAlpha = 0.0, endAlpha = 1.0; } // transparent => opaque
else { beginAlpha = 1.0, endAlpha = 0.0; } // opaque => transparent
NSRect fullWindowRect = (forBegin) ? _fullMovieRect : _restoreRect;
[_blackWindow setAlphaValue:beginAlpha];
[_fullWindow setFrame:fullWindowRect display:TRUE animate:TRUE];
[_blackWindow setAlphaValue:endAlpha];
#endif
[[NSNotificationCenter defaultCenter]
removeObserver:self
name:NSWindowDidResizeNotification object:_fullWindow];
}
- (void)fullWindowResized:(NSNotification*)notification
{
//TRACE(@"%s", __PRETTY_FUNCTION__);
// resize _mainWindow for _fullWindow
NSRect fr = [_fullWindow frame];
NSRect mr = [_mainWindow frameRectForMovieRect:fr];
if (_maxMainRect.size.width < mr.size.width) {
mr.origin.x += (mr.size.width - _maxMainRect.size.width) / 2;
mr.size.width = _maxMainRect.size.width;
}
if (_maxMainRect.size.height < mr.size.height) {
mr.origin.y += (mr.size.height - _maxMainRect.size.height) / 2;
mr.size.height = _maxMainRect.size.height;
}
[_mainWindow setFrame:mr display:TRUE]; // no animation
#if !defined(_USE_NSViewAnimation)
// update _blackWindow transparency
[_blackWindow setAlphaValue:fr.size.width / _fullMovieRect.size.width];
#endif
}
- (void)runBeginAnimation
{
//TRACE(@"%s", __PRETTY_FUNCTION__);
// create _blackWindow
NSRect frame = [[_mainWindow screen] frame];
_blackWindow = [[NSWindow alloc] initWithContentRect:frame
styleMask:NSBorderlessWindowMask
backing:NSBackingStoreBuffered
defer:FALSE
screen:[_mainWindow screen]];
[_blackWindow useOptimizedDrawing:TRUE];
[_blackWindow setBackgroundColor:[NSColor blackColor]];
[_blackWindow setHasShadow:FALSE];
[_blackWindow setOpaque:FALSE];
[_blackWindow setAlphaValue:0.0]; // initially transparent
[_fullWindow addChildWindow:_blackWindow ordered:NSWindowBelow];
[_fullWindow addChildWindow:_mainWindow ordered:NSWindowBelow];
[_mainWindow setHasShadow:FALSE];
// resizing-animation from movie-view-rect to full-movie-rect
[self animatedResizeForBegin:TRUE];
// resize to screen-rect
NSRect screenRect = [[_fullWindow screen] frame];
[_fullWindow setFrame:screenRect display:TRUE];
[_mainWindow setHasShadow:TRUE];
}
- (void)runEndAnimation
{
//TRACE(@"%s", __PRETTY_FUNCTION__);
[_mainWindow setHasShadow:FALSE];
// resize to full-movie-rect
[_fullWindow setFrame:_fullMovieRect display:TRUE];
// resizing-animation from full-movie-rect to movie-view-rect
[self animatedResizeForBegin:FALSE];
[_mainWindow setHasShadow:TRUE];
[_fullWindow removeChildWindow:_blackWindow];
[_fullWindow removeChildWindow:_mainWindow];
[_blackWindow release];
}
////////////////////////////////////////////////////////////////////////////////
#pragma mark -
- (void)initAnimationTransition
{
//TRACE(@"%s", __PRETTY_FUNCTION__);
// _restoreRect
_restoreRect = [[_mainWindow contentView] convertRect:[_movieView frame] toView:nil];
_restoreRect.origin = [_mainWindow convertRectToScreen:(NSRect){
.origin=_restoreRect.origin, .size=NSZeroSize}].origin;
// _fullMovieRect
NSRect sr = [[_fullWindow screen] frame];
_fullMovieRect = [_movieView calcMovieRectForBoundingRect:sr];
// _maxMainRect
_maxMainRect = [_mainWindow frameRectForMovieRect:_fullMovieRect];
if (sr.size.width < _maxMainRect.size.width) {
_maxMainRect.origin.x += (_maxMainRect.size.width - sr.size.width) / 2;
_maxMainRect.size.width = sr.size.width;
}
if (sr.size.height < _maxMainRect.size.height) {
_maxMainRect.origin.y += (_maxMainRect.size.height - sr.size.height) / 2;
_maxMainRect.size.height = sr.size.height;
}
}
- (void)beginAnimationTransition
{
[self hideMainMenuAndDock];
[NSCursor setHiddenUntilMouseMoves:TRUE];
[self attachMovieViewToFullWindow];
[_fullWindow setFrame:_restoreRect display:TRUE];
[self runBeginAnimation];
}
- (void)endAnimationTransition
{
[self runEndAnimation];
[self detachMovieViewFromFullWindow];
[self showMainMenuAndDock];
[NSCursor setHiddenUntilMouseMoves:FALSE];
}
@end