GLView improvements

it is not longer a singleton
it is possible to specify the size
This commit is contained in:
Ricardo Quesada 2014-01-23 15:36:55 -08:00
parent 646dd2f8c5
commit 8ecaf49f93
54 changed files with 416 additions and 350 deletions

View File

@ -1 +1 @@
e706fcdbf8b76069d794bc03e3849a57932cdf0a 72b2e67ce3473ec4d8adf2412a9ce1d9390e0882

View File

@ -376,9 +376,10 @@ void Director::setOpenGLView(EGLView *openGLView)
conf->gatherGPUInfo(); conf->gatherGPUInfo();
CCLOG("%s\n",conf->getInfo().c_str()); CCLOG("%s\n",conf->getInfo().c_str());
// EAGLView is not a Object if(_openGLView)
delete _openGLView; // [openGLView_ release] _openGLView->release();
_openGLView = openGLView; _openGLView = openGLView;
_openGLView->retain();
// set size // set size
_winSizeInPoints = _openGLView->getDesignResolutionSize(); _winSizeInPoints = _openGLView->getDesignResolutionSize();
@ -941,7 +942,8 @@ void Director::createStatsLabel()
Secondly, the size of this image is 480*320, to display the FPS label with correct size, Secondly, the size of this image is 480*320, to display the FPS label with correct size,
a factor of design resolution ratio of 480x320 is also needed. a factor of design resolution ratio of 480x320 is also needed.
*/ */
float factor = EGLView::getInstance()->getDesignResolutionSize().height / 320.0f; auto glview = Director::getInstance()->getOpenGLView();
float factor = glview->getDesignResolutionSize().height / 320.0f;
_FPSLabel = LabelAtlas::create(); _FPSLabel = LabelAtlas::create();
_FPSLabel->retain(); _FPSLabel->retain();

View File

@ -33,6 +33,8 @@ NS_CC_BEGIN
* @{ * @{
*/ */
class EAGLView;
class CC_DLL ApplicationProtocol class CC_DLL ApplicationProtocol
{ {
public: public:

View File

@ -131,9 +131,10 @@ void EGLViewProtocol::setDesignResolutionSize(float width, float height, Resolut
_resolutionPolicy = resolutionPolicy; _resolutionPolicy = resolutionPolicy;
// reset director's member variables to fit visible rect // reset director's member variables to fit visible rect
Director::getInstance()->_winSizeInPoints = getDesignResolutionSize(); auto director = Director::getInstance();
Director::getInstance()->createStatsLabel(); director->_winSizeInPoints = getDesignResolutionSize();
Director::getInstance()->setGLDefaultValues(); director->createStatsLabel();
director->setGLDefaultValues();
} }
const Size& EGLViewProtocol::getDesignResolutionSize() const const Size& EGLViewProtocol::getDesignResolutionSize() const

View File

@ -48,6 +48,39 @@ void initExtensions() {
NS_CC_BEGIN NS_CC_BEGIN
EGLView* EGLView::createWithSize(const std::string& viewName, Size size, float frameZoomFactor)
{
auto ret = new EGLView;
if(ret && ret->initWithSize(viewName, size, frameZoomFactor)) {
ret->autorelease();
return ret;
}
return nullptr;
}
EGLView* EGLView::create(const std::string& viewName)
{
auto ret = new EGLView;
if(ret && ret->initWithSize(viewName, Size(0,0), 0)) {
ret->autorelease();
return ret;
}
return nullptr;
}
EGLView* EGLView::createWithFullScreen(const std::string& viewName)
{
auto ret = new EGLView();
if(ret && ret->initWithFullScreen(viewName)) {
ret->autorelease();
return ret;
}
return nullptr;
}
EGLView::EGLView() EGLView::EGLView()
{ {
initExtensions(); initExtensions();
@ -58,6 +91,17 @@ EGLView::~EGLView()
} }
bool EGLView::initWithSize(const std::string& viewName, Size size, float frameZoomFactor)
{
return true;
}
bool EGLView::initWithFullScreen(const std::string& viewName)
{
return true;
}
bool EGLView::isOpenGLReady() bool EGLView::isOpenGLReady()
{ {
return (_screenSize.width != 0 && _screenSize.height != 0); return (_screenSize.width != 0 && _screenSize.height != 0);
@ -72,18 +116,6 @@ void EGLView::swapBuffers()
{ {
} }
EGLView* EGLView::getInstance()
{
static EGLView instance;
return &instance;
}
// XXX: deprecated
EGLView* EGLView::sharedOpenGLView()
{
return EGLView::getInstance();
}
void EGLView::setIMEKeyboardState(bool bOpen) void EGLView::setIMEKeyboardState(bool bOpen)
{ {
setKeyboardStateJNI((int)bOpen); setKeyboardStateJNI((int)bOpen);

View File

@ -26,39 +26,32 @@ THE SOFTWARE.
#ifndef __CC_EGLVIEW_ANDROID_H__ #ifndef __CC_EGLVIEW_ANDROID_H__
#define __CC_EGLVIEW_ANDROID_H__ #define __CC_EGLVIEW_ANDROID_H__
#include "CCObject.h"
#include "CCGeometry.h" #include "CCGeometry.h"
#include "platform/CCEGLViewProtocol.h" #include "platform/CCEGLViewProtocol.h"
NS_CC_BEGIN NS_CC_BEGIN
class CC_DLL EGLView : public EGLViewProtocol class CC_DLL EGLView : public Object, public EGLViewProtocol
{ {
public: public:
/**
* @js ctor
*/
EGLView();
/**
* @js NA
* @lua NA
*/
virtual ~EGLView();
bool isOpenGLReady();
// keep compatible
void end();
void swapBuffers();
void setIMEKeyboardState(bool bOpen);
// static function // static function
/** static EGLView* create(const std::string &viewname);
@brief get the shared main open gl window static EGLView* createWithSize(const std::string& viewName, Size size, float frameZoomFactor = 1.0f);
*/ static EGLView* createWithFullScreen(const std::string& viewName);
static EGLView* getInstance();
/** @deprecated Use getInstance() instead */ bool isOpenGLReady() override;
CC_DEPRECATED_ATTRIBUTE static EGLView* sharedOpenGLView(); void end() override;
void swapBuffers() override;
void setIMEKeyboardState(bool bOpen) override;
protected:
EGLView();
virtual ~EGLView();
bool initWithSize(const std::string& viewName, Size size, float frameZoomFactor);
bool initWithFullScreen(const std::string& viewName);
}; };
NS_CC_END NS_CC_END

View File

@ -12,4 +12,4 @@
android.library=true android.library=true
# Project target. # Project target.
target=android-10 target=android-19

View File

@ -115,8 +115,6 @@ extern "C" {
jsize size = env->GetArrayLength(text); jsize size = env->GetArrayLength(text);
pthread_mutex_lock(&(engine.app->mutex)); pthread_mutex_lock(&(engine.app->mutex));
if (size > 0) { if (size > 0) {
jbyte * data = (jbyte*)env->GetByteArrayElements(text, 0); jbyte * data = (jbyte*)env->GetByteArrayElements(text, 0);
char* pBuf = (char*)malloc(size+1); char* pBuf = (char*)malloc(size+1);
if (pBuf != NULL) { if (pBuf != NULL) {
@ -148,10 +146,13 @@ static void cocos_init(cocos_dimensions d, struct android_app* app) {
cocos2d::FileUtilsAndroid::setassetmanager(app->activity->assetManager); cocos2d::FileUtilsAndroid::setassetmanager(app->activity->assetManager);
if (!cocos2d::Director::getInstance()->getOpenGLView()) auto director = cocos2d::Director::getInstance();
auto glview = director->getOpenGLView();
if (!glview)
{ {
cocos2d::EGLView *view = cocos2d::EGLView::getInstance(); glview = cocos2d::EGLView::create("android app");
view->setFrameSize(d.w, d.h); director->setOpenGLView(glview);
glview->setFrameSize(d.w, d.h);
cocos_android_app_init(app); cocos_android_app_init(app);
@ -163,16 +164,18 @@ static void cocos_init(cocos_dimensions d, struct android_app* app) {
cocos2d::ShaderCache::getInstance()->reloadDefaultShaders(); cocos2d::ShaderCache::getInstance()->reloadDefaultShaders();
cocos2d::DrawPrimitives::init(); cocos2d::DrawPrimitives::init();
cocos2d::VolatileTextureMgr::reloadAllTextures(); cocos2d::VolatileTextureMgr::reloadAllTextures();
cocos2d::EventCustom foregroundEvent(EVENT_COME_TO_FOREGROUND); cocos2d::EventCustom foregroundEvent(EVENT_COME_TO_FOREGROUND);
cocos2d::Director::getInstance()->getEventDispatcher()->dispatchEvent(&foregroundEvent); director->getEventDispatcher()->dispatchEvent(&foregroundEvent);
cocos2d::Director::getInstance()->setGLDefaultValues(); director->setGLDefaultValues();
} }
} }
/** /**
* Initialize an EGL context for the current display. * Initialize an EGL context for the current display.
*/ */
static cocos_dimensions engine_init_display(struct engine* engine) { static cocos_dimensions engine_init_display(struct engine* engine)
{
cocos_dimensions r; cocos_dimensions r;
r.w = -1; r.w = -1;
r.h = -1; r.h = -1;

View File

@ -205,7 +205,7 @@ void EGLViewEventHandler::onGLFWError(int errorID, const char* errorDesc)
void EGLViewEventHandler::onGLFWMouseCallBack(GLFWwindow* window, int button, int action, int modify) void EGLViewEventHandler::onGLFWMouseCallBack(GLFWwindow* window, int button, int action, int modify)
{ {
EGLView* eglView = EGLView::getInstance(); EGLView* eglView = Director::getInstance()->getOpenGLView();
if(nullptr == eglView) return; if(nullptr == eglView) return;
if(GLFW_MOUSE_BUTTON_LEFT == button) if(GLFW_MOUSE_BUTTON_LEFT == button)
{ {
@ -249,7 +249,7 @@ void EGLViewEventHandler::onGLFWMouseCallBack(GLFWwindow* window, int button, in
void EGLViewEventHandler::onGLFWMouseMoveCallBack(GLFWwindow* window, double x, double y) void EGLViewEventHandler::onGLFWMouseMoveCallBack(GLFWwindow* window, double x, double y)
{ {
EGLView* eglView = EGLView::getInstance(); EGLView* eglView = Director::getInstance()->getOpenGLView();
if(nullptr == eglView) return; if(nullptr == eglView) return;
if (eglView->isRetina()) { if (eglView->isRetina()) {
@ -280,7 +280,7 @@ void EGLViewEventHandler::onGLFWMouseMoveCallBack(GLFWwindow* window, double x,
void EGLViewEventHandler::onGLFWMouseScrollCallback(GLFWwindow* window, double x, double y) void EGLViewEventHandler::onGLFWMouseScrollCallback(GLFWwindow* window, double x, double y)
{ {
EGLView* eglView = EGLView::getInstance(); EGLView* eglView = Director::getInstance()->getOpenGLView();
if(nullptr == eglView) return; if(nullptr == eglView) return;
EventMouse event(EventMouse::MouseEventType::MOUSE_SCROLL); EventMouse event(EventMouse::MouseEventType::MOUSE_SCROLL);
@ -312,7 +312,7 @@ void EGLViewEventHandler::onGLFWWindowPosCallback(GLFWwindow *windows, int x, in
void EGLViewEventHandler::onGLFWframebuffersize(GLFWwindow* window, int w, int h) void EGLViewEventHandler::onGLFWframebuffersize(GLFWwindow* window, int w, int h)
{ {
auto view = EGLView::getInstance(); auto view = Director::getInstance()->getOpenGLView();
float frameSizeW = view->getFrameSize().width; float frameSizeW = view->getFrameSize().width;
float frameSizeH = view->getFrameSize().height; float frameSizeH = view->getFrameSize().height;
@ -341,7 +341,39 @@ void EGLViewEventHandler::onGLFWframebuffersize(GLFWwindow* window, int w, int h
// implement EGLView // implement EGLView
////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////
EGLView* EGLView::s_pEglView = nullptr;
EGLView* EGLView::create(const std::string& viewName)
{
auto ret = new EGLView;
if(ret && ret->initWithSize(viewName, Size(960, 640), 1)) {
ret->autorelease();
return ret;
}
return nullptr;
}
EGLView* EGLView::createWithSize(const std::string& viewName, Size size, float frameZoomFactor)
{
auto ret = new EGLView;
if(ret && ret->initWithSize(viewName, size, frameZoomFactor)) {
ret->autorelease();
return ret;
}
return nullptr;
}
EGLView* EGLView::createWithFullScreen(const std::string& viewName)
{
auto ret = new EGLView();
if(ret && ret->initWithFullScreen(viewName)) {
ret->autorelease();
return ret;
}
return nullptr;
}
EGLView::EGLView() EGLView::EGLView()
: _captured(false) : _captured(false)
@ -351,9 +383,7 @@ EGLView::EGLView()
, _mainWindow(nullptr) , _mainWindow(nullptr)
, _primaryMonitor(nullptr) , _primaryMonitor(nullptr)
{ {
CCASSERT(nullptr == s_pEglView, "EGLView is singleton, Should be inited only one time\n");
_viewName = "cocos2dx"; _viewName = "cocos2dx";
s_pEglView = this;
g_keyCodeMap.clear(); g_keyCodeMap.clear();
for (auto& item : g_keyCodeStructArray) for (auto& item : g_keyCodeStructArray)
{ {
@ -367,16 +397,12 @@ EGLView::~EGLView()
{ {
CCLOGINFO("deallocing EGLView: %p", this); CCLOGINFO("deallocing EGLView: %p", this);
glfwTerminate(); glfwTerminate();
s_pEglView = nullptr;
} }
bool EGLView::init(const std::string& viewName, float width, float height, float frameZoomFactor) bool EGLView::initWithSize(const std::string& viewName, Size size, float frameZoomFactor)
{ {
if(_mainWindow != nullptr)
return true;
setViewName(viewName); setViewName(viewName);
setFrameSize(width, height); setFrameSize(size.width, size.height);
setFrameZoomFactor(frameZoomFactor); setFrameZoomFactor(frameZoomFactor);
glfwWindowHint(GLFW_RESIZABLE,GL_FALSE); glfwWindowHint(GLFW_RESIZABLE,GL_FALSE);
@ -397,7 +423,7 @@ bool EGLView::init(const std::string& viewName, float width, float height, float
{ {
_isRetina = true; _isRetina = true;
setFrameZoomFactor(frameZoomFactor * 2); setFrameZoomFactor(frameZoomFactor * 2);
glfwSetWindowSize(_mainWindow, width/2 * _frameZoomFactor, height/2 * _frameZoomFactor); glfwSetWindowSize(_mainWindow, size.width/2 * _frameZoomFactor, size.height/2 * _frameZoomFactor);
} }
glfwSetMouseButtonCallback(_mainWindow,EGLViewEventHandler::onGLFWMouseCallBack); glfwSetMouseButtonCallback(_mainWindow,EGLViewEventHandler::onGLFWMouseCallBack);
@ -435,7 +461,7 @@ bool EGLView::initWithFullScreen(const std::string& viewName)
return false; return false;
const GLFWvidmode* videoMode = glfwGetVideoMode(_primaryMonitor); const GLFWvidmode* videoMode = glfwGetVideoMode(_primaryMonitor);
return init(viewName, videoMode->width, videoMode->height, 1.0f); return initWithSize(viewName, Size(videoMode->width, videoMode->height), 1.0f);
} }
bool EGLView::isOpenGLReady() bool EGLView::isOpenGLReady()
@ -505,18 +531,6 @@ void EGLView::setScissorInPoints(float x , float y , float w , float h)
(GLsizei)(h * _scaleY * _frameZoomFactor)); (GLsizei)(h * _scaleY * _frameZoomFactor));
} }
EGLView* EGLView::getInstance()
{
CCASSERT(nullptr != s_pEglView, "EGL singleton should not be null");
return s_pEglView;
}
// XXX: deprecated
EGLView* EGLView::sharedOpenGLView()
{
return EGLView::getInstance();
}
#if (CC_TARGET_PLATFORM == CC_PLATFORM_WIN32) #if (CC_TARGET_PLATFORM == CC_PLATFORM_WIN32)
static bool glew_dynamic_binding() static bool glew_dynamic_binding()
{ {

View File

@ -26,52 +26,29 @@ THE SOFTWARE.
#ifndef __CC_EGLVIEW_DESKTOP_H__ #ifndef __CC_EGLVIEW_DESKTOP_H__
#define __CC_EGLVIEW_DESKTOP_H__ #define __CC_EGLVIEW_DESKTOP_H__
#include "CCObject.h"
#include "platform/CCCommon.h" #include "platform/CCCommon.h"
#include "platform/CCEGLViewProtocol.h" #include "platform/CCEGLViewProtocol.h"
#include "glfw3.h" #include "glfw3.h"
NS_CC_BEGIN NS_CC_BEGIN
class CC_DLL EGLView : public EGLViewProtocol class CC_DLL EGLView : public Object, public EGLViewProtocol
{ {
public: public:
// static function static EGLView* create(const std::string& viewName);
/** static EGLView* createWithSize(const std::string& viewName, Size size, float frameZoomFactor = 1.0f);
@brief get the shared main open gl window static EGLView* createWithFullScreen(const std::string& viewName);
*/
static EGLView* getInstance();
/** @deprecated Use getInstance() instead */
CC_DEPRECATED_ATTRIBUTE static EGLView* sharedOpenGLView();
/**
* @js ctor
*/
EGLView();
/**
* @js NA
* @lua NA
*/
virtual ~EGLView();
/* override functions */
virtual bool isOpenGLReady();
virtual void end();
virtual void swapBuffers();
virtual void setFrameSize(float width, float height);
virtual void setIMEKeyboardState(bool bOpen);
/* /*
*frameZoomFactor for frame. This method is for debugging big resolution (e.g.new ipad) app on desktop. *frameZoomFactor for frame. This method is for debugging big resolution (e.g.new ipad) app on desktop.
*/ */
bool init(const std::string& viewName, float width, float height, float frameZoomFactor = 1.0f);
bool initWithFullScreen(const std::string& viewName);
//void resize(int width, int height); //void resize(int width, int height);
float getFrameZoomFactor(); float getFrameZoomFactor();
//void centerWindow(); //void centerWindow();
virtual void setViewPortInPoints(float x , float y , float w , float h); virtual void setViewPortInPoints(float x , float y , float w , float h);
virtual void setScissorInPoints(float x , float y , float w , float h); virtual void setScissorInPoints(float x , float y , float w , float h);
@ -80,7 +57,20 @@ public:
void pollEvents(); void pollEvents();
GLFWwindow* getWindow() const { return _mainWindow; } GLFWwindow* getWindow() const { return _mainWindow; }
/* override functions */
virtual bool isOpenGLReady() override;
virtual void end() override;
virtual void swapBuffers() override;
virtual void setFrameSize(float width, float height) override;
virtual void setIMEKeyboardState(bool bOpen) override;
protected: protected:
EGLView();
virtual ~EGLView();
bool initWithSize(const std::string& viewName, Size size, float frameZoomFactor);
bool initWithFullScreen(const std::string& viewName);
/* /*
* Set zoom factor for frame. This method is for debugging big resolution (e.g.new ipad) app on desktop. * Set zoom factor for frame. This method is for debugging big resolution (e.g.new ipad) app on desktop.
*/ */
@ -93,11 +83,13 @@ protected:
bool _isRetina; bool _isRetina;
float _frameZoomFactor; float _frameZoomFactor;
static EGLView* s_pEglView;
GLFWwindow* _mainWindow; GLFWwindow* _mainWindow;
GLFWmonitor* _primaryMonitor; GLFWmonitor* _primaryMonitor;
friend class EGLViewEventHandler; friend class EGLViewEventHandler;
private:
CC_DISALLOW_COPY_AND_ASSIGN(EGLView);
}; };
NS_CC_END // end of namespace cocos2d NS_CC_END // end of namespace cocos2d

View File

@ -63,7 +63,7 @@ Copyright (C) 2008 Apple Inc. All Rights Reserved.
#import <QuartzCore/QuartzCore.h> #import <QuartzCore/QuartzCore.h>
#import "CCEGLView.h" #import "CCEGLView.h"
#import "EAGLView.h" #import "CCEAGLView.h"
#import "CCES2Renderer.h" #import "CCES2Renderer.h"
#import "CCDirector.h" #import "CCDirector.h"
#import "CCSet.h" #import "CCSet.h"
@ -413,7 +413,9 @@ static CCEAGLView *__view = 0;
ys[i] = [touch locationInView: [touch view]].y * __view.contentScaleFactor;; ys[i] = [touch locationInView: [touch view]].y * __view.contentScaleFactor;;
++i; ++i;
} }
cocos2d::EGLView::getInstance()->handleTouchesBegin(i, (int*)ids, xs, ys);
auto glview = cocos2d::Director::getInstance()->getOpenGLView();
glview->handleTouchesBegin(i, (int*)ids, xs, ys);
} }
- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event - (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event
@ -433,7 +435,9 @@ static CCEAGLView *__view = 0;
ys[i] = [touch locationInView: [touch view]].y * __view.contentScaleFactor;; ys[i] = [touch locationInView: [touch view]].y * __view.contentScaleFactor;;
++i; ++i;
} }
cocos2d::EGLView::getInstance()->handleTouchesMove(i, (int*)ids, xs, ys);
auto glview = cocos2d::Director::getInstance()->getOpenGLView();
glview->handleTouchesMove(i, (int*)ids, xs, ys);
} }
- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event - (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
@ -454,7 +458,9 @@ static CCEAGLView *__view = 0;
ys[i] = [touch locationInView: [touch view]].y * __view.contentScaleFactor;; ys[i] = [touch locationInView: [touch view]].y * __view.contentScaleFactor;;
++i; ++i;
} }
cocos2d::EGLView::getInstance()->handleTouchesEnd(i, (int*)ids, xs, ys);
auto glview = cocos2d::Director::getInstance()->getOpenGLView();
glview->handleTouchesEnd(i, (int*)ids, xs, ys);
} }
- (void)touchesCancelled:(NSSet *)touches withEvent:(UIEvent *)event - (void)touchesCancelled:(NSSet *)touches withEvent:(UIEvent *)event
@ -475,7 +481,9 @@ static CCEAGLView *__view = 0;
ys[i] = [touch locationInView: [touch view]].y * __view.contentScaleFactor;; ys[i] = [touch locationInView: [touch view]].y * __view.contentScaleFactor;;
++i; ++i;
} }
cocos2d::EGLView::getInstance()->handleTouchesCancel(i, (int*)ids, xs, ys);
auto glview = cocos2d::Director::getInstance()->getOpenGLView();
glview->handleTouchesCancel(i, (int*)ids, xs, ys);
} }
#pragma mark - UIView - Responder #pragma mark - UIView - Responder
@ -795,8 +803,9 @@ static CCEAGLView *__view = 0;
break; break;
} }
float scaleX = cocos2d::EGLView::getInstance()->getScaleX(); auto glview = cocos2d::Director::getInstance()->getOpenGLView();
float scaleY = cocos2d::EGLView::getInstance()->getScaleY(); float scaleX = glview->getScaleX();
float scaleY = glview->getScaleY();
if (self.contentScaleFactor == 2.0f) if (self.contentScaleFactor == 2.0f)
@ -807,7 +816,7 @@ static CCEAGLView *__view = 0;
end = CGRectApplyAffineTransform(end, CGAffineTransformScale(CGAffineTransformIdentity, 2.0f, 2.0f)); end = CGRectApplyAffineTransform(end, CGAffineTransformScale(CGAffineTransformIdentity, 2.0f, 2.0f));
} }
float offestY = cocos2d::EGLView::getInstance()->getViewPortRect().origin.y; float offestY = glview->getViewPortRect().origin.y;
CCLOG("offestY = %f", offestY); CCLOG("offestY = %f", offestY);
if (offestY < 0.0f) if (offestY < 0.0f)
{ {
@ -870,7 +879,8 @@ static CCEAGLView *__view = 0;
if (dis < 0.0f) dis = 0.0f; if (dis < 0.0f) dis = 0.0f;
dis *= cocos2d::EGLView::getInstance()->getScaleY(); auto glview = cocos2d::Director::getInstance()->getOpenGLView();
dis *= glview->getScaleY();
if (self.contentScaleFactor == 2.0f) if (self.contentScaleFactor == 2.0f)
{ {

View File

@ -26,6 +26,7 @@
#ifndef __CC_EGLVIEW_IPHONE_H__ #ifndef __CC_EGLVIEW_IPHONE_H__
#define __CC_EGLVIEW_IPHONE_H__ #define __CC_EGLVIEW_IPHONE_H__
#include "CCObject.h"
#include "platform/CCCommon.h" #include "platform/CCCommon.h"
#include "platform/CCEGLViewProtocol.h" #include "platform/CCEGLViewProtocol.h"
@ -33,58 +34,27 @@ NS_CC_BEGIN
class CC_DLL EGLView : public EGLViewProtocol class CC_DLL EGLView : public Object, public EGLViewProtocol
{ {
public: public:
/** static EGLView* create(const std::string& viewName);
* @js NA static EGLView* createWithSize(const std::string& viewName, Size size, float frameZoomFactor = 1.0f);
* @lua NA static EGLView* createWithFullScreen(const std::string& viewName);
*/
EGLView();
/**
* @js NA
* @lua NA
*/
~EGLView();
/**
* @js NA
* @lua NA
*/
virtual bool isOpenGLReady();
/**
* @js NA
* @lua NA
*/
virtual bool setContentScaleFactor(float contentScaleFactor); virtual bool setContentScaleFactor(float contentScaleFactor);
// keep compatible // overrides
/** virtual bool isOpenGLReady() override;
* @js NA virtual void end() override;
* @lua NA virtual void swapBuffers() override;
*/ virtual void setIMEKeyboardState(bool bOpen) override;
virtual void end();
/**
* @js NA
* @lua NA
*/
virtual void swapBuffers();
/**
* @js NA
* @lua NA
*/
virtual void setIMEKeyboardState(bool bOpen);
/** returns the singleton protected:
* @js NA EGLView();
*/ virtual ~EGLView();
static EGLView* getInstance();
/** @deprecated Use getInstance() instead
* @js NA
* @lua NA
*/
CC_DEPRECATED_ATTRIBUTE static EGLView* sharedOpenGLView();
bool initWithSize(const std::string& viewName, Size size, float frameZoomFactor);
bool initWithFullScreen(const std::string& viewName);
}; };
NS_CC_END NS_CC_END

View File

@ -22,7 +22,7 @@
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE. THE SOFTWARE.
****************************************************************************/ ****************************************************************************/
#include "EAGLView.h" #include "CCEAGLView.h"
#include "CCDirectorCaller.h" #include "CCDirectorCaller.h"
#include "CCEGLView.h" #include "CCEGLView.h"
#include "CCSet.h" #include "CCSet.h"
@ -30,6 +30,39 @@
NS_CC_BEGIN NS_CC_BEGIN
EGLView* EGLView::create(const std::string& viewName)
{
auto ret = new EGLView;
if(ret && ret->initWithSize(viewName, Size(0,0), 1)) {
ret->autorelease();
return ret;
}
return nullptr;
}
EGLView* EGLView::createWithSize(const std::string& viewName, Size size, float frameZoomFactor)
{
auto ret = new EGLView;
if(ret && ret->initWithSize(viewName, size, frameZoomFactor)) {
ret->autorelease();
return ret;
}
return nullptr;
}
EGLView* EGLView::createWithFullScreen(const std::string& viewName)
{
auto ret = new EGLView();
if(ret && ret->initWithFullScreen(viewName)) {
ret->autorelease();
return ret;
}
return nullptr;
}
EGLView::EGLView() EGLView::EGLView()
{ {
_screenSize.width = _designResolutionSize.width = [[CCEAGLView sharedEGLView] getWidth]; _screenSize.width = _designResolutionSize.width = [[CCEAGLView sharedEGLView] getWidth];
@ -41,6 +74,16 @@ EGLView::~EGLView()
} }
bool EGLView::initWithSize(const std::string& viewName, Size size, float frameZoomFactor)
{
return true;
}
bool EGLView::initWithFullScreen(const std::string& viewName)
{
return true;
}
bool EGLView::isOpenGLReady() bool EGLView::isOpenGLReady()
{ {
return [CCEAGLView sharedEGLView] != nullptr; return [CCEAGLView sharedEGLView] != nullptr;
@ -82,17 +125,6 @@ void EGLView::setIMEKeyboardState(bool bOpen)
} }
} }
EGLView* EGLView::getInstance()
{
static EGLView instance;
return &instance;
}
// XXX: deprecated
EGLView* EGLView::sharedOpenGLView()
{
return EGLView::getInstance();
}
NS_CC_END NS_CC_END

View File

@ -54,12 +54,12 @@ int Application::run()
{ {
return 0; return 0;
} }
EGLView* pMainWnd = EGLView::getInstance(); EGLView* glview = Director::getInstance()->getOpenGLView();
while (!pMainWnd->windowShouldClose()) while (!glview->windowShouldClose())
{ {
Director::getInstance()->mainLoop(); Director::getInstance()->mainLoop();
pMainWnd->pollEvents(); glview->pollEvents();
} }
/* Only work on Desktop /* Only work on Desktop

View File

@ -23,7 +23,10 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE. THE SOFTWARE.
****************************************************************************/ ****************************************************************************/
#include "platform/CCCommon.h" #include "platform/CCCommon.h"
#include "CCDirector.h"
#include "CCEGLView.h" #include "CCEGLView.h"
#define GLFW_EXPOSE_NATIVE_NSGL #define GLFW_EXPOSE_NATIVE_NSGL
#define GLFW_EXPOSE_NATIVE_COCOA #define GLFW_EXPOSE_NATIVE_COCOA
#include "glfw3native.h" #include "glfw3native.h"
@ -51,7 +54,8 @@ void MessageBox(const char * msg, const char * title)
[alert setInformativeText:tmpTitle]; [alert setInformativeText:tmpTitle];
[alert setAlertStyle:NSWarningAlertStyle]; [alert setAlertStyle:NSWarningAlertStyle];
id window = glfwGetCocoaWindow(EGLView::getInstance()->getWindow()); EGLView* glview = Director::getInstance()->getOpenGLView();
id window = glfwGetCocoaWindow(glview->getWindow());
[alert beginSheetModalForWindow:window [alert beginSheetModalForWindow:window
modalDelegate:[window delegate] modalDelegate:[window delegate]
didEndSelector:nil didEndSelector:nil

View File

@ -324,7 +324,8 @@ void Layout::onBeforeVisitScissor()
{ {
Rect clippingRect = getClippingRect(); Rect clippingRect = getClippingRect();
glEnable(GL_SCISSOR_TEST); glEnable(GL_SCISSOR_TEST);
EGLView::getInstance()->setScissorInPoints(clippingRect.origin.x, clippingRect.origin.y, clippingRect.size.width, clippingRect.size.height); auto glview = Director::getInstance()->getOpenGLView();
glview->setScissorInPoints(clippingRect.origin.x, clippingRect.origin.y, clippingRect.size.width, clippingRect.size.height);
} }
void Layout::onAfterVisitScissor() void Layout::onAfterVisitScissor()

View File

@ -29,15 +29,18 @@
#define kLabelZOrder 9999 #define kLabelZOrder 9999
#include "CCEditBox.h" #include "CCEditBox.h"
#import "EAGLView.h" #import "CCEAGLView.h"
#define getEditBoxImplIOS() ((cocos2d::extension::EditBoxImplIOS*)editBox_) #define getEditBoxImplIOS() ((cocos2d::extension::EditBoxImplIOS*)editBox_)
static const int CC_EDIT_BOX_PADDING = 5; static const int CC_EDIT_BOX_PADDING = 5;
@implementation CCCustomUITextField @implementation CCCustomUITextField
- (CGRect)textRectForBounds:(CGRect)bounds { - (CGRect)textRectForBounds:(CGRect)bounds
float padding = CC_EDIT_BOX_PADDING * cocos2d::EGLView::getInstance()->getScaleX() / [[CCEAGLView sharedEGLView] contentScaleFactor ]; {
auto glview = cocos2d::Director::getInstance()->getOpenGLView();
float padding = CC_EDIT_BOX_PADDING * glview->getScaleX() / [[CCEAGLView sharedEGLView] contentScaleFactor ];
return CGRectMake(bounds.origin.x + padding, bounds.origin.y + padding, return CGRectMake(bounds.origin.x + padding, bounds.origin.y + padding,
bounds.size.width - padding*2, bounds.size.height - padding*2); bounds.size.width - padding*2, bounds.size.height - padding*2);
} }
@ -281,9 +284,9 @@ bool EditBoxImplIOS::initWithSize(const Size& size)
{ {
do do
{ {
EGLViewProtocol* eglView = EGLView::getInstance(); auto glview = cocos2d::Director::getInstance()->getOpenGLView();
CGRect rect = CGRectMake(0, 0, size.width * eglView->getScaleX(),size.height * eglView->getScaleY()); CGRect rect = CGRectMake(0, 0, size.width * glview->getScaleX(),size.height * glview->getScaleY());
if (_inRetinaMode) if (_inRetinaMode)
{ {
@ -358,7 +361,10 @@ void EditBoxImplIOS::setFont(const char* pFontName, int fontSize)
float retinaFactor = _inRetinaMode ? 2.0f : 1.0f; float retinaFactor = _inRetinaMode ? 2.0f : 1.0f;
NSString * fntName = [NSString stringWithUTF8String:pFontName]; NSString * fntName = [NSString stringWithUTF8String:pFontName];
float scaleFactor = EGLView::getInstance()->getScaleX();
auto glview = cocos2d::Director::getInstance()->getOpenGLView();
float scaleFactor = glview->getScaleX();
UIFont *textFont = nil; UIFont *textFont = nil;
if (isValidFontName) { if (isValidFontName) {
textFont = [UIFont fontWithName:fntName size:fontSize * scaleFactor / retinaFactor]; textFont = [UIFont fontWithName:fntName size:fontSize * scaleFactor / retinaFactor];
@ -528,11 +534,11 @@ void EditBoxImplIOS::setPlaceHolder(const char* pText)
static CGPoint convertDesignCoordToScreenCoord(const Point& designCoord, bool bInRetinaMode) static CGPoint convertDesignCoordToScreenCoord(const Point& designCoord, bool bInRetinaMode)
{ {
EGLViewProtocol* eglView = EGLView::getInstance(); auto glview = cocos2d::Director::getInstance()->getOpenGLView();
float viewH = (float)[[CCEAGLView sharedEGLView] getHeight]; float viewH = (float)[[CCEAGLView sharedEGLView] getHeight];
Point visiblePos = Point(designCoord.x * eglView->getScaleX(), designCoord.y * eglView->getScaleY()); Point visiblePos = Point(designCoord.x * glview->getScaleX(), designCoord.y * glview->getScaleY());
Point screenGLPos = visiblePos + eglView->getViewPortRect().origin; Point screenGLPos = visiblePos + glview->getViewPortRect().origin;
CGPoint screenPos = CGPointMake(screenGLPos.x, viewH - screenGLPos.y); CGPoint screenPos = CGPointMake(screenGLPos.x, viewH - screenGLPos.y);
@ -561,8 +567,8 @@ void EditBoxImplIOS::setContentSize(const Size& size)
_contentSize = size; _contentSize = size;
CCLOG("[Edit text] content size = (%f, %f)", size.width, size.height); CCLOG("[Edit text] content size = (%f, %f)", size.width, size.height);
placeInactiveLabels(); placeInactiveLabels();
EGLViewProtocol* eglView = EGLView::getInstance(); auto glview = cocos2d::Director::getInstance()->getOpenGLView();
CGSize controlSize = CGSizeMake(size.width * eglView->getScaleX(),size.height * eglView->getScaleY()); CGSize controlSize = CGSizeMake(size.width * glview->getScaleX(),size.height * glview->getScaleY());
if (_inRetinaMode) if (_inRetinaMode)
{ {

View File

@ -24,6 +24,7 @@
****************************************************************************/ ****************************************************************************/
#include "CCEditBoxImplMac.h" #include "CCEditBoxImplMac.h"
#include "CCDirector.h"
#if (CC_TARGET_PLATFORM == CC_PLATFORM_MAC) #if (CC_TARGET_PLATFORM == CC_PLATFORM_MAC)
@ -63,8 +64,10 @@
@synthesize editState = editState_; @synthesize editState = editState_;
@synthesize editBox = editBox_; @synthesize editBox = editBox_;
- (id) getNSWindow { - (id) getNSWindow
return glfwGetCocoaWindow(cocos2d::EGLView::getInstance()->getWindow()); {
auto glview = cocos2d::Director::getInstance()->getOpenGLView();
return glfwGetCocoaWindow(glview->getWindow());
} }
- (void)dealloc - (void)dealloc
@ -265,7 +268,7 @@ void EditBoxImplMac::doAnimationWhenKeyboardMove(float duration, float distance)
bool EditBoxImplMac::initWithSize(const Size& size) bool EditBoxImplMac::initWithSize(const Size& size)
{ {
EGLViewProtocol* eglView = EGLView::getInstance(); EGLViewProtocol* eglView = Director::getInstance()->getOpenGLView();
NSRect rect = NSMakeRect(0, 0, size.width * eglView->getScaleX(),size.height * eglView->getScaleY()); NSRect rect = NSMakeRect(0, 0, size.width * eglView->getScaleX(),size.height * eglView->getScaleY());
@ -356,7 +359,7 @@ NSPoint EditBoxImplMac::convertDesignCoordToScreenCoord(const Point& designCoord
NSRect frame = [_sysEdit.textField frame]; NSRect frame = [_sysEdit.textField frame];
CGFloat height = frame.size.height; CGFloat height = frame.size.height;
EGLViewProtocol* eglView = EGLView::getInstance(); EGLViewProtocol* eglView = Director::getInstance()->getOpenGLView();
Point visiblePos = Point(designCoord.x * eglView->getScaleX(), designCoord.y * eglView->getScaleY()); Point visiblePos = Point(designCoord.x * eglView->getScaleX(), designCoord.y * eglView->getScaleY());
Point screenGLPos = visiblePos + eglView->getViewPortRect().origin; Point screenGLPos = visiblePos + eglView->getViewPortRect().origin;

View File

@ -44,7 +44,8 @@ NS_CC_EXT_BEGIN
static float convertDistanceFromPointToInch(float pointDis) static float convertDistanceFromPointToInch(float pointDis)
{ {
float factor = ( EGLView::getInstance()->getScaleX() + EGLView::getInstance()->getScaleY() ) / 2; auto glview = Director::getInstance()->getOpenGLView();
float factor = ( glview->getScaleX() + glview->getScaleY() ) / 2;
return pointDis * factor / Device::getDPI(); return pointDis * factor / Device::getDPI();
} }
@ -508,21 +509,23 @@ void ScrollView::onBeforeDraw()
{ {
_scissorRestored = false; _scissorRestored = false;
Rect frame = getViewRect(); Rect frame = getViewRect();
if (EGLView::getInstance()->isScissorEnabled()) { auto glview = Director::getInstance()->getOpenGLView();
if (glview->isScissorEnabled()) {
_scissorRestored = true; _scissorRestored = true;
_parentScissorRect = EGLView::getInstance()->getScissorRect(); _parentScissorRect = glview->getScissorRect();
//set the intersection of _parentScissorRect and frame as the new scissor rect //set the intersection of _parentScissorRect and frame as the new scissor rect
if (frame.intersectsRect(_parentScissorRect)) { if (frame.intersectsRect(_parentScissorRect)) {
float x = MAX(frame.origin.x, _parentScissorRect.origin.x); float x = MAX(frame.origin.x, _parentScissorRect.origin.x);
float y = MAX(frame.origin.y, _parentScissorRect.origin.y); float y = MAX(frame.origin.y, _parentScissorRect.origin.y);
float xx = MIN(frame.origin.x+frame.size.width, _parentScissorRect.origin.x+_parentScissorRect.size.width); float xx = MIN(frame.origin.x+frame.size.width, _parentScissorRect.origin.x+_parentScissorRect.size.width);
float yy = MIN(frame.origin.y+frame.size.height, _parentScissorRect.origin.y+_parentScissorRect.size.height); float yy = MIN(frame.origin.y+frame.size.height, _parentScissorRect.origin.y+_parentScissorRect.size.height);
EGLView::getInstance()->setScissorInPoints(x, y, xx-x, yy-y); glview->setScissorInPoints(x, y, xx-x, yy-y);
} }
} }
else { else {
glEnable(GL_SCISSOR_TEST); glEnable(GL_SCISSOR_TEST);
EGLView::getInstance()->setScissorInPoints(frame.origin.x, frame.origin.y, frame.size.width, frame.size.height); glview->setScissorInPoints(frame.origin.x, frame.origin.y, frame.size.width, frame.size.height);
} }
} }
} }
@ -543,7 +546,9 @@ void ScrollView::onAfterDraw()
if (_clippingToBounds) if (_clippingToBounds)
{ {
if (_scissorRestored) {//restore the parent's scissor rect if (_scissorRestored) {//restore the parent's scissor rect
EGLView::getInstance()->setScissorInPoints(_parentScissorRect.origin.x, _parentScissorRect.origin.y, _parentScissorRect.size.width, _parentScissorRect.size.height); auto glview = Director::getInstance()->getOpenGLView();
glview->setScissorInPoints(_parentScissorRect.origin.x, _parentScissorRect.origin.y, _parentScissorRect.size.width, _parentScissorRect.size.height);
} }
else { else {
glDisable(GL_SCISSOR_TEST); glDisable(GL_SCISSOR_TEST);

View File

@ -20,14 +20,14 @@ AppDelegate::~AppDelegate()
bool AppDelegate::applicationDidFinishLaunching() { bool AppDelegate::applicationDidFinishLaunching() {
// initialize director // initialize director
auto director = Director::getInstance(); auto director = Director::getInstance();
auto glView = EGLView::getInstance(); auto glview = EGLView::createWithSize("Hello Cpp", Size(900,640));
director->setOpenGLView(glView); director->setOpenGLView(glview);
// Set the design resolution // Set the design resolution
glView->setDesignResolutionSize(designResolutionSize.width, designResolutionSize.height, ResolutionPolicy::NO_BORDER); glview->setDesignResolutionSize(designResolutionSize.width, designResolutionSize.height, ResolutionPolicy::NO_BORDER);
Size frameSize = glView->getFrameSize(); Size frameSize = glview->getFrameSize();
vector<string> searchPath; vector<string> searchPath;

View File

@ -51,6 +51,6 @@ static cocos2d::Size designResolutionSize = cocos2d::Size(2048, 1536);
#endif #endif
// The font size 24 is designed for small resolution, so we should change it to fit for current design resolution // The font size 24 is designed for small resolution, so we should change it to fit for current design resolution
#define TITLE_FONT_SIZE (cocos2d::EGLView::getInstance()->getDesignResolutionSize().width / smallResource.size.width * 24) #define TITLE_FONT_SIZE (cocos2d::Director::getInstance()->getOpenGLView()->getDesignResolutionSize().width / smallResource.size.width * 24)
#endif /* __APPMACROS_H__ */ #endif /* __APPMACROS_H__ */

View File

@ -24,7 +24,7 @@
#import <UIKit/UIKit.h> #import <UIKit/UIKit.h>
#import "AppController.h" #import "AppController.h"
#import "cocos2d.h" #import "cocos2d.h"
#import "EAGLView.h" #import "CCEAGLView.h"
#import "AppDelegate.h" #import "AppDelegate.h"
#import "RootViewController.h" #import "RootViewController.h"

View File

@ -29,8 +29,6 @@ USING_NS_CC;
int main(int argc, char *argv[]) int main(int argc, char *argv[])
{ {
AppDelegate app; AppDelegate app;
EGLView eglView;
eglView.init("HelloCpp",900,640);
return Application::getInstance()->run(); return Application::getInstance()->run();
} }

View File

@ -15,10 +15,11 @@ AppDelegate::~AppDelegate()
bool AppDelegate::applicationDidFinishLaunching() { bool AppDelegate::applicationDidFinishLaunching() {
// initialize director // initialize director
auto director = Director::getInstance(); auto director = Director::getInstance();
auto glview = EGLView::createWithSize("Simple Game", Size(900,640));
director->setOpenGLView(EGLView::getInstance()); director->setOpenGLView(glview);
auto screenSize = EGLView::getInstance()->getFrameSize(); auto screenSize = glview->getFrameSize();
auto designSize = Size(480, 320); auto designSize = Size(480, 320);
std::vector<std::string> searchPaths; std::vector<std::string> searchPaths;
@ -36,7 +37,7 @@ bool AppDelegate::applicationDidFinishLaunching() {
FileUtils::getInstance()->setSearchPaths(searchPaths); FileUtils::getInstance()->setSearchPaths(searchPaths);
EGLView::getInstance()->setDesignResolutionSize(designSize.width, designSize.height, ResolutionPolicy::NO_BORDER); glview->setDesignResolutionSize(designSize.width, designSize.height, ResolutionPolicy::NO_BORDER);
// turn on display FPS // turn on display FPS
director->setDisplayStats(true); director->setDisplayStats(true);

View File

@ -24,7 +24,7 @@
#import <UIKit/UIKit.h> #import <UIKit/UIKit.h>
#import "AppController.h" #import "AppController.h"
#import "cocos2d.h" #import "cocos2d.h"
#import "EAGLView.h" #import "CCEAGLView.h"
#import "AppDelegate.h" #import "AppDelegate.h"
#import "RootViewController.h" #import "RootViewController.h"

View File

@ -29,8 +29,6 @@ USING_NS_CC;
int main(int argc, char *argv[]) int main(int argc, char *argv[])
{ {
AppDelegate app; AppDelegate app;
EGLView eglView;
eglView.init("SimpleGame",900,640);
return Application::getInstance()->run(); return Application::getInstance()->run();
} }

View File

@ -26,14 +26,16 @@ bool AppDelegate::applicationDidFinishLaunching()
// XXX: but at this point, the director is already initialized // XXX: but at this point, the director is already initialized
Configuration::getInstance()->loadConfigFile("configs/config-example.plist"); Configuration::getInstance()->loadConfigFile("configs/config-example.plist");
auto glview = EGLView::create("Test Cpp");
// initialize director // initialize director
auto director = Director::getInstance(); auto director = Director::getInstance();
director->setOpenGLView(EGLView::getInstance()); director->setOpenGLView(glview);
director->setDisplayStats(true); director->setDisplayStats(true);
director->setAnimationInterval(1.0 / 60); director->setAnimationInterval(1.0 / 60);
auto screenSize = EGLView::getInstance()->getFrameSize(); auto screenSize = glview->getFrameSize();
auto designSize = Size(480, 320); auto designSize = Size(480, 320);
@ -73,7 +75,7 @@ bool AppDelegate::applicationDidFinishLaunching()
pFileUtils->setSearchPaths(searchPaths); pFileUtils->setSearchPaths(searchPaths);
EGLView::getInstance()->setDesignResolutionSize(designSize.width, designSize.height, ResolutionPolicy::NO_BORDER); glview->setDesignResolutionSize(designSize.width, designSize.height, ResolutionPolicy::NO_BORDER);
auto scene = Scene::create(); auto scene = Scene::create();
auto layer = new TestController(); auto layer = new TestController();

View File

@ -15,8 +15,9 @@ USING_NS_CC_EXT;
EditBoxTest::EditBoxTest() EditBoxTest::EditBoxTest()
{ {
auto visibleOrigin = EGLView::getInstance()->getVisibleOrigin(); auto glview = Director::getInstance()->getOpenGLView();
auto visibleSize = EGLView::getInstance()->getVisibleSize(); auto visibleOrigin = glview->getVisibleOrigin();
auto visibleSize = glview->getVisibleSize();
auto pBg = Sprite::create("Images/HelloWorld.png"); auto pBg = Sprite::create("Images/HelloWorld.png");
pBg->setPosition(Point(visibleOrigin.x+visibleSize.width/2, visibleOrigin.y+visibleSize.height/2)); pBg->setPosition(Point(visibleOrigin.x+visibleSize.width/2, visibleOrigin.y+visibleSize.height/2));

View File

@ -6,7 +6,7 @@ void VisibleRect::lazyInit()
{ {
if (s_visibleRect.size.width == 0.0f && s_visibleRect.size.height == 0.0f) if (s_visibleRect.size.width == 0.0f && s_visibleRect.size.height == 0.0f)
{ {
auto glView = EGLView::getInstance(); auto glView = Director::getInstance()->getOpenGLView();
s_visibleRect.origin = glView->getVisibleOrigin(); s_visibleRect.origin = glView->getVisibleOrigin();
s_visibleRect.size = glView->getVisibleSize(); s_visibleRect.size = glView->getVisibleSize();
} }

View File

@ -8,6 +8,6 @@
# project structure. # project structure.
# Project target. # Project target.
target=android-10 target=android-19
android.library.reference.1=../../../../cocos/2d/platform/android/java android.library.reference.1=../../../../cocos/2d/platform/android/java

View File

@ -8,7 +8,7 @@
#import "testsAppDelegate.h" #import "testsAppDelegate.h"
#import "EAGLView.h" #import "CCEAGLView.h"
#import "cocos2d.h" #import "cocos2d.h"
#import "AppDelegate.h" #import "AppDelegate.h"
#import "RootViewController.h" #import "RootViewController.h"

View File

@ -29,7 +29,5 @@ USING_NS_CC;
int main(int argc, char *argv[]) int main(int argc, char *argv[])
{ {
AppDelegate app; AppDelegate app;
EGLView eglView;
eglView.init("TestCPP",900,640);
return Application::getInstance()->run(); return Application::getInstance()->run();
} }

View File

@ -32,14 +32,15 @@ AppDelegate::~AppDelegate()
bool AppDelegate::applicationDidFinishLaunching() bool AppDelegate::applicationDidFinishLaunching()
{ {
// initialize director // initialize director
auto pDirector = Director::getInstance(); auto director = Director::getInstance();
pDirector->setOpenGLView(EGLView::getInstance()); auto glview = EGLView::createWithSize("CocosDragon JS", Size(480, 720));
pDirector->setProjection(Director::Projection::_2D); director->setOpenGLView(glview);
director->setProjection(Director::Projection::_2D);
FileUtils::getInstance()->addSearchPath("script"); FileUtils::getInstance()->addSearchPath("script");
auto screenSize = EGLView::getInstance()->getFrameSize(); auto screenSize = glview->getFrameSize();
auto designSize = Size(320, 480); auto designSize = Size(320, 480);
auto resourceSize = Size(320, 480); auto resourceSize = Size(320, 480);
@ -110,15 +111,15 @@ bool AppDelegate::applicationDidFinishLaunching()
FileUtils::getInstance()->setSearchResolutionsOrder(resDirOrders); FileUtils::getInstance()->setSearchResolutionsOrder(resDirOrders);
pDirector->setContentScaleFactor(resourceSize.width/designSize.width); director->setContentScaleFactor(resourceSize.width/designSize.width);
EGLView::getInstance()->setDesignResolutionSize(designSize.width, designSize.height, ResolutionPolicy::NO_BORDER); glview->setDesignResolutionSize(designSize.width, designSize.height, ResolutionPolicy::NO_BORDER);
// turn on display FPS // turn on display FPS
pDirector->setDisplayStats(true); director->setDisplayStats(true);
// set FPS. the default value is 1.0/60 if you don't call this // set FPS. the default value is 1.0/60 if you don't call this
pDirector->setAnimationInterval(1.0 / 60); director->setAnimationInterval(1.0 / 60);
ScriptingCore* sc = ScriptingCore::getInstance(); ScriptingCore* sc = ScriptingCore::getInstance();
sc->addRegisterCallback(register_all_cocos2dx); sc->addRegisterCallback(register_all_cocos2dx);

View File

@ -8,7 +8,7 @@
#import <UIKit/UIKit.h> #import <UIKit/UIKit.h>
#import "AppController.h" #import "AppController.h"
#import "cocos2d.h" #import "cocos2d.h"
#import "EAGLView.h" #import "CCEAGLView.h"
#import "AppDelegate.h" #import "AppDelegate.h"
#import "RootViewController.h" #import "RootViewController.h"

View File

@ -30,7 +30,5 @@ USING_NS_CC;
int main(int argc, char *argv[]) int main(int argc, char *argv[])
{ {
AppDelegate app; AppDelegate app;
EGLView eglView;
eglView.init("CocosDragonJS", 480, 720);
return Application::getInstance()->run(); return Application::getInstance()->run();
} }

View File

@ -28,13 +28,15 @@ AppDelegate::~AppDelegate()
bool AppDelegate::applicationDidFinishLaunching() bool AppDelegate::applicationDidFinishLaunching()
{ {
// initialize director // initialize director
auto pDirector = Director::getInstance(); auto director = Director::getInstance();
pDirector->setOpenGLView(EGLView::getInstance()); auto glview = EGLView::createWithSize("Crystal Craze", Size(480, 720));
pDirector->setProjection(Director::Projection::_2D);
director->setOpenGLView(glview);
director->setProjection(Director::Projection::_2D);
FileUtils::getInstance()->addSearchPath("script"); FileUtils::getInstance()->addSearchPath("script");
auto screenSize = EGLView::getInstance()->getFrameSize(); auto screenSize = glview->getFrameSize();
auto designSize = Size(320, 480); auto designSize = Size(320, 480);
auto resourceSize = Size(320, 480); auto resourceSize = Size(320, 480);
@ -91,15 +93,15 @@ bool AppDelegate::applicationDidFinishLaunching()
FileUtils::getInstance()->setSearchResolutionsOrder(resDirOrders); FileUtils::getInstance()->setSearchResolutionsOrder(resDirOrders);
} }
pDirector->setContentScaleFactor(resourceSize.width/designSize.width); director->setContentScaleFactor(resourceSize.width/designSize.width);
EGLView::getInstance()->setDesignResolutionSize(designSize.width, designSize.height, ResolutionPolicy::SHOW_ALL); glview->setDesignResolutionSize(designSize.width, designSize.height, ResolutionPolicy::SHOW_ALL);
// turn on display FPS // turn on display FPS
pDirector->setDisplayStats(true); director->setDisplayStats(true);
// set FPS. the default value is 1.0/60 if you don't call this // set FPS. the default value is 1.0/60 if you don't call this
pDirector->setAnimationInterval(1.0 / 60); director->setAnimationInterval(1.0 / 60);
ScriptingCore* sc = ScriptingCore::getInstance(); ScriptingCore* sc = ScriptingCore::getInstance();
sc->addRegisterCallback(register_all_cocos2dx); sc->addRegisterCallback(register_all_cocos2dx);

View File

@ -8,7 +8,7 @@
#import <UIKit/UIKit.h> #import <UIKit/UIKit.h>
#import "AppController.h" #import "AppController.h"
#import "cocos2d.h" #import "cocos2d.h"
#import "EAGLView.h" #import "CCEAGLView.h"
#import "AppDelegate.h" #import "AppDelegate.h"
#import "RootViewController.h" #import "RootViewController.h"

View File

@ -30,7 +30,5 @@ USING_NS_CC;
int main(int argc, char *argv[]) int main(int argc, char *argv[])
{ {
AppDelegate app; AppDelegate app;
EGLView eglView;
eglView.init("CrystalCraze", 480, 720);
return Application::getInstance()->run(); return Application::getInstance()->run();
} }

View File

@ -28,18 +28,20 @@ AppDelegate::~AppDelegate()
bool AppDelegate::applicationDidFinishLaunching() bool AppDelegate::applicationDidFinishLaunching()
{ {
// initialize director // initialize director
auto pDirector = Director::getInstance(); auto director = Director::getInstance();
pDirector->setOpenGLView(EGLView::getInstance()); auto glview = EGLView::createWithSize("Moon Warriors", Size(480, 720));
pDirector->setProjection(Director::Projection::_2D);
director->setOpenGLView(glview);
director->setProjection(Director::Projection::_2D);
// Set the design resolution // Set the design resolution
EGLView::getInstance()->setDesignResolutionSize(320, 480, ResolutionPolicy::SHOW_ALL); glview->setDesignResolutionSize(320, 480, ResolutionPolicy::SHOW_ALL);
// turn on display FPS // turn on display FPS
pDirector->setDisplayStats(true); director->setDisplayStats(true);
// set FPS. the default value is 1.0/60 if you don't call this // set FPS. the default value is 1.0/60 if you don't call this
pDirector->setAnimationInterval(1.0 / 60); director->setAnimationInterval(1.0 / 60);
FileUtils::getInstance()->addSearchPath("script"); FileUtils::getInstance()->addSearchPath("script");

View File

@ -8,7 +8,7 @@
#import <UIKit/UIKit.h> #import <UIKit/UIKit.h>
#import "AppController.h" #import "AppController.h"
#import "cocos2d.h" #import "cocos2d.h"
#import "EAGLView.h" #import "CCEAGLView.h"
#import "AppDelegate.h" #import "AppDelegate.h"
#import "RootViewController.h" #import "RootViewController.h"

View File

@ -30,8 +30,6 @@ USING_NS_CC;
int main(int argc, char *argv[]) int main(int argc, char *argv[])
{ {
AppDelegate app; AppDelegate app;
EGLView eglView;
eglView.init("MoonWarriors", 480, 720);
return Application::getInstance()->run(); return Application::getInstance()->run();
} }

View File

@ -37,16 +37,18 @@ AppDelegate::~AppDelegate()
bool AppDelegate::applicationDidFinishLaunching() bool AppDelegate::applicationDidFinishLaunching()
{ {
// initialize director // initialize director
auto pDirector = Director::getInstance(); auto director = Director::getInstance();
pDirector->setOpenGLView(EGLView::getInstance()); auto glview = EGLView::createWithSize("Test JavaScript", Size(900,640));
director->setOpenGLView(glview);
// JS-Test in Html5 uses 800x450 as design resolution // JS-Test in Html5 uses 800x450 as design resolution
EGLView::getInstance()->setDesignResolutionSize(800, 450, ResolutionPolicy::FIXED_HEIGHT); glview->setDesignResolutionSize(800, 450, ResolutionPolicy::FIXED_HEIGHT);
// turn on display FPS // turn on display FPS
pDirector->setDisplayStats(true); director->setDisplayStats(true);
// set FPS. the default value is 1.0/60 if you don't call this // set FPS. the default value is 1.0/60 if you don't call this
pDirector->setAnimationInterval(1.0 / 60); director->setAnimationInterval(1.0 / 60);
auto fileUtils = FileUtils::getInstance(); auto fileUtils = FileUtils::getInstance();
std::vector<std::string> searchPaths; std::vector<std::string> searchPaths;

View File

@ -8,7 +8,7 @@
#import <UIKit/UIKit.h> #import <UIKit/UIKit.h>
#import "AppController.h" #import "AppController.h"
#import "cocos2d.h" #import "cocos2d.h"
#import "EAGLView.h" #import "CCEAGLView.h"
#import "AppDelegate.h" #import "AppDelegate.h"
#import "RootViewController.h" #import "RootViewController.h"

View File

@ -30,8 +30,6 @@ USING_NS_CC;
int main(int argc, char *argv[]) int main(int argc, char *argv[])
{ {
AppDelegate app; AppDelegate app;
EGLView eglView;
eglView.init("TestJavascript",900,640);
return Application::getInstance()->run(); return Application::getInstance()->run();
} }

View File

@ -28,16 +28,17 @@ AppDelegate::~AppDelegate()
bool AppDelegate::applicationDidFinishLaunching() bool AppDelegate::applicationDidFinishLaunching()
{ {
// initialize director // initialize director
auto pDirector = Director::getInstance(); auto director = Director::getInstance();
pDirector->setOpenGLView(EGLView::getInstance()); auto glview = EGLView::createWithSize("Watermelon With Me", Size(900,640));
director->setOpenGLView(glview);
// turn on display FPS // turn on display FPS
pDirector->setDisplayStats(true); director->setDisplayStats(true);
// set FPS. the default value is 1.0/60 if you don't call this // set FPS. the default value is 1.0/60 if you don't call this
pDirector->setAnimationInterval(1.0 / 60); director->setAnimationInterval(1.0 / 60);
EGLView::getInstance()->setDesignResolutionSize(480, 320, ResolutionPolicy::FIXED_HEIGHT); glview->setDesignResolutionSize(480, 320, ResolutionPolicy::FIXED_HEIGHT);
FileUtils::getInstance()->addSearchPath("script"); FileUtils::getInstance()->addSearchPath("script");

View File

@ -8,7 +8,7 @@
#import <UIKit/UIKit.h> #import <UIKit/UIKit.h>
#import "AppController.h" #import "AppController.h"
#import "cocos2d.h" #import "cocos2d.h"
#import "EAGLView.h" #import "CCEAGLView.h"
#import "AppDelegate.h" #import "AppDelegate.h"
#import "RootViewController.h" #import "RootViewController.h"

View File

@ -30,8 +30,6 @@ USING_NS_CC;
int main(int argc, char *argv[]) int main(int argc, char *argv[])
{ {
AppDelegate app; AppDelegate app;
EGLView eglView;
eglView.init("WatermelonWithMe",900,640);
return Application::getInstance()->run(); return Application::getInstance()->run();
} }

View File

@ -23,16 +23,18 @@ AppDelegate::~AppDelegate()
bool AppDelegate::applicationDidFinishLaunching() bool AppDelegate::applicationDidFinishLaunching()
{ {
// initialize director // initialize director
auto pDirector = Director::getInstance(); auto director = Director::getInstance();
pDirector->setOpenGLView(EGLView::getInstance()); auto glview = EGLView::createWithSize("Hello Lua", Size(900,640));
EGLView::getInstance()->setDesignResolutionSize(480, 320, ResolutionPolicy::NO_BORDER); director->setOpenGLView(glview);
glview->setDesignResolutionSize(480, 320, ResolutionPolicy::NO_BORDER);
// turn on display FPS // turn on display FPS
pDirector->setDisplayStats(true); director->setDisplayStats(true);
// set FPS. the default value is 1.0/60 if you don't call this // set FPS. the default value is 1.0/60 if you don't call this
pDirector->setAnimationInterval(1.0 / 60); director->setAnimationInterval(1.0 / 60);
// register lua engine // register lua engine
LuaEngine* pEngine = LuaEngine::getInstance(); LuaEngine* pEngine = LuaEngine::getInstance();

View File

@ -24,7 +24,7 @@
#import <UIKit/UIKit.h> #import <UIKit/UIKit.h>
#import "AppController.h" #import "AppController.h"
#import "cocos2d.h" #import "cocos2d.h"
#import "EAGLView.h" #import "CCEAGLView.h"
#import "AppDelegate.h" #import "AppDelegate.h"
#import "RootViewController.h" #import "RootViewController.h"

View File

@ -30,7 +30,5 @@ USING_NS_CC;
int main(int argc, char *argv[]) int main(int argc, char *argv[])
{ {
AppDelegate app; AppDelegate app;
EGLView eglView;
eglView.init("HelloLua",900,640);
return Application::getInstance()->run(); return Application::getInstance()->run();
} }

View File

@ -20,16 +20,18 @@ AppDelegate::~AppDelegate()
bool AppDelegate::applicationDidFinishLaunching() bool AppDelegate::applicationDidFinishLaunching()
{ {
// initialize director // initialize director
auto pDirector = Director::getInstance(); auto director = Director::getInstance();
pDirector->setOpenGLView(EGLView::getInstance()); auto glview = EGLView::createWithSize("Test Lua", Size(900,640));
director->setOpenGLView(glview);
// turn on display FPS // turn on display FPS
pDirector->setDisplayStats(true); director->setDisplayStats(true);
// set FPS. the default value is 1.0/60 if you don't call this // set FPS. the default value is 1.0/60 if you don't call this
pDirector->setAnimationInterval(1.0 / 60); director->setAnimationInterval(1.0 / 60);
auto screenSize = EGLView::getInstance()->getFrameSize(); auto screenSize = glview->getFrameSize();
auto designSize = Size(480, 320); auto designSize = Size(480, 320);
@ -41,10 +43,10 @@ bool AppDelegate::applicationDidFinishLaunching()
std::vector<std::string> searchPaths; std::vector<std::string> searchPaths;
searchPaths.push_back("hd"); searchPaths.push_back("hd");
pFileUtils->setSearchPaths(searchPaths); pFileUtils->setSearchPaths(searchPaths);
pDirector->setContentScaleFactor(resourceSize.height/designSize.height); director->setContentScaleFactor(resourceSize.height/designSize.height);
} }
EGLView::getInstance()->setDesignResolutionSize(designSize.width, designSize.height, ResolutionPolicy::FIXED_HEIGHT); glview->setDesignResolutionSize(designSize.width, designSize.height, ResolutionPolicy::FIXED_HEIGHT);
// register lua engine // register lua engine
LuaEngine* pEngine = LuaEngine::getInstance(); LuaEngine* pEngine = LuaEngine::getInstance();

View File

@ -24,7 +24,7 @@
#import <UIKit/UIKit.h> #import <UIKit/UIKit.h>
#import "AppController.h" #import "AppController.h"
#import "cocos2d.h" #import "cocos2d.h"
#import "EAGLView.h" #import "CCEAGLView.h"
#import "AppDelegate.h" #import "AppDelegate.h"
#import "RootViewController.h" #import "RootViewController.h"

View File

@ -29,7 +29,5 @@ USING_NS_CC;
int main(int argc, char *argv[]) int main(int argc, char *argv[])
{ {
AppDelegate app; AppDelegate app;
EGLView eglView;
eglView.init("TestLua",900,640);
return Application::getInstance()->run(); return Application::getInstance()->run();
} }