/*
iPhly: Radio Control on the iPhone

Copyright (C) 2010-2011 Ari Krupnik & Associates

This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License V2
as published by the Free Software Foundation.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
*/

#import "TiltAndSwipePadCar.h"

@implementation TiltAndSwipePadCar

- (id)initWithFrame:(CGRect)frame andProcessor:(ModelProcessor*) p {
    self = [super initWithFrame:frame andProcessor:p];
    if (self) {
        [self addSubview: wheelOutline=[[UIImageView alloc] initWithImage: [UIImage imageNamed:@"SteeringWheelOutline.png"]]];
        [self addSubview: wheel=[[UIImageView alloc] initWithImage: [UIImage imageNamed:@"SteeringWheel.png"]]];

        tiltXSink = [[processor channelByName: @"steering"] retain];
        swipeYSink = [[processor channelByName: @"throttle"] retain];
        
        swipeYSpring = 0.1;
		
        [self setNeedsDisplay];
    }
    return self;
}

- (void) drawRect:(CGRect)rect {
	CGAffineTransform rotation = CGAffineTransformMakeRotation(M_PI_2*[tiltXSink value]);
	CGAffineTransform translation = CGAffineTransformMakeTranslation(0, -wheel.bounds.size.width/3*[swipeYSink value]);
	wheel.transform = CGAffineTransformConcat(rotation, translation);
}

- (NSString *) gerund {
	return @"Driving";
}

- (TrimmerView*) trimmerForQuadrant:(enum quadrant) q {
    if (q==Q_RIGHT || q==Q_BOTTOM) {
        return  nil;
    } else {
        return [super trimmerForQuadrant:q];
    }
}

- (void) dealloc {
    [tiltXSink release];
    [swipeYSink release];
    
	[wheelOutline release];
	[wheel release];
	
	[super dealloc];
}
@end
