Revision: 18066
http://bibdesk.svn.sourceforge.net/bibdesk/?rev=18066&view=rev
Author: hofman
Date: 2011-08-17 17:33:07 +0000 (Wed, 17 Aug 2011)
Log Message:
-----------
use static function to avoid code duplication to create badged group icons
Modified Paths:
--------------
trunk/bibdesk/BDSKSharedGroup.m
Modified: trunk/bibdesk/BDSKSharedGroup.m
===================================================================
--- trunk/bibdesk/BDSKSharedGroup.m 2011-08-17 06:35:28 UTC (rev 18065)
+++ trunk/bibdesk/BDSKSharedGroup.m 2011-08-17 17:33:07 UTC (rev 18066)
@@ -58,68 +58,45 @@
return [NSImage imageNamed:NSImageNameBonjour];
}
+static inline NSImage *createBadgedIcon(NSImage *icon, NSString *badgeName) {
+ NSRect iconRect = NSMakeRect(0.0, 0.0, 32.0, 32.0);
+ NSRect badgeRect = NSMakeRect(20.0, 0.0, 12.0, 16.0);
+ NSImage *image = [[NSImage alloc] initWithSize:iconRect.size];
+ NSImage *badge = [NSImage imageNamed:badgeName];
+
+ [image lockFocus];
+ [[NSGraphicsContext currentContext]
setImageInterpolation:NSImageInterpolationHigh];
+ [icon drawInRect:iconRect fromRect:NSZeroRect
operation:NSCompositeSourceOver fraction:1.0];
+ [badge drawInRect:badgeRect fromRect:NSZeroRect
operation:NSCompositeSourceOver fraction:0.65];
+ [[NSGraphicsContext currentContext]
setImageInterpolation:NSImageInterpolationDefault];
+ [image unlockFocus];
+
+ iconRect = NSMakeRect(0.0, 0.0, 16.0, 16.0);
+ badgeRect = NSMakeRect(10.0, 0.0, 6.0, 8.0);
+
+ NSImage *tinyImage = [[NSImage alloc] initWithSize:iconRect.size];
+
+ [tinyImage lockFocus];
+ [[NSGraphicsContext currentContext]
setImageInterpolation:NSImageInterpolationHigh];
+ [icon drawInRect:iconRect fromRect:NSZeroRect
operation:NSCompositeSourceOver fraction:1.0];
+ [badge drawInRect:badgeRect fromRect:NSZeroRect
operation:NSCompositeSourceOver fraction:0.65];
+ [[NSGraphicsContext currentContext]
setImageInterpolation:NSImageInterpolationDefault];
+ [tinyImage unlockFocus];
+ [image addRepresentation:[[tinyImage representations] lastObject]];
+ [tinyImage release];
+
+ return image;
+}
+
+ (NSImage *)lockedIcon {
- if(lockedIcon == nil){
- NSRect iconRect = NSMakeRect(0.0, 0.0, 32.0, 32.0);
- NSRect badgeRect = NSMakeRect(20.0, 0.0, 12.0, 16.0);
- NSImage *image = [[NSImage alloc] initWithSize:iconRect.size];
- NSImage *badge = [NSImage imageNamed:NSImageNameLockLockedTemplate];
-
- [image lockFocus];
- [[NSGraphicsContext currentContext]
setImageInterpolation:NSImageInterpolationHigh];
- [[self icon] drawInRect:iconRect fromRect:NSZeroRect
operation:NSCompositeSourceOver fraction:1.0];
- [badge drawInRect:badgeRect fromRect:NSZeroRect
operation:NSCompositeSourceOver fraction:0.65];
- [[NSGraphicsContext currentContext]
setImageInterpolation:NSImageInterpolationDefault];
- [image unlockFocus];
-
- iconRect = NSMakeRect(0.0, 0.0, 16.0, 16.0);
- badgeRect = NSMakeRect(10.0, 0.0, 6.0, 8.0);
-
- NSImage *tinyImage = [[NSImage alloc] initWithSize:iconRect.size];
-
- [tinyImage lockFocus];
- [[NSGraphicsContext currentContext]
setImageInterpolation:NSImageInterpolationHigh];
- [[self icon] drawInRect:iconRect fromRect:NSZeroRect
operation:NSCompositeSourceOver fraction:1.0];
- [badge drawInRect:badgeRect fromRect:NSZeroRect
operation:NSCompositeSourceOver fraction:0.65];
- [[NSGraphicsContext currentContext]
setImageInterpolation:NSImageInterpolationDefault];
- [tinyImage unlockFocus];
- [image addRepresentation:[[tinyImage representations] lastObject]];
- [tinyImage release];
-
- lockedIcon = image;
- }
+ if(lockedIcon == nil)
+ lockedIcon = createIconWithLock([self icon],
NSImageNameLockLockedTemplate);
return lockedIcon;
}
+ (NSImage *)unlockedIcon {
- if(unlockedIcon == nil){
- NSRect iconRect = NSMakeRect(0.0, 0.0, 32.0, 32.0);
- NSRect badgeRect = NSMakeRect(20.0, 0.0, 12.0, 16.0);
- NSImage *image = [[NSImage alloc] initWithSize:iconRect.size];
- NSImage *badge = [NSImage imageNamed:NSImageNameLockUnlockedTemplate];
-
- [image lockFocus];
- [[NSGraphicsContext currentContext]
setImageInterpolation:NSImageInterpolationHigh];
- [[self icon] drawInRect:iconRect fromRect:NSZeroRect
operation:NSCompositeSourceOver fraction:1.0];
- [badge drawInRect:badgeRect fromRect:NSZeroRect
operation:NSCompositeSourceOver fraction:0.65];
- [[NSGraphicsContext currentContext]
setImageInterpolation:NSImageInterpolationDefault];
- [image unlockFocus];
-
- iconRect = NSMakeRect(0.0, 0.0, 16.0, 16.0);
- badgeRect = NSMakeRect(10.0, 0.0, 6.0, 8.0);
-
- NSImage *tinyImage = [[NSImage alloc] initWithSize:iconRect.size];
-
- [tinyImage lockFocus];
- [[NSGraphicsContext currentContext]
setImageInterpolation:NSImageInterpolationHigh];
- [[self icon] drawInRect:iconRect fromRect:NSZeroRect
operation:NSCompositeSourceOver fraction:1.0];
- [badge drawInRect:badgeRect fromRect:NSZeroRect
operation:NSCompositeSourceOver fraction:0.65];
- [tinyImage unlockFocus];
- [image addRepresentation:[[tinyImage representations] lastObject]];
- [tinyImage release];
-
- unlockedIcon = image;
- }
+ if(unlockedIcon == nil)
+ unlockedIcon = createIconWithLock([self icon],
NSImageNameLockUnlockedTemplate);
return unlockedIcon;
}
This was sent by the SourceForge.net collaborative development platform, the
world's largest Open Source development site.
------------------------------------------------------------------------------
Get a FREE DOWNLOAD! and learn more about uberSVN rich system,
user administration capabilities and model configuration. Take
the hassle out of deploying and managing Subversion and the
tools developers use with it. http://p.sf.net/sfu/wandisco-d2d-2
_______________________________________________
Bibdesk-commit mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/bibdesk-commit