mirror of https://github.com/axmolengine/axmol.git
GLView improvements
it is not longer a singleton it is possible to specify the size
This commit is contained in:
parent
646dd2f8c5
commit
8ecaf49f93
|
@ -1 +1 @@
|
|||
e706fcdbf8b76069d794bc03e3849a57932cdf0a
|
||||
72b2e67ce3473ec4d8adf2412a9ce1d9390e0882
|
|
@ -376,9 +376,10 @@ void Director::setOpenGLView(EGLView *openGLView)
|
|||
conf->gatherGPUInfo();
|
||||
CCLOG("%s\n",conf->getInfo().c_str());
|
||||
|
||||
// EAGLView is not a Object
|
||||
delete _openGLView; // [openGLView_ release]
|
||||
if(_openGLView)
|
||||
_openGLView->release();
|
||||
_openGLView = openGLView;
|
||||
_openGLView->retain();
|
||||
|
||||
// set size
|
||||
_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,
|
||||
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->retain();
|
||||
|
|
|
@ -33,6 +33,8 @@ NS_CC_BEGIN
|
|||
* @{
|
||||
*/
|
||||
|
||||
class EAGLView;
|
||||
|
||||
class CC_DLL ApplicationProtocol
|
||||
{
|
||||
public:
|
||||
|
|
|
@ -131,9 +131,10 @@ void EGLViewProtocol::setDesignResolutionSize(float width, float height, Resolut
|
|||
_resolutionPolicy = resolutionPolicy;
|
||||
|
||||
// reset director's member variables to fit visible rect
|
||||
Director::getInstance()->_winSizeInPoints = getDesignResolutionSize();
|
||||
Director::getInstance()->createStatsLabel();
|
||||
Director::getInstance()->setGLDefaultValues();
|
||||
auto director = Director::getInstance();
|
||||
director->_winSizeInPoints = getDesignResolutionSize();
|
||||
director->createStatsLabel();
|
||||
director->setGLDefaultValues();
|
||||
}
|
||||
|
||||
const Size& EGLViewProtocol::getDesignResolutionSize() const
|
||||
|
|
|
@ -48,6 +48,39 @@ void initExtensions() {
|
|||
|
||||
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()
|
||||
{
|
||||
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()
|
||||
{
|
||||
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)
|
||||
{
|
||||
setKeyboardStateJNI((int)bOpen);
|
||||
|
|
|
@ -26,39 +26,32 @@ THE SOFTWARE.
|
|||
#ifndef __CC_EGLVIEW_ANDROID_H__
|
||||
#define __CC_EGLVIEW_ANDROID_H__
|
||||
|
||||
#include "CCObject.h"
|
||||
#include "CCGeometry.h"
|
||||
#include "platform/CCEGLViewProtocol.h"
|
||||
|
||||
NS_CC_BEGIN
|
||||
|
||||
class CC_DLL EGLView : public EGLViewProtocol
|
||||
class CC_DLL EGLView : public Object, public EGLViewProtocol
|
||||
{
|
||||
public:
|
||||
/**
|
||||
* @js ctor
|
||||
*/
|
||||
|
||||
// static function
|
||||
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);
|
||||
|
||||
bool isOpenGLReady() override;
|
||||
void end() override;
|
||||
void swapBuffers() override;
|
||||
void setIMEKeyboardState(bool bOpen) override;
|
||||
|
||||
protected:
|
||||
EGLView();
|
||||
/**
|
||||
* @js NA
|
||||
* @lua NA
|
||||
*/
|
||||
virtual ~EGLView();
|
||||
|
||||
bool isOpenGLReady();
|
||||
|
||||
// keep compatible
|
||||
void end();
|
||||
void swapBuffers();
|
||||
void setIMEKeyboardState(bool bOpen);
|
||||
|
||||
// static function
|
||||
/**
|
||||
@brief get the shared main open gl window
|
||||
*/
|
||||
static EGLView* getInstance();
|
||||
|
||||
/** @deprecated Use getInstance() instead */
|
||||
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
|
||||
|
|
|
@ -12,4 +12,4 @@
|
|||
|
||||
android.library=true
|
||||
# Project target.
|
||||
target=android-10
|
||||
target=android-19
|
||||
|
|
|
@ -111,29 +111,27 @@ extern EditTextCallback s_pfEditTextCallback;
|
|||
extern void* s_ctx;
|
||||
|
||||
extern "C" {
|
||||
JNIEXPORT void JNICALL Java_org_cocos2dx_lib_Cocos2dxHelper_nativeSetEditTextDialogResult(JNIEnv * env, jobject obj, jbyteArray text) {
|
||||
jsize size = env->GetArrayLength(text);
|
||||
pthread_mutex_lock(&(engine.app->mutex));
|
||||
if (size > 0) {
|
||||
|
||||
JNIEXPORT void JNICALL Java_org_cocos2dx_lib_Cocos2dxHelper_nativeSetEditTextDialogResult(JNIEnv * env, jobject obj, jbyteArray text) {
|
||||
jsize size = env->GetArrayLength(text);
|
||||
pthread_mutex_lock(&(engine.app->mutex));
|
||||
if (size > 0) {
|
||||
jbyte * data = (jbyte*)env->GetByteArrayElements(text, 0);
|
||||
char* pBuf = (char*)malloc(size+1);
|
||||
if (pBuf != NULL) {
|
||||
memcpy(pBuf, data, size);
|
||||
pBuf[size] = '\0';
|
||||
editboxText = pBuf;
|
||||
}
|
||||
env->ReleaseByteArrayElements(text, data, 0);
|
||||
|
||||
jbyte * data = (jbyte*)env->GetByteArrayElements(text, 0);
|
||||
char* pBuf = (char*)malloc(size+1);
|
||||
if (pBuf != NULL) {
|
||||
memcpy(pBuf, data, size);
|
||||
pBuf[size] = '\0';
|
||||
editboxText = pBuf;
|
||||
}
|
||||
env->ReleaseByteArrayElements(text, data, 0);
|
||||
|
||||
} else {
|
||||
char* pBuf = (char*)malloc(1);
|
||||
pBuf[0] = '\0';
|
||||
editboxText = pBuf;
|
||||
}
|
||||
pthread_cond_broadcast(&engine.app->cond);
|
||||
pthread_mutex_unlock(&(engine.app->mutex));
|
||||
}
|
||||
} else {
|
||||
char* pBuf = (char*)malloc(1);
|
||||
pBuf[0] = '\0';
|
||||
editboxText = pBuf;
|
||||
}
|
||||
pthread_cond_broadcast(&engine.app->cond);
|
||||
pthread_mutex_unlock(&(engine.app->mutex));
|
||||
}
|
||||
}
|
||||
|
||||
typedef struct cocos_dimensions {
|
||||
|
@ -148,10 +146,13 @@ static void cocos_init(cocos_dimensions d, struct android_app* app) {
|
|||
|
||||
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();
|
||||
view->setFrameSize(d.w, d.h);
|
||||
glview = cocos2d::EGLView::create("android app");
|
||||
director->setOpenGLView(glview);
|
||||
glview->setFrameSize(d.w, d.h);
|
||||
|
||||
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::DrawPrimitives::init();
|
||||
cocos2d::VolatileTextureMgr::reloadAllTextures();
|
||||
|
||||
cocos2d::EventCustom foregroundEvent(EVENT_COME_TO_FOREGROUND);
|
||||
cocos2d::Director::getInstance()->getEventDispatcher()->dispatchEvent(&foregroundEvent);
|
||||
cocos2d::Director::getInstance()->setGLDefaultValues();
|
||||
director->getEventDispatcher()->dispatchEvent(&foregroundEvent);
|
||||
director->setGLDefaultValues();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 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;
|
||||
r.w = -1;
|
||||
r.h = -1;
|
||||
|
@ -293,14 +296,14 @@ static void engine_draw_frame(struct engine* engine) {
|
|||
/* // Just fill the screen with a color. */
|
||||
/* glClearColor(((float)engine->state.x)/engine->width, engine->state.angle, */
|
||||
/* ((float)engine->state.y)/engine->height, 1); */
|
||||
/* glClear(GL_COLOR_BUFFER_BIT); */
|
||||
|
||||
if (s_pfEditTextCallback && editboxText)
|
||||
{
|
||||
s_pfEditTextCallback(editboxText, s_ctx);
|
||||
free(editboxText);
|
||||
editboxText = NULL;
|
||||
}
|
||||
/* glClear(GL_COLOR_BUFFER_BIT); */
|
||||
|
||||
if (s_pfEditTextCallback && editboxText)
|
||||
{
|
||||
s_pfEditTextCallback(editboxText, s_ctx);
|
||||
free(editboxText);
|
||||
editboxText = NULL;
|
||||
}
|
||||
|
||||
eglSwapBuffers(engine->display, engine->surface);
|
||||
}
|
||||
|
@ -390,7 +393,7 @@ static int32_t handle_touch_input(AInputEvent *event) {
|
|||
int ids[pointerCount];
|
||||
float xs[pointerCount], ys[pointerCount];
|
||||
getTouchPos(event, ids, xs, ys);
|
||||
cocos2d::Director::getInstance()->getOpenGLView()->handleTouchesMove(pointerCount, ids, xs, ys);
|
||||
cocos2d::Director::getInstance()->getOpenGLView()->handleTouchesMove(pointerCount, ids, xs, ys);
|
||||
return 1;
|
||||
}
|
||||
break;
|
||||
|
@ -435,7 +438,7 @@ static int32_t handle_touch_input(AInputEvent *event) {
|
|||
int ids[pointerCount];
|
||||
float xs[pointerCount], ys[pointerCount];
|
||||
getTouchPos(event, ids, xs, ys);
|
||||
cocos2d::Director::getInstance()->getOpenGLView()->handleTouchesCancel(pointerCount, ids, xs, ys);
|
||||
cocos2d::Director::getInstance()->getOpenGLView()->handleTouchesCancel(pointerCount, ids, xs, ys);
|
||||
return 1;
|
||||
}
|
||||
break;
|
||||
|
@ -458,7 +461,7 @@ static int32_t handle_key_input(AInputEvent *event)
|
|||
|
||||
switch (AKeyEvent_getKeyCode(event))
|
||||
{
|
||||
case AKEYCODE_BACK:
|
||||
case AKEYCODE_BACK:
|
||||
{
|
||||
cocos2d::EventKeyboard event(cocos2d::EventKeyboard::KeyCode::KEY_BACKSPACE, false);
|
||||
dispatcher->dispatchEvent(&event);
|
||||
|
@ -494,8 +497,8 @@ static int32_t engine_handle_input(struct android_app* app, AInputEvent* event)
|
|||
|
||||
return handle_touch_input(event);
|
||||
}
|
||||
else
|
||||
return handle_key_input(event);
|
||||
else
|
||||
return handle_key_input(event);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
@ -576,7 +579,7 @@ static void engine_handle_cmd(struct android_app* app, int32_t cmd) {
|
|||
case APP_CMD_GAINED_FOCUS:
|
||||
if (cocos2d::Director::getInstance()->getOpenGLView()) {
|
||||
cocos2d::Application::getInstance()->applicationWillEnterForeground();
|
||||
engine->animating = 1;
|
||||
engine->animating = 1;
|
||||
}
|
||||
|
||||
break;
|
||||
|
@ -594,8 +597,8 @@ static void engine_handle_cmd(struct android_app* app, int32_t cmd) {
|
|||
}
|
||||
|
||||
static void onContentRectChanged(ANativeActivity* activity, const ARect* rect) {
|
||||
timeRectChanged = std::chrono::steady_clock::now();
|
||||
isContentRectChanged = true;
|
||||
timeRectChanged = std::chrono::steady_clock::now();
|
||||
isContentRectChanged = true;
|
||||
}
|
||||
|
||||
static void process_input(struct android_app* app, struct android_poll_source* source) {
|
||||
|
@ -644,8 +647,8 @@ void android_main(struct android_app* state) {
|
|||
engine.state = *(struct saved_state*)state->savedState;
|
||||
}
|
||||
|
||||
// Screen size change support
|
||||
state->activity->callbacks->onContentRectChanged = onContentRectChanged;
|
||||
// Screen size change support
|
||||
state->activity->callbacks->onContentRectChanged = onContentRectChanged;
|
||||
|
||||
// loop waiting for stuff to do.
|
||||
|
||||
|
@ -735,19 +738,19 @@ void android_main(struct android_app* state) {
|
|||
LOG_RENDER_DEBUG("android_main : !engine.animating");
|
||||
}
|
||||
|
||||
// Check if screen size changed
|
||||
if (isContentRectChanged) {
|
||||
std::chrono::duration<int, std::milli> duration(
|
||||
std::chrono::duration_cast<std::chrono::duration<int, std::milli>>(std::chrono::steady_clock::now() - timeRectChanged));
|
||||
// Check if screen size changed
|
||||
if (isContentRectChanged) {
|
||||
std::chrono::duration<int, std::milli> duration(
|
||||
std::chrono::duration_cast<std::chrono::duration<int, std::milli>>(std::chrono::steady_clock::now() - timeRectChanged));
|
||||
|
||||
// Wait about 30 ms to get new width and height. Without waiting we can get old values sometime
|
||||
if (duration.count() > 30) {
|
||||
isContentRectChanged = false;
|
||||
// Wait about 30 ms to get new width and height. Without waiting we can get old values sometime
|
||||
if (duration.count() > 30) {
|
||||
isContentRectChanged = false;
|
||||
|
||||
int32_t newWidth = ANativeWindow_getWidth(engine.app->window);
|
||||
int32_t newHeight = ANativeWindow_getHeight(engine.app->window);
|
||||
cocos2d::Application::getInstance()->applicationScreenSizeChanged(newWidth, newHeight);
|
||||
}
|
||||
}
|
||||
int32_t newWidth = ANativeWindow_getWidth(engine.app->window);
|
||||
int32_t newHeight = ANativeWindow_getHeight(engine.app->window);
|
||||
cocos2d::Application::getInstance()->applicationScreenSizeChanged(newWidth, newHeight);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -205,7 +205,7 @@ void EGLViewEventHandler::onGLFWError(int errorID, const char* errorDesc)
|
|||
|
||||
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(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)
|
||||
{
|
||||
EGLView* eglView = EGLView::getInstance();
|
||||
EGLView* eglView = Director::getInstance()->getOpenGLView();
|
||||
if(nullptr == eglView) return;
|
||||
|
||||
if (eglView->isRetina()) {
|
||||
|
@ -280,7 +280,7 @@ void EGLViewEventHandler::onGLFWMouseMoveCallBack(GLFWwindow* window, double x,
|
|||
|
||||
void EGLViewEventHandler::onGLFWMouseScrollCallback(GLFWwindow* window, double x, double y)
|
||||
{
|
||||
EGLView* eglView = EGLView::getInstance();
|
||||
EGLView* eglView = Director::getInstance()->getOpenGLView();
|
||||
if(nullptr == eglView) return;
|
||||
|
||||
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)
|
||||
{
|
||||
auto view = EGLView::getInstance();
|
||||
auto view = Director::getInstance()->getOpenGLView();
|
||||
|
||||
float frameSizeW = view->getFrameSize().width;
|
||||
float frameSizeH = view->getFrameSize().height;
|
||||
|
@ -341,7 +341,39 @@ void EGLViewEventHandler::onGLFWframebuffersize(GLFWwindow* window, int w, int h
|
|||
// 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()
|
||||
: _captured(false)
|
||||
|
@ -351,9 +383,7 @@ EGLView::EGLView()
|
|||
, _mainWindow(nullptr)
|
||||
, _primaryMonitor(nullptr)
|
||||
{
|
||||
CCASSERT(nullptr == s_pEglView, "EGLView is singleton, Should be inited only one time\n");
|
||||
_viewName = "cocos2dx";
|
||||
s_pEglView = this;
|
||||
g_keyCodeMap.clear();
|
||||
for (auto& item : g_keyCodeStructArray)
|
||||
{
|
||||
|
@ -367,16 +397,12 @@ EGLView::~EGLView()
|
|||
{
|
||||
CCLOGINFO("deallocing EGLView: %p", this);
|
||||
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);
|
||||
setFrameSize(width, height);
|
||||
setFrameSize(size.width, size.height);
|
||||
setFrameZoomFactor(frameZoomFactor);
|
||||
|
||||
glfwWindowHint(GLFW_RESIZABLE,GL_FALSE);
|
||||
|
@ -397,7 +423,7 @@ bool EGLView::init(const std::string& viewName, float width, float height, float
|
|||
{
|
||||
_isRetina = true;
|
||||
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);
|
||||
|
@ -435,7 +461,7 @@ bool EGLView::initWithFullScreen(const std::string& viewName)
|
|||
return false;
|
||||
|
||||
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()
|
||||
|
@ -505,18 +531,6 @@ void EGLView::setScissorInPoints(float x , float y , float w , float h)
|
|||
(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)
|
||||
static bool glew_dynamic_binding()
|
||||
{
|
||||
|
|
|
@ -26,52 +26,29 @@ THE SOFTWARE.
|
|||
#ifndef __CC_EGLVIEW_DESKTOP_H__
|
||||
#define __CC_EGLVIEW_DESKTOP_H__
|
||||
|
||||
#include "CCObject.h"
|
||||
#include "platform/CCCommon.h"
|
||||
#include "platform/CCEGLViewProtocol.h"
|
||||
#include "glfw3.h"
|
||||
|
||||
NS_CC_BEGIN
|
||||
|
||||
class CC_DLL EGLView : public EGLViewProtocol
|
||||
class CC_DLL EGLView : public Object, public EGLViewProtocol
|
||||
{
|
||||
public:
|
||||
// static function
|
||||
/**
|
||||
@brief get the shared main open gl window
|
||||
*/
|
||||
static EGLView* getInstance();
|
||||
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);
|
||||
|
||||
/** @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.
|
||||
*/
|
||||
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);
|
||||
|
||||
float getFrameZoomFactor();
|
||||
float getFrameZoomFactor();
|
||||
//void centerWindow();
|
||||
|
||||
|
||||
virtual void setViewPortInPoints(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();
|
||||
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:
|
||||
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.
|
||||
*/
|
||||
|
@ -93,11 +83,13 @@ protected:
|
|||
bool _isRetina;
|
||||
|
||||
float _frameZoomFactor;
|
||||
static EGLView* s_pEglView;
|
||||
|
||||
GLFWwindow* _mainWindow;
|
||||
GLFWmonitor* _primaryMonitor;
|
||||
friend class EGLViewEventHandler;
|
||||
|
||||
private:
|
||||
CC_DISALLOW_COPY_AND_ASSIGN(EGLView);
|
||||
};
|
||||
|
||||
NS_CC_END // end of namespace cocos2d
|
||||
|
|
|
@ -63,7 +63,7 @@ Copyright (C) 2008 Apple Inc. All Rights Reserved.
|
|||
|
||||
#import <QuartzCore/QuartzCore.h>
|
||||
#import "CCEGLView.h"
|
||||
#import "EAGLView.h"
|
||||
#import "CCEAGLView.h"
|
||||
#import "CCES2Renderer.h"
|
||||
#import "CCDirector.h"
|
||||
#import "CCSet.h"
|
||||
|
@ -413,7 +413,9 @@ static CCEAGLView *__view = 0;
|
|||
ys[i] = [touch locationInView: [touch view]].y * __view.contentScaleFactor;;
|
||||
++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
|
||||
|
@ -433,7 +435,9 @@ static CCEAGLView *__view = 0;
|
|||
ys[i] = [touch locationInView: [touch view]].y * __view.contentScaleFactor;;
|
||||
++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
|
||||
|
@ -454,7 +458,9 @@ static CCEAGLView *__view = 0;
|
|||
ys[i] = [touch locationInView: [touch view]].y * __view.contentScaleFactor;;
|
||||
++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
|
||||
|
@ -475,7 +481,9 @@ static CCEAGLView *__view = 0;
|
|||
ys[i] = [touch locationInView: [touch view]].y * __view.contentScaleFactor;;
|
||||
++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
|
||||
|
@ -794,9 +802,10 @@ static CCEAGLView *__view = 0;
|
|||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
float scaleX = cocos2d::EGLView::getInstance()->getScaleX();
|
||||
float scaleY = cocos2d::EGLView::getInstance()->getScaleY();
|
||||
|
||||
auto glview = cocos2d::Director::getInstance()->getOpenGLView();
|
||||
float scaleX = glview->getScaleX();
|
||||
float scaleY = glview->getScaleY();
|
||||
|
||||
|
||||
if (self.contentScaleFactor == 2.0f)
|
||||
|
@ -807,7 +816,7 @@ static CCEAGLView *__view = 0;
|
|||
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);
|
||||
if (offestY < 0.0f)
|
||||
{
|
||||
|
@ -870,7 +879,8 @@ static CCEAGLView *__view = 0;
|
|||
|
||||
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)
|
||||
{
|
|
@ -26,6 +26,7 @@
|
|||
#ifndef __CC_EGLVIEW_IPHONE_H__
|
||||
#define __CC_EGLVIEW_IPHONE_H__
|
||||
|
||||
#include "CCObject.h"
|
||||
#include "platform/CCCommon.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:
|
||||
/**
|
||||
* @js NA
|
||||
* @lua NA
|
||||
*/
|
||||
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);
|
||||
|
||||
virtual bool setContentScaleFactor(float contentScaleFactor);
|
||||
|
||||
// overrides
|
||||
virtual bool isOpenGLReady() override;
|
||||
virtual void end() override;
|
||||
virtual void swapBuffers() override;
|
||||
virtual void setIMEKeyboardState(bool bOpen) override;
|
||||
|
||||
protected:
|
||||
EGLView();
|
||||
/**
|
||||
* @js NA
|
||||
* @lua NA
|
||||
*/
|
||||
~EGLView();
|
||||
/**
|
||||
* @js NA
|
||||
* @lua NA
|
||||
*/
|
||||
virtual bool isOpenGLReady();
|
||||
/**
|
||||
* @js NA
|
||||
* @lua NA
|
||||
*/
|
||||
virtual bool setContentScaleFactor(float contentScaleFactor);
|
||||
|
||||
// keep compatible
|
||||
/**
|
||||
* @js NA
|
||||
* @lua NA
|
||||
*/
|
||||
virtual void end();
|
||||
/**
|
||||
* @js NA
|
||||
* @lua NA
|
||||
*/
|
||||
virtual void swapBuffers();
|
||||
/**
|
||||
* @js NA
|
||||
* @lua NA
|
||||
*/
|
||||
virtual void setIMEKeyboardState(bool bOpen);
|
||||
|
||||
/** returns the singleton
|
||||
* @js NA
|
||||
*/
|
||||
static EGLView* getInstance();
|
||||
|
||||
/** @deprecated Use getInstance() instead
|
||||
* @js NA
|
||||
* @lua NA
|
||||
*/
|
||||
CC_DEPRECATED_ATTRIBUTE static EGLView* sharedOpenGLView();
|
||||
virtual ~EGLView();
|
||||
|
||||
bool initWithSize(const std::string& viewName, Size size, float frameZoomFactor);
|
||||
bool initWithFullScreen(const std::string& viewName);
|
||||
};
|
||||
|
||||
NS_CC_END
|
||||
|
|
|
@ -22,7 +22,7 @@
|
|||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
****************************************************************************/
|
||||
#include "EAGLView.h"
|
||||
#include "CCEAGLView.h"
|
||||
#include "CCDirectorCaller.h"
|
||||
#include "CCEGLView.h"
|
||||
#include "CCSet.h"
|
||||
|
@ -30,6 +30,39 @@
|
|||
|
||||
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()
|
||||
{
|
||||
_screenSize.width = _designResolutionSize.width = [[CCEAGLView sharedEGLView] getWidth];
|
||||
|
@ -41,19 +74,29 @@ 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()
|
||||
{
|
||||
return [CCEAGLView sharedEGLView] != nullptr;
|
||||
}
|
||||
|
||||
|
||||
bool EGLView::setContentScaleFactor(float contentScaleFactor)
|
||||
{
|
||||
assert(_resolutionPolicy == ResolutionPolicy::UNKNOWN); // cannot enable retina mode
|
||||
|
||||
_scaleX = _scaleY = contentScaleFactor;
|
||||
[[CCEAGLView sharedEGLView] setNeedsLayout];
|
||||
|
||||
return true;
|
||||
|
||||
_scaleX = _scaleY = contentScaleFactor;
|
||||
[[CCEAGLView sharedEGLView] setNeedsLayout];
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void EGLView::end()
|
||||
|
@ -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
|
||||
|
||||
|
|
|
@ -54,12 +54,12 @@ int Application::run()
|
|||
{
|
||||
return 0;
|
||||
}
|
||||
EGLView* pMainWnd = EGLView::getInstance();
|
||||
EGLView* glview = Director::getInstance()->getOpenGLView();
|
||||
|
||||
while (!pMainWnd->windowShouldClose())
|
||||
while (!glview->windowShouldClose())
|
||||
{
|
||||
Director::getInstance()->mainLoop();
|
||||
pMainWnd->pollEvents();
|
||||
glview->pollEvents();
|
||||
}
|
||||
|
||||
/* Only work on Desktop
|
||||
|
|
|
@ -23,7 +23,10 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|||
THE SOFTWARE.
|
||||
****************************************************************************/
|
||||
#include "platform/CCCommon.h"
|
||||
|
||||
#include "CCDirector.h"
|
||||
#include "CCEGLView.h"
|
||||
|
||||
#define GLFW_EXPOSE_NATIVE_NSGL
|
||||
#define GLFW_EXPOSE_NATIVE_COCOA
|
||||
#include "glfw3native.h"
|
||||
|
@ -51,7 +54,8 @@ void MessageBox(const char * msg, const char * title)
|
|||
[alert setInformativeText:tmpTitle];
|
||||
[alert setAlertStyle:NSWarningAlertStyle];
|
||||
|
||||
id window = glfwGetCocoaWindow(EGLView::getInstance()->getWindow());
|
||||
EGLView* glview = Director::getInstance()->getOpenGLView();
|
||||
id window = glfwGetCocoaWindow(glview->getWindow());
|
||||
[alert beginSheetModalForWindow:window
|
||||
modalDelegate:[window delegate]
|
||||
didEndSelector:nil
|
||||
|
|
|
@ -324,7 +324,8 @@ void Layout::onBeforeVisitScissor()
|
|||
{
|
||||
Rect clippingRect = getClippingRect();
|
||||
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()
|
||||
|
|
|
@ -29,15 +29,18 @@
|
|||
#define kLabelZOrder 9999
|
||||
|
||||
#include "CCEditBox.h"
|
||||
#import "EAGLView.h"
|
||||
#import "CCEAGLView.h"
|
||||
|
||||
#define getEditBoxImplIOS() ((cocos2d::extension::EditBoxImplIOS*)editBox_)
|
||||
|
||||
static const int CC_EDIT_BOX_PADDING = 5;
|
||||
|
||||
@implementation CCCustomUITextField
|
||||
- (CGRect)textRectForBounds:(CGRect)bounds {
|
||||
float padding = CC_EDIT_BOX_PADDING * cocos2d::EGLView::getInstance()->getScaleX() / [[CCEAGLView sharedEGLView] contentScaleFactor ];
|
||||
- (CGRect)textRectForBounds:(CGRect)bounds
|
||||
{
|
||||
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,
|
||||
bounds.size.width - padding*2, bounds.size.height - padding*2);
|
||||
}
|
||||
|
@ -281,9 +284,9 @@ bool EditBoxImplIOS::initWithSize(const Size& size)
|
|||
{
|
||||
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)
|
||||
{
|
||||
|
@ -358,7 +361,10 @@ void EditBoxImplIOS::setFont(const char* pFontName, int fontSize)
|
|||
|
||||
float retinaFactor = _inRetinaMode ? 2.0f : 1.0f;
|
||||
NSString * fntName = [NSString stringWithUTF8String:pFontName];
|
||||
float scaleFactor = EGLView::getInstance()->getScaleX();
|
||||
|
||||
auto glview = cocos2d::Director::getInstance()->getOpenGLView();
|
||||
|
||||
float scaleFactor = glview->getScaleX();
|
||||
UIFont *textFont = nil;
|
||||
if (isValidFontName) {
|
||||
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)
|
||||
{
|
||||
EGLViewProtocol* eglView = EGLView::getInstance();
|
||||
auto glview = cocos2d::Director::getInstance()->getOpenGLView();
|
||||
float viewH = (float)[[CCEAGLView sharedEGLView] getHeight];
|
||||
|
||||
Point visiblePos = Point(designCoord.x * eglView->getScaleX(), designCoord.y * eglView->getScaleY());
|
||||
Point screenGLPos = visiblePos + eglView->getViewPortRect().origin;
|
||||
Point visiblePos = Point(designCoord.x * glview->getScaleX(), designCoord.y * glview->getScaleY());
|
||||
Point screenGLPos = visiblePos + glview->getViewPortRect().origin;
|
||||
|
||||
CGPoint screenPos = CGPointMake(screenGLPos.x, viewH - screenGLPos.y);
|
||||
|
||||
|
@ -561,8 +567,8 @@ void EditBoxImplIOS::setContentSize(const Size& size)
|
|||
_contentSize = size;
|
||||
CCLOG("[Edit text] content size = (%f, %f)", size.width, size.height);
|
||||
placeInactiveLabels();
|
||||
EGLViewProtocol* eglView = EGLView::getInstance();
|
||||
CGSize controlSize = CGSizeMake(size.width * eglView->getScaleX(),size.height * eglView->getScaleY());
|
||||
auto glview = cocos2d::Director::getInstance()->getOpenGLView();
|
||||
CGSize controlSize = CGSizeMake(size.width * glview->getScaleX(),size.height * glview->getScaleY());
|
||||
|
||||
if (_inRetinaMode)
|
||||
{
|
||||
|
|
|
@ -24,6 +24,7 @@
|
|||
****************************************************************************/
|
||||
|
||||
#include "CCEditBoxImplMac.h"
|
||||
#include "CCDirector.h"
|
||||
|
||||
#if (CC_TARGET_PLATFORM == CC_PLATFORM_MAC)
|
||||
|
||||
|
@ -63,8 +64,10 @@
|
|||
@synthesize editState = editState_;
|
||||
@synthesize editBox = editBox_;
|
||||
|
||||
- (id) getNSWindow {
|
||||
return glfwGetCocoaWindow(cocos2d::EGLView::getInstance()->getWindow());
|
||||
- (id) getNSWindow
|
||||
{
|
||||
auto glview = cocos2d::Director::getInstance()->getOpenGLView();
|
||||
return glfwGetCocoaWindow(glview->getWindow());
|
||||
}
|
||||
|
||||
- (void)dealloc
|
||||
|
@ -265,7 +268,7 @@ void EditBoxImplMac::doAnimationWhenKeyboardMove(float duration, float distance)
|
|||
|
||||
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());
|
||||
|
||||
|
@ -356,7 +359,7 @@ NSPoint EditBoxImplMac::convertDesignCoordToScreenCoord(const Point& designCoord
|
|||
NSRect frame = [_sysEdit.textField frame];
|
||||
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 screenGLPos = visiblePos + eglView->getViewPortRect().origin;
|
||||
|
|
|
@ -44,7 +44,8 @@ NS_CC_EXT_BEGIN
|
|||
|
||||
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();
|
||||
}
|
||||
|
||||
|
@ -508,21 +509,23 @@ void ScrollView::onBeforeDraw()
|
|||
{
|
||||
_scissorRestored = false;
|
||||
Rect frame = getViewRect();
|
||||
if (EGLView::getInstance()->isScissorEnabled()) {
|
||||
auto glview = Director::getInstance()->getOpenGLView();
|
||||
|
||||
if (glview->isScissorEnabled()) {
|
||||
_scissorRestored = true;
|
||||
_parentScissorRect = EGLView::getInstance()->getScissorRect();
|
||||
_parentScissorRect = glview->getScissorRect();
|
||||
//set the intersection of _parentScissorRect and frame as the new scissor rect
|
||||
if (frame.intersectsRect(_parentScissorRect)) {
|
||||
float x = MAX(frame.origin.x, _parentScissorRect.origin.x);
|
||||
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 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 {
|
||||
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 (_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 {
|
||||
glDisable(GL_SCISSOR_TEST);
|
||||
|
|
|
@ -20,14 +20,14 @@ AppDelegate::~AppDelegate()
|
|||
bool AppDelegate::applicationDidFinishLaunching() {
|
||||
// initialize director
|
||||
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
|
||||
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;
|
||||
|
||||
|
|
|
@ -51,6 +51,6 @@ static cocos2d::Size designResolutionSize = cocos2d::Size(2048, 1536);
|
|||
#endif
|
||||
|
||||
// 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__ */
|
||||
|
|
|
@ -24,7 +24,7 @@
|
|||
#import <UIKit/UIKit.h>
|
||||
#import "AppController.h"
|
||||
#import "cocos2d.h"
|
||||
#import "EAGLView.h"
|
||||
#import "CCEAGLView.h"
|
||||
#import "AppDelegate.h"
|
||||
|
||||
#import "RootViewController.h"
|
||||
|
|
|
@ -29,8 +29,6 @@ USING_NS_CC;
|
|||
int main(int argc, char *argv[])
|
||||
{
|
||||
AppDelegate app;
|
||||
EGLView eglView;
|
||||
eglView.init("HelloCpp",900,640);
|
||||
return Application::getInstance()->run();
|
||||
}
|
||||
|
||||
|
|
|
@ -15,10 +15,11 @@ AppDelegate::~AppDelegate()
|
|||
bool AppDelegate::applicationDidFinishLaunching() {
|
||||
// initialize director
|
||||
auto director = Director::getInstance();
|
||||
auto glview = EGLView::createWithSize("Simple Game", Size(900,640));
|
||||
|
||||
director->setOpenGLView(glview);
|
||||
|
||||
director->setOpenGLView(EGLView::getInstance());
|
||||
|
||||
auto screenSize = EGLView::getInstance()->getFrameSize();
|
||||
auto screenSize = glview->getFrameSize();
|
||||
auto designSize = Size(480, 320);
|
||||
std::vector<std::string> searchPaths;
|
||||
|
||||
|
@ -36,7 +37,7 @@ bool AppDelegate::applicationDidFinishLaunching() {
|
|||
|
||||
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
|
||||
director->setDisplayStats(true);
|
||||
|
|
|
@ -24,7 +24,7 @@
|
|||
#import <UIKit/UIKit.h>
|
||||
#import "AppController.h"
|
||||
#import "cocos2d.h"
|
||||
#import "EAGLView.h"
|
||||
#import "CCEAGLView.h"
|
||||
#import "AppDelegate.h"
|
||||
|
||||
#import "RootViewController.h"
|
||||
|
|
|
@ -29,8 +29,6 @@ USING_NS_CC;
|
|||
int main(int argc, char *argv[])
|
||||
{
|
||||
AppDelegate app;
|
||||
EGLView eglView;
|
||||
eglView.init("SimpleGame",900,640);
|
||||
return Application::getInstance()->run();
|
||||
}
|
||||
|
||||
|
|
|
@ -26,14 +26,16 @@ bool AppDelegate::applicationDidFinishLaunching()
|
|||
// XXX: but at this point, the director is already initialized
|
||||
Configuration::getInstance()->loadConfigFile("configs/config-example.plist");
|
||||
|
||||
auto glview = EGLView::create("Test Cpp");
|
||||
|
||||
// initialize director
|
||||
auto director = Director::getInstance();
|
||||
director->setOpenGLView(EGLView::getInstance());
|
||||
director->setOpenGLView(glview);
|
||||
|
||||
director->setDisplayStats(true);
|
||||
director->setAnimationInterval(1.0 / 60);
|
||||
|
||||
auto screenSize = EGLView::getInstance()->getFrameSize();
|
||||
auto screenSize = glview->getFrameSize();
|
||||
|
||||
auto designSize = Size(480, 320);
|
||||
|
||||
|
@ -73,7 +75,7 @@ bool AppDelegate::applicationDidFinishLaunching()
|
|||
|
||||
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 layer = new TestController();
|
||||
|
|
|
@ -15,8 +15,9 @@ USING_NS_CC_EXT;
|
|||
|
||||
EditBoxTest::EditBoxTest()
|
||||
{
|
||||
auto visibleOrigin = EGLView::getInstance()->getVisibleOrigin();
|
||||
auto visibleSize = EGLView::getInstance()->getVisibleSize();
|
||||
auto glview = Director::getInstance()->getOpenGLView();
|
||||
auto visibleOrigin = glview->getVisibleOrigin();
|
||||
auto visibleSize = glview->getVisibleSize();
|
||||
|
||||
auto pBg = Sprite::create("Images/HelloWorld.png");
|
||||
pBg->setPosition(Point(visibleOrigin.x+visibleSize.width/2, visibleOrigin.y+visibleSize.height/2));
|
||||
|
|
|
@ -6,7 +6,7 @@ void VisibleRect::lazyInit()
|
|||
{
|
||||
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.size = glView->getVisibleSize();
|
||||
}
|
||||
|
|
|
@ -8,6 +8,6 @@
|
|||
# project structure.
|
||||
|
||||
# Project target.
|
||||
target=android-10
|
||||
target=android-19
|
||||
|
||||
android.library.reference.1=../../../../cocos/2d/platform/android/java
|
||||
|
|
|
@ -8,7 +8,7 @@
|
|||
|
||||
#import "testsAppDelegate.h"
|
||||
|
||||
#import "EAGLView.h"
|
||||
#import "CCEAGLView.h"
|
||||
#import "cocos2d.h"
|
||||
#import "AppDelegate.h"
|
||||
#import "RootViewController.h"
|
||||
|
|
|
@ -29,7 +29,5 @@ USING_NS_CC;
|
|||
int main(int argc, char *argv[])
|
||||
{
|
||||
AppDelegate app;
|
||||
EGLView eglView;
|
||||
eglView.init("TestCPP",900,640);
|
||||
return Application::getInstance()->run();
|
||||
}
|
||||
|
|
|
@ -32,14 +32,15 @@ AppDelegate::~AppDelegate()
|
|||
bool AppDelegate::applicationDidFinishLaunching()
|
||||
{
|
||||
// initialize director
|
||||
auto pDirector = Director::getInstance();
|
||||
pDirector->setOpenGLView(EGLView::getInstance());
|
||||
pDirector->setProjection(Director::Projection::_2D);
|
||||
auto director = Director::getInstance();
|
||||
auto glview = EGLView::createWithSize("CocosDragon JS", Size(480, 720));
|
||||
director->setOpenGLView(glview);
|
||||
director->setProjection(Director::Projection::_2D);
|
||||
|
||||
|
||||
FileUtils::getInstance()->addSearchPath("script");
|
||||
|
||||
auto screenSize = EGLView::getInstance()->getFrameSize();
|
||||
auto screenSize = glview->getFrameSize();
|
||||
|
||||
auto designSize = Size(320, 480);
|
||||
auto resourceSize = Size(320, 480);
|
||||
|
@ -110,15 +111,15 @@ bool AppDelegate::applicationDidFinishLaunching()
|
|||
|
||||
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
|
||||
pDirector->setDisplayStats(true);
|
||||
director->setDisplayStats(true);
|
||||
|
||||
// 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();
|
||||
sc->addRegisterCallback(register_all_cocos2dx);
|
||||
|
|
|
@ -8,7 +8,7 @@
|
|||
#import <UIKit/UIKit.h>
|
||||
#import "AppController.h"
|
||||
#import "cocos2d.h"
|
||||
#import "EAGLView.h"
|
||||
#import "CCEAGLView.h"
|
||||
#import "AppDelegate.h"
|
||||
|
||||
#import "RootViewController.h"
|
||||
|
|
|
@ -30,7 +30,5 @@ USING_NS_CC;
|
|||
int main(int argc, char *argv[])
|
||||
{
|
||||
AppDelegate app;
|
||||
EGLView eglView;
|
||||
eglView.init("CocosDragonJS", 480, 720);
|
||||
return Application::getInstance()->run();
|
||||
}
|
||||
|
|
|
@ -28,13 +28,15 @@ AppDelegate::~AppDelegate()
|
|||
bool AppDelegate::applicationDidFinishLaunching()
|
||||
{
|
||||
// initialize director
|
||||
auto pDirector = Director::getInstance();
|
||||
pDirector->setOpenGLView(EGLView::getInstance());
|
||||
pDirector->setProjection(Director::Projection::_2D);
|
||||
auto director = Director::getInstance();
|
||||
auto glview = EGLView::createWithSize("Crystal Craze", Size(480, 720));
|
||||
|
||||
director->setOpenGLView(glview);
|
||||
director->setProjection(Director::Projection::_2D);
|
||||
|
||||
FileUtils::getInstance()->addSearchPath("script");
|
||||
|
||||
auto screenSize = EGLView::getInstance()->getFrameSize();
|
||||
auto screenSize = glview->getFrameSize();
|
||||
|
||||
auto designSize = Size(320, 480);
|
||||
auto resourceSize = Size(320, 480);
|
||||
|
@ -91,15 +93,15 @@ bool AppDelegate::applicationDidFinishLaunching()
|
|||
|
||||
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
|
||||
pDirector->setDisplayStats(true);
|
||||
director->setDisplayStats(true);
|
||||
|
||||
// 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();
|
||||
sc->addRegisterCallback(register_all_cocos2dx);
|
||||
|
|
|
@ -8,7 +8,7 @@
|
|||
#import <UIKit/UIKit.h>
|
||||
#import "AppController.h"
|
||||
#import "cocos2d.h"
|
||||
#import "EAGLView.h"
|
||||
#import "CCEAGLView.h"
|
||||
#import "AppDelegate.h"
|
||||
|
||||
#import "RootViewController.h"
|
||||
|
|
|
@ -30,7 +30,5 @@ USING_NS_CC;
|
|||
int main(int argc, char *argv[])
|
||||
{
|
||||
AppDelegate app;
|
||||
EGLView eglView;
|
||||
eglView.init("CrystalCraze", 480, 720);
|
||||
return Application::getInstance()->run();
|
||||
}
|
||||
|
|
|
@ -28,18 +28,20 @@ AppDelegate::~AppDelegate()
|
|||
bool AppDelegate::applicationDidFinishLaunching()
|
||||
{
|
||||
// initialize director
|
||||
auto pDirector = Director::getInstance();
|
||||
pDirector->setOpenGLView(EGLView::getInstance());
|
||||
pDirector->setProjection(Director::Projection::_2D);
|
||||
auto director = Director::getInstance();
|
||||
auto glview = EGLView::createWithSize("Moon Warriors", Size(480, 720));
|
||||
|
||||
director->setOpenGLView(glview);
|
||||
director->setProjection(Director::Projection::_2D);
|
||||
|
||||
// Set the design resolution
|
||||
EGLView::getInstance()->setDesignResolutionSize(320, 480, ResolutionPolicy::SHOW_ALL);
|
||||
glview->setDesignResolutionSize(320, 480, ResolutionPolicy::SHOW_ALL);
|
||||
|
||||
// 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
|
||||
pDirector->setAnimationInterval(1.0 / 60);
|
||||
director->setAnimationInterval(1.0 / 60);
|
||||
|
||||
FileUtils::getInstance()->addSearchPath("script");
|
||||
|
||||
|
|
|
@ -8,7 +8,7 @@
|
|||
#import <UIKit/UIKit.h>
|
||||
#import "AppController.h"
|
||||
#import "cocos2d.h"
|
||||
#import "EAGLView.h"
|
||||
#import "CCEAGLView.h"
|
||||
#import "AppDelegate.h"
|
||||
|
||||
#import "RootViewController.h"
|
||||
|
|
|
@ -30,8 +30,6 @@ USING_NS_CC;
|
|||
int main(int argc, char *argv[])
|
||||
{
|
||||
AppDelegate app;
|
||||
EGLView eglView;
|
||||
eglView.init("MoonWarriors", 480, 720);
|
||||
return Application::getInstance()->run();
|
||||
}
|
||||
|
||||
|
|
|
@ -37,16 +37,18 @@ AppDelegate::~AppDelegate()
|
|||
bool AppDelegate::applicationDidFinishLaunching()
|
||||
{
|
||||
// initialize director
|
||||
auto pDirector = Director::getInstance();
|
||||
pDirector->setOpenGLView(EGLView::getInstance());
|
||||
auto director = Director::getInstance();
|
||||
auto glview = EGLView::createWithSize("Test JavaScript", Size(900,640));
|
||||
|
||||
director->setOpenGLView(glview);
|
||||
|
||||
// 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
|
||||
pDirector->setDisplayStats(true);
|
||||
director->setDisplayStats(true);
|
||||
|
||||
// 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();
|
||||
std::vector<std::string> searchPaths;
|
||||
|
|
|
@ -8,7 +8,7 @@
|
|||
#import <UIKit/UIKit.h>
|
||||
#import "AppController.h"
|
||||
#import "cocos2d.h"
|
||||
#import "EAGLView.h"
|
||||
#import "CCEAGLView.h"
|
||||
#import "AppDelegate.h"
|
||||
|
||||
#import "RootViewController.h"
|
||||
|
|
|
@ -30,8 +30,6 @@ USING_NS_CC;
|
|||
int main(int argc, char *argv[])
|
||||
{
|
||||
AppDelegate app;
|
||||
EGLView eglView;
|
||||
eglView.init("TestJavascript",900,640);
|
||||
return Application::getInstance()->run();
|
||||
}
|
||||
|
||||
|
|
|
@ -28,16 +28,17 @@ AppDelegate::~AppDelegate()
|
|||
bool AppDelegate::applicationDidFinishLaunching()
|
||||
{
|
||||
// initialize director
|
||||
auto pDirector = Director::getInstance();
|
||||
pDirector->setOpenGLView(EGLView::getInstance());
|
||||
auto director = Director::getInstance();
|
||||
auto glview = EGLView::createWithSize("Watermelon With Me", Size(900,640));
|
||||
director->setOpenGLView(glview);
|
||||
|
||||
// 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
|
||||
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");
|
||||
|
||||
|
|
|
@ -8,7 +8,7 @@
|
|||
#import <UIKit/UIKit.h>
|
||||
#import "AppController.h"
|
||||
#import "cocos2d.h"
|
||||
#import "EAGLView.h"
|
||||
#import "CCEAGLView.h"
|
||||
#import "AppDelegate.h"
|
||||
|
||||
#import "RootViewController.h"
|
||||
|
|
|
@ -30,8 +30,6 @@ USING_NS_CC;
|
|||
int main(int argc, char *argv[])
|
||||
{
|
||||
AppDelegate app;
|
||||
EGLView eglView;
|
||||
eglView.init("WatermelonWithMe",900,640);
|
||||
return Application::getInstance()->run();
|
||||
}
|
||||
|
||||
|
|
|
@ -23,16 +23,18 @@ AppDelegate::~AppDelegate()
|
|||
bool AppDelegate::applicationDidFinishLaunching()
|
||||
{
|
||||
// initialize director
|
||||
auto pDirector = Director::getInstance();
|
||||
pDirector->setOpenGLView(EGLView::getInstance());
|
||||
auto director = Director::getInstance();
|
||||
auto glview = EGLView::createWithSize("Hello Lua", Size(900,640));
|
||||
|
||||
director->setOpenGLView(glview);
|
||||
|
||||
EGLView::getInstance()->setDesignResolutionSize(480, 320, ResolutionPolicy::NO_BORDER);
|
||||
glview->setDesignResolutionSize(480, 320, ResolutionPolicy::NO_BORDER);
|
||||
|
||||
// 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
|
||||
pDirector->setAnimationInterval(1.0 / 60);
|
||||
director->setAnimationInterval(1.0 / 60);
|
||||
|
||||
// register lua engine
|
||||
LuaEngine* pEngine = LuaEngine::getInstance();
|
||||
|
|
|
@ -24,7 +24,7 @@
|
|||
#import <UIKit/UIKit.h>
|
||||
#import "AppController.h"
|
||||
#import "cocos2d.h"
|
||||
#import "EAGLView.h"
|
||||
#import "CCEAGLView.h"
|
||||
#import "AppDelegate.h"
|
||||
|
||||
#import "RootViewController.h"
|
||||
|
|
|
@ -30,7 +30,5 @@ USING_NS_CC;
|
|||
int main(int argc, char *argv[])
|
||||
{
|
||||
AppDelegate app;
|
||||
EGLView eglView;
|
||||
eglView.init("HelloLua",900,640);
|
||||
return Application::getInstance()->run();
|
||||
}
|
||||
|
|
|
@ -20,16 +20,18 @@ AppDelegate::~AppDelegate()
|
|||
bool AppDelegate::applicationDidFinishLaunching()
|
||||
{
|
||||
// initialize director
|
||||
auto pDirector = Director::getInstance();
|
||||
pDirector->setOpenGLView(EGLView::getInstance());
|
||||
auto director = Director::getInstance();
|
||||
auto glview = EGLView::createWithSize("Test Lua", Size(900,640));
|
||||
|
||||
director->setOpenGLView(glview);
|
||||
|
||||
// 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
|
||||
pDirector->setAnimationInterval(1.0 / 60);
|
||||
director->setAnimationInterval(1.0 / 60);
|
||||
|
||||
auto screenSize = EGLView::getInstance()->getFrameSize();
|
||||
auto screenSize = glview->getFrameSize();
|
||||
|
||||
auto designSize = Size(480, 320);
|
||||
|
||||
|
@ -41,10 +43,10 @@ bool AppDelegate::applicationDidFinishLaunching()
|
|||
std::vector<std::string> searchPaths;
|
||||
searchPaths.push_back("hd");
|
||||
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
|
||||
LuaEngine* pEngine = LuaEngine::getInstance();
|
||||
|
|
|
@ -24,7 +24,7 @@
|
|||
#import <UIKit/UIKit.h>
|
||||
#import "AppController.h"
|
||||
#import "cocos2d.h"
|
||||
#import "EAGLView.h"
|
||||
#import "CCEAGLView.h"
|
||||
#import "AppDelegate.h"
|
||||
|
||||
#import "RootViewController.h"
|
||||
|
|
|
@ -29,7 +29,5 @@ USING_NS_CC;
|
|||
int main(int argc, char *argv[])
|
||||
{
|
||||
AppDelegate app;
|
||||
EGLView eglView;
|
||||
eglView.init("TestLua",900,640);
|
||||
return Application::getInstance()->run();
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue