Continue with the refactoring

This commit is contained in:
Ricardo Quesada 2014-01-27 19:16:09 -08:00
parent b96c4f1ad0
commit 20346499ab
7 changed files with 58 additions and 45 deletions

View File

@ -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 */ /** 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; + (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 */ /** 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 - (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 */ /** Initializes an CCEAGLView with a frame, a color buffer format, and 0-bit depth buffer */

View File

@ -78,8 +78,6 @@ Copyright (C) 2008 Apple Inc. All Rights Reserved.
#define IOS_MAX_TOUCHES_COUNT 10 #define IOS_MAX_TOUCHES_COUNT 10
static CCEAGLView *__view = 0;
@interface CCEAGLView (Private) @interface CCEAGLView (Private)
- (BOOL) setupSurfaceWithSharegroup:(EAGLSharegroup*)sharegroup; - (BOOL) setupSurfaceWithSharegroup:(EAGLSharegroup*)sharegroup;
- (unsigned int) convertPixelFormat:(NSString*) pixelFormat; - (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]; 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 - (id) initWithFrame:(CGRect)frame
{ {
return [self initWithFrame:frame pixelFormat:kEAGLColorFormatRGB565 depthFormat:0 preserveBackbuffer:NO sharegroup:nil multiSampling:NO numberOfSamples:0]; 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; return nil;
} }
__view = self;
originalRect_ = self.frame; originalRect_ = self.frame;
self.keyboardShowNotification = nil; 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; return self;
} }
@ -412,8 +402,8 @@ static CCEAGLView *__view = 0;
int i = 0; int i = 0;
for (UITouch *touch in touches) { for (UITouch *touch in touches) {
ids[i] = touch; ids[i] = touch;
xs[i] = [touch locationInView: [touch view]].x * __view.contentScaleFactor;; xs[i] = [touch locationInView: [touch view]].x * self.contentScaleFactor;;
ys[i] = [touch locationInView: [touch view]].y * __view.contentScaleFactor;; ys[i] = [touch locationInView: [touch view]].y * self.contentScaleFactor;;
++i; ++i;
} }
@ -434,8 +424,8 @@ static CCEAGLView *__view = 0;
int i = 0; int i = 0;
for (UITouch *touch in touches) { for (UITouch *touch in touches) {
ids[i] = touch; ids[i] = touch;
xs[i] = [touch locationInView: [touch view]].x * __view.contentScaleFactor;; xs[i] = [touch locationInView: [touch view]].x * self.contentScaleFactor;;
ys[i] = [touch locationInView: [touch view]].y * __view.contentScaleFactor;; ys[i] = [touch locationInView: [touch view]].y * self.contentScaleFactor;;
++i; ++i;
} }
@ -457,8 +447,8 @@ static CCEAGLView *__view = 0;
int i = 0; int i = 0;
for (UITouch *touch in touches) { for (UITouch *touch in touches) {
ids[i] = touch; ids[i] = touch;
xs[i] = [touch locationInView: [touch view]].x * __view.contentScaleFactor;; xs[i] = [touch locationInView: [touch view]].x * self.contentScaleFactor;;
ys[i] = [touch locationInView: [touch view]].y * __view.contentScaleFactor;; ys[i] = [touch locationInView: [touch view]].y * self.contentScaleFactor;;
++i; ++i;
} }
@ -480,8 +470,8 @@ static CCEAGLView *__view = 0;
int i = 0; int i = 0;
for (UITouch *touch in touches) { for (UITouch *touch in touches) {
ids[i] = touch; ids[i] = touch;
xs[i] = [touch locationInView: [touch view]].x * __view.contentScaleFactor;; xs[i] = [touch locationInView: [touch view]].x * self.contentScaleFactor;;
ys[i] = [touch locationInView: [touch view]].y * __view.contentScaleFactor;; ys[i] = [touch locationInView: [touch view]].y * self.contentScaleFactor;;
++i; ++i;
} }

View File

@ -40,6 +40,7 @@ NS_CC_BEGIN
class CC_DLL EGLView : public Object, public EGLViewProtocol class CC_DLL EGLView : public Object, public EGLViewProtocol
{ {
public: public:
static EGLView* createWithEAGLView(void* eaglview);
static EGLView* create(const std::string& viewName); static EGLView* create(const std::string& viewName);
static EGLView* createWithSize(const std::string& viewName, Size size, float frameZoomFactor = 1.0f); static EGLView* createWithSize(const std::string& viewName, Size size, float frameZoomFactor = 1.0f);
static EGLView* createWithFullScreen(const std::string& viewName); static EGLView* createWithFullScreen(const std::string& viewName);
@ -58,6 +59,8 @@ protected:
bool initWithSize(const std::string& viewName, Size size, float frameZoomFactor); bool initWithSize(const std::string& viewName, Size size, float frameZoomFactor);
bool initWithFullScreen(const std::string& viewName); bool initWithFullScreen(const std::string& viewName);
void *_glview;
}; };
NS_CC_END NS_CC_END

View File

@ -70,13 +70,26 @@ EGLView* EGLView::createWithFullScreen(const std::string& viewName)
EGLView::EGLView() EGLView::EGLView()
{ {
_screenSize.width = _designResolutionSize.width = [[CCEAGLView sharedEGLView] getWidth]; CGRect r = CGRectMake(0,0,300,300);
_screenSize.height = _designResolutionSize.height = [[CCEAGLView sharedEGLView] getHeight]; 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() EGLView::~EGLView()
{ {
CCEAGLView *glview = (CCEAGLView*) _glview;
[glview release];
} }
bool EGLView::initWithSize(const std::string& viewName, Size size, float frameZoomFactor) 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() bool EGLView::isOpenGLReady()
{ {
return [CCEAGLView sharedEGLView] != nullptr; return _glview != nullptr;
} }
bool EGLView::setContentScaleFactor(float contentScaleFactor) 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; _scaleX = _scaleY = contentScaleFactor;
[[CCEAGLView sharedEGLView] setNeedsLayout];
CCEAGLView *glview = (CCEAGLView*) _glview;
[glview setNeedsLayout];
return true; return true;
} }
@ -109,24 +123,30 @@ void EGLView::end()
[CCDirectorCaller destroy]; [CCDirectorCaller destroy];
// destroy EAGLView // destroy EAGLView
[[CCEAGLView sharedEGLView] removeFromSuperview]; CCEAGLView *glview = (CCEAGLView*) _glview;
[glview removeFromSuperview];
[glview release];
} }
void EGLView::swapBuffers() 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 else
{ {
[[CCEAGLView sharedEGLView] resignFirstResponder]; [glview resignFirstResponder];
} }
} }

View File

@ -41,7 +41,7 @@ bool AppDelegate::applicationDidFinishLaunching()
auto designSize = Size(480, 320); auto designSize = Size(480, 320);
auto pFileUtils = FileUtils::getInstance(); auto fileUtils = FileUtils::getInstance();
std::vector<std::string> searchPaths; std::vector<std::string> searchPaths;
if (screenSize.height > 320) if (screenSize.height > 320)
@ -75,7 +75,7 @@ bool AppDelegate::applicationDidFinishLaunching()
searchPaths.push_back("scenetest/TriggerTest"); searchPaths.push_back("scenetest/TriggerTest");
} }
pFileUtils->setSearchPaths(searchPaths); fileUtils->setSearchPaths(searchPaths);
glview->setDesignResolutionSize(designSize.width, designSize.height, ResolutionPolicy::NO_BORDER); glview->setDesignResolutionSize(designSize.width, designSize.height, ResolutionPolicy::NO_BORDER);

View File

@ -19,19 +19,19 @@ public:
@return true Initialize success, app continue. @return true Initialize success, app continue.
@return false Initialize failed, app terminate. @return false Initialize failed, app terminate.
*/ */
virtual bool applicationDidFinishLaunching(); virtual bool applicationDidFinishLaunching() override;
/** /**
@brief The function be called when the application enter background @brief The function be called when the application enter background
@param the pointer of the application @param the pointer of the application
*/ */
virtual void applicationDidEnterBackground(); virtual void applicationDidEnterBackground() override;
/** /**
@brief The function be called when the application enter foreground @brief The function be called when the application enter foreground
@param the pointer of the application @param the pointer of the application
*/ */
virtual void applicationWillEnterForeground(); virtual void applicationWillEnterForeground() override;
}; };
#endif // _APP_DELEGATE_H_ #endif // _APP_DELEGATE_H_

View File

@ -21,8 +21,11 @@
// cocos2d application instance // cocos2d application instance
static AppDelegate s_sharedApplication; 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. // Override point for customization after application launch.
// Add the view controller's view to the window and display. // Add the view controller's view to the window and display.
@ -59,7 +62,7 @@ static AppDelegate s_sharedApplication;
[[UIApplication sharedApplication] setStatusBarHidden:true]; [[UIApplication sharedApplication] setStatusBarHidden:true];
cocos2d::Application::getInstance()->run(); app->run();
return YES; return YES;
} }