You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

558 lines
21 KiB

  1. #include "pch.h"
  2. #include "app.h"
  3. #include "raylib.h"
  4. using namespace Windows::ApplicationModel::Core;
  5. using namespace Windows::ApplicationModel::Activation;
  6. using namespace Windows::UI::Core;
  7. using namespace Windows::UI::Input;
  8. using namespace Windows::Devices::Input;
  9. using namespace Windows::Foundation;
  10. using namespace Windows::Foundation::Collections;
  11. using namespace Windows::Gaming::Input;
  12. using namespace Windows::Graphics::Display;
  13. using namespace Microsoft::WRL;
  14. using namespace Platform;
  15. using namespace raylibUWP;
  16. /*
  17. To-do list
  18. - Cache reference to our CoreWindow?
  19. - Implement gestures
  20. */
  21. /* INPUT CODE */
  22. // Stand-ins for "core.c" variables
  23. #define MAX_GAMEPADS 4 // Max number of gamepads supported
  24. #define MAX_GAMEPAD_BUTTONS 32 // Max bumber of buttons supported (per gamepad)
  25. #define MAX_GAMEPAD_AXIS 8 // Max number of axis supported (per gamepad)
  26. static bool gamepadReady[MAX_GAMEPADS] = { false }; // Flag to know if gamepad is ready
  27. static float gamepadAxisState[MAX_GAMEPADS][MAX_GAMEPAD_AXIS]; // Gamepad axis state
  28. static char previousGamepadState[MAX_GAMEPADS][MAX_GAMEPAD_BUTTONS]; // Previous gamepad buttons state
  29. static char currentGamepadState[MAX_GAMEPADS][MAX_GAMEPAD_BUTTONS]; // Current gamepad buttons state
  30. static char previousKeyState[512] = { 0 }; // Contains previous frame keyboard state
  31. static char currentKeyState[512] = { 0 }; // Contains current frame keyboard state
  32. //...
  33. static char previousMouseState[3] = { 0 }; // Registers previous mouse button state
  34. static char currentMouseState[3] = { 0 }; // Registers current mouse button state
  35. static int previousMouseWheelY = 0; // Registers previous mouse wheel variation
  36. static int currentMouseWheelY = 0; // Registers current mouse wheel variation
  37. static bool cursorOnScreen = false; // Tracks if cursor is inside client area
  38. static bool cursorHidden = false; // Track if cursor is hidden
  39. static Vector2 mousePosition;
  40. static Vector2 mouseDelta; // NOTE: Added to keep track of mouse movement while the cursor is locked - no equivalent in "core.c"
  41. static bool toggleCursorLock;
  42. CoreCursor ^regularCursor = ref new CoreCursor(CoreCursorType::Arrow, 0); // The "visible arrow" cursor type
  43. // Helper to process key events
  44. void ProcessKeyEvent(Windows::System::VirtualKey key, int action)
  45. {
  46. using Windows::System::VirtualKey;
  47. switch (key)
  48. {
  49. case VirtualKey::Space: currentKeyState[KEY_SPACE] = action; break;
  50. case VirtualKey::Escape: currentKeyState[KEY_ESCAPE] = action; break;
  51. case VirtualKey::Enter: currentKeyState[KEY_ENTER] = action; break;
  52. case VirtualKey::Delete: currentKeyState[KEY_BACKSPACE] = action; break;
  53. case VirtualKey::Right: currentKeyState[KEY_RIGHT] = action; break;
  54. case VirtualKey::Left: currentKeyState[KEY_LEFT] = action; break;
  55. case VirtualKey::Down: currentKeyState[KEY_DOWN] = action; break;
  56. case VirtualKey::Up: currentKeyState[KEY_UP] = action; break;
  57. case VirtualKey::F1: currentKeyState[KEY_F1] = action; break;
  58. case VirtualKey::F2: currentKeyState[KEY_F2] = action; break;
  59. case VirtualKey::F3: currentKeyState[KEY_F4] = action; break;
  60. case VirtualKey::F4: currentKeyState[KEY_F5] = action; break;
  61. case VirtualKey::F5: currentKeyState[KEY_F6] = action; break;
  62. case VirtualKey::F6: currentKeyState[KEY_F7] = action; break;
  63. case VirtualKey::F7: currentKeyState[KEY_F8] = action; break;
  64. case VirtualKey::F8: currentKeyState[KEY_F9] = action; break;
  65. case VirtualKey::F9: currentKeyState[KEY_F10] = action; break;
  66. case VirtualKey::F10: currentKeyState[KEY_F11] = action; break;
  67. case VirtualKey::F11: currentKeyState[KEY_F12] = action; break;
  68. case VirtualKey::LeftShift: currentKeyState[KEY_LEFT_SHIFT] = action; break;
  69. case VirtualKey::LeftControl: currentKeyState[KEY_LEFT_CONTROL] = action; break;
  70. case VirtualKey::LeftMenu: currentKeyState[KEY_LEFT_ALT] = action; break; // NOTE: Potential UWP bug with Alt key: https://social.msdn.microsoft.com/Forums/windowsapps/en-US/9bebfb0a-7637-400e-8bda-e55620091407/unexpected-behavior-in-windowscoreuicorephysicalkeystatusismenukeydown
  71. case VirtualKey::RightShift: currentKeyState[KEY_RIGHT_SHIFT] = action; break;
  72. case VirtualKey::RightControl: currentKeyState[KEY_RIGHT_CONTROL] = action; break;
  73. case VirtualKey::RightMenu: currentKeyState[KEY_RIGHT_ALT] = action; break;
  74. case VirtualKey::Number0: currentKeyState[KEY_ZERO] = action; break;
  75. case VirtualKey::Number1: currentKeyState[KEY_ONE] = action; break;
  76. case VirtualKey::Number2: currentKeyState[KEY_TWO] = action; break;
  77. case VirtualKey::Number3: currentKeyState[KEY_THREE] = action; break;
  78. case VirtualKey::Number4: currentKeyState[KEY_FOUR] = action; break;
  79. case VirtualKey::Number5: currentKeyState[KEY_FIVE] = action; break;
  80. case VirtualKey::Number6: currentKeyState[KEY_SIX] = action; break;
  81. case VirtualKey::Number7: currentKeyState[KEY_SEVEN] = action; break;
  82. case VirtualKey::Number8: currentKeyState[KEY_EIGHT] = action; break;
  83. case VirtualKey::Number9: currentKeyState[KEY_NINE] = action; break;
  84. case VirtualKey::A: currentKeyState[KEY_A] = action; break;
  85. case VirtualKey::B: currentKeyState[KEY_B] = action; break;
  86. case VirtualKey::C: currentKeyState[KEY_C] = action; break;
  87. case VirtualKey::D: currentKeyState[KEY_D] = action; break;
  88. case VirtualKey::E: currentKeyState[KEY_E] = action; break;
  89. case VirtualKey::F: currentKeyState[KEY_F] = action; break;
  90. case VirtualKey::G: currentKeyState[KEY_G] = action; break;
  91. case VirtualKey::H: currentKeyState[KEY_H] = action; break;
  92. case VirtualKey::I: currentKeyState[KEY_I] = action; break;
  93. case VirtualKey::J: currentKeyState[KEY_J] = action; break;
  94. case VirtualKey::K: currentKeyState[KEY_K] = action; break;
  95. case VirtualKey::L: currentKeyState[KEY_L] = action; break;
  96. case VirtualKey::M: currentKeyState[KEY_M] = action; break;
  97. case VirtualKey::N: currentKeyState[KEY_N] = action; break;
  98. case VirtualKey::O: currentKeyState[KEY_O] = action; break;
  99. case VirtualKey::P: currentKeyState[KEY_P] = action; break;
  100. case VirtualKey::Q: currentKeyState[KEY_Q] = action; break;
  101. case VirtualKey::R: currentKeyState[KEY_R] = action; break;
  102. case VirtualKey::S: currentKeyState[KEY_S] = action; break;
  103. case VirtualKey::T: currentKeyState[KEY_T] = action; break;
  104. case VirtualKey::U: currentKeyState[KEY_U] = action; break;
  105. case VirtualKey::V: currentKeyState[KEY_V] = action; break;
  106. case VirtualKey::W: currentKeyState[KEY_W] = action; break;
  107. case VirtualKey::X: currentKeyState[KEY_X] = action; break;
  108. case VirtualKey::Y: currentKeyState[KEY_Y] = action; break;
  109. case VirtualKey::Z: currentKeyState[KEY_Z] = action; break;
  110. }
  111. }
  112. /* CALLBACKS */
  113. void App::PointerPressed(CoreWindow^ window, PointerEventArgs^ args)
  114. {
  115. if (args->CurrentPoint->Properties->IsLeftButtonPressed)
  116. {
  117. currentMouseState[MOUSE_LEFT_BUTTON] = 1;
  118. }
  119. if (args->CurrentPoint->Properties->IsRightButtonPressed)
  120. {
  121. currentMouseState[MOUSE_RIGHT_BUTTON] = 1;
  122. }
  123. if (args->CurrentPoint->Properties->IsMiddleButtonPressed)
  124. {
  125. currentMouseState[MOUSE_MIDDLE_BUTTON] = 1;
  126. }
  127. }
  128. void App::PointerReleased(CoreWindow ^window, PointerEventArgs^ args)
  129. {
  130. if (!(args->CurrentPoint->Properties->IsLeftButtonPressed))
  131. {
  132. currentMouseState[MOUSE_LEFT_BUTTON] = 0;
  133. }
  134. if (!(args->CurrentPoint->Properties->IsRightButtonPressed))
  135. {
  136. currentMouseState[MOUSE_RIGHT_BUTTON] = 0;
  137. }
  138. if (!(args->CurrentPoint->Properties->IsMiddleButtonPressed))
  139. {
  140. currentMouseState[MOUSE_MIDDLE_BUTTON] = 0;
  141. }
  142. }
  143. void App::PointerWheelChanged(CoreWindow ^window, PointerEventArgs^ args)
  144. {
  145. // TODO: Scale the MouseWheelDelta to match GLFW's mouse wheel sensitivity.
  146. currentMouseWheelY += args->CurrentPoint->Properties->MouseWheelDelta;
  147. }
  148. void App::MouseMoved(Windows::Devices::Input::MouseDevice^ mouseDevice, Windows::Devices::Input::MouseEventArgs^ args)
  149. {
  150. mouseDelta.x += args->MouseDelta.X;
  151. mouseDelta.y += args->MouseDelta.Y;
  152. }
  153. void App::OnKeyDown(CoreWindow ^ sender, KeyEventArgs ^ args)
  154. {
  155. ProcessKeyEvent(args->VirtualKey, 1);
  156. }
  157. void App::OnKeyUp(CoreWindow ^ sender, KeyEventArgs ^ args)
  158. {
  159. ProcessKeyEvent(args->VirtualKey, 0);
  160. }
  161. /* REIMPLEMENTED FROM CORE.C */
  162. // Get one key state
  163. static bool GetKeyStatus(int key)
  164. {
  165. return currentKeyState[key];
  166. }
  167. // Show mouse cursor
  168. void UWPShowCursor()
  169. {
  170. CoreWindow::GetForCurrentThread()->PointerCursor = regularCursor;
  171. cursorHidden = false;
  172. }
  173. // Hides mouse cursor
  174. void UWPHideCursor()
  175. {
  176. CoreWindow::GetForCurrentThread()->PointerCursor = nullptr;
  177. cursorHidden = true;
  178. }
  179. // Set mouse position XY
  180. void UWPSetMousePosition(Vector2 position)
  181. {
  182. CoreWindow ^window = CoreWindow::GetForCurrentThread();
  183. Point mousePosScreen = Point(position.x + window->Bounds.X, position.y + window->Bounds.Y);
  184. window->PointerPosition = mousePosScreen;
  185. mousePosition = position;
  186. }
  187. // Enables cursor (unlock cursor)
  188. void UWPEnableCursor()
  189. {
  190. UWPShowCursor();
  191. UWPSetMousePosition(mousePosition); // The mouse is hidden in the center of the screen - move it to where it should appear
  192. toggleCursorLock = false;
  193. }
  194. // Disables cursor (lock cursor)
  195. void UWPDisableCursor()
  196. {
  197. UWPHideCursor();
  198. toggleCursorLock = true;
  199. }
  200. // Get one mouse button state
  201. static bool UWPGetMouseButtonStatus(int button)
  202. {
  203. return currentMouseState[button];
  204. }
  205. // Poll (store) all input events
  206. void UWP_PollInput()
  207. {
  208. // Register previous keyboard state
  209. for (int k = 0; k < 512; k++) previousKeyState[k] = currentKeyState[k];
  210. // Process Mouse
  211. {
  212. // Register previous mouse states
  213. for (int i = 0; i < 3; i++) previousMouseState[i] = currentMouseState[i];
  214. previousMouseWheelY = currentMouseWheelY;
  215. currentMouseWheelY = 0;
  216. CoreWindow ^window = CoreWindow::GetForCurrentThread();
  217. if (toggleCursorLock)
  218. {
  219. // Track cursor movement delta, recenter it on the client
  220. mousePosition.x += mouseDelta.x;
  221. mousePosition.y += mouseDelta.y;
  222. // Why we're not using UWPSetMousePosition here...
  223. // UWPSetMousePosition changes the "mousePosition" variable to match where the cursor actually is.
  224. // Our cursor is locked to the middle of screen, and we don't want that reflected in "mousePosition"
  225. Vector2 centerClient = { (float)(GetScreenWidth() / 2), (float)(GetScreenHeight() / 2) };
  226. window->PointerPosition = Point(centerClient.x + window->Bounds.X, centerClient.y + window->Bounds.Y);
  227. }
  228. else
  229. {
  230. // Record the cursor's position relative to the client
  231. mousePosition.x = window->PointerPosition.X - window->Bounds.X;
  232. mousePosition.y = window->PointerPosition.Y - window->Bounds.Y;
  233. }
  234. mouseDelta = { 0 ,0 };
  235. }
  236. // Process Gamepads
  237. {
  238. // Check if gamepads are ready
  239. for (int i = 0; i < MAX_GAMEPADS; i++)
  240. {
  241. // HACK: UWP keeps a contiguous list of gamepads. For the interest of time I'm just doing a 1:1 mapping of
  242. // connected gamepads with their spot in the list, but this has serious robustness problems
  243. // e.g. player 1, 2, and 3 are playing a game - if player2 disconnects, p3's controller would now be mapped to p2's character since p3 is now second in the list.
  244. gamepadReady[i] = (i < Gamepad::Gamepads->Size);
  245. }
  246. // Get current gamepad state
  247. for (int i = 0; i < MAX_GAMEPADS; i++)
  248. {
  249. if (gamepadReady[i])
  250. {
  251. // Register previous gamepad states
  252. for (int k = 0; k < MAX_GAMEPAD_BUTTONS; k++) previousGamepadState[i][k] = currentGamepadState[i][k];
  253. // Get current gamepad state
  254. auto gamepad = Gamepad::Gamepads->GetAt(i);
  255. GamepadReading reading = gamepad->GetCurrentReading();
  256. // NOTE: Maybe it would be wiser to redefine the gamepad button mappings in "raylib.h" for the UWP platform instead of remapping them manually
  257. currentGamepadState[i][GAMEPAD_XBOX_BUTTON_A] = ((reading.Buttons & GamepadButtons::A) == GamepadButtons::A);
  258. currentGamepadState[i][GAMEPAD_XBOX_BUTTON_B] = ((reading.Buttons & GamepadButtons::B) == GamepadButtons::B);
  259. currentGamepadState[i][GAMEPAD_XBOX_BUTTON_X] = ((reading.Buttons & GamepadButtons::X) == GamepadButtons::X);
  260. currentGamepadState[i][GAMEPAD_XBOX_BUTTON_Y] = ((reading.Buttons & GamepadButtons::Y) == GamepadButtons::Y);
  261. currentGamepadState[i][GAMEPAD_XBOX_BUTTON_LB] = ((reading.Buttons & GamepadButtons::LeftShoulder) == GamepadButtons::LeftShoulder);
  262. currentGamepadState[i][GAMEPAD_XBOX_BUTTON_RB] = ((reading.Buttons & GamepadButtons::RightShoulder) == GamepadButtons::RightShoulder);
  263. currentGamepadState[i][GAMEPAD_XBOX_BUTTON_SELECT] = ((reading.Buttons & GamepadButtons::View) == GamepadButtons::View); // Changed for XB1 Controller
  264. currentGamepadState[i][GAMEPAD_XBOX_BUTTON_START] = ((reading.Buttons & GamepadButtons::Menu) == GamepadButtons::Menu); // Changed for XB1 Controller
  265. currentGamepadState[i][GAMEPAD_XBOX_BUTTON_UP] = ((reading.Buttons & GamepadButtons::DPadUp) == GamepadButtons::DPadUp);
  266. currentGamepadState[i][GAMEPAD_XBOX_BUTTON_RIGHT] = ((reading.Buttons & GamepadButtons::DPadRight) == GamepadButtons::DPadRight);
  267. currentGamepadState[i][GAMEPAD_XBOX_BUTTON_DOWN] = ((reading.Buttons & GamepadButtons::DPadLeft) == GamepadButtons::DPadDown);
  268. currentGamepadState[i][GAMEPAD_XBOX_BUTTON_LEFT] = ((reading.Buttons & GamepadButtons::DPadDown) == GamepadButtons::DPadLeft);
  269. currentGamepadState[i][GAMEPAD_XBOX_BUTTON_HOME] = false; // Home button not supported by UWP
  270. // Get current axis state
  271. gamepadAxisState[i][GAMEPAD_XBOX_AXIS_LEFT_X] = reading.LeftThumbstickX;
  272. gamepadAxisState[i][GAMEPAD_XBOX_AXIS_LEFT_Y] = reading.LeftThumbstickY;
  273. gamepadAxisState[i][GAMEPAD_XBOX_AXIS_RIGHT_X] = reading.RightThumbstickX;
  274. gamepadAxisState[i][GAMEPAD_XBOX_AXIS_RIGHT_Y] = reading.RightThumbstickY;
  275. gamepadAxisState[i][GAMEPAD_XBOX_AXIS_LT] = reading.LeftTrigger;
  276. gamepadAxisState[i][GAMEPAD_XBOX_AXIS_RT] = reading.RightTrigger;
  277. }
  278. }
  279. }
  280. }
  281. // The following functions were ripped from core.c and have *no additional work done on them*
  282. // Detect if a key has been pressed once
  283. bool UWPIsKeyPressed(int key)
  284. {
  285. bool pressed = false;
  286. if ((currentKeyState[key] != previousKeyState[key]) && (currentKeyState[key] == 1))
  287. pressed = true;
  288. else pressed = false;
  289. return pressed;
  290. }
  291. // Detect if a key is being pressed (key held down)
  292. bool UWPIsKeyDown(int key)
  293. {
  294. if (GetKeyStatus(key) == 1) return true;
  295. else return false;
  296. }
  297. // Detect if a key has been released once
  298. bool UWPIsKeyReleased(int key)
  299. {
  300. bool released = false;
  301. if ((currentKeyState[key] != previousKeyState[key]) && (currentKeyState[key] == 0)) released = true;
  302. else released = false;
  303. return released;
  304. }
  305. // Detect if a key is NOT being pressed (key not held down)
  306. bool UWPIsKeyUp(int key)
  307. {
  308. if (GetKeyStatus(key) == 0) return true;
  309. else return false;
  310. }
  311. /* OTHER CODE */
  312. // Helper to convert a length in device-independent pixels (DIPs) to a length in physical pixels.
  313. inline float ConvertDipsToPixels(float dips, float dpi)
  314. {
  315. static const float dipsPerInch = 96.0f;
  316. return floor(dips * dpi / dipsPerInch + 0.5f); // Round to nearest integer.
  317. }
  318. // Implementation of the IFrameworkViewSource interface, necessary to run our app.
  319. ref class SimpleApplicationSource sealed : Windows::ApplicationModel::Core::IFrameworkViewSource
  320. {
  321. public:
  322. virtual Windows::ApplicationModel::Core::IFrameworkView^ CreateView()
  323. {
  324. return ref new App();
  325. }
  326. };
  327. // The main function creates an IFrameworkViewSource for our app, and runs the app.
  328. [Platform::MTAThread]
  329. int main(Platform::Array<Platform::String^>^)
  330. {
  331. auto simpleApplicationSource = ref new SimpleApplicationSource();
  332. CoreApplication::Run(simpleApplicationSource);
  333. return 0;
  334. }
  335. App::App() :
  336. mWindowClosed(false),
  337. mWindowVisible(true)
  338. {
  339. }
  340. // The first method called when the IFrameworkView is being created.
  341. void App::Initialize(CoreApplicationView^ applicationView)
  342. {
  343. // Register event handlers for app lifecycle. This example includes Activated, so that we
  344. // can make the CoreWindow active and start rendering on the window.
  345. applicationView->Activated += ref new TypedEventHandler<CoreApplicationView^, IActivatedEventArgs^>(this, &App::OnActivated);
  346. // Logic for other event handlers could go here.
  347. // Information about the Suspending and Resuming event handlers can be found here:
  348. // http://msdn.microsoft.com/en-us/library/windows/apps/xaml/hh994930.aspx
  349. CoreApplication::Resuming += ref new EventHandler<Platform::Object^>(this, &App::OnResuming);
  350. }
  351. // Called when the CoreWindow object is created (or re-created).
  352. void App::SetWindow(CoreWindow^ window)
  353. {
  354. window->SizeChanged += ref new TypedEventHandler<CoreWindow^, WindowSizeChangedEventArgs^>(this, &App::OnWindowSizeChanged);
  355. window->VisibilityChanged += ref new TypedEventHandler<CoreWindow^, VisibilityChangedEventArgs^>(this, &App::OnVisibilityChanged);
  356. window->Closed += ref new TypedEventHandler<CoreWindow^, CoreWindowEventArgs^>(this, &App::OnWindowClosed);
  357. window->PointerPressed += ref new TypedEventHandler<CoreWindow^, PointerEventArgs^>(this, &App::PointerPressed);
  358. window->PointerReleased += ref new TypedEventHandler<CoreWindow^, PointerEventArgs^>(this, &App::PointerReleased);
  359. window->PointerWheelChanged += ref new TypedEventHandler<CoreWindow^, PointerEventArgs^>(this, &App::PointerWheelChanged);
  360. window->KeyDown += ref new TypedEventHandler<CoreWindow ^, KeyEventArgs ^>(this, &App::OnKeyDown);
  361. window->KeyUp += ref new TypedEventHandler<CoreWindow ^, KeyEventArgs ^>(this, &App::OnKeyUp);
  362. Windows::Devices::Input::MouseDevice::GetForCurrentView()->MouseMoved += ref new TypedEventHandler<MouseDevice^, MouseEventArgs^>(this, &App::MouseMoved);
  363. DisplayInformation^ currentDisplayInformation = DisplayInformation::GetForCurrentView();
  364. currentDisplayInformation->DpiChanged += ref new TypedEventHandler<DisplayInformation^, Object^>(this, &App::OnDpiChanged);
  365. currentDisplayInformation->OrientationChanged += ref new TypedEventHandler<DisplayInformation^, Object^>(this, &App::OnOrientationChanged);
  366. // The CoreWindow has been created, so EGL can be initialized.
  367. InitWindow(800, 450, (EGLNativeWindowType)window);
  368. }
  369. // Initializes scene resources
  370. void App::Load(Platform::String^ entryPoint)
  371. {
  372. // InitWindow() --> rlglInit()
  373. }
  374. static int posX = 100;
  375. static int posY = 100;
  376. static int time = 0;
  377. // This method is called after the window becomes active.
  378. void App::Run()
  379. {
  380. while (!mWindowClosed)
  381. {
  382. if (mWindowVisible)
  383. {
  384. // Draw
  385. BeginDrawing();
  386. ClearBackground(RAYWHITE);
  387. posX += gamepadAxisState[GAMEPAD_PLAYER1][GAMEPAD_XBOX_AXIS_LEFT_X] * 5;
  388. posY += gamepadAxisState[GAMEPAD_PLAYER1][GAMEPAD_XBOX_AXIS_LEFT_Y] * -5;
  389. DrawRectangle(posX, posY, 400, 100, RED);
  390. DrawLine(0, 0, GetScreenWidth(), GetScreenHeight(), BLUE);
  391. DrawCircle(mousePosition.x, mousePosition.y, 40, BLUE);
  392. if(UWPIsKeyDown(KEY_S))
  393. {
  394. DrawCircle(100, 100, 100, BLUE);
  395. }
  396. if(UWPIsKeyPressed(KEY_A))
  397. {
  398. posX -= 50;
  399. UWPEnableCursor();
  400. }
  401. if (UWPIsKeyPressed(KEY_D))
  402. {
  403. posX += 50;
  404. UWPDisableCursor();
  405. }
  406. if(currentKeyState[KEY_LEFT_ALT])
  407. DrawRectangle(250, 250, 20, 20, BLACK);
  408. if (currentKeyState[KEY_BACKSPACE])
  409. DrawRectangle(280, 250, 20, 20, BLACK);
  410. if (currentMouseState[MOUSE_LEFT_BUTTON])
  411. DrawRectangle(280, 250, 20, 20, BLACK);
  412. static int pos = 0;
  413. pos -= currentMouseWheelY;
  414. DrawRectangle(280, pos + 50, 20, 20, BLACK);
  415. DrawRectangle(250, 280 + (time++ % 60), 10, 10, PURPLE);
  416. EndDrawing();
  417. UWP_PollInput();
  418. CoreWindow::GetForCurrentThread()->Dispatcher->ProcessEvents(CoreProcessEventsOption::ProcessAllIfPresent);
  419. }
  420. else
  421. {
  422. CoreWindow::GetForCurrentThread()->Dispatcher->ProcessEvents(CoreProcessEventsOption::ProcessOneAndAllPending);
  423. }
  424. }
  425. CloseWindow();
  426. }
  427. // Terminate events do not cause Uninitialize to be called. It will be called if your IFrameworkView
  428. // class is torn down while the app is in the foreground.
  429. void App::Uninitialize()
  430. {
  431. // CloseWindow();
  432. }
  433. // Application lifecycle event handler.
  434. void App::OnActivated(CoreApplicationView^ applicationView, IActivatedEventArgs^ args)
  435. {
  436. // Run() won't start until the CoreWindow is activated.
  437. CoreWindow::GetForCurrentThread()->Activate();
  438. }
  439. void App::OnResuming(Object^ sender, Object^ args)
  440. {
  441. // Restore any data or state that was unloaded on suspend. By default, data
  442. // and state are persisted when resuming from suspend. Note that this event
  443. // does not occur if the app was previously terminated.
  444. }
  445. void App::OnWindowSizeChanged(CoreWindow^ sender, WindowSizeChangedEventArgs^ args)
  446. {
  447. // TODO: Update window and render area size
  448. //m_deviceResources->SetLogicalSize(Size(sender->Bounds.Width, sender->Bounds.Height));
  449. //m_main->UpdateForWindowSizeChange();
  450. }
  451. // Window event handlers.
  452. void App::OnVisibilityChanged(CoreWindow^ sender, VisibilityChangedEventArgs^ args)
  453. {
  454. mWindowVisible = args->Visible;
  455. // raylib core has the variable windowMinimized to register state,
  456. // it should be modifyed by this event...
  457. }
  458. void App::OnWindowClosed(CoreWindow^ sender, CoreWindowEventArgs^ args)
  459. {
  460. mWindowClosed = true;
  461. // raylib core has the variable windowShouldClose to register state,
  462. // it should be modifyed by this event...
  463. }
  464. void App::OnDpiChanged(DisplayInformation^ sender, Object^ args)
  465. {
  466. //m_deviceResources->SetDpi(sender->LogicalDpi);
  467. //m_main->UpdateForWindowSizeChange();
  468. }
  469. void App::OnOrientationChanged(DisplayInformation^ sender, Object^ args)
  470. {
  471. //m_deviceResources->SetCurrentOrientation(sender->CurrentOrientation);
  472. //m_main->UpdateForWindowSizeChange();
  473. }