2011-03-07 17:11:57 +08:00
|
|
|
#include "CCApplication.h"
|
2011-01-22 16:27:08 +08:00
|
|
|
|
|
|
|
#include "CCDirector.h"
|
2011-06-17 10:49:02 +08:00
|
|
|
#include <map>
|
2011-03-09 10:39:08 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
@brief This function change the PVRFrame show/hide setting in register.
|
|
|
|
@param bEnable If true show the PVRFrame window, otherwise hide.
|
|
|
|
*/
|
|
|
|
static void PVRFrameEnableControlWindow(bool bEnable);
|
2011-01-22 16:27:08 +08:00
|
|
|
|
2011-03-01 12:41:57 +08:00
|
|
|
NS_CC_BEGIN;
|
|
|
|
|
|
|
|
// sharedApplication pointer
|
2011-03-07 17:11:57 +08:00
|
|
|
CCApplication * CCApplication::sm_pSharedApplication = 0;
|
2011-03-01 12:41:57 +08:00
|
|
|
|
2011-03-07 17:11:57 +08:00
|
|
|
CCApplication::CCApplication()
|
2011-01-22 16:27:08 +08:00
|
|
|
: m_hInstance(NULL)
|
|
|
|
, m_hAccelTable(NULL)
|
|
|
|
{
|
|
|
|
m_hInstance = GetModuleHandle(NULL);
|
|
|
|
m_nAnimationInterval.QuadPart = 0;
|
2011-03-07 17:11:57 +08:00
|
|
|
CC_ASSERT(! sm_pSharedApplication);
|
2011-03-01 12:41:57 +08:00
|
|
|
sm_pSharedApplication = this;
|
2011-01-22 16:27:08 +08:00
|
|
|
}
|
|
|
|
|
2011-03-07 17:11:57 +08:00
|
|
|
CCApplication::~CCApplication()
|
2011-01-22 16:27:08 +08:00
|
|
|
{
|
2011-03-07 17:11:57 +08:00
|
|
|
CC_ASSERT(this == sm_pSharedApplication);
|
2011-03-01 12:41:57 +08:00
|
|
|
sm_pSharedApplication = NULL;
|
2011-01-22 16:27:08 +08:00
|
|
|
}
|
|
|
|
|
2011-03-07 17:11:57 +08:00
|
|
|
int CCApplication::run()
|
2011-01-22 16:27:08 +08:00
|
|
|
{
|
2011-03-09 10:39:08 +08:00
|
|
|
PVRFrameEnableControlWindow(false);
|
|
|
|
|
2011-01-22 16:27:08 +08:00
|
|
|
// Main message loop:
|
|
|
|
MSG msg;
|
|
|
|
LARGE_INTEGER nFreq;
|
|
|
|
LARGE_INTEGER nLast;
|
|
|
|
LARGE_INTEGER nNow;
|
|
|
|
|
|
|
|
QueryPerformanceFrequency(&nFreq);
|
|
|
|
QueryPerformanceCounter(&nLast);
|
|
|
|
|
2011-03-01 12:41:57 +08:00
|
|
|
// Initialize instance and cocos2d.
|
|
|
|
if (! initInstance() || ! applicationDidFinishLaunching())
|
2011-01-22 16:27:08 +08:00
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2011-03-07 17:11:57 +08:00
|
|
|
CCEGLView& mainWnd = CCEGLView::sharedOpenGLView();
|
2011-03-01 12:41:57 +08:00
|
|
|
mainWnd.centerWindow();
|
|
|
|
ShowWindow(mainWnd.getHWnd(), SW_SHOW);
|
2011-02-18 18:30:22 +08:00
|
|
|
|
2011-01-22 16:27:08 +08:00
|
|
|
while (1)
|
|
|
|
{
|
|
|
|
if (! PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
|
|
|
|
{
|
|
|
|
// Get current time tick.
|
|
|
|
QueryPerformanceCounter(&nNow);
|
|
|
|
|
|
|
|
// If it's the time to draw next frame, draw it, else sleep a while.
|
|
|
|
if (nNow.QuadPart - nLast.QuadPart > m_nAnimationInterval.QuadPart)
|
|
|
|
{
|
|
|
|
nLast.QuadPart = nNow.QuadPart;
|
|
|
|
CCDirector::sharedDirector()->mainLoop();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
Sleep(0);
|
|
|
|
}
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (WM_QUIT == msg.message)
|
|
|
|
{
|
|
|
|
// Quit message loop.
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Deal with windows message.
|
|
|
|
if (! m_hAccelTable || ! TranslateAccelerator(msg.hwnd, m_hAccelTable, &msg))
|
|
|
|
{
|
|
|
|
TranslateMessage(&msg);
|
|
|
|
DispatchMessage(&msg);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-03-01 12:41:57 +08:00
|
|
|
return (int) msg.wParam;
|
2011-02-18 18:30:22 +08:00
|
|
|
}
|
|
|
|
|
2011-03-07 17:11:57 +08:00
|
|
|
void CCApplication::setAnimationInterval(double interval)
|
2011-01-22 16:27:08 +08:00
|
|
|
{
|
|
|
|
LARGE_INTEGER nFreq;
|
|
|
|
QueryPerformanceFrequency(&nFreq);
|
|
|
|
m_nAnimationInterval.QuadPart = (LONGLONG)(interval * nFreq.QuadPart);
|
|
|
|
}
|
|
|
|
|
2011-03-07 17:11:57 +08:00
|
|
|
CCApplication::Orientation CCApplication::setOrientation(Orientation orientation)
|
2011-01-22 16:27:08 +08:00
|
|
|
{
|
2011-01-22 17:30:00 +08:00
|
|
|
// swap width and height
|
2011-03-07 17:11:57 +08:00
|
|
|
CCEGLView * pView = CCDirector::sharedDirector()->getOpenGLView();
|
2011-01-22 17:30:00 +08:00
|
|
|
if (pView)
|
|
|
|
{
|
|
|
|
return (Orientation)pView->setDeviceOrientation(orientation);
|
|
|
|
}
|
|
|
|
return (Orientation)CCDirector::sharedDirector()->getDeviceOrientation();
|
2011-01-22 16:27:08 +08:00
|
|
|
}
|
|
|
|
|
2011-03-07 17:11:57 +08:00
|
|
|
void CCApplication::statusBarFrame(CCRect * rect)
|
2011-01-22 16:27:08 +08:00
|
|
|
{
|
|
|
|
if (rect)
|
|
|
|
{
|
|
|
|
// Windows doesn't have status bar.
|
2011-03-07 17:11:57 +08:00
|
|
|
*rect = CCRectMake(0, 0, 0, 0);
|
2011-01-22 16:27:08 +08:00
|
|
|
}
|
|
|
|
}
|
2011-03-01 12:41:57 +08:00
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////
|
|
|
|
// static member function
|
|
|
|
//////////////////////////////////////////////////////////////////////////
|
2011-03-07 17:11:57 +08:00
|
|
|
CCApplication& CCApplication::sharedApplication()
|
2011-03-01 12:41:57 +08:00
|
|
|
{
|
2011-03-07 17:11:57 +08:00
|
|
|
CC_ASSERT(sm_pSharedApplication);
|
2011-03-01 12:41:57 +08:00
|
|
|
return *sm_pSharedApplication;
|
|
|
|
}
|
|
|
|
|
2011-06-17 10:49:02 +08:00
|
|
|
static std::map<LCID, ccLanguageType>::value_type s_MapValues[] =
|
|
|
|
{
|
|
|
|
std::map<LCID, ccLanguageType>::value_type(2052, kLanguageChinese),
|
|
|
|
std::map<LCID, ccLanguageType>::value_type(4100, kLanguageChinese),
|
|
|
|
std::map<LCID, ccLanguageType>::value_type(1028, kLanguageChinese),
|
|
|
|
std::map<LCID, ccLanguageType>::value_type(3076, kLanguageChinese),
|
|
|
|
std::map<LCID, ccLanguageType>::value_type(5124, kLanguageChinese),
|
|
|
|
};
|
|
|
|
static std::map<LCID, ccLanguageType> s_LanguageMap(s_MapValues, s_MapValues + 5);
|
|
|
|
|
|
|
|
ccLanguageType CCApplication::getCurrentLanguage()
|
|
|
|
{
|
|
|
|
LCID LanguageID = GetUserDefaultLCID();
|
|
|
|
ccLanguageType ret = kLanguageEnglish;
|
|
|
|
|
|
|
|
std::map<LCID, ccLanguageType>::iterator it = s_LanguageMap.find(LanguageID);
|
|
|
|
if (it != s_LanguageMap.end())
|
|
|
|
{
|
|
|
|
ret = it->second;
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2011-03-01 12:41:57 +08:00
|
|
|
NS_CC_END;
|
2011-03-09 10:39:08 +08:00
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////
|
|
|
|
// Local function
|
|
|
|
//////////////////////////////////////////////////////////////////////////
|
|
|
|
static void PVRFrameEnableControlWindow(bool bEnable)
|
|
|
|
{
|
|
|
|
HKEY hKey = 0;
|
|
|
|
|
|
|
|
// Open PVRFrame control key, if not exist create it.
|
|
|
|
if(ERROR_SUCCESS != RegCreateKeyExW(HKEY_CURRENT_USER,
|
|
|
|
L"Software\\Imagination Technologies\\PVRVFRame\\STARTUP\\",
|
|
|
|
0,
|
|
|
|
0,
|
|
|
|
REG_OPTION_NON_VOLATILE,
|
|
|
|
KEY_ALL_ACCESS,
|
|
|
|
0,
|
|
|
|
&hKey,
|
|
|
|
NULL))
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
const wchar_t * wszValue = L"hide_gui";
|
|
|
|
const wchar_t * wszNewData = (bEnable) ? L"NO" : L"YES";
|
|
|
|
wchar_t wszOldData[256] = {0};
|
|
|
|
DWORD dwSize = sizeof(wszOldData);
|
|
|
|
LSTATUS status = RegQueryValueExW(hKey, wszValue, 0, NULL, (LPBYTE)wszOldData, &dwSize);
|
|
|
|
if (ERROR_FILE_NOT_FOUND == status // the key not exist
|
|
|
|
|| (ERROR_SUCCESS == status // or the hide_gui value is exist
|
|
|
|
&& 0 != wcscmp(wszNewData, wszOldData))) // but new data and old data not equal
|
|
|
|
{
|
|
|
|
dwSize = sizeof(wchar_t) * (wcslen(wszNewData) + 1);
|
|
|
|
RegSetValueEx(hKey, wszValue, 0, REG_SZ, (const BYTE *)wszNewData, dwSize);
|
|
|
|
}
|
|
|
|
|
|
|
|
RegCloseKey(hKey);
|
|
|
|
}
|