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-31 07:11:37 +08:00
|
|
|
#import <UIKit/UIKit.h>
|
|
|
|
|
2014-01-24 07:36:55 +08:00
|
|
|
#include "CCEAGLView.h"
|
2010-11-12 17:16:15 +08:00
|
|
|
#include "CCDirectorCaller.h"
|
2014-01-31 08:51:43 +08:00
|
|
|
#include "CCGLView.h"
|
2011-03-09 16:19:20 +08:00
|
|
|
#include "CCSet.h"
|
2014-04-27 01:11:22 +08:00
|
|
|
#include "2d/CCTouch.h"
|
2010-11-12 17:16:15 +08:00
|
|
|
|
2012-04-18 18:43:45 +08:00
|
|
|
NS_CC_BEGIN
|
2010-11-12 17:16:15 +08:00
|
|
|
|
2014-01-31 07:40:56 +08:00
|
|
|
GLView* GLView::createWithEAGLView(void *eaglview)
|
2014-01-31 07:11:37 +08:00
|
|
|
{
|
2014-01-31 07:40:56 +08:00
|
|
|
auto ret = new GLView;
|
2014-01-31 07:11:37 +08:00
|
|
|
if(ret && ret->initWithEAGLView(eaglview)) {
|
|
|
|
ret->autorelease();
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2014-01-31 07:40:56 +08:00
|
|
|
GLView* GLView::create(const std::string& viewName)
|
2014-01-24 07:36:55 +08:00
|
|
|
{
|
2014-01-31 07:40:56 +08:00
|
|
|
auto ret = new GLView;
|
|
|
|
if(ret && ret->initWithFullScreen(viewName)) {
|
2014-01-24 07:36:55 +08:00
|
|
|
ret->autorelease();
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2014-01-31 07:40:56 +08:00
|
|
|
GLView* GLView::createWithRect(const std::string& viewName, Rect rect, float frameZoomFactor)
|
2014-01-24 07:36:55 +08:00
|
|
|
{
|
2014-01-31 07:40:56 +08:00
|
|
|
auto ret = new GLView;
|
|
|
|
if(ret && ret->initWithRect(viewName, rect, frameZoomFactor)) {
|
2014-01-24 07:36:55 +08:00
|
|
|
ret->autorelease();
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2014-01-31 07:40:56 +08:00
|
|
|
GLView* GLView::createWithFullScreen(const std::string& viewName)
|
2014-01-24 07:36:55 +08:00
|
|
|
{
|
2014-01-31 07:40:56 +08:00
|
|
|
auto ret = new GLView();
|
2014-01-24 07:36:55 +08:00
|
|
|
if(ret && ret->initWithFullScreen(viewName)) {
|
|
|
|
ret->autorelease();
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2014-01-31 07:40:56 +08:00
|
|
|
GLView::GLView()
|
2010-11-12 17:16:15 +08:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2014-01-31 07:40:56 +08:00
|
|
|
GLView::~GLView()
|
2010-11-12 17:16:15 +08:00
|
|
|
{
|
2014-01-31 07:11:37 +08:00
|
|
|
CCEAGLView *glview = (CCEAGLView*) _eaglview;
|
2014-01-28 11:16:09 +08:00
|
|
|
[glview release];
|
2010-11-12 17:16:15 +08:00
|
|
|
}
|
|
|
|
|
2014-01-31 07:40:56 +08:00
|
|
|
bool GLView::initWithEAGLView(void *eaglview)
|
2014-01-31 07:11:37 +08:00
|
|
|
{
|
|
|
|
_eaglview = eaglview;
|
|
|
|
CCEAGLView *glview = (CCEAGLView*) _eaglview;
|
|
|
|
|
|
|
|
_screenSize.width = _designResolutionSize.width = [glview getWidth];
|
|
|
|
_screenSize.height = _designResolutionSize.height = [glview getHeight];
|
|
|
|
// _scaleX = _scaleY = [glview contentScaleFactor];
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2014-01-31 07:40:56 +08:00
|
|
|
bool GLView::initWithRect(const std::string& viewName, Rect rect, float frameZoomFactor)
|
2014-01-24 07:36:55 +08:00
|
|
|
{
|
2014-01-31 07:40:56 +08:00
|
|
|
CGRect r = CGRectMake(rect.origin.x, rect.origin.y, rect.size.width, rect.size.height);
|
2014-01-31 07:11:37 +08:00
|
|
|
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;
|
|
|
|
|
2014-01-24 07:36:55 +08:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2014-01-31 07:40:56 +08:00
|
|
|
bool GLView::initWithFullScreen(const std::string& viewName)
|
2014-01-24 07:36:55 +08:00
|
|
|
{
|
2014-01-31 07:11:37 +08:00
|
|
|
CGRect rect = [[UIScreen mainScreen] bounds];
|
2014-01-31 07:40:56 +08:00
|
|
|
Rect r;
|
|
|
|
r.origin.x = rect.origin.x;
|
|
|
|
r.origin.y = rect.origin.y;
|
|
|
|
r.size.width = rect.size.width;
|
|
|
|
r.size.height = rect.size.height;
|
2014-01-31 07:11:37 +08:00
|
|
|
|
2014-01-31 07:40:56 +08:00
|
|
|
return initWithRect(viewName, r, 1);
|
2014-01-24 07:36:55 +08:00
|
|
|
}
|
|
|
|
|
2014-01-31 07:40:56 +08:00
|
|
|
bool GLView::isOpenGLReady()
|
2010-11-12 17:16:15 +08:00
|
|
|
{
|
2014-01-31 07:11:37 +08:00
|
|
|
return _eaglview != nullptr;
|
2010-11-12 17:16:15 +08:00
|
|
|
}
|
2014-01-24 07:36:55 +08:00
|
|
|
|
2014-01-31 07:40:56 +08:00
|
|
|
bool GLView::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
|
|
|
|
2014-01-31 07:11:37 +08:00
|
|
|
CCEAGLView *eaglview = (CCEAGLView*) _eaglview;
|
|
|
|
[eaglview 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
|
|
|
|
2014-01-31 07:40:56 +08:00
|
|
|
float GLView::getContentScaleFactor() const
|
2014-01-31 07:11:37 +08:00
|
|
|
{
|
|
|
|
CCEAGLView *eaglview = (CCEAGLView*) _eaglview;
|
|
|
|
|
|
|
|
float scaleFactor = [eaglview contentScaleFactor];
|
|
|
|
|
2014-01-31 07:40:56 +08:00
|
|
|
// CCASSERT(scaleFactor == _scaleX == _scaleY, "Logic error in GLView::getContentScaleFactor");
|
2014-01-31 07:11:37 +08:00
|
|
|
|
|
|
|
return scaleFactor;
|
|
|
|
}
|
|
|
|
|
2014-01-31 07:40:56 +08:00
|
|
|
void GLView::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-31 07:11:37 +08:00
|
|
|
CCEAGLView *eaglview = (CCEAGLView*) _eaglview;
|
2014-01-28 11:16:09 +08:00
|
|
|
|
2014-01-31 07:11:37 +08:00
|
|
|
[eaglview removeFromSuperview];
|
|
|
|
[eaglview release];
|
2010-11-12 17:16:15 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-01-31 07:40:56 +08:00
|
|
|
void GLView::swapBuffers()
|
2010-11-12 17:16:15 +08:00
|
|
|
{
|
2014-01-31 07:11:37 +08:00
|
|
|
CCEAGLView *eaglview = (CCEAGLView*) _eaglview;
|
|
|
|
[eaglview swapBuffers];
|
2010-11-12 17:16:15 +08:00
|
|
|
}
|
2011-04-19 18:11:57 +08:00
|
|
|
|
2014-01-31 07:40:56 +08:00
|
|
|
void GLView::setIMEKeyboardState(bool open)
|
2011-04-19 18:11:57 +08:00
|
|
|
{
|
2014-01-31 07:11:37 +08:00
|
|
|
CCEAGLView *eaglview = (CCEAGLView*) _eaglview;
|
2014-01-28 11:16:09 +08:00
|
|
|
|
|
|
|
if (open)
|
2011-04-19 18:11:57 +08:00
|
|
|
{
|
2014-01-31 07:11:37 +08:00
|
|
|
[eaglview becomeFirstResponder];
|
2011-04-19 18:11:57 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2014-01-31 07:11:37 +08:00
|
|
|
[eaglview 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
|
|
|
|
|