void ScreenSizeManager::DoInitFixedScreenSize(float myScreenWidth, float myScreenHeight) { _isInit = true; // cocos2d-x v3.0.0 이상만 지원. CCAssert(0x00030000 <= COCOS2D_VERSION, "ScreenSizeManager need to cocos2d-x 3.0.0 or higher!"); Director* kDirector = CCDirector::getInstance(); CCAssert(kDirector->getOpenGLView(), "ScreenSizeManager need to kDirector->getOpenGLView() is not NULL"); Size kWinSize = kDirector->getWinSize(); _screenSize.width = kWinSize.width; _screenSize.height = kWinSize.height; _imageResolutionSize.width = myScreenWidth; _imageResolutionSize.height = myScreenHeight; log("DoInitFixedScreenSizeManager %f %f", _imageResolutionSize.width, _imageResolutionSize.height); // Cocos2d상의 포인트영역이 _imageResolutionSize.width, _imageResolutionSize.height 으로 설정된다. // CCDirector::sharedDirector()->getWinSize()의 width, height 가 _imageResolutionSize.width, _imageResolutionSize.height 로 된다. ResolutionPolicy kResolutionPolicy = ResolutionPolicy::NO_BORDER; GLView* kGLView = kDirector->getOpenGLView(); kGLView->setDesignResolutionSize(_imageResolutionSize.width, _imageResolutionSize.height, kResolutionPolicy); }
void ClippingRectangleNode::onBeforeVisitScissor() { if (_clippingEnabled) { // record old ClipRegion GLView* glView = Director::getInstance()->getOpenGLView(); if (glView->isScissorEnabled()) { _preClipRegion = glView->getScissorRect(); } else { _preClipRegion = Rect::ZERO; } glEnable(GL_SCISSOR_TEST); float scaleX = _scaleX; float scaleY = _scaleY; Node *parent = this->getParent(); while (parent) { scaleX *= parent->getScaleX(); scaleY *= parent->getScaleY(); parent = parent->getParent(); } // push this ClipRegion const Point pos = convertToWorldSpace(Point(_clippingRegion.origin.x, _clippingRegion.origin.y)); glView->setScissorInPoints(pos.x, pos.y, _clippingRegion.size.width * scaleX, _clippingRegion.size.height * scaleY); } }
// Creates and restores Cocos2d-x after DirectX and Angle contexts are created or updated void Cocos2dRenderer::CreateGLResources() { auto director = cocos2d::Director::getInstance(); if(!mInitialized) { mInitialized = true; GLView* glview = GLView::create("Test Cpp"); glview->Create(m_eglDisplay, m_eglContext, m_eglSurface, m_renderTargetSize.Width, m_renderTargetSize.Height,m_orientation); director->setOpenGLView(glview); CCApplication::getInstance()->run(); glview->SetXamlEventDelegate(m_delegate); glview->SetXamlMessageBoxDelegate(m_messageBoxDelegate); glview->SetXamlEditBoxDelegate(m_editBoxDelegate); } else { cocos2d::GL::invalidateStateCache(); cocos2d::ShaderCache::getInstance()->reloadDefaultGLPrograms(); cocos2d::DrawPrimitives::init(); cocos2d::VolatileTextureMgr::reloadAllTextures(); cocos2d::EventCustom recreatedEvent(EVENT_RENDERER_RECREATED); director->getEventDispatcher()->dispatchEvent(&recreatedEvent); cocos2d::Application::getInstance()->applicationWillEnterForeground(); director->setGLDefaultValues(); } m_loadingComplete = true; }
int main(int argc, char *argv[]) { QApplication a(argc, argv); GLView v; v.show(); return a.exec(); }
void EditBoxImplWin::openKeyboard() { if (_delegate != nullptr) { _delegate->editBoxEditingDidBegin(_editBox); } CEditBox* pEditBox = this->getEditBox(); if (nullptr != pEditBox && 0 != pEditBox->getScriptEditBoxHandler()) { CommonScriptData data(pEditBox->getScriptEditBoxHandler(), "began",pEditBox); ScriptEvent event(kCommonEvent,(void*)&data); ScriptEngineManager::getInstance()->getScriptEngine()->sendEvent(&event); } std::string placeHolder = _labelPlaceHolder->getString(); if (placeHolder.length() == 0) placeHolder = "Enter value"; char pText[100]= {0}; std::string text = getText(); if (text.length()) strncpy(pText, text.c_str(), 100); GLView *glView = Director::getInstance()->getOpenGLView(); GLFWwindow *glfwWindow = glView->getWindow(); HWND hwnd = glfwGetWin32Window(glfwWindow); bool didChange = CWin32InputBox::InputBox("Input", placeHolder.c_str(), pText, 100, false, hwnd) == IDOK; if (didChange) setText(pText); if (_delegate != nullptr) { if (didChange) _delegate->editBoxTextChanged(_editBox, getText()); _delegate->editBoxEditingDidEnd(_editBox); _delegate->editBoxReturn(_editBox); } #if CC_ENABLE_SCRIPT_BINDING if (nullptr != _editBox && 0 != _editBox->getScriptEditBoxHandler()) { CommonScriptData data(_editBox->getScriptEditBoxHandler(), "changed",_editBox); ScriptEvent event(kCommonEvent,(void*)&data); if (didChange) { ScriptEngineManager::getInstance()->getScriptEngine()->sendEvent(&event); } memset(data.eventName,0,sizeof(data.eventName)); strncpy(data.eventName,"ended",sizeof(data.eventName)); event.data = (void*)&data; ScriptEngineManager::getInstance()->getScriptEngine()->sendEvent(&event); memset(data.eventName,0,sizeof(data.eventName)); strncpy(data.eventName,"return",sizeof(data.eventName)); event.data = (void*)&data; ScriptEngineManager::getInstance()->getScriptEngine()->sendEvent(&event); } #endif // #if CC_ENABLE_SCRIPT_BINDING }
void WelcomeMenu::_startGameMenuCallback(Ref* pSender) { Director* director = Director::getInstance(); GLView* glView = director->getOpenGLView(); Size frameSize = glView->getFrameSize(); Size winSize = director->getWinSize(); log("winSize %f=%f ",winSize.width, winSize.height ); log("frameSize %f=%f", frameSize.width, frameSize.height); }
// return true if eglSwapBuffers was called by OnRender() bool Cocos2dRenderer::OnRender() { if(m_loadingComplete) { GLView* glview = GLView::sharedOpenGLView(); glview->Render(); return true; // eglSwapBuffers was called by glview->Render(); } return false; }
void GLViewEventHandler::onGLFWMouseScrollCallback(GLFWwindow* window, double x, double y) { GLView* eglView = Director::getInstance()->getOpenGLView(); if(nullptr == eglView) return; EventMouse event(EventMouse::MouseEventType::MOUSE_SCROLL); //Because OpenGL and cocos2d-x uses different Y axis, we need to convert the coordinate here event.setScrollData((float)x, -(float)y); event.setCursorPosition(s_mouseX, eglView->getViewPortRect().size.height - s_mouseY); Director::getInstance()->getEventDispatcher()->dispatchEvent(&event); }
int main(int argc, char *argv[]) { QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling); QGuiApplication app(argc, argv); GLView view; view.setResizeMode(QQuickView::SizeRootObjectToView); view.setSource(QUrl("qrc:/main.qml")); view.show(); return app.exec(); }
void GLUINavigationProgram::Handle_Display() { glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT); DEBUG_GL_ERRORS() glMatrixMode(GL_MODELVIEW); glLoadIdentity(); //SetWorldLights(); camera.toCamera(viewport); GLView view; view.setViewport(viewport); view.setCurrentGL(); SetWorldLights(); DEBUG_GL_ERRORS() if(stereo_mode){ glColorMask(GL_FALSE,GL_TRUE,GL_TRUE,GL_TRUE); // draw only to green, blue and alpha glMatrixMode(GL_PROJECTION); glPushMatrix(); glTranslatef(-stereo_offset*camera.dist,0,0); RenderWorld(); glPopMatrix(); glClear(GL_DEPTH_BUFFER_BIT); // leave the blue image but clear Z (NOTE: may need to clear alpha as well for transparency effects!) glColorMask(GL_TRUE,GL_FALSE,GL_FALSE,GL_TRUE); // draw only to red and alpha glMatrixMode(GL_PROJECTION); glPushMatrix(); glTranslatef(stereo_offset*camera.dist,0,0); RenderWorld(); glPopMatrix(); glColorMask(GL_TRUE,GL_TRUE,GL_TRUE,GL_TRUE);} else { RenderWorld(); if(show_view_target) DisplayCameraTarget(); } DEBUG_GL_ERRORS() glMatrixMode(GL_PROJECTION); glLoadIdentity(); glOrtho(0,viewport.w,viewport.h,0,-100,100); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); RenderScreen(); DEBUG_GL_ERRORS() ++frames_rendered; glutSwapBuffers(); SleepIdleCallback(0); }
bool TextFieldTTF::detachWithIME() { bool ret = IMEDelegate::detachWithIME(); if (ret) { // close keyboard GLView * glView = Director::getInstance()->getOpenGLView(); if (glView) { glView->setIMEKeyboardState(false); } } return ret; }
void GLView::IdleDisplay() { const unsigned n_views = inherited_views_.size(); for (unsigned i = 0; i < n_views; ++i) { GLView* view = inherited_views_[i]; const unsigned n_listeners = view->listeners_.size(); for (unsigned i = 0; i < n_listeners; ++i) { if (view->listeners_[i]->IsEnabled()) { view->listeners_[i]->DoEvents(); } } glutSetWindow(view->window_handle_); view->Display(); } }
bool TextFieldTTF::attachWithIME() { bool ret = IMEDelegate::attachWithIME(); if (ret) { // open keyboard GLView * pGlView = Director::getInstance()->getOpenGLView(); if (pGlView) { pGlView->setIMEKeyboardState(true); } } return ret; }
void ScreenSizeManager::DoInitFlexibleScreenSize(float myImageResolutionWidth, float myImageResolutionHeight) { _isInit = true; // cocos2d-x v3.0.0 이상만 지원. CCAssert(0x00030000 <= COCOS2D_VERSION, "ScreenSizeManager need to cocos2d-x 3.0.0 or higher!"); Director* kDirector = Director::getInstance(); CCAssert(kDirector->getOpenGLView(), "ScreenSizeManager need to kDirector->getOpenGLView() is not NULL"); Size kWinSize = kDirector->getWinSize(); _screenSize.width = kWinSize.width; _screenSize.height = kWinSize.height; _imageResolutionSize.width = myImageResolutionWidth; _imageResolutionSize.height = myImageResolutionHeight; float kDefaultDesignResRatio = _imageResolutionSize.width / _imageResolutionSize.height; float kScreenRatio = _screenSize.width / _screenSize.height; if ( kDefaultDesignResRatio <= kScreenRatio) { float kHeightRatio = _screenSize.height / _imageResolutionSize.height; // 폭이 넓은 경우 _imageResolutionSize.width = (int)(_screenSize.width / kHeightRatio); _isScaleHeight = true; } else { // 높이가 긴 경우 float kWidthRatio = _screenSize.width / _imageResolutionSize.width; // 폭이 넓은 경우 _imageResolutionSize.height = (int)(_screenSize.height / kWidthRatio); _isScaleHeight = false; } log("DoInitResourceSizeScreen %f %f", _imageResolutionSize.width, _imageResolutionSize.height); // Cocos2d상의 포인트영역이 _imageResolutionSize.width, _imageResolutionSize.height 으로 설정된다. // CCDirector::sharedDirector()->getWinSize()의 width, height 가 _imageResolutionSize.width, _imageResolutionSize.height 로 된다. ResolutionPolicy kResolutionPolicy = ResolutionPolicy::NO_BORDER; GLView* kGLView = kDirector->getOpenGLView(); kGLView->setDesignResolutionSize(_imageResolutionSize.width, _imageResolutionSize.height, kResolutionPolicy); }
void ClippingRectangleNode::onAfterVisitScissor() { if (_clippingEnabled) { // rollback to old ClipRegion if (_preClipRegion.size.width > 0) { GLView* glView = Director::getInstance()->getOpenGLView(); glView->setScissorInPoints(_preClipRegion.origin.x, _preClipRegion.origin.y, _preClipRegion.size.width, _preClipRegion.size.height); } else { glDisable(GL_SCISSOR_TEST); } } }
bool WelcomeMenu::init() { if(!Layer::init()) { return false; } GLView* glView = Director::getInstance()->getOpenGLView(); enum ResolutionPolicy policy = ResolutionPolicy::SHOW_ALL; glView->setDesignResolutionSize(960, 640, policy); Size visibleSize = Director::getInstance()->getVisibleSize(); Point origin = Director::getInstance()->getVisibleOrigin(); auto menu = this->_createMenu(); menu->setPosition(480, 320); this->addChild(menu); return true; }
void GLViewEventHandler::onGLFWMouseMoveCallBack(GLFWwindow* window, double x, double y) { GLView* eglView = Director::getInstance()->getOpenGLView(); if(nullptr == eglView) return; if (eglView->isRetina()) { x *= 2; y *= 2; } s_mouseX = (float)x; s_mouseY = (float)y; s_mouseX /= eglView->getFrameZoomFactor(); s_mouseY /= eglView->getFrameZoomFactor(); if(s_captured) { if (eglView->getViewPortRect().equals(Rect::ZERO) || eglView->getViewPortRect().containsPoint(Point(s_mouseX,eglView->getFrameSize().height - s_mouseY))) { int id = 0; eglView->handleTouchesMove(1, &id, &s_mouseX, &s_mouseY); } } EventMouse event(EventMouse::MouseEventType::MOUSE_MOVE); //Because OpenGL and cocos2d-x uses different Y axis, we need to convert the coordinate here event.setCursorPosition(s_mouseX, eglView->getViewPortRect().size.height - s_mouseY); Director::getInstance()->getEventDispatcher()->dispatchEvent(&event); }
void WebViewImpl::draw(Renderer *renderer, Mat4 const &transform, uint32_t flags) { if (_createSucceeded && (flags & Node::FLAGS_TRANSFORM_DIRTY)) { Director *directorInstance = cocos2d::Director::getInstance(); GLView *glView = directorInstance->getOpenGLView(); const Size &frameSize = glView->getFrameSize(); const Size &winSize = directorInstance->getWinSize(); Vec2 leftBottom = this->_webView->convertToWorldSpace(Point::ZERO); Vec2 rightTop = this->_webView->convertToWorldSpace(Point(_webView->getContentSize().width, _webView->getContentSize().height)); float uiLeft = frameSize.width / 2 + (leftBottom.x - winSize.width / 2) * glView->getScaleX(); float uiTop = frameSize.height / 2 - (rightTop.y - winSize.height / 2) * glView->getScaleY(); _systemWebControl->setWebViewRect(uiLeft, uiTop, (rightTop.x - leftBottom.x) * glView->getScaleX(), (rightTop.y - leftBottom.y) * glView->getScaleY()); } }
bool Camera::initPerspective(float fieldOfView, float aspectRatio, float nearPlane, float farPlane) { _fieldOfView = fieldOfView; _aspectRatio = aspectRatio; _nearPlane = nearPlane; _farPlane = farPlane; Mat4::createPerspective(_fieldOfView, _aspectRatio, _nearPlane, _farPlane, &_projection); #if CC_TARGET_PLATFORM == CC_PLATFORM_WP8 //if needed, we need to add a rotation for Landscape orientations on Windows Phone 8 since it is always in Portrait Mode GLView* view = Director::getInstance()->getOpenGLView(); if(view != nullptr) { setAdditionalProjection(view->getOrientationMatrix()); } #endif _viewProjectionDirty = true; return true; }
bool Camera::initOrthographic(float zoomX, float zoomY, float nearPlane, float farPlane) { _zoom[0] = zoomX; _zoom[1] = zoomY; _nearPlane = nearPlane; _farPlane = farPlane; Mat4::createOrthographicOffCenter(0, _zoom[0], 0, _zoom[1], _nearPlane, _farPlane, &_projection); #if CC_TARGET_PLATFORM == CC_PLATFORM_WP8 //if needed, we need to add a rotation for Landscape orientations on Windows Phone 8 since it is always in Portrait Mode GLView* view = Director::getInstance()->getOpenGLView(); if(view != nullptr) { setAdditionalProjection(view->getOrientationMatrix()); } #endif _viewProjectionDirty = true; return true; }
void PopupLayer::setBackground() { GLView* pEGLView = Director::getInstance()->getOpenGLView(); Size frameSize = pEGLView->getFrameSize(); Sprite *colorBG = Sprite::create(); colorBG->setTextureRect(Rect(0, 0, frameSize.width, frameSize.height)); colorBG->setColor(Color3B::BLACK); colorBG->setOpacity(150); colorBG->setPosition(Point(0, 0)); colorBG->setScale(2.0f); this->addChild(colorBG); if (mBackgroundImage.size() > 0) { mBackgroundSprite = Sprite::create(mBackgroundImage.c_str()); this->addChild(mBackgroundSprite); } else { mBackgroundSprite = Sprite::create(); this->addChild(mBackgroundSprite); } }
void ClippingRectangleNode::onBeforeVisitScissor() { if (_clippingEnabled) { glEnable(GL_SCISSOR_TEST); float scaleX = _scaleX; float scaleY = _scaleY; Node *parent = this->getParent(); while (parent) { scaleX *= parent->getScaleX(); scaleY *= parent->getScaleY(); parent = parent->getParent(); } const Point pos = convertToWorldSpace(Point(_clippingRegion.origin.x, _clippingRegion.origin.y)); GLView* glView = Director::getInstance()->getOpenGLView(); glView->setScissorInPoints(pos.x, pos.y, _clippingRegion.size.width * scaleX, _clippingRegion.size.height * scaleY); } }
void GLViewEventHandler::onGLFWMouseCallBack(GLFWwindow* window, int button, int action, int modify) { GLView* eglView = Director::getInstance()->getOpenGLView(); if(nullptr == eglView) return; if(GLFW_MOUSE_BUTTON_LEFT == button) { if(GLFW_PRESS == action) { s_captured = true; if (eglView->getViewPortRect().equals(Rect::ZERO) || eglView->getViewPortRect().containsPoint(Point(s_mouseX,s_mouseY))) { int id = 0; eglView->handleTouchesBegin(1, &id, &s_mouseX, &s_mouseY); } } else if(GLFW_RELEASE == action) { s_captured = false; if (eglView->getViewPortRect().equals(Rect::ZERO) || eglView->getViewPortRect().containsPoint(Point(s_mouseX,s_mouseY))) { int id = 0; eglView->handleTouchesEnd(1, &id, &s_mouseX, &s_mouseY); } } } if(GLFW_PRESS == action) { EventMouse event(EventMouse::MouseEventType::MOUSE_DOWN); //Because OpenGL and cocos2d-x uses different Y axis, we need to convert the coordinate here event.setCursorPosition(s_mouseX, eglView->getViewPortRect().size.height - s_mouseY); event.setMouseButton(button); Director::getInstance()->getEventDispatcher()->dispatchEvent(&event); } else if(GLFW_RELEASE == action) { EventMouse event(EventMouse::MouseEventType::MOUSE_UP); //Because OpenGL and cocos2d-x uses different Y axis, we need to convert the coordinate here event.setCursorPosition(s_mouseX, eglView->getViewPortRect().size.height - s_mouseY); event.setMouseButton(button); Director::getInstance()->getEventDispatcher()->dispatchEvent(&event); } }
void EditBoxImplWin::openKeyboard() { if (_delegate != NULL) { _delegate->editBoxEditingDidBegin(_editBox); } EditBox* pEditBox = this->getEditBox(); if (NULL != pEditBox && 0 != pEditBox->getScriptEditBoxHandler()) { CommonScriptData data(pEditBox->getScriptEditBoxHandler(), "began",pEditBox); ScriptEvent event(kCommonEvent,(void*)&data); ScriptEngineManager::getInstance()->getScriptEngine()->sendEvent(&event); } std::string placeHolder = _labelPlaceHolder->getString(); if (placeHolder.length() == 0) placeHolder = "Enter value"; char pText[100]= {0}; std::string text = getText(); if (text.length()) strncpy(pText, text.c_str(), 100); GLView *glView = Director::getInstance()->getOpenGLView(); GLFWwindow *glfwWindow = glView->getWindow(); HWND hwnd = glfwGetWin32Window(glfwWindow); bool didChange = CWin32InputBox::InputBox("Input", placeHolder.c_str(), pText, 100, false, hwnd) == IDOK; if (didChange) setText(pText); if (_delegate != NULL) { if (didChange) _delegate->editBoxTextChanged(_editBox, getText()); _delegate->editBoxEditingDidEnd(_editBox); _delegate->editBoxReturn(_editBox); } }
bool AppDelegate::applicationDidFinishLaunching() { // initialize director Director* pDirector = gDirector; GLView* pGLView = pDirector->getOpenGLView(); if( NULL == pGLView ) { pGLView = GLView::create("game(v1.0.0.0)---test for inner"); #if (CC_TARGET_PLATFORM == CC_PLATFORM_WIN32) pGLView->setFrameSize(1334, 750); #endif pDirector->setOpenGLView(pGLView); } // turn on display FPS pDirector->setDisplayStats(true); // set FPS. the default value is 1.0/60 if you don't call this pDirector->setAnimationInterval(1.0 / 60); // resolution information Size size; size= pDirector->getWinSize(); log("***IDONG: Director getWinSize:w=%f,h=%f",size.width,size.height); size = pDirector->getWinSizeInPixels(); log("***IDONG: Director getWinSizeInPixels:w=%f,h=%f",size.width,size.height); size = pDirector->getVisibleSize(); log("***IDONG: Director getVisibleSize:w=%f,h=%f",size.width,size.height); Point point = pDirector->getVisibleOrigin(); log("***IDONG: Director getVisibleOrigin:x=%f,y=%f",point.x,point.y); log("***IDONG: Director BS: getContentScaleFactor: scaleFactor=%f",pDirector->getContentScaleFactor()); auto framsize = pGLView->getFrameSize(); auto dwinsize = pDirector->getWinSize(); auto designsize = Size(SCREEN_WIDTH, SCREEN_HEIGHT); auto widthRate = framsize.width/designsize.width; auto heightRate = framsize.height/designsize.height; auto resolutionRate = 1.f; if(widthRate > heightRate) { pGLView->setDesignResolutionSize(designsize.width, designsize.height*heightRate/widthRate, ResolutionPolicy::NO_BORDER); resolutionRate = heightRate/widthRate; } else { pGLView->setDesignResolutionSize(designsize.width*widthRate/heightRate, designsize.height, ResolutionPolicy::NO_BORDER); resolutionRate = widthRate/heightRate; } //pGLView->setDesignResolutionSize(SCREEN_WIDTH, SCREEN_HEIGHT, ResolutionPolicy::FIXED_HEIGHT); log("***IDONG:/n"); log("***IDONG: Director AS: getContentScaleFactor: scaleFactor=%f",pDirector->getContentScaleFactor()); size= pDirector->getWinSize(); log("***IDONG: Director getWinSize:w=%f,h=%f",size.width,size.height); size = pDirector->getWinSizeInPixels(); log("***IDONG: Director getWinSizeInPixels:w=%f,h=%f",size.width,size.height); size = pDirector->getVisibleSize(); log("***IDONG: Director getVisibleSize:w=%f,h=%f",size.width,size.height); point = pDirector->getVisibleOrigin(); log("***IDONG: Director getVisibleOrigin:x=%f,y=%f",point.x,point.y); // ‘ˆº”À—À˜¬∑æ∂ gFileUtils->addSearchPath("assets"); // …Ë÷√◊ ‘¥ƒø¬�? // ≥ı ºªØ◊ ‘¥ƒø¬�?dumpŒƒº˛…˙≥…ƒø¬�? string logfile = ""; #if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID) gGameManager->SetResourceRoot("/mnt/sdcard/com.zm.mszb/"); gGameManager->CreateDirectory(gGameManager->GetResourceRoot()); gGameManager->CreateDirectory(gGameManager->GetLogPath()); logfile = gGameManager->GetLogPath()+"/log.txt"; gLog->Open(logfile.c_str()); #endif #if (CC_TARGET_PLATFORM == CC_PLATFORM_WIN32) gGameManager->SetResourceRoot(""); gGameManager->CreateDirectory(gGameManager->GetResourceRoot()); gGameManager->CreateDirectory(gGameManager->GetLogPath()); logfile = gGameManager->GetLogPath()+"/log.txt"; gLog->Open(logfile.c_str()); #endif #if (CC_TARGET_PLATFORM == CC_PLATFORM_IOS) gGameManager->SetResourceRoot(gFileUtils->getWritablePath()); gGameManager->CreateDirectory(gGameManager->GetResourceRoot()); gGameManager->CreateDirectory(gGameManager->GetLogPath()); logfile = gGameManager->GetLogPath()+"/log.txt"; gLog->Open(logfile.c_str()); #endif gGameManager->LogMachineInfo(); // ø™ º∏¸–�? gGameManager->Start(); return true; }
void Cocos2dRenderer::OnUpdateDevice() { GLView* glview = GLView::sharedOpenGLView(); glview->UpdateDevice(m_eglDisplay, m_eglContext, m_eglSurface); }
GLView* GLView::create(const std::string &viewName) { GLView* view = GLView::create(NULL); view->setViewName(viewName); return view; }
bool ScreenTest::init() { // 物理分辨率 GLView *glview = Director::getInstance()->getOpenGLView(); Size frameSize = glview->getFrameSize(); CCLOG("FRAME SIZE: %dx%d", (int)frameSize.width, (int)frameSize.height); // Result: // iPhone(3.5-inch) 960x640 1.5 // iPhone(4-inch) 1136x640 1.775 // iPad 1024x768 1.333 // iPad Retina 2048x1536 1.333 // 设置逻辑上的游戏屏幕大小 // ResolutionPolicy::EXACT_FIT为了保持了全屏显示,对画面进行了拉伸(不推荐!) // glview->setDesignResolutionSize(400, 480, ResolutionPolicy::EXACT_FIT); // ResolutionPolicy::SHOW_ALL为了保持设计画面比例对四周进行留黑边处理,使得不同比例下画面不能全屏。 // glview->setDesignResolutionSize(400, 480, ResolutionPolicy::SHOW_ALL); // ResolutionPolicy::NO_BORDER为了填补留下的黑边,将画面稍微放大,以至于能够正好补齐黑边 glview->setDesignResolutionSize(m_designWidth, m_designHeight, ResolutionPolicy::NO_BORDER); // 其他参数,参考ResolutionPolicy的注释 Size winSize = Director::getInstance()->getWinSize(); CCLOG("WIN SIZE: %dx%d", (int)winSize.width, (int)winSize.height); // Result: winSize的大小为glview->setDesignResolutionSize()设置的值 // 默认为FrameSize auto dispatcher = Director::getInstance()->getEventDispatcher(); #if (CC_TARGET_PLATFORM == CC_PLATFORM_IOS || CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID) // Add Touch Listener auto touchListener = EventListenerTouchAllAtOnce::create(); touchListener->onTouchesBegan = CC_CALLBACK_2(ScreenTest::onTouchesBegan, this); touchListener->onTouchesMoved = CC_CALLBACK_2(ScreenTest::onTouchesMoved, this); touchListener->onTouchesEnded = CC_CALLBACK_2(ScreenTest::onTouchesEnded, this); touchListener->onTouchesCancelled = CC_CALLBACK_2(ScreenTest::onTouchesCancelled, this); dispatcher->addEventListenerWithSceneGraphPriority(touchListener, this); #elif (CC_TARGET_PLATFORM == CC_PLATFORM_MAC || CC_TARGET_PLATFORM == CC_PLATFORM_WIN32) // Add Mouse Listener auto mouseListener = EventListenerMouse::create(); // mouseListener->onMouseMove = CC_CALLBACK_1(ScreenTest::onMouseMove, this); // mouseListener->onMouseUp = CC_CALLBACK_1(ScreenTest::onMouseUp, this); // mouseListener->onMouseDown = CC_CALLBACK_1(ScreenTest::onMouseDown, this); mouseListener->onMouseScroll = CC_CALLBACK_1(ScreenTest::onMouseScroll, this); dispatcher->addEventListenerWithSceneGraphPriority(mouseListener, this); #endif m_editWidth = UIUtil::createEditBox(this, 100, 160, "Design Width"); m_editHeight = UIUtil::createEditBox(this, 100, 100, "Design Height"); m_editHeight->setInputMode(EditBox::InputMode::NUMERIC); m_editWidth->setInputMode(EditBox::InputMode::NUMERIC); char width[32]; sprintf(width, "%d", (int)winSize.width); m_editWidth->setText(width); char height[32]; sprintf(height, "%d", (int)winSize.height); m_editHeight->setText(height); return true; }
void EditBoxImplTizen::openKeyboard() { if (s_keypadWin) { return; } if (_delegate != NULL) { _delegate->editBoxEditingDidBegin(_editBox); } #if CC_ENABLE_SCRIPT_BINDING EditBox* pEditBox = this->getEditBox(); if (NULL != pEditBox && 0 != pEditBox->getScriptEditBoxHandler()) { CommonScriptData data(pEditBox->getScriptEditBoxHandler(), "began",pEditBox); ScriptEvent event(cocos2d::kCommonEvent,(void*)&data); ScriptEngineManager::getInstance()->getScriptEngine()->sendEvent(&event); } #endif Evas_Object* parent = Application::getInstance()->_win; GLView* glView = Director::getInstance()->getOpenGLView(); Size frameSize = glView->getFrameSize(); s_keypadWin = elm_win_add(parent, "cocos2d-x", ELM_WIN_BASIC); elm_win_autodel_set(s_keypadWin, EINA_TRUE); elm_win_conformant_set(s_keypadWin, EINA_TRUE); elm_win_alpha_set(s_keypadWin, EINA_TRUE); evas_object_show(s_keypadWin); eext_object_event_callback_add(s_keypadWin, EEXT_CALLBACK_BACK, entry_back_cb, this); int rots[2]; rots[0] = (int)(elm_win_rotation_get(parent)); rots[1] = rots[0] + 180 % 360; elm_win_wm_rotation_available_rotations_set(s_keypadWin, rots, 2); Evas_Object* bgFull = elm_bg_add(s_keypadWin); evas_object_color_set(bgFull, 0, 0, 0, 0xa0); evas_object_resize(bgFull, frameSize.width, frameSize.height); evas_object_show(bgFull); int height = frameSize.height / 10; Evas_Object* rectangle = elm_bg_add(bgFull); evas_object_resize(rectangle, frameSize.width, height); evas_object_move(rectangle, 0, height); evas_object_color_set(rectangle, 0xff, 0xff, 0xff, 0xff); evas_object_show(rectangle); Evas_Object* title = elm_entry_add(rectangle); evas_object_resize(title, frameSize.width, height); auto text = _placeHolder.c_str(); auto richText = (char*)malloc(strlen(text) + 50); sprintf(richText,"<color=#ffffff>%s</>", text); elm_entry_entry_set(title, richText); elm_entry_editable_set(title, EINA_FALSE); //elm_entry_drag_disabled_set(title, EINA_TRUE); //elm_entry_drop_disabled_set(title, EINA_TRUE); evas_object_show(title); free(richText); Evas_Object* entry = elm_entry_add(bgFull); elm_object_focus_set(entry, EINA_TRUE); evas_object_resize(entry, frameSize.width, height); evas_object_move(entry, 0, height); elm_entry_single_line_set(entry, EINA_TRUE); elm_entry_line_wrap_set(entry, ELM_WRAP_MIXED); elm_entry_entry_set(entry, _text.c_str()); evas_object_show(entry); elm_object_focus_set(entry, EINA_TRUE); eext_entry_selection_back_event_allow_set(entry, EINA_TRUE); Elm_Entry_Filter_Limit_Size limit_size = { 0, }; limit_size.max_char_count = _maxLength; elm_entry_markup_filter_append(entry, elm_entry_filter_limit_size, &limit_size); elm_entry_input_panel_return_key_type_set(entry, ELM_INPUT_PANEL_RETURN_KEY_TYPE_DONE); elm_entry_prediction_allow_set(entry, EINA_FALSE); evas_object_smart_callback_add(entry, "activated", entry_activated_cb, this); switch(_editBoxInputFlag) { case EditBox::InputFlag::PASSWORD: elm_entry_password_set(entry, EINA_TRUE); elm_entry_input_panel_layout_set(entry, ELM_INPUT_PANEL_LAYOUT_EMAIL); break; case EditBox::InputFlag::SENSITIVE: elm_entry_input_hint_set(entry, ELM_INPUT_HINT_SENSITIVE_DATA); break; case EditBox::InputFlag::INITIAL_CAPS_WORD: elm_entry_autocapital_type_set(entry, ELM_AUTOCAPITAL_TYPE_WORD); break; case EditBox::InputFlag::INITIAL_CAPS_SENTENCE: elm_entry_autocapital_type_set(entry, ELM_AUTOCAPITAL_TYPE_SENTENCE); break; case EditBox::InputFlag::INITIAL_CAPS_ALL_CHARACTERS: elm_entry_autocapital_type_set(entry, ELM_AUTOCAPITAL_TYPE_ALLCHARACTER); break; } switch(_editBoxInputMode) { case EditBox::InputMode::ANY: break; case EditBox::InputMode::EMAIL_ADDRESS: elm_entry_input_panel_layout_set(entry, ELM_INPUT_PANEL_LAYOUT_EMAIL); break; case EditBox::InputMode::NUMERIC: elm_entry_input_panel_layout_set(entry, ELM_INPUT_PANEL_LAYOUT_NUMBER); break; case EditBox::InputMode::PHONE_NUMBER: elm_entry_input_panel_layout_set(entry, ELM_INPUT_PANEL_LAYOUT_PHONENUMBER); break; case EditBox::InputMode::URL: elm_entry_input_panel_layout_set(entry, ELM_INPUT_PANEL_LAYOUT_URL); break; case EditBox::InputMode::DECIMAL: elm_entry_input_panel_layout_set(entry, ELM_INPUT_PANEL_LAYOUT_HEX); //fixme? break; case EditBox::InputMode::SINGLE_LINE: break; } }