istereo

annotate src/EAGLView.m @ 43:73813c1176de

better hgignore
author John Tsiombikas <nuclear@member.fsf.org>
date Fri, 14 Aug 2015 04:33:42 +0300
parents 23e5d274b2a2
children
rev   line source
nuclear@39 1 /*
nuclear@39 2 Stereoscopic tunnel for iOS.
nuclear@39 3 Copyright (C) 2011 John Tsiombikas <nuclear@member.fsf.org>
nuclear@39 4
nuclear@39 5 This program is free software: you can redistribute it and/or modify
nuclear@39 6 it under the terms of the GNU General Public License as published by
nuclear@39 7 the Free Software Foundation, either version 3 of the License, or
nuclear@39 8 (at your option) any later version.
nuclear@39 9
nuclear@39 10 This program is distributed in the hope that it will be useful,
nuclear@39 11 but WITHOUT ANY WARRANTY; without even the implied warranty of
nuclear@39 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
nuclear@39 13 GNU General Public License for more details.
nuclear@39 14
nuclear@39 15 You should have received a copy of the GNU General Public License
nuclear@39 16 along with this program. If not, see <http://www.gnu.org/licenses/>.
nuclear@39 17 */
nuclear@39 18
nuclear@39 19 /* XXX this file is mostly generated from Xcode and therefore sucks ass */
nuclear@39 20
nuclear@35 21 #import "EAGLView.h"
nuclear@35 22 #import "ES2Renderer.h"
nuclear@35 23 #import "ui.h"
nuclear@0 24
nuclear@0 25
nuclear@35 26 static UI *optgui;
nuclear@35 27
nuclear@0 28
nuclear@0 29 @implementation EAGLView
nuclear@0 30
nuclear@0 31 @synthesize animating;
nuclear@0 32 @dynamic animationFrameInterval;
nuclear@0 33
nuclear@0 34 // You must implement this method
nuclear@0 35 + (Class)layerClass
nuclear@0 36 {
nuclear@35 37 return [CAEAGLLayer class];
nuclear@0 38 }
nuclear@0 39
nuclear@0 40 //The EAGL view is stored in the nib file. When it's unarchived it's sent -initWithCoder:
nuclear@0 41 - (id)initWithCoder:(NSCoder*)coder
nuclear@30 42 {
nuclear@35 43 if ((self = [super initWithCoder:coder]))
nuclear@35 44 {
nuclear@35 45 // Get the layer
nuclear@35 46 CAEAGLLayer *eaglLayer = (CAEAGLLayer *)self.layer;
nuclear@0 47
nuclear@30 48 //self.contentScaleFactor = 2.0;
nuclear@30 49
nuclear@35 50 eaglLayer.opaque = TRUE;
nuclear@35 51 eaglLayer.drawableProperties = [NSDictionary dictionaryWithObjectsAndKeys:
nuclear@35 52 [NSNumber numberWithBool:FALSE], kEAGLDrawablePropertyRetainedBacking, kEAGLColorFormatRGBA8, kEAGLDrawablePropertyColorFormat, nil];
nuclear@0 53
nuclear@35 54 renderer = [[ES2Renderer alloc] init];
nuclear@35 55 if (!renderer) {
nuclear@35 56 [self release];
nuclear@35 57 return nil;
nuclear@35 58 }
nuclear@0 59
nuclear@35 60 animating = FALSE;
nuclear@35 61 displayLinkSupported = FALSE;
nuclear@35 62 animationFrameInterval = 1;
nuclear@35 63 displayLink = nil;
nuclear@35 64 animationTimer = nil;
nuclear@0 65
nuclear@35 66 // A system version of 3.1 or greater is required to use CADisplayLink. The NSTimer
nuclear@35 67 // class is used as fallback when it isn't available.
nuclear@35 68 NSString *reqSysVer = @"3.1";
nuclear@35 69 NSString *currSysVer = [[UIDevice currentDevice] systemVersion];
nuclear@35 70 if ([currSysVer compare:reqSysVer options:NSNumericSearch] != NSOrderedAscending)
nuclear@35 71 displayLinkSupported = TRUE;
nuclear@30 72
nuclear@30 73 self.multipleTouchEnabled = 1;
nuclear@0 74
nuclear@35 75 // load the options gui
nuclear@35 76 optgui = [[UI alloc] initWithNibName:@"ui" bundle: [NSBundle mainBundle]];
nuclear@35 77 hide_options();
nuclear@35 78 [self addSubview: optgui.view];
nuclear@35 79 }
nuclear@35 80
nuclear@35 81 return self;
nuclear@0 82 }
nuclear@0 83
nuclear@0 84 - (void)drawView:(id)sender
nuclear@0 85 {
nuclear@35 86 [renderer render];
nuclear@0 87 }
nuclear@0 88
nuclear@0 89 - (void)layoutSubviews
nuclear@0 90 {
nuclear@35 91 [renderer resizeFromLayer:(CAEAGLLayer*)self.layer];
nuclear@35 92 [self drawView:nil];
nuclear@0 93 }
nuclear@0 94
nuclear@0 95 - (NSInteger)animationFrameInterval
nuclear@0 96 {
nuclear@35 97 return animationFrameInterval;
nuclear@0 98 }
nuclear@0 99
nuclear@0 100 - (void)setAnimationFrameInterval:(NSInteger)frameInterval
nuclear@0 101 {
nuclear@35 102 // Frame interval defines how many display frames must pass between each time the
nuclear@35 103 // display link fires. The display link will only fire 30 times a second when the
nuclear@35 104 // frame internal is two on a display that refreshes 60 times a second. The default
nuclear@35 105 // frame interval setting of one will fire 60 times a second when the display refreshes
nuclear@35 106 // at 60 times a second. A frame interval setting of less than one results in undefined
nuclear@35 107 // behavior.
nuclear@35 108 if (frameInterval >= 1)
nuclear@35 109 {
nuclear@35 110 animationFrameInterval = frameInterval;
nuclear@0 111
nuclear@35 112 if (animating)
nuclear@35 113 {
nuclear@35 114 [self stopAnimation];
nuclear@35 115 [self startAnimation];
nuclear@35 116 }
nuclear@35 117 }
nuclear@0 118 }
nuclear@0 119
nuclear@0 120 - (void)startAnimation
nuclear@0 121 {
nuclear@35 122 if (!animating)
nuclear@35 123 {
nuclear@35 124 if (displayLinkSupported)
nuclear@35 125 {
nuclear@35 126 // CADisplayLink is API new to iPhone SDK 3.1. Compiling against earlier versions will result in a warning, but can be dismissed
nuclear@35 127 // if the system version runtime check for CADisplayLink exists in -initWithCoder:. The runtime check ensures this code will
nuclear@35 128 // not be called in system versions earlier than 3.1.
nuclear@0 129
nuclear@35 130 displayLink = [NSClassFromString(@"CADisplayLink") displayLinkWithTarget:self selector:@selector(drawView:)];
nuclear@35 131 [displayLink setFrameInterval:animationFrameInterval];
nuclear@35 132 [displayLink addToRunLoop:[NSRunLoop currentRunLoop] forMode:NSDefaultRunLoopMode];
nuclear@35 133 }
nuclear@35 134 else
nuclear@35 135 animationTimer = [NSTimer scheduledTimerWithTimeInterval:(NSTimeInterval)((1.0 / 60.0) * animationFrameInterval) target:self selector:@selector(drawView:) userInfo:nil repeats:TRUE];
nuclear@0 136
nuclear@35 137 animating = TRUE;
nuclear@35 138 }
nuclear@0 139 }
nuclear@0 140
nuclear@0 141 - (void)stopAnimation
nuclear@0 142 {
nuclear@35 143 if (animating)
nuclear@35 144 {
nuclear@35 145 if (displayLinkSupported)
nuclear@35 146 {
nuclear@35 147 [displayLink invalidate];
nuclear@35 148 displayLink = nil;
nuclear@35 149 }
nuclear@35 150 else
nuclear@35 151 {
nuclear@35 152 [animationTimer invalidate];
nuclear@35 153 animationTimer = nil;
nuclear@35 154 }
nuclear@0 155
nuclear@35 156 animating = FALSE;
nuclear@35 157 }
nuclear@0 158 }
nuclear@0 159
nuclear@30 160 static int touch_active;
nuclear@30 161 static CGPoint start_touch;
nuclear@30 162 extern int use_bump;
nuclear@30 163
nuclear@30 164 - (void) touchesBegan: (NSSet*) touches withEvent: (UIEvent*) event
nuclear@30 165 {
nuclear@30 166 UITouch *touch = [[touches allObjects] objectAtIndex: 0];
nuclear@30 167
nuclear@30 168 start_touch = [touch locationInView: self];
nuclear@30 169 touch_active = 1;
nuclear@30 170 }
nuclear@30 171
nuclear@30 172 - (void) touchesEnded: (NSSet*) touches withEvent: (UIEvent*) event
nuclear@30 173 {
nuclear@30 174 UITouch *touch = [[touches allObjects] objectAtIndex: 0];
nuclear@30 175
nuclear@30 176 CGPoint end_touch = [touch locationInView: self];
nuclear@30 177 int dx = end_touch.x - start_touch.x;
nuclear@30 178 int dy = end_touch.y - start_touch.y;
nuclear@30 179
nuclear@30 180 if(dx * dx + dy * dy < 30) {
nuclear@35 181 show_options();
nuclear@30 182 }
nuclear@30 183 }
nuclear@30 184
nuclear@0 185 - (void)dealloc
nuclear@0 186 {
nuclear@35 187 [renderer release];
nuclear@0 188
nuclear@35 189 [super dealloc];
nuclear@0 190 }
nuclear@0 191
nuclear@0 192 @end
nuclear@35 193
nuclear@35 194 void show_options(void)
nuclear@35 195 {
nuclear@35 196 assert(optgui);
nuclear@35 197 optgui.view.hidden = NO;
nuclear@35 198 }
nuclear@35 199
nuclear@35 200 void hide_options(void)
nuclear@35 201 {
nuclear@35 202 assert(optgui);
nuclear@35 203 optgui.view.hidden = YES;
nuclear@35 204 }