cocoaTouch/SDLOverrides/SDL_uikitview.m
changeset 2805 36a8cebb91e8
parent 2772 1965eba10be6
child 3006 da6023c2745b
equal deleted inserted replaced
2804:31c6c36c5d34 2805:36a8cebb91e8
    32 #endif
    32 #endif
    33 
    33 
    34 @implementation SDL_uikitview
    34 @implementation SDL_uikitview
    35 
    35 
    36 // they have to be global variables to allow showControls() to use them
    36 // they have to be global variables to allow showControls() to use them
    37 UIButton *attackButton, *menuButton;
    37 //UIButton *attackButton, *menuButton;
    38 
    38 UIView *menuView;
    39 -(void) dealloc {
    39 -(void) dealloc {
    40 #if SDL_IPHONE_KEYBOARD
    40 #if SDL_IPHONE_KEYBOARD
    41 	SDL_DelKeyboard(0);
    41 	SDL_DelKeyboard(0);
    42 	[textField release];
    42 	[textField release];
    43 #endif
    43 #endif
    44 	[menuButton release];
    44 	if (menuView) [menuView release];
    45 	[attackButton release];
    45 	//[menuButton release];
       
    46 	//[attackButton release];
    46 	[super dealloc];
    47 	[super dealloc];
    47 }
    48 }
    48 
    49 
    49 - (id)initWithFrame:(CGRect)frame {
    50 - (id)initWithFrame:(CGRect)frame {
    50 	// the addTarget parameter for the buttons below is set like that because
    51 	// the addTarget parameter for the buttons below is set like that because
    64 		SDL_AddMouse(&mice[i], "Mouse", 0, 0, 1);
    65 		SDL_AddMouse(&mice[i], "Mouse", 0, 0, 1);
    65 	}
    66 	}
    66 
    67 
    67 	self.multipleTouchEnabled = YES;
    68 	self.multipleTouchEnabled = YES;
    68 	self.exclusiveTouch = YES;
    69 	self.exclusiveTouch = YES;
    69 /*
    70 
       
    71 	
       
    72 	/*
    70 	// custom code
    73 	// custom code
    71 	// the coordinate system is still like in Portrait even though everything is rotated
    74 	// the coordinate system is still like in Portrait even though everything is rotated
    72 	attackButton = [[UIButton alloc] initWithFrame:CGRectMake(30, 480, 260, 50)];
    75 	attackButton = [[UIButton alloc] initWithFrame:CGRectMake(30, 480, 260, 50)];
    73 	[attackButton setBackgroundImage:[UIImage imageNamed:@"Default.png"] forState:UIControlStateNormal];
    76 	[attackButton setBackgroundImage:[UIImage imageNamed:@"Default.png"] forState:UIControlStateNormal];
    74 	[attackButton setBackgroundImage:[UIImage imageNamed:@"Default.png"] forState:UIControlStateHighlighted];
    77 	[attackButton setBackgroundImage:[UIImage imageNamed:@"Default.png"] forState:UIControlStateHighlighted];
   110 	UIButton *chatButton = [[UIButton alloc] initWithFrame:CGRectMake(70, 100, 250, 280)];
   113 	UIButton *chatButton = [[UIButton alloc] initWithFrame:CGRectMake(70, 100, 250, 280)];
   111 	[chatButton addTarget:[self superclass] action:@selector(chatBegin) forControlEvents:UIControlEventTouchDown];
   114 	[chatButton addTarget:[self superclass] action:@selector(chatBegin) forControlEvents:UIControlEventTouchDown];
   112 	[self insertSubview:chatButton atIndex:0];
   115 	[self insertSubview:chatButton atIndex:0];
   113 	[chatButton release];
   116 	[chatButton release];
   114 	*/
   117 	*/
       
   118 
       
   119 //(0,0) is the lower left corner
       
   120 //x:[0-320]
       
   121 //y:[0-480]
       
   122 	UIButton *menuButton = [[UIButton alloc] initWithFrame:CGRectMake(256, 416, 64, 64)];
       
   123 	[menuButton addTarget:[self superclass] action:@selector(showMenu) forControlEvents:UIControlEventTouchDown];
       
   124 	[menuButton setBackgroundImage:[UIImage imageNamed:@"Default.png"] forState:UIControlStateNormal];
       
   125 	[self insertSubview:menuButton atIndex:0];
       
   126 	[menuButton release];
       
   127 	
       
   128 	menuView = [[UIView alloc] initWithFrame:CGRectMake(320, 480, 150, 100)];
       
   129 	menuView.backgroundColor = [UIColor lightGrayColor];
       
   130 	[self insertSubview:menuView atIndex:1];
       
   131 
   115 	return self;
   132 	return self;
   116 }
   133 }
       
   134 
       
   135 +(void) showMenu {
       
   136 	HW_pause();
       
   137 	
       
   138 	[UIView beginAnimations:@"show menu" context:NULL];
       
   139 	[UIView setAnimationDuration:1];
       
   140 	
       
   141 	menuView.frame = CGRectMake(170, 380, 150, 100);
       
   142 	
       
   143 	[UIView commitAnimations];
       
   144 }
       
   145 
       
   146 +(void) hideMenu {
       
   147 	[UIView beginAnimations:@"hide menu" context:NULL];
       
   148 	[UIView setAnimationDuration:1];
       
   149 	
       
   150 	menuView.frame = CGRectMake(480, -70, 150, 100);
       
   151 	
       
   152 	[UIView commitAnimations];
       
   153 	
       
   154 	HW_pause();
       
   155 }
       
   156 
       
   157 
   117 
   158 
   118 #pragma mark -
   159 #pragma mark -
   119 #pragma mark Exported functions for FreePascal
   160 #pragma mark Exported functions for FreePascal
   120 const char* IPH_getDocumentsPath() {
   161 const char* IPH_getDocumentsPath() {
   121 	NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
   162 	NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
   160 	HW_aimDown();
   201 	HW_aimDown();
   161 }
   202 }
   162 
   203 
   163 +(void) chatBegin {
   204 +(void) chatBegin {
   164 	//TODO: implement a UITextScroll and put received chat lines in there
   205 	//TODO: implement a UITextScroll and put received chat lines in there
       
   206 }
       
   207 
       
   208 +(void) pauseGame {
       
   209 	HW_pause();
   165 }
   210 }
   166 
   211 
   167 #pragma mark -
   212 #pragma mark -
   168 #pragma mark Custom SDL_UIView input handling
   213 #pragma mark Custom SDL_UIView input handling
   169 #define kMinimumPinchDelta	50
   214 #define kMinimumPinchDelta	50