cocoaTouch/SDLOverrides/SDL_uikitview.m
author koda
Wed, 17 Mar 2010 00:26:35 +0000
changeset 3006 da6023c2745b
parent 2805 36a8cebb91e8
permissions -rw-r--r--
restore compilation on simulator and device new architecture for implementing controls controls implmented with a joystick (partially done) lotsa code cleanup
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
2772
1965eba10be6 some code cleanup for the ifrontend
koda
parents: 2754
diff changeset
    23
#import "PascalImports.h"
1965eba10be6 some code cleanup for the ifrontend
koda
parents: 2754
diff changeset
    24
#import "CGPointUtils.h"
2688
174c94b8ea72 move all sdl source files in a proper directory
koda
parents:
diff changeset
    25
#import "SDL_uikitview.h"
174c94b8ea72 move all sdl source files in a proper directory
koda
parents:
diff changeset
    26
#import "SDL_uikitappdelegate.h"
174c94b8ea72 move all sdl source files in a proper directory
koda
parents:
diff changeset
    27
174c94b8ea72 move all sdl source files in a proper directory
koda
parents:
diff changeset
    28
#if SDL_IPHONE_KEYBOARD
174c94b8ea72 move all sdl source files in a proper directory
koda
parents:
diff changeset
    29
#import "SDL_keyboard_c.h"
174c94b8ea72 move all sdl source files in a proper directory
koda
parents:
diff changeset
    30
#import "keyinfotable.h"
174c94b8ea72 move all sdl source files in a proper directory
koda
parents:
diff changeset
    31
#import "SDL_uikitwindow.h"
174c94b8ea72 move all sdl source files in a proper directory
koda
parents:
diff changeset
    32
#endif
174c94b8ea72 move all sdl source files in a proper directory
koda
parents:
diff changeset
    33
174c94b8ea72 move all sdl source files in a proper directory
koda
parents:
diff changeset
    34
@implementation SDL_uikitview
174c94b8ea72 move all sdl source files in a proper directory
koda
parents:
diff changeset
    35
2689
dfda97c153a4 iphone overlay button animation
koda
parents: 2688
diff changeset
    36
// they have to be global variables to allow showControls() to use them
2805
36a8cebb91e8 new menupage ingame for common actions
koda
parents: 2772
diff changeset
    37
//UIButton *attackButton, *menuButton;
36a8cebb91e8 new menupage ingame for common actions
koda
parents: 2772
diff changeset
    38
UIView *menuView;
2714
c85ffe57d971 update iphone frontend to the new (silly) sdl api, code cleanups for other sections
koda
parents: 2705
diff changeset
    39
-(void) dealloc {
2688
174c94b8ea72 move all sdl source files in a proper directory
koda
parents:
diff changeset
    40
#if SDL_IPHONE_KEYBOARD
174c94b8ea72 move all sdl source files in a proper directory
koda
parents:
diff changeset
    41
	SDL_DelKeyboard(0);
174c94b8ea72 move all sdl source files in a proper directory
koda
parents:
diff changeset
    42
	[textField release];
174c94b8ea72 move all sdl source files in a proper directory
koda
parents:
diff changeset
    43
#endif
174c94b8ea72 move all sdl source files in a proper directory
koda
parents:
diff changeset
    44
	[super dealloc];
174c94b8ea72 move all sdl source files in a proper directory
koda
parents:
diff changeset
    45
}
174c94b8ea72 move all sdl source files in a proper directory
koda
parents:
diff changeset
    46
3006
da6023c2745b restore compilation on simulator and device
koda
parents: 2805
diff changeset
    47
-(id) initWithFrame:(CGRect)frame {
2714
c85ffe57d971 update iphone frontend to the new (silly) sdl api, code cleanups for other sections
koda
parents: 2705
diff changeset
    48
	self = [super initWithFrame:frame];
2688
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
#if SDL_IPHONE_KEYBOARD
174c94b8ea72 move all sdl source files in a proper directory
koda
parents:
diff changeset
    51
	[self initializeKeyboard];
174c94b8ea72 move all sdl source files in a proper directory
koda
parents:
diff changeset
    52
#endif	
174c94b8ea72 move all sdl source files in a proper directory
koda
parents:
diff changeset
    53
174c94b8ea72 move all sdl source files in a proper directory
koda
parents:
diff changeset
    54
	int i;
174c94b8ea72 move all sdl source files in a proper directory
koda
parents:
diff changeset
    55
	for (i=0; i<MAX_SIMULTANEOUS_TOUCHES; i++) {
174c94b8ea72 move all sdl source files in a proper directory
koda
parents:
diff changeset
    56
        mice[i].id = i;
174c94b8ea72 move all sdl source files in a proper directory
koda
parents:
diff changeset
    57
		mice[i].driverdata = NULL;
174c94b8ea72 move all sdl source files in a proper directory
koda
parents:
diff changeset
    58
		SDL_AddMouse(&mice[i], "Mouse", 0, 0, 1);
174c94b8ea72 move all sdl source files in a proper directory
koda
parents:
diff changeset
    59
	}
174c94b8ea72 move all sdl source files in a proper directory
koda
parents:
diff changeset
    60
2724
601158aaa201 redo LANDSCAPE MODE in a saner way with lots of fps
koda
parents: 2714
diff changeset
    61
	self.multipleTouchEnabled = YES;
2772
1965eba10be6 some code cleanup for the ifrontend
koda
parents: 2754
diff changeset
    62
	self.exclusiveTouch = YES;
2805
36a8cebb91e8 new menupage ingame for common actions
koda
parents: 2772
diff changeset
    63
36a8cebb91e8 new menupage ingame for common actions
koda
parents: 2772
diff changeset
    64
//(0,0) is the lower left corner
36a8cebb91e8 new menupage ingame for common actions
koda
parents: 2772
diff changeset
    65
//x:[0-320]
36a8cebb91e8 new menupage ingame for common actions
koda
parents: 2772
diff changeset
    66
//y:[0-480]
3006
da6023c2745b restore compilation on simulator and device
koda
parents: 2805
diff changeset
    67
    
da6023c2745b restore compilation on simulator and device
koda
parents: 2805
diff changeset
    68
    // TO BE MOVED somewhere
da6023c2745b restore compilation on simulator and device
koda
parents: 2805
diff changeset
    69
    /*
da6023c2745b restore compilation on simulator and device
koda
parents: 2805
diff changeset
    70
	UIButton *menuCorner = [[UIButton alloc] initWithFrame:CGRectMake(256, 416, 64, 64)];
da6023c2745b restore compilation on simulator and device
koda
parents: 2805
diff changeset
    71
	[menuCorner addTarget:[self superclass] action:@selector(showMenu) forControlEvents:UIControlEventTouchDown];
da6023c2745b restore compilation on simulator and device
koda
parents: 2805
diff changeset
    72
	[menuCorner setBackgroundImage:[UIImage imageNamed:@"menuCorner.png"] forState:UIControlStateNormal];
da6023c2745b restore compilation on simulator and device
koda
parents: 2805
diff changeset
    73
	[self insertSubview:menuCorner atIndex:0];
da6023c2745b restore compilation on simulator and device
koda
parents: 2805
diff changeset
    74
	[menuCorner release];
2805
36a8cebb91e8 new menupage ingame for common actions
koda
parents: 2772
diff changeset
    75
	
36a8cebb91e8 new menupage ingame for common actions
koda
parents: 2772
diff changeset
    76
	menuView = [[UIView alloc] initWithFrame:CGRectMake(320, 480, 150, 100)];
36a8cebb91e8 new menupage ingame for common actions
koda
parents: 2772
diff changeset
    77
	menuView.backgroundColor = [UIColor lightGrayColor];
36a8cebb91e8 new menupage ingame for common actions
koda
parents: 2772
diff changeset
    78
	[self insertSubview:menuView atIndex:1];
3006
da6023c2745b restore compilation on simulator and device
koda
parents: 2805
diff changeset
    79
    */
2688
174c94b8ea72 move all sdl source files in a proper directory
koda
parents:
diff changeset
    80
	return self;
174c94b8ea72 move all sdl source files in a proper directory
koda
parents:
diff changeset
    81
}
174c94b8ea72 move all sdl source files in a proper directory
koda
parents:
diff changeset
    82
3006
da6023c2745b restore compilation on simulator and device
koda
parents: 2805
diff changeset
    83
/*
da6023c2745b restore compilation on simulator and device
koda
parents: 2805
diff changeset
    84
 TO BE MOVED IN overlayViewController ASAP
2805
36a8cebb91e8 new menupage ingame for common actions
koda
parents: 2772
diff changeset
    85
+(void) showMenu {
36a8cebb91e8 new menupage ingame for common actions
koda
parents: 2772
diff changeset
    86
	HW_pause();
36a8cebb91e8 new menupage ingame for common actions
koda
parents: 2772
diff changeset
    87
	
36a8cebb91e8 new menupage ingame for common actions
koda
parents: 2772
diff changeset
    88
	[UIView beginAnimations:@"show menu" context:NULL];
36a8cebb91e8 new menupage ingame for common actions
koda
parents: 2772
diff changeset
    89
	[UIView setAnimationDuration:1];
36a8cebb91e8 new menupage ingame for common actions
koda
parents: 2772
diff changeset
    90
	
36a8cebb91e8 new menupage ingame for common actions
koda
parents: 2772
diff changeset
    91
	menuView.frame = CGRectMake(170, 380, 150, 100);
36a8cebb91e8 new menupage ingame for common actions
koda
parents: 2772
diff changeset
    92
	
36a8cebb91e8 new menupage ingame for common actions
koda
parents: 2772
diff changeset
    93
	[UIView commitAnimations];
36a8cebb91e8 new menupage ingame for common actions
koda
parents: 2772
diff changeset
    94
}
36a8cebb91e8 new menupage ingame for common actions
koda
parents: 2772
diff changeset
    95
36a8cebb91e8 new menupage ingame for common actions
koda
parents: 2772
diff changeset
    96
+(void) hideMenu {
36a8cebb91e8 new menupage ingame for common actions
koda
parents: 2772
diff changeset
    97
	[UIView beginAnimations:@"hide menu" context:NULL];
36a8cebb91e8 new menupage ingame for common actions
koda
parents: 2772
diff changeset
    98
	[UIView setAnimationDuration:1];
36a8cebb91e8 new menupage ingame for common actions
koda
parents: 2772
diff changeset
    99
	
36a8cebb91e8 new menupage ingame for common actions
koda
parents: 2772
diff changeset
   100
	menuView.frame = CGRectMake(480, -70, 150, 100);
36a8cebb91e8 new menupage ingame for common actions
koda
parents: 2772
diff changeset
   101
	
36a8cebb91e8 new menupage ingame for common actions
koda
parents: 2772
diff changeset
   102
	[UIView commitAnimations];
36a8cebb91e8 new menupage ingame for common actions
koda
parents: 2772
diff changeset
   103
	
36a8cebb91e8 new menupage ingame for common actions
koda
parents: 2772
diff changeset
   104
	HW_pause();
36a8cebb91e8 new menupage ingame for common actions
koda
parents: 2772
diff changeset
   105
}
36a8cebb91e8 new menupage ingame for common actions
koda
parents: 2772
diff changeset
   106
3006
da6023c2745b restore compilation on simulator and device
koda
parents: 2805
diff changeset
   107
*/
2805
36a8cebb91e8 new menupage ingame for common actions
koda
parents: 2772
diff changeset
   108
2688
174c94b8ea72 move all sdl source files in a proper directory
koda
parents:
diff changeset
   109
#pragma mark -
2690
8e83c7e31720 move mixed functions in PascalExports
koda
parents: 2689
diff changeset
   110
#pragma mark Exported functions for FreePascal
8e83c7e31720 move mixed functions in PascalExports
koda
parents: 2689
diff changeset
   111
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
   112
	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
   113
	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
   114
	return [documentsDirectory UTF8String];
2690
8e83c7e31720 move mixed functions in PascalExports
koda
parents: 2689
diff changeset
   115
}
8e83c7e31720 move mixed functions in PascalExports
koda
parents: 2689
diff changeset
   116
8e83c7e31720 move mixed functions in PascalExports
koda
parents: 2689
diff changeset
   117
void IPH_showControls (void) {
2689
dfda97c153a4 iphone overlay button animation
koda
parents: 2688
diff changeset
   118
	NSLog(@"Showing controls");
2805
36a8cebb91e8 new menupage ingame for common actions
koda
parents: 2772
diff changeset
   119
}
36a8cebb91e8 new menupage ingame for common actions
koda
parents: 2772
diff changeset
   120
2688
174c94b8ea72 move all sdl source files in a proper directory
koda
parents:
diff changeset
   121
#pragma mark -
174c94b8ea72 move all sdl source files in a proper directory
koda
parents:
diff changeset
   122
#pragma mark Custom SDL_UIView input handling
3006
da6023c2745b restore compilation on simulator and device
koda
parents: 2805
diff changeset
   123
#define kMinimumPinchDelta      50
2725
89908847b155 input handling reworked, still a lot of bugs in mouse movement
koda
parents: 2724
diff changeset
   124
#define kMinimumGestureLength	10
3006
da6023c2745b restore compilation on simulator and device
koda
parents: 2805
diff changeset
   125
#define kMaximumVariance        3
2688
174c94b8ea72 move all sdl source files in a proper directory
koda
parents:
diff changeset
   126
174c94b8ea72 move all sdl source files in a proper directory
koda
parents:
diff changeset
   127
// we override default touch input to implement our own gestures
3006
da6023c2745b restore compilation on simulator and device
koda
parents: 2805
diff changeset
   128
-(void) touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
2772
1965eba10be6 some code cleanup for the ifrontend
koda
parents: 2754
diff changeset
   129
	NSArray *twoTouches;
2688
174c94b8ea72 move all sdl source files in a proper directory
koda
parents:
diff changeset
   130
	UITouch *touch = [touches anyObject];
2725
89908847b155 input handling reworked, still a lot of bugs in mouse movement
koda
parents: 2724
diff changeset
   131
	
89908847b155 input handling reworked, still a lot of bugs in mouse movement
koda
parents: 2724
diff changeset
   132
	switch ([touches count]) {
89908847b155 input handling reworked, still a lot of bugs in mouse movement
koda
parents: 2724
diff changeset
   133
		case 1:
89908847b155 input handling reworked, still a lot of bugs in mouse movement
koda
parents: 2724
diff changeset
   134
			gestureStartPoint = [touch locationInView:self];
89908847b155 input handling reworked, still a lot of bugs in mouse movement
koda
parents: 2724
diff changeset
   135
			initialDistanceForPinching = 0;
89908847b155 input handling reworked, still a lot of bugs in mouse movement
koda
parents: 2724
diff changeset
   136
			switch ([touch tapCount]) {
89908847b155 input handling reworked, still a lot of bugs in mouse movement
koda
parents: 2724
diff changeset
   137
				case 1:
2772
1965eba10be6 some code cleanup for the ifrontend
koda
parents: 2754
diff changeset
   138
					NSLog(@"X:%d Y:%d", (int)gestureStartPoint.x, (int)gestureStartPoint.y );
2734
fb9ad1587054 smaller improvements in mouse handling
koda
parents: 2725
diff changeset
   139
					SDL_WarpMouseInWindow([SDLUIKitDelegate sharedAppDelegate].window, 
fb9ad1587054 smaller improvements in mouse handling
koda
parents: 2725
diff changeset
   140
							      (int)gestureStartPoint.y, 320 - (int)gestureStartPoint.x);
2725
89908847b155 input handling reworked, still a lot of bugs in mouse movement
koda
parents: 2724
diff changeset
   141
					HW_click();
89908847b155 input handling reworked, still a lot of bugs in mouse movement
koda
parents: 2724
diff changeset
   142
					break;
89908847b155 input handling reworked, still a lot of bugs in mouse movement
koda
parents: 2724
diff changeset
   143
				case 2:
89908847b155 input handling reworked, still a lot of bugs in mouse movement
koda
parents: 2724
diff changeset
   144
					HW_ammoMenu();
89908847b155 input handling reworked, still a lot of bugs in mouse movement
koda
parents: 2724
diff changeset
   145
					break;
89908847b155 input handling reworked, still a lot of bugs in mouse movement
koda
parents: 2724
diff changeset
   146
				default:
89908847b155 input handling reworked, still a lot of bugs in mouse movement
koda
parents: 2724
diff changeset
   147
					break;
89908847b155 input handling reworked, still a lot of bugs in mouse movement
koda
parents: 2724
diff changeset
   148
			}
89908847b155 input handling reworked, still a lot of bugs in mouse movement
koda
parents: 2724
diff changeset
   149
			break;
89908847b155 input handling reworked, still a lot of bugs in mouse movement
koda
parents: 2724
diff changeset
   150
		case 2:
89908847b155 input handling reworked, still a lot of bugs in mouse movement
koda
parents: 2724
diff changeset
   151
			if (2 == [touch tapCount]) {
89908847b155 input handling reworked, still a lot of bugs in mouse movement
koda
parents: 2724
diff changeset
   152
				HW_zoomReset();
89908847b155 input handling reworked, still a lot of bugs in mouse movement
koda
parents: 2724
diff changeset
   153
			}
89908847b155 input handling reworked, still a lot of bugs in mouse movement
koda
parents: 2724
diff changeset
   154
			
89908847b155 input handling reworked, still a lot of bugs in mouse movement
koda
parents: 2724
diff changeset
   155
			// pinching
2772
1965eba10be6 some code cleanup for the ifrontend
koda
parents: 2754
diff changeset
   156
			twoTouches = [touches allObjects];
2725
89908847b155 input handling reworked, still a lot of bugs in mouse movement
koda
parents: 2724
diff changeset
   157
			UITouch *first = [twoTouches objectAtIndex:0];
89908847b155 input handling reworked, still a lot of bugs in mouse movement
koda
parents: 2724
diff changeset
   158
			UITouch *second = [twoTouches objectAtIndex:1];
89908847b155 input handling reworked, still a lot of bugs in mouse movement
koda
parents: 2724
diff changeset
   159
			initialDistanceForPinching = distanceBetweenPoints([first locationInView:self], [second locationInView:self]);
89908847b155 input handling reworked, still a lot of bugs in mouse movement
koda
parents: 2724
diff changeset
   160
			break;
89908847b155 input handling reworked, still a lot of bugs in mouse movement
koda
parents: 2724
diff changeset
   161
		default:
89908847b155 input handling reworked, still a lot of bugs in mouse movement
koda
parents: 2724
diff changeset
   162
			break;
2688
174c94b8ea72 move all sdl source files in a proper directory
koda
parents:
diff changeset
   163
	}
2725
89908847b155 input handling reworked, still a lot of bugs in mouse movement
koda
parents: 2724
diff changeset
   164
2688
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
3006
da6023c2745b restore compilation on simulator and device
koda
parents: 2805
diff changeset
   167
-(void) touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {
2725
89908847b155 input handling reworked, still a lot of bugs in mouse movement
koda
parents: 2724
diff changeset
   168
	initialDistanceForPinching = 0;
2772
1965eba10be6 some code cleanup for the ifrontend
koda
parents: 2754
diff changeset
   169
	gestureStartPoint.x = 0;
1965eba10be6 some code cleanup for the ifrontend
koda
parents: 2754
diff changeset
   170
	gestureStartPoint.y = 0;
2688
174c94b8ea72 move all sdl source files in a proper directory
koda
parents:
diff changeset
   171
	HW_allKeysUp();
174c94b8ea72 move all sdl source files in a proper directory
koda
parents:
diff changeset
   172
}
174c94b8ea72 move all sdl source files in a proper directory
koda
parents:
diff changeset
   173
3006
da6023c2745b restore compilation on simulator and device
koda
parents: 2805
diff changeset
   174
-(void) touchesCancelled:(NSSet *)touches withEvent:(UIEvent *)event {
2772
1965eba10be6 some code cleanup for the ifrontend
koda
parents: 2754
diff changeset
   175
	// this can happen if the user puts more than 5 touches on the screen at once, or perhaps in other circumstances.
1965eba10be6 some code cleanup for the ifrontend
koda
parents: 2754
diff changeset
   176
	// Usually (it seems) all active touches are canceled.
2725
89908847b155 input handling reworked, still a lot of bugs in mouse movement
koda
parents: 2724
diff changeset
   177
	[self touchesEnded:touches withEvent:event];
2688
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
3006
da6023c2745b restore compilation on simulator and device
koda
parents: 2805
diff changeset
   180
-(void) touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {
2725
89908847b155 input handling reworked, still a lot of bugs in mouse movement
koda
parents: 2724
diff changeset
   181
	NSArray *twoTouches;
89908847b155 input handling reworked, still a lot of bugs in mouse movement
koda
parents: 2724
diff changeset
   182
	CGPoint currentPosition;
2688
174c94b8ea72 move all sdl source files in a proper directory
koda
parents:
diff changeset
   183
	UITouch *touch = [touches anyObject];
2725
89908847b155 input handling reworked, still a lot of bugs in mouse movement
koda
parents: 2724
diff changeset
   184
89908847b155 input handling reworked, still a lot of bugs in mouse movement
koda
parents: 2724
diff changeset
   185
	switch ([touches count]) {
89908847b155 input handling reworked, still a lot of bugs in mouse movement
koda
parents: 2724
diff changeset
   186
		case 1:
89908847b155 input handling reworked, still a lot of bugs in mouse movement
koda
parents: 2724
diff changeset
   187
			currentPosition = [touch locationInView:self];
2734
fb9ad1587054 smaller improvements in mouse handling
koda
parents: 2725
diff changeset
   188
			// panning
fb9ad1587054 smaller improvements in mouse handling
koda
parents: 2725
diff changeset
   189
			SDL_WarpMouseInWindow([SDLUIKitDelegate sharedAppDelegate].window, 
fb9ad1587054 smaller improvements in mouse handling
koda
parents: 2725
diff changeset
   190
							(int)gestureStartPoint.y, 320 - (int)gestureStartPoint.x);
2725
89908847b155 input handling reworked, still a lot of bugs in mouse movement
koda
parents: 2724
diff changeset
   191
			// remember that we have x and y inverted
2734
fb9ad1587054 smaller improvements in mouse handling
koda
parents: 2725
diff changeset
   192
			/* temporarily disabling hog movements for camera panning testing
2772
1965eba10be6 some code cleanup for the ifrontend
koda
parents: 2754
diff changeset
   193
			CGFloat vertDiff = gestureStartPoint.x - currentPosition.x;
2725
89908847b155 input handling reworked, still a lot of bugs in mouse movement
koda
parents: 2724
diff changeset
   194
			CGFloat horizDiff = gestureStartPoint.y - currentPosition.y;
89908847b155 input handling reworked, still a lot of bugs in mouse movement
koda
parents: 2724
diff changeset
   195
			CGFloat deltaX = fabsf(vertDiff);
89908847b155 input handling reworked, still a lot of bugs in mouse movement
koda
parents: 2724
diff changeset
   196
			CGFloat deltaY = fabsf(horizDiff);
89908847b155 input handling reworked, still a lot of bugs in mouse movement
koda
parents: 2724
diff changeset
   197
			
89908847b155 input handling reworked, still a lot of bugs in mouse movement
koda
parents: 2724
diff changeset
   198
			if (deltaY >= kMinimumGestureLength && deltaX <= kMaximumVariance) {
89908847b155 input handling reworked, still a lot of bugs in mouse movement
koda
parents: 2724
diff changeset
   199
				NSLog(@"Horizontal swipe detected, begX:%f curX:%f", gestureStartPoint.x, currentPosition.x);
89908847b155 input handling reworked, still a lot of bugs in mouse movement
koda
parents: 2724
diff changeset
   200
				if (horizDiff > 0) HW_walkLeft();
89908847b155 input handling reworked, still a lot of bugs in mouse movement
koda
parents: 2724
diff changeset
   201
				else HW_walkRight();
89908847b155 input handling reworked, still a lot of bugs in mouse movement
koda
parents: 2724
diff changeset
   202
			} else if (deltaX >= kMinimumGestureLength && deltaY <= kMaximumVariance){
89908847b155 input handling reworked, still a lot of bugs in mouse movement
koda
parents: 2724
diff changeset
   203
				NSLog(@"Vertical swipe detected, begY:%f curY:%f", gestureStartPoint.y, currentPosition.y);
89908847b155 input handling reworked, still a lot of bugs in mouse movement
koda
parents: 2724
diff changeset
   204
				if (vertDiff < 0) HW_aimUp();
89908847b155 input handling reworked, still a lot of bugs in mouse movement
koda
parents: 2724
diff changeset
   205
				else HW_aimDown();
89908847b155 input handling reworked, still a lot of bugs in mouse movement
koda
parents: 2724
diff changeset
   206
			}
2734
fb9ad1587054 smaller improvements in mouse handling
koda
parents: 2725
diff changeset
   207
			*/
2725
89908847b155 input handling reworked, still a lot of bugs in mouse movement
koda
parents: 2724
diff changeset
   208
			break;
89908847b155 input handling reworked, still a lot of bugs in mouse movement
koda
parents: 2724
diff changeset
   209
		case 2:
89908847b155 input handling reworked, still a lot of bugs in mouse movement
koda
parents: 2724
diff changeset
   210
			twoTouches = [touches allObjects];
89908847b155 input handling reworked, still a lot of bugs in mouse movement
koda
parents: 2724
diff changeset
   211
			UITouch *first = [twoTouches objectAtIndex:0];
89908847b155 input handling reworked, still a lot of bugs in mouse movement
koda
parents: 2724
diff changeset
   212
			UITouch *second = [twoTouches objectAtIndex:1];
89908847b155 input handling reworked, still a lot of bugs in mouse movement
koda
parents: 2724
diff changeset
   213
			CGFloat currentDistanceOfPinching = distanceBetweenPoints([first locationInView:self], [second locationInView:self]);
89908847b155 input handling reworked, still a lot of bugs in mouse movement
koda
parents: 2724
diff changeset
   214
			
89908847b155 input handling reworked, still a lot of bugs in mouse movement
koda
parents: 2724
diff changeset
   215
			if (0 == initialDistanceForPinching) 
89908847b155 input handling reworked, still a lot of bugs in mouse movement
koda
parents: 2724
diff changeset
   216
				initialDistanceForPinching = currentDistanceOfPinching;
89908847b155 input handling reworked, still a lot of bugs in mouse movement
koda
parents: 2724
diff changeset
   217
2738
bfccb2ec4334 new graphics from Tiy and frontend is loaded in landscape mode
koda
parents: 2734
diff changeset
   218
			if (currentDistanceOfPinching < initialDistanceForPinching + kMinimumPinchDelta)
2725
89908847b155 input handling reworked, still a lot of bugs in mouse movement
koda
parents: 2724
diff changeset
   219
				HW_zoomOut();
2738
bfccb2ec4334 new graphics from Tiy and frontend is loaded in landscape mode
koda
parents: 2734
diff changeset
   220
			else if (currentDistanceOfPinching > initialDistanceForPinching + kMinimumPinchDelta)
2725
89908847b155 input handling reworked, still a lot of bugs in mouse movement
koda
parents: 2724
diff changeset
   221
				HW_zoomIn();
2738
bfccb2ec4334 new graphics from Tiy and frontend is loaded in landscape mode
koda
parents: 2734
diff changeset
   222
2725
89908847b155 input handling reworked, still a lot of bugs in mouse movement
koda
parents: 2724
diff changeset
   223
			currentDistanceOfPinching = initialDistanceForPinching;
89908847b155 input handling reworked, still a lot of bugs in mouse movement
koda
parents: 2724
diff changeset
   224
			break;
89908847b155 input handling reworked, still a lot of bugs in mouse movement
koda
parents: 2724
diff changeset
   225
		default:
89908847b155 input handling reworked, still a lot of bugs in mouse movement
koda
parents: 2724
diff changeset
   226
			break;
2688
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
}
174c94b8ea72 move all sdl source files in a proper directory
koda
parents:
diff changeset
   229
2772
1965eba10be6 some code cleanup for the ifrontend
koda
parents: 2754
diff changeset
   230
/*
2688
174c94b8ea72 move all sdl source files in a proper directory
koda
parents:
diff changeset
   231
#pragma mark -
2772
1965eba10be6 some code cleanup for the ifrontend
koda
parents: 2754
diff changeset
   232
#pragma mark Keyboard related functionality
2688
174c94b8ea72 move all sdl source files in a proper directory
koda
parents:
diff changeset
   233
#if SDL_IPHONE_KEYBOARD
2772
1965eba10be6 some code cleanup for the ifrontend
koda
parents: 2754
diff changeset
   234
// Is the iPhone virtual keyboard visible onscreen? 
2688
174c94b8ea72 move all sdl source files in a proper directory
koda
parents:
diff changeset
   235
- (BOOL)keyboardVisible {
174c94b8ea72 move all sdl source files in a proper directory
koda
parents:
diff changeset
   236
	return keyboardVisible;
174c94b8ea72 move all sdl source files in a proper directory
koda
parents:
diff changeset
   237
}
174c94b8ea72 move all sdl source files in a proper directory
koda
parents:
diff changeset
   238
2772
1965eba10be6 some code cleanup for the ifrontend
koda
parents: 2754
diff changeset
   239
// Set ourselves up as a UITextFieldDelegate
2688
174c94b8ea72 move all sdl source files in a proper directory
koda
parents:
diff changeset
   240
- (void)initializeKeyboard {
174c94b8ea72 move all sdl source files in a proper directory
koda
parents:
diff changeset
   241
		
174c94b8ea72 move all sdl source files in a proper directory
koda
parents:
diff changeset
   242
	textField = [[[UITextField alloc] initWithFrame: CGRectZero] autorelease];
174c94b8ea72 move all sdl source files in a proper directory
koda
parents:
diff changeset
   243
	textField.delegate = self;
2772
1965eba10be6 some code cleanup for the ifrontend
koda
parents: 2754
diff changeset
   244
	// placeholder so there is something to delete!
2688
174c94b8ea72 move all sdl source files in a proper directory
koda
parents:
diff changeset
   245
	textField.text = @" ";	
174c94b8ea72 move all sdl source files in a proper directory
koda
parents:
diff changeset
   246
	
2772
1965eba10be6 some code cleanup for the ifrontend
koda
parents: 2754
diff changeset
   247
	// set UITextInputTrait properties, mostly to defaults
2688
174c94b8ea72 move all sdl source files in a proper directory
koda
parents:
diff changeset
   248
	textField.autocapitalizationType = UITextAutocapitalizationTypeNone;
174c94b8ea72 move all sdl source files in a proper directory
koda
parents:
diff changeset
   249
	textField.autocorrectionType = UITextAutocorrectionTypeNo;
174c94b8ea72 move all sdl source files in a proper directory
koda
parents:
diff changeset
   250
	textField.enablesReturnKeyAutomatically = NO;
174c94b8ea72 move all sdl source files in a proper directory
koda
parents:
diff changeset
   251
	textField.keyboardAppearance = UIKeyboardAppearanceDefault;
174c94b8ea72 move all sdl source files in a proper directory
koda
parents:
diff changeset
   252
	textField.keyboardType = UIKeyboardTypeDefault;
174c94b8ea72 move all sdl source files in a proper directory
koda
parents:
diff changeset
   253
	textField.returnKeyType = UIReturnKeyDefault;
174c94b8ea72 move all sdl source files in a proper directory
koda
parents:
diff changeset
   254
	textField.secureTextEntry = NO;	
174c94b8ea72 move all sdl source files in a proper directory
koda
parents:
diff changeset
   255
	
174c94b8ea72 move all sdl source files in a proper directory
koda
parents:
diff changeset
   256
	textField.hidden = YES;
174c94b8ea72 move all sdl source files in a proper directory
koda
parents:
diff changeset
   257
	keyboardVisible = NO;
2772
1965eba10be6 some code cleanup for the ifrontend
koda
parents: 2754
diff changeset
   258
	// add the UITextField (hidden) to our view
2688
174c94b8ea72 move all sdl source files in a proper directory
koda
parents:
diff changeset
   259
	[self addSubview: textField];
174c94b8ea72 move all sdl source files in a proper directory
koda
parents:
diff changeset
   260
	
2772
1965eba10be6 some code cleanup for the ifrontend
koda
parents: 2754
diff changeset
   261
	// create our SDL_Keyboard
2688
174c94b8ea72 move all sdl source files in a proper directory
koda
parents:
diff changeset
   262
	SDL_Keyboard keyboard;
174c94b8ea72 move all sdl source files in a proper directory
koda
parents:
diff changeset
   263
	SDL_zero(keyboard);
174c94b8ea72 move all sdl source files in a proper directory
koda
parents:
diff changeset
   264
	SDL_AddKeyboard(&keyboard, 0);
174c94b8ea72 move all sdl source files in a proper directory
koda
parents:
diff changeset
   265
	SDLKey keymap[SDL_NUM_SCANCODES];
174c94b8ea72 move all sdl source files in a proper directory
koda
parents:
diff changeset
   266
	SDL_GetDefaultKeymap(keymap);
174c94b8ea72 move all sdl source files in a proper directory
koda
parents:
diff changeset
   267
	SDL_SetKeymap(0, 0, keymap, SDL_NUM_SCANCODES);
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
2772
1965eba10be6 some code cleanup for the ifrontend
koda
parents: 2754
diff changeset
   271
// reveal onscreen virtual keyboard
2688
174c94b8ea72 move all sdl source files in a proper directory
koda
parents:
diff changeset
   272
- (void)showKeyboard {
174c94b8ea72 move all sdl source files in a proper directory
koda
parents:
diff changeset
   273
	keyboardVisible = YES;
174c94b8ea72 move all sdl source files in a proper directory
koda
parents:
diff changeset
   274
	[textField becomeFirstResponder];
174c94b8ea72 move all sdl source files in a proper directory
koda
parents:
diff changeset
   275
}
174c94b8ea72 move all sdl source files in a proper directory
koda
parents:
diff changeset
   276
2772
1965eba10be6 some code cleanup for the ifrontend
koda
parents: 2754
diff changeset
   277
// hide onscreen virtual keyboard
2688
174c94b8ea72 move all sdl source files in a proper directory
koda
parents:
diff changeset
   278
- (void)hideKeyboard {
174c94b8ea72 move all sdl source files in a proper directory
koda
parents:
diff changeset
   279
	keyboardVisible = NO;
174c94b8ea72 move all sdl source files in a proper directory
koda
parents:
diff changeset
   280
	[textField resignFirstResponder];
174c94b8ea72 move all sdl source files in a proper directory
koda
parents:
diff changeset
   281
}
174c94b8ea72 move all sdl source files in a proper directory
koda
parents:
diff changeset
   282
2772
1965eba10be6 some code cleanup for the ifrontend
koda
parents: 2754
diff changeset
   283
// UITextFieldDelegate method.  Invoked when user types something.
2688
174c94b8ea72 move all sdl source files in a proper directory
koda
parents:
diff changeset
   284
- (BOOL)textField:(UITextField *)_textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string {
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
	if ([string length] == 0) {
2772
1965eba10be6 some code cleanup for the ifrontend
koda
parents: 2754
diff changeset
   287
		// it wants to replace text with nothing, ie a delete
2688
174c94b8ea72 move all sdl source files in a proper directory
koda
parents:
diff changeset
   288
		SDL_SendKeyboardKey( 0, SDL_PRESSED, SDL_SCANCODE_DELETE);
174c94b8ea72 move all sdl source files in a proper directory
koda
parents:
diff changeset
   289
		SDL_SendKeyboardKey( 0, SDL_RELEASED, SDL_SCANCODE_DELETE);
174c94b8ea72 move all sdl source files in a proper directory
koda
parents:
diff changeset
   290
	}
174c94b8ea72 move all sdl source files in a proper directory
koda
parents:
diff changeset
   291
	else {
2772
1965eba10be6 some code cleanup for the ifrontend
koda
parents: 2754
diff changeset
   292
		// go through all the characters in the string we've been sent and convert them to key presses
2688
174c94b8ea72 move all sdl source files in a proper directory
koda
parents:
diff changeset
   293
		int i;
174c94b8ea72 move all sdl source files in a proper directory
koda
parents:
diff changeset
   294
		for (i=0; i<[string length]; i++) {
174c94b8ea72 move all sdl source files in a proper directory
koda
parents:
diff changeset
   295
			
174c94b8ea72 move all sdl source files in a proper directory
koda
parents:
diff changeset
   296
			unichar c = [string characterAtIndex: i];
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
			Uint16 mod = 0;
174c94b8ea72 move all sdl source files in a proper directory
koda
parents:
diff changeset
   299
			SDL_scancode code;
174c94b8ea72 move all sdl source files in a proper directory
koda
parents:
diff changeset
   300
			
174c94b8ea72 move all sdl source files in a proper directory
koda
parents:
diff changeset
   301
			if (c < 127) {
2772
1965eba10be6 some code cleanup for the ifrontend
koda
parents: 2754
diff changeset
   302
				// figure out the SDL_scancode and SDL_keymod for this unichar
2688
174c94b8ea72 move all sdl source files in a proper directory
koda
parents:
diff changeset
   303
				code = unicharToUIKeyInfoTable[c].code;
174c94b8ea72 move all sdl source files in a proper directory
koda
parents:
diff changeset
   304
				mod  = unicharToUIKeyInfoTable[c].mod;
174c94b8ea72 move all sdl source files in a proper directory
koda
parents:
diff changeset
   305
			}
174c94b8ea72 move all sdl source files in a proper directory
koda
parents:
diff changeset
   306
			else {
2772
1965eba10be6 some code cleanup for the ifrontend
koda
parents: 2754
diff changeset
   307
				// we only deal with ASCII right now
2688
174c94b8ea72 move all sdl source files in a proper directory
koda
parents:
diff changeset
   308
				code = SDL_SCANCODE_UNKNOWN;
174c94b8ea72 move all sdl source files in a proper directory
koda
parents:
diff changeset
   309
				mod = 0;
174c94b8ea72 move all sdl source files in a proper directory
koda
parents:
diff changeset
   310
			}
174c94b8ea72 move all sdl source files in a proper directory
koda
parents:
diff changeset
   311
			
174c94b8ea72 move all sdl source files in a proper directory
koda
parents:
diff changeset
   312
			if (mod & KMOD_SHIFT) {
2772
1965eba10be6 some code cleanup for the ifrontend
koda
parents: 2754
diff changeset
   313
				// If character uses shift, press shift down
2688
174c94b8ea72 move all sdl source files in a proper directory
koda
parents:
diff changeset
   314
				SDL_SendKeyboardKey( 0, SDL_PRESSED, SDL_SCANCODE_LSHIFT);
174c94b8ea72 move all sdl source files in a proper directory
koda
parents:
diff changeset
   315
			}
2772
1965eba10be6 some code cleanup for the ifrontend
koda
parents: 2754
diff changeset
   316
			// send a keydown and keyup even for the character
2688
174c94b8ea72 move all sdl source files in a proper directory
koda
parents:
diff changeset
   317
			SDL_SendKeyboardKey( 0, SDL_PRESSED, code);
174c94b8ea72 move all sdl source files in a proper directory
koda
parents:
diff changeset
   318
			SDL_SendKeyboardKey( 0, SDL_RELEASED, code);
174c94b8ea72 move all sdl source files in a proper directory
koda
parents:
diff changeset
   319
			if (mod & KMOD_SHIFT) {
2772
1965eba10be6 some code cleanup for the ifrontend
koda
parents: 2754
diff changeset
   320
				// If character uses shift, press shift back up
2688
174c94b8ea72 move all sdl source files in a proper directory
koda
parents:
diff changeset
   321
				SDL_SendKeyboardKey( 0, SDL_RELEASED, SDL_SCANCODE_LSHIFT);
174c94b8ea72 move all sdl source files in a proper directory
koda
parents:
diff changeset
   322
			}			
174c94b8ea72 move all sdl source files in a proper directory
koda
parents:
diff changeset
   323
		}
174c94b8ea72 move all sdl source files in a proper directory
koda
parents:
diff changeset
   324
	}
2772
1965eba10be6 some code cleanup for the ifrontend
koda
parents: 2754
diff changeset
   325
	return NO; // don't allow the edit! (keep placeholder text there)
2688
174c94b8ea72 move all sdl source files in a proper directory
koda
parents:
diff changeset
   326
}
174c94b8ea72 move all sdl source files in a proper directory
koda
parents:
diff changeset
   327
2772
1965eba10be6 some code cleanup for the ifrontend
koda
parents: 2754
diff changeset
   328
// Terminates the editing session
2688
174c94b8ea72 move all sdl source files in a proper directory
koda
parents:
diff changeset
   329
- (BOOL)textFieldShouldReturn:(UITextField*)_textField {
174c94b8ea72 move all sdl source files in a proper directory
koda
parents:
diff changeset
   330
	[self hideKeyboard];
174c94b8ea72 move all sdl source files in a proper directory
koda
parents:
diff changeset
   331
	return YES;
174c94b8ea72 move all sdl source files in a proper directory
koda
parents:
diff changeset
   332
}
174c94b8ea72 move all sdl source files in a proper directory
koda
parents:
diff changeset
   333
174c94b8ea72 move all sdl source files in a proper directory
koda
parents:
diff changeset
   334
#endif
2772
1965eba10be6 some code cleanup for the ifrontend
koda
parents: 2754
diff changeset
   335
*/
2688
174c94b8ea72 move all sdl source files in a proper directory
koda
parents:
diff changeset
   336
@end
2772
1965eba10be6 some code cleanup for the ifrontend
koda
parents: 2754
diff changeset
   337
/*
1965eba10be6 some code cleanup for the ifrontend
koda
parents: 2754
diff changeset
   338
// iPhone keyboard addition functions
2688
174c94b8ea72 move all sdl source files in a proper directory
koda
parents:
diff changeset
   339
#if SDL_IPHONE_KEYBOARD
174c94b8ea72 move all sdl source files in a proper directory
koda
parents:
diff changeset
   340
2714
c85ffe57d971 update iphone frontend to the new (silly) sdl api, code cleanups for other sections
koda
parents: 2705
diff changeset
   341
int SDL_iPhoneKeyboardShow(SDL_Window *window) {
2688
174c94b8ea72 move all sdl source files in a proper directory
koda
parents:
diff changeset
   342
	SDL_WindowData *data;
174c94b8ea72 move all sdl source files in a proper directory
koda
parents:
diff changeset
   343
	SDL_uikitview *view;
174c94b8ea72 move all sdl source files in a proper directory
koda
parents:
diff changeset
   344
	
174c94b8ea72 move all sdl source files in a proper directory
koda
parents:
diff changeset
   345
	if (NULL == window) {
174c94b8ea72 move all sdl source files in a proper directory
koda
parents:
diff changeset
   346
		SDL_SetError("Window does not exist");
174c94b8ea72 move all sdl source files in a proper directory
koda
parents:
diff changeset
   347
		return -1;
174c94b8ea72 move all sdl source files in a proper directory
koda
parents:
diff changeset
   348
	}
174c94b8ea72 move all sdl source files in a proper directory
koda
parents:
diff changeset
   349
	
174c94b8ea72 move all sdl source files in a proper directory
koda
parents:
diff changeset
   350
	data = (SDL_WindowData *)window->driverdata;
174c94b8ea72 move all sdl source files in a proper directory
koda
parents:
diff changeset
   351
	view = data->view;
174c94b8ea72 move all sdl source files in a proper directory
koda
parents:
diff changeset
   352
	
174c94b8ea72 move all sdl source files in a proper directory
koda
parents:
diff changeset
   353
	if (nil == view) {
174c94b8ea72 move all sdl source files in a proper directory
koda
parents:
diff changeset
   354
		SDL_SetError("Window has no view");
174c94b8ea72 move all sdl source files in a proper directory
koda
parents:
diff changeset
   355
		return -1;
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
	else {
174c94b8ea72 move all sdl source files in a proper directory
koda
parents:
diff changeset
   358
		[view showKeyboard];
174c94b8ea72 move all sdl source files in a proper directory
koda
parents:
diff changeset
   359
		return 0;
174c94b8ea72 move all sdl source files in a proper directory
koda
parents:
diff changeset
   360
	}
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
2714
c85ffe57d971 update iphone frontend to the new (silly) sdl api, code cleanups for other sections
koda
parents: 2705
diff changeset
   363
int SDL_iPhoneKeyboardHide(SDL_Window *window) {
2688
174c94b8ea72 move all sdl source files in a proper directory
koda
parents:
diff changeset
   364
	SDL_WindowData *data;
174c94b8ea72 move all sdl source files in a proper directory
koda
parents:
diff changeset
   365
	SDL_uikitview *view;
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
	if (NULL == window) {
174c94b8ea72 move all sdl source files in a proper directory
koda
parents:
diff changeset
   368
		SDL_SetError("Window does not exist");
174c94b8ea72 move all sdl source files in a proper directory
koda
parents:
diff changeset
   369
		return -1;
174c94b8ea72 move all sdl source files in a proper directory
koda
parents:
diff changeset
   370
	}	
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
	data = (SDL_WindowData *)window->driverdata;
174c94b8ea72 move all sdl source files in a proper directory
koda
parents:
diff changeset
   373
	view = data->view;
174c94b8ea72 move all sdl source files in a proper directory
koda
parents:
diff changeset
   374
	
174c94b8ea72 move all sdl source files in a proper directory
koda
parents:
diff changeset
   375
	if (NULL == view) {
174c94b8ea72 move all sdl source files in a proper directory
koda
parents:
diff changeset
   376
		SDL_SetError("Window has no view");
174c94b8ea72 move all sdl source files in a proper directory
koda
parents:
diff changeset
   377
		return -1;
174c94b8ea72 move all sdl source files in a proper directory
koda
parents:
diff changeset
   378
	}
174c94b8ea72 move all sdl source files in a proper directory
koda
parents:
diff changeset
   379
	else {
174c94b8ea72 move all sdl source files in a proper directory
koda
parents:
diff changeset
   380
		[view hideKeyboard];
174c94b8ea72 move all sdl source files in a proper directory
koda
parents:
diff changeset
   381
		return 0;
174c94b8ea72 move all sdl source files in a proper directory
koda
parents:
diff changeset
   382
	}
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
2714
c85ffe57d971 update iphone frontend to the new (silly) sdl api, code cleanups for other sections
koda
parents: 2705
diff changeset
   385
SDL_bool SDL_iPhoneKeyboardIsShown(SDL_Window *window) {
2688
174c94b8ea72 move all sdl source files in a proper directory
koda
parents:
diff changeset
   386
	SDL_WindowData *data;
174c94b8ea72 move all sdl source files in a proper directory
koda
parents:
diff changeset
   387
	SDL_uikitview *view;
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
	if (NULL == window) {
174c94b8ea72 move all sdl source files in a proper directory
koda
parents:
diff changeset
   390
		SDL_SetError("Window does not exist");
174c94b8ea72 move all sdl source files in a proper directory
koda
parents:
diff changeset
   391
		return -1;
174c94b8ea72 move all sdl source files in a proper directory
koda
parents:
diff changeset
   392
	}	
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
	data = (SDL_WindowData *)window->driverdata;
174c94b8ea72 move all sdl source files in a proper directory
koda
parents:
diff changeset
   395
	view = data->view;
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
	if (NULL == view) {
174c94b8ea72 move all sdl source files in a proper directory
koda
parents:
diff changeset
   398
		SDL_SetError("Window has no view");
174c94b8ea72 move all sdl source files in a proper directory
koda
parents:
diff changeset
   399
		return 0;
174c94b8ea72 move all sdl source files in a proper directory
koda
parents:
diff changeset
   400
	}
174c94b8ea72 move all sdl source files in a proper directory
koda
parents:
diff changeset
   401
	else {
174c94b8ea72 move all sdl source files in a proper directory
koda
parents:
diff changeset
   402
		return view.keyboardVisible;
174c94b8ea72 move all sdl source files in a proper directory
koda
parents:
diff changeset
   403
	}
174c94b8ea72 move all sdl source files in a proper directory
koda
parents:
diff changeset
   404
}
174c94b8ea72 move all sdl source files in a proper directory
koda
parents:
diff changeset
   405
2714
c85ffe57d971 update iphone frontend to the new (silly) sdl api, code cleanups for other sections
koda
parents: 2705
diff changeset
   406
int SDL_iPhoneKeyboardToggle(SDL_Window *window) {
2688
174c94b8ea72 move all sdl source files in a proper directory
koda
parents:
diff changeset
   407
	SDL_WindowData *data;
174c94b8ea72 move all sdl source files in a proper directory
koda
parents:
diff changeset
   408
	SDL_uikitview *view;
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
	if (NULL == window) {
174c94b8ea72 move all sdl source files in a proper directory
koda
parents:
diff changeset
   411
		SDL_SetError("Window does not exist");
174c94b8ea72 move all sdl source files in a proper directory
koda
parents:
diff changeset
   412
		return -1;
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
	
174c94b8ea72 move all sdl source files in a proper directory
koda
parents:
diff changeset
   415
	data = (SDL_WindowData *)window->driverdata;
174c94b8ea72 move all sdl source files in a proper directory
koda
parents:
diff changeset
   416
	view = data->view;
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
	if (NULL == view) {
174c94b8ea72 move all sdl source files in a proper directory
koda
parents:
diff changeset
   419
		SDL_SetError("Window has no view");
174c94b8ea72 move all sdl source files in a proper directory
koda
parents:
diff changeset
   420
		return -1;
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
	else {
2714
c85ffe57d971 update iphone frontend to the new (silly) sdl api, code cleanups for other sections
koda
parents: 2705
diff changeset
   423
		if (SDL_iPhoneKeyboardIsShown(window)) {
c85ffe57d971 update iphone frontend to the new (silly) sdl api, code cleanups for other sections
koda
parents: 2705
diff changeset
   424
			SDL_iPhoneKeyboardHide(window);
2688
174c94b8ea72 move all sdl source files in a proper directory
koda
parents:
diff changeset
   425
		}
174c94b8ea72 move all sdl source files in a proper directory
koda
parents:
diff changeset
   426
		else {
2714
c85ffe57d971 update iphone frontend to the new (silly) sdl api, code cleanups for other sections
koda
parents: 2705
diff changeset
   427
			SDL_iPhoneKeyboardShow(window);
2688
174c94b8ea72 move all sdl source files in a proper directory
koda
parents:
diff changeset
   428
		}
174c94b8ea72 move all sdl source files in a proper directory
koda
parents:
diff changeset
   429
		return 0;
174c94b8ea72 move all sdl source files in a proper directory
koda
parents:
diff changeset
   430
	}
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
#else
174c94b8ea72 move all sdl source files in a proper directory
koda
parents:
diff changeset
   434
2772
1965eba10be6 some code cleanup for the ifrontend
koda
parents: 2754
diff changeset
   435
// stubs, used if compiled without keyboard support
2688
174c94b8ea72 move all sdl source files in a proper directory
koda
parents:
diff changeset
   436
2714
c85ffe57d971 update iphone frontend to the new (silly) sdl api, code cleanups for other sections
koda
parents: 2705
diff changeset
   437
int SDL_iPhoneKeyboardShow(SDL_Window *window) {
2688
174c94b8ea72 move all sdl source files in a proper directory
koda
parents:
diff changeset
   438
	SDL_SetError("Not compiled with keyboard support");
174c94b8ea72 move all sdl source files in a proper directory
koda
parents:
diff changeset
   439
	return -1;
174c94b8ea72 move all sdl source files in a proper directory
koda
parents:
diff changeset
   440
}
174c94b8ea72 move all sdl source files in a proper directory
koda
parents:
diff changeset
   441
2714
c85ffe57d971 update iphone frontend to the new (silly) sdl api, code cleanups for other sections
koda
parents: 2705
diff changeset
   442
int SDL_iPhoneKeyboardHide(SDL_Window *window) {
2688
174c94b8ea72 move all sdl source files in a proper directory
koda
parents:
diff changeset
   443
	SDL_SetError("Not compiled with keyboard support");
174c94b8ea72 move all sdl source files in a proper directory
koda
parents:
diff changeset
   444
	return -1;
174c94b8ea72 move all sdl source files in a proper directory
koda
parents:
diff changeset
   445
}
174c94b8ea72 move all sdl source files in a proper directory
koda
parents:
diff changeset
   446
2714
c85ffe57d971 update iphone frontend to the new (silly) sdl api, code cleanups for other sections
koda
parents: 2705
diff changeset
   447
SDL_bool SDL_iPhoneKeyboardIsShown(SDL_Window *window) {
2688
174c94b8ea72 move all sdl source files in a proper directory
koda
parents:
diff changeset
   448
	return 0;
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
2714
c85ffe57d971 update iphone frontend to the new (silly) sdl api, code cleanups for other sections
koda
parents: 2705
diff changeset
   451
int SDL_iPhoneKeyboardToggle(SDL_Window *window) {
2688
174c94b8ea72 move all sdl source files in a proper directory
koda
parents:
diff changeset
   452
	SDL_SetError("Not compiled with keyboard support");
174c94b8ea72 move all sdl source files in a proper directory
koda
parents:
diff changeset
   453
	return -1;
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
174c94b8ea72 move all sdl source files in a proper directory
koda
parents:
diff changeset
   456
#endif /* SDL_IPHONE_KEYBOARD */