//  Created by Joe Becker on 3/7/05.
//  Copyright 2005 __MyCompanyName__. All rights reserved.

#import "Label.h"

@implementation Label

- initRect:(NSRect)aBounds text:(NSString *)aText
                           size:(double)aSize
{
    [super init];

	const float sloppyCoding = -1.; //FIXME: AppKit(???) has an "off by one" bug, leaves turds...

	bounds = NSInsetRect(aBounds, sloppyCoding, sloppyCoding);

    font  = [NSFont fontWithName:@"Times-Roman" size:aSize];
    dict  = [[[NSMutableDictionary alloc] init] autorelease];
    [dict setObject:font forKey:NSFontAttributeName];

    text  = [[[NSMutableAttributedString alloc] initWithString:aText attributes:dict] autorelease];
    [self  setColor:[NSColor grayColor]]; //FIXME
    return self;
}

- (void)dealloc
{
    [dict release];
    [text release];
    [super dealloc];
}

- (int)tag              { return tag;}
- (void)setTag:(int)aTag{ tag=aTag;}
- (NSRect)bounds		{ return bounds;}
- (NSPoint)center		{ return center;}

- (void)setColor:(NSColor *)aColor
{
    [dict setObject:aColor forKey:NSForegroundColorAttributeName];
    [text setAttributes:dict range:NSMakeRange(0,[text length])];

    // Now reapply the alignment because of a Cocoa bug
    [text setAlignment:NSCenterTextAlignment
          range:NSMakeRange(0,[text length])];
}

- (NSColor *)color
{
    return color;
}

// This one works, but it requires a subview
- (void)stroke
{
	return;	//FIXME: premature exitulation
	
	
    NSView *fv = [NSView focusView];
    NSView *tempView;

    tempView = [ [NSView alloc] initWithFrame:bounds]; // gets removed in a few lines

    [fv addSubview:tempView];

    // Scale the tempView to screen coordinates
    [tempView setBounds:
              [tempView convertRect:[self bounds] toView:nil] ];

    [tempView lockFocus];
    [color set];
    [text drawInRect:[tempView bounds] ];
    [tempView unlockFocus];
    [tempView removeFromSuperviewWithoutNeedingDisplay];
}

@end