root/WiredClient/trunk/WCAboutWindow.m

Revision 4799, 5.0 kB (checked in by morris, 1 year ago)

Use NSInteger and NSUInteger everywhere

Make sure we use l in %d and %u format specifiers since they will be long on 64-bit

  • Property svn:keywords set to author date id revision
Line 
1 /* $Id$ */
2
3 /*
4  *  Copyright (c) 2003-2007 Axel Andersson
5  *  All rights reserved.
6  *
7  *  Redistribution and use in source and binary forms, with or without
8  *  modification, are permitted provided that the following conditions
9  *  are met:
10  *  1. Redistributions of source code must retain the above copyright
11  *     notice, this list of conditions and the following disclaimer.
12  *  2. Redistributions in binary form must reproduce the above copyright
13  *     notice, this list of conditions and the following disclaimer in the
14  *     documentation and/or other materials provided with the distribution.
15  *
16  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
17  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19  * DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
20  * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
22  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
24  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
25  * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
26  * POSSIBILITY OF SUCH DAMAGE.
27  */
28
29 #import "WCAboutWindow.h"
30
31 @implementation WCAboutWindow
32
33 + (WCAboutWindow *)aboutWindow {
34         static id       sharedAboutWindow;
35        
36         if(!sharedAboutWindow)
37                 sharedAboutWindow = [[self alloc] init];
38
39         return sharedAboutWindow;
40 }
41
42
43
44 - (id)init {
45         NSMutableAttributedString       *leftString, *rightString;
46         NSDictionary                            *attributes;
47         NSView                                          *view;
48         NSImage                                         *leftImage, *rightImage;
49         NSEnumerator                            *enumerator;
50         NSScreen                                        *screen, *last = NULL;
51         NSRect                                          viewRect, leftRect, rightRect;
52         CGFloat                                         width = 0, height;
53
54         enumerator = [[NSScreen screens] objectEnumerator];
55
56         while((screen = [enumerator nextObject])) {
57                 if(!last) {
58                     // --- add first screen
59                     width += [screen frame].size.width;
60                 } else {
61                     if(NSEqualSizes([screen frame].size, [last frame].size) &&
62                        [screen frame].origin.y == [last frame].origin.y) {
63                         // --- add another screen of equal size and along the same boundary
64                         width += [screen frame].size.width;
65                     }
66                 }
67
68                 last = screen;
69         }
70
71         // --- set window size
72         height = width / 11.0;
73         viewRect = [[NSScreen mainScreen] frame];
74         viewRect.origin.x = 0;
75         viewRect.origin.y = (viewRect.size.height - height) / 2;
76         viewRect.size.height = height;
77         viewRect.size.width = width;
78
79         // --- create window
80         self = [super initWithContentRect:viewRect
81                                     styleMask:NSBorderlessWindowMask
82                                       backing:NSBackingStoreBuffered
83                                         defer:NO];
84
85         viewRect.origin.x = viewRect.origin.y = 0;
86         view = [[NSView alloc] initWithFrame:viewRect];
87
88         [self setDelegate:self];
89         [self setReleasedWhenClosed:NO];
90         [self setBackgroundColor:[NSColor clearColor]];
91         [self setOpaque:NO];
92         [self setLevel:NSScreenSaverWindowLevel];
93         [self setContentView:view];
94
95         // --- create strings
96         attributes = [NSDictionary dictionaryWithObjectsAndKeys:
97                 [NSFont fontWithName:@"Helvetica-Bold" size:width / 14.60], NSFontAttributeName,
98                 [NSColor blackColor], NSForegroundColorAttributeName,
99                 NULL];
100
101         leftString = [NSMutableAttributedString attributedStringWithString:@"Close the world," attributes:attributes];
102         rightString = [NSMutableAttributedString attributedStringWithString:@"Open the nExt" attributes:attributes];
103
104         // --- red 'E'
105         [rightString addAttribute:NSForegroundColorAttributeName
106                                 value:[[NSColor redColor] shadowWithLevel:0.5]
107                                 range:[[rightString string] rangeOfString:@"E"]];
108
109         // --- create images
110         leftRect = NSMakeRect(0, 0, viewRect.size.width * 0.53, viewRect.size.height);
111         leftImage = [[[NSImage alloc] initWithSize:leftRect.size] autorelease];
112         rightRect = NSMakeRect(leftRect.size.width, 0, viewRect.size.width - leftRect.size.width, viewRect.size.height);
113         rightImage = [[[NSImage alloc] initWithSize:rightRect.size] autorelease];
114
115         // --- draw strings in images
116         [leftImage lockFocus];
117         [leftString drawInRect:leftRect];
118         [leftImage unlockFocus];
119
120         [rightImage lockFocus];
121         [rightString drawInRect:leftRect];
122         [rightImage unlockFocus];
123
124         // --- display window
125         [self display];
126
127         // --- draw images in view
128         [view lockFocus];
129         [leftImage compositeToPoint:leftRect.origin operation:NSCompositeSourceOver];
130         [[rightImage mirroredImage] compositeToPoint:rightRect.origin operation:NSCompositeSourceOver];
131         [view unlockFocus];
132
133         // --- subscribe to these
134         [[NSNotificationCenter defaultCenter]
135                 addObserver:self
136                    selector:@selector(applicationDidChangeActive:)
137                            name:WIApplicationDidChangeActiveNotification];
138
139         return self;
140 }
141
142
143
144 - (void)applicationDidChangeActive:(NSNotification *)notification {
145         [self close];
146 }
147
148
149
150 - (void)windowDidResignKey:(NSNotification *)notification {
151         [self close];
152 }
153
154
155
156 - (void)keyDown:(NSEvent *)event {
157         [self close];
158 }
159
160
161
162 - (void)mouseDown:(NSEvent *)event {
163         [self close];
164 }
165
166
167
168 - (BOOL)canBecomeKeyWindow {
169         return YES;
170 }
171
172 @end
Note: See TracBrowser for help on using the browser.