mirror of https://github.com/axmolengine/axmol.git
Adds the possibility to create EAGLView with an EAGLView
This commit is contained in:
parent
f1af117a1c
commit
d19a1012a4
|
@ -45,7 +45,11 @@ public:
|
||||||
static EGLView* createWithSize(const std::string& viewName, Size size, float frameZoomFactor = 1.0f);
|
static EGLView* createWithSize(const std::string& viewName, Size size, float frameZoomFactor = 1.0f);
|
||||||
static EGLView* createWithFullScreen(const std::string& viewName);
|
static EGLView* createWithFullScreen(const std::string& viewName);
|
||||||
|
|
||||||
virtual bool setContentScaleFactor(float contentScaleFactor);
|
bool setContentScaleFactor(float contentScaleFactor);
|
||||||
|
float getContentScaleFactor() const;
|
||||||
|
bool isRetinaDisplay() const { return getContentScaleFactor() == 2.0; }
|
||||||
|
|
||||||
|
void* getEAGLView() const { return _eaglview; }
|
||||||
|
|
||||||
// overrides
|
// overrides
|
||||||
virtual bool isOpenGLReady() override;
|
virtual bool isOpenGLReady() override;
|
||||||
|
@ -57,10 +61,11 @@ protected:
|
||||||
EGLView();
|
EGLView();
|
||||||
virtual ~EGLView();
|
virtual ~EGLView();
|
||||||
|
|
||||||
|
bool initWithEAGLView(void* eaglview);
|
||||||
bool initWithSize(const std::string& viewName, Size size, float frameZoomFactor);
|
bool initWithSize(const std::string& viewName, Size size, float frameZoomFactor);
|
||||||
bool initWithFullScreen(const std::string& viewName);
|
bool initWithFullScreen(const std::string& viewName);
|
||||||
|
|
||||||
void *_glview;
|
void *_eaglview;
|
||||||
};
|
};
|
||||||
|
|
||||||
NS_CC_END
|
NS_CC_END
|
||||||
|
|
|
@ -27,6 +27,8 @@
|
||||||
|
|
||||||
#if CC_TARGET_PLATFORM == CC_PLATFORM_IOS
|
#if CC_TARGET_PLATFORM == CC_PLATFORM_IOS
|
||||||
|
|
||||||
|
#import <UIKit/UIKit.h>
|
||||||
|
|
||||||
#include "CCEAGLView.h"
|
#include "CCEAGLView.h"
|
||||||
#include "CCDirectorCaller.h"
|
#include "CCDirectorCaller.h"
|
||||||
#include "CCEGLView.h"
|
#include "CCEGLView.h"
|
||||||
|
@ -35,6 +37,17 @@
|
||||||
|
|
||||||
NS_CC_BEGIN
|
NS_CC_BEGIN
|
||||||
|
|
||||||
|
EGLView* EGLView::createWithEAGLView(void *eaglview)
|
||||||
|
{
|
||||||
|
auto ret = new EGLView;
|
||||||
|
if(ret && ret->initWithEAGLView(eaglview)) {
|
||||||
|
ret->autorelease();
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
EGLView* EGLView::create(const std::string& viewName)
|
EGLView* EGLView::create(const std::string& viewName)
|
||||||
{
|
{
|
||||||
auto ret = new EGLView;
|
auto ret = new EGLView;
|
||||||
|
@ -70,41 +83,60 @@ EGLView* EGLView::createWithFullScreen(const std::string& viewName)
|
||||||
|
|
||||||
EGLView::EGLView()
|
EGLView::EGLView()
|
||||||
{
|
{
|
||||||
// CGRect r = CGRectMake(0,0,300,300);
|
|
||||||
// CCEAGLView *glView = [CCEAGLView viewWithFrame:r
|
|
||||||
// pixelFormat: kEAGLColorFormatRGB565
|
|
||||||
// depthFormat: GL_DEPTH24_STENCIL8_OES
|
|
||||||
// preserveBackbuffer: NO
|
|
||||||
// sharegroup: nil
|
|
||||||
// multiSampling: NO
|
|
||||||
// numberOfSamples: 0];
|
|
||||||
// [__glView setMultipleTouchEnabled:YES];
|
|
||||||
//
|
|
||||||
// _screenSize.width = _designResolutionSize.width = [glview getWidth];
|
|
||||||
// _screenSize.height = _designResolutionSize.height = [glview getHeight];
|
|
||||||
//
|
|
||||||
// _glview = glview;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
EGLView::~EGLView()
|
EGLView::~EGLView()
|
||||||
{
|
{
|
||||||
CCEAGLView *glview = (CCEAGLView*) _glview;
|
CCEAGLView *glview = (CCEAGLView*) _eaglview;
|
||||||
[glview release];
|
[glview release];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool EGLView::initWithEAGLView(void *eaglview)
|
||||||
|
{
|
||||||
|
_eaglview = eaglview;
|
||||||
|
CCEAGLView *glview = (CCEAGLView*) _eaglview;
|
||||||
|
|
||||||
|
_screenSize.width = _designResolutionSize.width = [glview getWidth];
|
||||||
|
_screenSize.height = _designResolutionSize.height = [glview getHeight];
|
||||||
|
// _scaleX = _scaleY = [glview contentScaleFactor];
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
bool EGLView::initWithSize(const std::string& viewName, Size size, float frameZoomFactor)
|
bool EGLView::initWithSize(const std::string& viewName, Size size, float frameZoomFactor)
|
||||||
{
|
{
|
||||||
|
CGRect r = CGRectMake(0,0,size.width, size.height);
|
||||||
|
CCEAGLView *eaglview = [CCEAGLView viewWithFrame: r
|
||||||
|
pixelFormat: kEAGLColorFormatRGB565
|
||||||
|
depthFormat: GL_DEPTH24_STENCIL8_OES
|
||||||
|
preserveBackbuffer: NO
|
||||||
|
sharegroup: nil
|
||||||
|
multiSampling: NO
|
||||||
|
numberOfSamples: 0];
|
||||||
|
[eaglview setMultipleTouchEnabled:YES];
|
||||||
|
|
||||||
|
_screenSize.width = _designResolutionSize.width = [eaglview getWidth];
|
||||||
|
_screenSize.height = _designResolutionSize.height = [eaglview getHeight];
|
||||||
|
// _scaleX = _scaleY = [eaglview contentScaleFactor];
|
||||||
|
|
||||||
|
_eaglview = eaglview;
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool EGLView::initWithFullScreen(const std::string& viewName)
|
bool EGLView::initWithFullScreen(const std::string& viewName)
|
||||||
{
|
{
|
||||||
return true;
|
CGRect rect = [[UIScreen mainScreen] bounds];
|
||||||
|
Size size;
|
||||||
|
size.width = rect.size.width;
|
||||||
|
size.height = rect.size.height;
|
||||||
|
|
||||||
|
return initWithSize(viewName, size, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool EGLView::isOpenGLReady()
|
bool EGLView::isOpenGLReady()
|
||||||
{
|
{
|
||||||
return _glview != nullptr;
|
return _eaglview != nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool EGLView::setContentScaleFactor(float contentScaleFactor)
|
bool EGLView::setContentScaleFactor(float contentScaleFactor)
|
||||||
|
@ -112,41 +144,52 @@ bool EGLView::setContentScaleFactor(float contentScaleFactor)
|
||||||
CC_ASSERT(_resolutionPolicy == ResolutionPolicy::UNKNOWN); // cannot enable retina mode
|
CC_ASSERT(_resolutionPolicy == ResolutionPolicy::UNKNOWN); // cannot enable retina mode
|
||||||
_scaleX = _scaleY = contentScaleFactor;
|
_scaleX = _scaleY = contentScaleFactor;
|
||||||
|
|
||||||
CCEAGLView *glview = (CCEAGLView*) _glview;
|
CCEAGLView *eaglview = (CCEAGLView*) _eaglview;
|
||||||
[glview setNeedsLayout];
|
[eaglview setNeedsLayout];
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
float EGLView::getContentScaleFactor() const
|
||||||
|
{
|
||||||
|
CCEAGLView *eaglview = (CCEAGLView*) _eaglview;
|
||||||
|
|
||||||
|
float scaleFactor = [eaglview contentScaleFactor];
|
||||||
|
|
||||||
|
// CCASSERT(scaleFactor == _scaleX == _scaleY, "Logic error in EGLView::getContentScaleFactor");
|
||||||
|
|
||||||
|
return scaleFactor;
|
||||||
|
}
|
||||||
|
|
||||||
void EGLView::end()
|
void EGLView::end()
|
||||||
{
|
{
|
||||||
[CCDirectorCaller destroy];
|
[CCDirectorCaller destroy];
|
||||||
|
|
||||||
// destroy EAGLView
|
// destroy EAGLView
|
||||||
CCEAGLView *glview = (CCEAGLView*) _glview;
|
CCEAGLView *eaglview = (CCEAGLView*) _eaglview;
|
||||||
|
|
||||||
[glview removeFromSuperview];
|
[eaglview removeFromSuperview];
|
||||||
[glview release];
|
[eaglview release];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void EGLView::swapBuffers()
|
void EGLView::swapBuffers()
|
||||||
{
|
{
|
||||||
CCEAGLView *glview = (CCEAGLView*) _glview;
|
CCEAGLView *eaglview = (CCEAGLView*) _eaglview;
|
||||||
[glview swapBuffers];
|
[eaglview swapBuffers];
|
||||||
}
|
}
|
||||||
|
|
||||||
void EGLView::setIMEKeyboardState(bool open)
|
void EGLView::setIMEKeyboardState(bool open)
|
||||||
{
|
{
|
||||||
CCEAGLView *glview = (CCEAGLView*) _glview;
|
CCEAGLView *eaglview = (CCEAGLView*) _eaglview;
|
||||||
|
|
||||||
if (open)
|
if (open)
|
||||||
{
|
{
|
||||||
[glview becomeFirstResponder];
|
[eaglview becomeFirstResponder];
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
[glview resignFirstResponder];
|
[eaglview resignFirstResponder];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue