More cleanup of the iOS Objective-C code. iOS-improvements
authorAlex Szpakowski <slime73@gmail.com>
Wed, 23 Jul 2014 03:05:31 -0300
branchiOS-improvements
changeset 9501574db299498f
parent 9500 cbf5c5ecf5ac
child 9502 933ed557b7c1
More cleanup of the iOS Objective-C code.
src/video/uikit/SDL_uikitappdelegate.m
src/video/uikit/SDL_uikitmessagebox.m
src/video/uikit/SDL_uikitopenglview.h
src/video/uikit/SDL_uikitopenglview.m
src/video/uikit/SDL_uikitview.h
src/video/uikit/SDL_uikitview.m
src/video/uikit/SDL_uikitviewcontroller.h
src/video/uikit/SDL_uikitwindow.m
     1.1 --- a/src/video/uikit/SDL_uikitappdelegate.m	Wed Jul 23 01:33:59 2014 -0300
     1.2 +++ b/src/video/uikit/SDL_uikitappdelegate.m	Wed Jul 23 03:05:31 2014 -0300
     1.3 @@ -75,17 +75,18 @@
     1.4      [UIApplication sharedApplication].idleTimerDisabled = disable;
     1.5  }
     1.6  
     1.7 -@interface SDL_splashviewcontroller : UIViewController {
     1.8 +@interface SDL_splashviewcontroller : UIViewController
     1.9 +
    1.10 +- (void)updateSplashImage:(UIInterfaceOrientation)interfaceOrientation;
    1.11 +
    1.12 +@end
    1.13 +
    1.14 +@implementation SDL_splashviewcontroller {
    1.15      UIImageView *splash;
    1.16      UIImage *splashPortrait;
    1.17      UIImage *splashLandscape;
    1.18  }
    1.19  
    1.20 -- (void)updateSplashImage:(UIInterfaceOrientation)interfaceOrientation;
    1.21 -@end
    1.22 -
    1.23 -@implementation SDL_splashviewcontroller
    1.24 -
    1.25  - (id)init
    1.26  {
    1.27      self = [super init];
     2.1 --- a/src/video/uikit/SDL_uikitmessagebox.m	Wed Jul 23 01:33:59 2014 -0300
     2.2 +++ b/src/video/uikit/SDL_uikitmessagebox.m	Wed Jul 23 03:05:31 2014 -0300
     2.3 @@ -30,17 +30,16 @@
     2.4  
     2.5  static SDL_bool s_showingMessageBox = SDL_FALSE;
     2.6  
     2.7 -@interface UIKit_UIAlertViewDelegate : NSObject <UIAlertViewDelegate> {
     2.8 -@private
     2.9 -    int *clickedButtonIndex;
    2.10 -}
    2.11 +@interface UIKit_UIAlertViewDelegate : NSObject <UIAlertViewDelegate>
    2.12  
    2.13  - (id)initWithButtonIndex:(int *)_buttonIndex;
    2.14  - (void)alertView:(UIAlertView *)alertView didDismissWithButtonIndex:(NSInteger)buttonIndex;
    2.15  
    2.16  @end
    2.17  
    2.18 -@implementation UIKit_UIAlertViewDelegate
    2.19 +@implementation UIKit_UIAlertViewDelegate {
    2.20 +    int *clickedButtonIndex;
    2.21 +}
    2.22  
    2.23  - (id)initWithButtonIndex:(int *)buttonIndex
    2.24  {
    2.25 @@ -48,7 +47,8 @@
    2.26      if (self == nil) {
    2.27          return nil;
    2.28      }
    2.29 -    self->clickedButtonIndex = buttonIndex;
    2.30 +
    2.31 +    clickedButtonIndex = buttonIndex;
    2.32  
    2.33      return self;
    2.34  }
     3.1 --- a/src/video/uikit/SDL_uikitopenglview.h	Wed Jul 23 01:33:59 2014 -0300
     3.2 +++ b/src/video/uikit/SDL_uikitopenglview.h	Wed Jul 23 03:05:31 2014 -0300
     3.3 @@ -29,38 +29,7 @@
     3.4      The view content is basically an EAGL surface you render your OpenGL scene into.
     3.5      Note that setting the view non-opaque will only work if the EAGL surface has an alpha channel.
     3.6   */
     3.7 -@interface SDL_uikitopenglview : SDL_uikitview {
     3.8 -
     3.9 -@private
    3.10 -    /* The pixel dimensions of the backbuffer */
    3.11 -    GLint backingWidth;
    3.12 -    GLint backingHeight;
    3.13 -
    3.14 -    EAGLContext *context;
    3.15 -
    3.16 -    /* OpenGL names for the renderbuffer and framebuffers used to render to this view */
    3.17 -    GLuint viewRenderbuffer, viewFramebuffer;
    3.18 -
    3.19 -    /* OpenGL name for the depth buffer that is attached to viewFramebuffer, if it exists (0 if it does not exist) */
    3.20 -    GLuint depthRenderbuffer;
    3.21 -
    3.22 -    /* format of depthRenderbuffer */
    3.23 -    GLenum depthBufferFormat;
    3.24 -
    3.25 -    id displayLink;
    3.26 -    int animationInterval;
    3.27 -    void (*animationCallback)(void*);
    3.28 -    void *animationCallbackParam;
    3.29 -}
    3.30 -
    3.31 -@property (nonatomic, retain, readonly) EAGLContext *context;
    3.32 -
    3.33 -/* The width and height of the drawable in pixels (as opposed to points.) */
    3.34 -@property (nonatomic, readonly) int backingWidth;
    3.35 -@property (nonatomic, readonly) int backingHeight;
    3.36 -
    3.37 -- (void)swapBuffers;
    3.38 -- (void)setCurrentContext;
    3.39 +@interface SDL_uikitopenglview : SDL_uikitview
    3.40  
    3.41  - (id)initWithFrame:(CGRect)frame
    3.42                scale:(CGFloat)scale
    3.43 @@ -75,11 +44,20 @@
    3.44         majorVersion:(int)majorVersion
    3.45           shareGroup:(EAGLSharegroup*)shareGroup;
    3.46  
    3.47 +@property (nonatomic, retain, readonly) EAGLContext *context;
    3.48 +
    3.49 +/* The width and height of the drawable in pixels (as opposed to points.) */
    3.50 +@property (nonatomic, readonly) int backingWidth;
    3.51 +@property (nonatomic, readonly) int backingHeight;
    3.52 +
    3.53 +- (void)swapBuffers;
    3.54 +- (void)setCurrentContext;
    3.55 +
    3.56  - (void)updateFrame;
    3.57  
    3.58  - (void)setAnimationCallback:(int)interval
    3.59 -    callback:(void (*)(void*))callback
    3.60 -    callbackParam:(void*)callbackParam;
    3.61 +                    callback:(void (*)(void*))callback
    3.62 +               callbackParam:(void*)callbackParam;
    3.63  
    3.64  - (void)startAnimation;
    3.65  - (void)stopAnimation;
     4.1 --- a/src/video/uikit/SDL_uikitopenglview.m	Wed Jul 23 01:33:59 2014 -0300
     4.2 +++ b/src/video/uikit/SDL_uikitopenglview.m	Wed Jul 23 03:05:31 2014 -0300
     4.3 @@ -28,12 +28,28 @@
     4.4  #include "SDL_uikitmessagebox.h"
     4.5  
     4.6  
     4.7 -@implementation SDL_uikitopenglview
     4.8 +@implementation SDL_uikitopenglview {
     4.9 +
    4.10 +    /* OpenGL names for the renderbuffer and framebuffers used to render to this view */
    4.11 +    GLuint viewRenderbuffer, viewFramebuffer;
    4.12 +
    4.13 +    /* OpenGL name for the depth buffer that is attached to viewFramebuffer, if it exists (0 if it does not exist) */
    4.14 +    GLuint depthRenderbuffer;
    4.15 +
    4.16 +    /* format of depthRenderbuffer */
    4.17 +    GLenum depthBufferFormat;
    4.18 +
    4.19 +    id displayLink;
    4.20 +    int animationInterval;
    4.21 +    void (*animationCallback)(void*);
    4.22 +    void *animationCallbackParam;
    4.23 +
    4.24 +}
    4.25  
    4.26  @synthesize context;
    4.27  
    4.28 -@synthesize backingWidth = backingWidth;
    4.29 -@synthesize backingHeight = backingHeight;
    4.30 +@synthesize backingWidth;
    4.31 +@synthesize backingHeight;
    4.32  
    4.33  + (Class)layerClass
    4.34  {
    4.35 @@ -53,8 +69,6 @@
    4.36         majorVersion:(int)majorVersion
    4.37           shareGroup:(EAGLSharegroup*)shareGroup
    4.38  {
    4.39 -    depthBufferFormat = 0;
    4.40 -
    4.41      if ((self = [super initWithFrame:frame])) {
    4.42          const BOOL useStencilBuffer = (stencilBits != 0);
    4.43          const BOOL useDepthBuffer = (depthBits != 0);
     5.1 --- a/src/video/uikit/SDL_uikitview.h	Wed Jul 23 01:33:59 2014 -0300
     5.2 +++ b/src/video/uikit/SDL_uikitview.h	Wed Jul 23 03:05:31 2014 -0300
     5.3 @@ -35,23 +35,10 @@
     5.4  #else
     5.5  @interface SDL_uikitview : UIView {
     5.6  #endif
     5.7 -
     5.8 -    SDL_TouchID touchId;
     5.9 -    UITouch *leftFingerDown;
    5.10 -#ifndef IPHONE_TOUCH_EFFICIENT_DANGEROUS
    5.11 -    UITouch *finger[MAX_SIMULTANEOUS_TOUCHES];
    5.12 -#endif
    5.13 -
    5.14 -#if SDL_IPHONE_KEYBOARD
    5.15 -    UITextField *textField;
    5.16 -    BOOL keyboardVisible;
    5.17 -    SDL_Rect textInputRect;
    5.18 -    int keyboardHeight;
    5.19 -#endif
    5.20 -
    5.21  @public
    5.22      SDL_uikitviewcontroller *viewcontroller;
    5.23  }
    5.24 +
    5.25  - (CGPoint)touchLocation:(UITouch *)touch shouldNormalize:(BOOL)normalize;
    5.26  - (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event;
    5.27  - (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event;
    5.28 @@ -61,7 +48,8 @@
    5.29  - (void)showKeyboard;
    5.30  - (void)hideKeyboard;
    5.31  - (void)initializeKeyboard;
    5.32 -@property (nonatomic, readonly) BOOL keyboardVisible;
    5.33 +
    5.34 +@property (nonatomic, readonly, assign, getter=isKeyboardVisible) BOOL keyboardVisible;
    5.35  @property (nonatomic, assign) SDL_Rect textInputRect;
    5.36  @property (nonatomic, assign) int keyboardHeight;
    5.37  
     6.1 --- a/src/video/uikit/SDL_uikitview.m	Wed Jul 23 01:33:59 2014 -0300
     6.2 +++ b/src/video/uikit/SDL_uikitview.m	Wed Jul 23 03:05:31 2014 -0300
     6.3 @@ -37,7 +37,19 @@
     6.4  
     6.5  void _uikit_keyboard_init();
     6.6  
     6.7 -@implementation SDL_uikitview
     6.8 +@implementation SDL_uikitview {
     6.9 +
    6.10 +    SDL_TouchID touchId;
    6.11 +    UITouch *leftFingerDown;
    6.12 +#ifndef IPHONE_TOUCH_EFFICIENT_DANGEROUS
    6.13 +    UITouch *finger[MAX_SIMULTANEOUS_TOUCHES];
    6.14 +#endif
    6.15 +
    6.16 +#if SDL_IPHONE_KEYBOARD
    6.17 +    UITextField *textField;
    6.18 +#endif
    6.19 +
    6.20 +}
    6.21  
    6.22  - (void)dealloc
    6.23  {
    6.24 @@ -66,7 +78,7 @@
    6.25      CGPoint point = [touch locationInView: self];
    6.26  
    6.27      if (normalize) {
    6.28 -        CGRect bounds = [self bounds];
    6.29 +        CGRect bounds = self.bounds;
    6.30          point.x /= bounds.size.width;
    6.31          point.y /= bounds.size.height;
    6.32      }
    6.33 @@ -122,7 +134,7 @@
    6.34  
    6.35          CGPoint locationInView = [self touchLocation:touch shouldNormalize:YES];
    6.36  #ifdef IPHONE_TOUCH_EFFICIENT_DANGEROUS
    6.37 -        SDL_SendTouch(touchId, (long)touch,
    6.38 +        SDL_SendTouch(touchId, (SDL_FingerID)((size_t)touch),
    6.39                        SDL_FALSE, locationInView.x, locationInView.y, 1.0f);
    6.40  #else
    6.41          int i;
    6.42 @@ -160,7 +172,7 @@
    6.43  
    6.44          CGPoint locationInView = [self touchLocation:touch shouldNormalize:YES];
    6.45  #ifdef IPHONE_TOUCH_EFFICIENT_DANGEROUS
    6.46 -        SDL_SendTouchMotion(touchId, (long)touch,
    6.47 +        SDL_SendTouchMotion(touchId, (SDL_FingerID)((size_t)touch),
    6.48                              locationInView.x, locationInView.y, 1.0f);
    6.49  #else
    6.50          int i;
    6.51 @@ -180,14 +192,9 @@
    6.52  */
    6.53  #if SDL_IPHONE_KEYBOARD
    6.54  
    6.55 -@synthesize textInputRect = textInputRect;
    6.56 -@synthesize keyboardHeight = keyboardHeight;
    6.57 -
    6.58 -/* Is the iPhone virtual keyboard visible onscreen? */
    6.59 -- (BOOL)keyboardVisible
    6.60 -{
    6.61 -    return keyboardVisible;
    6.62 -}
    6.63 +@synthesize textInputRect;
    6.64 +@synthesize keyboardHeight;
    6.65 +@synthesize keyboardVisible;
    6.66  
    6.67  /* Set ourselves up as a UITextFieldDelegate */
    6.68  - (void)initializeKeyboard
    6.69 @@ -337,7 +344,7 @@
    6.70          return 0;
    6.71      }
    6.72  
    6.73 -    return view.keyboardVisible;
    6.74 +    return view.isKeyboardVisible;
    6.75  }
    6.76  
    6.77  
     7.1 --- a/src/video/uikit/SDL_uikitviewcontroller.h	Wed Jul 23 01:33:59 2014 -0300
     7.2 +++ b/src/video/uikit/SDL_uikitviewcontroller.h	Wed Jul 23 03:05:31 2014 -0300
     7.3 @@ -23,12 +23,9 @@
     7.4  
     7.5  #include "../SDL_sysvideo.h"
     7.6  
     7.7 -@interface SDL_uikitviewcontroller : UIViewController {
     7.8 -@private
     7.9 -    SDL_Window *window;
    7.10 -}
    7.11 +@interface SDL_uikitviewcontroller : UIViewController
    7.12  
    7.13 -@property (nonatomic, readwrite) SDL_Window *window;
    7.14 +@property (nonatomic, assign) SDL_Window *window;
    7.15  
    7.16  - (id)initWithSDLWindow:(SDL_Window *)_window;
    7.17  - (void)loadView;
     8.1 --- a/src/video/uikit/SDL_uikitwindow.m	Wed Jul 23 01:33:59 2014 -0300
     8.2 +++ b/src/video/uikit/SDL_uikitwindow.m	Wed Jul 23 03:05:31 2014 -0300
     8.3 @@ -239,7 +239,6 @@
     8.4      SDL_DisplayData *displaydata = (SDL_DisplayData *) display->driverdata;
     8.5      SDL_WindowData *windowdata = (SDL_WindowData *) window->driverdata;
     8.6      SDL_uikitviewcontroller *viewcontroller = windowdata->viewcontroller;
     8.7 -    UIWindow *uiwindow = windowdata->uiwindow;
     8.8      CGRect bounds;
     8.9  
    8.10      if (fullscreen || (window->flags & SDL_WINDOW_BORDERLESS)) {