/*
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 "DriveByTouchViewController.h"


@implementation DriveByTouchViewController

- (void) setupOnLoad {
	[swipePad addSubview: wheelOutline=[[UIImageView alloc] initWithImage: [UIImage imageNamed:@"SteeringWheelOutline.png"]]];
	[swipePad addSubview: wheel=[[UIImageView alloc] initWithImage: [UIImage imageNamed:@"SteeringWheel.png"]]];
	
	tiltXSink = [processor channelByName: @"aileron"];
	if (!tiltXSink)
		tiltXSink = [processor channelByName: @"steering"];
	tiltYSink = [processor channelByName: @"elevator"];
	swipeXSink = [processor channelByName: @"rudder"];
	swipeYSink = [processor channelByName: @"throttle"];
	
	[[self view] addSubview:[[[TrimmerView alloc] initWithSwipePad:swipePad andChannel: tiltXSink  inQuadrant:Q_TOP] autorelease]];
	//[[self view] addSubview:[[[TrimmerView alloc] initWithSwipePad:swipePad andChannel: tiltYSink  inQuadrant:Q_RIGHT] autorelease]];
	//[[self view] addSubview:[[[TrimmerView alloc] initWithSwipePad:swipePad andChannel: swipeXSink inQuadrant:Q_BOTTOM] autorelease]v];
	[[self view] addSubview:[[[TrimmerView alloc] initWithSwipePad:swipePad andChannel: swipeYSink inQuadrant:Q_LEFT] autorelease]];

	swipeYSpring = 0.1;
		
	[self doDisplayThing];
}

- (void) doDisplayThing {
	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";
}

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