1//
2//  PXTeensyHexView.m
3//  Pixen-XCode
4//
5//  Created by Ian Henderson on 16.10.04.
6//  Copyright 2004 Open Sword Group. All rights reserved.
7//
8
9#import "PXTeensyHexView.h"
10
11
12@implementation PXTeensyHexView
13
14
15- (void)setColor:aColor
16{
17	color = [[aColor colorUsingColorSpaceName:NSCalibratedRGBColorSpace] copy];
18	[self setNeedsDisplay:YES];
19}
20
21- (void)dealloc
22{
23	[color release];
24	[super dealloc];
25}
26
27- (id)initWithFrame:(NSRect)frame {
28    self = [super initWithFrame:frame];
29    if (self) {
30        color = [self setColor:[NSColor whiteColor]];
31    }
32    return self;
33}
34
35- (void)drawRect:(NSRect)rect {
36	if (color == nil) {
37		return;
38	}
39
40	NSString *string = [NSString stringWithFormat:@"#%02x%02x%02x", (int)([color redComponent] * 255), (int)([color greenComponent] * 255), (int)([color blueComponent] * 255)];
41	NSAttributedString *attributedString = [[[NSAttributedString alloc] initWithString:string attributes:[NSDictionary dictionaryWithObjectsAndKeys:
42		[NSFont fontWithName:@"Courier" size:8], NSFontAttributeName,
43		[NSNumber numberWithFloat:-1.0], NSKernAttributeName,
44		nil]] autorelease];
45	NSRect drawRect = NSMakeRect(0, 0, [self frame].size.width, [self frame].size.height);
46	NSSize stringSize = [attributedString size];
47	drawRect.origin.x += (drawRect.size.width - stringSize.width) / 2;
48
49	[attributedString drawAtPoint:drawRect.origin];
50}
51
52@end
53