Initial commit of GrowlITTSW. Currently, all settings are hardcoded.
[GrowlITTSW.git] / GrowlITTSWController.m
1 //
2 //  GrowlITTSWController.m
3 //  Growl
4 //
5 //  Created by Joseph Spiros on 2/28/09.
6 //  Copyright 2009 iThink Software. All rights reserved.
7 //
8
9 #import "GrowlITTSWController.h"
10 #import "GrowlITTSWWindow.h"
11
12 #import <ITKit/ITTSWBackgroundView.h>
13 #import <ITKit/ITWindowEffect.h>
14
15 @implementation NSImage (SmoothAdditions)
16
17 - (NSImage *)imageScaledSmoothlyToSize:(NSSize)scaledSize
18 {
19     NSImage *newImage;
20     NSImageRep *rep = [self bestRepresentationForDevice:nil];
21     
22     newImage = [[NSImage alloc] initWithSize:scaledSize];
23     [newImage lockFocus];
24     {
25         [[NSGraphicsContext currentContext] setImageInterpolation:NSImageInterpolationHigh];
26         [[NSGraphicsContext currentContext] setShouldAntialias:YES];
27         [rep drawInRect:NSMakeRect(3, 3, scaledSize.width - 6, scaledSize.height - 6)];
28     }
29     [newImage unlockFocus];
30     return [newImage autorelease];
31 }
32
33 @end
34
35 @implementation GrowlITTSWController
36
37 - (id)init
38 {
39     if ( ( self = [super init] ) ) {
40                 NSArray *screens = [NSScreen screens];
41         
42                 _window = [[GrowlITTSWWindow sharedWindow] retain];
43                 
44                 [_window setScreen:[screens objectAtIndex:0]];
45                 
46         [_window setExitMode:ITTransientStatusWindowExitAfterDelay];
47         [_window setExitDelay:4.0];
48         
49         [_window setHorizontalPosition:ITWindowPositionRight];
50         [_window setVerticalPosition:ITWindowPositionTop];
51         
52         [_window setSizing:ITTransientStatusWindowMini];
53         
54         [_window setEntryEffect:[[[NSClassFromString(@"ITSlideVerticallyWindowEffect") alloc] initWithWindow:_window] autorelease]];
55         [_window setExitEffect:[[[NSClassFromString(@"ITSlideHorizontallyWindowEffect") alloc] initWithWindow:_window] autorelease]];
56         
57         [[_window entryEffect] setEffectTime:0.8];
58         [[_window exitEffect]  setEffectTime:0.8];
59         
60         [(ITTSWBackgroundView *)[_window contentView]setBackgroundMode:
61                  ITTSWBackgroundReadable];
62     }
63     
64     return self;
65 }
66
67 - (void)dealloc
68 {
69     [_window release];
70     [super dealloc];
71 }
72
73 - (void)showWindowWithText:(NSString *)text image:(NSImage *)image
74 {
75     NSMutableAttributedString *attributedText = [[NSMutableAttributedString alloc] initWithString:text];
76         NSSize newSize;
77         NSSize oldSize = [image size];
78         
79         if (oldSize.width > oldSize.height) {
80                 newSize = NSMakeSize(110.0f, (oldSize.height * (110.0f / oldSize.width)));
81         } else {
82                 newSize = NSMakeSize((oldSize.width * (110.0f / oldSize.height)), 110.0f);
83         }
84         
85         image = [[[[NSImage alloc] initWithData:[image TIFFRepresentation]] autorelease] imageScaledSmoothlyToSize:newSize];
86         
87         [_window setImage:image];
88     [_window buildTextWindowWithString:attributedText];
89     [_window appear:self];
90         [attributedText release];
91 }
92
93 @end