pushing iphone events to sdl - its easy |
michelleC
|
So I set out to create an OSD overlay for the sdl/opengl iphone player I've been building.
Please look at this picture before reading more. http://web.me.com/cannonwc/Site_4/Photos.html#1 But How to translate the uikit touches to an sdl event, turns out it was a lot easier than I thought. Here's how. 1) first lets create a simple event loop, for simplicity lets include only a few events. SDL_Event event; double incr, pos, frac; int done = 0; while (!done) { SDL_WaitEvent(&event); switch(event.type) { case SDL_KEYDOWN: switch(event.key.keysym.sym) { case SDLK_f: toggle_full_screen(); break; case SDLK_F11: do_exit(&done); break; default: sdl_quit; fprintf(stdout, "Release control"); break; Now on the iphone uikit HUDView.m we create the button bar. Again for simplicity we will only show the quit_event we are handling. UIButton *quitButton = [[UIButton alloc] initWithFrame:CGRectMake(200, 10, 48.0f, 48.0f)]; [quitButton setBackgroundImage:[[UIImage imageNamed:@"quit.png"] stretchableImageWithLeftCapWidth:48.0 topCapHeight:0.0] forState:UIControlStateNormal]; //[stopButton setCenter:CGPointMake(195.0f, 208.0f)]; quitButton.backgroundColor = [UIColor colorWithWhite:0 alpha:0]; [quitButton addTarget:self action:@selector(quitClicked) forControlEvents:UIControlEventTouchUpInside]; [self addSubview:quitButton]; //Notice the selector //when we click the quitbutton the quitClicked method is called. //we create an event simulating pressing the f11 key. -(void)quitClicked { SDL_KeyboardEvent event; event.type = SDL_KEYDOWN; event.which = 0; event.state = SDL_PRESSED; event.keysym.sym = SDLK_F11; SDL_PushEvent((SDL_Event*)&event); // Send the F11 key press event.type = SDL_KEYUP; event.state = SDL_RELEASED; SDL_PushEvent((SDL_Event*)&event); // Send the F11 key release } //Thats all To see the viewer in action you can see this on youtube http://www.youtube.com/watch?v=Rdb0eKhmH4Q |
|||||||||||
|
pushing iphone events to sdl - its easy |
Sam Lantinga
|
Very cool, thanks for the tutorial!
On Fri, Mar 26, 2010 at 9:38 PM, michelleC wrote:
-- -Sam Lantinga, Founder and President, Galaxy Gameworks LLC _______________________________________________ SDL mailing list http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org |
|||||||||||||
|