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"
|
2011-03-09 16:19:20 +08:00
|
|
|
#include "CCEGLView_ios.h"
|
|
|
|
#include "CCSet.h"
|
2010-11-12 17:16:15 +08:00
|
|
|
#include "CCTouch.h"
|
|
|
|
#include "CCTouchDispatcher.h"
|
|
|
|
|
|
|
|
namespace cocos2d {
|
|
|
|
|
2011-03-09 16:19:20 +08:00
|
|
|
CCEGLView::CCEGLView()
|
2011-02-23 18:22:05 +08:00
|
|
|
: m_pDelegate(0)
|
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
|
|
|
cocos2d::CCSize CCEGLView::getSize()
|
2010-11-12 17:16:15 +08:00
|
|
|
{
|
2011-03-09 16:19:20 +08:00
|
|
|
cocos2d::CCSize size([[EAGLView sharedEGLView] getWidth], [[EAGLView sharedEGLView] getHeight]);
|
2010-11-12 17:16:15 +08:00
|
|
|
return size;
|
|
|
|
}
|
|
|
|
|
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
|
|
|
|
2011-03-09 16:19:20 +08:00
|
|
|
bool CCEGLView::canSetContentScaleFactor()
|
2011-01-07 09:35:27 +08:00
|
|
|
{
|
2012-02-16 10:47:16 +08:00
|
|
|
return [[EAGLView sharedEGLView] respondsToSelector:@selector(setContentScaleFactor:)];
|
2011-01-07 09:35:27 +08:00
|
|
|
}
|
|
|
|
|
2011-03-09 16:19:20 +08:00
|
|
|
void CCEGLView::setContentScaleFactor(float contentScaleFactor)
|
2011-01-07 09:35:27 +08:00
|
|
|
{
|
2011-05-23 16:21:31 +08:00
|
|
|
UIView * view = [EAGLView sharedEGLView];
|
|
|
|
view.contentScaleFactor = contentScaleFactor;
|
|
|
|
[view setNeedsLayout];
|
2011-01-07 09:35:27 +08:00
|
|
|
}
|
2010-11-12 17:16:15 +08:00
|
|
|
|
2011-03-09 16:19:20 +08:00
|
|
|
void CCEGLView::release()
|
2010-11-12 17:16:15 +08:00
|
|
|
{
|
|
|
|
[CCDirectorCaller destroy];
|
|
|
|
|
|
|
|
// destroy EAGLView
|
2010-11-16 12:02:45 +08:00
|
|
|
[[EAGLView sharedEGLView] removeFromSuperview];
|
2010-11-12 17:16:15 +08:00
|
|
|
}
|
|
|
|
|
2011-03-09 16:19:20 +08:00
|
|
|
void CCEGLView::setTouchDelegate(EGLTouchDelegate * pDelegate)
|
2010-11-12 17:16:15 +08:00
|
|
|
{
|
|
|
|
m_pDelegate = pDelegate;
|
|
|
|
}
|
|
|
|
|
2011-03-09 16:19:20 +08:00
|
|
|
void CCEGLView::swapBuffers()
|
2010-11-12 17:16:15 +08:00
|
|
|
{
|
2010-11-16 12:02:45 +08:00
|
|
|
[[EAGLView sharedEGLView] swapBuffers];
|
2010-11-12 17:16:15 +08:00
|
|
|
}
|
|
|
|
|
2011-03-09 16:19:20 +08:00
|
|
|
void CCEGLView::touchesBegan(CCSet *set)
|
2010-11-12 17:16:15 +08:00
|
|
|
{
|
|
|
|
if (m_pDelegate) {
|
|
|
|
m_pDelegate->touchesBegan(set, NULL);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-03-09 16:19:20 +08:00
|
|
|
void CCEGLView::touchesMoved(CCSet *set)
|
2010-11-12 17:16:15 +08:00
|
|
|
{
|
|
|
|
if (m_pDelegate) {
|
|
|
|
m_pDelegate->touchesMoved(set, NULL);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-03-09 16:19:20 +08:00
|
|
|
void CCEGLView::touchesEnded(CCSet *set)
|
2010-11-12 17:16:15 +08:00
|
|
|
{
|
|
|
|
if (m_pDelegate) {
|
|
|
|
m_pDelegate->touchesEnded(set, NULL);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-03-09 16:19:20 +08:00
|
|
|
void CCEGLView::touchesCancelled(CCSet *set)
|
2010-11-12 17:16:15 +08:00
|
|
|
{
|
|
|
|
if (m_pDelegate) {
|
|
|
|
m_pDelegate->touchesCancelled(set, NULL);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-03-09 16:19:20 +08:00
|
|
|
void CCEGLView::setViewPortInPoints(float x, float y, float w, float h)
|
2011-02-23 18:22:05 +08:00
|
|
|
{
|
2011-04-19 18:11:57 +08:00
|
|
|
glViewport((GLint)x, (GLint)y, (GLint)w, (GLint)h);
|
|
|
|
}
|
|
|
|
|
2011-06-27 10:55:45 +08:00
|
|
|
void CCEGLView::setScissorInPoints(float x, float y, float w, float h)
|
|
|
|
{
|
|
|
|
glScissor((GLint)x, (GLint)y, (GLint)w, (GLint)h);
|
|
|
|
}
|
|
|
|
|
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];
|
|
|
|
}
|
|
|
|
|
2011-02-23 18:22:05 +08:00
|
|
|
} // end of namespace cocos2d;
|