Synchronize access to transfer queues.
[MacTF.git] / iLifeControls / NFHUDButtonCell.m
blobcc0c6458ce62867c50467fa284e2425d3b42dbed
1 //
2 //  NFHUDButtonCell.m
3 //  iLife HUD 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 "NFHUDButtonCell.h"
10 #import "NSImage+FrameworkImage.h"
12 @implementation NFHUDButtonCell
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 isHighlighted] ? @"P" : @"N";
22         NSString *position = [self intValue] ? @"On" : @"Off";
23         NSImage *checkImage = [NSImage frameworkImageNamed:[NSString stringWithFormat:@"HUDCheckbox%@%@.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)drawWithFrame:(NSRect)cellFrame inView:(NSView *)controlView
35         if([self showsStateBy] != NSNoCellMask){
36                 [super drawWithFrame:cellFrame inView:controlView];
37                 return;
38         }
40         NSString *state = [self isHighlighted] ? @"P" : @"N";
41         NSImage *leftImage = [NSImage frameworkImageNamed:[NSString stringWithFormat:@"HUDButtonLeft%@.tiff", state]];
42         NSImage *fillImage = [NSImage frameworkImageNamed:[NSString stringWithFormat:@"HUDButtonFill%@", state]];
43         NSImage *rightImage = [NSImage frameworkImageNamed:[NSString stringWithFormat:@"HUDButtonRight%@", 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 - 1;
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];
64         
65         [self drawInteriorWithFrame:cellFrame inView:controlView];
68 @end