Expand the icon maker.

This commit is contained in:
Lukhnos Liu 2012-09-08 22:02:35 -07:00
parent 484fbf54c8
commit f4f3a19447
5 changed files with 158 additions and 44 deletions

View File

@ -9,5 +9,6 @@
#import <Cocoa/Cocoa.h>
@interface BopomofoIconRenderView : NSView
@property (assign, nonatomic) BOOL textMenuIcon;
@property (assign, nonatomic) BOOL plainBopomofoIcon;
@end

View File

@ -23,26 +23,67 @@
boundsRect.size.width -= 1.0;
NSBezierPath *backgroundPath = [NSBezierPath bezierPathWithRoundedRect:boundsRect xRadius:2.0 yRadius:2.0];
if (self.textMenuIcon) {
[[NSColor colorWithDeviceWhite:0.95 alpha:1.0] setFill];
[[NSColor colorWithDeviceWhite:0.6 alpha:1.0] setStroke];
[backgroundPath fill];
NSRect innerBoundRect = boundsRect;
innerBoundRect.size.width -= 1.0;
innerBoundRect.size.height -= 1.0;
innerBoundRect.origin.x += 0.5;
innerBoundRect.origin.y += 0.5;
backgroundPath = [NSBezierPath bezierPathWithRoundedRect:innerBoundRect xRadius:2.0 yRadius:2.0];
[backgroundPath stroke];
[NSGraphicsContext saveGraphicsState];
NSBezierPath *coveringPath = [NSBezierPath bezierPath];
[coveringPath appendBezierPathWithArcWithCenter:NSMakePoint(16.0, 1.0) radius:14.0 startAngle:0.0 endAngle:360.0];
[coveringPath setClip];
NSColor *darkGrayColor = [NSColor colorWithDeviceWhite:0.3 alpha:1.0];
[darkGrayColor setFill];
[[NSBezierPath bezierPathWithRoundedRect:boundsRect xRadius:2.0 yRadius:2.0] fill];
[[NSColor colorWithDeviceWhite:0.3 alpha:1.0] setStroke];
backgroundPath = [NSBezierPath bezierPathWithRoundedRect:innerBoundRect xRadius:2.0 yRadius:2.0];
[backgroundPath stroke];
[NSGraphicsContext restoreGraphicsState];
}
else {
if (self.plainBopomofoIcon) {
if ([self bounds].size.width > 16.0) {
[[NSColor colorWithDeviceWhite:0.3 alpha:1.0] setFill];
}
else {
[[NSColor colorWithDeviceWhite:0.1 alpha:1.0] setFill];
}
}
else {
[[NSColor colorWithDeviceWhite:0.3 alpha:1.0] setFill];
}
[backgroundPath fill];
}
NSInteger fontSize = ([self bounds].size.width > 16.0) ? 14.0 : 13.5;
CGFloat fontSize = ([self bounds].size.width > 16.0) ? 14.0 : 13.0;
NSString *text = @"ㄅ";
NSString *fontName = @"BiauKai";
NSColor *textColor = nil;
if (self.textMenuIcon) {
textColor = [NSColor blackColor];
}
else if (self.plainBopomofoIcon) {
textColor = [NSColor colorWithDeviceWhite:0.95 alpha:1.0];
}
else {
textColor = [NSColor colorWithDeviceWhite:1.0 alpha:1.0];
}
NSMutableDictionary *attrDict = [NSMutableDictionary dictionaryWithObjectsAndKeys:
textColor, NSForegroundColorAttributeName,
[NSFont fontWithName:fontName size:fontSize], NSFontAttributeName,
nil];
NSAttributedString *attrString = [[NSAttributedString alloc] initWithString:text attributes:attrDict];
NSMutableAttributedString *attrString = [[[NSMutableAttributedString alloc] initWithString:text attributes:attrDict] autorelease];
NSRect textBounds = [attrString boundingRectWithSize:boundsRect.size options:NSStringDrawingUsesLineFragmentOrigin];
@ -50,7 +91,32 @@
textOrigin.x = boundsRect.origin.x + (boundsRect.size.width - textBounds.size.width) / 2.0;
textOrigin.y = boundsRect.origin.y;
attrString = [[NSAttributedString alloc] initWithString:text attributes:attrDict];
[attrString drawAtPoint:textOrigin];
if (self.plainBopomofoIcon) {
NSBezierPath *coveringPath = [NSBezierPath bezierPath];
[coveringPath appendBezierPathWithArcWithCenter:NSMakePoint(16.0, -3.0) radius:13.0 startAngle:0.0 endAngle:360.0];
[coveringPath setClip];
if (!([self bounds].size.width > 16.0)) {
[[NSColor colorWithDeviceWhite:0.6 alpha:1.0] setFill];
[[NSColor colorWithDeviceWhite:0.6 alpha:1.0] setStroke];
}
[[NSColor colorWithDeviceWhite:0.65 alpha:1.0] setFill];
[[NSColor colorWithDeviceWhite:0.65 alpha:1.0] setStroke];
[backgroundPath fill];
boundsRect.size.width -= 1.0;
boundsRect.size.height -= 1.0;
boundsRect.origin.x += 0.5;
boundsRect.origin.y += 0.5;
backgroundPath = [NSBezierPath bezierPathWithRoundedRect:boundsRect xRadius:2.0 yRadius:2.0];
[backgroundPath stroke];
[attrDict setObject:[NSColor colorWithDeviceWhite:1.0 alpha:1.0] forKey:NSForegroundColorAttributeName];
[attrString setAttributes:attrDict range:NSMakeRange(0, [text length])];
[attrString drawAtPoint:textOrigin];
}
}
@end

View File

@ -34,13 +34,12 @@
#import <Cocoa/Cocoa.h>
#import "TISIconRendererView.h"
#import "BopomofoIconRenderView.h"
@interface IconMakerAppDelegate : NSObject <NSApplicationDelegate> {
@private
NSWindow *window;
}
@interface IconMakerAppDelegate : NSObject <NSApplicationDelegate>
@property (assign) IBOutlet NSWindow *window;
@property (assign) IBOutlet TISIconRendererView *selectedTISIconRendererView;
@property (assign) IBOutlet TISIconRendererView *faviconRenderView;
@property (assign) IBOutlet BopomofoIconRenderView *bopomofoIconRenderView;
@property (assign) IBOutlet BopomofoIconRenderView *bopomofoIconRenderView2x;
@end

View File

@ -35,9 +35,6 @@
#import "IconMakerAppDelegate.h"
@implementation IconMakerAppDelegate
@synthesize selectedTISIconRendererView;
@synthesize faviconRenderView;
@synthesize window;
- (void)makeIconForObject:(id)object size:(NSSize)size filename:(NSString *)name
{
@ -48,6 +45,7 @@
NSView *view = nil;
if ([object isKindOfClass:[NSView class]]) {
view = object;
[view setFrame:NSMakeRect(0.0, 0.0, size.width, size.height)];
}
else if ([object isKindOfClass:[NSString class]]) {
view = [[[NSClassFromString(object) alloc] initWithFrame:rect] autorelease];
@ -64,30 +62,51 @@
- (void)applicationDidFinishLaunching:(NSNotification *)aNotification
{
// Insert code here to initialize your application
selectedTISIconRendererView.selected = YES;
[selectedTISIconRendererView setNeedsDisplay:YES];
self.selectedTISIconRendererView.selected = YES;
[self.selectedTISIconRendererView setNeedsDisplay:YES];
faviconRenderView.favicon = YES;
faviconRenderView.selected = YES;
[faviconRenderView setNeedsDisplay:YES];
self.faviconRenderView.favicon = YES;
self.faviconRenderView.selected = YES;
NSRect oldFrame = [self.faviconRenderView frame];
[self makeIconForObject:self.faviconRenderView size:NSMakeSize(16, 16) filename:@"/tmp/BopomofoFavicon.tiff"];
[self.faviconRenderView setFrame:oldFrame];
[self.faviconRenderView setNeedsDisplay:YES];
// [self makeIconForObject:@"TISIconRendererView" size:NSMakeSize(16, 16) filename:@"/tmp/Bopomofo.tiff"];
// [self makeIconForObject:selectedTISIconRendererView size:NSMakeSize(16, 16) filename:@"/tmp/BopomofoSelected.tiff"];
[self makeIconForObject:@"BopomofoIconRenderView" size:NSMakeSize(16, 16) filename:@"/tmp/Bopomofo.tiff"];
[self makeIconForObject:@"BopomofoIconRenderView" size:NSMakeSize(32, 32) filename:@"/tmp/Bopomofo@2x.tiff"];
[self makeIconForObject:@"BopomofoIconRenderView" size:NSMakeSize(16, 16) filename:@"/tmp/BopomofoSelected.tiff"];
self.bopomofoIconRenderView.textMenuIcon = NO;
self.bopomofoIconRenderView.plainBopomofoIcon = NO;
self.bopomofoIconRenderView2x.textMenuIcon = NO;
self.bopomofoIconRenderView2x.plainBopomofoIcon = NO;
[self.bopomofoIconRenderView setNeedsDisplay:YES];
[self.bopomofoIconRenderView2x setNeedsDisplay:YES];
[self makeIconForObject:faviconRenderView size:NSMakeSize(16, 16) filename:@"/tmp/BopomofoFavicon.tiff"];
BopomofoIconRenderView *iconRenderView = [[[BopomofoIconRenderView alloc] init] autorelease];
iconRenderView.textMenuIcon = NO;
iconRenderView.plainBopomofoIcon = NO;
[self makeIconForObject:iconRenderView size:NSMakeSize(16, 16) filename:@"/tmp/Bopomofo.tiff"];
[self makeIconForObject:iconRenderView size:NSMakeSize(32, 32) filename:@"/tmp/Bopomofo@2x.tiff"];
iconRenderView.textMenuIcon = NO;
iconRenderView.plainBopomofoIcon = YES;
[self makeIconForObject:iconRenderView size:NSMakeSize(16, 16) filename:@"/tmp/PlainBopomofo.tiff"];
[self makeIconForObject:iconRenderView size:NSMakeSize(32, 32) filename:@"/tmp/PlainBopomofo@2x.tiff"];
[self makeIconForObject:@"AppIconRendererView" size:NSMakeSize(32, 32) filename:@"/tmp/Bopomofo-32.tiff"];
[self makeIconForObject:@"AppIconRendererView" size:NSMakeSize(57, 57) filename:@"/tmp/Bopomofo-57.tiff"];
[self makeIconForObject:@"AppIconRendererView" size:NSMakeSize(64, 64) filename:@"/tmp/Bopomofo-64.tiff"];
[self makeIconForObject:@"AppIconRendererView" size:NSMakeSize(72, 72) filename:@"/tmp/Bopomofo-72.tiff"];
[self makeIconForObject:@"AppIconRendererView" size:NSMakeSize(128, 128) filename:@"/tmp/Bopomofo-128.tiff"];
[self makeIconForObject:@"AppIconRendererView" size:NSMakeSize(144, 144) filename:@"/tmp/Bopomofo-144.tiff"];
[self makeIconForObject:@"AppIconRendererView" size:NSMakeSize(256, 256) filename:@"/tmp/Bopomofo-256.tiff"];
[self makeIconForObject:@"AppIconRendererView" size:NSMakeSize(512, 512) filename:@"/tmp/Bopomofo-512.tiff"];
iconRenderView.plainBopomofoIcon = NO;
iconRenderView.textMenuIcon = YES;
[self makeIconForObject:iconRenderView size:NSMakeSize(16, 16) filename:@"/tmp/BopomofoTextMenu.tiff"];
[self makeIconForObject:iconRenderView size:NSMakeSize(32, 32) filename:@"/tmp/BopomofoTextMenu@2x.tiff"];
[self makeIconForObject:iconRenderView size:NSMakeSize(16, 16) filename:@"/tmp/Bopomofo_16x16.tiff"];
[self makeIconForObject:iconRenderView size:NSMakeSize(32, 32) filename:@"/tmp/Bopomofo_16x16@2x.tiff"];
[self makeIconForObject:iconRenderView size:NSMakeSize(32, 32) filename:@"/tmp/Bopomofo_32x32.tiff"];
[self makeIconForObject:iconRenderView size:NSMakeSize(64, 64) filename:@"/tmp/Bopomofo_32x32@2x.tiff"];
[self makeIconForObject:@"AppIconRendererView" size:NSMakeSize(64, 64) filename:@"/tmp/Bopomofo_64x64.tiff"];
[self makeIconForObject:@"AppIconRendererView" size:NSMakeSize(128, 128) filename:@"/tmp/Bopomofo_64x64@2x.tiff"];
[self makeIconForObject:@"AppIconRendererView" size:NSMakeSize(128, 128) filename:@"/tmp/Bopomofo_128x128.tiff"];
[self makeIconForObject:@"AppIconRendererView" size:NSMakeSize(256, 256) filename:@"/tmp/Bopomofo_128x128@2x.tiff"];
[self makeIconForObject:@"AppIconRendererView" size:NSMakeSize(256, 256) filename:@"/tmp/Bopomofo_256x256.tiff"];
[self makeIconForObject:@"AppIconRendererView" size:NSMakeSize(512, 512) filename:@"/tmp/Bopomofo_256x256@2x.tiff"];
[self makeIconForObject:@"AppIconRendererView" size:NSMakeSize(512, 512) filename:@"/tmp/Bopomofo_512x512.tiff"];
[self makeIconForObject:@"AppIconRendererView" size:NSMakeSize(1024, 1024) filename:@"/tmp/Bopomofo_512x512@2x.tiff"];
NSRunAlertPanel(@"Icons Generated", @"TIFF files are placed in /tmp", @"Dismiss", nil, nil);
}

View File

@ -1361,7 +1361,6 @@
<string key="NSFrame">{{180, 20}, {256, 256}}</string>
<reference key="NSSuperview" ref="439893737"/>
<reference key="NSWindow"/>
<reference key="NSNextKeyView"/>
<string key="NSClassName">AppIconRendererView</string>
</object>
<object class="NSCustomView" id="249506468">
@ -2107,6 +2106,22 @@
</object>
<int key="connectionID">539</int>
</object>
<object class="IBConnectionRecord">
<object class="IBOutletConnection" key="connection">
<string key="label">bopomofoIconRenderView</string>
<reference key="source" ref="976324537"/>
<reference key="destination" ref="497031166"/>
</object>
<int key="connectionID">542</int>
</object>
<object class="IBConnectionRecord">
<object class="IBOutletConnection" key="connection">
<string key="label">bopomofoIconRenderView2x</string>
<reference key="source" ref="976324537"/>
<reference key="destination" ref="373465065"/>
</object>
<int key="connectionID">543</int>
</object>
</object>
<object class="IBMutableOrderedSet" key="objectRecords">
<object class="NSArray" key="orderedObjects">
@ -3540,7 +3555,7 @@
<reference key="dict.values" ref="0"/>
</object>
<nil key="sourceID"/>
<int key="maxID">541</int>
<int key="maxID">543</int>
</object>
<object class="IBClassDescriber" key="IBDocument.Classes">
<object class="NSMutableArray" key="referencedPartialClassDescriptions">
@ -3568,12 +3583,16 @@
<bool key="EncodedWithXMLCoder">YES</bool>
<object class="NSArray" key="dict.sortedKeys">
<bool key="EncodedWithXMLCoder">YES</bool>
<string>bopomofoIconRenderView</string>
<string>bopomofoIconRenderView2x</string>
<string>faviconRenderView</string>
<string>selectedTISIconRendererView</string>
<string>window</string>
</object>
<object class="NSArray" key="dict.values">
<bool key="EncodedWithXMLCoder">YES</bool>
<string>BopomofoIconRenderView</string>
<string>BopomofoIconRenderView</string>
<string>TISIconRendererView</string>
<string>TISIconRendererView</string>
<string>NSWindow</string>
@ -3583,12 +3602,22 @@
<bool key="EncodedWithXMLCoder">YES</bool>
<object class="NSArray" key="dict.sortedKeys">
<bool key="EncodedWithXMLCoder">YES</bool>
<string>bopomofoIconRenderView</string>
<string>bopomofoIconRenderView2x</string>
<string>faviconRenderView</string>
<string>selectedTISIconRendererView</string>
<string>window</string>
</object>
<object class="NSArray" key="dict.values">
<bool key="EncodedWithXMLCoder">YES</bool>
<object class="IBToOneOutletInfo">
<string key="name">bopomofoIconRenderView</string>
<string key="candidateClassName">BopomofoIconRenderView</string>
</object>
<object class="IBToOneOutletInfo">
<string key="name">bopomofoIconRenderView2x</string>
<string key="candidateClassName">BopomofoIconRenderView</string>
</object>
<object class="IBToOneOutletInfo">
<string key="name">faviconRenderView</string>
<string key="candidateClassName">TISIconRendererView</string>