CCGLViewImpl.h 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  1. /****************************************************************************
  2. Copyright (c) 2010 cocos2d-x.org
  3. Copyright (c) Microsoft Open Technologies, Inc.
  4. http://www.cocos2d-x.org
  5. Permission is hereby granted, free of charge, to any person obtaining a copy
  6. of this software and associated documentation files (the "Software"), to deal
  7. in the Software without restriction, including without limitation the rights
  8. to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  9. copies of the Software, and to permit persons to whom the Software is
  10. furnished to do so, subject to the following conditions:
  11. The above copyright notice and this permission notice shall be included in
  12. all copies or substantial portions of the Software.
  13. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  14. IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  15. FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  16. AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  17. LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  18. OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  19. THE SOFTWARE.
  20. ****************************************************************************/
  21. #ifndef __CC_EGLVIEWIMPL_WINRT_H__
  22. #define __CC_EGLVIEWIMPL_WINRT_H__
  23. #include "platform/CCPlatformConfig.h"
  24. #if (CC_TARGET_PLATFORM == CC_PLATFORM_WINRT)
  25. #include "platform/winrt/CCStdC.h"
  26. #include "platform/winrt/CCGL.h"
  27. #include "platform/CCCommon.h"
  28. #include "platform/winrt/InputEvent.h"
  29. #include "platform/CCGLView.h"
  30. #include <wrl/client.h>
  31. #include <agile.h>
  32. #include <DirectXMath.h>
  33. #include <mutex>
  34. #include <queue>
  35. NS_CC_BEGIN
  36. class CCEGL;
  37. class GLViewImpl;
  38. ref class WinRTWindow sealed
  39. {
  40. public:
  41. WinRTWindow(Windows::UI::Core::CoreWindow^ window);
  42. void Initialize(Windows::UI::Core::CoreWindow^ window, Windows::UI::Xaml::Controls::SwapChainBackgroundPanel^ panel);
  43. void setIMEKeyboardState(bool bOpen);
  44. void swapBuffers();
  45. private:
  46. cocos2d::Vec2 GetCCPoint(Windows::UI::Core::PointerEventArgs^ args);
  47. void OnTextKeyDown(Object^ sender, Windows::UI::Xaml::Input::KeyRoutedEventArgs^ e);
  48. void OnTextKeyUp(Object^ sender, Windows::UI::Xaml::Input::KeyRoutedEventArgs^ e);
  49. void OnPointerWheelChanged(Windows::UI::Core::CoreWindow^, Windows::UI::Core::PointerEventArgs^ args);
  50. void OnPointerMoved(Windows::UI::Core::CoreWindow^, Windows::UI::Core::PointerEventArgs^ args);
  51. void OnPointerPressed(Windows::UI::Core::CoreWindow^ sender, Windows::UI::Core::PointerEventArgs^ args);
  52. void OnPointerReleased(Windows::UI::Core::CoreWindow^ sender, Windows::UI::Core::PointerEventArgs^ args);
  53. void OnWindowSizeChanged(Windows::UI::Core::CoreWindow^ sender, Windows::UI::Core::WindowSizeChangedEventArgs^ args);
  54. void OnLogicalDpiChanged(Platform::Object^ sender);
  55. void OnOrientationChanged(Platform::Object^ sender);
  56. void OnDisplayContentsInvalidated(Platform::Object^ sender);
  57. void OnRendering(Platform::Object^ sender, Platform::Object^ args);
  58. void OnSuspending();
  59. void ResizeWindow();
  60. void ShowKeyboard(Windows::UI::ViewManagement::InputPane^ inputPane, Windows::UI::ViewManagement::InputPaneVisibilityEventArgs^ args);
  61. void HideKeyboard(Windows::UI::ViewManagement::InputPane^ inputPane, Windows::UI::ViewManagement::InputPaneVisibilityEventArgs^ args);
  62. Platform::Agile<Windows::UI::Core::CoreWindow> m_window;
  63. Windows::Foundation::Point m_lastPoint;
  64. Windows::Foundation::EventRegistrationToken m_eventToken;
  65. bool m_lastPointValid;
  66. bool m_textInputEnabled;
  67. Microsoft::WRL::ComPtr<IWinrtEglWindow> m_eglWindow;
  68. Windows::UI::Xaml::Controls::TextBox^ m_textBox;
  69. Windows::UI::Xaml::Controls::Button^ m_dummy;
  70. ESContext m_esContext;
  71. friend GLViewImpl;
  72. };
  73. class CC_DLL GLViewImpl : public GLView
  74. {
  75. public:
  76. GLViewImpl();
  77. virtual ~GLViewImpl();
  78. /* override functions */
  79. virtual bool isOpenGLReady();
  80. virtual void end();
  81. virtual void swapBuffers();
  82. virtual void setFrameSize(float width, float height);
  83. virtual void setIMEKeyboardState(bool bOpen);
  84. void ShowKeyboard(Windows::Foundation::Rect r);
  85. void HideKeyboard(Windows::Foundation::Rect r);
  86. virtual bool Create(Windows::UI::Core::CoreWindow^ window, Windows::UI::Xaml::Controls::SwapChainBackgroundPanel^ panel);
  87. void UpdateForWindowSizeChange();
  88. void OnRendering();
  89. void OnSuspending();
  90. void GLViewImpl::QueueEvent(std::shared_ptr<InputEvent>& event);
  91. void OnPointerPressed(Windows::UI::Core::PointerEventArgs^ args);
  92. void OnPointerMoved(Windows::UI::Core::PointerEventArgs^ args);
  93. void OnPointerReleased(Windows::UI::Core::PointerEventArgs^ args);
  94. void OnPointerPressed(Windows::UI::Core::CoreWindow^ sender, Windows::UI::Core::PointerEventArgs^ args);
  95. void OnBackKeyPress();
  96. private:
  97. Windows::Foundation::EventRegistrationToken m_eventToken;
  98. Windows::Foundation::Point m_lastPoint;
  99. bool m_lastPointValid;
  100. public:
  101. // winrt platform functions
  102. Windows::UI::Core::CoreWindow^ getWindow() { return m_window.Get(); };
  103. int Run();
  104. void resize(int width, int height);
  105. /*
  106. * Set zoom factor for frame. This method is for debugging big resolution (e.g.new ipad) app on desktop.
  107. */
  108. void setFrameZoomFactor(float fZoomFactor);
  109. float getFrameZoomFactor();
  110. void centerWindow();
  111. // static function
  112. /**
  113. @brief get the shared main open gl window
  114. */
  115. static GLViewImpl* sharedOpenGLView();
  116. protected:
  117. private:
  118. Platform::Agile<Windows::UI::Core::CoreWindow> m_window;
  119. bool m_running;
  120. bool m_initialized;
  121. bool m_bSupportTouch;
  122. float m_fFrameZoomFactor;
  123. WinRTWindow^ m_winRTWindow;
  124. Windows::Foundation::Rect m_keyboardRect;
  125. std::queue<std::shared_ptr<InputEvent>> mInputEvents;
  126. std::mutex mMutex;
  127. };
  128. NS_CC_END
  129. #endif // (CC_TARGET_PLATFORM == CC_PLATFORM_WINRT)
  130. #endif // end of __CC_EGLVIEWIMPL_WINRT_H__