cocoaTouch/SDL_uikitview.m
author koda
Thu, 07 Jan 2010 22:49:25 +0000
changeset 2683 bad2a30d5d6c
parent 2682 d4c395f25db2
child 2685 0ba746be5d59
permissions -rw-r--r--
touch input: reset zoom, attack button
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2678
334016e8d895 injection of custom code in SDL for iPhone in order to implement our frontend
koda
parents:
diff changeset
     1
/*
334016e8d895 injection of custom code in SDL for iPhone in order to implement our frontend
koda
parents:
diff changeset
     2
 SDL - Simple DirectMedia Layer
334016e8d895 injection of custom code in SDL for iPhone in order to implement our frontend
koda
parents:
diff changeset
     3
 Copyright (C) 1997-2009 Sam Lantinga
334016e8d895 injection of custom code in SDL for iPhone in order to implement our frontend
koda
parents:
diff changeset
     4
 
334016e8d895 injection of custom code in SDL for iPhone in order to implement our frontend
koda
parents:
diff changeset
     5
 This library is free software; you can redistribute it and/or
334016e8d895 injection of custom code in SDL for iPhone in order to implement our frontend
koda
parents:
diff changeset
     6
 modify it under the terms of the GNU Lesser General Public
334016e8d895 injection of custom code in SDL for iPhone in order to implement our frontend
koda
parents:
diff changeset
     7
 License as published by the Free Software Foundation; either
334016e8d895 injection of custom code in SDL for iPhone in order to implement our frontend
koda
parents:
diff changeset
     8
 version 2.1 of the License, or (at your option) any later version.
334016e8d895 injection of custom code in SDL for iPhone in order to implement our frontend
koda
parents:
diff changeset
     9
 
334016e8d895 injection of custom code in SDL for iPhone in order to implement our frontend
koda
parents:
diff changeset
    10
 This library is distributed in the hope that it will be useful,
334016e8d895 injection of custom code in SDL for iPhone in order to implement our frontend
koda
parents:
diff changeset
    11
 but WITHOUT ANY WARRANTY; without even the implied warranty of
334016e8d895 injection of custom code in SDL for iPhone in order to implement our frontend
koda
parents:
diff changeset
    12
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
334016e8d895 injection of custom code in SDL for iPhone in order to implement our frontend
koda
parents:
diff changeset
    13
 Lesser General Public License for more details.
334016e8d895 injection of custom code in SDL for iPhone in order to implement our frontend
koda
parents:
diff changeset
    14
 
334016e8d895 injection of custom code in SDL for iPhone in order to implement our frontend
koda
parents:
diff changeset
    15
 You should have received a copy of the GNU Lesser General Public
334016e8d895 injection of custom code in SDL for iPhone in order to implement our frontend
koda
parents:
diff changeset
    16
 License along with this library; if not, write to the Free Software
334016e8d895 injection of custom code in SDL for iPhone in order to implement our frontend
koda
parents:
diff changeset
    17
 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
334016e8d895 injection of custom code in SDL for iPhone in order to implement our frontend
koda
parents:
diff changeset
    18
 
334016e8d895 injection of custom code in SDL for iPhone in order to implement our frontend
koda
parents:
diff changeset
    19
 Sam Lantinga, mods for Hedgewars by Vittorio Giovara
334016e8d895 injection of custom code in SDL for iPhone in order to implement our frontend
koda
parents:
diff changeset
    20
 slouken@libsdl.org, vittorio.giovara@gmail.com
334016e8d895 injection of custom code in SDL for iPhone in order to implement our frontend
koda
parents:
diff changeset
    21
 */
334016e8d895 injection of custom code in SDL for iPhone in order to implement our frontend
koda
parents:
diff changeset
    22
334016e8d895 injection of custom code in SDL for iPhone in order to implement our frontend
koda
parents:
diff changeset
    23
#include "PascalImports.h"
334016e8d895 injection of custom code in SDL for iPhone in order to implement our frontend
koda
parents:
diff changeset
    24
#import "SDL_uikitview.h"
2682
d4c395f25db2 additional modifications for touch input
koda
parents: 2678
diff changeset
    25
#import "SDL_uikitappdelegate.h"
2678
334016e8d895 injection of custom code in SDL for iPhone in order to implement our frontend
koda
parents:
diff changeset
    26
334016e8d895 injection of custom code in SDL for iPhone in order to implement our frontend
koda
parents:
diff changeset
    27
#if SDL_IPHONE_KEYBOARD
334016e8d895 injection of custom code in SDL for iPhone in order to implement our frontend
koda
parents:
diff changeset
    28
#import "SDL_keyboard_c.h"
334016e8d895 injection of custom code in SDL for iPhone in order to implement our frontend
koda
parents:
diff changeset
    29
#import "keyinfotable.h"
334016e8d895 injection of custom code in SDL for iPhone in order to implement our frontend
koda
parents:
diff changeset
    30
#import "SDL_uikitwindow.h"
334016e8d895 injection of custom code in SDL for iPhone in order to implement our frontend
koda
parents:
diff changeset
    31
#endif
334016e8d895 injection of custom code in SDL for iPhone in order to implement our frontend
koda
parents:
diff changeset
    32
334016e8d895 injection of custom code in SDL for iPhone in order to implement our frontend
koda
parents:
diff changeset
    33
@implementation SDL_uikitview
334016e8d895 injection of custom code in SDL for iPhone in order to implement our frontend
koda
parents:
diff changeset
    34
2682
d4c395f25db2 additional modifications for touch input
koda
parents: 2678
diff changeset
    35
@synthesize initialDistance, gestureStartPoint;
2678
334016e8d895 injection of custom code in SDL for iPhone in order to implement our frontend
koda
parents:
diff changeset
    36
334016e8d895 injection of custom code in SDL for iPhone in order to implement our frontend
koda
parents:
diff changeset
    37
- (void)dealloc {
334016e8d895 injection of custom code in SDL for iPhone in order to implement our frontend
koda
parents:
diff changeset
    38
#if SDL_IPHONE_KEYBOARD
334016e8d895 injection of custom code in SDL for iPhone in order to implement our frontend
koda
parents:
diff changeset
    39
	SDL_DelKeyboard(0);
334016e8d895 injection of custom code in SDL for iPhone in order to implement our frontend
koda
parents:
diff changeset
    40
	[textField release];
334016e8d895 injection of custom code in SDL for iPhone in order to implement our frontend
koda
parents:
diff changeset
    41
#endif
334016e8d895 injection of custom code in SDL for iPhone in order to implement our frontend
koda
parents:
diff changeset
    42
	[super dealloc];
334016e8d895 injection of custom code in SDL for iPhone in order to implement our frontend
koda
parents:
diff changeset
    43
}
334016e8d895 injection of custom code in SDL for iPhone in order to implement our frontend
koda
parents:
diff changeset
    44
334016e8d895 injection of custom code in SDL for iPhone in order to implement our frontend
koda
parents:
diff changeset
    45
- (id)initWithFrame:(CGRect)frame {
334016e8d895 injection of custom code in SDL for iPhone in order to implement our frontend
koda
parents:
diff changeset
    46
334016e8d895 injection of custom code in SDL for iPhone in order to implement our frontend
koda
parents:
diff changeset
    47
	self = [super initWithFrame: frame];
334016e8d895 injection of custom code in SDL for iPhone in order to implement our frontend
koda
parents:
diff changeset
    48
	
334016e8d895 injection of custom code in SDL for iPhone in order to implement our frontend
koda
parents:
diff changeset
    49
#if SDL_IPHONE_KEYBOARD
334016e8d895 injection of custom code in SDL for iPhone in order to implement our frontend
koda
parents:
diff changeset
    50
	[self initializeKeyboard];
334016e8d895 injection of custom code in SDL for iPhone in order to implement our frontend
koda
parents:
diff changeset
    51
#endif	
334016e8d895 injection of custom code in SDL for iPhone in order to implement our frontend
koda
parents:
diff changeset
    52
334016e8d895 injection of custom code in SDL for iPhone in order to implement our frontend
koda
parents:
diff changeset
    53
	int i;
334016e8d895 injection of custom code in SDL for iPhone in order to implement our frontend
koda
parents:
diff changeset
    54
	for (i=0; i<MAX_SIMULTANEOUS_TOUCHES; i++) {
334016e8d895 injection of custom code in SDL for iPhone in order to implement our frontend
koda
parents:
diff changeset
    55
        mice[i].id = i;
334016e8d895 injection of custom code in SDL for iPhone in order to implement our frontend
koda
parents:
diff changeset
    56
		mice[i].driverdata = NULL;
334016e8d895 injection of custom code in SDL for iPhone in order to implement our frontend
koda
parents:
diff changeset
    57
		SDL_AddMouse(&mice[i], "Mouse", 0, 0, 1);
334016e8d895 injection of custom code in SDL for iPhone in order to implement our frontend
koda
parents:
diff changeset
    58
	}
2683
bad2a30d5d6c touch input: reset zoom, attack button
koda
parents: 2682
diff changeset
    59
	
bad2a30d5d6c touch input: reset zoom, attack button
koda
parents: 2682
diff changeset
    60
	UIButton *attackButton;
bad2a30d5d6c touch input: reset zoom, attack button
koda
parents: 2682
diff changeset
    61
bad2a30d5d6c touch input: reset zoom, attack button
koda
parents: 2682
diff changeset
    62
	attackButton = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, 90,60)];
bad2a30d5d6c touch input: reset zoom, attack button
koda
parents: 2682
diff changeset
    63
	[attackButton setBackgroundImage:[UIImage imageNamed:@"Default.png"] forState:UIControlStateNormal];
bad2a30d5d6c touch input: reset zoom, attack button
koda
parents: 2682
diff changeset
    64
	// this object is inherited by SDL_openglesview.m which is the one allocated by SDL.
bad2a30d5d6c touch input: reset zoom, attack button
koda
parents: 2682
diff changeset
    65
	// We select this class with [self superclass] and call the selectors with "+" because
bad2a30d5d6c touch input: reset zoom, attack button
koda
parents: 2682
diff changeset
    66
	// they are superclass methods 
bad2a30d5d6c touch input: reset zoom, attack button
koda
parents: 2682
diff changeset
    67
	[attackButton addTarget:[self superclass] action:@selector(attackButtonPressed) forControlEvents:UIControlEventTouchDown];
bad2a30d5d6c touch input: reset zoom, attack button
koda
parents: 2682
diff changeset
    68
	[attackButton addTarget:[self superclass] action:@selector(attackButtonReleased) forControlEvents:UIControlEventTouchUpInside|UIControlEventTouchUpOutside];
bad2a30d5d6c touch input: reset zoom, attack button
koda
parents: 2682
diff changeset
    69
	[self insertSubview:attackButton atIndex:10];
bad2a30d5d6c touch input: reset zoom, attack button
koda
parents: 2682
diff changeset
    70
	[attackButton release];
bad2a30d5d6c touch input: reset zoom, attack button
koda
parents: 2682
diff changeset
    71
2678
334016e8d895 injection of custom code in SDL for iPhone in order to implement our frontend
koda
parents:
diff changeset
    72
	self.multipleTouchEnabled = YES;
334016e8d895 injection of custom code in SDL for iPhone in order to implement our frontend
koda
parents:
diff changeset
    73
			
334016e8d895 injection of custom code in SDL for iPhone in order to implement our frontend
koda
parents:
diff changeset
    74
	return self;
2683
bad2a30d5d6c touch input: reset zoom, attack button
koda
parents: 2682
diff changeset
    75
}
2678
334016e8d895 injection of custom code in SDL for iPhone in order to implement our frontend
koda
parents:
diff changeset
    76
2683
bad2a30d5d6c touch input: reset zoom, attack button
koda
parents: 2682
diff changeset
    77
#pragma mark -
bad2a30d5d6c touch input: reset zoom, attack button
koda
parents: 2682
diff changeset
    78
#pragma mark Superclass methods
bad2a30d5d6c touch input: reset zoom, attack button
koda
parents: 2682
diff changeset
    79
+(void) attackButtonPressed {
bad2a30d5d6c touch input: reset zoom, attack button
koda
parents: 2682
diff changeset
    80
	HW_shoot();
bad2a30d5d6c touch input: reset zoom, attack button
koda
parents: 2682
diff changeset
    81
}
bad2a30d5d6c touch input: reset zoom, attack button
koda
parents: 2682
diff changeset
    82
bad2a30d5d6c touch input: reset zoom, attack button
koda
parents: 2682
diff changeset
    83
+(void) attackButtonReleased {
bad2a30d5d6c touch input: reset zoom, attack button
koda
parents: 2682
diff changeset
    84
	HW_allKeysUp();
2678
334016e8d895 injection of custom code in SDL for iPhone in order to implement our frontend
koda
parents:
diff changeset
    85
}
334016e8d895 injection of custom code in SDL for iPhone in order to implement our frontend
koda
parents:
diff changeset
    86
334016e8d895 injection of custom code in SDL for iPhone in order to implement our frontend
koda
parents:
diff changeset
    87
#pragma mark -
334016e8d895 injection of custom code in SDL for iPhone in order to implement our frontend
koda
parents:
diff changeset
    88
#pragma mark Custom SDL_UIView input handling
334016e8d895 injection of custom code in SDL for iPhone in order to implement our frontend
koda
parents:
diff changeset
    89
334016e8d895 injection of custom code in SDL for iPhone in order to implement our frontend
koda
parents:
diff changeset
    90
// we override default touch input to implement our own gestures
334016e8d895 injection of custom code in SDL for iPhone in order to implement our frontend
koda
parents:
diff changeset
    91
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
334016e8d895 injection of custom code in SDL for iPhone in order to implement our frontend
koda
parents:
diff changeset
    92
	/*NSEnumerator *enumerator = [touches objectEnumerator];
334016e8d895 injection of custom code in SDL for iPhone in order to implement our frontend
koda
parents:
diff changeset
    93
	UITouch *touch =(UITouch*)[enumerator nextObject];
334016e8d895 injection of custom code in SDL for iPhone in order to implement our frontend
koda
parents:
diff changeset
    94
	
334016e8d895 injection of custom code in SDL for iPhone in order to implement our frontend
koda
parents:
diff changeset
    95
	/* associate touches with mice, so long as we have slots 
334016e8d895 injection of custom code in SDL for iPhone in order to implement our frontend
koda
parents:
diff changeset
    96
	int i;
334016e8d895 injection of custom code in SDL for iPhone in order to implement our frontend
koda
parents:
diff changeset
    97
	int found = 0;
334016e8d895 injection of custom code in SDL for iPhone in order to implement our frontend
koda
parents:
diff changeset
    98
	for(i=0; touch && i < MAX_SIMULTANEOUS_TOUCHES; i++) {
334016e8d895 injection of custom code in SDL for iPhone in order to implement our frontend
koda
parents:
diff changeset
    99
	
334016e8d895 injection of custom code in SDL for iPhone in order to implement our frontend
koda
parents:
diff changeset
   100
		/* check if this mouse is already tracking a touch 
334016e8d895 injection of custom code in SDL for iPhone in order to implement our frontend
koda
parents:
diff changeset
   101
		if (mice[i].driverdata != NULL) {
334016e8d895 injection of custom code in SDL for iPhone in order to implement our frontend
koda
parents:
diff changeset
   102
			continue;
334016e8d895 injection of custom code in SDL for iPhone in order to implement our frontend
koda
parents:
diff changeset
   103
		}
334016e8d895 injection of custom code in SDL for iPhone in order to implement our frontend
koda
parents:
diff changeset
   104
		/*	
334016e8d895 injection of custom code in SDL for iPhone in order to implement our frontend
koda
parents:
diff changeset
   105
			mouse not associated with anything right now,
334016e8d895 injection of custom code in SDL for iPhone in order to implement our frontend
koda
parents:
diff changeset
   106
			associate the touch with this mouse
334016e8d895 injection of custom code in SDL for iPhone in order to implement our frontend
koda
parents:
diff changeset
   107
		
334016e8d895 injection of custom code in SDL for iPhone in order to implement our frontend
koda
parents:
diff changeset
   108
		found = 1;
334016e8d895 injection of custom code in SDL for iPhone in order to implement our frontend
koda
parents:
diff changeset
   109
		
334016e8d895 injection of custom code in SDL for iPhone in order to implement our frontend
koda
parents:
diff changeset
   110
		/* save old mouse so we can switch back 
334016e8d895 injection of custom code in SDL for iPhone in order to implement our frontend
koda
parents:
diff changeset
   111
		int oldMouse = SDL_SelectMouse(-1);
334016e8d895 injection of custom code in SDL for iPhone in order to implement our frontend
koda
parents:
diff changeset
   112
		
334016e8d895 injection of custom code in SDL for iPhone in order to implement our frontend
koda
parents:
diff changeset
   113
		/* select this slot's mouse 
334016e8d895 injection of custom code in SDL for iPhone in order to implement our frontend
koda
parents:
diff changeset
   114
		SDL_SelectMouse(i);
334016e8d895 injection of custom code in SDL for iPhone in order to implement our frontend
koda
parents:
diff changeset
   115
		CGPoint locationInView = [touch locationInView: self];
334016e8d895 injection of custom code in SDL for iPhone in order to implement our frontend
koda
parents:
diff changeset
   116
		
334016e8d895 injection of custom code in SDL for iPhone in order to implement our frontend
koda
parents:
diff changeset
   117
		/* set driver data to touch object, we'll use touch object later 
334016e8d895 injection of custom code in SDL for iPhone in order to implement our frontend
koda
parents:
diff changeset
   118
		mice[i].driverdata = [touch retain];
334016e8d895 injection of custom code in SDL for iPhone in order to implement our frontend
koda
parents:
diff changeset
   119
		
334016e8d895 injection of custom code in SDL for iPhone in order to implement our frontend
koda
parents:
diff changeset
   120
		/* send moved event 
334016e8d895 injection of custom code in SDL for iPhone in order to implement our frontend
koda
parents:
diff changeset
   121
		SDL_SendMouseMotion(i, 0, locationInView.x, locationInView.y, 0);
334016e8d895 injection of custom code in SDL for iPhone in order to implement our frontend
koda
parents:
diff changeset
   122
		
334016e8d895 injection of custom code in SDL for iPhone in order to implement our frontend
koda
parents:
diff changeset
   123
		/* send mouse down event 
334016e8d895 injection of custom code in SDL for iPhone in order to implement our frontend
koda
parents:
diff changeset
   124
		SDL_SendMouseButton(i, SDL_PRESSED, SDL_BUTTON_LEFT);
334016e8d895 injection of custom code in SDL for iPhone in order to implement our frontend
koda
parents:
diff changeset
   125
		
334016e8d895 injection of custom code in SDL for iPhone in order to implement our frontend
koda
parents:
diff changeset
   126
		/* re-calibrate relative mouse motion 
334016e8d895 injection of custom code in SDL for iPhone in order to implement our frontend
koda
parents:
diff changeset
   127
		SDL_GetRelativeMouseState(i, NULL, NULL);
334016e8d895 injection of custom code in SDL for iPhone in order to implement our frontend
koda
parents:
diff changeset
   128
		
334016e8d895 injection of custom code in SDL for iPhone in order to implement our frontend
koda
parents:
diff changeset
   129
		/* grab next touch 
334016e8d895 injection of custom code in SDL for iPhone in order to implement our frontend
koda
parents:
diff changeset
   130
		touch = (UITouch*)[enumerator nextObject]; 
334016e8d895 injection of custom code in SDL for iPhone in order to implement our frontend
koda
parents:
diff changeset
   131
		
334016e8d895 injection of custom code in SDL for iPhone in order to implement our frontend
koda
parents:
diff changeset
   132
		/* switch back to our old mouse 
334016e8d895 injection of custom code in SDL for iPhone in order to implement our frontend
koda
parents:
diff changeset
   133
		SDL_SelectMouse(oldMouse);
334016e8d895 injection of custom code in SDL for iPhone in order to implement our frontend
koda
parents:
diff changeset
   134
		
334016e8d895 injection of custom code in SDL for iPhone in order to implement our frontend
koda
parents:
diff changeset
   135
	}	*/
2682
d4c395f25db2 additional modifications for touch input
koda
parents: 2678
diff changeset
   136
	
2678
334016e8d895 injection of custom code in SDL for iPhone in order to implement our frontend
koda
parents:
diff changeset
   137
	UITouch *touch = [touches anyObject];
2682
d4c395f25db2 additional modifications for touch input
koda
parents: 2678
diff changeset
   138
	gestureStartPoint = [touch locationInView:self];
d4c395f25db2 additional modifications for touch input
koda
parents: 2678
diff changeset
   139
2683
bad2a30d5d6c touch input: reset zoom, attack button
koda
parents: 2682
diff changeset
   140
	// one tap - single click
2682
d4c395f25db2 additional modifications for touch input
koda
parents: 2678
diff changeset
   141
	if (1 == [touch tapCount] ) {
d4c395f25db2 additional modifications for touch input
koda
parents: 2678
diff changeset
   142
		//SDL_WarpMouseInWindow([SDLUIKitDelegate sharedAppDelegate].windowID, gestureStartPoint.x, gestureStartPoint.y);
d4c395f25db2 additional modifications for touch input
koda
parents: 2678
diff changeset
   143
		HW_click();
d4c395f25db2 additional modifications for touch input
koda
parents: 2678
diff changeset
   144
	}
d4c395f25db2 additional modifications for touch input
koda
parents: 2678
diff changeset
   145
	
2683
bad2a30d5d6c touch input: reset zoom, attack button
koda
parents: 2682
diff changeset
   146
	// two taps - right click
2678
334016e8d895 injection of custom code in SDL for iPhone in order to implement our frontend
koda
parents:
diff changeset
   147
	if (2 == [touch tapCount] ) {
334016e8d895 injection of custom code in SDL for iPhone in order to implement our frontend
koda
parents:
diff changeset
   148
		HW_ammoMenu();
334016e8d895 injection of custom code in SDL for iPhone in order to implement our frontend
koda
parents:
diff changeset
   149
	}
334016e8d895 injection of custom code in SDL for iPhone in order to implement our frontend
koda
parents:
diff changeset
   150
	
2683
bad2a30d5d6c touch input: reset zoom, attack button
koda
parents: 2682
diff changeset
   151
	// two taps with two fingers - middle click
bad2a30d5d6c touch input: reset zoom, attack button
koda
parents: 2682
diff changeset
   152
	if (2 == [touch tapCount] && 2 == [touches count]) {
bad2a30d5d6c touch input: reset zoom, attack button
koda
parents: 2682
diff changeset
   153
		HW_zoomReset();
bad2a30d5d6c touch input: reset zoom, attack button
koda
parents: 2682
diff changeset
   154
	}
bad2a30d5d6c touch input: reset zoom, attack button
koda
parents: 2682
diff changeset
   155
	
bad2a30d5d6c touch input: reset zoom, attack button
koda
parents: 2682
diff changeset
   156
	// two fingers - begin pinching
2678
334016e8d895 injection of custom code in SDL for iPhone in order to implement our frontend
koda
parents:
diff changeset
   157
	if (2 == [touches count]) {
334016e8d895 injection of custom code in SDL for iPhone in order to implement our frontend
koda
parents:
diff changeset
   158
		NSArray *twoTouches = [touches allObjects];
334016e8d895 injection of custom code in SDL for iPhone in order to implement our frontend
koda
parents:
diff changeset
   159
		UITouch *first = [twoTouches objectAtIndex:0];
334016e8d895 injection of custom code in SDL for iPhone in order to implement our frontend
koda
parents:
diff changeset
   160
		UITouch *second = [twoTouches objectAtIndex:1];
334016e8d895 injection of custom code in SDL for iPhone in order to implement our frontend
koda
parents:
diff changeset
   161
		initialDistance = distanceBetweenPoints([first locationInView:self], [second locationInView:self]);
334016e8d895 injection of custom code in SDL for iPhone in order to implement our frontend
koda
parents:
diff changeset
   162
	}
334016e8d895 injection of custom code in SDL for iPhone in order to implement our frontend
koda
parents:
diff changeset
   163
}
334016e8d895 injection of custom code in SDL for iPhone in order to implement our frontend
koda
parents:
diff changeset
   164
334016e8d895 injection of custom code in SDL for iPhone in order to implement our frontend
koda
parents:
diff changeset
   165
- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {
334016e8d895 injection of custom code in SDL for iPhone in order to implement our frontend
koda
parents:
diff changeset
   166
	initialDistance = 0;
2682
d4c395f25db2 additional modifications for touch input
koda
parents: 2678
diff changeset
   167
	NSLog(@"touches ended, sigh");
d4c395f25db2 additional modifications for touch input
koda
parents: 2678
diff changeset
   168
	
d4c395f25db2 additional modifications for touch input
koda
parents: 2678
diff changeset
   169
	HW_allKeysUp();
2678
334016e8d895 injection of custom code in SDL for iPhone in order to implement our frontend
koda
parents:
diff changeset
   170
	/*NSEnumerator *enumerator = [touches objectEnumerator];
334016e8d895 injection of custom code in SDL for iPhone in order to implement our frontend
koda
parents:
diff changeset
   171
	UITouch *touch=nil;
334016e8d895 injection of custom code in SDL for iPhone in order to implement our frontend
koda
parents:
diff changeset
   172
	
334016e8d895 injection of custom code in SDL for iPhone in order to implement our frontend
koda
parents:
diff changeset
   173
	while(touch = (UITouch *)[enumerator nextObject]) {
334016e8d895 injection of custom code in SDL for iPhone in order to implement our frontend
koda
parents:
diff changeset
   174
		/* search for the mouse slot associated with this touch 
334016e8d895 injection of custom code in SDL for iPhone in order to implement our frontend
koda
parents:
diff changeset
   175
		int i, found = NO;
334016e8d895 injection of custom code in SDL for iPhone in order to implement our frontend
koda
parents:
diff changeset
   176
		for (i=0; i<MAX_SIMULTANEOUS_TOUCHES && !found; i++) {
334016e8d895 injection of custom code in SDL for iPhone in order to implement our frontend
koda
parents:
diff changeset
   177
			if (mice[i].driverdata == touch) {
334016e8d895 injection of custom code in SDL for iPhone in order to implement our frontend
koda
parents:
diff changeset
   178
				/* found the mouse associate with the touch 
334016e8d895 injection of custom code in SDL for iPhone in order to implement our frontend
koda
parents:
diff changeset
   179
				[(UITouch*)(mice[i].driverdata) release];
334016e8d895 injection of custom code in SDL for iPhone in order to implement our frontend
koda
parents:
diff changeset
   180
				mice[i].driverdata = NULL;
334016e8d895 injection of custom code in SDL for iPhone in order to implement our frontend
koda
parents:
diff changeset
   181
				/* send mouse up 
334016e8d895 injection of custom code in SDL for iPhone in order to implement our frontend
koda
parents:
diff changeset
   182
				SDL_SendMouseButton(i, SDL_RELEASED, SDL_BUTTON_LEFT);
334016e8d895 injection of custom code in SDL for iPhone in order to implement our frontend
koda
parents:
diff changeset
   183
				/* discontinue search for this touch 
334016e8d895 injection of custom code in SDL for iPhone in order to implement our frontend
koda
parents:
diff changeset
   184
				found = YES;
334016e8d895 injection of custom code in SDL for iPhone in order to implement our frontend
koda
parents:
diff changeset
   185
			}
334016e8d895 injection of custom code in SDL for iPhone in order to implement our frontend
koda
parents:
diff changeset
   186
		}
334016e8d895 injection of custom code in SDL for iPhone in order to implement our frontend
koda
parents:
diff changeset
   187
	}*/
334016e8d895 injection of custom code in SDL for iPhone in order to implement our frontend
koda
parents:
diff changeset
   188
}
334016e8d895 injection of custom code in SDL for iPhone in order to implement our frontend
koda
parents:
diff changeset
   189
334016e8d895 injection of custom code in SDL for iPhone in order to implement our frontend
koda
parents:
diff changeset
   190
- (void)touchesCancelled:(NSSet *)touches withEvent:(UIEvent *)event {
334016e8d895 injection of custom code in SDL for iPhone in order to implement our frontend
koda
parents:
diff changeset
   191
	/*
334016e8d895 injection of custom code in SDL for iPhone in order to implement our frontend
koda
parents:
diff changeset
   192
		this can happen if the user puts more than 5 touches on the screen
334016e8d895 injection of custom code in SDL for iPhone in order to implement our frontend
koda
parents:
diff changeset
   193
		at once, or perhaps in other circumstances.  Usually (it seems)
334016e8d895 injection of custom code in SDL for iPhone in order to implement our frontend
koda
parents:
diff changeset
   194
		all active touches are canceled.
334016e8d895 injection of custom code in SDL for iPhone in order to implement our frontend
koda
parents:
diff changeset
   195
	*/
334016e8d895 injection of custom code in SDL for iPhone in order to implement our frontend
koda
parents:
diff changeset
   196
	[self touchesEnded: touches withEvent: event];
334016e8d895 injection of custom code in SDL for iPhone in order to implement our frontend
koda
parents:
diff changeset
   197
}
334016e8d895 injection of custom code in SDL for iPhone in order to implement our frontend
koda
parents:
diff changeset
   198
334016e8d895 injection of custom code in SDL for iPhone in order to implement our frontend
koda
parents:
diff changeset
   199
- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {
2682
d4c395f25db2 additional modifications for touch input
koda
parents: 2678
diff changeset
   200
	UITouch *touch = [touches anyObject];
d4c395f25db2 additional modifications for touch input
koda
parents: 2678
diff changeset
   201
	CGPoint currentPosition = [touch locationInView:self];
2678
334016e8d895 injection of custom code in SDL for iPhone in order to implement our frontend
koda
parents:
diff changeset
   202
	
2683
bad2a30d5d6c touch input: reset zoom, attack button
koda
parents: 2682
diff changeset
   203
	CGFloat Xdiff = gestureStartPoint.x - currentPosition.x;
bad2a30d5d6c touch input: reset zoom, attack button
koda
parents: 2682
diff changeset
   204
	CGFloat Ydiff = gestureStartPoint.y - currentPosition.y;
bad2a30d5d6c touch input: reset zoom, attack button
koda
parents: 2682
diff changeset
   205
	CGFloat deltaX = fabsf(Xdiff);
bad2a30d5d6c touch input: reset zoom, attack button
koda
parents: 2682
diff changeset
   206
    CGFloat deltaY = fabsf(Ydiff);
2682
d4c395f25db2 additional modifications for touch input
koda
parents: 2678
diff changeset
   207
    
d4c395f25db2 additional modifications for touch input
koda
parents: 2678
diff changeset
   208
	if (deltaX >= kMinimumGestureLength && deltaY <= kMaximumVariance) {
d4c395f25db2 additional modifications for touch input
koda
parents: 2678
diff changeset
   209
		NSLog(@"Horizontal swipe detected, begX:%f curX:%f", gestureStartPoint.x, currentPosition.x);
2683
bad2a30d5d6c touch input: reset zoom, attack button
koda
parents: 2682
diff changeset
   210
		if (Xdiff > 0) HW_walkLeft();
bad2a30d5d6c touch input: reset zoom, attack button
koda
parents: 2682
diff changeset
   211
		else HW_walkRight();
2682
d4c395f25db2 additional modifications for touch input
koda
parents: 2678
diff changeset
   212
    }
d4c395f25db2 additional modifications for touch input
koda
parents: 2678
diff changeset
   213
    else if (deltaY >= kMinimumGestureLength && deltaX <= kMaximumVariance){
d4c395f25db2 additional modifications for touch input
koda
parents: 2678
diff changeset
   214
		NSLog(@"Vertical swipe detected, begY:%f curY:%f", gestureStartPoint.y, currentPosition.y);
2683
bad2a30d5d6c touch input: reset zoom, attack button
koda
parents: 2682
diff changeset
   215
		if (Ydiff > 0) HW_aimUp();
bad2a30d5d6c touch input: reset zoom, attack button
koda
parents: 2682
diff changeset
   216
		else HW_aimDown();
bad2a30d5d6c touch input: reset zoom, attack button
koda
parents: 2682
diff changeset
   217
	}
2682
d4c395f25db2 additional modifications for touch input
koda
parents: 2678
diff changeset
   218
	
2678
334016e8d895 injection of custom code in SDL for iPhone in order to implement our frontend
koda
parents:
diff changeset
   219
	if (2 == [touches count]) {
334016e8d895 injection of custom code in SDL for iPhone in order to implement our frontend
koda
parents:
diff changeset
   220
		NSArray *twoTouches = [touches allObjects];
334016e8d895 injection of custom code in SDL for iPhone in order to implement our frontend
koda
parents:
diff changeset
   221
		UITouch *first = [twoTouches objectAtIndex:0];
334016e8d895 injection of custom code in SDL for iPhone in order to implement our frontend
koda
parents:
diff changeset
   222
		UITouch *second = [twoTouches objectAtIndex:1];
334016e8d895 injection of custom code in SDL for iPhone in order to implement our frontend
koda
parents:
diff changeset
   223
		CGFloat currentDistance = distanceBetweenPoints([first locationInView:self], [second locationInView:self]);
334016e8d895 injection of custom code in SDL for iPhone in order to implement our frontend
koda
parents:
diff changeset
   224
	
334016e8d895 injection of custom code in SDL for iPhone in order to implement our frontend
koda
parents:
diff changeset
   225
		if (0 == initialDistance) 
334016e8d895 injection of custom code in SDL for iPhone in order to implement our frontend
koda
parents:
diff changeset
   226
			initialDistance = currentDistance;
334016e8d895 injection of custom code in SDL for iPhone in order to implement our frontend
koda
parents:
diff changeset
   227
		else if (currentDistance - initialDistance > kMinimumPinchDelta) {
334016e8d895 injection of custom code in SDL for iPhone in order to implement our frontend
koda
parents:
diff changeset
   228
			NSLog(@"Outward pinch detected");
334016e8d895 injection of custom code in SDL for iPhone in order to implement our frontend
koda
parents:
diff changeset
   229
			HW_zoomOut();
334016e8d895 injection of custom code in SDL for iPhone in order to implement our frontend
koda
parents:
diff changeset
   230
		}
334016e8d895 injection of custom code in SDL for iPhone in order to implement our frontend
koda
parents:
diff changeset
   231
		else if (initialDistance - currentDistance > kMinimumPinchDelta) {
334016e8d895 injection of custom code in SDL for iPhone in order to implement our frontend
koda
parents:
diff changeset
   232
			NSLog(@"Inward pinch detected");
334016e8d895 injection of custom code in SDL for iPhone in order to implement our frontend
koda
parents:
diff changeset
   233
			HW_zoomIn();
334016e8d895 injection of custom code in SDL for iPhone in order to implement our frontend
koda
parents:
diff changeset
   234
		}
334016e8d895 injection of custom code in SDL for iPhone in order to implement our frontend
koda
parents:
diff changeset
   235
	}
334016e8d895 injection of custom code in SDL for iPhone in order to implement our frontend
koda
parents:
diff changeset
   236
	
2682
d4c395f25db2 additional modifications for touch input
koda
parents: 2678
diff changeset
   237
	/*NSEnumerator *enumerator = [touches objectEnumerator];
d4c395f25db2 additional modifications for touch input
koda
parents: 2678
diff changeset
   238
	 UITouch *touch=nil;while(touch = (UITouch *)[enumerator nextObject]) {
2678
334016e8d895 injection of custom code in SDL for iPhone in order to implement our frontend
koda
parents:
diff changeset
   239
		// try to find the mouse associated with this touch 
334016e8d895 injection of custom code in SDL for iPhone in order to implement our frontend
koda
parents:
diff changeset
   240
		int i, found = NO;
334016e8d895 injection of custom code in SDL for iPhone in order to implement our frontend
koda
parents:
diff changeset
   241
		for (i=0; i<MAX_SIMULTANEOUS_TOUCHES && !found; i++) {
334016e8d895 injection of custom code in SDL for iPhone in order to implement our frontend
koda
parents:
diff changeset
   242
			if (mice[i].driverdata == touch) {
334016e8d895 injection of custom code in SDL for iPhone in order to implement our frontend
koda
parents:
diff changeset
   243
				// found proper mouse 
334016e8d895 injection of custom code in SDL for iPhone in order to implement our frontend
koda
parents:
diff changeset
   244
				CGPoint locationInView = [touch locationInView: self];
334016e8d895 injection of custom code in SDL for iPhone in order to implement our frontend
koda
parents:
diff changeset
   245
				// send moved event 
334016e8d895 injection of custom code in SDL for iPhone in order to implement our frontend
koda
parents:
diff changeset
   246
				SDL_SendMouseMotion(i, 0, locationInView.x, locationInView.y, 0);
334016e8d895 injection of custom code in SDL for iPhone in order to implement our frontend
koda
parents:
diff changeset
   247
				// discontinue search 
334016e8d895 injection of custom code in SDL for iPhone in order to implement our frontend
koda
parents:
diff changeset
   248
				found = YES;
334016e8d895 injection of custom code in SDL for iPhone in order to implement our frontend
koda
parents:
diff changeset
   249
			}
334016e8d895 injection of custom code in SDL for iPhone in order to implement our frontend
koda
parents:
diff changeset
   250
		}
334016e8d895 injection of custom code in SDL for iPhone in order to implement our frontend
koda
parents:
diff changeset
   251
	}*/
334016e8d895 injection of custom code in SDL for iPhone in order to implement our frontend
koda
parents:
diff changeset
   252
}
334016e8d895 injection of custom code in SDL for iPhone in order to implement our frontend
koda
parents:
diff changeset
   253
334016e8d895 injection of custom code in SDL for iPhone in order to implement our frontend
koda
parents:
diff changeset
   254
#pragma mark -
334016e8d895 injection of custom code in SDL for iPhone in order to implement our frontend
koda
parents:
diff changeset
   255
#pragma mark default routines
334016e8d895 injection of custom code in SDL for iPhone in order to implement our frontend
koda
parents:
diff changeset
   256
/*
334016e8d895 injection of custom code in SDL for iPhone in order to implement our frontend
koda
parents:
diff changeset
   257
	---- Keyboard related functionality below this line ----
334016e8d895 injection of custom code in SDL for iPhone in order to implement our frontend
koda
parents:
diff changeset
   258
*/
334016e8d895 injection of custom code in SDL for iPhone in order to implement our frontend
koda
parents:
diff changeset
   259
#if SDL_IPHONE_KEYBOARD
334016e8d895 injection of custom code in SDL for iPhone in order to implement our frontend
koda
parents:
diff changeset
   260
334016e8d895 injection of custom code in SDL for iPhone in order to implement our frontend
koda
parents:
diff changeset
   261
/* Is the iPhone virtual keyboard visible onscreen? */
334016e8d895 injection of custom code in SDL for iPhone in order to implement our frontend
koda
parents:
diff changeset
   262
- (BOOL)keyboardVisible {
334016e8d895 injection of custom code in SDL for iPhone in order to implement our frontend
koda
parents:
diff changeset
   263
	return keyboardVisible;
334016e8d895 injection of custom code in SDL for iPhone in order to implement our frontend
koda
parents:
diff changeset
   264
}
334016e8d895 injection of custom code in SDL for iPhone in order to implement our frontend
koda
parents:
diff changeset
   265
334016e8d895 injection of custom code in SDL for iPhone in order to implement our frontend
koda
parents:
diff changeset
   266
/* Set ourselves up as a UITextFieldDelegate */
334016e8d895 injection of custom code in SDL for iPhone in order to implement our frontend
koda
parents:
diff changeset
   267
- (void)initializeKeyboard {
334016e8d895 injection of custom code in SDL for iPhone in order to implement our frontend
koda
parents:
diff changeset
   268
		
334016e8d895 injection of custom code in SDL for iPhone in order to implement our frontend
koda
parents:
diff changeset
   269
	textField = [[[UITextField alloc] initWithFrame: CGRectZero] autorelease];
334016e8d895 injection of custom code in SDL for iPhone in order to implement our frontend
koda
parents:
diff changeset
   270
	textField.delegate = self;
334016e8d895 injection of custom code in SDL for iPhone in order to implement our frontend
koda
parents:
diff changeset
   271
	/* placeholder so there is something to delete! */
334016e8d895 injection of custom code in SDL for iPhone in order to implement our frontend
koda
parents:
diff changeset
   272
	textField.text = @" ";	
334016e8d895 injection of custom code in SDL for iPhone in order to implement our frontend
koda
parents:
diff changeset
   273
	
334016e8d895 injection of custom code in SDL for iPhone in order to implement our frontend
koda
parents:
diff changeset
   274
	/* set UITextInputTrait properties, mostly to defaults */
334016e8d895 injection of custom code in SDL for iPhone in order to implement our frontend
koda
parents:
diff changeset
   275
	textField.autocapitalizationType = UITextAutocapitalizationTypeNone;
334016e8d895 injection of custom code in SDL for iPhone in order to implement our frontend
koda
parents:
diff changeset
   276
	textField.autocorrectionType = UITextAutocorrectionTypeNo;
334016e8d895 injection of custom code in SDL for iPhone in order to implement our frontend
koda
parents:
diff changeset
   277
	textField.enablesReturnKeyAutomatically = NO;
334016e8d895 injection of custom code in SDL for iPhone in order to implement our frontend
koda
parents:
diff changeset
   278
	textField.keyboardAppearance = UIKeyboardAppearanceDefault;
334016e8d895 injection of custom code in SDL for iPhone in order to implement our frontend
koda
parents:
diff changeset
   279
	textField.keyboardType = UIKeyboardTypeDefault;
334016e8d895 injection of custom code in SDL for iPhone in order to implement our frontend
koda
parents:
diff changeset
   280
	textField.returnKeyType = UIReturnKeyDefault;
334016e8d895 injection of custom code in SDL for iPhone in order to implement our frontend
koda
parents:
diff changeset
   281
	textField.secureTextEntry = NO;	
334016e8d895 injection of custom code in SDL for iPhone in order to implement our frontend
koda
parents:
diff changeset
   282
	
334016e8d895 injection of custom code in SDL for iPhone in order to implement our frontend
koda
parents:
diff changeset
   283
	textField.hidden = YES;
334016e8d895 injection of custom code in SDL for iPhone in order to implement our frontend
koda
parents:
diff changeset
   284
	keyboardVisible = NO;
334016e8d895 injection of custom code in SDL for iPhone in order to implement our frontend
koda
parents:
diff changeset
   285
	/* add the UITextField (hidden) to our view */
334016e8d895 injection of custom code in SDL for iPhone in order to implement our frontend
koda
parents:
diff changeset
   286
	[self addSubview: textField];
334016e8d895 injection of custom code in SDL for iPhone in order to implement our frontend
koda
parents:
diff changeset
   287
	
334016e8d895 injection of custom code in SDL for iPhone in order to implement our frontend
koda
parents:
diff changeset
   288
	/* create our SDL_Keyboard */
334016e8d895 injection of custom code in SDL for iPhone in order to implement our frontend
koda
parents:
diff changeset
   289
	SDL_Keyboard keyboard;
334016e8d895 injection of custom code in SDL for iPhone in order to implement our frontend
koda
parents:
diff changeset
   290
	SDL_zero(keyboard);
334016e8d895 injection of custom code in SDL for iPhone in order to implement our frontend
koda
parents:
diff changeset
   291
	SDL_AddKeyboard(&keyboard, 0);
334016e8d895 injection of custom code in SDL for iPhone in order to implement our frontend
koda
parents:
diff changeset
   292
	SDLKey keymap[SDL_NUM_SCANCODES];
334016e8d895 injection of custom code in SDL for iPhone in order to implement our frontend
koda
parents:
diff changeset
   293
	SDL_GetDefaultKeymap(keymap);
334016e8d895 injection of custom code in SDL for iPhone in order to implement our frontend
koda
parents:
diff changeset
   294
	SDL_SetKeymap(0, 0, keymap, SDL_NUM_SCANCODES);
334016e8d895 injection of custom code in SDL for iPhone in order to implement our frontend
koda
parents:
diff changeset
   295
	
334016e8d895 injection of custom code in SDL for iPhone in order to implement our frontend
koda
parents:
diff changeset
   296
}
334016e8d895 injection of custom code in SDL for iPhone in order to implement our frontend
koda
parents:
diff changeset
   297
334016e8d895 injection of custom code in SDL for iPhone in order to implement our frontend
koda
parents:
diff changeset
   298
/* reveal onscreen virtual keyboard */
334016e8d895 injection of custom code in SDL for iPhone in order to implement our frontend
koda
parents:
diff changeset
   299
- (void)showKeyboard {
334016e8d895 injection of custom code in SDL for iPhone in order to implement our frontend
koda
parents:
diff changeset
   300
	keyboardVisible = YES;
334016e8d895 injection of custom code in SDL for iPhone in order to implement our frontend
koda
parents:
diff changeset
   301
	[textField becomeFirstResponder];
334016e8d895 injection of custom code in SDL for iPhone in order to implement our frontend
koda
parents:
diff changeset
   302
}
334016e8d895 injection of custom code in SDL for iPhone in order to implement our frontend
koda
parents:
diff changeset
   303
334016e8d895 injection of custom code in SDL for iPhone in order to implement our frontend
koda
parents:
diff changeset
   304
/* hide onscreen virtual keyboard */
334016e8d895 injection of custom code in SDL for iPhone in order to implement our frontend
koda
parents:
diff changeset
   305
- (void)hideKeyboard {
334016e8d895 injection of custom code in SDL for iPhone in order to implement our frontend
koda
parents:
diff changeset
   306
	keyboardVisible = NO;
334016e8d895 injection of custom code in SDL for iPhone in order to implement our frontend
koda
parents:
diff changeset
   307
	[textField resignFirstResponder];
334016e8d895 injection of custom code in SDL for iPhone in order to implement our frontend
koda
parents:
diff changeset
   308
}
334016e8d895 injection of custom code in SDL for iPhone in order to implement our frontend
koda
parents:
diff changeset
   309
334016e8d895 injection of custom code in SDL for iPhone in order to implement our frontend
koda
parents:
diff changeset
   310
/* UITextFieldDelegate method.  Invoked when user types something. */
334016e8d895 injection of custom code in SDL for iPhone in order to implement our frontend
koda
parents:
diff changeset
   311
- (BOOL)textField:(UITextField *)_textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string {
334016e8d895 injection of custom code in SDL for iPhone in order to implement our frontend
koda
parents:
diff changeset
   312
	
334016e8d895 injection of custom code in SDL for iPhone in order to implement our frontend
koda
parents:
diff changeset
   313
	if ([string length] == 0) {
334016e8d895 injection of custom code in SDL for iPhone in order to implement our frontend
koda
parents:
diff changeset
   314
		/* it wants to replace text with nothing, ie a delete */
334016e8d895 injection of custom code in SDL for iPhone in order to implement our frontend
koda
parents:
diff changeset
   315
		SDL_SendKeyboardKey( 0, SDL_PRESSED, SDL_SCANCODE_DELETE);
334016e8d895 injection of custom code in SDL for iPhone in order to implement our frontend
koda
parents:
diff changeset
   316
		SDL_SendKeyboardKey( 0, SDL_RELEASED, SDL_SCANCODE_DELETE);
334016e8d895 injection of custom code in SDL for iPhone in order to implement our frontend
koda
parents:
diff changeset
   317
	}
334016e8d895 injection of custom code in SDL for iPhone in order to implement our frontend
koda
parents:
diff changeset
   318
	else {
334016e8d895 injection of custom code in SDL for iPhone in order to implement our frontend
koda
parents:
diff changeset
   319
		/* go through all the characters in the string we've been sent
334016e8d895 injection of custom code in SDL for iPhone in order to implement our frontend
koda
parents:
diff changeset
   320
		   and convert them to key presses */
334016e8d895 injection of custom code in SDL for iPhone in order to implement our frontend
koda
parents:
diff changeset
   321
		int i;
334016e8d895 injection of custom code in SDL for iPhone in order to implement our frontend
koda
parents:
diff changeset
   322
		for (i=0; i<[string length]; i++) {
334016e8d895 injection of custom code in SDL for iPhone in order to implement our frontend
koda
parents:
diff changeset
   323
			
334016e8d895 injection of custom code in SDL for iPhone in order to implement our frontend
koda
parents:
diff changeset
   324
			unichar c = [string characterAtIndex: i];
334016e8d895 injection of custom code in SDL for iPhone in order to implement our frontend
koda
parents:
diff changeset
   325
			
334016e8d895 injection of custom code in SDL for iPhone in order to implement our frontend
koda
parents:
diff changeset
   326
			Uint16 mod = 0;
334016e8d895 injection of custom code in SDL for iPhone in order to implement our frontend
koda
parents:
diff changeset
   327
			SDL_scancode code;
334016e8d895 injection of custom code in SDL for iPhone in order to implement our frontend
koda
parents:
diff changeset
   328
			
334016e8d895 injection of custom code in SDL for iPhone in order to implement our frontend
koda
parents:
diff changeset
   329
			if (c < 127) {
334016e8d895 injection of custom code in SDL for iPhone in order to implement our frontend
koda
parents:
diff changeset
   330
				/* figure out the SDL_scancode and SDL_keymod for this unichar */
334016e8d895 injection of custom code in SDL for iPhone in order to implement our frontend
koda
parents:
diff changeset
   331
				code = unicharToUIKeyInfoTable[c].code;
334016e8d895 injection of custom code in SDL for iPhone in order to implement our frontend
koda
parents:
diff changeset
   332
				mod  = unicharToUIKeyInfoTable[c].mod;
334016e8d895 injection of custom code in SDL for iPhone in order to implement our frontend
koda
parents:
diff changeset
   333
			}
334016e8d895 injection of custom code in SDL for iPhone in order to implement our frontend
koda
parents:
diff changeset
   334
			else {
334016e8d895 injection of custom code in SDL for iPhone in order to implement our frontend
koda
parents:
diff changeset
   335
				/* we only deal with ASCII right now */
334016e8d895 injection of custom code in SDL for iPhone in order to implement our frontend
koda
parents:
diff changeset
   336
				code = SDL_SCANCODE_UNKNOWN;
334016e8d895 injection of custom code in SDL for iPhone in order to implement our frontend
koda
parents:
diff changeset
   337
				mod = 0;
334016e8d895 injection of custom code in SDL for iPhone in order to implement our frontend
koda
parents:
diff changeset
   338
			}
334016e8d895 injection of custom code in SDL for iPhone in order to implement our frontend
koda
parents:
diff changeset
   339
			
334016e8d895 injection of custom code in SDL for iPhone in order to implement our frontend
koda
parents:
diff changeset
   340
			if (mod & KMOD_SHIFT) {
334016e8d895 injection of custom code in SDL for iPhone in order to implement our frontend
koda
parents:
diff changeset
   341
				/* If character uses shift, press shift down */
334016e8d895 injection of custom code in SDL for iPhone in order to implement our frontend
koda
parents:
diff changeset
   342
				SDL_SendKeyboardKey( 0, SDL_PRESSED, SDL_SCANCODE_LSHIFT);
334016e8d895 injection of custom code in SDL for iPhone in order to implement our frontend
koda
parents:
diff changeset
   343
			}
334016e8d895 injection of custom code in SDL for iPhone in order to implement our frontend
koda
parents:
diff changeset
   344
			/* send a keydown and keyup even for the character */
334016e8d895 injection of custom code in SDL for iPhone in order to implement our frontend
koda
parents:
diff changeset
   345
			SDL_SendKeyboardKey( 0, SDL_PRESSED, code);
334016e8d895 injection of custom code in SDL for iPhone in order to implement our frontend
koda
parents:
diff changeset
   346
			SDL_SendKeyboardKey( 0, SDL_RELEASED, code);
334016e8d895 injection of custom code in SDL for iPhone in order to implement our frontend
koda
parents:
diff changeset
   347
			if (mod & KMOD_SHIFT) {
334016e8d895 injection of custom code in SDL for iPhone in order to implement our frontend
koda
parents:
diff changeset
   348
				/* If character uses shift, press shift back up */
334016e8d895 injection of custom code in SDL for iPhone in order to implement our frontend
koda
parents:
diff changeset
   349
				SDL_SendKeyboardKey( 0, SDL_RELEASED, SDL_SCANCODE_LSHIFT);
334016e8d895 injection of custom code in SDL for iPhone in order to implement our frontend
koda
parents:
diff changeset
   350
			}			
334016e8d895 injection of custom code in SDL for iPhone in order to implement our frontend
koda
parents:
diff changeset
   351
		}
334016e8d895 injection of custom code in SDL for iPhone in order to implement our frontend
koda
parents:
diff changeset
   352
	}
334016e8d895 injection of custom code in SDL for iPhone in order to implement our frontend
koda
parents:
diff changeset
   353
	return NO; /* don't allow the edit! (keep placeholder text there) */
334016e8d895 injection of custom code in SDL for iPhone in order to implement our frontend
koda
parents:
diff changeset
   354
}
334016e8d895 injection of custom code in SDL for iPhone in order to implement our frontend
koda
parents:
diff changeset
   355
334016e8d895 injection of custom code in SDL for iPhone in order to implement our frontend
koda
parents:
diff changeset
   356
/* Terminates the editing session */
334016e8d895 injection of custom code in SDL for iPhone in order to implement our frontend
koda
parents:
diff changeset
   357
- (BOOL)textFieldShouldReturn:(UITextField*)_textField {
334016e8d895 injection of custom code in SDL for iPhone in order to implement our frontend
koda
parents:
diff changeset
   358
	[self hideKeyboard];
334016e8d895 injection of custom code in SDL for iPhone in order to implement our frontend
koda
parents:
diff changeset
   359
	return YES;
334016e8d895 injection of custom code in SDL for iPhone in order to implement our frontend
koda
parents:
diff changeset
   360
}
334016e8d895 injection of custom code in SDL for iPhone in order to implement our frontend
koda
parents:
diff changeset
   361
334016e8d895 injection of custom code in SDL for iPhone in order to implement our frontend
koda
parents:
diff changeset
   362
#endif
334016e8d895 injection of custom code in SDL for iPhone in order to implement our frontend
koda
parents:
diff changeset
   363
334016e8d895 injection of custom code in SDL for iPhone in order to implement our frontend
koda
parents:
diff changeset
   364
@end
334016e8d895 injection of custom code in SDL for iPhone in order to implement our frontend
koda
parents:
diff changeset
   365
334016e8d895 injection of custom code in SDL for iPhone in order to implement our frontend
koda
parents:
diff changeset
   366
/* iPhone keyboard addition functions */
334016e8d895 injection of custom code in SDL for iPhone in order to implement our frontend
koda
parents:
diff changeset
   367
#if SDL_IPHONE_KEYBOARD
334016e8d895 injection of custom code in SDL for iPhone in order to implement our frontend
koda
parents:
diff changeset
   368
334016e8d895 injection of custom code in SDL for iPhone in order to implement our frontend
koda
parents:
diff changeset
   369
int SDL_iPhoneKeyboardShow(SDL_WindowID windowID) {
334016e8d895 injection of custom code in SDL for iPhone in order to implement our frontend
koda
parents:
diff changeset
   370
	
334016e8d895 injection of custom code in SDL for iPhone in order to implement our frontend
koda
parents:
diff changeset
   371
	SDL_Window *window = SDL_GetWindowFromID(windowID);
334016e8d895 injection of custom code in SDL for iPhone in order to implement our frontend
koda
parents:
diff changeset
   372
	SDL_WindowData *data;
334016e8d895 injection of custom code in SDL for iPhone in order to implement our frontend
koda
parents:
diff changeset
   373
	SDL_uikitview *view;
334016e8d895 injection of custom code in SDL for iPhone in order to implement our frontend
koda
parents:
diff changeset
   374
	
334016e8d895 injection of custom code in SDL for iPhone in order to implement our frontend
koda
parents:
diff changeset
   375
	if (NULL == window) {
334016e8d895 injection of custom code in SDL for iPhone in order to implement our frontend
koda
parents:
diff changeset
   376
		SDL_SetError("Window does not exist");
334016e8d895 injection of custom code in SDL for iPhone in order to implement our frontend
koda
parents:
diff changeset
   377
		return -1;
334016e8d895 injection of custom code in SDL for iPhone in order to implement our frontend
koda
parents:
diff changeset
   378
	}
334016e8d895 injection of custom code in SDL for iPhone in order to implement our frontend
koda
parents:
diff changeset
   379
	
334016e8d895 injection of custom code in SDL for iPhone in order to implement our frontend
koda
parents:
diff changeset
   380
	data = (SDL_WindowData *)window->driverdata;
334016e8d895 injection of custom code in SDL for iPhone in order to implement our frontend
koda
parents:
diff changeset
   381
	view = data->view;
334016e8d895 injection of custom code in SDL for iPhone in order to implement our frontend
koda
parents:
diff changeset
   382
	
334016e8d895 injection of custom code in SDL for iPhone in order to implement our frontend
koda
parents:
diff changeset
   383
	if (nil == view) {
334016e8d895 injection of custom code in SDL for iPhone in order to implement our frontend
koda
parents:
diff changeset
   384
		SDL_SetError("Window has no view");
334016e8d895 injection of custom code in SDL for iPhone in order to implement our frontend
koda
parents:
diff changeset
   385
		return -1;
334016e8d895 injection of custom code in SDL for iPhone in order to implement our frontend
koda
parents:
diff changeset
   386
	}
334016e8d895 injection of custom code in SDL for iPhone in order to implement our frontend
koda
parents:
diff changeset
   387
	else {
334016e8d895 injection of custom code in SDL for iPhone in order to implement our frontend
koda
parents:
diff changeset
   388
		[view showKeyboard];
334016e8d895 injection of custom code in SDL for iPhone in order to implement our frontend
koda
parents:
diff changeset
   389
		return 0;
334016e8d895 injection of custom code in SDL for iPhone in order to implement our frontend
koda
parents:
diff changeset
   390
	}
334016e8d895 injection of custom code in SDL for iPhone in order to implement our frontend
koda
parents:
diff changeset
   391
}
334016e8d895 injection of custom code in SDL for iPhone in order to implement our frontend
koda
parents:
diff changeset
   392
334016e8d895 injection of custom code in SDL for iPhone in order to implement our frontend
koda
parents:
diff changeset
   393
int SDL_iPhoneKeyboardHide(SDL_WindowID windowID) {
334016e8d895 injection of custom code in SDL for iPhone in order to implement our frontend
koda
parents:
diff changeset
   394
	
334016e8d895 injection of custom code in SDL for iPhone in order to implement our frontend
koda
parents:
diff changeset
   395
	SDL_Window *window = SDL_GetWindowFromID(windowID);
334016e8d895 injection of custom code in SDL for iPhone in order to implement our frontend
koda
parents:
diff changeset
   396
	SDL_WindowData *data;
334016e8d895 injection of custom code in SDL for iPhone in order to implement our frontend
koda
parents:
diff changeset
   397
	SDL_uikitview *view;
334016e8d895 injection of custom code in SDL for iPhone in order to implement our frontend
koda
parents:
diff changeset
   398
	
334016e8d895 injection of custom code in SDL for iPhone in order to implement our frontend
koda
parents:
diff changeset
   399
	if (NULL == window) {
334016e8d895 injection of custom code in SDL for iPhone in order to implement our frontend
koda
parents:
diff changeset
   400
		SDL_SetError("Window does not exist");
334016e8d895 injection of custom code in SDL for iPhone in order to implement our frontend
koda
parents:
diff changeset
   401
		return -1;
334016e8d895 injection of custom code in SDL for iPhone in order to implement our frontend
koda
parents:
diff changeset
   402
	}	
334016e8d895 injection of custom code in SDL for iPhone in order to implement our frontend
koda
parents:
diff changeset
   403
	
334016e8d895 injection of custom code in SDL for iPhone in order to implement our frontend
koda
parents:
diff changeset
   404
	data = (SDL_WindowData *)window->driverdata;
334016e8d895 injection of custom code in SDL for iPhone in order to implement our frontend
koda
parents:
diff changeset
   405
	view = data->view;
334016e8d895 injection of custom code in SDL for iPhone in order to implement our frontend
koda
parents:
diff changeset
   406
	
334016e8d895 injection of custom code in SDL for iPhone in order to implement our frontend
koda
parents:
diff changeset
   407
	if (NULL == view) {
334016e8d895 injection of custom code in SDL for iPhone in order to implement our frontend
koda
parents:
diff changeset
   408
		SDL_SetError("Window has no view");
334016e8d895 injection of custom code in SDL for iPhone in order to implement our frontend
koda
parents:
diff changeset
   409
		return -1;
334016e8d895 injection of custom code in SDL for iPhone in order to implement our frontend
koda
parents:
diff changeset
   410
	}
334016e8d895 injection of custom code in SDL for iPhone in order to implement our frontend
koda
parents:
diff changeset
   411
	else {
334016e8d895 injection of custom code in SDL for iPhone in order to implement our frontend
koda
parents:
diff changeset
   412
		[view hideKeyboard];
334016e8d895 injection of custom code in SDL for iPhone in order to implement our frontend
koda
parents:
diff changeset
   413
		return 0;
334016e8d895 injection of custom code in SDL for iPhone in order to implement our frontend
koda
parents:
diff changeset
   414
	}
334016e8d895 injection of custom code in SDL for iPhone in order to implement our frontend
koda
parents:
diff changeset
   415
}
334016e8d895 injection of custom code in SDL for iPhone in order to implement our frontend
koda
parents:
diff changeset
   416
334016e8d895 injection of custom code in SDL for iPhone in order to implement our frontend
koda
parents:
diff changeset
   417
SDL_bool SDL_iPhoneKeyboardIsShown(SDL_WindowID windowID) {
334016e8d895 injection of custom code in SDL for iPhone in order to implement our frontend
koda
parents:
diff changeset
   418
	
334016e8d895 injection of custom code in SDL for iPhone in order to implement our frontend
koda
parents:
diff changeset
   419
	SDL_Window *window = SDL_GetWindowFromID(windowID);
334016e8d895 injection of custom code in SDL for iPhone in order to implement our frontend
koda
parents:
diff changeset
   420
	SDL_WindowData *data;
334016e8d895 injection of custom code in SDL for iPhone in order to implement our frontend
koda
parents:
diff changeset
   421
	SDL_uikitview *view;
334016e8d895 injection of custom code in SDL for iPhone in order to implement our frontend
koda
parents:
diff changeset
   422
	
334016e8d895 injection of custom code in SDL for iPhone in order to implement our frontend
koda
parents:
diff changeset
   423
	if (NULL == window) {
334016e8d895 injection of custom code in SDL for iPhone in order to implement our frontend
koda
parents:
diff changeset
   424
		SDL_SetError("Window does not exist");
334016e8d895 injection of custom code in SDL for iPhone in order to implement our frontend
koda
parents:
diff changeset
   425
		return -1;
334016e8d895 injection of custom code in SDL for iPhone in order to implement our frontend
koda
parents:
diff changeset
   426
	}	
334016e8d895 injection of custom code in SDL for iPhone in order to implement our frontend
koda
parents:
diff changeset
   427
	
334016e8d895 injection of custom code in SDL for iPhone in order to implement our frontend
koda
parents:
diff changeset
   428
	data = (SDL_WindowData *)window->driverdata;
334016e8d895 injection of custom code in SDL for iPhone in order to implement our frontend
koda
parents:
diff changeset
   429
	view = data->view;
334016e8d895 injection of custom code in SDL for iPhone in order to implement our frontend
koda
parents:
diff changeset
   430
	
334016e8d895 injection of custom code in SDL for iPhone in order to implement our frontend
koda
parents:
diff changeset
   431
	if (NULL == view) {
334016e8d895 injection of custom code in SDL for iPhone in order to implement our frontend
koda
parents:
diff changeset
   432
		SDL_SetError("Window has no view");
334016e8d895 injection of custom code in SDL for iPhone in order to implement our frontend
koda
parents:
diff changeset
   433
		return 0;
334016e8d895 injection of custom code in SDL for iPhone in order to implement our frontend
koda
parents:
diff changeset
   434
	}
334016e8d895 injection of custom code in SDL for iPhone in order to implement our frontend
koda
parents:
diff changeset
   435
	else {
334016e8d895 injection of custom code in SDL for iPhone in order to implement our frontend
koda
parents:
diff changeset
   436
		return view.keyboardVisible;
334016e8d895 injection of custom code in SDL for iPhone in order to implement our frontend
koda
parents:
diff changeset
   437
	}
334016e8d895 injection of custom code in SDL for iPhone in order to implement our frontend
koda
parents:
diff changeset
   438
}
334016e8d895 injection of custom code in SDL for iPhone in order to implement our frontend
koda
parents:
diff changeset
   439
334016e8d895 injection of custom code in SDL for iPhone in order to implement our frontend
koda
parents:
diff changeset
   440
int SDL_iPhoneKeyboardToggle(SDL_WindowID windowID) {
334016e8d895 injection of custom code in SDL for iPhone in order to implement our frontend
koda
parents:
diff changeset
   441
	
334016e8d895 injection of custom code in SDL for iPhone in order to implement our frontend
koda
parents:
diff changeset
   442
	SDL_Window *window = SDL_GetWindowFromID(windowID);
334016e8d895 injection of custom code in SDL for iPhone in order to implement our frontend
koda
parents:
diff changeset
   443
	SDL_WindowData *data;
334016e8d895 injection of custom code in SDL for iPhone in order to implement our frontend
koda
parents:
diff changeset
   444
	SDL_uikitview *view;
334016e8d895 injection of custom code in SDL for iPhone in order to implement our frontend
koda
parents:
diff changeset
   445
	
334016e8d895 injection of custom code in SDL for iPhone in order to implement our frontend
koda
parents:
diff changeset
   446
	if (NULL == window) {
334016e8d895 injection of custom code in SDL for iPhone in order to implement our frontend
koda
parents:
diff changeset
   447
		SDL_SetError("Window does not exist");
334016e8d895 injection of custom code in SDL for iPhone in order to implement our frontend
koda
parents:
diff changeset
   448
		return -1;
334016e8d895 injection of custom code in SDL for iPhone in order to implement our frontend
koda
parents:
diff changeset
   449
	}	
334016e8d895 injection of custom code in SDL for iPhone in order to implement our frontend
koda
parents:
diff changeset
   450
	
334016e8d895 injection of custom code in SDL for iPhone in order to implement our frontend
koda
parents:
diff changeset
   451
	data = (SDL_WindowData *)window->driverdata;
334016e8d895 injection of custom code in SDL for iPhone in order to implement our frontend
koda
parents:
diff changeset
   452
	view = data->view;
334016e8d895 injection of custom code in SDL for iPhone in order to implement our frontend
koda
parents:
diff changeset
   453
	
334016e8d895 injection of custom code in SDL for iPhone in order to implement our frontend
koda
parents:
diff changeset
   454
	if (NULL == view) {
334016e8d895 injection of custom code in SDL for iPhone in order to implement our frontend
koda
parents:
diff changeset
   455
		SDL_SetError("Window has no view");
334016e8d895 injection of custom code in SDL for iPhone in order to implement our frontend
koda
parents:
diff changeset
   456
		return -1;
334016e8d895 injection of custom code in SDL for iPhone in order to implement our frontend
koda
parents:
diff changeset
   457
	}
334016e8d895 injection of custom code in SDL for iPhone in order to implement our frontend
koda
parents:
diff changeset
   458
	else {
334016e8d895 injection of custom code in SDL for iPhone in order to implement our frontend
koda
parents:
diff changeset
   459
		if (SDL_iPhoneKeyboardIsShown(windowID)) {
334016e8d895 injection of custom code in SDL for iPhone in order to implement our frontend
koda
parents:
diff changeset
   460
			SDL_iPhoneKeyboardHide(windowID);
334016e8d895 injection of custom code in SDL for iPhone in order to implement our frontend
koda
parents:
diff changeset
   461
		}
334016e8d895 injection of custom code in SDL for iPhone in order to implement our frontend
koda
parents:
diff changeset
   462
		else {
334016e8d895 injection of custom code in SDL for iPhone in order to implement our frontend
koda
parents:
diff changeset
   463
			SDL_iPhoneKeyboardShow(windowID);
334016e8d895 injection of custom code in SDL for iPhone in order to implement our frontend
koda
parents:
diff changeset
   464
		}
334016e8d895 injection of custom code in SDL for iPhone in order to implement our frontend
koda
parents:
diff changeset
   465
		return 0;
334016e8d895 injection of custom code in SDL for iPhone in order to implement our frontend
koda
parents:
diff changeset
   466
	}
334016e8d895 injection of custom code in SDL for iPhone in order to implement our frontend
koda
parents:
diff changeset
   467
}
334016e8d895 injection of custom code in SDL for iPhone in order to implement our frontend
koda
parents:
diff changeset
   468
334016e8d895 injection of custom code in SDL for iPhone in order to implement our frontend
koda
parents:
diff changeset
   469
#else
334016e8d895 injection of custom code in SDL for iPhone in order to implement our frontend
koda
parents:
diff changeset
   470
334016e8d895 injection of custom code in SDL for iPhone in order to implement our frontend
koda
parents:
diff changeset
   471
/* stubs, used if compiled without keyboard support */
334016e8d895 injection of custom code in SDL for iPhone in order to implement our frontend
koda
parents:
diff changeset
   472
334016e8d895 injection of custom code in SDL for iPhone in order to implement our frontend
koda
parents:
diff changeset
   473
int SDL_iPhoneKeyboardShow(SDL_WindowID windowID) {
334016e8d895 injection of custom code in SDL for iPhone in order to implement our frontend
koda
parents:
diff changeset
   474
	SDL_SetError("Not compiled with keyboard support");
334016e8d895 injection of custom code in SDL for iPhone in order to implement our frontend
koda
parents:
diff changeset
   475
	return -1;
334016e8d895 injection of custom code in SDL for iPhone in order to implement our frontend
koda
parents:
diff changeset
   476
}
334016e8d895 injection of custom code in SDL for iPhone in order to implement our frontend
koda
parents:
diff changeset
   477
334016e8d895 injection of custom code in SDL for iPhone in order to implement our frontend
koda
parents:
diff changeset
   478
int SDL_iPhoneKeyboardHide(SDL_WindowID windowID) {
334016e8d895 injection of custom code in SDL for iPhone in order to implement our frontend
koda
parents:
diff changeset
   479
	SDL_SetError("Not compiled with keyboard support");
334016e8d895 injection of custom code in SDL for iPhone in order to implement our frontend
koda
parents:
diff changeset
   480
	return -1;
334016e8d895 injection of custom code in SDL for iPhone in order to implement our frontend
koda
parents:
diff changeset
   481
}
334016e8d895 injection of custom code in SDL for iPhone in order to implement our frontend
koda
parents:
diff changeset
   482
334016e8d895 injection of custom code in SDL for iPhone in order to implement our frontend
koda
parents:
diff changeset
   483
SDL_bool SDL_iPhoneKeyboardIsShown(SDL_WindowID windowID) {
334016e8d895 injection of custom code in SDL for iPhone in order to implement our frontend
koda
parents:
diff changeset
   484
	return 0;
334016e8d895 injection of custom code in SDL for iPhone in order to implement our frontend
koda
parents:
diff changeset
   485
}
334016e8d895 injection of custom code in SDL for iPhone in order to implement our frontend
koda
parents:
diff changeset
   486
334016e8d895 injection of custom code in SDL for iPhone in order to implement our frontend
koda
parents:
diff changeset
   487
int SDL_iPhoneKeyboardToggle(SDL_WindowID windowID) {
334016e8d895 injection of custom code in SDL for iPhone in order to implement our frontend
koda
parents:
diff changeset
   488
	SDL_SetError("Not compiled with keyboard support");
334016e8d895 injection of custom code in SDL for iPhone in order to implement our frontend
koda
parents:
diff changeset
   489
	return -1;
334016e8d895 injection of custom code in SDL for iPhone in order to implement our frontend
koda
parents:
diff changeset
   490
}
334016e8d895 injection of custom code in SDL for iPhone in order to implement our frontend
koda
parents:
diff changeset
   491
334016e8d895 injection of custom code in SDL for iPhone in order to implement our frontend
koda
parents:
diff changeset
   492
334016e8d895 injection of custom code in SDL for iPhone in order to implement our frontend
koda
parents:
diff changeset
   493
#endif /* SDL_IPHONE_KEYBOARD */