5 // Created by Sean Patrick O'Brien on 9/23/06.
6 // Copyright 2006 Sean Patrick O'Brien. All rights reserved.
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];
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]];
25 NSSize size = [checkImage size];
27 float y = NSMaxY(frame) - (frame.size.height-size.height)/2.0;
28 float x = frame.origin.x+addX;
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];
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]];
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;
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;
59 [rightImage compositeToPoint:NSMakePoint(x, y) operation:NSCompositeSourceOver];
61 [fillImage setScalesWhenResized:YES];
62 [fillImage setSize:NSMakeSize(fillWidth, [fillImage size].height)];
63 [fillImage compositeToPoint:NSMakePoint(fillX, y) operation:NSCompositeSourceOver];
65 [self drawInteriorWithFrame:cellFrame inView:controlView];