istereo

diff src/EAGLView.m @ 35:23e5d274b2a2

added options panel, also added the xib files to the repository as they're needed
author John Tsiombikas <nuclear@member.fsf.org>
date Fri, 09 Sep 2011 10:03:42 +0300
parents 8dd271942543
children ff055bff6a15
line diff
     1.1 --- a/src/EAGLView.m	Fri Sep 09 00:31:54 2011 +0300
     1.2 +++ b/src/EAGLView.m	Fri Sep 09 10:03:42 2011 +0300
     1.3 @@ -1,15 +1,10 @@
     1.4 -//
     1.5 -//  EAGLView.m
     1.6 -//  istereo
     1.7 -//
     1.8 -//  Created by nuclear on 9/6/11.
     1.9 -//  Copyright __MyCompanyName__ 2011. All rights reserved.
    1.10 -//
    1.11 +#import "EAGLView.h"
    1.12 +#import "ES2Renderer.h"
    1.13 +#import "ui.h"
    1.14  
    1.15 -#import "EAGLView.h"
    1.16  
    1.17 -#import "ES1Renderer.h"
    1.18 -#import "ES2Renderer.h"
    1.19 +static UI *optgui;
    1.20 +
    1.21  
    1.22  @implementation EAGLView
    1.23  
    1.24 @@ -19,129 +14,127 @@
    1.25  // You must implement this method
    1.26  + (Class)layerClass
    1.27  {
    1.28 -    return [CAEAGLLayer class];
    1.29 +	return [CAEAGLLayer class];
    1.30  }
    1.31  
    1.32  //The EAGL view is stored in the nib file. When it's unarchived it's sent -initWithCoder:
    1.33  - (id)initWithCoder:(NSCoder*)coder
    1.34  {
    1.35 -    if ((self = [super initWithCoder:coder]))
    1.36 -    {
    1.37 -        // Get the layer
    1.38 -        CAEAGLLayer *eaglLayer = (CAEAGLLayer *)self.layer;
    1.39 +	if ((self = [super initWithCoder:coder]))
    1.40 +	{
    1.41 +		// Get the layer
    1.42 +		CAEAGLLayer *eaglLayer = (CAEAGLLayer *)self.layer;
    1.43  
    1.44  		//self.contentScaleFactor = 2.0;
    1.45  
    1.46 -        eaglLayer.opaque = TRUE;
    1.47 -        eaglLayer.drawableProperties = [NSDictionary dictionaryWithObjectsAndKeys:
    1.48 -                                        [NSNumber numberWithBool:FALSE], kEAGLDrawablePropertyRetainedBacking, kEAGLColorFormatRGBA8, kEAGLDrawablePropertyColorFormat, nil];
    1.49 +		eaglLayer.opaque = TRUE;
    1.50 +		eaglLayer.drawableProperties = [NSDictionary dictionaryWithObjectsAndKeys:
    1.51 +										[NSNumber numberWithBool:FALSE], kEAGLDrawablePropertyRetainedBacking, kEAGLColorFormatRGBA8, kEAGLDrawablePropertyColorFormat, nil];
    1.52  
    1.53 -        renderer = [[ES2Renderer alloc] init];
    1.54 +		renderer = [[ES2Renderer alloc] init];
    1.55 +		if (!renderer) {
    1.56 +			[self release];
    1.57 +			return nil;
    1.58 +		}
    1.59  
    1.60 -        if (!renderer)
    1.61 -        {
    1.62 -            renderer = [[ES1Renderer alloc] init];
    1.63 +		animating = FALSE;
    1.64 +		displayLinkSupported = FALSE;
    1.65 +		animationFrameInterval = 1;
    1.66 +		displayLink = nil;
    1.67 +		animationTimer = nil;
    1.68  
    1.69 -            if (!renderer)
    1.70 -            {
    1.71 -                [self release];
    1.72 -                return nil;
    1.73 -            }
    1.74 -        }
    1.75 -
    1.76 -        animating = FALSE;
    1.77 -        displayLinkSupported = FALSE;
    1.78 -        animationFrameInterval = 1;
    1.79 -        displayLink = nil;
    1.80 -        animationTimer = nil;
    1.81 -
    1.82 -        // A system version of 3.1 or greater is required to use CADisplayLink. The NSTimer
    1.83 -        // class is used as fallback when it isn't available.
    1.84 -        NSString *reqSysVer = @"3.1";
    1.85 -        NSString *currSysVer = [[UIDevice currentDevice] systemVersion];
    1.86 -        if ([currSysVer compare:reqSysVer options:NSNumericSearch] != NSOrderedAscending)
    1.87 -            displayLinkSupported = TRUE;
    1.88 +		// A system version of 3.1 or greater is required to use CADisplayLink. The NSTimer
    1.89 +		// class is used as fallback when it isn't available.
    1.90 +		NSString *reqSysVer = @"3.1";
    1.91 +		NSString *currSysVer = [[UIDevice currentDevice] systemVersion];
    1.92 +		if ([currSysVer compare:reqSysVer options:NSNumericSearch] != NSOrderedAscending)
    1.93 +			displayLinkSupported = TRUE;
    1.94  
    1.95  		self.multipleTouchEnabled = 1;
    1.96 -    }
    1.97  
    1.98 -    return self;
    1.99 +		// load the options gui
   1.100 +		optgui = [[UI alloc] initWithNibName:@"ui" bundle: [NSBundle mainBundle]];
   1.101 +		hide_options();
   1.102 +		[self addSubview: optgui.view];
   1.103 +	}
   1.104 +
   1.105 +	return self;
   1.106  }
   1.107  
   1.108  - (void)drawView:(id)sender
   1.109  {
   1.110 -    [renderer render];
   1.111 +	[renderer render];
   1.112  }
   1.113  
   1.114  - (void)layoutSubviews
   1.115  {
   1.116 -    [renderer resizeFromLayer:(CAEAGLLayer*)self.layer];
   1.117 -    [self drawView:nil];
   1.118 +	[renderer resizeFromLayer:(CAEAGLLayer*)self.layer];
   1.119 +	[self drawView:nil];
   1.120  }
   1.121  
   1.122  - (NSInteger)animationFrameInterval
   1.123  {
   1.124 -    return animationFrameInterval;
   1.125 +	return animationFrameInterval;
   1.126  }
   1.127  
   1.128  - (void)setAnimationFrameInterval:(NSInteger)frameInterval
   1.129  {
   1.130 -    // Frame interval defines how many display frames must pass between each time the
   1.131 -    // display link fires. The display link will only fire 30 times a second when the
   1.132 -    // frame internal is two on a display that refreshes 60 times a second. The default
   1.133 -    // frame interval setting of one will fire 60 times a second when the display refreshes
   1.134 -    // at 60 times a second. A frame interval setting of less than one results in undefined
   1.135 -    // behavior.
   1.136 -    if (frameInterval >= 1)
   1.137 -    {
   1.138 -        animationFrameInterval = frameInterval;
   1.139 +	// Frame interval defines how many display frames must pass between each time the
   1.140 +	// display link fires. The display link will only fire 30 times a second when the
   1.141 +	// frame internal is two on a display that refreshes 60 times a second. The default
   1.142 +	// frame interval setting of one will fire 60 times a second when the display refreshes
   1.143 +	// at 60 times a second. A frame interval setting of less than one results in undefined
   1.144 +	// behavior.
   1.145 +	if (frameInterval >= 1)
   1.146 +	{
   1.147 +		animationFrameInterval = frameInterval;
   1.148  
   1.149 -        if (animating)
   1.150 -        {
   1.151 -            [self stopAnimation];
   1.152 -            [self startAnimation];
   1.153 -        }
   1.154 -    }
   1.155 +		if (animating)
   1.156 +		{
   1.157 +			[self stopAnimation];
   1.158 +			[self startAnimation];
   1.159 +		}
   1.160 +	}
   1.161  }
   1.162  
   1.163  - (void)startAnimation
   1.164  {
   1.165 -    if (!animating)
   1.166 -    {
   1.167 -        if (displayLinkSupported)
   1.168 -        {
   1.169 -            // CADisplayLink is API new to iPhone SDK 3.1. Compiling against earlier versions will result in a warning, but can be dismissed
   1.170 -            // if the system version runtime check for CADisplayLink exists in -initWithCoder:. The runtime check ensures this code will
   1.171 -            // not be called in system versions earlier than 3.1.
   1.172 +	if (!animating)
   1.173 +	{
   1.174 +		if (displayLinkSupported)
   1.175 +		{
   1.176 +			// CADisplayLink is API new to iPhone SDK 3.1. Compiling against earlier versions will result in a warning, but can be dismissed
   1.177 +			// if the system version runtime check for CADisplayLink exists in -initWithCoder:. The runtime check ensures this code will
   1.178 +			// not be called in system versions earlier than 3.1.
   1.179  
   1.180 -            displayLink = [NSClassFromString(@"CADisplayLink") displayLinkWithTarget:self selector:@selector(drawView:)];
   1.181 -            [displayLink setFrameInterval:animationFrameInterval];
   1.182 -            [displayLink addToRunLoop:[NSRunLoop currentRunLoop] forMode:NSDefaultRunLoopMode];
   1.183 -        }
   1.184 -        else
   1.185 -            animationTimer = [NSTimer scheduledTimerWithTimeInterval:(NSTimeInterval)((1.0 / 60.0) * animationFrameInterval) target:self selector:@selector(drawView:) userInfo:nil repeats:TRUE];
   1.186 +			displayLink = [NSClassFromString(@"CADisplayLink") displayLinkWithTarget:self selector:@selector(drawView:)];
   1.187 +			[displayLink setFrameInterval:animationFrameInterval];
   1.188 +			[displayLink addToRunLoop:[NSRunLoop currentRunLoop] forMode:NSDefaultRunLoopMode];
   1.189 +		}
   1.190 +		else
   1.191 +			animationTimer = [NSTimer scheduledTimerWithTimeInterval:(NSTimeInterval)((1.0 / 60.0) * animationFrameInterval) target:self selector:@selector(drawView:) userInfo:nil repeats:TRUE];
   1.192  
   1.193 -        animating = TRUE;
   1.194 -    }
   1.195 +		animating = TRUE;
   1.196 +	}
   1.197  }
   1.198  
   1.199  - (void)stopAnimation
   1.200  {
   1.201 -    if (animating)
   1.202 -    {
   1.203 -        if (displayLinkSupported)
   1.204 -        {
   1.205 -            [displayLink invalidate];
   1.206 -            displayLink = nil;
   1.207 -        }
   1.208 -        else
   1.209 -        {
   1.210 -            [animationTimer invalidate];
   1.211 -            animationTimer = nil;
   1.212 -        }
   1.213 +	if (animating)
   1.214 +	{
   1.215 +		if (displayLinkSupported)
   1.216 +		{
   1.217 +			[displayLink invalidate];
   1.218 +			displayLink = nil;
   1.219 +		}
   1.220 +		else
   1.221 +		{
   1.222 +			[animationTimer invalidate];
   1.223 +			animationTimer = nil;
   1.224 +		}
   1.225  
   1.226 -        animating = FALSE;
   1.227 -    }
   1.228 +		animating = FALSE;
   1.229 +	}
   1.230  }
   1.231  
   1.232  static int touch_active;
   1.233 @@ -165,15 +158,27 @@
   1.234  	int dy = end_touch.y - start_touch.y;
   1.235  
   1.236  	if(dx * dx + dy * dy < 30) {
   1.237 -		use_bump = !use_bump;
   1.238 +		show_options();
   1.239  	}
   1.240  }
   1.241  
   1.242  - (void)dealloc
   1.243  {
   1.244 -    [renderer release];
   1.245 +	[renderer release];
   1.246  
   1.247 -    [super dealloc];
   1.248 +	[super dealloc];
   1.249  }
   1.250  
   1.251  @end
   1.252 +
   1.253 +void show_options(void)
   1.254 +{
   1.255 +	assert(optgui);
   1.256 +	optgui.view.hidden = NO;
   1.257 +}
   1.258 +
   1.259 +void hide_options(void)
   1.260 +{
   1.261 +	assert(optgui);
   1.262 +	optgui.view.hidden = YES;
   1.263 +}