5
// Created by döme on 25.10.2009.
9
* Copyright (c) 2009 Doemoetoer Gulyas.
10
* All rights reserved.
12
* Redistribution and use in source and binary forms, with or without
13
* modification, are permitted provided that the following conditions
15
* 1. Redistributions of source code must retain the above copyright
16
* notice, this list of conditions and the following disclaimer.
17
* 2. Redistributions in binary form must reproduce the above copyright
18
* notice, this list of conditions and the following disclaimer in the
19
* documentation and/or other materials provided with the distribution.
20
* 3. The name of the author may not be used to endorse or promote products
21
* derived from this software without specific prior written permission.
23
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
24
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
25
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
26
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
27
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
28
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
29
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
30
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
31
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
32
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
35
#import "TappityView.h"
36
#import "TappityClient.h"
39
#import "VertexArray.h"
42
@implementation TappityView
45
- (id)initWithFrame:(CGRect)frame
47
if ((self = [super initWithFrame: frame]))
54
- (void) setupGraphicsForApi: (EAGLRenderingAPI) glApi
57
secondaryContext = [[EAGLContext alloc] initWithAPI: glApi sharegroup: [context sharegroup]];
59
glClearColor(0.0f,0.0f,0.0f,1.0f);
61
if ([[EAGLContext currentContext] API] == kEAGLRenderingAPIOpenGLES2)
63
imgShader = [[[ESShader shader] initWithVertexShaderFile: @"simple.vs" fragmentShaderFile: @"simple.fs"] retain];
67
imgShader = [[[ESShader shader] init] retain];
73
- (void) setImage: (UIImage*) img
75
[EAGLContext setCurrentContext: secondaryContext];
78
[self textureFromCgImage: [img CGImage] texName: &tex width: 320 height: 480 repeat: NO mipmap: NO filter: NO];
89
glDeleteTextures(1, &imageTex);
95
[self performSelectorOnMainThread: @selector(drawView) withObject: nil waitUntilDone: NO];
96
//[self setNeedsDisplay];
103
[self setupViewDrawing];
105
glDisable(GL_CULL_FACE);
106
glEnable(GL_TEXTURE_2D);
107
glDisable(GL_DEPTH_TEST);
109
glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
111
glBindTexture(GL_TEXTURE_2D, imageTex);
113
[imgShader bindShader];
115
[imgShader setColorRed: 1.0f green: 1.0f blue: 1.0f alpha: 1.0f];
117
[imgShader setTextureMatrix: &I];
118
[imgShader setProjectionMatrix: &I];
119
[imgShader setModelviewMatrix: &I];
121
[[VertexArray sharedQuad] draw];
124
[self finishViewDrawing];
129
- (void) doDrawingInContext: (void*) _c
131
CGContextRef c = (CGContextRef)_c;
132
//[[UIColor blueColor] set];
133
//CGContextFillRect(c, rect);
135
CGContextSetInterpolationQuality(c, kCGInterpolationNone);
136
CGContextSetAllowsAntialiasing(c, NO);
137
CGContextSetShouldAntialias(c, NO);
147
img = [UIImage imageNamed: @"image-not-found-icon.png"];
149
CGRect bounds = [self bounds];
153
[img drawInRect: bounds blendMode: kCGBlendModeCopy alpha: 1.0f];
156
- (void) drawRect: (CGRect) rect
158
CGContextRef c = UIGraphicsGetCurrentContext();
160
[self doDrawingInContext: c];
166
self.tapClient = nil;
170
- (NSArray*) touchesAsPlist: (NSSet*) touches
172
NSMutableArray* ary = [NSMutableArray array];
173
for (UITouch* touch in touches)
175
NSMutableDictionary* dict = [NSMutableDictionary dictionary];
176
[dict setObject: [NSNumber numberWithInteger: (NSInteger)touch] forKey: @"touchIdentifier"];
177
[dict setObject: [NSNumber numberWithInteger: [touch phase]] forKey: @"touchPhase"];
178
[dict setObject: [NSNumber numberWithInteger: [touch tapCount]] forKey: @"touchTapCount"];
179
[dict setObject: [NSNumber numberWithFloat: [touch locationInView: self].x] forKey: @"touchX"];
180
[dict setObject: [NSNumber numberWithFloat: [touch locationInView: self].x] forKey: @"touchY"];
181
[dict setObject: [NSNumber numberWithFloat: [touch previousLocationInView: self].x] forKey: @"touchPX"];
182
[dict setObject: [NSNumber numberWithFloat: [touch previousLocationInView: self].x] forKey: @"touchPY"];
184
[ary addObject: dict];
189
- (void) touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
191
NSLog(@"touchesBegan");
192
_printGSEvent(event);
194
[tapClient sendTouch: event inPhase: UITouchPhaseBegan];
197
- (void) touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
199
NSLog(@"touchesEnded");
200
_printGSEvent(event);
202
[tapClient sendTouch: event inPhase: UITouchPhaseEnded];
205
- (void) touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event
207
NSLog(@"touchesMoved");
208
_printGSEvent(event);
210
[tapClient sendTouch: event inPhase: UITouchPhaseMoved];
213
- (void) touchesCancelled:(NSSet *)touches withEvent:(UIEvent *)event
215
NSLog(@"touchesCancelled");
216
_printGSEvent(event);
218
[tapClient sendTouch: event inPhase: UITouchPhaseCancelled];
222
@synthesize tapClient, image;