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
|
|
|
{
|
2012-08-07 14:29:46 +08:00
|
|
|
m_obScreenSize.width = m_obDesignResolutionSize.width = [[EAGLView sharedEGLView] getWidth];
|
|
|
|
m_obScreenSize.height = m_obDesignResolutionSize.height = [[EAGLView sharedEGLView] getHeight];
|
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
|
|
|
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-08-07 14:29:46 +08:00
|
|
|
bool CCEGLView::setContentScaleFactor(float contentScaleFactor)
|
2012-04-23 15:40:46 +08:00
|
|
|
{
|
2012-09-15 06:26:38 +08:00
|
|
|
assert(m_eResolutionPolicy == kResolutionUnKnown); // cannot enable retina mode
|
2012-09-24 18:22:02 +08:00
|
|
|
|
|
|
|
m_fScaleX = m_fScaleY = contentScaleFactor;
|
|
|
|
[[EAGLView sharedEGLView] setNeedsLayout];
|
2012-08-07 14:29:46 +08:00
|
|
|
|
2012-09-24 18:22:02 +08:00
|
|
|
return 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
|
|
|
|
|
|
|
void CCEGLView::setIMEKeyboardState(bool bOpen)
|
|
|
|
{
|
|
|
|
if (bOpen)
|
|
|
|
{
|
|
|
|
[[EAGLView sharedEGLView] becomeFirstResponder];
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
[[EAGLView sharedEGLView] resignFirstResponder];
|
|
|
|
}
|
2011-02-23 18:22:05 +08:00
|
|
|
}
|
|
|
|
|
2012-08-21 14:58:31 +08:00
|
|
|
CCEGLView* CCEGLView::sharedOpenGLView()
|
2011-02-23 18:22:05 +08:00
|
|
|
{
|
2011-04-19 18:11:57 +08:00
|
|
|
static CCEGLView instance;
|
2012-08-21 14:58:31 +08:00
|
|
|
return &instance;
|
2011-02-23 18:22:05 +08:00
|
|
|
}
|
2010-11-12 17:16:15 +08:00
|
|
|
|
2012-04-18 18:43:45 +08:00
|
|
|
NS_CC_END
|
|
|
|
|