Changeset 14255
- Timestamp:
- 11/30/2005 07:58:49 PM (3 years ago)
- Files:
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
branches/adium-0.8/Frameworks/Adium Framework/ESFileTransfer.m
r14111 r14255 19 19 #import "ESFileTransfer.h" 20 20 21 22 #define UPLOAD_ARROW [NSString stringWithFormat:@"%C", 0x2B06] 23 #define DOWNLOAD_ARROW [NSString stringWithFormat:@"%C", 0x2B07] 24 21 static NSBezierPath *arrowPath = nil; 25 22 26 23 @implementation ESFileTransfer … … 271 268 if (extension && [extension length]) { 272 269 NSImage *systemIcon = [[NSWorkspace sharedWorkspace] iconForFileType:extension]; 273 NSString *badgeArrow = nil;274 270 NSFont *appleGothicFont = [NSFont fontWithName:@"AppleGothic" size:24]; 275 271 276 switch (type) { 277 case Incoming_FileTransfer: 278 badgeArrow = DOWNLOAD_ARROW; 279 break; 280 case Outgoing_FileTransfer: 281 badgeArrow = UPLOAD_ARROW; 282 break; 283 case Unknown_FileTransfer: 284 default: 285 break; 286 } 287 288 if (!badgeArrow || !appleGothicFont) 289 return systemIcon; 290 272 BOOL pointingDown = (type == Incoming_FileTransfer); 273 BOOL drawArrow = pointingDown || (type == Outgoing_FileTransfer); 274 291 275 // If type is Incoming (*down*load) or Outgoing (*up*load), overlay an arrow in a circle. 292 276 iconImage = [[NSImage alloc] initWithSize:[systemIcon size]]; 293 277 294 278 NSRect rect = { NSZeroPoint, [iconImage size] }; 295 NSRect bottomRight = NSMakeRect(NSMidX(rect), ([iconImage isFlipped] ? NSMidY(rect) : NSMinY(rect)), (NSWidth(rect)/2.0), (NSHeight(rect)/2.0)); 296 297 NSMutableDictionary *atts = [(NSMutableDictionary *)[[NSDictionary dictionaryWithObjectsAndKeys: 298 [NSColor alternateSelectedControlColor], NSForegroundColorAttributeName, 299 appleGothicFont, NSFontAttributeName, // AppleGothic has our arrow glyphs 300 nil] mutableCopy] autorelease]; 301 302 NSSize arrowSize = [badgeArrow sizeWithAttributes:atts]; 303 while (arrowSize.height > NSHeight(bottomRight)*0.9) { // shrink arrow to fit 304 NSFont *tempFont = (NSFont *)[atts objectForKey:NSFontAttributeName]; 305 [atts setObject:[NSFont fontWithName:[tempFont fontName] size:[tempFont pointSize]*0.99] forKey:NSFontAttributeName]; 306 arrowSize = [badgeArrow sizeWithAttributes:atts]; 307 } 308 279 NSRect bottomRight = NSMakeRect(NSMidX(rect), 280 ([iconImage isFlipped] ? NSMidY(rect) : NSMinY(rect)), 281 (NSWidth(rect)/2.0), 282 (NSHeight(rect)/2.0)); 283 309 284 [iconImage lockFocus]; 310 285 311 [systemIcon compositeToPoint:NS MakePoint(0.0,0.0)operation:NSCompositeSourceOver];286 [systemIcon compositeToPoint:NSZeroPoint operation:NSCompositeSourceOver]; 312 287 313 288 float line = ((NSWidth(bottomRight) / 15) + ((NSHeight(bottomRight) / 15) / 2)); … … 317 292 NSHeight(bottomRight) - (line)); 318 293 294 //draw our circle background... 319 295 NSBezierPath *circle = [NSBezierPath bezierPathWithOvalInRect:circleRect]; 320 296 [circle setLineWidth:line]; … … 323 299 [circle fill]; 324 300 [circle stroke]; 325 326 NSMutableParagraphStyle *mps = [[NSParagraphStyle defaultParagraphStyle] mutableCopy]; 327 [mps setAlignment:NSCenterTextAlignment]; 328 float lineheight = NSHeight(circleRect) * 0.99; 329 [mps setMaximumLineHeight:lineheight]; 330 [mps setMinimumLineHeight:lineheight]; 331 [mps setLineHeightMultiple:lineheight]; 332 [atts setObject:mps forKey:NSParagraphStyleAttributeName]; 333 [mps release]; 334 335 [badgeArrow drawInRect:circleRect withAttributes:atts]; 301 302 //and the arrow on top of it. 303 if(drawArrow) { 304 NSBezierPath *arrow = [self arrowPathInSize:bottomRight.size pointingDown:pointingDown]; 305 306 //bring it into position. 307 NSAffineTransform *transform = [NSAffineTransform transform]; 308 [transform translateXBy:circleRect.origin.x yBy:circleRect.origin.y]; 309 [arrow transformUsingAffineTransform:transform]; 310 311 [[NSColor alternateSelectedControlColor] setFill]; 312 [arrow fill]; 313 } 336 314 337 315 [iconImage unlockFocus];