2010-11-12 17:16:15 +08:00
|
|
|
/****************************************************************************
|
2014-01-07 11:25:07 +08:00
|
|
|
Copyright (c) 2010-2012 cocos2d-x.org
|
|
|
|
Copyright (c) 2013-2014 Chukong Technologies Inc.
|
2010-11-12 17:16:15 +08:00
|
|
|
|
2014-01-07 11:25:07 +08:00
|
|
|
http://www.cocos2d-x.org
|
2010-11-12 17:16:15 +08:00
|
|
|
|
2014-01-07 11:25:07 +08:00
|
|
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
|
|
of this software and associated documentation files (the "Software"), to deal
|
|
|
|
in the Software without restriction, including without limitation the rights
|
|
|
|
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
|
|
copies of the Software, and to permit persons to whom the Software is
|
|
|
|
furnished to do so, subject to the following conditions:
|
2010-11-12 17:16:15 +08:00
|
|
|
|
2014-01-07 11:25:07 +08:00
|
|
|
The above copyright notice and this permission notice shall be included in
|
|
|
|
all copies or substantial portions of the Software.
|
2010-11-12 17:16:15 +08:00
|
|
|
|
2014-01-07 11:25:07 +08:00
|
|
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
|
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
|
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
|
|
THE SOFTWARE.
|
|
|
|
****************************************************************************/
|
2014-01-28 08:44:10 +08:00
|
|
|
|
|
|
|
#include "CCPlatformConfig.h"
|
|
|
|
|
|
|
|
#if CC_TARGET_PLATFORM == CC_PLATFORM_IOS
|
|
|
|
|
2014-01-24 07:36:55 +08:00
|
|
|
#include "CCEAGLView.h"
|
2010-11-12 17:16:15 +08:00
|
|
|
#include "CCDirectorCaller.h"
|
2012-04-25 17:33:28 +08:00
|
|
|
#include "CCEGLView.h"
|
2011-03-09 16:19:20 +08:00
|
|
|
#include "CCSet.h"
|
2010-11-12 17:16:15 +08:00
|
|
|
#include "CCTouch.h"
|
|
|
|
|
2012-04-18 18:43:45 +08:00
|
|
|
NS_CC_BEGIN
|
2010-11-12 17:16:15 +08:00
|
|
|
|
2014-01-24 07:36:55 +08:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2013-06-20 14:13:12 +08:00
|
|
|
EGLView::EGLView()
|
2010-11-12 17:16:15 +08:00
|
|
|
{
|
2014-01-29 03:32:25 +08:00
|
|
|
// 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;
|
2010-11-12 17:16:15 +08:00
|
|
|
}
|
|
|
|
|
2013-06-20 14:13:12 +08:00
|
|
|
EGLView::~EGLView()
|
2010-11-12 17:16:15 +08:00
|
|
|
{
|
2014-01-28 11:16:09 +08:00
|
|
|
CCEAGLView *glview = (CCEAGLView*) _glview;
|
|
|
|
[glview release];
|
2010-11-12 17:16:15 +08:00
|
|
|
}
|
|
|
|
|
2014-01-24 07:36:55 +08:00
|
|
|
bool EGLView::initWithSize(const std::string& viewName, Size size, float frameZoomFactor)
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool EGLView::initWithFullScreen(const std::string& viewName)
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2013-06-20 14:13:12 +08:00
|
|
|
bool EGLView::isOpenGLReady()
|
2010-11-12 17:16:15 +08:00
|
|
|
{
|
2014-01-28 11:16:09 +08:00
|
|
|
return _glview != nullptr;
|
2010-11-12 17:16:15 +08:00
|
|
|
}
|
2014-01-24 07:36:55 +08:00
|
|
|
|
2013-06-20 14:13:12 +08:00
|
|
|
bool EGLView::setContentScaleFactor(float contentScaleFactor)
|
2012-04-23 15:40:46 +08:00
|
|
|
{
|
2014-01-28 11:16:09 +08:00
|
|
|
CC_ASSERT(_resolutionPolicy == ResolutionPolicy::UNKNOWN); // cannot enable retina mode
|
2014-01-24 07:36:55 +08:00
|
|
|
_scaleX = _scaleY = contentScaleFactor;
|
2014-01-28 11:16:09 +08:00
|
|
|
|
|
|
|
CCEAGLView *glview = (CCEAGLView*) _glview;
|
|
|
|
[glview setNeedsLayout];
|
2014-01-24 07:36:55 +08:00
|
|
|
|
|
|
|
return true;
|
2012-04-23 15:40:46 +08:00
|
|
|
}
|
2010-11-12 17:16:15 +08:00
|
|
|
|
2013-06-20 14:13:12 +08:00
|
|
|
void EGLView::end()
|
2010-11-12 17:16:15 +08:00
|
|
|
{
|
2013-06-21 08:46:22 +08:00
|
|
|
[CCDirectorCaller destroy];
|
2012-04-19 14:35:52 +08:00
|
|
|
|
|
|
|
// destroy EAGLView
|
2014-01-28 11:16:09 +08:00
|
|
|
CCEAGLView *glview = (CCEAGLView*) _glview;
|
|
|
|
|
|
|
|
[glview removeFromSuperview];
|
|
|
|
[glview release];
|
2010-11-12 17:16:15 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-06-20 14:13:12 +08:00
|
|
|
void EGLView::swapBuffers()
|
2010-11-12 17:16:15 +08:00
|
|
|
{
|
2014-01-28 11:16:09 +08:00
|
|
|
CCEAGLView *glview = (CCEAGLView*) _glview;
|
|
|
|
[glview swapBuffers];
|
2010-11-12 17:16:15 +08:00
|
|
|
}
|
2011-04-19 18:11:57 +08:00
|
|
|
|
2014-01-28 11:16:09 +08:00
|
|
|
void EGLView::setIMEKeyboardState(bool open)
|
2011-04-19 18:11:57 +08:00
|
|
|
{
|
2014-01-28 11:16:09 +08:00
|
|
|
CCEAGLView *glview = (CCEAGLView*) _glview;
|
|
|
|
|
|
|
|
if (open)
|
2011-04-19 18:11:57 +08:00
|
|
|
{
|
2014-01-28 11:16:09 +08:00
|
|
|
[glview becomeFirstResponder];
|
2011-04-19 18:11:57 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2014-01-28 11:16:09 +08:00
|
|
|
[glview resignFirstResponder];
|
2011-04-19 18:11:57 +08:00
|
|
|
}
|
2011-02-23 18:22:05 +08:00
|
|
|
}
|
|
|
|
|
2012-04-18 18:43:45 +08:00
|
|
|
NS_CC_END
|
|
|
|
|
2014-01-28 08:44:10 +08:00
|
|
|
#endif // CC_PLATFOR_IOS
|
|
|
|
|