Skip to content
This repository has been archived by the owner on Feb 11, 2021. It is now read-only.

Commit

Permalink
Created a header file for system dependent API functions, and added S…
Browse files Browse the repository at this point in the history
…DL_iPhoneSetAnimationCallback()
  • Loading branch information
slouken committed Jun 22, 2012
1 parent 6cc5530 commit 22ada2e
Show file tree
Hide file tree
Showing 9 changed files with 89 additions and 6 deletions.
2 changes: 1 addition & 1 deletion README.iOS
Expand Up @@ -78,7 +78,7 @@ Finally, if your application completely redraws the screen each frame, you may f
Notes -- Keyboard
==============================================================================

SDL for iPhone contains several additional functions related to keyboard visibility. These functions are not part of the SDL standard API, but are necessary for revealing and hiding the iPhone's virtual onscreen keyboard. You can use them in your own applications by including a copy of the SDL_uikitkeyboard.h header (located in src/video/uikit) in your project.
SDL for iPhone contains several additional functions related to keyboard visibility. These functions are not part of the SDL standard API, but are necessary for revealing and hiding the iPhone's virtual onscreen keyboard.

int SDL_iPhoneKeyboardShow(SDL_Window * window)
-- reveals the onscreen keyboard. Returns 0 on success and -1 on error.
Expand Down
1 change: 1 addition & 0 deletions include/SDL.h
Expand Up @@ -86,6 +86,7 @@
#include "SDL_power.h"
#include "SDL_render.h"
#include "SDL_rwops.h"
#include "SDL_system.h"
#include "SDL_thread.h"
#include "SDL_timer.h"
#include "SDL_version.h"
Expand Down
24 changes: 21 additions & 3 deletions src/video/uikit/SDL_uikitkeyboard.h → include/SDL_system.h 100755 → 100644
Expand Up @@ -19,28 +19,46 @@
3. This notice may not be removed or altered from any source distribution.
*/

#ifndef sdl_uikitkeyboard_h
#define sdl_uikitkeyboard_h
/**
* \file SDL_system.h
*
* Include file for platform specific SDL API functions
*/

#ifndef _SDL_system_h
#define _SDL_system_h

#include "SDL_stdinc.h"

#include "begin_code.h"
/* Set up for C function definitions, even when using C++ */
#ifdef __cplusplus
/* *INDENT-OFF* */
extern "C" {
/* *INDENT-ON* */
#endif

#if __IPHONEOS__

#include "SDL_video.h"

extern DECLSPEC int SDLCALL SDL_iPhoneSetAnimationCallback(SDL_Window * window, int interval, void (*callback)(void*), void *callbackParam);

extern DECLSPEC int SDLCALL SDL_iPhoneKeyboardShow(SDL_Window * window);
extern DECLSPEC int SDLCALL SDL_iPhoneKeyboardHide(SDL_Window * window);
extern DECLSPEC SDL_bool SDLCALL SDL_iPhoneKeyboardIsShown(SDL_Window * window);
extern DECLSPEC int SDLCALL SDL_iPhoneKeyboardToggle(SDL_Window * window);

#endif

/* Ends C function definitions when using C++ */
#ifdef __cplusplus
/* *INDENT-OFF* */
}
/* *INDENT-ON* */
#endif
#include "close_code.h"

#endif /* sdl_uikitkeyboard_h */
#endif /* _SDL_system_h */

/* vi: set ts=4 sw=4 expandtab: */
2 changes: 1 addition & 1 deletion include/SDL_touch.h
Expand Up @@ -119,6 +119,6 @@ struct SDL_Touch {
#endif
#include "close_code.h"

#endif /* _SDL_mouse_h */
#endif /* _SDL_touch_h */

/* vi: set ts=4 sw=4 expandtab: */
2 changes: 2 additions & 0 deletions src/video/uikit/SDL_uikitappdelegate.m
Expand Up @@ -108,6 +108,8 @@ - (void)postFinishLaunch
exit_status = SDL_main(forward_argc, forward_argv);

/* exit, passing the return status from the user's application */
// We don't actually exit to support applications that do setup in
// their main function and then allow the Cocoa event loop to run.
// exit(exit_status);
}

Expand Down
14 changes: 14 additions & 0 deletions src/video/uikit/SDL_uikitopenglview.h
Expand Up @@ -46,6 +46,11 @@

/* format of depthRenderbuffer */
GLenum depthBufferFormat;

id displayLink;
int animationInterval;
void (*animationCallback)(void*);
void *animationCallbackParam;
}

@property (nonatomic, retain, readonly) EAGLContext *context;
Expand All @@ -66,6 +71,15 @@

- (void)updateFrame;

- (void)setAnimationCallback:(int)interval
callback:(void (*)(void*))callback
callbackParam:(void*)callbackParam;

- (void)startAnimation;
- (void)stopAnimation;

- (void)doLoop:(id)sender;

@end

/* vi: set ts=4 sw=4 expandtab: */
35 changes: 35 additions & 0 deletions src/video/uikit/SDL_uikitopenglview.m
Expand Up @@ -147,6 +147,41 @@ - (void)updateFrame
}
}

- (void)setAnimationCallback:(int)interval
callback:(void (*)(void*))callback
callbackParam:(void*)callbackParam
{
[self stopAnimation];

animationInterval = interval;
animationCallback = callback;
animationCallbackParam = callbackParam;

if (animationCallback)
[self startAnimation];
}

- (void)startAnimation
{
// CADisplayLink is API new to iPhone SDK 3.1. Compiling against earlier versions will result in a warning, but can be dismissed
// if the system version runtime check for CADisplayLink exists in -initWithCoder:.

displayLink = [NSClassFromString(@"CADisplayLink") displayLinkWithTarget:self selector:@selector(doLoop:)];
[displayLink setFrameInterval:animationInterval];
[displayLink addToRunLoop:[NSRunLoop currentRunLoop] forMode:NSDefaultRunLoopMode];
}

- (void)stopAnimation
{
[displayLink invalidate];
displayLink = nil;
}

- (void)doLoop:(id)sender
{
animationCallback(animationCallbackParam);
}

- (void)setCurrentContext
{
[EAGLContext setCurrentContext:context];
Expand Down
1 change: 0 additions & 1 deletion src/video/uikit/SDL_uikitview.m
Expand Up @@ -31,7 +31,6 @@
#if SDL_IPHONE_KEYBOARD
#import "keyinfotable.h"
#import "SDL_uikitappdelegate.h"
#import "SDL_uikitkeyboard.h"
#import "SDL_uikitwindow.h"
#endif

Expand Down
14 changes: 14 additions & 0 deletions src/video/uikit/SDL_uikitwindow.m
Expand Up @@ -279,6 +279,20 @@ static int SetupWindowData(_THIS, SDL_Window *window, UIWindow *uiwindow, SDL_bo
}
}

int
SDL_iPhoneSetAnimationCallback(SDL_Window * window, int interval, void (*callback)(void*), void *callbackParam)
{
SDL_WindowData *data = window ? (SDL_WindowData *)window->driverdata : NULL;

if (!data || !data->view) {
SDL_SetError("Invalid window or view not set");
return -1;
}

[data->view setAnimationCallback:interval callback:callback callbackParam:callbackParam];
return 0;
}

#endif /* SDL_VIDEO_DRIVER_UIKIT */

/* vi: set ts=4 sw=4 expandtab: */

0 comments on commit 22ada2e

Please sign in to comment.