2010-07-28 10:26:06 +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.
|
|
|
|
****************************************************************************/
|
|
|
|
|
2010-09-06 18:35:24 +08:00
|
|
|
#include "TG3.h"
|
2010-12-02 18:44:13 +08:00
|
|
|
#include "ssBackLightControl.h"
|
2010-09-06 18:35:24 +08:00
|
|
|
|
2010-07-29 16:05:14 +08:00
|
|
|
#include "EGL/egl.h"
|
2010-10-09 16:23:58 +08:00
|
|
|
#include "GLES/gl.h"
|
2010-07-29 16:05:14 +08:00
|
|
|
|
2011-03-07 18:20:48 +08:00
|
|
|
#include "CCSet.h"
|
2010-08-05 12:02:55 +08:00
|
|
|
#include "CCDirector.h"
|
2010-08-25 10:19:20 +08:00
|
|
|
#include "CCTouch.h"
|
|
|
|
#include "CCTouchDispatcher.h"
|
2010-07-29 12:12:11 +08:00
|
|
|
|
2010-11-10 16:29:52 +08:00
|
|
|
#include "TCOM_Sensors_Interface.h"
|
2011-03-07 18:20:48 +08:00
|
|
|
#include "CCAccelerometer.h"
|
2010-12-13 14:10:39 +08:00
|
|
|
#include "CCKeypadDispatcher.h"
|
2011-05-05 18:17:50 +08:00
|
|
|
#include "CCIMEDispatcher.h"
|
2010-11-10 16:29:52 +08:00
|
|
|
|
2011-03-07 18:20:48 +08:00
|
|
|
#include "CCApplication.h"
|
2011-02-19 17:44:43 +08:00
|
|
|
#include "ccMacros.h"
|
2010-12-02 18:44:13 +08:00
|
|
|
|
2010-07-28 10:26:06 +08:00
|
|
|
namespace cocos2d {
|
|
|
|
|
2010-12-09 18:28:16 +08:00
|
|
|
#define MAX_TOUCHES 4
|
|
|
|
static CCTouch *s_pTouches[MAX_TOUCHES] = { NULL };
|
|
|
|
|
2011-03-07 18:20:48 +08:00
|
|
|
class CCEGL
|
2010-07-29 16:05:14 +08:00
|
|
|
{
|
|
|
|
public:
|
2011-03-07 18:20:48 +08:00
|
|
|
~CCEGL()
|
2010-09-17 12:02:23 +08:00
|
|
|
{
|
|
|
|
if (EGL_NO_DISPLAY == m_eglDisplay)
|
2010-09-06 18:35:24 +08:00
|
|
|
{
|
2010-09-17 12:02:23 +08:00
|
|
|
return;
|
2010-09-06 18:35:24 +08:00
|
|
|
}
|
2010-09-17 12:02:23 +08:00
|
|
|
|
2010-09-06 18:35:24 +08:00
|
|
|
if (EGL_NO_SURFACE != m_eglSurface)
|
|
|
|
{
|
|
|
|
eglDestroySurface(m_eglDisplay, m_eglSurface);
|
|
|
|
}
|
|
|
|
if (EGL_NO_CONTEXT != m_eglContext)
|
|
|
|
{
|
|
|
|
eglDestroyContext(m_eglDisplay, m_eglContext);
|
|
|
|
}
|
2010-09-17 12:02:23 +08:00
|
|
|
eglMakeCurrent(m_eglDisplay, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT);
|
|
|
|
eglTerminate(m_eglDisplay);
|
2010-09-06 18:35:24 +08:00
|
|
|
}
|
|
|
|
|
2011-03-07 18:20:48 +08:00
|
|
|
static CCEGL * create(TWindow * pWindow)
|
2010-09-06 18:35:24 +08:00
|
|
|
{
|
2011-03-07 18:20:48 +08:00
|
|
|
CCEGL * pEGL = new CCEGL;
|
2010-09-06 18:35:24 +08:00
|
|
|
Boolean bSuccess = FALSE;
|
|
|
|
do
|
|
|
|
{
|
2011-03-07 18:20:48 +08:00
|
|
|
CC_BREAK_IF(! pEGL);
|
2010-09-06 18:35:24 +08:00
|
|
|
|
2010-10-29 16:36:34 +08:00
|
|
|
TUChar szError[] = {'E','R','R','O','R',0};
|
|
|
|
TUChar szEglInitFailed[] = {'e','g','l','I','n','i','t','i','a','l','i','z','e',' ','f','a','i','l','e','d',0};
|
|
|
|
TUChar szCreateContextFailed[] = {'e','g','l','C','r','e','a','t','e','C','o','n','t','e','x','t',' ','f','a','i','l','e','d',0};
|
|
|
|
TUChar szEglCreateWindowSurfaceFailed[] = {'e','g','l','C','r','e','a','t','e','W','i','n','d','o','w','S','u','r','f','a','c','e',' ','f','a','i','l','e','d',0};
|
|
|
|
TUChar szEglMakeCurrentFailed[] = {'e','g','l','M','a','k','e','C','u','r','r','e','n','t',' ','f','a','i','l','e','d',0};
|
|
|
|
|
2010-09-17 12:02:23 +08:00
|
|
|
pEGL->m_eglNativeWindow = pWindow;
|
2010-09-06 18:35:24 +08:00
|
|
|
|
|
|
|
EGLDisplay eglDisplay;
|
2011-03-07 18:20:48 +08:00
|
|
|
CC_BREAK_IF(EGL_NO_DISPLAY == (eglDisplay = eglGetDisplay(pEGL->m_eglNativeDisplay)));
|
2010-09-06 18:35:24 +08:00
|
|
|
|
|
|
|
EGLint nMajor, nMinor;
|
2010-10-29 16:36:34 +08:00
|
|
|
EGLBoolean bEglRet;
|
|
|
|
|
|
|
|
bEglRet = eglInitialize(eglDisplay, &nMajor, &nMinor);
|
|
|
|
if ( EGL_FALSE == bEglRet || 1 != nMajor )
|
|
|
|
{
|
|
|
|
TApplication::GetCurrentApplication()->MessageBox(szEglInitFailed, szError, WMB_OK);
|
|
|
|
break;
|
|
|
|
}
|
2010-09-06 18:35:24 +08:00
|
|
|
|
|
|
|
const EGLint aConfigAttribs[] =
|
|
|
|
{
|
|
|
|
EGL_LEVEL, 0,
|
|
|
|
EGL_SURFACE_TYPE, EGL_WINDOW_BIT,
|
|
|
|
EGL_RENDERABLE_TYPE, EGL_OPENGL_ES2_BIT,
|
|
|
|
EGL_NATIVE_RENDERABLE, EGL_FALSE,
|
2010-09-17 09:20:46 +08:00
|
|
|
EGL_DEPTH_SIZE, 16,
|
2010-09-06 18:35:24 +08:00
|
|
|
EGL_NONE,
|
|
|
|
};
|
|
|
|
EGLint iConfigs;
|
|
|
|
EGLConfig eglConfig;
|
2011-03-07 18:20:48 +08:00
|
|
|
CC_BREAK_IF( EGL_FALSE == eglChooseConfig(eglDisplay, aConfigAttribs, &eglConfig, 1, &iConfigs) ||
|
2010-10-29 16:36:34 +08:00
|
|
|
(iConfigs != 1) );
|
2010-09-06 18:35:24 +08:00
|
|
|
|
2010-10-29 16:36:34 +08:00
|
|
|
EGLContext eglContext = eglCreateContext(eglDisplay, eglConfig, NULL, NULL);
|
|
|
|
if (EGL_NO_CONTEXT == eglContext)
|
|
|
|
{
|
|
|
|
TApplication::GetCurrentApplication()->MessageBox(szCreateContextFailed, szError, WMB_OK);
|
|
|
|
break;
|
|
|
|
}
|
2010-09-06 18:35:24 +08:00
|
|
|
|
2010-09-17 12:02:23 +08:00
|
|
|
EGLSurface eglSurface;
|
|
|
|
eglSurface = eglCreateWindowSurface(eglDisplay, eglConfig, pEGL->m_eglNativeWindow, NULL);
|
2010-10-29 16:36:34 +08:00
|
|
|
if (EGL_NO_SURFACE == eglSurface)
|
|
|
|
{
|
|
|
|
TApplication::GetCurrentApplication()->MessageBox(szEglCreateWindowSurfaceFailed, szError, WMB_OK);
|
|
|
|
break;
|
|
|
|
}
|
2010-09-17 12:02:23 +08:00
|
|
|
|
2010-10-29 16:36:34 +08:00
|
|
|
bEglRet = eglMakeCurrent(eglDisplay, eglSurface, eglSurface, eglContext);
|
|
|
|
if (EGL_FALSE == bEglRet)
|
|
|
|
{
|
|
|
|
TApplication::GetCurrentApplication()->MessageBox(szEglMakeCurrentFailed, szError, WMB_OK);
|
|
|
|
break;
|
|
|
|
}
|
2010-09-06 18:35:24 +08:00
|
|
|
|
|
|
|
pEGL->m_eglDisplay = eglDisplay;
|
|
|
|
pEGL->m_eglConfig = eglConfig;
|
|
|
|
pEGL->m_eglContext = eglContext;
|
2010-09-17 12:02:23 +08:00
|
|
|
pEGL->m_eglSurface = eglSurface;
|
2010-09-06 18:35:24 +08:00
|
|
|
bSuccess = TRUE;
|
|
|
|
} while (0);
|
|
|
|
|
|
|
|
if (! bSuccess)
|
|
|
|
{
|
2011-03-07 18:20:48 +08:00
|
|
|
CC_SAFE_DELETE(pEGL);
|
2010-09-06 18:35:24 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
return pEGL;
|
|
|
|
}
|
|
|
|
|
|
|
|
void resizeSurface()
|
|
|
|
{
|
2010-09-17 12:02:23 +08:00
|
|
|
// if (! m_eglWnd || 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_eglWnd, NULL);
|
|
|
|
// eglMakeCurrent(m_eglDisplay, m_eglSurface, m_eglSurface, m_eglContext);
|
2010-09-06 18:35:24 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void swapBuffers()
|
|
|
|
{
|
|
|
|
if (EGL_NO_DISPLAY != m_eglDisplay)
|
|
|
|
{
|
|
|
|
eglSwapBuffers(m_eglDisplay, m_eglSurface);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
private:
|
2011-03-07 18:20:48 +08:00
|
|
|
CCEGL()
|
2010-09-17 12:02:23 +08:00
|
|
|
: m_eglNativeWindow(NULL)
|
|
|
|
, m_eglNativeDisplay(EGL_DEFAULT_DISPLAY)
|
2010-09-06 18:35:24 +08:00
|
|
|
, m_eglDisplay(EGL_NO_DISPLAY)
|
|
|
|
, m_eglConfig(0)
|
|
|
|
, m_eglSurface(EGL_NO_SURFACE)
|
|
|
|
, m_eglContext(EGL_NO_CONTEXT)
|
|
|
|
{}
|
|
|
|
|
2010-09-17 12:02:23 +08:00
|
|
|
EGLNativeWindowType m_eglNativeWindow;
|
|
|
|
EGLNativeDisplayType m_eglNativeDisplay;
|
2010-09-06 18:35:24 +08:00
|
|
|
EGLDisplay m_eglDisplay;
|
|
|
|
EGLConfig m_eglConfig;
|
|
|
|
EGLSurface m_eglSurface;
|
|
|
|
EGLContext m_eglContext;
|
|
|
|
};
|
|
|
|
|
2010-12-03 15:27:55 +08:00
|
|
|
//////////////////////////////////////////////////////////////////////////
|
2011-03-07 18:20:48 +08:00
|
|
|
// impliment CCEGLView
|
2010-12-03 15:27:55 +08:00
|
|
|
//////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2011-03-07 18:20:48 +08:00
|
|
|
static CCEGLView* s_pMainWindow = NULL;
|
2011-02-19 17:44:43 +08:00
|
|
|
|
2011-03-07 18:20:48 +08:00
|
|
|
CCEGLView::CCEGLView(TApplication * pApp)
|
2010-07-28 10:26:06 +08:00
|
|
|
: TWindow(pApp)
|
2010-07-28 18:18:27 +08:00
|
|
|
, m_pDelegate(NULL)
|
2010-07-29 16:05:14 +08:00
|
|
|
, m_pEGL(NULL)
|
2011-02-19 17:44:43 +08:00
|
|
|
, m_fScreenScaleFactor(1.0f)
|
2011-05-05 18:17:50 +08:00
|
|
|
, m_pTextField(NULL)
|
|
|
|
, m_nTextLen(0)
|
2010-07-28 10:26:06 +08:00
|
|
|
{
|
2011-05-06 16:38:09 +08:00
|
|
|
memset(&m_rcKeyboard, 0, sizeof(m_rcKeyboard));
|
2010-07-28 10:26:06 +08:00
|
|
|
}
|
|
|
|
|
2011-03-07 18:20:48 +08:00
|
|
|
CCEGLView::~CCEGLView()
|
2010-07-28 10:26:06 +08:00
|
|
|
{
|
2011-03-07 18:20:48 +08:00
|
|
|
CC_SAFE_DELETE(m_pDelegate);
|
|
|
|
CC_SAFE_DELETE(m_pEGL);
|
2010-07-28 10:26:06 +08:00
|
|
|
}
|
|
|
|
|
2011-05-06 16:38:09 +08:00
|
|
|
Boolean CCEGLView::Create(int nWidthInPoints, int nHeightInPoints, UInt32 eRotateMode)
|
2011-02-19 17:44:43 +08:00
|
|
|
{
|
|
|
|
// record the window size in points
|
|
|
|
m_tSizeInPoints.SetWidth(nWidthInPoints);
|
|
|
|
m_tSizeInPoints.SetHeight(nHeightInPoints);
|
|
|
|
|
|
|
|
// get the screen size
|
|
|
|
TApplication* pApp = TApplication::GetCurrentApplication();
|
|
|
|
Int32 nWidth = pApp->GetScreenWidth();
|
|
|
|
Int32 nHeight = pApp->GetScreenHeight();
|
|
|
|
|
|
|
|
// calculate the factor and the rect of viewport
|
|
|
|
m_fScreenScaleFactor = MIN((float)nWidth / nWidthInPoints, (float)nHeight / nHeightInPoints);
|
|
|
|
int viewPortW = (int)(m_tSizeInPoints.Width() * m_fScreenScaleFactor);
|
|
|
|
int viewPortH = (int)(m_tSizeInPoints.Height() * m_fScreenScaleFactor);
|
|
|
|
m_rcViewPort.SetX((nWidth - viewPortW) / 2);
|
|
|
|
m_rcViewPort.SetY((nHeight - viewPortH) / 2);
|
|
|
|
m_rcViewPort.SetWidth(viewPortW);
|
|
|
|
m_rcViewPort.SetHeight(viewPortH);
|
|
|
|
|
|
|
|
Boolean bRet = TWindow::Create(&TRectangle(0, 0, nWidth, nHeight));
|
|
|
|
|
2011-05-06 16:38:09 +08:00
|
|
|
Coord temp;
|
|
|
|
Int32 tmp;
|
|
|
|
if (WM_WINDOW_ROTATE_MODE_CW == eRotateMode
|
|
|
|
|| WM_WINDOW_ROTATE_MODE_CCW == eRotateMode)
|
|
|
|
{
|
|
|
|
temp = m_rcViewPort.X();
|
|
|
|
m_rcViewPort.SetX(m_rcViewPort.Y());
|
|
|
|
m_rcViewPort.SetY(temp);
|
|
|
|
temp = m_rcViewPort.Width();
|
|
|
|
m_rcViewPort.SetWidth(m_rcViewPort.Height());
|
|
|
|
m_rcViewPort.SetHeight(temp);
|
|
|
|
|
|
|
|
tmp = m_tSizeInPoints.Width();
|
|
|
|
m_tSizeInPoints.SetWidth(m_tSizeInPoints.Height());
|
|
|
|
m_tSizeInPoints.SetHeight(tmp);
|
|
|
|
}
|
|
|
|
this->RotateWindow(eRotateMode);
|
2011-02-19 17:44:43 +08:00
|
|
|
if (bRet)
|
|
|
|
{
|
|
|
|
s_pMainWindow = this;
|
|
|
|
}
|
|
|
|
|
|
|
|
return bRet;
|
|
|
|
}
|
|
|
|
|
2011-03-07 18:20:48 +08:00
|
|
|
Boolean CCEGLView::AfterCreate(void)
|
2010-08-03 11:23:12 +08:00
|
|
|
{
|
2011-03-07 18:20:48 +08:00
|
|
|
return (m_pEGL = CCEGL::create(this)) ? TRUE : FALSE;
|
2010-08-03 11:23:12 +08:00
|
|
|
}
|
|
|
|
|
2011-03-07 18:20:48 +08:00
|
|
|
Boolean CCEGLView::EventHandler(TApplication * pApp, EventType * pEvent)
|
2010-07-28 10:26:06 +08:00
|
|
|
{
|
2010-07-28 18:18:27 +08:00
|
|
|
Boolean bHandled = FALSE;
|
2010-07-29 16:05:14 +08:00
|
|
|
|
|
|
|
switch(pEvent->eType)
|
2010-07-28 18:18:27 +08:00
|
|
|
{
|
2010-08-05 17:20:24 +08:00
|
|
|
case EVENT_WinInit:
|
2011-05-05 18:17:50 +08:00
|
|
|
if ((m_pTextField = new TEdit)
|
|
|
|
&& m_pTextField->Create(this))
|
|
|
|
{
|
|
|
|
TRectangle rc(0, pApp->GetScreenHeight(), pApp->GetScreenWidth(), 50);
|
|
|
|
m_pTextField->SetBounds(&rc);
|
|
|
|
m_pTextField->HideCursor();
|
|
|
|
CfgRegisterScreenSwitchNotify(GetWindowHwndId(), 0);
|
|
|
|
bHandled = TRUE;
|
|
|
|
}
|
2010-08-05 17:20:24 +08:00
|
|
|
break;
|
|
|
|
|
2010-07-29 16:05:14 +08:00
|
|
|
case EVENT_WinPaint:
|
2010-12-04 18:16:09 +08:00
|
|
|
if (CfgGetScreenStatus())
|
|
|
|
{
|
|
|
|
// draw
|
2010-12-31 14:56:24 +08:00
|
|
|
CCDirector::sharedDirector()->mainLoop();
|
2010-12-04 18:16:09 +08:00
|
|
|
}
|
2010-08-05 17:20:24 +08:00
|
|
|
bHandled = TRUE;
|
2010-07-29 16:05:14 +08:00
|
|
|
break;
|
|
|
|
|
|
|
|
case EVENT_PenDown:
|
2010-12-09 18:28:16 +08:00
|
|
|
bHandled = OnPenDown(pEvent, 0);
|
2010-07-29 16:05:14 +08:00
|
|
|
break;
|
2010-08-06 12:02:54 +08:00
|
|
|
|
2010-07-29 16:05:14 +08:00
|
|
|
case EVENT_PenMove:
|
2010-12-09 18:28:16 +08:00
|
|
|
bHandled = OnPenMove(pEvent);
|
2010-07-29 16:05:14 +08:00
|
|
|
break;
|
|
|
|
|
|
|
|
case EVENT_PenUp:
|
2010-12-09 18:28:16 +08:00
|
|
|
bHandled = OnPenUp(pEvent, 0);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case EVENT_MultiTouchDown:
|
|
|
|
bHandled = OnPenDown(pEvent, pEvent->lParam3);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case EVENT_MultiTouchUp:
|
|
|
|
bHandled = OnPenUp(pEvent, pEvent->lParam3);
|
2010-07-29 16:05:14 +08:00
|
|
|
break;
|
2010-08-05 17:20:24 +08:00
|
|
|
|
2010-12-13 14:10:39 +08:00
|
|
|
case EVENT_KeyCommand:
|
|
|
|
{
|
|
|
|
if (pEvent->sParam1 == SYS_KEY_SOFTKEY_RIGHT_UP ||
|
|
|
|
pEvent->sParam1 == SYS_KEY_SOFTKEY_RIGHT_LONG)
|
|
|
|
{
|
|
|
|
bHandled = CCKeypadDispatcher::sharedDispatcher()->dispatchKeypadMSG(kTypeBackClicked);
|
|
|
|
}
|
2011-03-09 11:26:13 +08:00
|
|
|
else if (pEvent->sParam1 == KEY_COMMAND_MAINMENU)
|
2010-12-31 18:15:30 +08:00
|
|
|
{
|
2011-01-17 16:21:11 +08:00
|
|
|
bHandled = CCKeypadDispatcher::sharedDispatcher()->dispatchKeypadMSG(kTypeMenuClicked);
|
2010-12-31 18:15:30 +08:00
|
|
|
}
|
2010-12-13 14:10:39 +08:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2011-05-06 16:38:09 +08:00
|
|
|
case EVENT_WinImeStatusNotify:
|
|
|
|
{
|
|
|
|
EosImeNotifyEventType * pNotify = (EosImeNotifyEventType*)pEvent;
|
|
|
|
if (IME_NOTIFY_TYPE_KEYBOARD_SIZE == pNotify->notifyType)
|
|
|
|
{
|
|
|
|
m_rcKeyboard = pNotify->rtKeyboard;
|
|
|
|
|
|
|
|
//keyboard open
|
|
|
|
CCIMEKeyboardNotificationInfo info;
|
|
|
|
info.begin = CCRectMake((float)0
|
|
|
|
, (float)0 - m_rcKeyboard.extent.Y
|
|
|
|
, (float)m_rcKeyboard.extent.X
|
|
|
|
, (float)m_rcKeyboard.extent.Y);
|
|
|
|
info.end = CCRectMake((float)0
|
|
|
|
, (float)0
|
|
|
|
, (float)m_rcKeyboard.extent.X
|
|
|
|
, (float)m_rcKeyboard.extent.Y);
|
|
|
|
info.duration = 0;
|
|
|
|
CCIMEDispatcher::sharedDispatcher()->dispatchKeyboardWillShow(info);
|
|
|
|
CCIMEDispatcher::sharedDispatcher()->dispatchKeyboardDidShow(info);
|
|
|
|
}
|
|
|
|
else if (IME_NOTIFY_TYPE_IME_CLOSE == pNotify->notifyType)
|
|
|
|
{
|
|
|
|
CCIMEKeyboardNotificationInfo info;
|
|
|
|
info.begin = CCRectMake((float)0
|
|
|
|
, (float)0
|
|
|
|
, (float)m_rcKeyboard.extent.X
|
|
|
|
, (float)m_rcKeyboard.extent.Y);
|
|
|
|
info.end = CCRectMake((float)0
|
|
|
|
, (float)0 - m_rcKeyboard.extent.Y
|
|
|
|
, (float)m_rcKeyboard.extent.X
|
|
|
|
, (float)m_rcKeyboard.extent.Y);
|
|
|
|
info.duration = 0;
|
|
|
|
CCIMEDispatcher::sharedDispatcher()->dispatchKeyboardWillHide(info);
|
|
|
|
CCIMEDispatcher::sharedDispatcher()->dispatchKeyboardDidHide(info);
|
|
|
|
}
|
|
|
|
pEvent->sParam1 = pEvent->sParam1;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2011-05-05 18:17:50 +08:00
|
|
|
case EVENT_FieldChanged:
|
|
|
|
do
|
|
|
|
{
|
|
|
|
CC_BREAK_IF(pEvent->sParam1 != m_pTextField->GetId());
|
|
|
|
|
|
|
|
const TUChar * ptszText = m_pTextField->GetCaption();
|
|
|
|
CC_BREAK_IF(! ptszText);
|
|
|
|
|
|
|
|
int nLen = TUString::StrLen(ptszText);
|
|
|
|
if (nLen > m_nTextLen)
|
|
|
|
{
|
|
|
|
char szText[MAX_PATH] = {0};
|
|
|
|
CCIMEDispatcher::sharedDispatcher()->dispatchInsertText(szText
|
|
|
|
, TUString::StrUnicodeToStrUtf8((Char *)szText, ptszText + m_nTextLen));
|
|
|
|
m_nTextLen = nLen;
|
|
|
|
}
|
|
|
|
else if (nLen < m_nTextLen)
|
|
|
|
{
|
|
|
|
for (int i = m_nTextLen - nLen; i > 0; --i)
|
|
|
|
{
|
|
|
|
CCIMEDispatcher::sharedDispatcher()->dispatchDeleteBackward();
|
|
|
|
}
|
|
|
|
m_nTextLen = nLen;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
const char * pszReturn = "\n";
|
|
|
|
CCIMEDispatcher::sharedDispatcher()->dispatchInsertText(pszReturn, 1);
|
|
|
|
}
|
|
|
|
} while (0);
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
2010-11-10 16:29:52 +08:00
|
|
|
case MESSAGE_SENSORS_DATA:
|
|
|
|
{
|
|
|
|
TG3SensorsDataType data;
|
|
|
|
|
|
|
|
if (Sys_GetMessageBody((MESSAGE_t *)pEvent, &data, sizeof(TG3SensorsDataType)) == sizeof(TG3SensorsDataType) &&
|
|
|
|
TG3_SENSOR_TYPE_ACCELEROMETER == data.sensorMask)
|
|
|
|
{
|
|
|
|
// convert the data to iphone format
|
2011-03-09 11:26:13 +08:00
|
|
|
CCAcceleration AccValue;
|
2010-11-10 16:29:52 +08:00
|
|
|
AccValue.x = -(data.acceleration.x / TG3_GRAVITY_EARTH);
|
|
|
|
AccValue.y = -(data.acceleration.y / TG3_GRAVITY_EARTH);
|
|
|
|
AccValue.z = -(data.acceleration.z / TG3_GRAVITY_EARTH);
|
|
|
|
AccValue.timestamp = (double) TimGetTicks() / 100;
|
|
|
|
|
|
|
|
// call delegates' didAccelerate function
|
2011-03-07 18:20:48 +08:00
|
|
|
CCAccelerometer::sharedAccelerometer()->didAccelerate(&AccValue);
|
2010-11-10 16:29:52 +08:00
|
|
|
bHandled = TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2010-08-05 17:20:24 +08:00
|
|
|
case EVENT_WinClose:
|
2011-05-05 18:17:50 +08:00
|
|
|
ImeCloseIme();
|
2010-12-04 18:16:09 +08:00
|
|
|
CfgUnRegisterScreenSwitchNotify(GetWindowHwndId(), 0);
|
2010-08-05 17:20:24 +08:00
|
|
|
// Stop the application since the main form has been closed
|
|
|
|
pApp->SendStopEvent();
|
|
|
|
break;
|
|
|
|
|
2010-12-02 18:44:13 +08:00
|
|
|
case EVENT_ScreenSwitchNotify:
|
|
|
|
{
|
2011-03-07 18:20:48 +08:00
|
|
|
CCApplication::sharedApplication().switchNotify(pEvent->sParam1);
|
2011-01-20 13:41:58 +08:00
|
|
|
break;
|
2010-12-02 18:44:13 +08:00
|
|
|
}
|
2010-12-04 18:16:09 +08:00
|
|
|
|
2010-07-28 18:18:27 +08:00
|
|
|
}
|
|
|
|
|
2010-08-03 11:23:12 +08:00
|
|
|
if (! bHandled)
|
2010-07-28 18:18:27 +08:00
|
|
|
{
|
|
|
|
return TWindow::EventHandler(pApp, pEvent);
|
|
|
|
}
|
2010-08-03 11:23:12 +08:00
|
|
|
return bHandled;
|
2010-07-28 10:26:06 +08:00
|
|
|
}
|
|
|
|
|
2011-03-07 18:20:48 +08:00
|
|
|
Boolean CCEGLView::OnPenDown(EventType* pEvent, Int32 nIndex)
|
2010-12-09 18:28:16 +08:00
|
|
|
{
|
|
|
|
if (m_pDelegate && nIndex < MAX_TOUCHES)
|
|
|
|
{
|
|
|
|
CCTouch* pTouch = s_pTouches[nIndex];
|
|
|
|
if (!pTouch)
|
|
|
|
{
|
|
|
|
pTouch = new CCTouch;
|
|
|
|
}
|
|
|
|
|
2011-02-19 17:44:43 +08:00
|
|
|
pTouch->SetTouchInfo(0, (float)(pEvent->sParam1 - m_rcViewPort.X()) / m_fScreenScaleFactor,
|
|
|
|
(float)(pEvent->sParam2 - m_rcViewPort.Y()) / m_fScreenScaleFactor);
|
2010-12-09 18:28:16 +08:00
|
|
|
s_pTouches[nIndex] = pTouch;
|
2011-03-07 18:20:48 +08:00
|
|
|
CCSet set;
|
2010-12-09 18:28:16 +08:00
|
|
|
set.addObject(pTouch);
|
|
|
|
m_pDelegate->touchesBegan(&set, NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2011-03-07 18:20:48 +08:00
|
|
|
Boolean CCEGLView::OnPenUp(EventType* pEvent, Int32 nIndex)
|
2010-12-09 18:28:16 +08:00
|
|
|
{
|
|
|
|
if (m_pDelegate && nIndex < MAX_TOUCHES)
|
|
|
|
{
|
|
|
|
CCTouch* pTouch = s_pTouches[nIndex];
|
|
|
|
if (pTouch)
|
|
|
|
{
|
2011-03-07 18:20:48 +08:00
|
|
|
CCSet set;
|
2011-02-19 17:44:43 +08:00
|
|
|
pTouch->SetTouchInfo(0, (float)(pEvent->sParam1 - m_rcViewPort.X()) / m_fScreenScaleFactor,
|
|
|
|
(float)(pEvent->sParam2 - m_rcViewPort.Y()) / m_fScreenScaleFactor);
|
2010-12-09 18:28:16 +08:00
|
|
|
set.addObject(pTouch);
|
|
|
|
m_pDelegate->touchesEnded(&set, NULL);
|
|
|
|
|
|
|
|
pTouch->release();
|
|
|
|
for (Int32 i = nIndex; i < MAX_TOUCHES; ++i)
|
|
|
|
{
|
|
|
|
if (i != (MAX_TOUCHES - 1))
|
|
|
|
{
|
|
|
|
s_pTouches[i] = s_pTouches[i + 1];
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
s_pTouches[i] = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2011-03-07 18:20:48 +08:00
|
|
|
Boolean CCEGLView::OnPenMove(EventType* pEvent)
|
2010-12-09 18:28:16 +08:00
|
|
|
{
|
|
|
|
do
|
|
|
|
{
|
2011-03-07 18:20:48 +08:00
|
|
|
CC_BREAK_IF(!m_pDelegate);
|
2010-12-09 18:28:16 +08:00
|
|
|
|
|
|
|
Int32 nCount = EvtGetPenMultiPointCount(pEvent);
|
2011-03-07 18:20:48 +08:00
|
|
|
CC_BREAK_IF(nCount <= 0 || nCount > MAX_TOUCHES);
|
2010-12-09 18:28:16 +08:00
|
|
|
|
2011-03-07 18:20:48 +08:00
|
|
|
CCSet set;
|
2010-12-09 18:28:16 +08:00
|
|
|
Int32 nPosX, nPosY;
|
|
|
|
for (Int32 i = 0; i < nCount; ++i)
|
|
|
|
{
|
|
|
|
CCTouch* pTouch = s_pTouches[i];
|
2011-03-07 18:20:48 +08:00
|
|
|
CC_BREAK_IF(!pTouch);
|
2010-12-09 18:28:16 +08:00
|
|
|
|
|
|
|
EvtGetPenMultiPointXY(pEvent, i, &nPosX, &nPosY);
|
2011-02-19 17:44:43 +08:00
|
|
|
pTouch->SetTouchInfo(0, (float) (nPosX - m_rcViewPort.X()) / m_fScreenScaleFactor,
|
|
|
|
(float) (nPosY - m_rcViewPort.Y()) / m_fScreenScaleFactor);
|
2010-12-09 18:28:16 +08:00
|
|
|
set.addObject(pTouch);
|
|
|
|
}
|
|
|
|
|
|
|
|
m_pDelegate->touchesMoved(&set, NULL);
|
|
|
|
} while (0);
|
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2011-03-07 18:20:48 +08:00
|
|
|
CCSize CCEGLView::getSize()
|
2010-07-28 10:26:06 +08:00
|
|
|
{
|
2011-03-07 18:20:48 +08:00
|
|
|
return CCSize((float)m_tSizeInPoints.Width(), (float)m_tSizeInPoints.Height());
|
2010-08-18 15:24:19 +08:00
|
|
|
}
|
|
|
|
|
2011-03-07 18:20:48 +08:00
|
|
|
CCRect CCEGLView::getFrame()
|
2010-08-18 15:24:19 +08:00
|
|
|
{
|
|
|
|
TRectangle rc;
|
|
|
|
GetClientBounds(&rc);
|
2011-03-07 18:20:48 +08:00
|
|
|
return (CCRect((float)rc.X(), (float)rc.Y(), (float)rc.Width(), (float)rc.Height()));
|
2010-07-28 10:26:06 +08:00
|
|
|
}
|
|
|
|
|
2011-03-07 18:20:48 +08:00
|
|
|
bool CCEGLView::isOpenGLReady()
|
2010-07-28 18:18:27 +08:00
|
|
|
{
|
2010-07-29 16:05:14 +08:00
|
|
|
return (NULL != m_pEGL);
|
2010-07-28 18:18:27 +08:00
|
|
|
}
|
2010-07-28 10:26:06 +08:00
|
|
|
|
2011-03-07 18:20:48 +08:00
|
|
|
void CCEGLView::release()
|
2010-07-28 18:18:27 +08:00
|
|
|
{
|
|
|
|
CloseWindow();
|
|
|
|
}
|
2010-07-28 10:26:06 +08:00
|
|
|
|
2011-03-07 18:20:48 +08:00
|
|
|
void CCEGLView::setTouchDelegate(EGLTouchDelegate * pDelegate)
|
2010-07-28 18:18:27 +08:00
|
|
|
{
|
|
|
|
m_pDelegate = pDelegate;
|
|
|
|
}
|
|
|
|
|
2011-03-07 18:20:48 +08:00
|
|
|
void CCEGLView::swapBuffers()
|
2010-07-28 18:18:27 +08:00
|
|
|
{
|
2010-07-29 16:05:14 +08:00
|
|
|
if (m_pEGL)
|
|
|
|
{
|
2010-08-06 11:14:22 +08:00
|
|
|
m_pEGL->swapBuffers();
|
2010-07-29 16:05:14 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-03-07 18:20:48 +08:00
|
|
|
bool CCEGLView::canSetContentScaleFactor()
|
2010-12-29 18:01:37 +08:00
|
|
|
{
|
|
|
|
// can scale content?
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2011-03-07 18:20:48 +08:00
|
|
|
void CCEGLView::setContentScaleFactor(float contentScaleFactor)
|
2010-12-29 18:01:37 +08:00
|
|
|
{
|
|
|
|
// if it supports scaling content, set it
|
2011-02-19 17:44:43 +08:00
|
|
|
m_fScreenScaleFactor = contentScaleFactor;
|
|
|
|
}
|
|
|
|
|
2011-03-07 18:20:48 +08:00
|
|
|
void CCEGLView::setViewPortInPoints(float x, float y, float w, float h)
|
2011-02-19 17:44:43 +08:00
|
|
|
{
|
|
|
|
if (m_pEGL)
|
|
|
|
{
|
|
|
|
float factor = m_fScreenScaleFactor / CC_CONTENT_SCALE_FACTOR();
|
|
|
|
glViewport((GLint)(x * factor) + m_rcViewPort.X(),
|
|
|
|
(GLint)(y * factor) + m_rcViewPort.Y(),
|
|
|
|
(GLint)(w * factor),
|
|
|
|
(GLint)(h * factor));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-05-05 18:17:50 +08:00
|
|
|
void CCEGLView::setIMEKeyboardState(bool bOpen)
|
|
|
|
{
|
|
|
|
if (bOpen)
|
|
|
|
{
|
|
|
|
m_nTextLen = 0;
|
|
|
|
TUChar tszEmpty[1] = {0};
|
|
|
|
m_pTextField->SetTitle(tszEmpty, FALSE);
|
|
|
|
m_pTextField->SetFocusStatus(TRUE);
|
|
|
|
ImeOpenIme(IME_MODE_STATIC, IME_CLASS_UNDEFINED);
|
|
|
|
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
ImeCloseIme();
|
|
|
|
m_pTextField->SetFocusStatus(FALSE);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-03-07 18:20:48 +08:00
|
|
|
CCEGLView& CCEGLView::sharedOpenGLView()
|
2011-02-19 17:44:43 +08:00
|
|
|
{
|
2011-03-07 18:20:48 +08:00
|
|
|
CC_ASSERT(s_pMainWindow);
|
2011-02-19 17:44:43 +08:00
|
|
|
return *s_pMainWindow;
|
2010-12-29 18:01:37 +08:00
|
|
|
}
|
|
|
|
|
2010-08-03 11:23:12 +08:00
|
|
|
} // end of namespace cocos2d
|