diff --git a/cocos2dx/platform/win32/CCAccelerometer_win32.h b/cocos2dx/platform/win32/CCAccelerometer_win32.h index ddcc125f27..002fa90d49 100644 --- a/cocos2dx/platform/win32/CCAccelerometer_win32.h +++ b/cocos2dx/platform/win32/CCAccelerometer_win32.h @@ -25,6 +25,8 @@ THE SOFTWARE. #ifndef __PLATFORM_WIN32_UIACCELEROMETER_H__ #define __PLATFORM_WIN32_UIACCELEROMETER_H__ +#include "CCAccelerometerDelegate.h" + namespace cocos2d { class CC_DLL CCAccelerometer @@ -33,8 +35,13 @@ public: CCAccelerometer(); ~CCAccelerometer(); - static CCAccelerometer* sharedAccelerometer() { return NULL; } - void setDelegate(CCAccelerometerDelegate* pDelegate) {CC_UNUSED_PARAM(pDelegate);} + static CCAccelerometer* sharedAccelerometer(); + 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 diff --git a/cocos2dx/platform/win32/CCEGLView_win32.cpp b/cocos2dx/platform/win32/CCEGLView_win32.cpp index 1aa8c38d4d..8fabb1bca2 100644 --- a/cocos2dx/platform/win32/CCEGLView_win32.cpp +++ b/cocos2dx/platform/win32/CCEGLView_win32.cpp @@ -191,6 +191,7 @@ CCEGLView::CCEGLView() , m_hWnd(NULL) , m_eInitOrientation(CCDeviceOrientationPortrait) , m_fScreenScaleFactor(1.0f) +, m_lpfnAccelerometerKeyHook(NULL) { m_pTouch = new CCTouch; 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) 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; case WM_CHAR: { @@ -364,6 +375,10 @@ LRESULT CCEGLView::WindowProc(UINT message, WPARAM wParam, LPARAM lParam) CCIMEDispatcher::sharedDispatcher()->dispatchInsertText(szUtf8, nLen); } + if ( m_lpfnAccelerometerKeyHook!=NULL ) + { + (*m_lpfnAccelerometerKeyHook)( message,wParam,lParam ); + } } break; @@ -386,6 +401,11 @@ LRESULT CCEGLView::WindowProc(UINT message, WPARAM wParam, LPARAM lParam) return 0; } +void CCEGLView::setAccelerometerKeyHook( LPFN_ACCELEROMETER_KEYHOOK lpfnAccelerometerKeyHook ) +{ + m_lpfnAccelerometerKeyHook=lpfnAccelerometerKeyHook; +} + CCSize CCEGLView::getSize() { if (m_bOrientationReverted) diff --git a/cocos2dx/platform/win32/CCEGLView_win32.h b/cocos2dx/platform/win32/CCEGLView_win32.h index c3ca1e5e29..384522fa4f 100644 --- a/cocos2dx/platform/win32/CCEGLView_win32.h +++ b/cocos2dx/platform/win32/CCEGLView_win32.h @@ -67,6 +67,8 @@ public: void resize(int width, int height); void centerWindow(); void setScreenScale(float factor); + typedef void (*LPFN_ACCELEROMETER_KEYHOOK)( UINT message,WPARAM wParam, LPARAM lParam ); + void setAccelerometerKeyHook( LPFN_ACCELEROMETER_KEYHOOK lpfnAccelerometerKeyHook ); // static function @@ -94,6 +96,7 @@ private: SIZE m_tSizeInPoints; float m_fScreenScaleFactor; RECT m_rcViewPort; + LPFN_ACCELEROMETER_KEYHOOK m_lpfnAccelerometerKeyHook; }; NS_CC_END; diff --git a/cocos2dx/proj.win32/cocos2d-win32.vcproj b/cocos2dx/proj.win32/cocos2d-win32.vcproj index 419d3d9b91..93bdcdf6c8 100644 --- a/cocos2dx/proj.win32/cocos2d-win32.vcproj +++ b/cocos2dx/proj.win32/cocos2d-win32.vcproj @@ -834,6 +834,10 @@ + + diff --git a/tests/test.win32/test.win32.vcproj b/tests/test.win32/test.win32.vcproj index 695b575624..f2cd9837b3 100644 --- a/tests/test.win32/test.win32.vcproj +++ b/tests/test.win32/test.win32.vcproj @@ -1151,6 +1151,18 @@ > + + + + + + diff --git a/tests/tests/controller.cpp b/tests/tests/controller.cpp index 21fdea3833..c97b955737 100644 --- a/tests/tests/controller.cpp +++ b/tests/tests/controller.cpp @@ -83,10 +83,8 @@ static TestScene* CreateTestScene(int nIdx) pScene = new EffectAdvanceScene(); break; case TEST_HIRES: pScene = new HiResTestScene(); break; -#if (CC_TARGET_PLATFORM != CC_PLATFORM_WIN32) case TEST_ACCELEROMRTER: pScene = new AccelerometerTestScene(); break; -#endif #if (CC_TARGET_PLATFORM != CC_PLATFORM_BADA) case TEST_KEYPAD: pScene = new KeypadTestScene(); break;