2010-11-12 17:16:15 +08:00
|
|
|
/****************************************************************************
|
|
|
|
Copyright (c) 2010 cocos2d-x.org
|
|
|
|
|
|
|
|
http://www.cocos2d-x.org
|
|
|
|
|
|
|
|
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:
|
|
|
|
|
|
|
|
The above copyright notice and this permission notice shall be included in
|
|
|
|
all copies or substantial portions of the Software.
|
|
|
|
|
|
|
|
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.
|
|
|
|
****************************************************************************/
|
|
|
|
#include "EAGLView.h"
|
|
|
|
#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"
|
|
|
|
#include "CCTouchDispatcher.h"
|
|
|
|
|
2012-04-18 18:43:45 +08:00
|
|
|
NS_CC_BEGIN
|
2010-11-12 17:16:15 +08:00
|
|
|
|
2011-03-09 16:19:20 +08:00
|
|
|
CCEGLView::CCEGLView()
|
2010-11-12 17:16:15 +08:00
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2011-03-09 16:19:20 +08:00
|
|
|
CCEGLView::~CCEGLView()
|
2010-11-12 17:16:15 +08:00
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2012-04-23 14:35:41 +08:00
|
|
|
CCSize CCEGLView::getSize()
|
2010-11-12 17:16:15 +08:00
|
|
|
{
|
2012-04-19 14:35:52 +08:00
|
|
|
cocos2d::CCSize size([[EAGLView sharedEGLView] getWidth], [[EAGLView sharedEGLView] getHeight]);
|
2012-04-23 15:40:46 +08:00
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
return size;
|
2010-11-12 17:16:15 +08:00
|
|
|
}
|
|
|
|
|
2012-04-08 14:16:29 +08:00
|
|
|
bool CCEGLView::isIpad()
|
|
|
|
{
|
|
|
|
return UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad;
|
|
|
|
}
|
|
|
|
|
2011-03-09 16:19:20 +08:00
|
|
|
bool CCEGLView::isOpenGLReady()
|
2010-11-12 17:16:15 +08:00
|
|
|
{
|
2010-11-16 12:02:45 +08:00
|
|
|
return [EAGLView sharedEGLView] != NULL;
|
2010-11-12 17:16:15 +08:00
|
|
|
}
|
2011-01-07 09:35:27 +08:00
|
|
|
|
2012-04-23 15:40:46 +08:00
|
|
|
bool CCEGLView::canSetContentScaleFactor()
|
|
|
|
{
|
|
|
|
return [[EAGLView sharedEGLView] respondsToSelector:@selector(setContentScaleFactor:)];
|
|
|
|
}
|
2011-01-07 09:35:27 +08:00
|
|
|
|
2012-04-23 15:40:46 +08:00
|
|
|
void CCEGLView::setContentScaleFactor(float contentScaleFactor)
|
|
|
|
{
|
|
|
|
UIView * view = [EAGLView sharedEGLView];
|
|
|
|
view.contentScaleFactor = contentScaleFactor;
|
|
|
|
[view setNeedsLayout];
|
2012-08-01 16:56:12 +08:00
|
|
|
|
|
|
|
m_fXScale = m_fYScale = contentScaleFactor;
|
2012-08-01 18:44:10 +08:00
|
|
|
m_bIsRetinaEnabled = true;
|
2012-04-23 15:40:46 +08:00
|
|
|
}
|
2010-11-12 17:16:15 +08:00
|
|
|
|
2012-04-23 14:35:41 +08:00
|
|
|
void CCEGLView::end()
|
2010-11-12 17:16:15 +08:00
|
|
|
{
|
2012-04-19 14:35:52 +08:00
|
|
|
[CCDirectorCaller destroy];
|
|
|
|
|
|
|
|
// destroy EAGLView
|
|
|
|
[[EAGLView sharedEGLView] removeFromSuperview];
|
2010-11-12 17:16:15 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-03-09 16:19:20 +08:00
|
|
|
void CCEGLView::swapBuffers()
|
2010-11-12 17:16:15 +08:00
|
|
|
{
|
2012-04-19 14:35:52 +08:00
|
|
|
[[EAGLView sharedEGLView] swapBuffers];
|
2010-11-12 17:16:15 +08:00
|
|
|
}
|
2011-04-19 18:11:57 +08:00
|
|
|
|
2012-05-30 18:31:20 +08:00
|
|
|
CCSize CCEGLView::getFrameSize()
|
|
|
|
{
|
|
|
|
assert(false);
|
2012-06-09 04:52:40 +08:00
|
|
|
return CCSizeMake(0, 0);
|
2012-05-30 18:31:20 +08:00
|
|
|
}
|
2011-06-27 10:55:45 +08:00
|
|
|
|
2011-04-19 18:11:57 +08:00
|
|
|
void CCEGLView::setIMEKeyboardState(bool bOpen)
|
|
|
|
{
|
|
|
|
if (bOpen)
|
|
|
|
{
|
|
|
|
[[EAGLView sharedEGLView] becomeFirstResponder];
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
[[EAGLView sharedEGLView] resignFirstResponder];
|
|
|
|
}
|
2011-02-23 18:22:05 +08:00
|
|
|
}
|
|
|
|
|
2011-03-09 16:19:20 +08:00
|
|
|
CCEGLView& CCEGLView::sharedOpenGLView()
|
2011-02-23 18:22:05 +08:00
|
|
|
{
|
2011-04-19 18:11:57 +08:00
|
|
|
static CCEGLView instance;
|
|
|
|
return instance;
|
2011-02-23 18:22:05 +08:00
|
|
|
}
|
2010-11-12 17:16:15 +08:00
|
|
|
|
2012-02-16 10:47:16 +08:00
|
|
|
float CCEGLView::getMainScreenScale()
|
|
|
|
{
|
|
|
|
return [[UIScreen mainScreen] scale];
|
|
|
|
}
|
|
|
|
|
2012-04-18 18:43:45 +08:00
|
|
|
NS_CC_END
|
|
|
|
|