/* Copyright (c) 2011 Artjom Popov */

#import "UTScannerIndicatorView.h"


@implementation UTScannerIndicatorView

@dynamic state;

- (UTScannerIndicatorViewState)state
{
	return self->m_state;
}

- (void)setState:(UTScannerIndicatorViewState)state
{
	//NSLog(@"State: %d", self->m_state);
	
	if (self->m_state != state) {
		self->m_state = state;
		[self setNeedsDisplay];
	}
}

#pragma mark UIView

- (void)drawRect:(CGRect)rect;
{   
    CGContextRef context = UIGraphicsGetCurrentContext(); 
    //CGContextSetRGBStrokeColor(context, 1.0F, 0.0F, 0.0F, 1.0F);
	
	
	switch (self->m_state) {
		default:
		case UTScannerIndicatorViewStateNoMatch:
			CGContextSetRGBStrokeColor(context, 1.0F, 0.0F, 0.0F, 1.0F);
			break;
			
		case UTScannerIndicatorViewStatePartialMatch:
			CGContextSetRGBStrokeColor(context, 1.0F, 0.0F, 1.0F, 1.0F);
			break;
			
		case UTScannerIndicatorViewStateFullMatch:
			CGContextSetRGBStrokeColor(context, 1.0F, 1.0F, 0.0F, 1.0F);
			break;
	}
	
    CGContextBeginPath(context);
	
    CGContextMoveToPoint(context, 0.0, 0.0);
    CGContextAddLineToPoint(context, self.bounds.size.width, 0.0);
    CGContextAddLineToPoint(context, self.bounds.size.width, self.bounds.size.height);
    CGContextAddLineToPoint(context, 0.0F, self.bounds.size.height);
	
    CGContextClosePath(context);
    CGContextSetLineWidth(context, 5.0F);
    CGContextStrokePath(context);
}

@end
