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"
|
|
|
|
|
2012-04-18 18:43:45 +08:00
|
|
|
NS_CC_BEGIN
|
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
|
|
|
{
|
2013-06-21 08:46:22 +08:00
|
|
|
_screenSize.width = _designResolutionSize.width = [[CCEAGLView sharedEGLView] getWidth];
|
|
|
|
_screenSize.height = _designResolutionSize.height = [[CCEAGLView sharedEGLView] getHeight];
|
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
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2013-06-20 14:13:12 +08:00
|
|
|
bool EGLView::isOpenGLReady()
|
2010-11-12 17:16:15 +08:00
|
|
|
{
|
2013-12-18 17:47:20 +08:00
|
|
|
return [CCEAGLView sharedEGLView] != nullptr;
|
2010-11-12 17:16:15 +08:00
|
|
|
}
|
2011-01-07 09:35:27 +08:00
|
|
|
|
2013-06-20 14:13:12 +08:00
|
|
|
bool EGLView::setContentScaleFactor(float contentScaleFactor)
|
2012-04-23 15:40:46 +08:00
|
|
|
{
|
2013-07-26 18:18:58 +08:00
|
|
|
assert(_resolutionPolicy == ResolutionPolicy::UNKNOWN); // cannot enable retina mode
|
2012-09-24 18:22:02 +08:00
|
|
|
|
2013-06-15 14:03:30 +08:00
|
|
|
_scaleX = _scaleY = contentScaleFactor;
|
2013-06-21 08:46:22 +08:00
|
|
|
[[CCEAGLView 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
|
|
|
|
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
|
2013-06-21 08:46:22 +08:00
|
|
|
[[CCEAGLView sharedEGLView] removeFromSuperview];
|
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
|
|
|
{
|
2013-06-21 08:46:22 +08:00
|
|
|
[[CCEAGLView sharedEGLView] swapBuffers];
|
2010-11-12 17:16:15 +08:00
|
|
|
}
|
2011-04-19 18:11:57 +08:00
|
|
|
|
2013-06-20 14:13:12 +08:00
|
|
|
void EGLView::setIMEKeyboardState(bool bOpen)
|
2011-04-19 18:11:57 +08:00
|
|
|
{
|
|
|
|
if (bOpen)
|
|
|
|
{
|
2013-06-21 08:46:22 +08:00
|
|
|
[[CCEAGLView sharedEGLView] becomeFirstResponder];
|
2011-04-19 18:11:57 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2013-06-21 08:46:22 +08:00
|
|
|
[[CCEAGLView sharedEGLView] resignFirstResponder];
|
2011-04-19 18:11:57 +08:00
|
|
|
}
|
2011-02-23 18:22:05 +08:00
|
|
|
}
|
|
|
|
|
2013-07-12 06:24:23 +08:00
|
|
|
EGLView* EGLView::getInstance()
|
2011-02-23 18:22:05 +08:00
|
|
|
{
|
2013-06-20 14:13:12 +08:00
|
|
|
static EGLView 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
|
|
|
|
2013-07-12 06:24:23 +08:00
|
|
|
// XXX: deprecated
|
|
|
|
EGLView* EGLView::sharedOpenGLView()
|
|
|
|
{
|
|
|
|
return EGLView::getInstance();
|
|
|
|
}
|
|
|
|
|
2012-04-18 18:43:45 +08:00
|
|
|
NS_CC_END
|
|
|
|
|