| File: | Frameworks/ShortcutRecorder/Source/SRCommon.m |
| Location: | line 242, column 3 |
| Description: | dead store |
| 1 | // |
| 2 | // SRCommon.m |
| 3 | // ShortcutRecorder |
| 4 | // |
| 5 | // Copyright 2006-2007 Contributors. All rights reserved. |
| 6 | // |
| 7 | // License: BSD |
| 8 | // |
| 9 | // Contributors: |
| 10 | // David Dauer |
| 11 | // Jesper |
| 12 | // Jamie Kirkpatrick |
| 13 | |
| 14 | #import "SRCommon.h" |
| 15 | #import "SRKeyCodeTransformer.h" |
| 16 | |
| 17 | //#define SRCommon_PotentiallyUsefulDebugInfo |
| 18 | |
| 19 | #ifdef SRCommon_PotentiallyUsefulDebugInfo |
| 20 | #define PUDNSLog(X,...) NSLog(X,##__VA_ARGS__) |
| 21 | #else |
| 22 | #define PUDNSLog(X,...) { ; } |
| 23 | #endif |
| 24 | |
| 25 | #pragma mark - |
| 26 | #pragma mark dummy class |
| 27 | |
| 28 | @implementation SRDummyClass @end |
| 29 | |
| 30 | #pragma mark - |
| 31 | |
| 32 | //---------------------------------------------------------- |
| 33 | // SRStringForKeyCode() |
| 34 | //---------------------------------------------------------- |
| 35 | NSString * SRStringForKeyCode( signed short keyCode ) |
| 36 | { |
| 37 | static SRKeyCodeTransformer *keyCodeTransformer = nil0; |
| 38 | if ( !keyCodeTransformer ) |
| 39 | keyCodeTransformer = [[SRKeyCodeTransformer alloc] init]; |
| 40 | return [keyCodeTransformer transformedValue:[NSNumber numberWithShort:keyCode]]; |
| 41 | } |
| 42 | |
| 43 | //---------------------------------------------------------- |
| 44 | // SRStringForCarbonModifierFlags() |
| 45 | //---------------------------------------------------------- |
| 46 | NSString * SRStringForCarbonModifierFlags( unsigned int flags ) |
| 47 | { |
| 48 | NSString *modifierFlagsString = [NSString stringWithFormat:@"%@%@%@%@", |
| 49 | ( flags & controlKey ? [NSString stringWithFormat:@"%C", KeyboardControlGlyph] : @"" ), |
| 50 | ( flags & optionKey ? [NSString stringWithFormat:@"%C", KeyboardOptionGlyph] : @"" ), |
| 51 | ( flags & shiftKey ? [NSString stringWithFormat:@"%C", KeyboardShiftGlyph] : @"" ), |
| 52 | ( flags & cmdKey ? [NSString stringWithFormat:@"%C", KeyboardCommandGlyph] : @"" )]; |
| 53 | return modifierFlagsString; |
| 54 | } |
| 55 | |
| 56 | //---------------------------------------------------------- |
| 57 | // SRStringForCarbonModifierFlagsAndKeyCode() |
| 58 | //---------------------------------------------------------- |
| 59 | NSString * SRStringForCarbonModifierFlagsAndKeyCode( unsigned int flags, signed short keyCode ) |
| 60 | { |
| 61 | return [NSString stringWithFormat: @"%@%@", |
| 62 | SRStringForCarbonModifierFlags( flags ), |
| 63 | SRStringForKeyCode( keyCode )]; |
| 64 | } |
| 65 | |
| 66 | //---------------------------------------------------------- |
| 67 | // SRStringForCocoaModifierFlags() |
| 68 | //---------------------------------------------------------- |
| 69 | NSString * SRStringForCocoaModifierFlags( unsigned int flags ) |
| 70 | { |
| 71 | NSString *modifierFlagsString = [NSString stringWithFormat:@"%@%@%@%@", |
| 72 | ( flags & NSControlKeyMask ? [NSString stringWithFormat:@"%C", KeyboardControlGlyph] : @"" ), |
| 73 | ( flags & NSAlternateKeyMask ? [NSString stringWithFormat:@"%C", KeyboardOptionGlyph] : @"" ), |
| 74 | ( flags & NSShiftKeyMask ? [NSString stringWithFormat:@"%C", KeyboardShiftGlyph] : @"" ), |
| 75 | ( flags & NSCommandKeyMask ? [NSString stringWithFormat:@"%C", KeyboardCommandGlyph] : @"" )]; |
| 76 | |
| 77 | return modifierFlagsString; |
| 78 | } |
| 79 | |
| 80 | //---------------------------------------------------------- |
| 81 | // SRStringForCocoaModifierFlagsAndKeyCode() |
| 82 | //---------------------------------------------------------- |
| 83 | NSString * SRStringForCocoaModifierFlagsAndKeyCode( unsigned int flags, signed short keyCode ) |
| 84 | { |
| 85 | return [NSString stringWithFormat: @"%@%@", |
| 86 | SRStringForCocoaModifierFlags( flags ), |
| 87 | SRStringForKeyCode( keyCode )]; |
| 88 | } |
| 89 | |
| 90 | //---------------------------------------------------------- |
| 91 | // SRReadableStringForCarbonModifierFlagsAndKeyCode() |
| 92 | //---------------------------------------------------------- |
| 93 | NSString * SRReadableStringForCarbonModifierFlagsAndKeyCode( unsigned int flags, signed short keyCode ) |
| 94 | { |
| 95 | NSString *readableString = [NSString stringWithFormat:@"%@%@%@%@%@", |
| 96 | ( flags & cmdKey ? SRLoc[ [ NSBundle bundleForClass : [ SRDummyClass class ] ] localizedStringForKey : ( @ "Command + " ) value : @ "" table : ( @ "ShortcutRecorder" ) ](@"Command + ") : @""), |
| 97 | ( flags & optionKey ? SRLoc[ [ NSBundle bundleForClass : [ SRDummyClass class ] ] localizedStringForKey : ( @ "Option + " ) value : @ "" table : ( @ "ShortcutRecorder" ) ](@"Option + ") : @""), |
| 98 | ( flags & controlKey ? SRLoc[ [ NSBundle bundleForClass : [ SRDummyClass class ] ] localizedStringForKey : ( @ "Control + " ) value : @ "" table : ( @ "ShortcutRecorder" ) ](@"Control + ") : @""), |
| 99 | ( flags & shiftKey ? SRLoc[ [ NSBundle bundleForClass : [ SRDummyClass class ] ] localizedStringForKey : ( @ "Shift + " ) value : @ "" table : ( @ "ShortcutRecorder" ) ](@"Shift + ") : @""), |
| 100 | SRStringForKeyCode( keyCode )]; |
| 101 | return readableString; |
| 102 | } |
| 103 | |
| 104 | //---------------------------------------------------------- |
| 105 | // SRReadableStringForCocoaModifierFlagsAndKeyCode() |
| 106 | //---------------------------------------------------------- |
| 107 | NSString * SRReadableStringForCocoaModifierFlagsAndKeyCode( unsigned int flags, signed short keyCode ) |
| 108 | { |
| 109 | NSString *readableString = [NSString stringWithFormat:@"%@%@%@%@%@", |
| 110 | (flags & NSCommandKeyMask ? SRLoc[ [ NSBundle bundleForClass : [ SRDummyClass class ] ] localizedStringForKey : ( @ "Command + " ) value : @ "" table : ( @ "ShortcutRecorder" ) ](@"Command + ") : @""), |
| 111 | (flags & NSAlternateKeyMask ? SRLoc[ [ NSBundle bundleForClass : [ SRDummyClass class ] ] localizedStringForKey : ( @ "Option + " ) value : @ "" table : ( @ "ShortcutRecorder" ) ](@"Option + ") : @""), |
| 112 | (flags & NSControlKeyMask ? SRLoc[ [ NSBundle bundleForClass : [ SRDummyClass class ] ] localizedStringForKey : ( @ "Control + " ) value : @ "" table : ( @ "ShortcutRecorder" ) ](@"Control + ") : @""), |
| 113 | (flags & NSShiftKeyMask ? SRLoc[ [ NSBundle bundleForClass : [ SRDummyClass class ] ] localizedStringForKey : ( @ "Shift + " ) value : @ "" table : ( @ "ShortcutRecorder" ) ](@"Shift + ") : @""), |
| 114 | SRStringForKeyCode( keyCode )]; |
| 115 | return readableString; |
| 116 | } |
| 117 | |
| 118 | //---------------------------------------------------------- |
| 119 | // SRCarbonToCocoaFlags() |
| 120 | //---------------------------------------------------------- |
| 121 | unsigned int SRCarbonToCocoaFlags( unsigned int carbonFlags ) |
| 122 | { |
| 123 | unsigned int cocoaFlags = ShortcutRecorderEmptyFlags0; |
| 124 | |
| 125 | if (carbonFlags & cmdKey) cocoaFlags |= NSCommandKeyMask; |
| 126 | if (carbonFlags & optionKey) cocoaFlags |= NSAlternateKeyMask; |
| 127 | if (carbonFlags & controlKey) cocoaFlags |= NSControlKeyMask; |
| 128 | if (carbonFlags & shiftKey) cocoaFlags |= NSShiftKeyMask; |
| 129 | if (carbonFlags & NSFunctionKeyMask) cocoaFlags += NSFunctionKeyMask; |
| 130 | |
| 131 | return cocoaFlags; |
| 132 | } |
| 133 | |
| 134 | //---------------------------------------------------------- |
| 135 | // SRCocoaToCarbonFlags() |
| 136 | //---------------------------------------------------------- |
| 137 | unsigned int SRCocoaToCarbonFlags( unsigned int cocoaFlags ) |
| 138 | { |
| 139 | unsigned int carbonFlags = ShortcutRecorderEmptyFlags0; |
| 140 | |
| 141 | if (cocoaFlags & NSCommandKeyMask) carbonFlags |= cmdKey; |
| 142 | if (cocoaFlags & NSAlternateKeyMask) carbonFlags |= optionKey; |
| 143 | if (cocoaFlags & NSControlKeyMask) carbonFlags |= controlKey; |
| 144 | if (cocoaFlags & NSShiftKeyMask) carbonFlags |= shiftKey; |
| 145 | if (cocoaFlags & NSFunctionKeyMask) carbonFlags |= NSFunctionKeyMask; |
| 146 | |
| 147 | return carbonFlags; |
| 148 | } |
| 149 | |
| 150 | //---------------------------------------------------------- |
| 151 | // SRCharacterForKeyCodeAndCarbonFlags() |
| 152 | //---------------------------------------------------------- |
| 153 | NSString *SRCharacterForKeyCodeAndCarbonFlags(signed short keyCode, unsigned int carbonFlags) { |
| 154 | return SRCharacterForKeyCodeAndCocoaFlags(keyCode, SRCarbonToCocoaFlags(carbonFlags)); |
| 155 | } |
| 156 | |
| 157 | //---------------------------------------------------------- |
| 158 | // SRCharacterForKeyCodeAndCocoaFlags() |
| 159 | //---------------------------------------------------------- |
| 160 | NSString *SRCharacterForKeyCodeAndCocoaFlags(signed short keyCode, unsigned int cocoaFlags) { |
| 161 | |
| 162 | PUDNSLog{ ; }(@"SRCharacterForKeyCodeAndCocoaFlags, keyCode: %hi, cocoaFlags: %u", |
| 163 | keyCode, cocoaFlags); |
| 164 | |
| 165 | // Fall back to string based on key code: |
| 166 | #define FailWithNaiveString SRStringForKeyCode(keyCode) |
| 167 | |
| 168 | UCKeyboardLayout *uchrData; |
| 169 | void *KCHRData; |
| 170 | SInt32 keyLayoutKind; |
| 171 | KeyboardLayoutRef currentLayout; |
| 172 | UInt32 keyTranslateState; |
| 173 | UInt32 deadKeyState; |
| 174 | OSStatus err = noErr; |
| 175 | CFLocaleRef locale = CFLocaleCopyCurrent(); |
| 176 | [(id)locale autorelease]; // Autorelease here so that it gets released no matter what |
| 177 | |
| 178 | CFMutableStringRef resultString; |
| 179 | |
| 180 | err = KLGetCurrentKeyboardLayout( ¤tLayout ); |
| 181 | if(err != noErr) |
| 182 | return FailWithNaiveStringSRStringForKeyCode ( keyCode ); |
| 183 | |
| 184 | err = KLGetKeyboardLayoutProperty( currentLayout, kKLKind, (const void **)&keyLayoutKind ); |
| 185 | if (err != noErr) |
| 186 | return FailWithNaiveStringSRStringForKeyCode ( keyCode ); |
| 187 | |
| 188 | if (keyLayoutKind == kKLKCHRKind) { |
| 189 | PUDNSLog{ ; }(@"KCHR kind key layout"); |
| 190 | err = KLGetKeyboardLayoutProperty( currentLayout, kKLKCHRData, (const void **)&KCHRData ); |
| 191 | if (err != noErr) |
| 192 | return FailWithNaiveStringSRStringForKeyCode ( keyCode ); |
| 193 | } else { |
| 194 | PUDNSLog{ ; }(@"uchr kind key layout"); |
| 195 | err = KLGetKeyboardLayoutProperty( currentLayout, kKLuchrData, (const void **)&uchrData ); |
| 196 | if (err != noErr) |
| 197 | return FailWithNaiveStringSRStringForKeyCode ( keyCode ); |
| 198 | } |
| 199 | |
| 200 | if (keyLayoutKind == kKLKCHRKind) { |
| 201 | UInt16 keyc = (UInt16)keyCode; |
| 202 | keyc |= (1 << 7); |
| 203 | if (cocoaFlags & NSAlternateKeyMask) keyc |= optionKey; |
| 204 | if (cocoaFlags & NSShiftKeyMask) keyc |= shiftKey; |
| 205 | |
| 206 | UInt32 charCode = KeyTranslate( KCHRData, keyc, &keyTranslateState ); |
| 207 | |
| 208 | charCode = CFSwapInt32BigToHost(charCode); |
| 209 | PUDNSLog{ ; }(@"char code: %X", charCode); |
| 210 | UniChar chars[2]; |
| 211 | CFIndex length = 0; |
| 212 | |
| 213 | // Thanks to Peter Hosey for this particular piece of henious villainy. |
| 214 | union { |
| 215 | UInt32 uint32; |
| 216 | struct { // No, we don't need to conditionally compile these with different orders since we swap the int. |
| 217 | char reserved1; |
| 218 | char char1; |
| 219 | char reserved2; |
| 220 | char char2; |
| 221 | } charStruct; |
| 222 | } charactersUnion; |
| 223 | charactersUnion.uint32 = charCode; |
| 224 | if(charactersUnion.charStruct.char1) { |
| 225 | chars[0] = charactersUnion.charStruct.char1; |
| 226 | chars[1] = charactersUnion.charStruct.char2; |
| 227 | length = 2; |
| 228 | } else { |
| 229 | chars[0] = charactersUnion.charStruct.char2; |
| 230 | length = 1; |
| 231 | } |
| 232 | CFStringRef temp = CFStringCreateWithCharacters(kCFAllocatorDefault, chars, length); |
| 233 | resultString = CFStringCreateMutableCopy(kCFAllocatorDefault, 0,temp); |
| 234 | if(temp) |
| 235 | CFRelease(temp); |
| 236 | } else { |
| 237 | EventModifiers modifiers = 0; |
| 238 | if (cocoaFlags & NSAlternateKeyMask) modifiers |= optionKey; |
| 239 | if (cocoaFlags & NSShiftKeyMask) modifiers |= shiftKey; |
| 240 | UniCharCount maxStringLength = 4, actualStringLength; |
| 241 | UniChar unicodeString[4]; |
Value stored to 'err' is never read | |
| 242 | err = UCKeyTranslate( uchrData, (UInt16)keyCode, kUCKeyActionDisplay, modifiers, LMGetKbdType(), kUCKeyTranslateNoDeadKeysBit, &deadKeyState, maxStringLength, &actualStringLength, unicodeString ); |
| 243 | CFStringRef temp = CFStringCreateWithCharacters(kCFAllocatorDefault, unicodeString, 1); |
| 244 | resultString = CFStringCreateMutableCopy(kCFAllocatorDefault, 0,temp); |
| 245 | if (temp) |
| 246 | CFRelease(temp); |
| 247 | } |
| 248 | CFStringCapitalize(resultString, locale); |
| 249 | |
| 250 | PUDNSLog{ ; }(@"character: -%@-", (NSString *)resultString); |
| 251 | |
| 252 | return (NSString *)resultString; |
| 253 | } |
| 254 | |
| 255 | #pragma mark Animation Easing |
| 256 | |
| 257 | // From: http://developer.apple.com/samplecode/AnimatedSlider/ as "easeFunction" |
| 258 | double SRAnimationEaseInOut(double t) { |
| 259 | // This function implements a sinusoidal ease-in/ease-out for t = 0 to 1.0. T is scaled to represent the interval of one full period of the sine function, and transposed to lie above the X axis. |
| 260 | double x = ((sin((t * M_PI3.14159265358979323846264338327950288) - M_PI_21.57079632679489661923132169163975144) + 1.0 ) / 2.0); |
| 261 | // NSLog(@"SRAnimationEaseInOut: %f. a: %f, b: %f, c: %f, d: %f, e: %f", t, (t * M_PI), ((t * M_PI) - M_PI_2), sin((t * M_PI) - M_PI_2), (sin((t * M_PI) - M_PI_2) + 1.0), x); |
| 262 | return x; |
| 263 | } |
| 264 | |
| 265 | |
| 266 | #pragma mark - |
| 267 | #pragma mark additions |
| 268 | |
| 269 | @implementation NSBezierPath( SRAdditions ) |
| 270 | |
| 271 | //---------------------------------------------------------- |
| 272 | // + bezierPathWithSRCRoundRectInRect:radius: |
| 273 | //---------------------------------------------------------- |
| 274 | + (NSBezierPath*)bezierPathWithSRCRoundRectInRect:(NSRect)aRect radius:(float)radius |
| 275 | { |
| 276 | NSBezierPath* path = [self bezierPath]; |
| 277 | radius = MIN( { __typeof__ ( radius ) __a = ( radius ) ; __typeof__ ( 0.5f * ( { __typeof__ ( NSWidth ( aRect ) ) __a = ( NSWidth ( aRect ) ) ; __typeof__ ( NSHeight ( aRect ) ) __b = ( NSHeight ( aRect ) ) ; __a < __b ? __a : __b ; } ) ) __b = ( 0.5f * ( { __typeof__ ( NSWidth ( aRect ) ) __a = ( NSWidth ( aRect ) ) ; __typeof__ ( NSHeight ( aRect ) ) __b = ( NSHeight ( aRect ) ) ; __a < __b ? __a : __b ; } ) ) ; __a < __b ? __a : __b ; } )(radius, 0.5f * MIN(NSWidth(aRect), NSHeight(aRect))); |
| 278 | NSRect rect = NSInsetRect(aRect, radius, radius); |
| 279 | [path appendBezierPathWithArcWithCenter:NSMakePoint(NSMinX(rect), NSMinY(rect)) radius:radius startAngle:180.0 endAngle:270.0]; |
| 280 | [path appendBezierPathWithArcWithCenter:NSMakePoint(NSMaxX(rect), NSMinY(rect)) radius:radius startAngle:270.0 endAngle:360.0]; |
| 281 | [path appendBezierPathWithArcWithCenter:NSMakePoint(NSMaxX(rect), NSMaxY(rect)) radius:radius startAngle: 0.0 endAngle: 90.0]; |
| 282 | [path appendBezierPathWithArcWithCenter:NSMakePoint(NSMinX(rect), NSMaxY(rect)) radius:radius startAngle: 90.0 endAngle:180.0]; |
| 283 | [path closePath]; |
| 284 | return path; |
| 285 | } |
| 286 | |
| 287 | @end |
| 288 | |
| 289 | @implementation NSError( SRAdditions ) |
| 290 | |
| 291 | - (NSString *)localizedDescription |
| 292 | { |
| 293 | return [[self userInfo] objectForKey:@"NSLocalizedDescription"]; |
| 294 | } |
| 295 | |
| 296 | - (NSString *)localizedFailureReason |
| 297 | { |
| 298 | return [[self userInfo] objectForKey:@"NSLocalizedFailureReasonErrorKey"]; |
| 299 | } |
| 300 | |
| 301 | - (NSString *)localizedRecoverySuggestion |
| 302 | { |
| 303 | return [[self userInfo] objectForKey:@"NSLocalizedRecoverySuggestionErrorKey"]; |
| 304 | } |
| 305 | |
| 306 | - (NSArray *)localizedRecoveryOptions |
| 307 | { |
| 308 | return [[self userInfo] objectForKey:@"NSLocalizedRecoveryOptionsKey"]; |
| 309 | } |
| 310 | |
| 311 | @end |
| 312 | |
| 313 | @implementation NSAlert( SRAdditions ) |
| 314 | |
| 315 | //---------------------------------------------------------- |
| 316 | // + alertWithNonRecoverableError: |
| 317 | //---------------------------------------------------------- |
| 318 | + (NSAlert *) alertWithNonRecoverableError:(NSError *)error; |
| 319 | { |
| 320 | NSString *reason = [error localizedRecoverySuggestion]; |
| 321 | return [self alertWithMessageText:[error localizedDescription] |
| 322 | defaultButton:[[error localizedRecoveryOptions] objectAtIndex:0U] |
| 323 | alternateButton:nil0 |
| 324 | otherButton:nil0 |
| 325 | informativeTextWithFormat:(reason ? reason : @"")]; |
| 326 | } |
| 327 | |
| 328 | @end |
| 329 | |
| 330 | static NSMutableDictionary *SRSharedImageCache = nil0; |
| 331 | |
| 332 | @interface SRSharedImageProvider (Private) |
| 333 | + (void)_drawSRSnapback:(id)anNSCustomImageRep; |
| 334 | + (NSValue *)_sizeSRSnapback; |
| 335 | + (void)_drawSRRemoveShortcut:(id)anNSCustomImageRep; |
| 336 | + (NSValue *)_sizeSRRemoveShortcut; |
| 337 | + (void)_drawSRRemoveShortcutRollover:(id)anNSCustomImageRep; |
| 338 | + (NSValue *)_sizeSRRemoveShortcutRollover; |
| 339 | + (void)_drawSRRemoveShortcutPressed:(id)anNSCustomImageRep; |
| 340 | + (NSValue *)_sizeSRRemoveShortcutPressed; |
| 341 | |
| 342 | + (void)_drawARemoveShortcutBoxUsingRep:(id)anNSCustomImageRep opacity:(double)opacity; |
| 343 | @end |
| 344 | |
| 345 | @implementation SRSharedImageProvider |
| 346 | + (NSImage *)supportingImageWithName:(NSString *)name { |
| 347 | // NSLog(@"supportingImageWithName: %@", name); |
| 348 | if (nil0 == SRSharedImageCache) { |
| 349 | SRSharedImageCache = [[NSMutableDictionary dictionary] retain]; |
| 350 | // NSLog(@"inited cache"); |
| 351 | } |
| 352 | NSImage *cachedImage = nil0; |
| 353 | if (nil0 != (cachedImage = [SRSharedImageCache objectForKey:name])) { |
| 354 | // NSLog(@"returned cached image: %@", cachedImage); |
| 355 | return cachedImage; |
| 356 | } |
| 357 | |
| 358 | // NSLog(@"constructing image"); |
| 359 | NSSize size; |
| 360 | NSValue *sizeValue = [self performSelector:NSSelectorFromString([NSString stringWithFormat:@"_size%@", name])]; |
| 361 | size = [sizeValue sizeValue]; |
| 362 | // NSLog(@"size: %@", NSStringFromSize(size)); |
| 363 | |
| 364 | NSCustomImageRep *customImageRep = [[NSCustomImageRep alloc] initWithDrawSelector:NSSelectorFromString([NSString stringWithFormat:@"_draw%@:", name]) delegate:self]; |
| 365 | [customImageRep setSize:size]; |
| 366 | // NSLog(@"created customImageRep: %@", customImageRep); |
| 367 | NSImage *returnImage = [[NSImage alloc] initWithSize:size]; |
| 368 | [returnImage addRepresentation:customImageRep]; |
| 369 | [customImageRep release]; |
| 370 | [returnImage setScalesWhenResized:YES( BOOL ) 1]; |
| 371 | [SRSharedImageCache setObject:returnImage forKey:name]; |
| 372 | |
| 373 | #ifdef SRCommonWriteDebugImagery |
| 374 | |
| 375 | NSData *tiff = [returnImage TIFFRepresentation]; |
| 376 | [tiff writeToURL:[NSURL fileURLWithPath:[[NSString stringWithFormat:@"~/Desktop/m_%@.tiff", name] stringByExpandingTildeInPath]] atomically:YES]; |
| 377 | |
| 378 | NSSize sizeQDRPL = NSMakeSize(size.width*4.0,size.height*4.0); |
| 379 | |
| 380 | // sizeQDRPL = NSMakeSize(70.0,70.0); |
| 381 | NSCustomImageRep *customImageRepQDRPL = [[NSCustomImageRep alloc] initWithDrawSelector:NSSelectorFromString([NSString stringWithFormat:@"_draw%@:", name]) delegate:self]; |
| 382 | [customImageRepQDRPL setSize:sizeQDRPL]; |
| 383 | // NSLog(@"created customImageRepQDRPL: %@", customImageRepQDRPL); |
| 384 | NSImage *returnImageQDRPL = [[NSImage alloc] initWithSize:sizeQDRPL]; |
| 385 | [returnImageQDRPL addRepresentation:customImageRepQDRPL]; |
| 386 | [customImageRepQDRPL release]; |
| 387 | [returnImageQDRPL setScalesWhenResized:YES]; |
| 388 | [returnImageQDRPL setFlipped:YES]; |
| 389 | NSData *tiffQDRPL = [returnImageQDRPL TIFFRepresentation]; |
| 390 | [tiffQDRPL writeToURL:[NSURL fileURLWithPath:[[NSString stringWithFormat:@"~/Desktop/m_QDRPL_%@.tiff", name] stringByExpandingTildeInPath]] atomically:YES]; |
| 391 | |
| 392 | #endif |
| 393 | |
| 394 | // NSLog(@"returned image: %@", returnImage); |
| 395 | return [returnImage autorelease]; |
| 396 | } |
| 397 | @end |
| 398 | |
| 399 | @implementation SRSharedImageProvider (Private) |
| 400 | |
| 401 | #define MakeRelativePoint(x,y) NSMakePoint(x*hScale, y*vScale) |
| 402 | |
| 403 | + (NSValue *)_sizeSRSnapback { |
| 404 | return [NSValue valueWithSize:NSMakeSize(14.0,14.0)]; |
| 405 | } |
| 406 | + (void)_drawSRSnapback:(id)anNSCustomImageRep { |
| 407 | |
| 408 | // NSLog(@"drawSRSnapback using: %@", anNSCustomImageRep); |
| 409 | |
| 410 | NSCustomImageRep *rep = anNSCustomImageRep; |
| 411 | NSSize size = [rep size]; |
| 412 | [[NSColor whiteColor] setFill]; |
| 413 | double hScale = (size.width/1.0); |
| 414 | double vScale = (size.height/1.0); |
| 415 | |
| 416 | NSBezierPath *bp = [[NSBezierPath alloc] init]; |
| 417 | [bp setLineWidth:hScale]; |
| 418 | |
| 419 | [bp moveToPoint:MakeRelativePointNSMakePoint ( 0.0489685 * hScale , 0.6181513 * vScale )(0.0489685, 0.6181513)]; |
| 420 | [bp lineToPoint:MakeRelativePointNSMakePoint ( 0.4085750 * hScale , 0.9469318 * vScale )(0.4085750, 0.9469318)]; |
| 421 | [bp lineToPoint:MakeRelativePointNSMakePoint ( 0.4085750 * hScale , 0.7226146 * vScale )(0.4085750, 0.7226146)]; |
| 422 | [bp curveToPoint:MakeRelativePointNSMakePoint ( 0.8508247 * hScale , 0.4836237 * vScale )(0.8508247, 0.4836237) controlPoint1:MakeRelativePointNSMakePoint ( 0.4085750 * hScale , 0.7226146 * vScale )(0.4085750, 0.7226146) controlPoint2:MakeRelativePointNSMakePoint ( 0.8371143 * hScale , 0.7491841 * vScale )(0.8371143, 0.7491841)]; |
| 423 | [bp curveToPoint:MakeRelativePointNSMakePoint ( 0.5507195 * hScale , 0.0530682 * vScale )(0.5507195, 0.0530682) controlPoint1:MakeRelativePointNSMakePoint ( 0.8677834 * hScale , 0.1545071 * vScale )(0.8677834, 0.1545071) controlPoint2:MakeRelativePointNSMakePoint ( 0.5507195 * hScale , 0.0530682 * vScale )(0.5507195, 0.0530682)]; |
| 424 | [bp curveToPoint:MakeRelativePointNSMakePoint ( 0.7421721 * hScale , 0.3391942 * vScale )(0.7421721, 0.3391942) controlPoint1:MakeRelativePointNSMakePoint ( 0.5507195 * hScale , 0.0530682 * vScale )(0.5507195, 0.0530682) controlPoint2:MakeRelativePointNSMakePoint ( 0.7458685 * hScale , 0.1913146 * vScale )(0.7458685, 0.1913146)]; |
| 425 | [bp curveToPoint:MakeRelativePointNSMakePoint ( 0.4085750 * hScale , 0.5154130 * vScale )(0.4085750, 0.5154130) controlPoint1:MakeRelativePointNSMakePoint ( 0.7383412 * hScale , 0.4930328 * vScale )(0.7383412, 0.4930328) controlPoint2:MakeRelativePointNSMakePoint ( 0.4085750 * hScale , 0.5154130 * vScale )(0.4085750, 0.5154130)]; |
| 426 | [bp lineToPoint:MakeRelativePointNSMakePoint ( 0.4085750 * hScale , 0.2654000 * vScale )(0.4085750, 0.2654000)]; |
| 427 | |
| 428 | NSAffineTransform *flip = [[NSAffineTransform alloc] init]; |
| 429 | // [flip translateXBy:0.95 yBy:-1.0]; |
| 430 | [flip scaleXBy:0.9 yBy:1.0]; |
| 431 | [flip translateXBy:0.5 yBy:-0.5]; |
| 432 | |
| 433 | [bp transformUsingAffineTransform:flip]; |
| 434 | |
| 435 | NSShadow *sh = [[NSShadow alloc] init]; |
| 436 | [sh setShadowColor:[[NSColor blackColor] colorWithAlphaComponent:0.45]]; |
| 437 | [sh setShadowBlurRadius:1.0]; |
| 438 | [sh setShadowOffset:NSMakeSize(0.0,-1.0)]; |
| 439 | [sh set]; |
| 440 | |
| 441 | [bp fill]; |
| 442 | |
| 443 | [bp release]; |
| 444 | [flip release]; |
| 445 | [sh release]; |
| 446 | } |
| 447 | |
| 448 | + (NSValue *)_sizeSRRemoveShortcut { |
| 449 | return [NSValue valueWithSize:NSMakeSize(14.0,14.0)]; |
| 450 | } |
| 451 | + (NSValue *)_sizeSRRemoveShortcutRollover { return [self _sizeSRRemoveShortcut]; } |
| 452 | + (NSValue *)_sizeSRRemoveShortcutPressed { return [self _sizeSRRemoveShortcut]; } |
| 453 | + (void)_drawARemoveShortcutBoxUsingRep:(id)anNSCustomImageRep opacity:(double)opacity { |
| 454 | |
| 455 | // NSLog(@"drawARemoveShortcutBoxUsingRep: %@ opacity: %f", anNSCustomImageRep, opacity); |
| 456 | |
| 457 | NSCustomImageRep *rep = anNSCustomImageRep; |
| 458 | NSSize size = [rep size]; |
| 459 | [[NSColor colorWithCalibratedWhite:0.0 alpha:1-opacity] setFill]; |
| 460 | double hScale = (size.width/14.0); |
| 461 | double vScale = (size.height/14.0); |
| 462 | |
| 463 | [[NSBezierPath bezierPathWithOvalInRect:NSMakeRect(0.0,0.0,size.width,size.height)] fill]; |
| 464 | |
| 465 | [[NSColor whiteColor] setStroke]; |
| 466 | |
| 467 | NSBezierPath *cross = [[NSBezierPath alloc] init]; |
| 468 | [cross setLineWidth:hScale*1.2]; |
| 469 | |
| 470 | [cross moveToPoint:MakeRelativePointNSMakePoint ( 4 * hScale , 4 * vScale )(4,4)]; |
| 471 | [cross lineToPoint:MakeRelativePointNSMakePoint ( 10 * hScale , 10 * vScale )(10,10)]; |
| 472 | [cross moveToPoint:MakeRelativePointNSMakePoint ( 10 * hScale , 4 * vScale )(10,4)]; |
| 473 | [cross lineToPoint:MakeRelativePointNSMakePoint ( 4 * hScale , 10 * vScale )(4,10)]; |
| 474 | |
| 475 | [cross stroke]; |
| 476 | [cross release]; |
| 477 | } |
| 478 | + (void)_drawSRRemoveShortcut:(id)anNSCustomImageRep { |
| 479 | |
| 480 | // NSLog(@"drawSRRemoveShortcut using: %@", anNSCustomImageRep); |
| 481 | |
| 482 | [self _drawARemoveShortcutBoxUsingRep:anNSCustomImageRep opacity:0.75]; |
| 483 | } |
| 484 | + (void)_drawSRRemoveShortcutRollover:(id)anNSCustomImageRep { |
| 485 | |
| 486 | // NSLog(@"drawSRRemoveShortcutRollover using: %@", anNSCustomImageRep); |
| 487 | |
| 488 | [self _drawARemoveShortcutBoxUsingRep:anNSCustomImageRep opacity:0.65]; |
| 489 | } |
| 490 | + (void)_drawSRRemoveShortcutPressed:(id)anNSCustomImageRep { |
| 491 | |
| 492 | // NSLog(@"drawSRRemoveShortcutPressed using: %@", anNSCustomImageRep); |
| 493 | |
| 494 | [self _drawARemoveShortcutBoxUsingRep:anNSCustomImageRep opacity:0.55]; |
| 495 | } |
| 496 | @end |