From 20346499abf9e3b3af3e133ba6cb52c00e361d74 Mon Sep 17 00:00:00 2001 From: Ricardo Quesada Date: Mon, 27 Jan 2014 19:16:09 -0800 Subject: [PATCH] Continue with the refactoring --- cocos/2d/platform/ios/CCEAGLView.h | 3 -- cocos/2d/platform/ios/CCEAGLView.mm | 32 +++++-------- cocos/2d/platform/ios/CCEGLView.h | 3 ++ cocos/2d/platform/ios/CCEGLView.mm | 46 +++++++++++++------ samples/Cpp/TestCpp/Classes/AppDelegate.cpp | 4 +- samples/Cpp/TestCpp/Classes/AppDelegate.h | 6 +-- .../proj.ios/Classes/testsAppDelegate.mm | 9 ++-- 7 files changed, 58 insertions(+), 45 deletions(-) diff --git a/cocos/2d/platform/ios/CCEAGLView.h b/cocos/2d/platform/ios/CCEAGLView.h index 6f4e72e178..fe80ab099c 100644 --- a/cocos/2d/platform/ios/CCEAGLView.h +++ b/cocos/2d/platform/ios/CCEAGLView.h @@ -122,9 +122,6 @@ Copyright (C) 2008 Apple Inc. All Rights Reserved. /** creates an initializes an CCEAGLView with a frame, a color buffer format, a depth buffer format, a sharegroup, and multisamping */ + (id) viewWithFrame:(CGRect)frame pixelFormat:(NSString*)format depthFormat:(GLuint)depth preserveBackbuffer:(BOOL)retained sharegroup:(EAGLSharegroup*)sharegroup multiSampling:(BOOL)multisampling numberOfSamples:(unsigned int)samples; -// get the view object -+(id) sharedEGLView; - /** Initializes an CCEAGLView with a frame and 0-bit depth buffer, and a RGB565 color buffer */ - (id) initWithFrame:(CGRect)frame; //These also set the current context /** Initializes an CCEAGLView with a frame, a color buffer format, and 0-bit depth buffer */ diff --git a/cocos/2d/platform/ios/CCEAGLView.mm b/cocos/2d/platform/ios/CCEAGLView.mm index bde7f822ac..56c76e3543 100644 --- a/cocos/2d/platform/ios/CCEAGLView.mm +++ b/cocos/2d/platform/ios/CCEAGLView.mm @@ -78,8 +78,6 @@ Copyright (C) 2008 Apple Inc. All Rights Reserved. #define IOS_MAX_TOUCHES_COUNT 10 -static CCEAGLView *__view = 0; - @interface CCEAGLView (Private) - (BOOL) setupSurfaceWithSharegroup:(EAGLSharegroup*)sharegroup; - (unsigned int) convertPixelFormat:(NSString*) pixelFormat; @@ -118,11 +116,6 @@ static CCEAGLView *__view = 0; return [[[self alloc]initWithFrame:frame pixelFormat:format depthFormat:depth preserveBackbuffer:retained sharegroup:sharegroup multiSampling:multisampling numberOfSamples:samples] autorelease]; } -+ (id) sharedEGLView -{ - return __view; -} - - (id) initWithFrame:(CGRect)frame { return [self initWithFrame:frame pixelFormat:kEAGLColorFormatRGB565 depthFormat:0 preserveBackbuffer:NO sharegroup:nil multiSampling:NO numberOfSamples:0]; @@ -149,15 +142,13 @@ static CCEAGLView *__view = 0; return nil; } - - __view = self; - + originalRect_ = self.frame; self.keyboardShowNotification = nil; - if ([__view respondsToSelector:@selector(setContentScaleFactor:)]) + if ([self respondsToSelector:@selector(setContentScaleFactor:)]) { - __view.contentScaleFactor = [[UIScreen mainScreen] scale]; + self.contentScaleFactor = [[UIScreen mainScreen] scale]; } } @@ -183,7 +174,6 @@ static CCEAGLView *__view = 0; } } - __view = self; return self; } @@ -412,8 +402,8 @@ static CCEAGLView *__view = 0; int i = 0; for (UITouch *touch in touches) { ids[i] = touch; - xs[i] = [touch locationInView: [touch view]].x * __view.contentScaleFactor;; - ys[i] = [touch locationInView: [touch view]].y * __view.contentScaleFactor;; + xs[i] = [touch locationInView: [touch view]].x * self.contentScaleFactor;; + ys[i] = [touch locationInView: [touch view]].y * self.contentScaleFactor;; ++i; } @@ -434,8 +424,8 @@ static CCEAGLView *__view = 0; int i = 0; for (UITouch *touch in touches) { ids[i] = touch; - xs[i] = [touch locationInView: [touch view]].x * __view.contentScaleFactor;; - ys[i] = [touch locationInView: [touch view]].y * __view.contentScaleFactor;; + xs[i] = [touch locationInView: [touch view]].x * self.contentScaleFactor;; + ys[i] = [touch locationInView: [touch view]].y * self.contentScaleFactor;; ++i; } @@ -457,8 +447,8 @@ static CCEAGLView *__view = 0; int i = 0; for (UITouch *touch in touches) { ids[i] = touch; - xs[i] = [touch locationInView: [touch view]].x * __view.contentScaleFactor;; - ys[i] = [touch locationInView: [touch view]].y * __view.contentScaleFactor;; + xs[i] = [touch locationInView: [touch view]].x * self.contentScaleFactor;; + ys[i] = [touch locationInView: [touch view]].y * self.contentScaleFactor;; ++i; } @@ -480,8 +470,8 @@ static CCEAGLView *__view = 0; int i = 0; for (UITouch *touch in touches) { ids[i] = touch; - xs[i] = [touch locationInView: [touch view]].x * __view.contentScaleFactor;; - ys[i] = [touch locationInView: [touch view]].y * __view.contentScaleFactor;; + xs[i] = [touch locationInView: [touch view]].x * self.contentScaleFactor;; + ys[i] = [touch locationInView: [touch view]].y * self.contentScaleFactor;; ++i; } diff --git a/cocos/2d/platform/ios/CCEGLView.h b/cocos/2d/platform/ios/CCEGLView.h index 83ce928908..70e9575608 100644 --- a/cocos/2d/platform/ios/CCEGLView.h +++ b/cocos/2d/platform/ios/CCEGLView.h @@ -40,6 +40,7 @@ NS_CC_BEGIN class CC_DLL EGLView : public Object, public EGLViewProtocol { public: + static EGLView* createWithEAGLView(void* eaglview); static EGLView* create(const std::string& viewName); static EGLView* createWithSize(const std::string& viewName, Size size, float frameZoomFactor = 1.0f); static EGLView* createWithFullScreen(const std::string& viewName); @@ -58,6 +59,8 @@ protected: bool initWithSize(const std::string& viewName, Size size, float frameZoomFactor); bool initWithFullScreen(const std::string& viewName); + + void *_glview; }; NS_CC_END diff --git a/cocos/2d/platform/ios/CCEGLView.mm b/cocos/2d/platform/ios/CCEGLView.mm index 7e5ffd23ae..8bfe57fd12 100644 --- a/cocos/2d/platform/ios/CCEGLView.mm +++ b/cocos/2d/platform/ios/CCEGLView.mm @@ -70,13 +70,26 @@ EGLView* EGLView::createWithFullScreen(const std::string& viewName) EGLView::EGLView() { - _screenSize.width = _designResolutionSize.width = [[CCEAGLView sharedEGLView] getWidth]; - _screenSize.height = _designResolutionSize.height = [[CCEAGLView sharedEGLView] getHeight]; + CGRect r = CGRectMake(0,0,300,300); + CCEAGLView *glView = [CCEAGLView viewWithFrame:r + pixelFormat: kEAGLColorFormatRGB565 + depthFormat: GL_DEPTH24_STENCIL8_OES + preserveBackbuffer: NO + sharegroup: nil + multiSampling: NO + numberOfSamples: 0]; + [__glView setMultipleTouchEnabled:YES]; + + _screenSize.width = _designResolutionSize.width = [glview getWidth]; + _screenSize.height = _designResolutionSize.height = [glview getHeight]; + + _glview = glview; } EGLView::~EGLView() { - + CCEAGLView *glview = (CCEAGLView*) _glview; + [glview release]; } bool EGLView::initWithSize(const std::string& viewName, Size size, float frameZoomFactor) @@ -91,15 +104,16 @@ bool EGLView::initWithFullScreen(const std::string& viewName) bool EGLView::isOpenGLReady() { - return [CCEAGLView sharedEGLView] != nullptr; + return _glview != nullptr; } bool EGLView::setContentScaleFactor(float contentScaleFactor) { - assert(_resolutionPolicy == ResolutionPolicy::UNKNOWN); // cannot enable retina mode - + CC_ASSERT(_resolutionPolicy == ResolutionPolicy::UNKNOWN); // cannot enable retina mode _scaleX = _scaleY = contentScaleFactor; - [[CCEAGLView sharedEGLView] setNeedsLayout]; + + CCEAGLView *glview = (CCEAGLView*) _glview; + [glview setNeedsLayout]; return true; } @@ -109,24 +123,30 @@ void EGLView::end() [CCDirectorCaller destroy]; // destroy EAGLView - [[CCEAGLView sharedEGLView] removeFromSuperview]; + CCEAGLView *glview = (CCEAGLView*) _glview; + + [glview removeFromSuperview]; + [glview release]; } void EGLView::swapBuffers() { - [[CCEAGLView sharedEGLView] swapBuffers]; + CCEAGLView *glview = (CCEAGLView*) _glview; + [glview swapBuffers]; } -void EGLView::setIMEKeyboardState(bool bOpen) +void EGLView::setIMEKeyboardState(bool open) { - if (bOpen) + CCEAGLView *glview = (CCEAGLView*) _glview; + + if (open) { - [[CCEAGLView sharedEGLView] becomeFirstResponder]; + [glview becomeFirstResponder]; } else { - [[CCEAGLView sharedEGLView] resignFirstResponder]; + [glview resignFirstResponder]; } } diff --git a/samples/Cpp/TestCpp/Classes/AppDelegate.cpp b/samples/Cpp/TestCpp/Classes/AppDelegate.cpp index 05723b7852..0d2b7bf2c6 100644 --- a/samples/Cpp/TestCpp/Classes/AppDelegate.cpp +++ b/samples/Cpp/TestCpp/Classes/AppDelegate.cpp @@ -41,7 +41,7 @@ bool AppDelegate::applicationDidFinishLaunching() auto designSize = Size(480, 320); - auto pFileUtils = FileUtils::getInstance(); + auto fileUtils = FileUtils::getInstance(); std::vector searchPaths; if (screenSize.height > 320) @@ -75,7 +75,7 @@ bool AppDelegate::applicationDidFinishLaunching() searchPaths.push_back("scenetest/TriggerTest"); } - pFileUtils->setSearchPaths(searchPaths); + fileUtils->setSearchPaths(searchPaths); glview->setDesignResolutionSize(designSize.width, designSize.height, ResolutionPolicy::NO_BORDER); diff --git a/samples/Cpp/TestCpp/Classes/AppDelegate.h b/samples/Cpp/TestCpp/Classes/AppDelegate.h index 18ee8aeb63..39ecd105e1 100644 --- a/samples/Cpp/TestCpp/Classes/AppDelegate.h +++ b/samples/Cpp/TestCpp/Classes/AppDelegate.h @@ -19,19 +19,19 @@ public: @return true Initialize success, app continue. @return false Initialize failed, app terminate. */ - virtual bool applicationDidFinishLaunching(); + virtual bool applicationDidFinishLaunching() override; /** @brief The function be called when the application enter background @param the pointer of the application */ - virtual void applicationDidEnterBackground(); + virtual void applicationDidEnterBackground() override; /** @brief The function be called when the application enter foreground @param the pointer of the application */ - virtual void applicationWillEnterForeground(); + virtual void applicationWillEnterForeground() override; }; #endif // _APP_DELEGATE_H_ diff --git a/samples/Cpp/TestCpp/proj.ios/Classes/testsAppDelegate.mm b/samples/Cpp/TestCpp/proj.ios/Classes/testsAppDelegate.mm index 7473da28a0..0be72cad25 100644 --- a/samples/Cpp/TestCpp/proj.ios/Classes/testsAppDelegate.mm +++ b/samples/Cpp/TestCpp/proj.ios/Classes/testsAppDelegate.mm @@ -21,8 +21,11 @@ // cocos2d application instance static AppDelegate s_sharedApplication; -- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { - +- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions +{ + + cocos2d::Application *app = cocos2d::Application::getInstance(); + // Override point for customization after application launch. // Add the view controller's view to the window and display. @@ -59,7 +62,7 @@ static AppDelegate s_sharedApplication; [[UIApplication sharedApplication] setStatusBarHidden:true]; - cocos2d::Application::getInstance()->run(); + app->run(); return YES; }