source: releases/Pester/1.1b5/Source/NSImage-NJRExtensions.m

Last change on this file was 60, checked in by Nicholas Riley, 22 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: 2.3 KB
Line 
1//
2// NSImage-NJRExtensions.m
3// Pester
4//
5// Created by Nicholas Riley on Mon Oct 28 2002.
6// Copyright (c) 2002 Nicholas Riley. All rights reserved.
7//
8
9#import "NSImage-NJRExtensions.h"
10
11
12@implementation NSImage (NJRExtensions)
13
14- (NSImage *)bestFitImageForSize:(NSSize)imageSize;
15{
16 NSSize repSize;
17 NSArray *imageReps;
18 int i, repCount;
19 NSImageRep *preferredRep, *rep;
20 imageReps = [self representations];
21 repCount = [imageReps count];
22 preferredRep = [imageReps objectAtIndex: 0];
23 for (i = 1 ; i < repCount ; i++) {
24 rep = [imageReps objectAtIndex: i];
25 repSize = [rep size];
26 if (repSize.width == imageSize.width && repSize.height == imageSize.height) {
27 preferredRep = rep;
28 break;
29 }
30 if (repSize.width >= imageSize.width || repSize.height >= imageSize.height) {
31 // pick the smallest of the larger representations
32 if (repSize.width <= [preferredRep size].width ||
33 repSize.height <= [preferredRep size].height) preferredRep = rep;
34 } else {
35 // or the largest of the smaller representations
36 if (([preferredRep size].width > imageSize.width ||
37 [preferredRep size].height > imageSize.height) ||
38 // (assuming that the previous preferred rep was smaller, too)
39 // XXX fix this in HostLauncher too - or is the FSA code better?
40 (repSize.width >= [preferredRep size].width ||
41 repSize.height >= [preferredRep size].height)) preferredRep = rep;
42 }
43 }
44 // Begin workaround code for bug in OS X 10.1 (removeRepresentation: has no effect)
45 if ([preferredRep size].width > imageSize.width || [preferredRep size].height > imageSize.height) {
46 NSImage *scaledImage = [[NSImage alloc] initWithSize: imageSize];
47 NSRect rect = { NSZeroPoint, imageSize };
48 [scaledImage setFlipped: [self isFlipped]]; // XXX this works, but is correct?
49 [scaledImage lockFocus];
50 [preferredRep drawInRect: rect];
51 [scaledImage unlockFocus];
52 return scaledImage;
53 } else if (repCount > 1) {
54 NSImage *sizedImage = [[NSImage alloc] initWithSize: [preferredRep size]];
55 [sizedImage addRepresentation: preferredRep];
56 return sizedImage;
57 } else {
58 return self;
59 }
60}
61
62@end
Note: See TracBrowser for help on using the repository browser.