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