2011-09-19 18:05:40 +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 "CCEGLView.h"
|
|
|
|
#include "CCSet.h"
|
|
|
|
#include "CCDirector.h"
|
|
|
|
#include "CCTouch.h"
|
|
|
|
#include "CCTouchDispatcher.h"
|
|
|
|
#include "CCAccelerometer_bada.h"
|
2011-11-08 15:59:04 +08:00
|
|
|
#include "CCIMEDispatcher.h"
|
2011-09-19 18:05:40 +08:00
|
|
|
#include <GLES/egl.h>
|
|
|
|
#include <GLES/gl.h>
|
|
|
|
#include <GLES/glext.h>
|
2011-11-08 15:59:04 +08:00
|
|
|
#include <FText.h>
|
2011-09-19 18:05:40 +08:00
|
|
|
|
|
|
|
using namespace Osp::Base;
|
|
|
|
using namespace Osp::Base::Runtime;
|
2011-11-05 11:36:27 +08:00
|
|
|
using namespace Osp::Base::Collection;
|
2011-11-08 15:59:04 +08:00
|
|
|
using namespace Osp::Text;
|
2011-09-19 18:05:40 +08:00
|
|
|
using namespace Osp::System;
|
|
|
|
using namespace Osp::App;
|
|
|
|
using namespace Osp::Ui;
|
|
|
|
using namespace Osp::Ui::Controls;
|
2011-09-28 09:49:18 +08:00
|
|
|
using namespace Osp::Graphics;
|
2011-09-19 18:05:40 +08:00
|
|
|
|
|
|
|
NS_CC_BEGIN;
|
|
|
|
|
2011-11-05 11:36:27 +08:00
|
|
|
|
|
|
|
static CCEGLView * s_pMainWindow;
|
|
|
|
#define MAX_TOUCHES 5
|
|
|
|
static CCTouch* s_pTouches[MAX_TOUCHES] = { NULL };
|
|
|
|
static HashMapT<int, int> s_idMap;
|
|
|
|
static int s_iIndex = 0;
|
2011-09-19 18:05:40 +08:00
|
|
|
//////////////////////////////////////////////////////////////////////////
|
|
|
|
// impliment CCEGL
|
|
|
|
//////////////////////////////////////////////////////////////////////////
|
|
|
|
class CCEGL
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
~CCEGL()
|
|
|
|
{
|
|
|
|
if (EGL_NO_SURFACE != m_eglSurface)
|
|
|
|
{
|
|
|
|
eglDestroySurface(m_eglDisplay, m_eglSurface);
|
|
|
|
}
|
|
|
|
if (EGL_NO_CONTEXT != m_eglContext)
|
|
|
|
{
|
|
|
|
eglDestroyContext(m_eglDisplay, m_eglContext);
|
|
|
|
}
|
|
|
|
eglMakeCurrent(m_eglDisplay, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT);
|
|
|
|
eglTerminate(m_eglDisplay);
|
|
|
|
}
|
|
|
|
|
|
|
|
static CCEGL * create(CCEGLView * pWindow)
|
|
|
|
{
|
|
|
|
CCEGL * pEGL = new CCEGL;
|
|
|
|
bool bSuccess = false;
|
|
|
|
do
|
|
|
|
{
|
|
|
|
CC_BREAK_IF(! pEGL);
|
|
|
|
|
|
|
|
pEGL->m_eglNativeWindow = pWindow;
|
|
|
|
|
|
|
|
EGLDisplay eglDisplay;
|
|
|
|
CC_BREAK_IF(EGL_NO_DISPLAY == (eglDisplay = eglGetDisplay(pEGL->m_eglNativeDisplay)));
|
|
|
|
|
|
|
|
EGLint nMajor, nMinor;
|
|
|
|
CC_BREAK_IF(EGL_FALSE == eglInitialize(eglDisplay, &nMajor, &nMinor) || 1 != nMajor);
|
|
|
|
|
|
|
|
EGLint aConfigAttribs[] = {
|
|
|
|
EGL_RED_SIZE, 5,
|
|
|
|
EGL_GREEN_SIZE, 6,
|
|
|
|
EGL_BLUE_SIZE, 5,
|
|
|
|
EGL_ALPHA_SIZE, 0,
|
|
|
|
EGL_DEPTH_SIZE, 8,
|
|
|
|
EGL_SURFACE_TYPE, EGL_WINDOW_BIT,
|
|
|
|
EGL_RENDERABLE_TYPE, EGL_OPENGL_ES_BIT,
|
|
|
|
EGL_NONE
|
|
|
|
};
|
|
|
|
eglBindAPI(EGL_OPENGL_ES_API);
|
|
|
|
///
|
|
|
|
|
|
|
|
EGLint iConfigs;
|
|
|
|
EGLConfig eglConfig;
|
|
|
|
CC_BREAK_IF(EGL_FALSE == eglChooseConfig(eglDisplay, aConfigAttribs, &eglConfig, 1, &iConfigs)
|
|
|
|
|| (iConfigs != 1));
|
|
|
|
|
|
|
|
EGLContext eglContext;
|
|
|
|
eglContext = eglCreateContext(eglDisplay, eglConfig, NULL, NULL);
|
|
|
|
CC_BREAK_IF(EGL_NO_CONTEXT == eglContext);
|
|
|
|
|
|
|
|
EGLSurface eglSurface;
|
|
|
|
eglSurface = eglCreateWindowSurface(eglDisplay, eglConfig, pEGL->m_eglNativeWindow, NULL);
|
|
|
|
CC_BREAK_IF(EGL_NO_SURFACE == eglSurface);
|
|
|
|
|
|
|
|
CC_BREAK_IF(EGL_FALSE == eglMakeCurrent(eglDisplay, eglSurface, eglSurface, eglContext));
|
|
|
|
|
|
|
|
pEGL->m_eglDisplay = eglDisplay;
|
|
|
|
pEGL->m_eglConfig = eglConfig;
|
|
|
|
pEGL->m_eglContext = eglContext;
|
|
|
|
pEGL->m_eglSurface = eglSurface;
|
|
|
|
bSuccess = true;
|
|
|
|
|
|
|
|
} while (0);
|
|
|
|
|
|
|
|
if (! bSuccess)
|
|
|
|
{
|
|
|
|
CC_SAFE_DELETE(pEGL);
|
|
|
|
}
|
|
|
|
|
|
|
|
return pEGL;
|
|
|
|
}
|
|
|
|
|
|
|
|
void resizeSurface()
|
|
|
|
{
|
|
|
|
// if (! m_eglNativeWindow || EGL_NO_DISPLAY == m_eglDisplay)
|
|
|
|
// {
|
|
|
|
// return;
|
|
|
|
// }
|
|
|
|
//
|
|
|
|
// // release old surface
|
|
|
|
// if (EGL_NO_SURFACE != m_eglSurface)
|
|
|
|
// {
|
|
|
|
// eglDestroySurface(m_eglDisplay, m_eglSurface);
|
|
|
|
// m_eglSurface = EGL_NO_SURFACE;
|
|
|
|
// }
|
|
|
|
//
|
|
|
|
// // create new surface and make current
|
|
|
|
// m_eglSurface = eglCreateWindowSurface(m_eglDisplay, m_eglConfig, m_eglNativeWindow, NULL);
|
|
|
|
// eglMakeCurrent(m_eglDisplay, m_eglSurface, m_eglSurface, m_eglContext);
|
|
|
|
}
|
|
|
|
|
|
|
|
void swapBuffers()
|
|
|
|
{
|
|
|
|
if (EGL_NO_DISPLAY != m_eglDisplay)
|
|
|
|
{
|
|
|
|
eglSwapBuffers(m_eglDisplay, m_eglSurface);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
private:
|
|
|
|
CCEGL()
|
|
|
|
: m_eglNativeWindow(NULL)
|
|
|
|
, m_eglNativeDisplay(EGL_DEFAULT_DISPLAY)
|
|
|
|
, m_eglDisplay(EGL_NO_DISPLAY)
|
|
|
|
, m_eglConfig(0)
|
|
|
|
, m_eglSurface(EGL_NO_SURFACE)
|
|
|
|
, m_eglContext(EGL_NO_CONTEXT)
|
|
|
|
{}
|
|
|
|
|
|
|
|
EGLNativeWindowType m_eglNativeWindow;
|
|
|
|
EGLNativeDisplayType m_eglNativeDisplay;
|
|
|
|
EGLDisplay m_eglDisplay;
|
|
|
|
EGLConfig m_eglConfig;
|
|
|
|
EGLSurface m_eglSurface;
|
|
|
|
EGLContext m_eglContext;
|
|
|
|
};
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////
|
|
|
|
// impliment CCEGLView
|
|
|
|
//////////////////////////////////////////////////////////////////////////
|
|
|
|
CCEGLView::CCEGLView()
|
2011-11-08 15:59:04 +08:00
|
|
|
: m_pKeypad(null)
|
|
|
|
, m_bNotHVGA(true)
|
2011-09-19 18:05:40 +08:00
|
|
|
, m_pDelegate(NULL)
|
|
|
|
, m_fScreenScaleFactor(1.0)
|
|
|
|
, m_bCaptured(false)
|
|
|
|
, m_pEGL(NULL)
|
|
|
|
{
|
|
|
|
m_pTouch = new CCTouch;
|
|
|
|
m_pSet = new CCSet;
|
|
|
|
m_eInitOrientation = CCDirector::sharedDirector()->getDeviceOrientation();
|
|
|
|
}
|
|
|
|
|
|
|
|
CCEGLView::~CCEGLView()
|
|
|
|
{
|
|
|
|
release();
|
|
|
|
CC_SAFE_DELETE(m_pSet);
|
|
|
|
CC_SAFE_DELETE(m_pTouch);
|
|
|
|
CC_SAFE_DELETE(m_pDelegate);
|
|
|
|
CC_SAFE_DELETE(m_pEGL);
|
2011-11-08 15:59:04 +08:00
|
|
|
CC_SAFE_DELETE(m_pKeypad);
|
2011-09-19 18:05:40 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
CCSize CCEGLView::getSize()
|
|
|
|
{
|
2011-10-08 18:17:01 +08:00
|
|
|
CCSize s;
|
2011-10-09 18:15:31 +08:00
|
|
|
// if (m_bNotHVGA)
|
2011-10-08 18:17:01 +08:00
|
|
|
{
|
2011-10-09 18:15:31 +08:00
|
|
|
s = CCSizeMake(m_sSizeInPoint.width, m_sSizeInPoint.height);
|
2011-10-08 18:17:01 +08:00
|
|
|
}
|
2011-10-09 18:15:31 +08:00
|
|
|
// else
|
|
|
|
// {
|
|
|
|
// s = CCSizeMake(m_sSizeInPixel.width, m_sSizeInPixel.height);
|
|
|
|
// }
|
2011-10-08 18:17:01 +08:00
|
|
|
return s;
|
2011-09-19 18:05:40 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
CCRect CCEGLView::getFrame()
|
|
|
|
{
|
2011-09-28 09:49:18 +08:00
|
|
|
CCRect rc;
|
2011-10-09 18:15:31 +08:00
|
|
|
// if (m_bNotHVGA)
|
|
|
|
// {
|
|
|
|
// rc = CCRectMake(0, 0, m_sSizeInPixel.width, m_sSizeInPixel.height);
|
|
|
|
// }
|
|
|
|
// else
|
2011-09-28 09:49:18 +08:00
|
|
|
{
|
2011-10-09 18:15:31 +08:00
|
|
|
rc = CCRectMake(0, 0, m_sSizeInPoint.width, m_sSizeInPoint.height);
|
2011-09-28 09:49:18 +08:00
|
|
|
}
|
2011-09-19 18:05:40 +08:00
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool CCEGLView::isOpenGLReady()
|
|
|
|
{
|
|
|
|
return (NULL != m_pEGL);
|
|
|
|
}
|
|
|
|
|
|
|
|
void CCEGLView::release()
|
|
|
|
{
|
|
|
|
Application::GetInstance()->Terminate();
|
|
|
|
}
|
|
|
|
|
|
|
|
void CCEGLView::setTouchDelegate(EGLTouchDelegate * pDelegate)
|
|
|
|
{
|
|
|
|
m_pDelegate = pDelegate;
|
|
|
|
}
|
|
|
|
|
|
|
|
void CCEGLView::swapBuffers()
|
|
|
|
{
|
|
|
|
if (m_pEGL)
|
|
|
|
{
|
|
|
|
m_pEGL->swapBuffers();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bool CCEGLView::canSetContentScaleFactor()
|
|
|
|
{
|
|
|
|
// can scale content?
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
void CCEGLView::setContentScaleFactor(float contentScaleFactor)
|
|
|
|
{
|
2011-09-28 09:49:18 +08:00
|
|
|
m_fScreenScaleFactor = contentScaleFactor;
|
2011-09-19 18:05:40 +08:00
|
|
|
}
|
|
|
|
|
2011-11-07 18:18:10 +08:00
|
|
|
int CCEGLView::setDeviceOrientation(Orientation eOritation)
|
2011-09-19 18:05:40 +08:00
|
|
|
{
|
2011-11-07 18:18:10 +08:00
|
|
|
SetOrientation(eOritation);
|
2011-10-13 11:55:48 +08:00
|
|
|
|
2011-11-07 18:18:10 +08:00
|
|
|
if (eOritation == ORIENTATION_PORTRAIT || eOritation == ORIENTATION_PORTRAIT_REVERSE)
|
2011-10-13 11:55:48 +08:00
|
|
|
{
|
|
|
|
int width = MIN(m_sSizeInPixel.width, m_sSizeInPixel.height);
|
|
|
|
m_sSizeInPixel.height = MAX(m_sSizeInPixel.width, m_sSizeInPixel.height);
|
|
|
|
m_sSizeInPixel.width = width;
|
|
|
|
width = MIN(m_sSizeInPoint.width, m_sSizeInPoint.height);
|
|
|
|
m_sSizeInPoint.height = MAX(m_sSizeInPoint.width, m_sSizeInPoint.height);
|
|
|
|
m_sSizeInPoint.width = width;
|
|
|
|
resize(m_sSizeInPoint.width, m_sSizeInPoint.height);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
int width = MAX(m_sSizeInPixel.width, m_sSizeInPixel.height);
|
|
|
|
m_sSizeInPixel.height = MIN(m_sSizeInPixel.width, m_sSizeInPixel.height);
|
|
|
|
m_sSizeInPixel.width = width;
|
|
|
|
width = MAX(m_sSizeInPoint.width, m_sSizeInPoint.height);
|
|
|
|
m_sSizeInPoint.height = MIN(m_sSizeInPoint.width, m_sSizeInPoint.height);
|
|
|
|
m_sSizeInPoint.width = width;
|
|
|
|
resize(m_sSizeInPoint.width, m_sSizeInPoint.height);
|
|
|
|
}
|
2011-10-08 18:17:01 +08:00
|
|
|
|
2011-10-13 11:55:48 +08:00
|
|
|
return m_eInitOrientation;
|
2011-09-19 18:05:40 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void CCEGLView::setViewPortInPoints(float x, float y, float w, float h)
|
|
|
|
{
|
2011-10-08 18:17:01 +08:00
|
|
|
float factor = m_fScreenScaleFactor / CC_CONTENT_SCALE_FACTOR();
|
|
|
|
glViewport((GLint)(x * factor) + m_rcViewPort.origin.x,
|
|
|
|
(GLint)(y * factor) + m_rcViewPort.origin.y,
|
|
|
|
(GLint)(w * factor),
|
|
|
|
(GLint)(h * factor));
|
2011-09-19 18:05:40 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void CCEGLView::setScissorInPoints(float x, float y, float w, float h)
|
|
|
|
{
|
2011-10-08 18:17:01 +08:00
|
|
|
float factor = m_fScreenScaleFactor / CC_CONTENT_SCALE_FACTOR();
|
|
|
|
glScissor((GLint)(x * factor) + m_rcViewPort.origin.x,
|
|
|
|
(GLint)(y * factor) + m_rcViewPort.origin.y,
|
|
|
|
(GLint)(w * factor),
|
|
|
|
(GLint)(h * factor));
|
2011-09-19 18:05:40 +08:00
|
|
|
}
|
|
|
|
|
2011-09-30 17:19:16 +08:00
|
|
|
void CCEGLView::setIMEKeyboardState(bool bOpen)
|
2011-09-19 18:05:40 +08:00
|
|
|
{
|
2011-11-08 15:59:04 +08:00
|
|
|
if (bOpen)
|
|
|
|
{
|
|
|
|
const char * pszText = CCIMEDispatcher::sharedDispatcher()->getContentText();
|
|
|
|
m_pKeypad->SetText(pszText);
|
|
|
|
m_pKeypad->SetShowState(bOpen);
|
|
|
|
m_pKeypad->Show();
|
|
|
|
}
|
2011-09-19 18:05:40 +08:00
|
|
|
}
|
|
|
|
|
2011-09-30 17:19:16 +08:00
|
|
|
bool CCEGLView::Create(Osp::App::Application* pApp, int width, int height)
|
2011-09-19 18:05:40 +08:00
|
|
|
{
|
2011-10-08 18:17:01 +08:00
|
|
|
m_sSizeInPoint.width = MIN(width, height);
|
|
|
|
m_sSizeInPoint.height = MAX(width, height);
|
2011-09-19 18:05:40 +08:00
|
|
|
Construct(FORM_STYLE_NORMAL);
|
|
|
|
Frame *pFrame = Application::GetInstance()->GetAppFrame()->GetFrame();
|
|
|
|
|
|
|
|
pFrame->AddControl(*this);
|
|
|
|
pFrame->SetCurrentForm(*this);
|
|
|
|
|
|
|
|
m_pEGL = CCEGL::create(this);
|
|
|
|
if (m_pEGL == null)
|
|
|
|
return false;
|
|
|
|
s_pMainWindow = this;
|
|
|
|
Draw();
|
|
|
|
Show();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2011-10-08 18:17:01 +08:00
|
|
|
|
|
|
|
void CCEGLView::resize(int width, int height)
|
|
|
|
{
|
2011-10-20 13:44:21 +08:00
|
|
|
int viewPortW = (int)ceil(width * m_fScreenScaleFactor);
|
|
|
|
int viewPortH = (int)ceil(height * m_fScreenScaleFactor);
|
2011-10-09 18:15:31 +08:00
|
|
|
m_rcViewPort.origin.x = (m_sSizeInPixel.width - viewPortW) / 2;
|
|
|
|
m_rcViewPort.origin.y = (m_sSizeInPixel.height - viewPortH) / 2;
|
2011-10-08 18:17:01 +08:00
|
|
|
m_rcViewPort.size.width = viewPortW;
|
|
|
|
m_rcViewPort.size.height = viewPortH;
|
2011-11-07 00:28:09 +08:00
|
|
|
//AppLog("m_rcViewPort.origin.x = %f, y = %f, width = %f, height = %f", \
|
2011-10-08 18:17:01 +08:00
|
|
|
m_rcViewPort.origin.x, m_rcViewPort.origin.y, m_rcViewPort.size.width, m_rcViewPort.size.height);
|
|
|
|
}
|
|
|
|
|
|
|
|
result CCEGLView::OnInitializing(void)
|
2011-09-19 18:05:40 +08:00
|
|
|
{
|
|
|
|
result r = E_SUCCESS;
|
2011-11-05 11:36:27 +08:00
|
|
|
s_idMap.Construct();
|
2011-09-19 18:05:40 +08:00
|
|
|
|
|
|
|
AddTouchEventListener(*this);
|
2011-11-05 11:36:27 +08:00
|
|
|
Touch touch;
|
|
|
|
touch.SetMultipointEnabled(*this, true);
|
2011-09-19 18:05:40 +08:00
|
|
|
|
2011-11-08 15:59:04 +08:00
|
|
|
m_pKeypad = new Keypad();
|
|
|
|
m_pKeypad->Construct(KEYPAD_STYLE_NORMAL, KEYPAD_MODE_ALPHA);
|
|
|
|
m_pKeypad->AddTextEventListener(*this);
|
|
|
|
|
2011-09-28 09:49:18 +08:00
|
|
|
Rectangle rc = GetBounds();
|
|
|
|
if ((rc.width == 480 && rc.height == 720)
|
|
|
|
|| (rc.width == 720 && rc.height == 480))
|
|
|
|
{
|
|
|
|
m_bNotHVGA = false;
|
2011-10-08 18:17:01 +08:00
|
|
|
m_sSizeInPixel.width = rc.width / 1.5f;
|
|
|
|
m_sSizeInPixel.height = rc.height / 1.5f;
|
2011-09-28 09:49:18 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
m_bNotHVGA = true;
|
2011-10-08 18:17:01 +08:00
|
|
|
m_sSizeInPixel.width = rc.width;
|
|
|
|
m_sSizeInPixel.height = rc.height;
|
2011-09-28 09:49:18 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// calculate the factor and the rect of viewport
|
|
|
|
m_fScreenScaleFactor = MIN((float)m_sSizeInPixel.width / m_sSizeInPoint.width,
|
|
|
|
(float)m_sSizeInPixel.height / m_sSizeInPoint.height);
|
2011-11-07 00:28:09 +08:00
|
|
|
//AppLog("rc.width = %d, rc.height = %d, m_fScreenScaleFactor = %f", rc.width, rc.height, m_fScreenScaleFactor);
|
2011-10-09 18:15:31 +08:00
|
|
|
resize(m_sSizeInPoint.width, m_sSizeInPoint.height);
|
2011-09-29 15:52:16 +08:00
|
|
|
|
2011-09-19 18:05:40 +08:00
|
|
|
return r;
|
|
|
|
}
|
|
|
|
|
2011-09-30 17:19:16 +08:00
|
|
|
result CCEGLView::OnTerminating(void)
|
2011-09-19 18:05:40 +08:00
|
|
|
{
|
|
|
|
result r = E_SUCCESS;
|
|
|
|
|
|
|
|
// TODO: Add your termination code here
|
|
|
|
|
|
|
|
return r;
|
|
|
|
}
|
|
|
|
|
2011-11-05 11:36:27 +08:00
|
|
|
void CCEGLView::onPenDown(int nIndex, float x, float y)
|
|
|
|
{
|
2011-11-07 00:28:09 +08:00
|
|
|
//AppLog("onPenDown nIndex = %d,x = %f, y=%f", nIndex, x, y);
|
2011-11-05 11:36:27 +08:00
|
|
|
if (m_pDelegate && nIndex < MAX_TOUCHES)
|
|
|
|
{
|
|
|
|
CCTouch* pTouch = s_pTouches[nIndex];
|
|
|
|
if (!pTouch)
|
|
|
|
{
|
|
|
|
pTouch = new CCTouch;
|
|
|
|
}
|
|
|
|
|
|
|
|
pTouch->SetTouchInfo(0, (x - m_rcViewPort.origin.x) / m_fScreenScaleFactor,
|
|
|
|
(y - m_rcViewPort.origin.y) / m_fScreenScaleFactor);
|
|
|
|
s_pTouches[nIndex] = pTouch;
|
|
|
|
CCSet set;
|
|
|
|
set.addObject(pTouch);
|
|
|
|
m_pDelegate->touchesBegan(&set, NULL);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void CCEGLView::onPenMove(const Control& source)
|
|
|
|
{
|
|
|
|
IList *pList = null;
|
|
|
|
do
|
|
|
|
{
|
|
|
|
CC_BREAK_IF(!m_pDelegate);
|
|
|
|
Touch touch;
|
|
|
|
pList = touch.GetTouchInfoListN(source);
|
|
|
|
CC_BREAK_IF(pList == NULL);
|
|
|
|
|
|
|
|
int nCount = pList->GetCount();
|
|
|
|
CC_BREAK_IF(nCount <= 0 || nCount > MAX_TOUCHES);
|
|
|
|
|
2011-11-07 00:28:09 +08:00
|
|
|
//AppLog("---------------touch count = %d ------------", nCount);
|
2011-11-05 11:36:27 +08:00
|
|
|
CCSet set;
|
|
|
|
float x = 0, y = 0;
|
|
|
|
for (int i = 0; i < nCount; ++i)
|
|
|
|
{
|
|
|
|
TouchInfo *pTouchInfo = static_cast<TouchInfo *>(pList->GetAt(i));
|
|
|
|
x = (float)pTouchInfo->position.x;
|
|
|
|
y = (float)pTouchInfo->position.y;
|
|
|
|
|
|
|
|
CCTouch* pTouch = s_pTouches[i];
|
|
|
|
|
|
|
|
CC_BREAK_IF(!pTouch);
|
2011-11-07 00:28:09 +08:00
|
|
|
//AppLog("onPenMove nIndex = %d,x = %f, y=%f", i, x, y);
|
2011-11-05 11:36:27 +08:00
|
|
|
|
|
|
|
if (!m_bNotHVGA)
|
|
|
|
{
|
|
|
|
x = x * 2 / 3;
|
|
|
|
y = y * 2 / 3;
|
|
|
|
}
|
|
|
|
|
|
|
|
pTouch->SetTouchInfo(0, (x - m_rcViewPort.origin.x) / m_fScreenScaleFactor,
|
|
|
|
(y - m_rcViewPort.origin.y) / m_fScreenScaleFactor);
|
|
|
|
set.addObject(pTouch);
|
|
|
|
}
|
|
|
|
|
|
|
|
m_pDelegate->touchesMoved(&set, NULL);
|
|
|
|
} while (0);
|
|
|
|
|
|
|
|
if (pList != null)
|
|
|
|
{
|
|
|
|
pList->RemoveAll(true);
|
|
|
|
delete pList;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void CCEGLView::onPenUp(int nIndex, float x, float y)
|
|
|
|
{
|
2011-11-07 00:28:09 +08:00
|
|
|
//AppLog("onPenUp nIndex = %d,x = %f, y=%f", nIndex, x, y);
|
2011-11-05 11:36:27 +08:00
|
|
|
if (m_pDelegate && nIndex < MAX_TOUCHES)
|
|
|
|
{
|
|
|
|
CCTouch* pTouch = s_pTouches[nIndex];
|
|
|
|
if (pTouch)
|
|
|
|
{
|
|
|
|
CCSet set;
|
|
|
|
pTouch->SetTouchInfo(0, (x - m_rcViewPort.origin.x) / m_fScreenScaleFactor,
|
|
|
|
(y - m_rcViewPort.origin.y) / m_fScreenScaleFactor);
|
|
|
|
set.addObject(pTouch);
|
|
|
|
m_pDelegate->touchesEnded(&set, NULL);
|
|
|
|
|
|
|
|
pTouch->release();
|
|
|
|
for (int i = nIndex; i < MAX_TOUCHES; ++i)
|
|
|
|
{
|
|
|
|
if (i != (MAX_TOUCHES - 1))
|
|
|
|
{
|
|
|
|
s_pTouches[i] = s_pTouches[i + 1];
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
s_pTouches[i] = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-09-19 18:05:40 +08:00
|
|
|
// touch event
|
2011-11-05 11:36:27 +08:00
|
|
|
void CCEGLView::OnTouchIndicated(const Control& source,
|
|
|
|
const Point& startPosition, const Point& currentPoint)
|
2011-09-19 18:05:40 +08:00
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2011-11-05 11:36:27 +08:00
|
|
|
void CCEGLView::OnTouchPressed(const Control& source,
|
|
|
|
const Point& currentPosition, const TouchEventInfo & touchInfo)
|
2011-09-19 18:05:40 +08:00
|
|
|
{
|
2011-11-07 00:28:09 +08:00
|
|
|
//AppLog("touch id = %d", touchInfo.GetPointId());
|
2011-09-30 17:19:16 +08:00
|
|
|
float x, y;
|
|
|
|
if (!m_bNotHVGA)
|
|
|
|
{
|
2011-11-05 11:36:27 +08:00
|
|
|
x = touchInfo.GetCurrentPosition().x * 2 / 3;
|
|
|
|
y = touchInfo.GetCurrentPosition().y * 2 / 3;
|
2011-09-30 17:19:16 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2011-11-05 11:36:27 +08:00
|
|
|
x = touchInfo.GetCurrentPosition().x;
|
|
|
|
y = touchInfo.GetCurrentPosition().y;
|
2011-09-30 17:19:16 +08:00
|
|
|
}
|
2011-11-05 11:36:27 +08:00
|
|
|
|
|
|
|
if (s_iIndex >= 0)
|
2011-09-19 18:05:40 +08:00
|
|
|
{
|
2011-11-05 11:36:27 +08:00
|
|
|
s_idMap.Add(touchInfo.GetPointId(), s_iIndex);
|
|
|
|
onPenDown(s_iIndex, x, y);
|
2011-09-19 18:05:40 +08:00
|
|
|
}
|
2011-11-05 11:36:27 +08:00
|
|
|
else
|
|
|
|
{
|
|
|
|
s_iIndex = 0;
|
|
|
|
}
|
|
|
|
s_iIndex++;
|
2011-09-19 18:05:40 +08:00
|
|
|
}
|
|
|
|
|
2011-11-05 11:36:27 +08:00
|
|
|
void CCEGLView::OnTouchLongPressed(const Control& source,
|
|
|
|
const Point& currentPosition, const TouchEventInfo & touchInfo)
|
2011-09-19 18:05:40 +08:00
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-11-05 11:36:27 +08:00
|
|
|
void CCEGLView::OnTouchReleased(const Control& source,
|
|
|
|
const Point& currentPosition, const TouchEventInfo & touchInfo)
|
2011-09-19 18:05:40 +08:00
|
|
|
{
|
2011-11-05 11:36:27 +08:00
|
|
|
result r = E_SUCCESS;
|
2011-11-07 00:28:09 +08:00
|
|
|
//AppLog("touch id = %d", touchInfo.GetPointId());
|
2011-09-30 17:19:16 +08:00
|
|
|
float x, y;
|
|
|
|
if (!m_bNotHVGA)
|
2011-09-19 18:05:40 +08:00
|
|
|
{
|
2011-11-05 11:36:27 +08:00
|
|
|
x = touchInfo.GetCurrentPosition().x * 2 / 3;
|
|
|
|
y = touchInfo.GetCurrentPosition().y * 2 / 3;
|
2011-09-30 17:19:16 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2011-11-05 11:36:27 +08:00
|
|
|
x = touchInfo.GetCurrentPosition().x;
|
|
|
|
y = touchInfo.GetCurrentPosition().y;
|
2011-09-30 17:19:16 +08:00
|
|
|
}
|
2011-09-28 09:49:18 +08:00
|
|
|
|
2011-11-05 11:36:27 +08:00
|
|
|
int index = 0;
|
|
|
|
int id = touchInfo.GetPointId();
|
|
|
|
r = s_idMap.GetValue(id, index);
|
|
|
|
|
|
|
|
TryReturnVoid(r == E_SUCCESS, "can't get the point id = %d", id);
|
|
|
|
|
|
|
|
onPenUp(index, x, y);
|
|
|
|
s_idMap.Remove(id);
|
|
|
|
|
|
|
|
if (s_idMap.GetCount() > 0)
|
2011-09-30 17:19:16 +08:00
|
|
|
{
|
2011-11-05 11:36:27 +08:00
|
|
|
int key = 0, value = 0;
|
|
|
|
ArrayListT<int> list;
|
|
|
|
list.Construct();
|
|
|
|
IMapEnumeratorT<int, int>* pMapEnum = s_idMap.GetMapEnumeratorN();
|
|
|
|
while (pMapEnum->MoveNext() == E_SUCCESS)
|
|
|
|
{
|
|
|
|
pMapEnum->GetValue(value);
|
|
|
|
if (value > index)
|
|
|
|
{
|
|
|
|
pMapEnum->GetKey(key);
|
|
|
|
list.Add(key);
|
2011-11-07 00:28:09 +08:00
|
|
|
//AppLog("[%d]=%d",key, value);
|
2011-11-05 11:36:27 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
delete pMapEnum;
|
|
|
|
|
|
|
|
for (int i=0; i < list.GetCount(); i++)
|
|
|
|
{
|
|
|
|
list.GetAt(i, key);
|
|
|
|
s_idMap.GetValue(key, value);
|
|
|
|
value--;
|
|
|
|
s_idMap.SetValue(key, value);
|
|
|
|
}
|
2011-09-19 18:05:40 +08:00
|
|
|
}
|
2011-11-05 11:36:27 +08:00
|
|
|
s_iIndex--;
|
2011-09-19 18:05:40 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-11-05 11:36:27 +08:00
|
|
|
void CCEGLView::OnTouchMoved(const Control& source,
|
|
|
|
const Point& currentPosition, const TouchEventInfo & touchInfo)
|
2011-09-19 18:05:40 +08:00
|
|
|
{
|
2011-11-07 00:28:09 +08:00
|
|
|
//AppLog("touch id = %d", touchInfo.GetPointId());
|
2011-11-05 11:36:27 +08:00
|
|
|
onPenMove(source);
|
2011-09-19 18:05:40 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-11-05 11:36:27 +08:00
|
|
|
void CCEGLView::OnTouchDoublePressed(const Control& source,
|
|
|
|
const Point& currentPosition, const TouchEventInfo & touchInfo)
|
2011-09-19 18:05:40 +08:00
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-11-05 11:36:27 +08:00
|
|
|
void CCEGLView::OnTouchFocusIn(const Control& source,
|
|
|
|
const Point& currentPosition, const TouchEventInfo & touchInfo)
|
2011-09-19 18:05:40 +08:00
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-11-05 11:36:27 +08:00
|
|
|
void CCEGLView::OnTouchFocusOut(const Control& source,
|
|
|
|
const Point& currentPosition, const TouchEventInfo & touchInfo)
|
2011-09-19 18:05:40 +08:00
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
result CCEGLView::OnDraw(void)
|
|
|
|
{
|
|
|
|
result r = E_SUCCESS;
|
|
|
|
CCDirector * pDirector = CCDirector::sharedDirector();
|
|
|
|
pDirector->drawScene();
|
|
|
|
return r;
|
|
|
|
}
|
|
|
|
|
2011-11-08 15:59:04 +08:00
|
|
|
// Implement an ITextEventListener
|
|
|
|
void CCEGLView::OnTextValueChanged(const Control& source)
|
|
|
|
{
|
|
|
|
// clear textinput text
|
|
|
|
std::string strOldText = CCIMEDispatcher::sharedDispatcher()->getContentText();
|
|
|
|
|
|
|
|
for (int i = 0; i < strOldText.length(); i++)
|
|
|
|
{
|
|
|
|
CCIMEDispatcher::sharedDispatcher()->dispatchDeleteBackward();
|
|
|
|
}
|
|
|
|
|
|
|
|
String str = m_pKeypad->GetText();
|
|
|
|
if (str.GetLength() <= 0)
|
|
|
|
{
|
|
|
|
CCIMEDispatcher::sharedDispatcher()->dispatchInsertText("\n", 1);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
Utf8Encoding utf8;
|
|
|
|
ByteBuffer* pBuffer = utf8.GetBytesN(str);
|
|
|
|
if (pBuffer != null)
|
|
|
|
{
|
|
|
|
const char* pszText = (const char*)pBuffer->GetPointer();
|
|
|
|
if (pszText != NULL)
|
|
|
|
{
|
|
|
|
int len = strlen(pszText);
|
|
|
|
if (pszText[len-1] != '\n')
|
|
|
|
{
|
|
|
|
std::string strText = pszText;
|
|
|
|
strText.append("\n");
|
|
|
|
CCIMEDispatcher::sharedDispatcher()->dispatchInsertText(strText.c_str(), strText.length());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
delete pBuffer;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void CCEGLView::OnTextValueChangeCanceled(const Control& source)
|
|
|
|
{
|
|
|
|
CCIMEDispatcher::sharedDispatcher()->dispatchInsertText("\n", 1);
|
|
|
|
}
|
|
|
|
|
2011-09-19 18:05:40 +08:00
|
|
|
CCEGLView& CCEGLView::sharedOpenGLView()
|
|
|
|
{
|
|
|
|
CC_ASSERT(s_pMainWindow);
|
|
|
|
return *s_pMainWindow;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_CC_END;
|