2010-08-03 11:23:12 +08:00
|
|
|
#include "CCXApplication_uphone.h"
|
|
|
|
|
|
|
|
#include "CCDirector.h"
|
|
|
|
|
2010-08-31 16:53:25 +08:00
|
|
|
// #include "CCXGLExtFunc.h"
|
|
|
|
#include <GLES/glext.h>
|
2010-08-16 12:29:06 +08:00
|
|
|
|
2010-08-03 11:23:12 +08:00
|
|
|
namespace cocos2d {
|
|
|
|
|
|
|
|
static const Int32 CCX_ON_APPLICATION_IDLE = (EVENT_FirstUser + EVENT_LastUser) / 2;
|
|
|
|
|
|
|
|
static Int32 _OnAppIdle(MESSAGE_t * pMsg, UInt32 uData)
|
|
|
|
{
|
2010-08-09 13:57:33 +08:00
|
|
|
//CCDirector::getSharedDirector()->preMainLoop();
|
|
|
|
CCXEGLView * pView = CCDirector::getSharedDirector()->getOpenGLView();
|
|
|
|
if (pView)
|
|
|
|
{
|
|
|
|
pView->UpdateWindow(0);
|
|
|
|
}
|
2010-08-03 11:23:12 +08:00
|
|
|
int nRtn = Sys_PostMessage2(MESSAGE_PRIOR_LOWEST, (MESSAGE_t *)uData);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
CCXApplication::CCXApplication()
|
|
|
|
{
|
2010-09-08 14:11:24 +08:00
|
|
|
memset(&m_tMsg, 0, sizeof(m_tMsg));
|
|
|
|
SS_GetCurrentGTID(&m_tMsg.gtid);
|
|
|
|
m_tMsg.type = CCX_ON_APPLICATION_IDLE;
|
2010-08-03 11:23:12 +08:00
|
|
|
|
2010-09-08 14:11:24 +08:00
|
|
|
Sys_RegisterMessageCallBack(CCX_ON_APPLICATION_IDLE, _OnAppIdle, (UInt32)&m_tMsg);
|
2010-08-03 11:23:12 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
CCXApplication::~CCXApplication()
|
|
|
|
{
|
|
|
|
Sys_RegisterMessageCallBack(CCX_ON_APPLICATION_IDLE, NULL, NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
Boolean CCXApplication::EventHandler(EventType * pEvent)
|
|
|
|
{
|
|
|
|
Boolean bHandled = FALSE;
|
|
|
|
switch (pEvent->eType)
|
|
|
|
{
|
|
|
|
case EVENT_AppLoad:
|
2010-09-08 14:11:24 +08:00
|
|
|
if (! initCocos2d())
|
|
|
|
{
|
|
|
|
SendStopEvent();
|
|
|
|
}
|
|
|
|
bHandled = Sys_PostMessage2(MESSAGE_PRIOR_LOWEST, &m_tMsg);
|
2010-08-03 11:23:12 +08:00
|
|
|
bHandled = TRUE;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case EVENT_AppStopNotify:
|
|
|
|
|
2010-09-25 11:54:33 +08:00
|
|
|
break;
|
|
|
|
case EVENT_AppActiveNotify:
|
|
|
|
if (pEvent->sParam1 == 0)
|
|
|
|
{
|
2010-10-13 16:21:59 +08:00
|
|
|
applicationDidEnterBackground();
|
2010-09-25 11:54:33 +08:00
|
|
|
}
|
|
|
|
else if (pEvent->sParam1 > 0)
|
|
|
|
{
|
2010-10-13 16:21:59 +08:00
|
|
|
applicationWillEnterForeground();
|
2010-09-25 11:54:33 +08:00
|
|
|
}
|
2010-08-03 11:23:12 +08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (! bHandled)
|
|
|
|
{
|
|
|
|
bHandled = TApplication::EventHandler(pEvent);
|
|
|
|
}
|
|
|
|
return bHandled;
|
|
|
|
}
|
2010-08-05 10:29:29 +08:00
|
|
|
|
|
|
|
void CCXApplication::setDeviceOrientation(int nOritation)
|
|
|
|
{
|
|
|
|
TWindow * pWnd = TApplication::GetCurrentWindow();
|
|
|
|
if (! pWnd)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
switch (nOritation)
|
|
|
|
{
|
|
|
|
/// Device oriented vertically, home button on the bottom
|
|
|
|
case kCCDeviceOrientationPortrait:
|
|
|
|
pWnd->RotateWindow(WM_WINDOW_ROTATE_MODE_NORMAL);
|
|
|
|
break;
|
|
|
|
/// Device oriented vertically, home button on the top
|
|
|
|
case kCCDeviceOrientationPortraitUpsideDown:
|
|
|
|
pWnd->RotateWindow(WM_WINDOW_ROTATE_MODE_UD);
|
|
|
|
break;
|
|
|
|
|
|
|
|
/// Device oriented horizontally, home button on the right
|
|
|
|
case kCCDeviceOrientationLandscapeLeft:
|
|
|
|
pWnd->RotateWindow(WM_WINDOW_ROTATE_MODE_CW);
|
|
|
|
break;
|
|
|
|
/// Device oriented horizontally, home button on the left
|
|
|
|
case kCCDeviceOrientationLandscapeRight:
|
|
|
|
pWnd->RotateWindow(WM_WINDOW_ROTATE_MODE_CCW);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2010-08-10 12:03:05 +08:00
|
|
|
|
|
|
|
CGRect CCXApplication::statusBarFrame()
|
|
|
|
{
|
|
|
|
CGRect rc;
|
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
2010-08-05 10:29:29 +08:00
|
|
|
//////////////////////////////////////////////////////////////////////////
|
|
|
|
/// Implement static class member
|
|
|
|
//////////////////////////////////////////////////////////////////////////
|
|
|
|
CCXApplication * CCXApplication::getSharedApplication()
|
|
|
|
{
|
|
|
|
return (CCXApplication *)TApplication::GetCurrentApplication();
|
|
|
|
}
|
2010-08-10 12:03:05 +08:00
|
|
|
|
2010-08-03 11:23:12 +08:00
|
|
|
}
|