Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Objective-C/C++ codes to supporting ARC #6889

Merged
merged 23 commits into from
May 17, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions addons/ofxiOS/src/core/ofxiOSAppDelegate.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,10 @@
NSInteger currentScreenIndex;
}

@property (nonatomic, retain) UIWindow * window;
@property (nonatomic, retain) UIWindow * externalWindow;
@property (nonatomic, retain) UIViewController * uiViewController;
@property (readonly, assign) NSInteger currentScreenIndex;
@property (nonatomic, strong) UIWindow * window;
@property (nonatomic, strong) UIWindow * externalWindow;
@property (nonatomic, strong) UIViewController * uiViewController;
@property (readonly) NSInteger currentScreenIndex;

- (BOOL)application:(UIApplication*)application
handleOpenURL:(NSURL*)url;
Expand Down
58 changes: 34 additions & 24 deletions addons/ofxiOS/src/core/ofxiOSAppDelegate.mm
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,13 @@
*
* ***********************************************************************/

#include "ofxiOSAppDelegate.h"
#import "ofxiOSAppDelegate.h"

#if TARGET_OS_IOS || (TARGET_OS_IPHONE && !TARGET_OS_TV)

#include "ofxiOSViewController.h"
#include "ofxiOSExternalDisplay.h"
#import "ofxiOSViewController.h"
#import "ofxiOSGLKViewController.h"
#import "ofxiOSExternalDisplay.h"
#include "ofxiOSExtras.h"
#include "ofxiOSAlerts.h"
#include "ofxiOSEAGLView.h"
Expand All @@ -45,22 +46,17 @@

@implementation ofxiOSAppDelegate

@synthesize window;
@synthesize externalWindow;
@synthesize currentScreenIndex;

@synthesize uiViewController;

- (void)dealloc {
self.window = nil;
self.externalWindow = nil;
self.uiViewController = nil;
[super dealloc];
}

- (void)applicationDidFinishLaunching:(UIApplication *)application {

self.window = [[[UIWindow alloc] initWithFrame: [[UIScreen mainScreen] bounds]] autorelease];
self.window = [[UIWindow alloc] initWithFrame: [[UIScreen mainScreen] bounds]];
[self.window makeKeyAndVisible];

currentScreenIndex = 0;
Expand Down Expand Up @@ -145,11 +141,11 @@ - (void)applicationDidFinishLaunching:(UIApplication *)application {
case METAL_KIT:
NSLog(@"No MetalKit yet supported for openFrameworks: Falling back to GLKit");
case GL_KIT:
self.uiViewController = (UIViewController*)[[[ofxiOSGLKViewController alloc] initWithFrame:frame app:(ofxiOSApp *)ofGetAppPtr() sharegroup:nil] autorelease];
self.uiViewController = (UIViewController *)[[ofxiOSGLKViewController alloc] initWithFrame:frame app:(ofxiOSApp *)ofGetAppPtr() sharegroup:nil];
break;
case CORE_ANIMATION:
default:
self.uiViewController = [[[ofxiOSViewController alloc] initWithFrame:frame app:(ofxiOSApp *)ofGetAppPtr() sharegroup:nil] autorelease];
self.uiViewController = [[ofxiOSViewController alloc] initWithFrame:frame app:(ofxiOSApp *)ofGetAppPtr() sharegroup:nil];
break;

}
Expand All @@ -172,14 +168,22 @@ - (void)applicationDidFinishLaunching:(UIApplication *)application {
}

if(!bDoesHWOrientation) {
if([self.uiViewController respondsToSelector:@selector(rotateToInterfaceOrientation:animated:)]) {
[self.uiViewController rotateToInterfaceOrientation:UIInterfaceOrientationPortrait animated:false];
}
if([self.uiViewController isKindOfClass:ofxiOSViewController.class]) {
ofxiOSViewController *controller = (ofxiOSViewController*)self.uiViewController;
[controller rotateToInterfaceOrientation:UIInterfaceOrientationPortrait animated:false];
} else if([self.uiViewController isKindOfClass:ofxiOSGLKViewController.class]) {
ofxiOSGLKViewController *controller = (ofxiOSGLKViewController *)self.uiViewController;
[controller rotateToInterfaceOrientation:UIInterfaceOrientationPortrait animated:false];
}
} else {
[[UIApplication sharedApplication] setStatusBarOrientation:interfaceOrientation animated:NO];
if([self.uiViewController respondsToSelector:@selector(rotateToInterfaceOrientation:animated:)]) {
[self.uiViewController rotateToInterfaceOrientation:interfaceOrientation animated:false];
}
if([self.uiViewController isKindOfClass:ofxiOSViewController.class]) {
ofxiOSViewController *controller = (ofxiOSViewController*)self.uiViewController;
[controller rotateToInterfaceOrientation:UIInterfaceOrientationPortrait animated:false];
} else if([self.uiViewController isKindOfClass:ofxiOSGLKViewController.class]) {
ofxiOSGLKViewController *controller = (ofxiOSGLKViewController *)self.uiViewController;
[controller rotateToInterfaceOrientation:UIInterfaceOrientationPortrait animated:false];
}
ofSetOrientation(requested);
}

Expand Down Expand Up @@ -239,11 +243,17 @@ - (void)receivedRotate:(NSNotification*)notification {
if( [[[UIDevice currentDevice] systemVersion] compare:@"8.0" options:NSNumericSearch] == NSOrderedAscending ) {
//iOS7-
if(deviceOrientation != UIDeviceOrientationUnknown && deviceOrientation != UIDeviceOrientationFaceUp && deviceOrientation != UIDeviceOrientationFaceDown ) {
if([self.uiViewController respondsToSelector:@selector(isReadyToRotate)]) {
if([self.uiViewController isReadyToRotate]) {
ofxiOSAlerts.deviceOrientationChanged( deviceOrientation );
}
}
if([self.uiViewController isKindOfClass:ofxiOSViewController.class]) {
ofxiOSViewController *controller = (ofxiOSViewController*)self.uiViewController;
if([controller isReadyToRotate]) {
ofxiOSAlerts.deviceOrientationChanged( deviceOrientation );
}
} else if([self.uiViewController isKindOfClass:ofxiOSGLKViewController.class]) {
ofxiOSGLKViewController *controller = (ofxiOSGLKViewController *)self.uiViewController;
if([controller isReadyToRotate]) {
ofxiOSAlerts.deviceOrientationChanged( deviceOrientation );
}
}
}
}else {
ofxiOSAlerts.deviceOrientationChanged( deviceOrientation );
Expand Down Expand Up @@ -293,7 +303,7 @@ - (BOOL)createExternalWindowWithPreferredMode {
externalScreenFrame = CGRectZero;
externalScreenFrame.size = CGSizeMake(w, h);

self.externalWindow = [[[UIWindow alloc] initWithFrame:externalScreenFrame] autorelease];
self.externalWindow = [[UIWindow alloc] initWithFrame:externalScreenFrame];
self.externalWindow.screen = externalScreen;
self.externalWindow.clipsToBounds = YES;
self.externalWindow.hidden = NO;
Expand Down Expand Up @@ -331,7 +341,7 @@ - (BOOL)createExternalWindowWithScreenModeIndex:(NSInteger)screenModeIndex {
externalScreenFrame = CGRectZero;
externalScreenFrame.size = CGSizeMake(w, h);

self.externalWindow = [[[UIWindow alloc] initWithFrame:externalScreenFrame] autorelease];
self.externalWindow = [[UIWindow alloc] initWithFrame:externalScreenFrame];
self.externalWindow.screen = externalScreen;
self.externalWindow.clipsToBounds = YES;
self.externalWindow.hidden = NO;
Expand Down
6 changes: 3 additions & 3 deletions addons/ofxiOS/src/core/ofxiOSEAGLView.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class ofAppiOSWindow;
@interface ofxiOSEAGLView : EAGLView {

@protected
NSMutableDictionary * activeTouches;
NSMutableDictionary<NSValue *, NSNumber *> *activeTouches;
glm::vec2 * screenSize; // because glm::vec2 is forward declared,
glm::vec2 * windowSize; // these values have to be pointers.
glm::vec2 * windowPos;
Expand All @@ -29,8 +29,8 @@ class ofAppiOSWindow;

+ (ofxiOSEAGLView *) getInstance;

- (id)initWithFrame:(CGRect)frame andApp:(ofxiOSApp *)app;
- (id)initWithFrame:(CGRect)frame andApp:(ofxiOSApp *)app sharegroup:(EAGLSharegroup *)sharegroup;
- (instancetype)initWithFrame:(CGRect)frame andApp:(ofxiOSApp *)app;
- (instancetype)initWithFrame:(CGRect)frame andApp:(ofxiOSApp *)app sharegroup:(EAGLSharegroup *)sharegroup;
- (void)setup;
- (void)updateDimensions;
- (void)destroy;
Expand Down
27 changes: 12 additions & 15 deletions addons/ofxiOS/src/core/ofxiOSEAGLView.mm
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,11 @@ + (ofxiOSEAGLView *) getInstance {
return _instanceRef;
}

- (id)initWithFrame:(CGRect)frame andApp:(ofxiOSApp *)appPtr {
[self initWithFrame:frame andApp:appPtr sharegroup:nil];
return self;
- (instancetype)initWithFrame:(CGRect)frame andApp:(ofxiOSApp *)appPtr {
return [self initWithFrame:frame andApp:appPtr sharegroup:nil];
}

- (id)initWithFrame:(CGRect)frame andApp:(ofxiOSApp *)appPtr sharegroup:(EAGLSharegroup *)sharegroup {
- (instancetype)initWithFrame:(CGRect)frame andApp:(ofxiOSApp *)appPtr sharegroup:(EAGLSharegroup *)sharegroup {

window = dynamic_pointer_cast<ofAppiOSWindow>(ofGetMainLoop()->getCurrentWindow());

Expand Down Expand Up @@ -128,8 +127,7 @@ - (void)destroy {
app = NULL;
window = NULL;

[activeTouches release];

activeTouches = nil;
delete screenSize;
screenSize = NULL;
delete windowSize;
Expand All @@ -146,7 +144,6 @@ - (void)destroy {

- (void)dealloc {
[self destroy];
[super dealloc];
}

- (void)layoutSubviews {
Expand Down Expand Up @@ -248,7 +245,7 @@ -(void) resetTouches {
[activeTouches removeAllObjects];
}

- (void)touchesBegan:(NSSet *)touches
- (void)touchesBegan:(NSSet<UITouch *> *)touches
withEvent:(UIEvent *)event{

if(!bInit || !bSetup) {
Expand All @@ -259,12 +256,12 @@ - (void)touchesBegan:(NSSet *)touches

for(UITouch *touch in touches) {
int touchIndex = 0;
while([[activeTouches allValues] containsObject:[NSNumber numberWithInt:touchIndex]]){
while([[activeTouches allValues] containsObject:@(touchIndex)]){
touchIndex++;
}

[activeTouches setObject:[NSNumber numberWithInt:touchIndex] forKey:[NSValue valueWithPointer:touch]];

[activeTouches setObject:[NSNumber numberWithInt:touchIndex]
forKey:[NSValue valueWithPointer:(__bridge void *)touch]];
CGPoint touchPoint = [touch locationInView:self];

touchPoint.x *= scaleFactor; // this has to be done because retina still returns points in 320x240 but with high percision
Expand Down Expand Up @@ -300,7 +297,7 @@ - (void)touchesMoved:(NSSet *)touches
}

for(UITouch *touch in touches){
int touchIndex = [[activeTouches objectForKey:[NSValue valueWithPointer:touch]] intValue];
int touchIndex = [[activeTouches objectForKey:[NSValue valueWithPointer:(__bridge void *)touch]] intValue];

CGPoint touchPoint = [touch locationInView:self];

Expand Down Expand Up @@ -332,9 +329,9 @@ - (void)touchesEnded:(NSSet *)touches
}

for(UITouch *touch in touches){
int touchIndex = [[activeTouches objectForKey:[NSValue valueWithPointer:touch]] intValue];
int touchIndex = [[activeTouches objectForKey:[NSValue valueWithPointer:(__bridge void *)touch]] intValue];

[activeTouches removeObjectForKey:[NSValue valueWithPointer:touch]];
[activeTouches removeObjectForKey:[NSValue valueWithPointer:(__bridge void *)touch]];

CGPoint touchPoint = [touch locationInView:self];

Expand Down Expand Up @@ -367,7 +364,7 @@ - (void)touchesCancelled:(NSSet *)touches
}

for(UITouch *touch in touches){
int touchIndex = [[activeTouches objectForKey:[NSValue valueWithPointer:touch]] intValue];
int touchIndex = [[activeTouches objectForKey:[NSValue valueWithPointer:(__bridge void *)touch]] intValue];

CGPoint touchPoint = [touch locationInView:self];

Expand Down
12 changes: 6 additions & 6 deletions addons/ofxiOS/src/core/ofxiOSGLKView.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class ofAppiOSWindow;
@interface ofxiOSGLKView : EAGLKView {

@protected
NSMutableDictionary * activeTouches;
NSMutableDictionary<NSValue *, NSNumber *> * activeTouches;
glm::vec2 * screenSize; // because glm::vec2 is forward declared,
glm::vec2 * windowSize; // these values have to be pointers.
glm::vec2 * windowPos;
Expand All @@ -30,11 +30,11 @@ class ofAppiOSWindow;

+ (ofxiOSGLKView *) getInstance;

- (id)initWithFrame:(CGRect)frame
andApp:(ofxiOSApp *)app;
- (id)initWithFrame:(CGRect)frame
andApp:(ofxiOSApp *)app
sharegroup:(EAGLSharegroup *)sharegroup;
- (instancetype)initWithFrame:(CGRect)frame
andApp:(ofxiOSApp *)app;
- (instancetype)initWithFrame:(CGRect)frame
andApp:(ofxiOSApp *)app
sharegroup:(EAGLSharegroup *)sharegroup;
- (void)setup;
- (void)update;
- (void)draw;
Expand Down
18 changes: 8 additions & 10 deletions addons/ofxiOS/src/core/ofxiOSGLKView.mm
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,11 @@ + (ofxiOSGLKView *) getInstance {
return _instanceRef;
}

- (id)initWithFrame:(CGRect)frame andApp:(ofxiOSApp *)appPtr {
- (instancetype)initWithFrame:(CGRect)frame andApp:(ofxiOSApp *)appPtr {
return [self initWithFrame:frame andApp:appPtr sharegroup:nil];
}

- (id)initWithFrame:(CGRect)frame andApp:(ofxiOSApp *)appPtr sharegroup:(EAGLSharegroup *)sharegroup{
- (instancetype)initWithFrame:(CGRect)frame andApp:(ofxiOSApp *)appPtr sharegroup:(EAGLSharegroup *)sharegroup{

window = dynamic_pointer_cast<ofAppiOSWindow>(ofGetMainLoop()->getCurrentWindow());

Expand Down Expand Up @@ -128,8 +128,7 @@ - (void)destroy {
app = NULL;
window = NULL;

[activeTouches release];

activeTouches = nil;
delete screenSize;
screenSize = NULL;
delete windowSize;
Expand All @@ -146,7 +145,6 @@ - (void)destroy {

- (void)dealloc {
[self destroy];
[super dealloc];
}

- (void)layoutSubviews {
Expand Down Expand Up @@ -270,7 +268,7 @@ - (void)touchesBegan:(NSSet *)touches
touchIndex++;
}

[activeTouches setObject:[NSNumber numberWithInt:touchIndex] forKey:[NSValue valueWithPointer:touch]];
[activeTouches setObject:@(touchIndex) forKey:[NSValue valueWithPointer:(__bridge void *)touch]];

CGPoint touchPoint = [touch locationInView:self];

Expand Down Expand Up @@ -307,7 +305,7 @@ - (void)touchesMoved:(NSSet *)touches
}

for(UITouch *touch in touches){
int touchIndex = [[activeTouches objectForKey:[NSValue valueWithPointer:touch]] intValue];
int touchIndex = [[activeTouches objectForKey:[NSValue valueWithPointer:(__bridge void *)touch]] intValue];

CGPoint touchPoint = [touch locationInView:self];

Expand Down Expand Up @@ -339,9 +337,9 @@ - (void)touchesEnded:(NSSet *)touches
}

for(UITouch *touch in touches){
int touchIndex = [[activeTouches objectForKey:[NSValue valueWithPointer:touch]] intValue];
int touchIndex = [[activeTouches objectForKey:[NSValue valueWithPointer:(__bridge void *)touch]] intValue];

[activeTouches removeObjectForKey:[NSValue valueWithPointer:touch]];
[activeTouches removeObjectForKey:[NSValue valueWithPointer:(__bridge void *)touch]];

CGPoint touchPoint = [touch locationInView:self];

Expand Down Expand Up @@ -374,7 +372,7 @@ - (void)touchesCancelled:(NSSet *)touches
}

for(UITouch *touch in touches){
int touchIndex = [[activeTouches objectForKey:[NSValue valueWithPointer:touch]] intValue];
int touchIndex = [[activeTouches objectForKey:[NSValue valueWithPointer:(__bridge void *)touch]] intValue];

CGPoint touchPoint = [touch locationInView:self];

Expand Down
6 changes: 3 additions & 3 deletions addons/ofxiOS/src/core/ofxiOSGLKViewController.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@ class ofxiOSApp;

@interface ofxiOSGLKViewController : GLKViewController

@property (nonatomic, retain) ofxiOSGLKView * glView;
@property (nonatomic, strong) ofxiOSGLKView * glView;

- (id)initWithFrame:(CGRect)frame app:(ofxiOSApp *)app;
- (id)initWithFrame:(CGRect)frame app:(ofxiOSApp *)app sharegroup:(EAGLSharegroup *)sharegroup;
- (instancetype)initWithFrame:(CGRect)frame app:(ofxiOSApp *)app;
- (instancetype)initWithFrame:(CGRect)frame app:(ofxiOSApp *)app sharegroup:(EAGLSharegroup *)sharegroup;

- (UIInterfaceOrientation)currentInterfaceOrientation;
- (void)setCurrentInterfaceOrientation:(UIInterfaceOrientation) orient;
Expand Down
8 changes: 3 additions & 5 deletions addons/ofxiOS/src/core/ofxiOSGLKViewController.mm
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,11 @@ @implementation ofxiOSGLKViewController

@synthesize glView;

- (id)initWithFrame:(CGRect)frame app:(ofxiOSApp *)app {
- (instancetype)initWithFrame:(CGRect)frame app:(ofxiOSApp *)app {
return [self initWithFrame:frame app:app sharegroup:nil];
}

- (id)initWithFrame:(CGRect)frame app:(ofxiOSApp *)app sharegroup:(EAGLSharegroup *)sharegroup{
- (instancetype)initWithFrame:(CGRect)frame app:(ofxiOSApp *)app sharegroup:(EAGLSharegroup *)sharegroup{
currentInterfaceOrientation = pendingInterfaceOrientation = UIInterfaceOrientationPortrait;
if((self = [super init])) {
currentInterfaceOrientation = pendingInterfaceOrientation = self.interfaceOrientation;
Expand All @@ -43,7 +43,7 @@ - (id)initWithFrame:(CGRect)frame app:(ofxiOSApp *)app sharegroup:(EAGLSharegrou
bFirstUpdate = NO;
bAnimated = NO;

self.glView = [[[ofxiOSGLKView alloc] initWithFrame:frame andApp:app sharegroup:sharegroup] autorelease];
self.glView = [[ofxiOSGLKView alloc] initWithFrame:frame andApp:app sharegroup:sharegroup];
self.glView.delegate = self;
}

Expand All @@ -54,8 +54,6 @@ - (void) dealloc {
[self.glView removeFromSuperview];
self.glView.delegate = nil;
self.glView = nil;

[super dealloc];
}

- (void)viewDidLoad {
Expand Down
Loading