forked from samiamwork/Movist
-
Notifications
You must be signed in to change notification settings - Fork 0
/
AppController_Video.m
482 lines (436 loc) · 14.4 KB
/
AppController_Video.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
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
//
// 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 "AppController.h"
#import "UserDefaults.h"
#import "MMovie.h"
#import "MMovieView.h"
#import "MainWindow.h"
#import "FullScreener.h"
@implementation AppController (Video)
- (void)setVideoTrackAtIndex:(unsigned int)index enabled:(BOOL)enabled
{
MTrack* track = (MTrack*)[[_movie videoTracks] objectAtIndex:index];
[track setEnabled:enabled];
if (enabled) {
[_movieView setMessage:[NSString stringWithFormat:
NSLocalizedString(@"%@ enabled", nil), [track name]]];
}
else {
[_movieView setMessage:[NSString stringWithFormat:
NSLocalizedString(@"%@ disabled", nil), [track name]]];
}
//[self updateVideoTrackMenuItems];
}
- (void)resizeWithMagnification:(float)magnification
{
//TRACE(@"%s %g", __PRETTY_FUNCTION__, magnification);
if (!_movie) {
return;
}
NSSize size = [_movie adjustedSizeByAspectRatio];
if (magnification != 1.0) {
size.width *= magnification;
size.height *= magnification;
}
BOOL subtitleVisible = [_movieView subtitleVisible];
[_seekSlider hideMouseTimeToolTip];
[_movieView setSubtitleVisible:FALSE];
if ([self isFullScreen]) {
[_movieView setFullScreenMovieSize:size];
}
else {
int align = ALIGN_WINDOW_TITLE_CENTER;
switch ([_defaults integerForKey:MMovieResizeCenterKey]) {
case MOVIE_RESIZE_CENTER_TM : align = ALIGN_WINDOW_TITLE_CENTER; break;
case MOVIE_RESIZE_CENTER_TL : align = ALIGN_WINDOW_TITLE_LEFT; break;
case MOVIE_RESIZE_CENTER_TR : align = ALIGN_WINDOW_TITLE_RIGHT; break;
case MOVIE_RESIZE_CENTER_BM : align = ALIGN_WINDOW_BOTTOM_CENTER; break;
case MOVIE_RESIZE_CENTER_BL : align = ALIGN_WINDOW_BOTTOM_LEFT; break;
case MOVIE_RESIZE_CENTER_BR : align = ALIGN_WINDOW_BOTTOM_RIGHT; break;
}
NSRect frame = [_mainWindow frameRectForMovieSize:size align:align];
if ([[_mainWindow screen] visibleFrame].size.height < frame.size.height) {
frame = [_mainWindow frameRectForScreen];
}
[_mainWindow setFrame:frame display:TRUE animate:TRUE];
}
[_movieView setSubtitleVisible:subtitleVisible];
}
- (void)resizeToScreen
{
//TRACE(@"%s", __PRETTY_FUNCTION__);
if ([self isFullScreen]) {
[_movieView setFullScreenMovieSize:NSZeroSize];
}
else {
NSRect frame = [_mainWindow frameRectForScreen];
BOOL subtitleVisible = [_movieView subtitleVisible];
[_seekSlider hideMouseTimeToolTip];
[_movieView setSubtitleVisible:FALSE];
[_mainWindow setFrame:frame display:TRUE animate:TRUE];
[_movieView setSubtitleVisible:subtitleVisible];
}
}
////////////////////////////////////////////////////////////////////////////////
#pragma mark -
#pragma mark full-screen
- (BOOL)isFullScreen { return _fullScreener && [_fullScreener isFullScreen]; }
- (void)beginFullScreen
{
//TRACE(@"%s", __PRETTY_FUNCTION__);
[_fullScreenLock lock];
if (_movie && ![self isFullScreen]) {
NSEvent* event = [NSApp currentEvent];
unsigned int flags = [event modifierFlags];
if (!(flags & NSCommandKeyMask)) {
if (flags & NSControlKeyMask) {
[self setFullScreenFill:FS_FILL_STRETCH];
}
else if (flags & NSAlternateKeyMask) {
[self setFullScreenFill:FS_FILL_CROP];
}
else if (flags & NSShiftKeyMask) {
[self setFullScreenFill:FS_FILL_NEVER];
}
}
if (_alwaysOnTopEnabled) {
[self updateAlwaysOnTop:FALSE];
}
if (!_fullScreener) {
_fullScreener = [FullScreener alloc];
[_fullScreener initWithMainWindow:_mainWindow playPanel:_playPanel];
[_fullScreener setMovieURL:[self movieURL]];
[_fullScreener setAutoShowDock:[_defaults boolForKey:MAutoShowDockKey]];
}
[_seekSlider hideMouseTimeToolTip];
[_fullScreener beginFullScreen];
}
[_fullScreenLock unlock];
}
- (void)endFullScreen
{
//TRACE(@"%s", __PRETTY_FUNCTION__);
[_fullScreenLock lock];
if ([self isFullScreen]) {
[_fullScreener endFullScreen];
if (![self isDesktopBackground]) {
[_fullScreener release];
_fullScreener = nil;
}
[_movieView updateMovieRect:TRUE];
if (_alwaysOnTopEnabled) {
[self updateAlwaysOnTop:TRUE];
}
}
[_fullScreenLock unlock];
}
////////////////////////////////////////////////////////////////////////////////
#pragma mark -
#pragma mark desktop-background
- (BOOL)isDesktopBackground { return _fullScreener && [_fullScreener isDesktopBackground]; }
- (void)beginDesktopBackground
{
//TRACE(@"%s", __PRETTY_FUNCTION__);
[_fullScreenLock lock];
if (_movie && ![self isDesktopBackground]) {
if (_alwaysOnTopEnabled) {
[self updateAlwaysOnTop:FALSE];
}
if (!_fullScreener) {
_fullScreener = [FullScreener alloc];
[_fullScreener initWithMainWindow:_mainWindow playPanel:_playPanel];
[_fullScreener setMovieURL:[self movieURL]];
}
[_seekSlider hideMouseTimeToolTip];
[_fullScreener beginDesktopBackground];
}
[_fullScreenLock unlock];
}
- (void)endDesktopBackground
{
//TRACE(@"%s", __PRETTY_FUNCTION__);
[_fullScreenLock lock];
if ([self isDesktopBackground]) {
[_fullScreener endDesktopBackground];
[_fullScreener release];
_fullScreener = nil;
[_movieView updateMovieRect:TRUE];
if (_alwaysOnTopEnabled) {
[self updateAlwaysOnTop:TRUE];
}
}
[_fullScreenLock unlock];
}
////////////////////////////////////////////////////////////////////////////////
#pragma mark -
#pragma mark full-navigation
- (BOOL)isFullNavigation { return _fullScreener && [_fullScreener isNavigation]; }
- (void)beginFullNavigation
{
//TRACE(@"%s", __PRETTY_FUNCTION__);
if (![_defaults boolForKey:MFullNavUseKey]) {
return;
}
[_fullScreenLock lock];
if (_alwaysOnTopEnabled) {
[self updateAlwaysOnTop:FALSE];
}
[_controlPanel orderOut:self];
if ([self isFullScreen]) {
// enter from full-screen-mode with playing movie
[_fullScreener setMovieURL:nil];
}
else if ([self isDesktopBackground]) {
// enter from desktop-background with playing movie
[_fullScreener setMovieURL:nil];
[_fullScreener beginNavigation];
}
else {
// enter from window-mode with no-movie
_fullScreener = [FullScreener alloc];
[_fullScreener initWithMainWindow:_mainWindow playPanel:_playPanel];
[_fullScreener setMovieURL:nil];
[_seekSlider hideMouseTimeToolTip];
[_fullScreener beginNavigation];
}
[_fullScreenLock unlock];
}
- (void)endFullNavigation
{
//TRACE(@"%s", __PRETTY_FUNCTION__);
[_fullScreenLock lock];
if ([self isFullNavigation]) {
[_movieView showLogo];
[_fullScreener endNavigation];
[_fullScreener release];
_fullScreener = nil;
[_movieView updateMovieRect:TRUE];
if (_alwaysOnTopEnabled) {
[self updateAlwaysOnTop:TRUE];
}
}
[_fullScreenLock unlock];
}
- (void)setFullScreenFill:(int)fill forWideMovie:(BOOL)forWideMovie
{
//TRACE(@"%s", __PRETTY_FUNCTION__);
if (_movie) {
NSSize ss = [[_mainWindow screen] frame].size;
NSSize ms = [_movie adjustedSizeByAspectRatio];
if (ss.width / ss.height < ms.width / ms.height) {
if (forWideMovie) {
[self setFullScreenFill:fill];
}
}
else {
if (!forWideMovie) {
[self setFullScreenFill:fill];
}
}
}
}
- (void)setFullScreenFill:(int)fill
{
//TRACE(@"%s", __PRETTY_FUNCTION__);
[_movieView setFullScreenFill:fill];
[_movieView updateMovieRect:TRUE];
NSMenuItem* item;
unsigned int i, count = [_fullScreenFillMenu numberOfItems];
for (i = 0; i < count; i++) {
item = [_fullScreenFillMenu itemAtIndex:i];
if ([item tag] == fill) {
break;
}
}
[_movieView setMessage:[NSString stringWithFormat:
@"%@: %@", [_fullScreenFillMenu title], [item title]]];
[self updateFullScreenFillMenu];
}
- (void)setFullScreenUnderScan:(float)underScan
{
//TRACE(@"%s %f", __PRETTY_FUNCTION__, underScan);
[_movieView setFullScreenUnderScan:underScan];
[_movieView updateMovieRect:TRUE];
unsigned int count = [_fullScreenFillMenu numberOfItems];
NSMenuItem* item = [_fullScreenFillMenu itemAtIndex:count - 1];
[item setState:(underScan != 0)];
if (underScan == 0) {
[_movieView setMessage:[NSString stringWithFormat:
@"%@ %@", [item title], NSLocalizedString(@"Never", nil)]];
}
else {
[_movieView setMessage:[NSString stringWithFormat:
@"%@ %.1f %%", [item title], underScan]];
}
}
- (void)updateFullScreenFillMenu
{
//TRACE(@"%s", __PRETTY_FUNCTION__);
NSMenuItem* item;
unsigned int i, count = [_fullScreenFillMenu numberOfItems];
for (i = 0; i < count; i++) {
item = [_fullScreenFillMenu itemAtIndex:i];
if ([item tag] <= FS_FILL_CROP) {
[item setState:(_movie && [item tag] == [_movieView fullScreenFill])];
}
else { // under scan
[item setState:(0 < [_movieView fullScreenUnderScan])];
}
}
}
////////////////////////////////////////////////////////////////////////////////
#pragma mark -
#pragma mark aspect-ratio
- (int)aspectRatio { return (_movie) ? [_movie aspectRatio] : ASPECT_RATIO_DAR; }
- (void)setAspectRatio:(int)aspectRatio
{
//TRACE(@"%s", __PRETTY_FUNCTION__);
if (_movie) {
NSMenuItem* item;
unsigned int i, count = [_aspectRatioMenu numberOfItems];
for (i = 0; i < count; i++) {
item = [_aspectRatioMenu itemAtIndex:i];
if ([item tag] == aspectRatio) {
[_movieView setMessage:[item title]];
break;
}
}
[_movie setAspectRatio:aspectRatio];
[_movieView setMessage:[NSString stringWithFormat:
@"%@: %@", [_aspectRatioMenu title], [item title]]];
if (![self isFullScreen] && ![self isDesktopBackground]) {
[self resizeWithMagnification:1.0];
}
[_movieView updateOSDImageBaseWidth];
[_movieView updateLetterBoxHeight];
[_movieView updateMovieRect:TRUE];
[self updateAspectRatioMenu];
[self updateLetterBoxHeightMenuItems];
}
}
- (void)updateAspectRatioMenu
{
//TRACE(@"%s", __PRETTY_FUNCTION__);
NSMenuItem* item;
unsigned int i, count = [_aspectRatioMenu numberOfItems];
for (i = 0; i < count; i++) {
item = [_aspectRatioMenu itemAtIndex:i];
[item setState:(_movie) ? ([item tag] == [_movie aspectRatio]) : NSOffState];
}
}
////////////////////////////////////////////////////////////////////////////////
#pragma mark -
#pragma mark IB actions
- (IBAction)movieSizeAction:(id)sender
{
//TRACE(@"%s %d", __PRETTY_FUNCTION__, [sender tag]);
switch ([sender tag]) {
case 0 : [self resizeWithMagnification:0.5]; break;
case 1 : [self resizeWithMagnification:1.0]; break;
case 2 : [self resizeWithMagnification:2.0]; break;
case 3 : [self resizeToScreen]; break;
}
}
- (IBAction)fullScreenAction:(id)sender
{
//TRACE(@"%s", __PRETTY_FUNCTION__);
if (!_movie) {
if (!_fullScreener) {
[self beginFullNavigation];
}
else {
if (![_fullScreener closeCurrent]) {
[self endFullNavigation];
}
}
}
else if ([self isFullNavigation]) {
if (![_fullScreener closeCurrent]) {
[self endFullNavigation];
}
}
else if ([self isFullScreen]) {
[self endFullScreen];
}
else {
[self beginFullScreen];
if ([_defaults boolForKey:MAutoPlayOnFullScreenKey]) {
[_movie setRate:_playRate]; // auto play
}
}
}
- (IBAction)desktopBackgroundAction:(id)sender
{
if ([self isDesktopBackground]) {
[self endDesktopBackground];
}
else if (_movie && ![self isFullNavigation]) {
[self beginDesktopBackground];
}
}
- (IBAction)fullNavigationAction:(id)sender
{
if ([self isFullNavigation]) {
[self endFullNavigation];
}
else {
if (_movie) {
if ([self isFullScreen]) {
[self endFullScreen];
}
[self closeMovie];
}
[self beginFullNavigation];
}
}
- (IBAction)fullScreenFillAction:(id)sender
{
if ([sender tag] < 0) {
int fill = [_movieView fullScreenFill];
switch (fill) {
case FS_FILL_NEVER : fill = FS_FILL_STRETCH; break;
case FS_FILL_STRETCH : fill = FS_FILL_CROP; break;
case FS_FILL_CROP : fill = FS_FILL_NEVER; break;
default : fill = FS_FILL_NEVER; break;
}
[self setFullScreenFill:fill];
}
else {
[self setFullScreenFill:[sender tag]];
}
}
- (IBAction)fullScreenUnderScanAction:(id)sender
{
BOOL underScan = ![sender state];
[self setFullScreenUnderScan:
((underScan) ? [_defaults floatForKey:MFullScreenUnderScanKey] : 0)];
}
- (IBAction)aspectRatioAction:(id)sender
{
//TRACE(@"%s", __PRETTY_FUNCTION__);
[self setAspectRatio:[sender tag]];
}
- (IBAction)saveCurrentImage:(id)sender
{
[_movieView saveCurrentImage:[sender tag] != 0];
}
@end