From f4f3a19447ccbf42a485f79d624c277e60baabe8 Mon Sep 17 00:00:00 2001 From: Lukhnos Liu Date: Sat, 8 Sep 2012 22:02:35 -0700 Subject: [PATCH] Expand the icon maker. --- Source/IconMaker/BopomofoIconRenderView.h | 3 +- Source/IconMaker/BopomofoIconRenderView.m | 88 ++++++++++++++++++++--- Source/IconMaker/IconMakerAppDelegate.h | 9 ++- Source/IconMaker/IconMakerAppDelegate.m | 69 +++++++++++------- Source/IconMaker/en.lproj/MainMenu.xib | 33 ++++++++- 5 files changed, 158 insertions(+), 44 deletions(-) diff --git a/Source/IconMaker/BopomofoIconRenderView.h b/Source/IconMaker/BopomofoIconRenderView.h index 08fe6ee4..bbdca90d 100644 --- a/Source/IconMaker/BopomofoIconRenderView.h +++ b/Source/IconMaker/BopomofoIconRenderView.h @@ -9,5 +9,6 @@ #import @interface BopomofoIconRenderView : NSView - +@property (assign, nonatomic) BOOL textMenuIcon; +@property (assign, nonatomic) BOOL plainBopomofoIcon; @end diff --git a/Source/IconMaker/BopomofoIconRenderView.m b/Source/IconMaker/BopomofoIconRenderView.m index 3a888065..d0aa15cb 100644 --- a/Source/IconMaker/BopomofoIconRenderView.m +++ b/Source/IconMaker/BopomofoIconRenderView.m @@ -23,26 +23,67 @@ boundsRect.size.width -= 1.0; - [NSGraphicsContext saveGraphicsState]; + 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]; - NSColor *darkGrayColor = [NSColor colorWithDeviceWhite:0.3 alpha:1.0]; - [darkGrayColor setFill]; - [[NSBezierPath bezierPathWithRoundedRect:boundsRect xRadius:2.0 yRadius:2.0] fill]; - [NSGraphicsContext restoreGraphicsState]; + 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 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; - textColor = [NSColor colorWithDeviceWhite:1.0 alpha:1.0]; + + 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]; + [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 diff --git a/Source/IconMaker/IconMakerAppDelegate.h b/Source/IconMaker/IconMakerAppDelegate.h index 190772cd..59eed283 100644 --- a/Source/IconMaker/IconMakerAppDelegate.h +++ b/Source/IconMaker/IconMakerAppDelegate.h @@ -34,13 +34,12 @@ #import #import "TISIconRendererView.h" +#import "BopomofoIconRenderView.h" -@interface IconMakerAppDelegate : NSObject { -@private - NSWindow *window; -} - +@interface IconMakerAppDelegate : NSObject @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 diff --git a/Source/IconMaker/IconMakerAppDelegate.m b/Source/IconMaker/IconMakerAppDelegate.m index 51d56a25..0e297add 100644 --- a/Source/IconMaker/IconMakerAppDelegate.m +++ b/Source/IconMaker/IconMakerAppDelegate.m @@ -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,31 +62,52 @@ - (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 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.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:faviconRenderView size:NSMakeSize(16, 16) filename:@"/tmp/BopomofoFavicon.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]; + + 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"]; + + 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"]; - - [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"]; - NSRunAlertPanel(@"Icons Generated", @"TIFF files are placed in /tmp", @"Dismiss", nil, nil); } diff --git a/Source/IconMaker/en.lproj/MainMenu.xib b/Source/IconMaker/en.lproj/MainMenu.xib index 859c8d83..49314f54 100644 --- a/Source/IconMaker/en.lproj/MainMenu.xib +++ b/Source/IconMaker/en.lproj/MainMenu.xib @@ -1361,7 +1361,6 @@ {{180, 20}, {256, 256}} - AppIconRendererView @@ -2107,6 +2106,22 @@ 539 + + + bopomofoIconRenderView + + + + 542 + + + + bopomofoIconRenderView2x + + + + 543 + @@ -3540,7 +3555,7 @@ - 541 + 543 @@ -3568,12 +3583,16 @@ YES YES + bopomofoIconRenderView + bopomofoIconRenderView2x faviconRenderView selectedTISIconRendererView window YES + BopomofoIconRenderView + BopomofoIconRenderView TISIconRendererView TISIconRendererView NSWindow @@ -3583,12 +3602,22 @@ YES YES + bopomofoIconRenderView + bopomofoIconRenderView2x faviconRenderView selectedTISIconRendererView window YES + + bopomofoIconRenderView + BopomofoIconRenderView + + + bopomofoIconRenderView2x + BopomofoIconRenderView + faviconRenderView TISIconRendererView