Minor Objective-C code tweaks. iOS-improvements
authorAlex Szpakowski <slime73@gmail.com>
Thu, 27 Nov 2014 20:25:54 -0400
branchiOS-improvements
changeset 95294bf9830d8153
parent 9528 6915f7db6791
child 9530 ac0885050d79
Minor Objective-C code tweaks.
src/video/uikit/SDL_uikitopengles.m
src/video/uikit/SDL_uikitopenglview.m
src/video/uikit/SDL_uikitvideo.m
src/video/uikit/SDL_uikitview.h
src/video/uikit/SDL_uikitview.m
src/video/uikit/SDL_uikitviewcontroller.m
src/video/uikit/SDL_uikitwindow.h
src/video/uikit/SDL_uikitwindow.m
     1.1 --- a/src/video/uikit/SDL_uikitopengles.m	Sun Nov 23 23:29:24 2014 -0400
     1.2 +++ b/src/video/uikit/SDL_uikitopengles.m	Thu Nov 27 20:25:54 2014 -0400
     1.3 @@ -58,7 +58,8 @@
     1.4      return 0;
     1.5  }
     1.6  
     1.7 -void UIKit_GL_GetDrawableSize(_THIS, SDL_Window * window, int * w, int * h)
     1.8 +void
     1.9 +UIKit_GL_GetDrawableSize(_THIS, SDL_Window * window, int * w, int * h)
    1.10  {
    1.11      @autoreleasepool {
    1.12          SDL_WindowData *data = (__bridge SDL_WindowData *)window->driverdata;
    1.13 @@ -157,16 +158,15 @@
    1.14              return NULL;
    1.15          }
    1.16  
    1.17 +        view.sdlwindow = window;
    1.18          data.view = view;
    1.19 -        view.viewcontroller = data.viewcontroller;
    1.20 -        if (view.viewcontroller != nil) {
    1.21 -            view.viewcontroller.view = view;
    1.22 -        }
    1.23 -        [uiwindow addSubview:view];
    1.24 +        data.viewcontroller.view = view;
    1.25  
    1.26 -        /* The view controller needs to be the root in order to control rotation on iOS 6.0 */
    1.27 +        /* The view controller needs to be the root in order to control rotation */
    1.28          if (uiwindow.rootViewController == nil) {
    1.29 -            uiwindow.rootViewController = view.viewcontroller;
    1.30 +            uiwindow.rootViewController = data.viewcontroller;
    1.31 +        } else {
    1.32 +            [uiwindow addSubview:view];
    1.33          }
    1.34  
    1.35          EAGLContext *context = view.context;
    1.36 @@ -199,17 +199,17 @@
    1.37              SDL_WindowData *data = (__bridge SDL_WindowData *) window->driverdata;
    1.38              SDL_uikitopenglview *view = data.view;
    1.39              if (view.context == eaglcontext) {
    1.40 -                /* the delegate has retained the view, this will release him */
    1.41 -                if (view.viewcontroller) {
    1.42 +                /* the view controller has retained the view */
    1.43 +                if (data.viewcontroller) {
    1.44                      UIWindow *uiwindow = (UIWindow *)view.superview;
    1.45 -                    if (uiwindow.rootViewController == view.viewcontroller) {
    1.46 +                    if (uiwindow.rootViewController == data.viewcontroller) {
    1.47                          uiwindow.rootViewController = nil;
    1.48                      }
    1.49 -                    view.viewcontroller.view = nil;
    1.50 -                    view.viewcontroller = nil;
    1.51 +                    data.viewcontroller.view = nil;
    1.52                  }
    1.53 +
    1.54                  [view removeFromSuperview];
    1.55 -
    1.56 +                view.sdlwindow = NULL;
    1.57                  data.view = nil;
    1.58                  return;
    1.59              }
    1.60 @@ -217,7 +217,8 @@
    1.61      }
    1.62  }
    1.63  
    1.64 -Uint32 SDL_iPhoneGetViewRenderbuffer(SDL_Window * window)
    1.65 +Uint32
    1.66 +SDL_iPhoneGetViewRenderbuffer(SDL_Window * window)
    1.67  {
    1.68      if (!window) {
    1.69          SDL_SetError("Invalid window");
    1.70 @@ -234,7 +235,8 @@
    1.71      }
    1.72  }
    1.73  
    1.74 -Uint32 SDL_iPhoneGetViewFramebuffer(SDL_Window * window)
    1.75 +Uint32
    1.76 +SDL_iPhoneGetViewFramebuffer(SDL_Window * window)
    1.77  {
    1.78      if (!window) {
    1.79          SDL_SetError("Invalid window");
     2.1 --- a/src/video/uikit/SDL_uikitopenglview.m	Sun Nov 23 23:29:24 2014 -0400
     2.2 +++ b/src/video/uikit/SDL_uikitopenglview.m	Thu Nov 27 20:25:54 2014 -0400
     2.3 @@ -46,7 +46,6 @@
     2.4      int animationInterval;
     2.5      void (*animationCallback)(void*);
     2.6      void *animationCallbackParam;
     2.7 -
     2.8  }
     2.9  
    2.10  @synthesize context;
     3.1 --- a/src/video/uikit/SDL_uikitvideo.m	Sun Nov 23 23:29:24 2014 -0400
     3.2 +++ b/src/video/uikit/SDL_uikitvideo.m	Thu Nov 27 20:25:54 2014 -0400
     3.3 @@ -75,6 +75,7 @@
     3.4      device->SetDisplayMode = UIKit_SetDisplayMode;
     3.5      device->PumpEvents = UIKit_PumpEvents;
     3.6      device->CreateWindow = UIKit_CreateWindow;
     3.7 +    device->SetWindowTitle = UIKit_SetWindowTitle;
     3.8      device->ShowWindow = UIKit_ShowWindow;
     3.9      device->HideWindow = UIKit_HideWindow;
    3.10      device->RaiseWindow = UIKit_RaiseWindow;
     4.1 --- a/src/video/uikit/SDL_uikitview.h	Sun Nov 23 23:29:24 2014 -0400
     4.2 +++ b/src/video/uikit/SDL_uikitview.h	Thu Nov 27 20:25:54 2014 -0400
     4.3 @@ -20,7 +20,7 @@
     4.4  */
     4.5  
     4.6  #import <UIKit/UIKit.h>
     4.7 -#import "SDL_uikitviewcontroller.h"
     4.8 +#include "../SDL_sysvideo.h"
     4.9  
    4.10  #include "SDL_touch.h"
    4.11  
    4.12 @@ -30,7 +30,7 @@
    4.13  @interface SDL_uikitview : UIView
    4.14  #endif
    4.15  
    4.16 -@property (nonatomic, weak) SDL_uikitviewcontroller *viewcontroller;
    4.17 +@property (nonatomic, assign) SDL_Window *sdlwindow;
    4.18  
    4.19  - (CGPoint)touchLocation:(UITouch *)touch shouldNormalize:(BOOL)normalize;
    4.20  - (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event;
     5.1 --- a/src/video/uikit/SDL_uikitview.m	Sun Nov 23 23:29:24 2014 -0400
     5.2 +++ b/src/video/uikit/SDL_uikitview.m	Thu Nov 27 20:25:54 2014 -0400
     5.3 @@ -46,7 +46,7 @@
     5.4  
     5.5  }
     5.6  
     5.7 -@synthesize viewcontroller;
     5.8 +@synthesize sdlwindow;
     5.9  
    5.10  - (id)initWithFrame:(CGRect)frame
    5.11  {
    5.12 @@ -92,10 +92,10 @@
    5.13              CGPoint locationInView = [self touchLocation:touch shouldNormalize:NO];
    5.14  
    5.15              /* send moved event */
    5.16 -            SDL_SendMouseMotion(self.viewcontroller.window, SDL_TOUCH_MOUSEID, 0, locationInView.x, locationInView.y);
    5.17 +            SDL_SendMouseMotion(sdlwindow, SDL_TOUCH_MOUSEID, 0, locationInView.x, locationInView.y);
    5.18  
    5.19              /* send mouse down event */
    5.20 -            SDL_SendMouseButton(self.viewcontroller.window, SDL_TOUCH_MOUSEID, SDL_PRESSED, SDL_BUTTON_LEFT);
    5.21 +            SDL_SendMouseButton(sdlwindow, SDL_TOUCH_MOUSEID, SDL_PRESSED, SDL_BUTTON_LEFT);
    5.22  
    5.23              leftFingerDown = touch;
    5.24          }
    5.25 @@ -111,7 +111,7 @@
    5.26      for (UITouch *touch in touches) {
    5.27          if (touch == leftFingerDown) {
    5.28              /* send mouse up */
    5.29 -            SDL_SendMouseButton(self.viewcontroller.window, SDL_TOUCH_MOUSEID, SDL_RELEASED, SDL_BUTTON_LEFT);
    5.30 +            SDL_SendMouseButton(sdlwindow, SDL_TOUCH_MOUSEID, SDL_RELEASED, SDL_BUTTON_LEFT);
    5.31              leftFingerDown = nil;
    5.32          }
    5.33  
    5.34 @@ -138,7 +138,7 @@
    5.35              CGPoint locationInView = [self touchLocation:touch shouldNormalize:NO];
    5.36  
    5.37              /* send moved event */
    5.38 -            SDL_SendMouseMotion(self.viewcontroller.window, SDL_TOUCH_MOUSEID, 0, locationInView.x, locationInView.y);
    5.39 +            SDL_SendMouseMotion(sdlwindow, SDL_TOUCH_MOUSEID, 0, locationInView.x, locationInView.y);
    5.40          }
    5.41  
    5.42          CGPoint locationInView = [self touchLocation:touch shouldNormalize:YES];
     6.1 --- a/src/video/uikit/SDL_uikitviewcontroller.m	Sun Nov 23 23:29:24 2014 -0400
     6.2 +++ b/src/video/uikit/SDL_uikitviewcontroller.m	Thu Nov 27 20:25:54 2014 -0400
     6.3 @@ -73,11 +73,7 @@
     6.4  
     6.5  - (BOOL)prefersStatusBarHidden
     6.6  {
     6.7 -    if (window->flags & (SDL_WINDOW_FULLSCREEN|SDL_WINDOW_BORDERLESS)) {
     6.8 -        return YES;
     6.9 -    } else {
    6.10 -        return NO;
    6.11 -    }
    6.12 +    return (window->flags & (SDL_WINDOW_FULLSCREEN|SDL_WINDOW_BORDERLESS)) != 0;
    6.13  }
    6.14  
    6.15  - (UIStatusBarStyle)preferredStatusBarStyle
     7.1 --- a/src/video/uikit/SDL_uikitwindow.h	Sun Nov 23 23:29:24 2014 -0400
     7.2 +++ b/src/video/uikit/SDL_uikitwindow.h	Thu Nov 27 20:25:54 2014 -0400
     7.3 @@ -27,6 +27,7 @@
     7.4  #import "SDL_uikitviewcontroller.h"
     7.5  
     7.6  extern int UIKit_CreateWindow(_THIS, SDL_Window * window);
     7.7 +extern void UIKit_SetWindowTitle(_THIS, SDL_Window * window);
     7.8  extern void UIKit_ShowWindow(_THIS, SDL_Window * window);
     7.9  extern void UIKit_HideWindow(_THIS, SDL_Window * window);
    7.10  extern void UIKit_RaiseWindow(_THIS, SDL_Window * window);
     8.1 --- a/src/video/uikit/SDL_uikitwindow.m	Sun Nov 23 23:29:24 2014 -0400
     8.2 +++ b/src/video/uikit/SDL_uikitwindow.m	Thu Nov 27 20:25:54 2014 -0400
     8.3 @@ -55,7 +55,6 @@
     8.4      SDL_VideoDisplay *display = SDL_GetDisplayForWindow(window);
     8.5      SDL_DisplayData *displaydata = (__bridge SDL_DisplayData *) display->driverdata;
     8.6  
     8.7 -    /* Allocate the window data */
     8.8      SDL_WindowData *data = [[SDL_WindowData alloc] init];
     8.9      if (!data) {
    8.10          return SDL_OutOfMemory();
    8.11 @@ -67,7 +66,6 @@
    8.12      {
    8.13          CGRect frame = UIKit_ComputeViewFrame(window, displaydata.uiscreen);
    8.14  
    8.15 -        /* Get frame dimensions */
    8.16          int width = (int) frame.size.width;
    8.17          int height = (int) frame.size.height;
    8.18  
    8.19 @@ -114,7 +112,7 @@
    8.20       * appropriate.
    8.21       */
    8.22      data.viewcontroller = [[SDL_uikitviewcontroller alloc] initWithSDLWindow:window];
    8.23 -    data.viewcontroller.title = @"SDL App";  /* !!! FIXME: hook up SDL_SetWindowTitle() */
    8.24 +    data.viewcontroller.title = @"";
    8.25  
    8.26      return 0;
    8.27  }
    8.28 @@ -186,11 +184,9 @@
    8.29              } else {
    8.30                  if (!(orientations & (UIInterfaceOrientationMaskPortrait|UIInterfaceOrientationMaskPortraitUpsideDown))) {
    8.31                      UIInterfaceOrientation orient = UIInterfaceOrientationLandscapeLeft;
    8.32 -
    8.33                      if (orientations & UIInterfaceOrientationMaskLandscapeRight) {
    8.34                          orient = UIInterfaceOrientationLandscapeRight;
    8.35                      }
    8.36 -
    8.37                      [app setStatusBarOrientation:orient animated:NO];
    8.38                  }
    8.39              }
    8.40 @@ -212,13 +208,25 @@
    8.41          if (SetupWindowData(_this, window, uiwindow, SDL_TRUE) < 0) {
    8.42              return -1;
    8.43          }
    8.44 -
    8.45      }
    8.46  
    8.47      return 1;
    8.48  }
    8.49  
    8.50  void
    8.51 +UIKit_SetWindowTitle(_THIS, SDL_Window * window)
    8.52 +{
    8.53 +    @autoreleasepool {
    8.54 +        SDL_uikitviewcontroller *vc = ((__bridge SDL_WindowData *) window->driverdata).viewcontroller;
    8.55 +        if (window->title) {
    8.56 +            vc.title = @(window->title);
    8.57 +        } else {
    8.58 +            vc.title = @"";
    8.59 +        }
    8.60 +    }
    8.61 +}
    8.62 +
    8.63 +void
    8.64  UIKit_ShowWindow(_THIS, SDL_Window * window)
    8.65  {
    8.66      @autoreleasepool {
    8.67 @@ -275,16 +283,16 @@
    8.68      [windowdata.view layoutIfNeeded];
    8.69  
    8.70      /* Get frame dimensions */
    8.71 -    int width  = (int) frame.size.width;
    8.72 -    int height = (int) frame.size.height;
    8.73 +    int w = (int) frame.size.width;
    8.74 +    int h = (int) frame.size.height;
    8.75  
    8.76      /* We can pick either width or height here and we'll rotate the
    8.77       screen to match, so we pick the closest to what we wanted.
    8.78       */
    8.79      if (window->w >= window->h) {
    8.80 -        SDL_SendWindowEvent(window, SDL_WINDOWEVENT_RESIZED, SDL_max(width, height), SDL_min(width, height));
    8.81 +        SDL_SendWindowEvent(window, SDL_WINDOWEVENT_RESIZED, SDL_max(w, h), SDL_min(w, h));
    8.82      } else {
    8.83 -        SDL_SendWindowEvent(window, SDL_WINDOWEVENT_RESIZED, SDL_min(width, height), SDL_max(width, height));
    8.84 +        SDL_SendWindowEvent(window, SDL_WINDOWEVENT_RESIZED, SDL_min(w, h), SDL_max(w, h));
    8.85      }
    8.86  }
    8.87  
    8.88 @@ -312,7 +320,6 @@
    8.89              CFRelease(window->driverdata);
    8.90          }
    8.91      }
    8.92 -
    8.93      window->driverdata = NULL;
    8.94  }
    8.95