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