source: trunk/Cocoa/Pester/Source/NJRCenteringMovieView.m@ 60

Last change on this file since 60 was 60, checked in by Nicholas Riley, 20 years ago

PSScriptAlert.m: Removed reference to NDAppleScriptObject.

PSMovieAlertController.[hm]: Added minimum sizing.

NJRCenteringMovieView.[hm]: Support for centering movie inside its
frame if the frame is too large for the movie; sizes movie
proportionally if necessary (not used in Pester).

NSImage-NJRExtensions.[hm]: Fixed copyright.

Read Me.rtfd: Updated with bug fixes.

PSMovieAlert.m: Note bug in NSMovieView, currently doesn't affect us.

NJRQTMediaPopUpButton.m: Work around background processor use bug when
NSMovieView has movie set but not playing.

NJRVoicePopUpButton.m: Removed obsolete comment.

PSApplication.m: Only show alarm set window on rapp if alerts aren't
expiring.

PSAlarms.[hm]: Added -alarmsExpiring for support of conditional
rapp window open feature in PSApplication.

PSAlarmSetController.m: Stop window update timer and movie playback on
hide, restart timer on activate - fixes background processor usage.

File size: 1.8 KB
Line 
1//
2// NJRCenteringMovieView.m
3// Pester
4//
5// Created by Nicholas Riley on Fri Jan 03 2003.
6// Copyright (c) 2003 Nicholas Riley. All rights reserved.
7//
8
9#import "NJRCenteringMovieView.h"
10#import <QuickTime/Movies.h>
11
12@implementation NJRCenteringMovieView
13
14// from _MacTech_ December 2002, p. 76
15
16- (NSRect)movieRect;
17{
18 NSRect viewRect = [super movieRect];
19 Movie qtMovie = [[self movie] QTMovie];
20 Rect movieRect = {0, 0, 0, 0};
21
22 GetMovieNaturalBoundsRect(qtMovie, &movieRect);
23
24 float movieWidth = movieRect.right - movieRect.left;
25 float movieHeight = movieRect.bottom - movieRect.top;
26
27 if ( (movieWidth <= viewRect.size.width) &&
28 (movieHeight <= viewRect.size.height) ) {
29 // Movie is smaller than or equal to the view size; just center the movie
30 viewRect.origin.y += (int)((viewRect.size.height - movieHeight) / 2.);
31 viewRect.size.height = movieHeight;
32
33 viewRect.origin.x += (int)((viewRect.size.width - movieWidth) / 2.);
34 viewRect.size.width = movieWidth;
35 } else {
36 // We need to scale down movie, centering horizontally and vertically
37 float movieRatio = movieWidth / (float)movieHeight;
38 float viewRatio = viewRect.size.width / viewRect.size.height;
39
40 if (movieRatio > viewRatio) {
41 // Movie is wider than will fit; rescale.
42 float newHeight = viewRect.size.width / movieRatio;
43
44 viewRect.origin.y += (int)((viewRect.size.height - newHeight) / 2.);
45 viewRect.size.height = newHeight;
46 } else {
47 // Movie is taller than will fit (or has the ideal aspect ratio); rescale.
48 float newWidth = viewRect.size.height * movieRatio;
49
50 viewRect.origin.x += (int) ((viewRect.size.width - newWidth) / 2.);
51 viewRect.size.width = newWidth;
52 }
53 }
54 return viewRect;
55}
56
57@end
Note: See TracBrowser for help on using the repository browser.