Revision: 5878
http://skim-app.svn.sourceforge.net/skim-app/?rev=5878&view=rev
Author: hofman
Date: 2009-10-14 16:52:21 +0000 (Wed, 14 Oct 2009)
Log Message:
-----------
don't create images at a fixed size, instead make sure the images are drawn at
the correct size
Modified Paths:
--------------
trunk/NSImage_SKExtensions.h
trunk/NSImage_SKExtensions.m
trunk/NSMenu_SKExtensions.h
trunk/NSMenu_SKExtensions.m
trunk/SKApplicationController.m
trunk/SKBookmark.m
trunk/SKBookmarkController.m
trunk/SKTextWithIconCell.m
Modified: trunk/NSImage_SKExtensions.h
===================================================================
--- trunk/NSImage_SKExtensions.h 2009-10-14 16:18:17 UTC (rev 5877)
+++ trunk/NSImage_SKExtensions.h 2009-10-14 16:52:21 UTC (rev 5878)
@@ -125,21 +125,4 @@
+ (void)makeAdornImages;
+ (void)makeCursorImages;
-+ (NSImage *)smallFolderImage;
-+ (NSImage *)tinyFolderImage;
-
-+ (NSImage *)smallMissingFileImage;
-+ (NSImage *)tinyMissingFileImage;
-
-+ (NSImage *)smallMultipleFilesImage;
-+ (NSImage *)tinyMultipleFilesImage;
-
-+ (NSImage *)smallDeleteImage;
-+ (NSImage *)tinyDeleteImage;
-
-- (void)drawFlippedInRect:(NSRect)dstRect fromRect:(NSRect)srcRect
operation:(NSCompositingOperation)op fraction:(CGFloat)delta;
-- (void)drawFlipped:(BOOL)isFlipped inRect:(NSRect)dstRect
fromRect:(NSRect)srcRect operation:(NSCompositingOperation)op
fraction:(CGFloat)delta;
-- (void)drawMirroredAndFlipped:(BOOL)isFlipped inRect:(NSRect)dstRect
fromRect:(NSRect)srcRect operation:(NSCompositingOperation)op
fraction:(CGFloat)delta;
-- (void)drawMirrored:(BOOL)isMirrored andFlipped:(BOOL)isFlipped
inRect:(NSRect)dstRect fromRect:(NSRect)srcRect
operation:(NSCompositingOperation)op fraction:(CGFloat)delta;
-
@end
Modified: trunk/NSImage_SKExtensions.m
===================================================================
--- trunk/NSImage_SKExtensions.m 2009-10-14 16:18:17 UTC (rev 5877)
+++ trunk/NSImage_SKExtensions.m 2009-10-14 16:52:21 UTC (rev 5878)
@@ -1330,8 +1330,9 @@
[toolbarSelectToolImage unlockFocus];
[toolbarSelectToolImage setName:SKImageNameToolbarSelectTool];
- toolbarNewFolderImage = [[self smallFolderImage] copy];
+ toolbarNewFolderImage = [[NSImage alloc] initWithSize:NSMakeSize(32.0,
32.0)];
[toolbarNewFolderImage lockFocus];
+ [[[NSWorkspace sharedWorkspace]
iconForFileType:NSFileTypeForHFSTypeCode(kGenericFolderIcon)]
drawInRect:NSMakeRect(0.0, 0.0, 32.0, 32.0) fromRect:NSZeroRect
operation:NSCompositeCopy fraction:1.0];
[[self class] drawAddBadgeAtPoint:NSMakePoint(18.0, 18.0)];
[toolbarNewFolderImage unlockFocus];
[toolbarNewFolderImage setName:SKImageNameToolbarNewFolder];
@@ -1865,149 +1866,4 @@
[zoomOutCursorImage setName:SKImageNameZoomOutCursor];
}
-#define smallImageSize NSMakeSize(32.0, 32.0)
-#define smallImageRect NSMakeRect(0.0, 0.0, 32.0, 32.0)
-#define tinyImageSize NSMakeSize(16.0, 16.0)
-#define tinyImageRect NSMakeRect(0.0, 0.0, 16.0, 16.0)
-
-+ (NSImage *)smallFolderImage {
- static NSImage *image = nil;
- if(image == nil) {
- NSImage *folder = [[NSWorkspace sharedWorkspace]
iconForFileType:NSFileTypeForHFSTypeCode(kGenericFolderIcon)];
- image = [[NSImage alloc] initWithSize:smallImageSize];
- [image lockFocus];
- [folder drawInRect:smallImageRect fromRect:NSZeroRect
operation:NSCompositeCopy fraction:1.0];
- [image unlockFocus];
- }
- return image;
-}
-
-+ (NSImage *)tinyFolderImage {
- static NSImage *image = nil;
- if(image == nil) {
- NSImage *folder = [[NSWorkspace sharedWorkspace]
iconForFileType:NSFileTypeForHFSTypeCode(kGenericFolderIcon)];
- image = [[NSImage alloc] initWithSize:tinyImageSize];
- [image lockFocus];
- [folder drawInRect:tinyImageRect fromRect:NSZeroRect
operation:NSCompositeCopy fraction:1.0];
- [image unlockFocus];
- }
- return image;
-}
-
-+ (NSImage *)smallMissingFileImage {
- static NSImage *image = nil;
- if(image == nil){
- image = [[NSImage alloc] initWithSize:smallImageSize];
- NSImage *genericDocImage = [[NSWorkspace sharedWorkspace]
iconForFileType:NSFileTypeForHFSTypeCode(kGenericDocumentIcon)];
- NSImage *questionMark = [[NSWorkspace sharedWorkspace]
iconForFileType:NSFileTypeForHFSTypeCode(kQuestionMarkIcon)];
- [image lockFocus];
- [genericDocImage drawInRect:smallImageRect fromRect:NSZeroRect
operation:NSCompositeCopy fraction:0.7];
- [questionMark drawInRect:NSMakeRect(6.0, 4.0, 20.0, 20.0)
fromRect:NSZeroRect operation:NSCompositeSourceOver fraction:0.7];
- [image unlockFocus];
- }
- return image;
-}
-
-+ (NSImage *)tinyMissingFileImage {
- static NSImage *image = nil;
- if(image == nil){
- image = [[NSImage alloc] initWithSize:tinyImageSize];
- NSImage *genericDocImage = [[NSWorkspace sharedWorkspace]
iconForFileType:NSFileTypeForHFSTypeCode(kGenericDocumentIcon)];
- NSImage *questionMark = [[NSWorkspace sharedWorkspace]
iconForFileType:NSFileTypeForHFSTypeCode(kQuestionMarkIcon)];
- [image lockFocus];
- [genericDocImage drawInRect:tinyImageRect fromRect:NSZeroRect
operation:NSCompositeCopy fraction:0.7];
- [questionMark drawInRect:NSMakeRect(3.0, 2.0, 10.0, 10.0)
fromRect:NSZeroRect operation:NSCompositeSourceOver fraction:0.7];
- [image unlockFocus];
- }
- return image;
-}
-
-+ (NSImage *)smallMultipleFilesImage {
- static NSImage *image = nil;
- if(image == nil) {
- image = [[NSImage alloc] initWithSize:smallImageSize];
- NSImage *multipleFilesImage = [NSImage
imageNamed:NSImageNameMultipleDocuments];
- NSRect sourceRect = {NSZeroPoint, [multipleFilesImage size]};
- [image lockFocus];
- [multipleFilesImage drawInRect:smallImageRect fromRect:sourceRect
operation:NSCompositeCopy fraction:1.0];
- [image unlockFocus];
- }
- return image;
-}
-
-+ (NSImage *)tinyMultipleFilesImage {
- static NSImage *image = nil;
- if(image == nil) {
- image = [[NSImage alloc] initWithSize:tinyImageSize];
- NSImage *multipleFilesImage = [NSImage
imageNamed:NSImageNameMultipleDocuments];
- NSRect sourceRect = {NSZeroPoint, [multipleFilesImage size]};
- [image lockFocus];
- [multipleFilesImage drawInRect:tinyImageRect fromRect:sourceRect
operation:NSCompositeCopy fraction:1.0];
- [image unlockFocus];
- }
- return image;
-}
-
-+ (NSImage *)smallDeleteImage {
- static NSImage *image = nil;
- if(image == nil) {
- NSImage *delete = [[NSWorkspace sharedWorkspace]
iconForFileType:NSFileTypeForHFSTypeCode(kToolbarDeleteIcon)];
- image = [[NSImage alloc] initWithSize:smallImageSize];
- [image lockFocus];
- [delete drawInRect:smallImageRect fromRect:NSZeroRect
operation:NSCompositeCopy fraction:1.0];
- [image unlockFocus];
- }
- return image;
-}
-
-+ (NSImage *)tinyDeleteImage {
- static NSImage *image = nil;
- if(image == nil) {
- NSImage *delete = [[NSWorkspace sharedWorkspace]
iconForFileType:NSFileTypeForHFSTypeCode(kToolbarDeleteIcon)];
- image = [[NSImage alloc] initWithSize:tinyImageSize];
- [image lockFocus];
- [delete drawInRect:tinyImageRect fromRect:NSZeroRect
operation:NSCompositeCopy fraction:1.0];
- [image unlockFocus];
- }
- return image;
-}
-
-- (void)drawFlippedInRect:(NSRect)dstRect fromRect:(NSRect)srcRect
operation:(NSCompositingOperation)op fraction:(CGFloat)delta {
- [self drawMirrored:NO andFlipped:YES inRect:dstRect fromRect:srcRect
operation:op fraction:delta];
-}
-
-- (void)drawFlipped:(BOOL)isFlipped inRect:(NSRect)dstRect
fromRect:(NSRect)srcRect operation:(NSCompositingOperation)op
fraction:(CGFloat)delta {
- [self drawMirrored:NO andFlipped:isFlipped inRect:dstRect fromRect:srcRect
operation:op fraction:delta];
-}
-
-- (void)drawMirroredAndFlipped:(BOOL)isFlipped inRect:(NSRect)dstRect
fromRect:(NSRect)srcRect operation:(NSCompositingOperation)op
fraction:(CGFloat)delta {
- [self drawMirrored:YES andFlipped:isFlipped inRect:dstRect
fromRect:srcRect operation:op fraction:delta];
-}
-
-- (void)drawMirrored:(BOOL)isMirrored andFlipped:(BOOL)isFlipped
inRect:(NSRect)dstRect fromRect:(NSRect)srcRect
operation:(NSCompositingOperation)op fraction:(CGFloat)delta {
- if (isMirrored || isFlipped) {
- CGFloat dx1 = 0.0, dx2 = 0.0, dy1 = 0.0, dy2 = 0.0, sx = 1.0, sy = 1.0;
- if (isMirrored) {
- sx = -1.0;
- dx1 = NSMaxX(dstRect);
- dx2 = -NSMinX(dstRect);
- }
- if (isFlipped) {
- sy = -1.0;
- dy1 = NSMaxY(dstRect);
- dy2 = -NSMinY(dstRect);
- }
- [NSGraphicsContext saveGraphicsState];
- NSAffineTransform *transform = [NSAffineTransform transform];
- [transform translateXBy:dx1 yBy:dy1];
- [transform scaleXBy:sx yBy:sy];
- [transform translateXBy:dx2 yBy:dy2];
- [transform concat];
- [self drawInRect:dstRect fromRect:srcRect operation:op fraction:delta];
- [NSGraphicsContext restoreGraphicsState];
- } else {
- [self drawInRect:dstRect fromRect:srcRect operation:op fraction:delta];
- }
-}
-
@end
Modified: trunk/NSMenu_SKExtensions.h
===================================================================
--- trunk/NSMenu_SKExtensions.h 2009-10-14 16:18:17 UTC (rev 5877)
+++ trunk/NSMenu_SKExtensions.h 2009-10-14 16:52:21 UTC (rev 5878)
@@ -70,4 +70,6 @@
- (id)initWithTitle:(NSString *)aString imageNamed:(NSString *)anImageName
action:(SEL)aSelector target:(id)aTarget tag:(NSInteger)aTag;
- (id)initWithTitle:(NSString *)aString submenu:(NSMenu *)aSubmenu;
+- (void)setImageAndSize:(NSImage *)image;
+
@end
Modified: trunk/NSMenu_SKExtensions.m
===================================================================
--- trunk/NSMenu_SKExtensions.m 2009-10-14 16:18:17 UTC (rev 5877)
+++ trunk/NSMenu_SKExtensions.m 2009-10-14 16:52:21 UTC (rev 5878)
@@ -146,4 +146,24 @@
return self;
}
+- (void)setImageAndSize:(NSImage *)image {
+ NSLayoutManager *layoutManager = [[NSLayoutManager alloc] init];
+ [layoutManager setTypesetterBehavior:NSTypesetterBehavior_10_4];
+ CGFloat lineHeight = [layoutManager defaultLineHeightForFont:[NSFont
menuFontOfSize:0]];
+ [layoutManager release];
+ NSSize dstSize = { lineHeight, lineHeight };
+ NSSize srcSize = [image size];
+ if (NSEqualSizes(srcSize, dstSize)) {
+ [self setImage:image];
+ } else {
+ NSImage *newImage = [[NSImage alloc] initWithSize:dstSize];
+ [newImage lockFocus];
+ [[NSGraphicsContext currentContext]
setImageInterpolation:NSImageInterpolationHigh];
+ [image drawInRect:NSMakeRect(0, 0, dstSize.width, dstSize.height)
fromRect:NSZeroRect operation:NSCompositeCopy fraction:1.0];
+ [newImage unlockFocus];
+ [self setImage:newImage];
+ [newImage release];
+ }
+}
+
@end
Modified: trunk/SKApplicationController.m
===================================================================
--- trunk/SKApplicationController.m 2009-10-14 16:18:17 UTC (rev 5877)
+++ trunk/SKApplicationController.m 2009-10-14 16:52:21 UTC (rev 5878)
@@ -349,7 +349,7 @@
case SKBookmarkTypeFolder:
item = [menu addItemWithTitle:[bm label] submenu:[[[NSMenu
allocWithZone:[NSMenu menuZone]] initWithTitle:[bm label]] autorelease]];
[item setRepresentedObject:bm];
- [item setImage:[bm icon]];
+ [item setImageAndSize:[bm icon]];
[[item submenu] setDelegate:self];
break;
case SKBookmarkTypeSeparator:
@@ -358,7 +358,7 @@
default:
item = [menu addItemWithTitle:[bm label]
action:@selector(openBookmark:) target:self];
[item setRepresentedObject:bm];
- [item setImage:[bm icon]];
+ [item setImageAndSize:[bm icon]];
break;
}
}
Modified: trunk/SKBookmark.m
===================================================================
--- trunk/SKBookmark.m 2009-10-14 16:18:17 UTC (rev 5877)
+++ trunk/SKBookmark.m 2009-10-14 16:52:21 UTC (rev 5878)
@@ -280,6 +280,30 @@
@implementation SKFileBookmark
++ (NSImage *)missingFileImage {
+ static NSImage *image = nil;
+ if (image == nil) {
+ NSImage *image = [[NSImage alloc] initWithSize:NSMakeSize(32.0, 32.0)];
+ NSImage *genericDocImage = [[NSWorkspace sharedWorkspace]
iconForFileType:NSFileTypeForHFSTypeCode(kGenericDocumentIcon)];
+ NSImage *questionMark = [[NSWorkspace sharedWorkspace]
iconForFileType:NSFileTypeForHFSTypeCode(kQuestionMarkIcon)];
+ NSImage *tmpImage = [[NSImage alloc] initWithSize:NSMakeSize(32.0,
32.0)];
+ [tmpImage lockFocus];
+ [genericDocImage drawInRect:NSMakeRect(0.0, 0.0, 32.0, 32.0)
fromRect:NSZeroRect operation:NSCompositeCopy fraction:0.7];
+ [questionMark drawInRect:NSMakeRect(6.0, 4.0, 20.0, 20.0)
fromRect:NSZeroRect operation:NSCompositeSourceOver fraction:0.7];
+ [tmpImage unlockFocus];
+ [image addRepresentation:[[tmpImage representations] lastObject]];
+ [tmpImage release];
+ tmpImage = [[NSImage alloc] initWithSize:NSMakeSize(16.0, 16.0)];
+ [tmpImage lockFocus];
+ [genericDocImage drawInRect:NSMakeRect(0.0, 0.0, 16.0, 16.0)
fromRect:NSZeroRect operation:NSCompositeCopy fraction:0.7];
+ [questionMark drawInRect:NSMakeRect(3.0, 2.0, 10.0, 10.0)
fromRect:NSZeroRect operation:NSCompositeSourceOver fraction:0.7];
+ [tmpImage unlockFocus];
+ [image addRepresentation:[[tmpImage representations] lastObject]];
+ [tmpImage release];
+ }
+ return image;
+}
+
- (id)initWithAlias:(BDAlias *)anAlias pageIndex:(NSUInteger)aPageIndex
label:(NSString *)aLabel {
if (self = [super init]) {
if (anAlias) {
@@ -342,33 +366,8 @@
}
- (NSImage *)icon {
- static NSMutableDictionary *tinyIcons = nil;
-
NSString *filePath = [self path];
-
- if (filePath == nil)
- return [NSImage tinyMissingFileImage];
-
- NSString *extension = [filePath pathExtension];
- NSImage *icon = [tinyIcons objectForKey:extension];
-
- if (icon == nil) {
- if (tinyIcons == nil)
- tinyIcons = [[NSMutableDictionary alloc] init];
- NSImage *image = [[NSWorkspace sharedWorkspace]
iconForFileType:extension];
- if (image) {
- NSRect sourceRect = {NSZeroPoint, [image size]};
- NSRect targetRect = NSMakeRect(0.0, 0.0, 16.0, 16.0);
- icon = [[NSImage alloc] initWithSize:targetRect.size];
- [icon lockFocus];
- [[NSGraphicsContext currentContext]
setImageInterpolation:NSImageInterpolationHigh];
- [image drawInRect:targetRect fromRect:sourceRect
operation:NSCompositeCopy fraction:1.0];
- [icon unlockFocus];
- [tinyIcons setObject:icon forKey:extension];
- [icon release];
- }
- }
- return icon;
+ return filePath ? [[NSWorkspace sharedWorkspace] iconForFile:filePath] :
[[self class] missingFileImage];
}
- (NSUInteger)pageIndex {
@@ -428,7 +427,7 @@
}
- (NSImage *)icon {
- return [NSImage tinyFolderImage];
+ return [[NSWorkspace sharedWorkspace]
iconForFileType:NSFileTypeForHFSTypeCode(kGenericFolderIcon)];
}
- (NSString *)label {
@@ -479,7 +478,7 @@
}
- (NSImage *)icon {
- return [NSImage tinyMultipleFilesImage];
+ return [NSImage imageNamed:NSImageNameMultipleDocuments];
}
@end
Modified: trunk/SKBookmarkController.m
===================================================================
--- trunk/SKBookmarkController.m 2009-10-14 16:18:17 UTC (rev 5877)
+++ trunk/SKBookmarkController.m 2009-10-14 16:52:21 UTC (rev 5878)
@@ -780,7 +780,7 @@
item = [[SKToolbarItem alloc]
initWithItemIdentifier:SKBookmarksDeleteToolbarItemIdentifier];
[item setLabels:NSLocalizedString(@"Delete", @"Toolbar item label")];
[item setToolTip:NSLocalizedString(@"Delete Selected Items", @"Tool tip
message")];
- [item setImage:[NSImage smallDeleteImage]];
+ [item setImage:[[NSWorkspace sharedWorkspace]
iconForFileType:NSFileTypeForHFSTypeCode(kToolbarDeleteIcon)]];
[item setTarget:self];
[item setAction:@selector(deleteBookmark:)];
[toolbarItems setObject:item
forKey:SKBookmarksDeleteToolbarItemIdentifier];
Modified: trunk/SKTextWithIconCell.m
===================================================================
--- trunk/SKTextWithIconCell.m 2009-10-14 16:18:17 UTC (rev 5877)
+++ trunk/SKTextWithIconCell.m 2009-10-14 16:52:21 UTC (rev 5878)
@@ -102,13 +102,12 @@
if (nil != img) {
- NSRect srcRect = NSZeroRect;
- srcRect.size = [img size];
+ NSSize imgSize = [img size];
NSRect drawFrame = iconRect;
- CGFloat ratio = MIN(NSWidth(drawFrame) / srcRect.size.width,
NSHeight(drawFrame) / srcRect.size.height);
- drawFrame.size.width = ratio * srcRect.size.width;
- drawFrame.size.height = ratio * srcRect.size.height;
+ CGFloat ratio = MIN(NSWidth(drawFrame) / imgSize.width,
NSHeight(drawFrame) / imgSize.height);
+ drawFrame.size.width = ratio * imgSize.width;
+ drawFrame.size.height = ratio * imgSize.height;
drawFrame = SKCenterRect(drawFrame, drawFrame.size, [controlView
isFlipped]);
@@ -118,7 +117,15 @@
// this is the critical part that NSImageCell doesn't do
[ctxt setImageInterpolation:NSImageInterpolationHigh];
- [img drawFlipped:[controlView isFlipped] inRect:drawFrame
fromRect:srcRect operation:NSCompositeSourceOver fraction:1.0];
+ if ([controlView isFlipped]) {
+ NSAffineTransform *transform = [NSAffineTransform transform];
+ [transform translateXBy:0.0 yBy:NSMaxY(drawFrame)];
+ [transform scaleXBy:1.0 yBy:-1.0];
+ [transform translateXBy:0.0 yBy:-NSMinY(drawFrame)];
+ [transform concat];
+ [img drawInRect:drawFrame fromRect:NSZeroRect
operation:NSCompositeSourceOver fraction:1.0];
+ }
+ [img drawInRect:drawFrame fromRect:NSZeroRect
operation:NSCompositeSourceOver fraction:1.0];
[ctxt restoreGraphicsState];
}
This was sent by the SourceForge.net collaborative development platform, the
world's largest Open Source development site.
------------------------------------------------------------------------------
Come build with us! The BlackBerry(R) Developer Conference in SF, CA
is the only developer event you need to attend this year. Jumpstart your
developing skills, take BlackBerry mobile applications to market and stay
ahead of the curve. Join us from November 9 - 12, 2009. Register now!
http://p.sf.net/sfu/devconference
_______________________________________________
Skim-app-commit mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/skim-app-commit