2 // GrowlITTSWController.m
5 // Created by Joseph Spiros on 2/28/09.
6 // Copyright 2009 iThink Software. All rights reserved.
9 #import "GrowlITTSWController.h"
10 #import "GrowlITTSWWindow.h"
12 #import <ITKit/ITTSWBackgroundView.h>
13 #import <ITKit/ITWindowEffect.h>
15 @implementation NSImage (SmoothAdditions)
17 - (NSImage *)imageScaledSmoothlyToSize:(NSSize)scaledSize
20 NSImageRep *rep = [self bestRepresentationForDevice:nil];
22 newImage = [[NSImage alloc] initWithSize:scaledSize];
25 [[NSGraphicsContext currentContext] setImageInterpolation:NSImageInterpolationHigh];
26 [[NSGraphicsContext currentContext] setShouldAntialias:YES];
27 [rep drawInRect:NSMakeRect(3, 3, scaledSize.width - 6, scaledSize.height - 6)];
29 [newImage unlockFocus];
30 return [newImage autorelease];
35 @implementation GrowlITTSWController
39 if ( ( self = [super init] ) ) {
40 NSArray *screens = [NSScreen screens];
42 _window = [[GrowlITTSWWindow sharedWindow] retain];
44 [_window setScreen:[screens objectAtIndex:0]];
46 [_window setExitMode:ITTransientStatusWindowExitAfterDelay];
47 [_window setExitDelay:4.0];
49 [_window setHorizontalPosition:ITWindowPositionRight];
50 [_window setVerticalPosition:ITWindowPositionTop];
52 [_window setSizing:ITTransientStatusWindowMini];
54 [_window setEntryEffect:[[[NSClassFromString(@"ITSlideVerticallyWindowEffect") alloc] initWithWindow:_window] autorelease]];
55 [_window setExitEffect:[[[NSClassFromString(@"ITSlideHorizontallyWindowEffect") alloc] initWithWindow:_window] autorelease]];
57 [[_window entryEffect] setEffectTime:0.8];
58 [[_window exitEffect] setEffectTime:0.8];
60 [(ITTSWBackgroundView *)[_window contentView]setBackgroundMode:
61 ITTSWBackgroundReadable];
73 - (void)showWindowWithText:(NSString *)text image:(NSImage *)image
75 NSMutableAttributedString *attributedText = [[NSMutableAttributedString alloc] initWithString:text];
77 NSSize oldSize = [image size];
79 if (oldSize.width > oldSize.height) {
80 newSize = NSMakeSize(110.0f, (oldSize.height * (110.0f / oldSize.width)));
82 newSize = NSMakeSize((oldSize.width * (110.0f / oldSize.height)), 110.0f);
85 image = [[[[NSImage alloc] initWithData:[image TIFFRepresentation]] autorelease] imageScaledSmoothlyToSize:newSize];
87 [_window setImage:image];
88 [_window buildTextWindowWithString:attributedText];
89 [_window appear:self];
90 [attributedText release];