Synchronize access to transfer queues.
[MacTF.git] / iLifeControls / NFIButtonCell.m
blob0f86b91f63a16dc82078fb260947dc1ff1dda6d1
1 //
2 //  NFIButtonCell.m
3 //  iLife Button
4 //
5 //  Created by Sean Patrick O'Brien on 9/23/06.
6 //  Copyright 2006 Sean Patrick O'Brien. All rights reserved.
7 //
9 #import "NFIButtonCell.h"
10 #import "NSImage+FrameworkImage.h"
12 @implementation NFIButtonCell
14 - (void)drawImage:(NSImage*)image withFrame:(NSRect)frame inView:(NSView*)controlView
16         if([self showsStateBy] == NSNoCellMask){
17                 [super drawImage:image withFrame:frame inView:controlView];
18                 return;
19         }
20         
21         NSString *state = [self isEnabled] ? ([self isHighlighted] ? @"P" : @"N") : @"D";
22         NSString *position = [self intValue] ? @"On" : @"Off";
23         NSImage *checkImage = [NSImage frameworkImageNamed:[NSString stringWithFormat:@"Checkbox%@%@.tiff", position, state]];
24         
25         NSSize size = [checkImage size];
26         float addX = 2;
27         float y = NSMaxY(frame) - (frame.size.height-size.height)/2.0;
28         float x = frame.origin.x+addX;
29         
30         [checkImage compositeToPoint:NSMakePoint(x, y) operation:NSCompositeSourceOver];
33 - (void)drawInteriorWithFrame:(NSRect)cellFrame inView:(NSView *)controlView
35         if([self showsStateBy] != NSNoCellMask){
36                 [super drawInteriorWithFrame:cellFrame inView:controlView];
37                 return;
38         }
40         NSString *state = [self isEnabled] ? ([self isHighlighted] ? @"P" : @"N") : @"D";
41         NSImage *leftImage = [NSImage frameworkImageNamed:[NSString stringWithFormat:@"ButtonLeft%@.tiff", state]];
42         NSImage *fillImage = [NSImage frameworkImageNamed:[NSString stringWithFormat:@"ButtonFill%@", state]];
43         NSImage *rightImage = [NSImage frameworkImageNamed:[NSString stringWithFormat:@"ButtonRight%@", state]];
44                                 
45         NSSize size = [leftImage size];
46         float addX = size.width / 2.0;
47         float y = NSMaxY(cellFrame) - (cellFrame.size.height-size.height)/2.0;
48         float x = cellFrame.origin.x+addX;
49         float fillX = x + size.width;
50         float fillWidth = cellFrame.size.width - size.width - addX;
51         
52         [leftImage compositeToPoint:NSMakePoint(x, y) operation:NSCompositeSourceOver];
54         size = [rightImage size];
55         addX = size.width / 2.0;
56         x = NSMaxX(cellFrame) - size.width - addX;
57         fillWidth -= size.width+addX;
58         
59         [rightImage compositeToPoint:NSMakePoint(x, y) operation:NSCompositeSourceOver];
60         
61         [fillImage setScalesWhenResized:YES];
62         [fillImage setSize:NSMakeSize(fillWidth, [fillImage size].height)];
63         [fillImage compositeToPoint:NSMakePoint(fillX, y) operation:NSCompositeSourceOver];
66 - (void)drawImageWithFrame:(NSRect)frame inView:(NSButton *)view
68         NSImage *image;
69         if ([self isHighlighted] && [self alternateImage])
70                 image = [self alternateImage];
71         else
72                 image = [self image];
74         [super drawImage:image withFrame:NSOffsetRect(frame, 0, ([view isFlipped] ? -1 : 1)) inView:view];
77 - (void)drawWithFrame:(NSRect)frame inView:(NSButton *)view
79         [self drawInteriorWithFrame:frame inView:view];
80         
81         if([self showsStateBy] != NSNoCellMask){
82                 return;
83         }
84         
85         [NSGraphicsContext saveGraphicsState]; 
86         NSShadow* theShadow = [[NSShadow alloc] init]; 
87         [theShadow setShadowOffset:NSMakeSize(0, -1)]; 
88         [theShadow setShadowBlurRadius:0.9]; 
90         [theShadow setShadowColor:[[NSColor whiteColor]
91              colorWithAlphaComponent:1.0]]; 
92         
93         [theShadow set];
94         
95         if ([self image] && [self imagePosition] != NSNoImage)
96                 [self drawImageWithFrame:frame inView:view];
97         else
98                 [self drawTitle:[view attributedTitle] withFrame:frame inView:view];
99         
100         [NSGraphicsContext restoreGraphicsState];
101         [theShadow release];
104 @end