Created a header file for system dependent API functions, and added SDL_iPhoneSetAnimationCallback()
authorSam Lantinga <slouken@libsdl.org>
Fri, 22 Jun 2012 19:19:18 -0400
changeset 6342ac83b73f0edd
parent 6341 057bbdb514d5
child 6343 e94f912d20b9
Created a header file for system dependent API functions, and added SDL_iPhoneSetAnimationCallback()
README.iOS
include/SDL.h
include/SDL_system.h
include/SDL_touch.h
src/video/uikit/SDL_uikitappdelegate.m
src/video/uikit/SDL_uikitkeyboard.h
src/video/uikit/SDL_uikitopenglview.h
src/video/uikit/SDL_uikitopenglview.m
src/video/uikit/SDL_uikitview.m
src/video/uikit/SDL_uikitwindow.m
     1.1 --- a/README.iOS	Fri Jun 22 11:38:49 2012 -0400
     1.2 +++ b/README.iOS	Fri Jun 22 19:19:18 2012 -0400
     1.3 @@ -78,7 +78,7 @@
     1.4  Notes -- Keyboard
     1.5  ==============================================================================
     1.6  
     1.7 -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.
     1.8 +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.
     1.9  
    1.10  int SDL_iPhoneKeyboardShow(SDL_Window * window) 
    1.11  	-- reveals the onscreen keyboard.  Returns 0 on success and -1 on error.
     2.1 --- a/include/SDL.h	Fri Jun 22 11:38:49 2012 -0400
     2.2 +++ b/include/SDL.h	Fri Jun 22 19:19:18 2012 -0400
     2.3 @@ -86,6 +86,7 @@
     2.4  #include "SDL_power.h"
     2.5  #include "SDL_render.h"
     2.6  #include "SDL_rwops.h"
     2.7 +#include "SDL_system.h"
     2.8  #include "SDL_thread.h"
     2.9  #include "SDL_timer.h"
    2.10  #include "SDL_version.h"
     3.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     3.2 +++ b/include/SDL_system.h	Fri Jun 22 19:19:18 2012 -0400
     3.3 @@ -0,0 +1,64 @@
     3.4 +/*
     3.5 +  Simple DirectMedia Layer
     3.6 +  Copyright (C) 1997-2012 Sam Lantinga <slouken@libsdl.org>
     3.7 +
     3.8 +  This software is provided 'as-is', without any express or implied
     3.9 +  warranty.  In no event will the authors be held liable for any damages
    3.10 +  arising from the use of this software.
    3.11 +
    3.12 +  Permission is granted to anyone to use this software for any purpose,
    3.13 +  including commercial applications, and to alter it and redistribute it
    3.14 +  freely, subject to the following restrictions:
    3.15 +
    3.16 +  1. The origin of this software must not be misrepresented; you must not
    3.17 +     claim that you wrote the original software. If you use this software
    3.18 +     in a product, an acknowledgment in the product documentation would be
    3.19 +     appreciated but is not required.
    3.20 +  2. Altered source versions must be plainly marked as such, and must not be
    3.21 +     misrepresented as being the original software.
    3.22 +  3. This notice may not be removed or altered from any source distribution.
    3.23 +*/
    3.24 +
    3.25 +/**
    3.26 + *  \file SDL_system.h
    3.27 + *  
    3.28 + *  Include file for platform specific SDL API functions
    3.29 + */
    3.30 +
    3.31 +#ifndef _SDL_system_h
    3.32 +#define _SDL_system_h
    3.33 +
    3.34 +#include "SDL_stdinc.h"
    3.35 +
    3.36 +#include "begin_code.h"
    3.37 +/* Set up for C function definitions, even when using C++ */
    3.38 +#ifdef __cplusplus
    3.39 +/* *INDENT-OFF* */
    3.40 +extern "C" {
    3.41 +/* *INDENT-ON* */
    3.42 +#endif
    3.43 +
    3.44 +#if __IPHONEOS__
    3.45 +
    3.46 +#include "SDL_video.h"
    3.47 +
    3.48 +extern DECLSPEC int SDLCALL SDL_iPhoneSetAnimationCallback(SDL_Window * window, int interval, void (*callback)(void*), void *callbackParam);
    3.49 +
    3.50 +extern DECLSPEC int SDLCALL SDL_iPhoneKeyboardShow(SDL_Window * window);
    3.51 +extern DECLSPEC int SDLCALL SDL_iPhoneKeyboardHide(SDL_Window * window);
    3.52 +extern DECLSPEC SDL_bool SDLCALL SDL_iPhoneKeyboardIsShown(SDL_Window * window);
    3.53 +extern DECLSPEC int SDLCALL SDL_iPhoneKeyboardToggle(SDL_Window * window);
    3.54 +
    3.55 +#endif
    3.56 +
    3.57 +/* Ends C function definitions when using C++ */
    3.58 +#ifdef __cplusplus
    3.59 +/* *INDENT-OFF* */
    3.60 +}
    3.61 +/* *INDENT-ON* */
    3.62 +#endif
    3.63 +#include "close_code.h"
    3.64 +
    3.65 +#endif /* _SDL_system_h */
    3.66 +
    3.67 +/* vi: set ts=4 sw=4 expandtab: */
     4.1 --- a/include/SDL_touch.h	Fri Jun 22 11:38:49 2012 -0400
     4.2 +++ b/include/SDL_touch.h	Fri Jun 22 19:19:18 2012 -0400
     4.3 @@ -119,6 +119,6 @@
     4.4  #endif
     4.5  #include "close_code.h"
     4.6  
     4.7 -#endif /* _SDL_mouse_h */
     4.8 +#endif /* _SDL_touch_h */
     4.9  
    4.10  /* vi: set ts=4 sw=4 expandtab: */
     5.1 --- a/src/video/uikit/SDL_uikitappdelegate.m	Fri Jun 22 11:38:49 2012 -0400
     5.2 +++ b/src/video/uikit/SDL_uikitappdelegate.m	Fri Jun 22 19:19:18 2012 -0400
     5.3 @@ -108,6 +108,8 @@
     5.4      exit_status = SDL_main(forward_argc, forward_argv);
     5.5  
     5.6      /* exit, passing the return status from the user's application */
     5.7 +    // We don't actually exit to support applications that do setup in
     5.8 +    // their main function and then allow the Cocoa event loop to run.
     5.9      // exit(exit_status);
    5.10  }
    5.11  
     6.1 --- a/src/video/uikit/SDL_uikitkeyboard.h	Fri Jun 22 11:38:49 2012 -0400
     6.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
     6.3 @@ -1,46 +0,0 @@
     6.4 -/*
     6.5 -  Simple DirectMedia Layer
     6.6 -  Copyright (C) 1997-2012 Sam Lantinga <slouken@libsdl.org>
     6.7 -
     6.8 -  This software is provided 'as-is', without any express or implied
     6.9 -  warranty.  In no event will the authors be held liable for any damages
    6.10 -  arising from the use of this software.
    6.11 -
    6.12 -  Permission is granted to anyone to use this software for any purpose,
    6.13 -  including commercial applications, and to alter it and redistribute it
    6.14 -  freely, subject to the following restrictions:
    6.15 -
    6.16 -  1. The origin of this software must not be misrepresented; you must not
    6.17 -     claim that you wrote the original software. If you use this software
    6.18 -     in a product, an acknowledgment in the product documentation would be
    6.19 -     appreciated but is not required.
    6.20 -  2. Altered source versions must be plainly marked as such, and must not be
    6.21 -     misrepresented as being the original software.
    6.22 -  3. This notice may not be removed or altered from any source distribution.
    6.23 -*/
    6.24 -
    6.25 -#ifndef sdl_uikitkeyboard_h
    6.26 -#define sdl_uikitkeyboard_h
    6.27 -
    6.28 -/* Set up for C function definitions, even when using C++ */
    6.29 -#ifdef __cplusplus
    6.30 -/* *INDENT-OFF* */
    6.31 -extern "C" {
    6.32 -/* *INDENT-ON* */
    6.33 -#endif
    6.34 -
    6.35 -extern DECLSPEC int SDLCALL SDL_iPhoneKeyboardShow(SDL_Window * window);
    6.36 -extern DECLSPEC int SDLCALL SDL_iPhoneKeyboardHide(SDL_Window * window);
    6.37 -extern DECLSPEC SDL_bool SDLCALL SDL_iPhoneKeyboardIsShown(SDL_Window * window);
    6.38 -extern DECLSPEC int SDLCALL SDL_iPhoneKeyboardToggle(SDL_Window * window);
    6.39 -
    6.40 -/* Ends C function definitions when using C++ */
    6.41 -#ifdef __cplusplus
    6.42 -/* *INDENT-OFF* */
    6.43 -}
    6.44 -/* *INDENT-ON* */
    6.45 -#endif
    6.46 -
    6.47 -#endif /* sdl_uikitkeyboard_h */
    6.48 -
    6.49 -/* vi: set ts=4 sw=4 expandtab: */
     7.1 --- a/src/video/uikit/SDL_uikitopenglview.h	Fri Jun 22 11:38:49 2012 -0400
     7.2 +++ b/src/video/uikit/SDL_uikitopenglview.h	Fri Jun 22 19:19:18 2012 -0400
     7.3 @@ -46,6 +46,11 @@
     7.4  
     7.5      /* format of depthRenderbuffer */
     7.6      GLenum depthBufferFormat;
     7.7 +
     7.8 +    id displayLink;
     7.9 +    int animationInterval;
    7.10 +    void (*animationCallback)(void*);
    7.11 +    void *animationCallbackParam;
    7.12  }
    7.13  
    7.14  @property (nonatomic, retain, readonly) EAGLContext *context;
    7.15 @@ -66,6 +71,15 @@
    7.16  
    7.17  - (void)updateFrame;
    7.18  
    7.19 +- (void)setAnimationCallback:(int)interval
    7.20 +    callback:(void (*)(void*))callback
    7.21 +    callbackParam:(void*)callbackParam;
    7.22 +
    7.23 +- (void)startAnimation;
    7.24 +- (void)stopAnimation;
    7.25 +
    7.26 +- (void)doLoop:(id)sender;
    7.27 +
    7.28  @end
    7.29  
    7.30  /* vi: set ts=4 sw=4 expandtab: */
     8.1 --- a/src/video/uikit/SDL_uikitopenglview.m	Fri Jun 22 11:38:49 2012 -0400
     8.2 +++ b/src/video/uikit/SDL_uikitopenglview.m	Fri Jun 22 19:19:18 2012 -0400
     8.3 @@ -147,6 +147,41 @@
     8.4      }
     8.5  }
     8.6  
     8.7 +- (void)setAnimationCallback:(int)interval
     8.8 +    callback:(void (*)(void*))callback
     8.9 +    callbackParam:(void*)callbackParam
    8.10 +{
    8.11 +    [self stopAnimation];
    8.12 +
    8.13 +    animationInterval = interval;
    8.14 +    animationCallback = callback;
    8.15 +    animationCallbackParam = callbackParam;
    8.16 +
    8.17 +    if (animationCallback)
    8.18 +        [self startAnimation];
    8.19 +}
    8.20 +
    8.21 +- (void)startAnimation
    8.22 +{
    8.23 +    // CADisplayLink is API new to iPhone SDK 3.1. Compiling against earlier versions will result in a warning, but can be dismissed
    8.24 +    // if the system version runtime check for CADisplayLink exists in -initWithCoder:. 
    8.25 +    
    8.26 +    displayLink = [NSClassFromString(@"CADisplayLink") displayLinkWithTarget:self selector:@selector(doLoop:)];
    8.27 +    [displayLink setFrameInterval:animationInterval];
    8.28 +    [displayLink addToRunLoop:[NSRunLoop currentRunLoop] forMode:NSDefaultRunLoopMode];
    8.29 +}
    8.30 +
    8.31 +- (void)stopAnimation
    8.32 +{
    8.33 +    [displayLink invalidate];
    8.34 +    displayLink = nil;
    8.35 +}
    8.36 +
    8.37 +- (void)doLoop:(id)sender
    8.38 +{
    8.39 +    animationCallback(animationCallbackParam);
    8.40 +}
    8.41 +
    8.42  - (void)setCurrentContext
    8.43  {
    8.44      [EAGLContext setCurrentContext:context];
     9.1 --- a/src/video/uikit/SDL_uikitview.m	Fri Jun 22 11:38:49 2012 -0400
     9.2 +++ b/src/video/uikit/SDL_uikitview.m	Fri Jun 22 19:19:18 2012 -0400
     9.3 @@ -31,7 +31,6 @@
     9.4  #if SDL_IPHONE_KEYBOARD
     9.5  #import "keyinfotable.h"
     9.6  #import "SDL_uikitappdelegate.h"
     9.7 -#import "SDL_uikitkeyboard.h"
     9.8  #import "SDL_uikitwindow.h"
     9.9  #endif
    9.10  
    10.1 --- a/src/video/uikit/SDL_uikitwindow.m	Fri Jun 22 11:38:49 2012 -0400
    10.2 +++ b/src/video/uikit/SDL_uikitwindow.m	Fri Jun 22 19:19:18 2012 -0400
    10.3 @@ -279,6 +279,20 @@
    10.4      }
    10.5  }
    10.6  
    10.7 +int
    10.8 +SDL_iPhoneSetAnimationCallback(SDL_Window * window, int interval, void (*callback)(void*), void *callbackParam)
    10.9 +{
   10.10 +    SDL_WindowData *data = window ? (SDL_WindowData *)window->driverdata : NULL;
   10.11 +
   10.12 +    if (!data || !data->view) {
   10.13 +        SDL_SetError("Invalid window or view not set");
   10.14 +        return -1;
   10.15 +    }
   10.16 +
   10.17 +    [data->view setAnimationCallback:interval callback:callback callbackParam:callbackParam];
   10.18 +    return 0;
   10.19 +}
   10.20 +
   10.21  #endif /* SDL_VIDEO_DRIVER_UIKIT */
   10.22  
   10.23  /* vi: set ts=4 sw=4 expandtab: */