CCGLViewImpl-winrt.cpp 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642
  1. /****************************************************************************
  2. Copyright (c) 2013 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. #include "platform/winrt/CCGLViewImpl-winrt.h"
  22. #include "base/ccMacros.h"
  23. #include "base/CCDirector.h"
  24. #include "base/CCTouch.h"
  25. #include "base/CCIMEDispatcher.h"
  26. #include "base/CCEventListenerKeyboard.h"
  27. #include "platform/winrt/CCApplication.h"
  28. #include "platform/winrt/CCWinRTUtils.h"
  29. #include "deprecated/CCNotificationCenter.h"
  30. #include "base/CCEventDispatcher.h"
  31. #include "base/CCEventMouse.h"
  32. #include <map>
  33. using namespace Platform;
  34. using namespace Concurrency;
  35. using namespace Windows::System;
  36. using namespace Windows::Foundation;
  37. using namespace Windows::Foundation::Collections;
  38. using namespace Windows::Graphics::Display;
  39. using namespace Windows::UI::Input;
  40. using namespace Windows::UI::Core;
  41. using namespace Windows::UI::Xaml;
  42. using namespace Windows::UI::Xaml::Controls;
  43. using namespace Windows::UI::Xaml::Media;
  44. using namespace Windows::UI::Xaml::Input;
  45. using namespace Windows::System;
  46. using namespace Windows::UI::ViewManagement;
  47. using namespace Windows::ApplicationModel;
  48. using namespace Windows::ApplicationModel::Core;
  49. using namespace Windows::ApplicationModel::Activation;
  50. using namespace Platform;
  51. using namespace Microsoft::WRL;
  52. NS_CC_BEGIN
  53. static GLViewImpl* s_pEglView = nullptr;
  54. GLViewImpl* GLViewImpl::create(const std::string& viewName)
  55. {
  56. auto ret = new GLViewImpl;
  57. if(ret && ret->initWithFullScreen(viewName))
  58. {
  59. ret->autorelease();
  60. return ret;
  61. }
  62. return nullptr;
  63. }
  64. GLViewImpl::GLViewImpl()
  65. : _frameZoomFactor(1.0f)
  66. , _supportTouch(true)
  67. , _isRetina(false)
  68. , _isCursorVisible(true)
  69. , m_lastPointValid(false)
  70. , m_running(false)
  71. , m_initialized(false)
  72. , m_windowClosed(false)
  73. , m_windowVisible(true)
  74. , m_width(0)
  75. , m_height(0)
  76. , m_orientation(DisplayOrientations::Landscape)
  77. , m_appShouldExit(false)
  78. , _lastMouseButtonPressed(EventMouse::MouseButton::BUTTON_UNSET)
  79. {
  80. s_pEglView = this;
  81. _viewName = "cocos2dx";
  82. m_keyboard = ref new KeyBoardWinRT();
  83. m_backButtonListener = EventListenerKeyboard::create();
  84. m_backButtonListener->onKeyReleased = CC_CALLBACK_2(GLViewImpl::BackButtonListener, this);
  85. Director::getInstance()->getEventDispatcher()->addEventListenerWithFixedPriority(m_backButtonListener, INT_MAX);
  86. }
  87. GLViewImpl::~GLViewImpl()
  88. {
  89. CC_ASSERT(this == s_pEglView);
  90. s_pEglView = nullptr;
  91. // TODO: cleanup
  92. }
  93. bool GLViewImpl::initWithRect(const std::string& viewName, Rect rect, float frameZoomFactor)
  94. {
  95. setViewName(viewName);
  96. setFrameSize(rect.size.width, rect.size.height);
  97. setFrameZoomFactor(frameZoomFactor);
  98. return true;
  99. }
  100. bool GLViewImpl::initWithFullScreen(const std::string& viewName)
  101. {
  102. return initWithRect(viewName, Rect(0, 0, m_width, m_height), 1.0f);
  103. }
  104. bool GLViewImpl::Create(float width, float height, float dpi, DisplayOrientations orientation)
  105. {
  106. m_orientation = orientation;
  107. m_dpi = dpi;
  108. UpdateForWindowSizeChange(width, height);
  109. return true;
  110. }
  111. void cocos2d::GLViewImpl::setCursorVisible(bool isVisible)
  112. {
  113. _isCursorVisible = isVisible;
  114. }
  115. void GLViewImpl::setDispatcher(Windows::UI::Core::CoreDispatcher^ dispatcher)
  116. {
  117. m_dispatcher = dispatcher;
  118. }
  119. void GLViewImpl::setPanel(Windows::UI::Xaml::Controls::Panel^ panel)
  120. {
  121. m_panel = panel;
  122. }
  123. void GLViewImpl::setIMEKeyboardState(bool bOpen)
  124. {
  125. std::string str;
  126. setIMEKeyboardState(bOpen, str);
  127. }
  128. bool GLViewImpl::ShowMessageBox(Platform::String^ title, Platform::String^ message)
  129. {
  130. if (m_dispatcher.Get())
  131. {
  132. m_dispatcher.Get()->RunAsync(Windows::UI::Core::CoreDispatcherPriority::Normal, ref new Windows::UI::Core::DispatchedHandler([title, message]()
  133. {
  134. // Show the message dialog
  135. auto msg = ref new Windows::UI::Popups::MessageDialog(message, title);
  136. // Set the command to be invoked when a user presses 'ESC'
  137. msg->CancelCommandIndex = 1;
  138. msg->ShowAsync();
  139. }));
  140. return true;
  141. }
  142. return false;
  143. }
  144. void GLViewImpl::setIMEKeyboardState(bool bOpen, const std::string& str)
  145. {
  146. if(bOpen)
  147. {
  148. m_keyboard->ShowKeyboard(PlatformStringFromString(str));
  149. }
  150. else
  151. {
  152. m_keyboard->HideKeyboard(PlatformStringFromString(str));
  153. }
  154. }
  155. void GLViewImpl::swapBuffers()
  156. {
  157. }
  158. bool GLViewImpl::isOpenGLReady()
  159. {
  160. return true;
  161. }
  162. void GLViewImpl::end()
  163. {
  164. m_windowClosed = true;
  165. m_appShouldExit = true;
  166. }
  167. void GLViewImpl::OnSuspending(Platform::Object^ sender, SuspendingEventArgs^ args)
  168. {
  169. }
  170. void GLViewImpl::OnResuming(Platform::Object^ sender, Platform::Object^ args)
  171. {
  172. }
  173. // user pressed the Back Key on the phone
  174. void GLViewImpl::OnBackKeyPress()
  175. {
  176. cocos2d::EventKeyboard::KeyCode cocos2dKey = EventKeyboard::KeyCode::KEY_ESCAPE;
  177. cocos2d::EventKeyboard event(cocos2dKey, false);
  178. cocos2d::Director::getInstance()->getEventDispatcher()->dispatchEvent(&event);
  179. }
  180. void GLViewImpl::BackButtonListener(EventKeyboard::KeyCode keyCode, Event* event)
  181. {
  182. if (keyCode == EventKeyboard::KeyCode::KEY_ESCAPE)
  183. {
  184. CCLOG("*********************************************************************");
  185. CCLOG("GLViewImpl::BackButtonListener: Exiting application!");
  186. CCLOG("");
  187. CCLOG("If you want to listen for Windows Phone back button events,");
  188. CCLOG("add a listener for EventKeyboard::KeyCode::KEY_ESCAPE");
  189. CCLOG("Make sure you call stopPropagation() on the Event if you don't");
  190. CCLOG("want your app to exit when the back button is pressed.");
  191. CCLOG("");
  192. CCLOG("For example, add the following to your scene...");
  193. CCLOG("auto listener = EventListenerKeyboard::create();");
  194. CCLOG("listener->onKeyReleased = CC_CALLBACK_2(HelloWorld::onKeyReleased, this);");
  195. CCLOG("getEventDispatcher()->addEventListenerWithFixedPriority(listener, 1);");
  196. CCLOG("");
  197. CCLOG("void HelloWorld::onKeyReleased(EventKeyboard::KeyCode keyCode, Event* event)");
  198. CCLOG("{");
  199. CCLOG(" if (keyCode == EventKeyboard::KeyCode::KEY_ESCAPE)");
  200. CCLOG(" {");
  201. CCLOG(" if (myAppShouldNotQuit) // or whatever logic you want...");
  202. CCLOG(" {");
  203. CCLOG(" event->stopPropagation();");
  204. CCLOG(" }");
  205. CCLOG(" }");
  206. CCLOG("}");
  207. CCLOG("");
  208. CCLOG("You MUST call event->stopPropagation() if you don't want your app to quit!");
  209. CCLOG("*********************************************************************");
  210. Director::getInstance()->end();
  211. }
  212. }
  213. bool GLViewImpl::AppShouldExit()
  214. {
  215. return m_appShouldExit;
  216. }
  217. void GLViewImpl::OnPointerPressed(CoreWindow^ sender, PointerEventArgs^ args)
  218. {
  219. OnPointerPressed(args);
  220. }
  221. void GLViewImpl::OnPointerPressed(PointerEventArgs^ args)
  222. {
  223. intptr_t id = args->CurrentPoint->PointerId;
  224. Vec2 pt = GetPoint(args);
  225. handleTouchesBegin(1, &id, &pt.x, &pt.y);
  226. }
  227. void GLViewImpl::OnPointerWheelChanged(CoreWindow^ sender, PointerEventArgs^ args)
  228. {
  229. float direction = (float)args->CurrentPoint->Properties->MouseWheelDelta;
  230. intptr_t id = 0;
  231. Vec2 p(0.0f,0.0f);
  232. handleTouchesBegin(1, &id, &p.x, &p.y);
  233. p.y += direction;
  234. handleTouchesMove(1, &id, &p.x, &p.y);
  235. handleTouchesEnd(1, &id, &p.x, &p.y);
  236. }
  237. void GLViewImpl::OnVisibilityChanged(CoreWindow^ sender, VisibilityChangedEventArgs^ args)
  238. {
  239. m_windowVisible = args->Visible;
  240. }
  241. void GLViewImpl::OnWindowClosed(CoreWindow^ sender, CoreWindowEventArgs^ args)
  242. {
  243. m_windowClosed = true;
  244. }
  245. void GLViewImpl::OnPointerMoved(CoreWindow^ sender, PointerEventArgs^ args)
  246. {
  247. OnPointerMoved(args);
  248. }
  249. void GLViewImpl::OnPointerMoved( PointerEventArgs^ args)
  250. {
  251. auto currentPoint = args->CurrentPoint;
  252. if (currentPoint->IsInContact)
  253. {
  254. if (m_lastPointValid)
  255. {
  256. intptr_t id = args->CurrentPoint->PointerId;
  257. Vec2 p = GetPoint(args);
  258. handleTouchesMove(1, &id, &p.x, &p.y);
  259. }
  260. m_lastPoint = currentPoint->Position;
  261. m_lastPointValid = true;
  262. }
  263. else
  264. {
  265. m_lastPointValid = false;
  266. }
  267. }
  268. void GLViewImpl::OnPointerReleased(CoreWindow^ sender, PointerEventArgs^ args)
  269. {
  270. OnPointerReleased(args);
  271. }
  272. void GLViewImpl::OnPointerReleased(PointerEventArgs^ args)
  273. {
  274. intptr_t id = args->CurrentPoint->PointerId;
  275. Vec2 pt = GetPoint(args);
  276. handleTouchesEnd(1, &id, &pt.x, &pt.y);
  277. }
  278. void cocos2d::GLViewImpl::OnMousePressed(Windows::UI::Core::PointerEventArgs^ args)
  279. {
  280. Vec2 mousePosition = GetPointMouse(args);
  281. // Emulated touch, if left mouse button
  282. if (args->CurrentPoint->Properties->IsLeftButtonPressed)
  283. {
  284. intptr_t id = 0;
  285. Vec2 pt = GetPoint(args);
  286. handleTouchesBegin(1, &id, &pt.x, &pt.y);
  287. }
  288. if (_lastMouseButtonPressed != EventMouse::MouseButton::BUTTON_UNSET)
  289. {
  290. EventMouse event(EventMouse::MouseEventType::MOUSE_UP);
  291. event.setMouseButton(_lastMouseButtonPressed);
  292. event.setCursorPosition(mousePosition.x, mousePosition.y);
  293. Director::getInstance()->getEventDispatcher()->dispatchEvent(&event);
  294. }
  295. EventMouse event(EventMouse::MouseEventType::MOUSE_DOWN);
  296. // Set current button
  297. if (args->CurrentPoint->Properties->IsLeftButtonPressed)
  298. {
  299. _lastMouseButtonPressed = EventMouse::MouseButton::BUTTON_LEFT;
  300. }
  301. else if (args->CurrentPoint->Properties->IsRightButtonPressed)
  302. {
  303. _lastMouseButtonPressed = EventMouse::MouseButton::BUTTON_RIGHT;
  304. }
  305. else if (args->CurrentPoint->Properties->IsMiddleButtonPressed)
  306. {
  307. _lastMouseButtonPressed = EventMouse::MouseButton::BUTTON_MIDDLE;
  308. }
  309. event.setMouseButton(_lastMouseButtonPressed);
  310. event.setCursorPosition(mousePosition.x, mousePosition.y);
  311. Director::getInstance()->getEventDispatcher()->dispatchEvent(&event);
  312. }
  313. void cocos2d::GLViewImpl::OnMouseMoved(Windows::UI::Core::PointerEventArgs^ args)
  314. {
  315. Vec2 mousePosition = GetPointMouse(args);
  316. // Emulated touch, if left mouse button
  317. if (args->CurrentPoint->Properties->IsLeftButtonPressed)
  318. {
  319. intptr_t id = 0;
  320. Vec2 pt = GetPoint(args);
  321. handleTouchesMove(1, &id, &pt.x, &pt.y);
  322. }
  323. EventMouse event(EventMouse::MouseEventType::MOUSE_MOVE);
  324. // Set current button
  325. if (args->CurrentPoint->Properties->IsLeftButtonPressed)
  326. {
  327. event.setMouseButton(EventMouse::MouseButton::BUTTON_LEFT);
  328. }
  329. else if (args->CurrentPoint->Properties->IsRightButtonPressed)
  330. {
  331. event.setMouseButton(EventMouse::MouseButton::BUTTON_RIGHT);
  332. }
  333. else if (args->CurrentPoint->Properties->IsMiddleButtonPressed)
  334. {
  335. event.setMouseButton(EventMouse::MouseButton::BUTTON_MIDDLE);
  336. }
  337. event.setCursorPosition(mousePosition.x, mousePosition.y);
  338. Director::getInstance()->getEventDispatcher()->dispatchEvent(&event);
  339. }
  340. void cocos2d::GLViewImpl::OnMouseReleased(Windows::UI::Core::PointerEventArgs^ args)
  341. {
  342. Vec2 mousePosition = GetPointMouse(args);
  343. // Emulated touch, if left mouse button
  344. if (_lastMouseButtonPressed == EventMouse::MouseButton::BUTTON_LEFT)
  345. {
  346. intptr_t id = 0;
  347. Vec2 pt = GetPoint(args);
  348. handleTouchesEnd(1, &id, &pt.x, &pt.y);
  349. }
  350. EventMouse event(EventMouse::MouseEventType::MOUSE_UP);
  351. event.setMouseButton(_lastMouseButtonPressed);
  352. event.setCursorPosition(mousePosition.x, mousePosition.y);
  353. Director::getInstance()->getEventDispatcher()->dispatchEvent(&event);
  354. _lastMouseButtonPressed = EventMouse::MouseButton::BUTTON_UNSET;
  355. }
  356. void cocos2d::GLViewImpl::OnMouseWheelChanged(Windows::UI::Core::PointerEventArgs^ args)
  357. {
  358. Vec2 mousePosition = GetPointMouse(args);
  359. EventMouse event(EventMouse::MouseEventType::MOUSE_SCROLL);
  360. float delta = args->CurrentPoint->Properties->MouseWheelDelta;
  361. if (args->CurrentPoint->Properties->IsHorizontalMouseWheel)
  362. {
  363. event.setScrollData(delta, 0.0f);
  364. }
  365. else
  366. {
  367. event.setScrollData(0.0f, -delta);
  368. }
  369. event.setCursorPosition(mousePosition.x, mousePosition.y);
  370. Director::getInstance()->getEventDispatcher()->dispatchEvent(&event);
  371. }
  372. void GLViewImpl::resize(int width, int height)
  373. {
  374. }
  375. void GLViewImpl::setFrameZoomFactor(float fZoomFactor)
  376. {
  377. _frameZoomFactor = fZoomFactor;
  378. Director::getInstance()->setProjection(Director::getInstance()->getProjection());
  379. //resize(m_obScreenSize.width * fZoomFactor, m_obScreenSize.height * fZoomFactor);
  380. }
  381. float GLViewImpl::getFrameZoomFactor()
  382. {
  383. return _frameZoomFactor;
  384. }
  385. void GLViewImpl::centerWindow()
  386. {
  387. // not implemented in WinRT. Window is always full screen
  388. }
  389. GLViewImpl* GLViewImpl::sharedOpenGLView()
  390. {
  391. return s_pEglView;
  392. }
  393. int GLViewImpl::Run()
  394. {
  395. // XAML version does not have a run loop
  396. m_running = true;
  397. return 0;
  398. };
  399. void GLViewImpl::Render()
  400. {
  401. OnRendering();
  402. }
  403. void GLViewImpl::OnRendering()
  404. {
  405. if(m_running && m_initialized)
  406. {
  407. Director::getInstance()->mainLoop();
  408. }
  409. }
  410. // called by orientation change from WP8 XAML
  411. void GLViewImpl::UpdateOrientation(DisplayOrientations orientation)
  412. {
  413. if(m_orientation != orientation)
  414. {
  415. m_orientation = orientation;
  416. UpdateWindowSize();
  417. }
  418. }
  419. // called by size change from WP8 XAML
  420. void GLViewImpl::UpdateForWindowSizeChange(float width, float height)
  421. {
  422. if (width != m_width || height != m_height)
  423. {
  424. m_width = width;
  425. m_height = height;
  426. UpdateWindowSize();
  427. }
  428. }
  429. #if 0
  430. win32 version
  431. void GLViewEventHandler::OnGLFWWindowSizeFunCallback(GLFWwindow *windows, int width, int height)
  432. {
  433. auto view = Director::getInstance()->getOpenGLView();
  434. if(view && view->getResolutionPolicy() != ResolutionPolicy::UNKNOWN)
  435. {
  436. Size resSize=view->getDesignResolutionSize();
  437. ResolutionPolicy resPolicy=view->getResolutionPolicy();
  438. view->setFrameSize(width, height);
  439. view->setDesignResolutionSize(resSize.width, resSize.height, resPolicy);
  440. Director::getInstance()->setViewport();
  441. }
  442. }
  443. #endif
  444. void GLViewImpl::UpdateWindowSize()
  445. {
  446. float width, height;
  447. width = m_width;
  448. height = m_height;
  449. //CCSize designSize = getDesignResolutionSize();
  450. if(!m_initialized)
  451. {
  452. m_initialized = true;
  453. GLView::setFrameSize(width, height);
  454. }
  455. auto view = Director::getInstance()->getOpenGLView();
  456. if(view && view->getResolutionPolicy() != ResolutionPolicy::UNKNOWN)
  457. {
  458. Size resSize=view->getDesignResolutionSize();
  459. ResolutionPolicy resPolicy=view->getResolutionPolicy();
  460. view->setFrameSize(width, height);
  461. view->setDesignResolutionSize(resSize.width, resSize.height, resPolicy);
  462. auto director = Director::getInstance();
  463. director->setViewport();
  464. director->setProjection(director->getProjection());
  465. }
  466. }
  467. cocos2d::Vec2 GLViewImpl::TransformToOrientation(Windows::Foundation::Point p)
  468. {
  469. cocos2d::Vec2 returnValue;
  470. float x = p.X;
  471. float y = p.Y;
  472. returnValue = Vec2(x, y);
  473. #if 0
  474. switch (m_orientation)
  475. {
  476. case DisplayOrientations::Portrait:
  477. default:
  478. returnValue = Vec2(x, y);
  479. break;
  480. case DisplayOrientations::Landscape:
  481. returnValue = Vec2(y, m_width - x);
  482. break;
  483. case DisplayOrientations::PortraitFlipped:
  484. returnValue = Vec2(m_width - x, m_height - y);
  485. break;
  486. case DisplayOrientations::LandscapeFlipped:
  487. returnValue = Vec2(m_height - y, x);
  488. break;
  489. }
  490. #endif
  491. float zoomFactor = GLViewImpl::sharedOpenGLView()->getFrameZoomFactor();
  492. if(zoomFactor > 0.0f) {
  493. returnValue.x /= zoomFactor;
  494. returnValue.y /= zoomFactor;
  495. }
  496. // CCLOG("%.2f %.2f : %.2f %.2f", p.X, p.Y,returnValue.x, returnValue.y);
  497. return returnValue;
  498. }
  499. Vec2 GLViewImpl::GetPoint(PointerEventArgs^ args) {
  500. return TransformToOrientation(args->CurrentPoint->Position);
  501. }
  502. Vec2 GLViewImpl::GetPointMouse(PointerEventArgs^ args) {
  503. Vec2 position = TransformToOrientation(args->CurrentPoint->Position);
  504. //Because Windows and cocos2d-x uses different Y axis, we need to convert the coordinate here
  505. position.x = (position.x - _viewPortRect.origin.x) / _scaleX;
  506. position.y = (_viewPortRect.origin.y + _viewPortRect.size.height - position.y) / _scaleY;
  507. return position;
  508. }
  509. void GLViewImpl::QueueBackKeyPress()
  510. {
  511. std::shared_ptr<BackButtonEvent> e(new BackButtonEvent());
  512. mInputEvents.push(e);
  513. }
  514. void GLViewImpl::QueuePointerEvent(PointerEventType type, PointerEventArgs^ args)
  515. {
  516. std::shared_ptr<PointerEvent> e(new PointerEvent(type, args));
  517. mInputEvents.push(e);
  518. }
  519. void GLViewImpl::QueueWinRTKeyboardEvent(WinRTKeyboardEventType type, KeyEventArgs^ args)
  520. {
  521. std::shared_ptr<WinRTKeyboardEvent> e(new WinRTKeyboardEvent(type, args));
  522. mInputEvents.push(e);
  523. }
  524. void GLViewImpl::OnWinRTKeyboardEvent(WinRTKeyboardEventType type, KeyEventArgs^ args)
  525. {
  526. m_keyboard->OnWinRTKeyboardEvent(type, args);
  527. }
  528. void GLViewImpl::QueueEvent(std::shared_ptr<InputEvent>& event)
  529. {
  530. mInputEvents.push(event);
  531. }
  532. void GLViewImpl::ProcessEvents()
  533. {
  534. std::shared_ptr<InputEvent> e;
  535. while (mInputEvents.try_pop(e))
  536. {
  537. e->execute();
  538. }
  539. }
  540. NS_CC_END