RSS

(root)/iphone/common : 60 : tappity/source/TappityView.m

To get this branch, use:
bzr branch /browse/iphone/common

« back to all changes in this revision

Viewing changes to tappity/source/TappityView.m

Dömötör Gulyás
2010-01-18 09:02:59
Revision ID: dognotdog@gmail.com-20100118080259-1633mzyepdhdacy0
made tappity a nested tree

Show diffs side-by-side

added added

removed removed

1
 
//
2
 
//  TappityView.m
3
 
//  tappity
4
 
//
5
 
//  Created by döme on 25.10.2009.
6
 
//
7
 
 
8
 
/*
9
 
 * Copyright (c) 2009 Doemoetoer Gulyas.
10
 
 * All rights reserved.
11
 
 *
12
 
 * Redistribution and use in source and binary forms, with or without
13
 
 * modification, are permitted provided that the following conditions
14
 
 * are met:
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.
22
 
 *
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.
33
 
 */
34
 
 
35
 
#import "TappityView.h"
36
 
#import "TappityClient.h"
37
 
#import "Tappity.h"
38
 
#import "ES2Shader.h"
39
 
#import "VertexArray.h"
40
 
 
41
 
 
42
 
@implementation TappityView
43
 
 
44
 
 
45
 
- (id)initWithFrame:(CGRect)frame
46
 
{
47
 
    if ((self = [super initWithFrame: frame]))
48
 
        {
49
 
 
50
 
    }
51
 
    return self;
52
 
}
53
 
 
54
 
- (void) setupGraphicsForApi: (EAGLRenderingAPI) glApi
55
 
{
56
 
 
57
 
        secondaryContext = [[EAGLContext alloc] initWithAPI: glApi sharegroup: [context sharegroup]];
58
 
 
59
 
        glClearColor(0.0f,0.0f,0.0f,1.0f);
60
 
 
61
 
        if ([[EAGLContext currentContext] API] == kEAGLRenderingAPIOpenGLES2)
62
 
        {
63
 
                imgShader = [[[ESShader shader] initWithVertexShaderFile: @"simple.vs" fragmentShaderFile: @"simple.fs"] retain];
64
 
        }
65
 
        else
66
 
        {
67
 
                imgShader = [[[ESShader shader] init] retain];
68
 
        }
69
 
 
70
 
        
71
 
}
72
 
 
73
 
- (void) setImage: (UIImage*) img
74
 
{
75
 
        [EAGLContext setCurrentContext: secondaryContext];
76
 
        
77
 
        GLuint tex = 0;
78
 
        [self textureFromCgImage: [img CGImage] texName: &tex width: 320 height: 480 repeat: NO mipmap: NO filter: NO];
79
 
        
80
 
        glFlush();
81
 
 
82
 
        @synchronized(self)
83
 
        {
84
 
                [img retain];
85
 
                [image release];
86
 
                image = img;
87
 
                
88
 
                if (imageTex)
89
 
                        glDeleteTextures(1, &imageTex);
90
 
                imageTex = tex;
91
 
        }
92
 
 
93
 
        glFlush();
94
 
 
95
 
        [self performSelectorOnMainThread: @selector(drawView) withObject: nil waitUntilDone: NO];
96
 
        //[self setNeedsDisplay];
97
 
}
98
 
 
99
 
- (void) drawView
100
 
{
101
 
        m16 I = midentity();
102
 
                
103
 
        [self setupViewDrawing];
104
 
        
105
 
        glDisable(GL_CULL_FACE);
106
 
        glEnable(GL_TEXTURE_2D);
107
 
        glDisable(GL_DEPTH_TEST);
108
 
        glDisable(GL_BLEND);
109
 
        glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
110
 
        
111
 
        glBindTexture(GL_TEXTURE_2D, imageTex);
112
 
        
113
 
        [imgShader bindShader];
114
 
        
115
 
        [imgShader setColorRed: 1.0f green: 1.0f blue: 1.0f alpha: 1.0f];
116
 
        
117
 
        [imgShader setTextureMatrix: &I];
118
 
        [imgShader setProjectionMatrix: &I];
119
 
        [imgShader setModelviewMatrix: &I];
120
 
        
121
 
        [[VertexArray sharedQuad] draw];
122
 
        
123
 
        
124
 
        [self finishViewDrawing];
125
 
}
126
 
 
127
 
 
128
 
/*
129
 
- (void) doDrawingInContext: (void*) _c
130
 
{
131
 
        CGContextRef c = (CGContextRef)_c;
132
 
        //[[UIColor blueColor] set];
133
 
        //CGContextFillRect(c, rect);
134
 
 
135
 
        CGContextSetInterpolationQuality(c, kCGInterpolationNone);
136
 
        CGContextSetAllowsAntialiasing(c, NO);
137
 
        CGContextSetShouldAntialias(c, NO);
138
 
 
139
 
        UIImage* img = nil;
140
 
        
141
 
        @synchronized(self)
142
 
        {
143
 
                img = image;
144
 
        }
145
 
 
146
 
        if (!img)
147
 
                img = [UIImage imageNamed: @"image-not-found-icon.png"];
148
 
        
149
 
        CGRect bounds = [self bounds];
150
 
 
151
 
 
152
 
 
153
 
        [img drawInRect: bounds blendMode: kCGBlendModeCopy alpha: 1.0f];
154
 
}
155
 
 
156
 
- (void) drawRect: (CGRect) rect
157
 
{
158
 
        CGContextRef c = UIGraphicsGetCurrentContext();
159
 
        
160
 
        [self doDrawingInContext: c];
161
 
}
162
 
*/
163
 
 
164
 
- (void)dealloc
165
 
{
166
 
        self.tapClient = nil;
167
 
    [super dealloc];
168
 
}
169
 
 
170
 
- (NSArray*) touchesAsPlist: (NSSet*) touches
171
 
{
172
 
        NSMutableArray* ary = [NSMutableArray array];
173
 
        for (UITouch* touch in touches)
174
 
        {
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"];
183
 
                
184
 
                [ary addObject: dict];
185
 
        }
186
 
        return ary;
187
 
}
188
 
/*
189
 
- (void) touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
190
 
{
191
 
        NSLog(@"touchesBegan");
192
 
        _printGSEvent(event);
193
 
 
194
 
        [tapClient sendTouch: event inPhase: UITouchPhaseBegan];
195
 
}
196
 
 
197
 
- (void) touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
198
 
{
199
 
        NSLog(@"touchesEnded");
200
 
        _printGSEvent(event);
201
 
 
202
 
        [tapClient sendTouch: event inPhase: UITouchPhaseEnded];
203
 
}
204
 
 
205
 
- (void) touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event
206
 
{
207
 
        NSLog(@"touchesMoved");
208
 
        _printGSEvent(event);
209
 
 
210
 
        [tapClient sendTouch: event inPhase: UITouchPhaseMoved];
211
 
}
212
 
 
213
 
- (void) touchesCancelled:(NSSet *)touches withEvent:(UIEvent *)event
214
 
{
215
 
        NSLog(@"touchesCancelled");
216
 
        _printGSEvent(event);
217
 
 
218
 
        [tapClient sendTouch: event inPhase: UITouchPhaseCancelled];
219
 
}
220
 
*/
221
 
 
222
 
@synthesize tapClient, image;
223
 
 
224
 
@end

Loggerhead 1.17 is a web-based interface for Bazaar branches