Skip to content

Commit

Permalink
More cleanup of the iOS Objective-C code.
Browse files Browse the repository at this point in the history
  • Loading branch information
slime73 committed Jul 23, 2014
1 parent 6d552ca commit ef0490a
Show file tree
Hide file tree
Showing 8 changed files with 69 additions and 85 deletions.
13 changes: 7 additions & 6 deletions src/video/uikit/SDL_uikitappdelegate.m
Expand Up @@ -75,16 +75,17 @@ int main(int argc, char **argv)
[UIApplication sharedApplication].idleTimerDisabled = disable;
}

@interface SDL_splashviewcontroller : UIViewController {
UIImageView *splash;
UIImage *splashPortrait;
UIImage *splashLandscape;
}
@interface SDL_splashviewcontroller : UIViewController

- (void)updateSplashImage:(UIInterfaceOrientation)interfaceOrientation;

@end

@implementation SDL_splashviewcontroller
@implementation SDL_splashviewcontroller {
UIImageView *splash;
UIImage *splashPortrait;
UIImage *splashLandscape;
}

- (id)init
{
Expand Down
12 changes: 6 additions & 6 deletions src/video/uikit/SDL_uikitmessagebox.m
Expand Up @@ -30,25 +30,25 @@

static SDL_bool s_showingMessageBox = SDL_FALSE;

@interface UIKit_UIAlertViewDelegate : NSObject <UIAlertViewDelegate> {
@private
int *clickedButtonIndex;
}
@interface UIKit_UIAlertViewDelegate : NSObject <UIAlertViewDelegate>

- (id)initWithButtonIndex:(int *)_buttonIndex;
- (void)alertView:(UIAlertView *)alertView didDismissWithButtonIndex:(NSInteger)buttonIndex;

@end

@implementation UIKit_UIAlertViewDelegate
@implementation UIKit_UIAlertViewDelegate {
int *clickedButtonIndex;
}

- (id)initWithButtonIndex:(int *)buttonIndex
{
self = [self init];
if (self == nil) {
return nil;
}
self->clickedButtonIndex = buttonIndex;

clickedButtonIndex = buttonIndex;

return self;
}
Expand Down
46 changes: 12 additions & 34 deletions src/video/uikit/SDL_uikitopenglview.h
Expand Up @@ -29,38 +29,7 @@
The view content is basically an EAGL surface you render your OpenGL scene into.
Note that setting the view non-opaque will only work if the EAGL surface has an alpha channel.
*/
@interface SDL_uikitopenglview : SDL_uikitview {

@private
/* The pixel dimensions of the backbuffer */
GLint backingWidth;
GLint backingHeight;

EAGLContext *context;

/* OpenGL names for the renderbuffer and framebuffers used to render to this view */
GLuint viewRenderbuffer, viewFramebuffer;

/* OpenGL name for the depth buffer that is attached to viewFramebuffer, if it exists (0 if it does not exist) */
GLuint depthRenderbuffer;

/* format of depthRenderbuffer */
GLenum depthBufferFormat;

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

@property (nonatomic, retain, readonly) EAGLContext *context;

/* The width and height of the drawable in pixels (as opposed to points.) */
@property (nonatomic, readonly) int backingWidth;
@property (nonatomic, readonly) int backingHeight;

- (void)swapBuffers;
- (void)setCurrentContext;
@interface SDL_uikitopenglview : SDL_uikitview

- (id)initWithFrame:(CGRect)frame
scale:(CGFloat)scale
Expand All @@ -75,11 +44,20 @@
majorVersion:(int)majorVersion
shareGroup:(EAGLSharegroup*)shareGroup;

@property (nonatomic, retain, readonly) EAGLContext *context;

/* The width and height of the drawable in pixels (as opposed to points.) */
@property (nonatomic, readonly) int backingWidth;
@property (nonatomic, readonly) int backingHeight;

- (void)swapBuffers;
- (void)setCurrentContext;

- (void)updateFrame;

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

- (void)startAnimation;
- (void)stopAnimation;
Expand Down
24 changes: 19 additions & 5 deletions src/video/uikit/SDL_uikitopenglview.m
Expand Up @@ -28,12 +28,28 @@
#include "SDL_uikitmessagebox.h"


@implementation SDL_uikitopenglview
@implementation SDL_uikitopenglview {

/* OpenGL names for the renderbuffer and framebuffers used to render to this view */
GLuint viewRenderbuffer, viewFramebuffer;

/* OpenGL name for the depth buffer that is attached to viewFramebuffer, if it exists (0 if it does not exist) */
GLuint depthRenderbuffer;

/* format of depthRenderbuffer */
GLenum depthBufferFormat;

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

}

@synthesize context;

@synthesize backingWidth = backingWidth;
@synthesize backingHeight = backingHeight;
@synthesize backingWidth;
@synthesize backingHeight;

+ (Class)layerClass
{
Expand All @@ -53,8 +69,6 @@ - (id)initWithFrame:(CGRect)frame
majorVersion:(int)majorVersion
shareGroup:(EAGLSharegroup*)shareGroup
{
depthBufferFormat = 0;

if ((self = [super initWithFrame:frame])) {
const BOOL useStencilBuffer = (stencilBits != 0);
const BOOL useDepthBuffer = (depthBits != 0);
Expand Down
18 changes: 3 additions & 15 deletions src/video/uikit/SDL_uikitview.h
Expand Up @@ -35,23 +35,10 @@
#else
@interface SDL_uikitview : UIView {
#endif

SDL_TouchID touchId;
UITouch *leftFingerDown;
#ifndef IPHONE_TOUCH_EFFICIENT_DANGEROUS
UITouch *finger[MAX_SIMULTANEOUS_TOUCHES];
#endif

#if SDL_IPHONE_KEYBOARD
UITextField *textField;
BOOL keyboardVisible;
SDL_Rect textInputRect;
int keyboardHeight;
#endif

@public
SDL_uikitviewcontroller *viewcontroller;
}

- (CGPoint)touchLocation:(UITouch *)touch shouldNormalize:(BOOL)normalize;
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event;
- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event;
Expand All @@ -61,7 +48,8 @@
- (void)showKeyboard;
- (void)hideKeyboard;
- (void)initializeKeyboard;
@property (nonatomic, readonly) BOOL keyboardVisible;

@property (nonatomic, readonly, assign, getter=isKeyboardVisible) BOOL keyboardVisible;
@property (nonatomic, assign) SDL_Rect textInputRect;
@property (nonatomic, assign) int keyboardHeight;

Expand Down
33 changes: 20 additions & 13 deletions src/video/uikit/SDL_uikitview.m
Expand Up @@ -37,7 +37,19 @@

void _uikit_keyboard_init();

@implementation SDL_uikitview
@implementation SDL_uikitview {

SDL_TouchID touchId;
UITouch *leftFingerDown;
#ifndef IPHONE_TOUCH_EFFICIENT_DANGEROUS
UITouch *finger[MAX_SIMULTANEOUS_TOUCHES];
#endif

#if SDL_IPHONE_KEYBOARD
UITextField *textField;
#endif

}

- (void)dealloc
{
Expand Down Expand Up @@ -66,7 +78,7 @@ - (CGPoint)touchLocation:(UITouch *)touch shouldNormalize:(BOOL)normalize
CGPoint point = [touch locationInView: self];

if (normalize) {
CGRect bounds = [self bounds];
CGRect bounds = self.bounds;
point.x /= bounds.size.width;
point.y /= bounds.size.height;
}
Expand Down Expand Up @@ -122,7 +134,7 @@ - (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event

CGPoint locationInView = [self touchLocation:touch shouldNormalize:YES];
#ifdef IPHONE_TOUCH_EFFICIENT_DANGEROUS
SDL_SendTouch(touchId, (long)touch,
SDL_SendTouch(touchId, (SDL_FingerID)((size_t)touch),
SDL_FALSE, locationInView.x, locationInView.y, 1.0f);
#else
int i;
Expand Down Expand Up @@ -160,7 +172,7 @@ - (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event

CGPoint locationInView = [self touchLocation:touch shouldNormalize:YES];
#ifdef IPHONE_TOUCH_EFFICIENT_DANGEROUS
SDL_SendTouchMotion(touchId, (long)touch,
SDL_SendTouchMotion(touchId, (SDL_FingerID)((size_t)touch),
locationInView.x, locationInView.y, 1.0f);
#else
int i;
Expand All @@ -180,14 +192,9 @@ - (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event
*/
#if SDL_IPHONE_KEYBOARD

@synthesize textInputRect = textInputRect;
@synthesize keyboardHeight = keyboardHeight;

/* Is the iPhone virtual keyboard visible onscreen? */
- (BOOL)keyboardVisible
{
return keyboardVisible;
}
@synthesize textInputRect;
@synthesize keyboardHeight;
@synthesize keyboardVisible;

/* Set ourselves up as a UITextFieldDelegate */
- (void)initializeKeyboard
Expand Down Expand Up @@ -337,7 +344,7 @@ SDL_bool UIKit_IsScreenKeyboardShown(_THIS, SDL_Window *window)
return 0;
}

return view.keyboardVisible;
return view.isKeyboardVisible;
}


Expand Down
7 changes: 2 additions & 5 deletions src/video/uikit/SDL_uikitviewcontroller.h
Expand Up @@ -23,12 +23,9 @@

#include "../SDL_sysvideo.h"

@interface SDL_uikitviewcontroller : UIViewController {
@private
SDL_Window *window;
}
@interface SDL_uikitviewcontroller : UIViewController

@property (nonatomic, readwrite) SDL_Window *window;
@property (nonatomic, assign) SDL_Window *window;

- (id)initWithSDLWindow:(SDL_Window *)_window;
- (void)loadView;
Expand Down
1 change: 0 additions & 1 deletion src/video/uikit/SDL_uikitwindow.m
Expand Up @@ -239,7 +239,6 @@ static int SetupWindowData(_THIS, SDL_Window *window, UIWindow *uiwindow, SDL_bo
SDL_DisplayData *displaydata = (SDL_DisplayData *) display->driverdata;
SDL_WindowData *windowdata = (SDL_WindowData *) window->driverdata;
SDL_uikitviewcontroller *viewcontroller = windowdata->viewcontroller;
UIWindow *uiwindow = windowdata->uiwindow;
CGRect bounds;

if (fullscreen || (window->flags & SDL_WINDOW_BORDERLESS)) {
Expand Down

0 comments on commit ef0490a

Please sign in to comment.