Second half of commit for adding Accelerometer simulation to Win32.

This commit is contained in:
Wartortle 2012-02-06 11:38:53 +00:00
parent ffc4457991
commit aa06de2fb3
6 changed files with 48 additions and 4 deletions

View File

@ -25,6 +25,8 @@ THE SOFTWARE.
#ifndef __PLATFORM_WIN32_UIACCELEROMETER_H__ #ifndef __PLATFORM_WIN32_UIACCELEROMETER_H__
#define __PLATFORM_WIN32_UIACCELEROMETER_H__ #define __PLATFORM_WIN32_UIACCELEROMETER_H__
#include "CCAccelerometerDelegate.h"
namespace cocos2d { namespace cocos2d {
class CC_DLL CCAccelerometer class CC_DLL CCAccelerometer
@ -33,8 +35,13 @@ public:
CCAccelerometer(); CCAccelerometer();
~CCAccelerometer(); ~CCAccelerometer();
static CCAccelerometer* sharedAccelerometer() { return NULL; } static CCAccelerometer* sharedAccelerometer();
void setDelegate(CCAccelerometerDelegate* pDelegate) {CC_UNUSED_PARAM(pDelegate);} void setDelegate(CCAccelerometerDelegate* pDelegate);
void update( double x,double y,double z,double timestamp );
private:
static CCAccelerometer* m_spCCAccelerometer;
CCAccelerometerDelegate* m_pAccelDelegate;
CCAcceleration m_obAccelerationValue;
}; };
}//namespace cocos2d }//namespace cocos2d

View File

@ -191,6 +191,7 @@ CCEGLView::CCEGLView()
, m_hWnd(NULL) , m_hWnd(NULL)
, m_eInitOrientation(CCDeviceOrientationPortrait) , m_eInitOrientation(CCDeviceOrientationPortrait)
, m_fScreenScaleFactor(1.0f) , m_fScreenScaleFactor(1.0f)
, m_lpfnAccelerometerKeyHook(NULL)
{ {
m_pTouch = new CCTouch; m_pTouch = new CCTouch;
m_pSet = new CCSet; m_pSet = new CCSet;
@ -329,6 +330,16 @@ LRESULT CCEGLView::WindowProc(UINT message, WPARAM wParam, LPARAM lParam)
if (GetKeyState(VK_LSHIFT) < 0 || GetKeyState(VK_RSHIFT) < 0 || GetKeyState(VK_SHIFT) < 0) if (GetKeyState(VK_LSHIFT) < 0 || GetKeyState(VK_RSHIFT) < 0 || GetKeyState(VK_SHIFT) < 0)
CCKeypadDispatcher::sharedDispatcher()->dispatchKeypadMSG(wParam == VK_F1 ? kTypeBackClicked : kTypeMenuClicked); CCKeypadDispatcher::sharedDispatcher()->dispatchKeypadMSG(wParam == VK_F1 ? kTypeBackClicked : kTypeMenuClicked);
} }
if ( m_lpfnAccelerometerKeyHook!=NULL )
{
(*m_lpfnAccelerometerKeyHook)( message,wParam,lParam );
}
break;
case WM_KEYUP:
if ( m_lpfnAccelerometerKeyHook!=NULL )
{
(*m_lpfnAccelerometerKeyHook)( message,wParam,lParam );
}
break; break;
case WM_CHAR: case WM_CHAR:
{ {
@ -364,6 +375,10 @@ LRESULT CCEGLView::WindowProc(UINT message, WPARAM wParam, LPARAM lParam)
CCIMEDispatcher::sharedDispatcher()->dispatchInsertText(szUtf8, nLen); CCIMEDispatcher::sharedDispatcher()->dispatchInsertText(szUtf8, nLen);
} }
if ( m_lpfnAccelerometerKeyHook!=NULL )
{
(*m_lpfnAccelerometerKeyHook)( message,wParam,lParam );
}
} }
break; break;
@ -386,6 +401,11 @@ LRESULT CCEGLView::WindowProc(UINT message, WPARAM wParam, LPARAM lParam)
return 0; return 0;
} }
void CCEGLView::setAccelerometerKeyHook( LPFN_ACCELEROMETER_KEYHOOK lpfnAccelerometerKeyHook )
{
m_lpfnAccelerometerKeyHook=lpfnAccelerometerKeyHook;
}
CCSize CCEGLView::getSize() CCSize CCEGLView::getSize()
{ {
if (m_bOrientationReverted) if (m_bOrientationReverted)

View File

@ -67,6 +67,8 @@ public:
void resize(int width, int height); void resize(int width, int height);
void centerWindow(); void centerWindow();
void setScreenScale(float factor); void setScreenScale(float factor);
typedef void (*LPFN_ACCELEROMETER_KEYHOOK)( UINT message,WPARAM wParam, LPARAM lParam );
void setAccelerometerKeyHook( LPFN_ACCELEROMETER_KEYHOOK lpfnAccelerometerKeyHook );
// static function // static function
@ -94,6 +96,7 @@ private:
SIZE m_tSizeInPoints; SIZE m_tSizeInPoints;
float m_fScreenScaleFactor; float m_fScreenScaleFactor;
RECT m_rcViewPort; RECT m_rcViewPort;
LPFN_ACCELEROMETER_KEYHOOK m_lpfnAccelerometerKeyHook;
}; };
NS_CC_END; NS_CC_END;

View File

@ -834,6 +834,10 @@
<Filter <Filter
Name="win32" Name="win32"
> >
<File
RelativePath="..\platform\win32\CCAccelerometer_win32.cpp"
>
</File>
<File <File
RelativePath="..\platform\win32\CCAccelerometer_win32.h" RelativePath="..\platform\win32\CCAccelerometer_win32.h"
> >

View File

@ -1151,6 +1151,18 @@
> >
</File> </File>
</Filter> </Filter>
<Filter
Name="AccelerometerTest"
>
<File
RelativePath="..\tests\AccelerometerTest\AccelerometerTest.cpp"
>
</File>
<File
RelativePath="..\tests\AccelerometerTest\AccelerometerTest.h"
>
</File>
</Filter>
</Filter> </Filter>
</Filter> </Filter>
</Files> </Files>

View File

@ -83,10 +83,8 @@ static TestScene* CreateTestScene(int nIdx)
pScene = new EffectAdvanceScene(); break; pScene = new EffectAdvanceScene(); break;
case TEST_HIRES: case TEST_HIRES:
pScene = new HiResTestScene(); break; pScene = new HiResTestScene(); break;
#if (CC_TARGET_PLATFORM != CC_PLATFORM_WIN32)
case TEST_ACCELEROMRTER: case TEST_ACCELEROMRTER:
pScene = new AccelerometerTestScene(); break; pScene = new AccelerometerTestScene(); break;
#endif
#if (CC_TARGET_PLATFORM != CC_PLATFORM_BADA) #if (CC_TARGET_PLATFORM != CC_PLATFORM_BADA)
case TEST_KEYPAD: case TEST_KEYPAD:
pScene = new KeypadTestScene(); break; pScene = new KeypadTestScene(); break;