diff --git a/.gitignore b/.gitignore index 08e661af..df96338a 100644 --- a/.gitignore +++ b/.gitignore @@ -45,6 +45,7 @@ ipch/ *.opensdf *.db *.opendb +packages/ # Ignore compiled binaries *.o diff --git a/projects/VS2015.UWP/raylib.App.UWP/App.cpp b/projects/VS2015.UWP/raylib.App.UWP/App.cpp deleted file mode 100644 index 6ce6915c..00000000 --- a/projects/VS2015.UWP/raylib.App.UWP/App.cpp +++ /dev/null @@ -1,558 +0,0 @@ -#include "pch.h" -#include "app.h" - -#include "raylib.h" - -using namespace Windows::ApplicationModel::Core; -using namespace Windows::ApplicationModel::Activation; -using namespace Windows::UI::Core; -using namespace Windows::UI::Input; -using namespace Windows::Devices::Input; -using namespace Windows::Foundation; -using namespace Windows::Foundation::Collections; -using namespace Windows::Gaming::Input; -using namespace Windows::Graphics::Display; -using namespace Microsoft::WRL; -using namespace Platform; - -using namespace raylibUWP; - -/* -TODO list: - - Cache reference to our CoreWindow? - - Implement gestures support -*/ - -// Declare uwpWindow as exter to be used by raylib internals -// NOTE: It should be properly assigned before calling InitWindow() -extern "C" { EGLNativeWindowType uwpWindow; }; - -/* INPUT CODE */ -// Stand-ins for "core.c" variables -#define MAX_GAMEPADS 4 // Max number of gamepads supported -#define MAX_GAMEPAD_BUTTONS 32 // Max bumber of buttons supported (per gamepad) -#define MAX_GAMEPAD_AXIS 8 // Max number of axis supported (per gamepad) - -static bool gamepadReady[MAX_GAMEPADS] = { false }; // Flag to know if gamepad is ready -static float gamepadAxisState[MAX_GAMEPADS][MAX_GAMEPAD_AXIS]; // Gamepad axis state -static char previousGamepadState[MAX_GAMEPADS][MAX_GAMEPAD_BUTTONS]; // Previous gamepad buttons state -static char currentGamepadState[MAX_GAMEPADS][MAX_GAMEPAD_BUTTONS]; // Current gamepad buttons state - -static char previousKeyState[512] = { 0 }; // Contains previous frame keyboard state -static char currentKeyState[512] = { 0 }; // Contains current frame keyboard state - -static char previousMouseState[3] = { 0 }; // Registers previous mouse button state -static char currentMouseState[3] = { 0 }; // Registers current mouse button state -static int previousMouseWheelY = 0; // Registers previous mouse wheel variation -static int currentMouseWheelY = 0; // Registers current mouse wheel variation - -static bool cursorOnScreen = false; // Tracks if cursor is inside client area -static bool cursorHidden = false; // Track if cursor is hidden - -static Vector2 mousePosition; -static Vector2 mouseDelta; // NOTE: Added to keep track of mouse movement while the cursor is locked - no equivalent in "core.c" -static bool toggleCursorLock; - -CoreCursor ^regularCursor = ref new CoreCursor(CoreCursorType::Arrow, 0); // The "visible arrow" cursor type - -// Helper to process key events -void ProcessKeyEvent(Windows::System::VirtualKey key, int action) -{ - using Windows::System::VirtualKey; - switch (key) - { - case VirtualKey::Space: currentKeyState[KEY_SPACE] = action; break; - case VirtualKey::Escape: currentKeyState[KEY_ESCAPE] = action; break; - case VirtualKey::Enter: currentKeyState[KEY_ENTER] = action; break; - case VirtualKey::Delete: currentKeyState[KEY_BACKSPACE] = action; break; - case VirtualKey::Right: currentKeyState[KEY_RIGHT] = action; break; - case VirtualKey::Left: currentKeyState[KEY_LEFT] = action; break; - case VirtualKey::Down: currentKeyState[KEY_DOWN] = action; break; - case VirtualKey::Up: currentKeyState[KEY_UP] = action; break; - case VirtualKey::F1: currentKeyState[KEY_F1] = action; break; - case VirtualKey::F2: currentKeyState[KEY_F2] = action; break; - case VirtualKey::F3: currentKeyState[KEY_F4] = action; break; - case VirtualKey::F4: currentKeyState[KEY_F5] = action; break; - case VirtualKey::F5: currentKeyState[KEY_F6] = action; break; - case VirtualKey::F6: currentKeyState[KEY_F7] = action; break; - case VirtualKey::F7: currentKeyState[KEY_F8] = action; break; - case VirtualKey::F8: currentKeyState[KEY_F9] = action; break; - case VirtualKey::F9: currentKeyState[KEY_F10] = action; break; - case VirtualKey::F10: currentKeyState[KEY_F11] = action; break; - case VirtualKey::F11: currentKeyState[KEY_F12] = action; break; - case VirtualKey::LeftShift: currentKeyState[KEY_LEFT_SHIFT] = action; break; - case VirtualKey::LeftControl: currentKeyState[KEY_LEFT_CONTROL] = action; break; - 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 - case VirtualKey::RightShift: currentKeyState[KEY_RIGHT_SHIFT] = action; break; - case VirtualKey::RightControl: currentKeyState[KEY_RIGHT_CONTROL] = action; break; - case VirtualKey::RightMenu: currentKeyState[KEY_RIGHT_ALT] = action; break; - case VirtualKey::Number0: currentKeyState[KEY_ZERO] = action; break; - case VirtualKey::Number1: currentKeyState[KEY_ONE] = action; break; - case VirtualKey::Number2: currentKeyState[KEY_TWO] = action; break; - case VirtualKey::Number3: currentKeyState[KEY_THREE] = action; break; - case VirtualKey::Number4: currentKeyState[KEY_FOUR] = action; break; - case VirtualKey::Number5: currentKeyState[KEY_FIVE] = action; break; - case VirtualKey::Number6: currentKeyState[KEY_SIX] = action; break; - case VirtualKey::Number7: currentKeyState[KEY_SEVEN] = action; break; - case VirtualKey::Number8: currentKeyState[KEY_EIGHT] = action; break; - case VirtualKey::Number9: currentKeyState[KEY_NINE] = action; break; - case VirtualKey::A: currentKeyState[KEY_A] = action; break; - case VirtualKey::B: currentKeyState[KEY_B] = action; break; - case VirtualKey::C: currentKeyState[KEY_C] = action; break; - case VirtualKey::D: currentKeyState[KEY_D] = action; break; - case VirtualKey::E: currentKeyState[KEY_E] = action; break; - case VirtualKey::F: currentKeyState[KEY_F] = action; break; - case VirtualKey::G: currentKeyState[KEY_G] = action; break; - case VirtualKey::H: currentKeyState[KEY_H] = action; break; - case VirtualKey::I: currentKeyState[KEY_I] = action; break; - case VirtualKey::J: currentKeyState[KEY_J] = action; break; - case VirtualKey::K: currentKeyState[KEY_K] = action; break; - case VirtualKey::L: currentKeyState[KEY_L] = action; break; - case VirtualKey::M: currentKeyState[KEY_M] = action; break; - case VirtualKey::N: currentKeyState[KEY_N] = action; break; - case VirtualKey::O: currentKeyState[KEY_O] = action; break; - case VirtualKey::P: currentKeyState[KEY_P] = action; break; - case VirtualKey::Q: currentKeyState[KEY_Q] = action; break; - case VirtualKey::R: currentKeyState[KEY_R] = action; break; - case VirtualKey::S: currentKeyState[KEY_S] = action; break; - case VirtualKey::T: currentKeyState[KEY_T] = action; break; - case VirtualKey::U: currentKeyState[KEY_U] = action; break; - case VirtualKey::V: currentKeyState[KEY_V] = action; break; - case VirtualKey::W: currentKeyState[KEY_W] = action; break; - case VirtualKey::X: currentKeyState[KEY_X] = action; break; - case VirtualKey::Y: currentKeyState[KEY_Y] = action; break; - case VirtualKey::Z: currentKeyState[KEY_Z] = action; break; - - } -} - -// Callbacks -void App::PointerPressed(CoreWindow^ window, PointerEventArgs^ args) -{ - if (args->CurrentPoint->Properties->IsLeftButtonPressed) - { - currentMouseState[MOUSE_LEFT_BUTTON] = 1; - } - if (args->CurrentPoint->Properties->IsRightButtonPressed) - { - currentMouseState[MOUSE_RIGHT_BUTTON] = 1; - } - if (args->CurrentPoint->Properties->IsMiddleButtonPressed) - { - currentMouseState[MOUSE_MIDDLE_BUTTON] = 1; - } -} - -void App::PointerReleased(CoreWindow ^window, PointerEventArgs^ args) -{ - if (!(args->CurrentPoint->Properties->IsLeftButtonPressed)) - { - currentMouseState[MOUSE_LEFT_BUTTON] = 0; - } - if (!(args->CurrentPoint->Properties->IsRightButtonPressed)) - { - currentMouseState[MOUSE_RIGHT_BUTTON] = 0; - } - if (!(args->CurrentPoint->Properties->IsMiddleButtonPressed)) - { - currentMouseState[MOUSE_MIDDLE_BUTTON] = 0; - } -} - -void App::PointerWheelChanged(CoreWindow ^window, PointerEventArgs^ args) -{ - // TODO: Scale the MouseWheelDelta to match GLFW's mouse wheel sensitivity. - currentMouseWheelY += args->CurrentPoint->Properties->MouseWheelDelta; -} - -void App::MouseMoved(Windows::Devices::Input::MouseDevice^ mouseDevice, Windows::Devices::Input::MouseEventArgs^ args) -{ - mouseDelta.x += args->MouseDelta.X; - mouseDelta.y += args->MouseDelta.Y; -} - -void App::OnKeyDown(CoreWindow ^ sender, KeyEventArgs ^ args) -{ - ProcessKeyEvent(args->VirtualKey, 1); -} - -void App::OnKeyUp(CoreWindow ^ sender, KeyEventArgs ^ args) -{ - ProcessKeyEvent(args->VirtualKey, 0); -} - -/* REIMPLEMENTED FROM CORE.C */ -// Get one key state -static bool GetKeyStatus(int key) -{ - return currentKeyState[key]; -} - -// Show mouse cursor -void UWPShowCursor() -{ - CoreWindow::GetForCurrentThread()->PointerCursor = regularCursor; - cursorHidden = false; -} - -// Hides mouse cursor -void UWPHideCursor() -{ - CoreWindow::GetForCurrentThread()->PointerCursor = nullptr; - cursorHidden = true; -} - -// Set mouse position XY -void UWPSetMousePosition(Vector2 position) -{ - CoreWindow ^window = CoreWindow::GetForCurrentThread(); - Point mousePosScreen = Point(position.x + window->Bounds.X, position.y + window->Bounds.Y); - window->PointerPosition = mousePosScreen; - mousePosition = position; -} - -// Enables cursor (unlock cursor) -void UWPEnableCursor() -{ - UWPShowCursor(); - UWPSetMousePosition(mousePosition); // The mouse is hidden in the center of the screen - move it to where it should appear - toggleCursorLock = false; -} - -// Disables cursor (lock cursor) -void UWPDisableCursor() -{ - UWPHideCursor(); - toggleCursorLock = true; -} - -// Get one mouse button state -static bool UWPGetMouseButtonStatus(int button) -{ - return currentMouseState[button]; -} - -// Poll (store) all input events -void UWP_PollInput() -{ - // Register previous keyboard state - for (int k = 0; k < 512; k++) previousKeyState[k] = currentKeyState[k]; - - // Process Mouse - { - // Register previous mouse states - for (int i = 0; i < 3; i++) previousMouseState[i] = currentMouseState[i]; - previousMouseWheelY = currentMouseWheelY; - currentMouseWheelY = 0; - - CoreWindow ^window = CoreWindow::GetForCurrentThread(); - if (toggleCursorLock) - { - // Track cursor movement delta, recenter it on the client - mousePosition.x += mouseDelta.x; - mousePosition.y += mouseDelta.y; - - // Why we're not using UWPSetMousePosition here... - // UWPSetMousePosition changes the "mousePosition" variable to match where the cursor actually is. - // Our cursor is locked to the middle of screen, and we don't want that reflected in "mousePosition" - Vector2 centerClient = { (float)(GetScreenWidth() / 2), (float)(GetScreenHeight() / 2) }; - window->PointerPosition = Point(centerClient.x + window->Bounds.X, centerClient.y + window->Bounds.Y); - } - else - { - // Record the cursor's position relative to the client - mousePosition.x = window->PointerPosition.X - window->Bounds.X; - mousePosition.y = window->PointerPosition.Y - window->Bounds.Y; - } - - mouseDelta = { 0 ,0 }; - } - - // Process Gamepads - { - // Check if gamepads are ready - for (int i = 0; i < MAX_GAMEPADS; i++) - { - // HACK: UWP keeps a contiguous list of gamepads. For the interest of time I'm just doing a 1:1 mapping of - // connected gamepads with their spot in the list, but this has serious robustness problems - // 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. - - gamepadReady[i] = (i < Gamepad::Gamepads->Size); - } - - // Get current gamepad state - for (int i = 0; i < MAX_GAMEPADS; i++) - { - if (gamepadReady[i]) - { - // Register previous gamepad states - for (int k = 0; k < MAX_GAMEPAD_BUTTONS; k++) previousGamepadState[i][k] = currentGamepadState[i][k]; - - // Get current gamepad state - auto gamepad = Gamepad::Gamepads->GetAt(i); - GamepadReading reading = gamepad->GetCurrentReading(); - - // NOTE: Maybe it would be wiser to redefine the gamepad button mappings in "raylib.h" for the UWP platform instead of remapping them manually - currentGamepadState[i][GAMEPAD_XBOX_BUTTON_A] = ((reading.Buttons & GamepadButtons::A) == GamepadButtons::A); - currentGamepadState[i][GAMEPAD_XBOX_BUTTON_B] = ((reading.Buttons & GamepadButtons::B) == GamepadButtons::B); - currentGamepadState[i][GAMEPAD_XBOX_BUTTON_X] = ((reading.Buttons & GamepadButtons::X) == GamepadButtons::X); - currentGamepadState[i][GAMEPAD_XBOX_BUTTON_Y] = ((reading.Buttons & GamepadButtons::Y) == GamepadButtons::Y); - currentGamepadState[i][GAMEPAD_XBOX_BUTTON_LB] = ((reading.Buttons & GamepadButtons::LeftShoulder) == GamepadButtons::LeftShoulder); - currentGamepadState[i][GAMEPAD_XBOX_BUTTON_RB] = ((reading.Buttons & GamepadButtons::RightShoulder) == GamepadButtons::RightShoulder); - currentGamepadState[i][GAMEPAD_XBOX_BUTTON_SELECT] = ((reading.Buttons & GamepadButtons::View) == GamepadButtons::View); // Changed for XB1 Controller - currentGamepadState[i][GAMEPAD_XBOX_BUTTON_START] = ((reading.Buttons & GamepadButtons::Menu) == GamepadButtons::Menu); // Changed for XB1 Controller - currentGamepadState[i][GAMEPAD_XBOX_BUTTON_UP] = ((reading.Buttons & GamepadButtons::DPadUp) == GamepadButtons::DPadUp); - currentGamepadState[i][GAMEPAD_XBOX_BUTTON_RIGHT] = ((reading.Buttons & GamepadButtons::DPadRight) == GamepadButtons::DPadRight); - currentGamepadState[i][GAMEPAD_XBOX_BUTTON_DOWN] = ((reading.Buttons & GamepadButtons::DPadLeft) == GamepadButtons::DPadDown); - currentGamepadState[i][GAMEPAD_XBOX_BUTTON_LEFT] = ((reading.Buttons & GamepadButtons::DPadDown) == GamepadButtons::DPadLeft); - currentGamepadState[i][GAMEPAD_XBOX_BUTTON_HOME] = false; // Home button not supported by UWP - - // Get current axis state - gamepadAxisState[i][GAMEPAD_XBOX_AXIS_LEFT_X] = reading.LeftThumbstickX; - gamepadAxisState[i][GAMEPAD_XBOX_AXIS_LEFT_Y] = reading.LeftThumbstickY; - gamepadAxisState[i][GAMEPAD_XBOX_AXIS_RIGHT_X] = reading.RightThumbstickX; - gamepadAxisState[i][GAMEPAD_XBOX_AXIS_RIGHT_Y] = reading.RightThumbstickY; - gamepadAxisState[i][GAMEPAD_XBOX_AXIS_LT] = reading.LeftTrigger; - gamepadAxisState[i][GAMEPAD_XBOX_AXIS_RT] = reading.RightTrigger; - } - } - } - -} - -// The following functions were ripped from core.c and have *no additional work done on them* -// Detect if a key has been pressed once -bool UWPIsKeyPressed(int key) -{ - bool pressed = false; - - if ((currentKeyState[key] != previousKeyState[key]) && (currentKeyState[key] == 1)) pressed = true; - else pressed = false; - - return pressed; -} - -// Detect if a key is being pressed (key held down) -bool UWPIsKeyDown(int key) -{ - if (GetKeyStatus(key) == 1) return true; - else return false; -} - -// Detect if a key has been released once -bool UWPIsKeyReleased(int key) -{ - bool released = false; - - if ((currentKeyState[key] != previousKeyState[key]) && (currentKeyState[key] == 0)) released = true; - else released = false; - - return released; -} - -// Detect if a key is NOT being pressed (key not held down) -bool UWPIsKeyUp(int key) -{ - if (GetKeyStatus(key) == 0) return true; - else return false; -} - -/* OTHER CODE */ - -// Helper to convert a length in device-independent pixels (DIPs) to a length in physical pixels. -inline float ConvertDipsToPixels(float dips, float dpi) -{ - static const float dipsPerInch = 96.0f; - return floor(dips * dpi / dipsPerInch + 0.5f); // Round to nearest integer. -} - -// Implementation of the IFrameworkViewSource interface, necessary to run our app. -ref class SimpleApplicationSource sealed : Windows::ApplicationModel::Core::IFrameworkViewSource -{ -public: - virtual Windows::ApplicationModel::Core::IFrameworkView^ CreateView() - { - return ref new App(); - } -}; - -// The main function creates an IFrameworkViewSource for our app, and runs the app. -[Platform::MTAThread] -int main(Platform::Array^) -{ - auto simpleApplicationSource = ref new SimpleApplicationSource(); - CoreApplication::Run(simpleApplicationSource); - - return 0; -} - -App::App() : - mWindowClosed(false), - mWindowVisible(true) -{ -} - -// The first method called when the IFrameworkView is being created. -void App::Initialize(CoreApplicationView^ applicationView) -{ - // Register event handlers for app lifecycle. This example includes Activated, so that we - // can make the CoreWindow active and start rendering on the window. - applicationView->Activated += ref new TypedEventHandler(this, &App::OnActivated); - - // Logic for other event handlers could go here. - // Information about the Suspending and Resuming event handlers can be found here: - // http://msdn.microsoft.com/en-us/library/windows/apps/xaml/hh994930.aspx - - CoreApplication::Resuming += ref new EventHandler(this, &App::OnResuming); -} - -// Called when the CoreWindow object is created (or re-created). -void App::SetWindow(CoreWindow^ window) -{ - window->SizeChanged += ref new TypedEventHandler(this, &App::OnWindowSizeChanged); - window->VisibilityChanged += ref new TypedEventHandler(this, &App::OnVisibilityChanged); - window->Closed += ref new TypedEventHandler(this, &App::OnWindowClosed); - - window->PointerPressed += ref new TypedEventHandler(this, &App::PointerPressed); - window->PointerReleased += ref new TypedEventHandler(this, &App::PointerReleased); - window->PointerWheelChanged += ref new TypedEventHandler(this, &App::PointerWheelChanged); - window->KeyDown += ref new TypedEventHandler(this, &App::OnKeyDown); - window->KeyUp += ref new TypedEventHandler(this, &App::OnKeyUp); - - Windows::Devices::Input::MouseDevice::GetForCurrentView()->MouseMoved += ref new TypedEventHandler(this, &App::MouseMoved); - - DisplayInformation^ currentDisplayInformation = DisplayInformation::GetForCurrentView(); - currentDisplayInformation->DpiChanged += ref new TypedEventHandler(this, &App::OnDpiChanged); - currentDisplayInformation->OrientationChanged += ref new TypedEventHandler(this, &App::OnOrientationChanged); - - // The CoreWindow has been created, so EGL can be initialized. - - uwpWindow = (EGLNativeWindowType)window; - - InitWindow(800, 450, NULL); -} - -// Initializes scene resources -void App::Load(Platform::String^ entryPoint) -{ - // InitWindow() --> rlglInit() -} - -static int posX = 100; -static int posY = 100; -static int time = 0; -// This method is called after the window becomes active. -void App::Run() -{ - while (!mWindowClosed) - { - if (mWindowVisible) - { - // Draw - BeginDrawing(); - - ClearBackground(RAYWHITE); - - posX += gamepadAxisState[GAMEPAD_PLAYER1][GAMEPAD_XBOX_AXIS_LEFT_X] * 5; - posY += gamepadAxisState[GAMEPAD_PLAYER1][GAMEPAD_XBOX_AXIS_LEFT_Y] * -5; - DrawRectangle(posX, posY, 400, 100, RED); - - DrawLine(0, 0, GetScreenWidth(), GetScreenHeight(), BLUE); - - DrawCircle(mousePosition.x, mousePosition.y, 40, BLUE); - - if (UWPIsKeyDown(KEY_S)) DrawCircle(100, 100, 100, BLUE); - - if (UWPIsKeyPressed(KEY_A)) - { - posX -= 50; - UWPEnableCursor(); - } - - if (UWPIsKeyPressed(KEY_D)) - { - posX += 50; - UWPDisableCursor(); - } - - if (currentKeyState[KEY_LEFT_ALT]) DrawRectangle(250, 250, 20, 20, BLACK); - if (currentKeyState[KEY_BACKSPACE]) DrawRectangle(280, 250, 20, 20, BLACK); - if (currentMouseState[MOUSE_LEFT_BUTTON]) DrawRectangle(280, 250, 20, 20, BLACK); - - static int pos = 0; - pos -= currentMouseWheelY; - - DrawRectangle(280, pos + 50, 20, 20, BLACK); - DrawRectangle(250, 280 + (time++ % 60), 10, 10, PURPLE); - - EndDrawing(); - - UWP_PollInput(); - - CoreWindow::GetForCurrentThread()->Dispatcher->ProcessEvents(CoreProcessEventsOption::ProcessAllIfPresent); - } - else - { - CoreWindow::GetForCurrentThread()->Dispatcher->ProcessEvents(CoreProcessEventsOption::ProcessOneAndAllPending); - } - } - - CloseWindow(); -} - -// Terminate events do not cause Uninitialize to be called. It will be called if your IFrameworkView -// class is torn down while the app is in the foreground. -void App::Uninitialize() -{ - // CloseWindow(); -} - -// Application lifecycle event handler. -void App::OnActivated(CoreApplicationView^ applicationView, IActivatedEventArgs^ args) -{ - // Run() won't start until the CoreWindow is activated. - CoreWindow::GetForCurrentThread()->Activate(); -} - -void App::OnResuming(Object^ sender, Object^ args) -{ - // Restore any data or state that was unloaded on suspend. By default, data - // and state are persisted when resuming from suspend. Note that this event - // does not occur if the app was previously terminated. -} - -void App::OnWindowSizeChanged(CoreWindow^ sender, WindowSizeChangedEventArgs^ args) -{ - // TODO: Update window and render area size - //m_deviceResources->SetLogicalSize(Size(sender->Bounds.Width, sender->Bounds.Height)); - //m_main->UpdateForWindowSizeChange(); -} - -// Window event handlers. -void App::OnVisibilityChanged(CoreWindow^ sender, VisibilityChangedEventArgs^ args) -{ - mWindowVisible = args->Visible; - - // raylib core has the variable windowMinimized to register state, - // it should be modifyed by this event... -} - -void App::OnWindowClosed(CoreWindow^ sender, CoreWindowEventArgs^ args) -{ - mWindowClosed = true; - - // raylib core has the variable windowShouldClose to register state, - // it should be modifyed by this event... -} - -void App::OnDpiChanged(DisplayInformation^ sender, Object^ args) -{ - //m_deviceResources->SetDpi(sender->LogicalDpi); - //m_main->UpdateForWindowSizeChange(); -} - -void App::OnOrientationChanged(DisplayInformation^ sender, Object^ args) -{ - //m_deviceResources->SetCurrentOrientation(sender->CurrentOrientation); - //m_main->UpdateForWindowSizeChange(); -} diff --git a/projects/VS2015.UWP/raylib.App.UWP/App.h b/projects/VS2015.UWP/raylib.App.UWP/App.h deleted file mode 100644 index 5b58528b..00000000 --- a/projects/VS2015.UWP/raylib.App.UWP/App.h +++ /dev/null @@ -1,49 +0,0 @@ -#pragma once - -#include - -#include "pch.h" - -namespace raylibUWP -{ - ref class App sealed : public Windows::ApplicationModel::Core::IFrameworkView - { - public: - App(); - - // IFrameworkView Methods. - virtual void Initialize(Windows::ApplicationModel::Core::CoreApplicationView^ applicationView); - virtual void SetWindow(Windows::UI::Core::CoreWindow^ window); - virtual void Load(Platform::String^ entryPoint); - virtual void Run(); - virtual void Uninitialize(); - - protected: - - // Application lifecycle event handlers. - void OnActivated(Windows::ApplicationModel::Core::CoreApplicationView^ applicationView, Windows::ApplicationModel::Activation::IActivatedEventArgs^ args); - void OnResuming(Platform::Object^ sender, Platform::Object^ args); - - // Window event handlers. - void OnWindowSizeChanged(Windows::UI::Core::CoreWindow^ sender, Windows::UI::Core::WindowSizeChangedEventArgs^ args); - void OnVisibilityChanged(Windows::UI::Core::CoreWindow^ sender, Windows::UI::Core::VisibilityChangedEventArgs^ args); - void OnWindowClosed(Windows::UI::Core::CoreWindow^ sender, Windows::UI::Core::CoreWindowEventArgs^ args); - - // DisplayInformation event handlers. - void OnDpiChanged(Windows::Graphics::Display::DisplayInformation^ sender, Platform::Object^ args); - void OnOrientationChanged(Windows::Graphics::Display::DisplayInformation^ sender, Platform::Object^ args); - - // Input event handlers - void PointerPressed(Windows::UI::Core::CoreWindow^ sender, Windows::UI::Core::PointerEventArgs^ args); - void PointerReleased(Windows::UI::Core::CoreWindow ^sender, Windows::UI::Core::PointerEventArgs^ args); - void PointerWheelChanged(Windows::UI::Core::CoreWindow ^sender, Windows::UI::Core::PointerEventArgs^ args); - void MouseMoved(Windows::Devices::Input::MouseDevice^ mouseDevice, Windows::Devices::Input::MouseEventArgs^ args); - void OnKeyDown(Windows::UI::Core::CoreWindow ^ sender, Windows::UI::Core::KeyEventArgs ^ args); - void OnKeyUp(Windows::UI::Core::CoreWindow ^ sender, Windows::UI::Core::KeyEventArgs ^ args); - - private: - - bool mWindowClosed; - bool mWindowVisible; - }; -} diff --git a/projects/VS2015.UWP/raylib.App.UWP/raylib.App.UWP.user b/projects/VS2015.UWP/raylib.App.UWP/raylib.App.UWP.user deleted file mode 100644 index abe8dd89..00000000 --- a/projects/VS2015.UWP/raylib.App.UWP/raylib.App.UWP.user +++ /dev/null @@ -1,4 +0,0 @@ - - - - \ No newline at end of file diff --git a/projects/VS2015.UWP/raylib/raylib.vcxproj b/projects/VS2015.UWP/raylib/raylib.vcxproj deleted file mode 100644 index ed8eb80b..00000000 --- a/projects/VS2015.UWP/raylib/raylib.vcxproj +++ /dev/null @@ -1,182 +0,0 @@ - - - - - Debug - Win32 - - - Debug - x64 - - - Release - Win32 - - - Release - x64 - - - - {E89D61AC-55DE-4482-AFD4-DF7242EBC859} - Win32Proj - raylib - 10.0.16299.0 - - - - StaticLibrary - true - v140 - Unicode - - - StaticLibrary - true - v140 - Unicode - - - StaticLibrary - false - v140 - true - Unicode - - - StaticLibrary - false - v140 - true - Unicode - - - - - - - - - - - - - - - - - - - - - $(SolutionDir)$(ProjectName)\$(Configuration)\ - - - - $(SolutionDir)$(ProjectName)\$(Configuration)\ - $(SolutionDir)$(ProjectName)\$(Configuration)\temp - - - - - - Level3 - Disabled - WIN32;_DEBUG;_LIB;%(PreprocessorDefinitions);GRAPHICS_API_OPENGL_ES2;PLATFORM_UWP - CompileAsC - $(SolutionDir)..\..\release\include;$(SolutionDir)..\..\src\external\ANGLE - - - Windows - - - %(AdditionalLibraryDirectories) - - - - - - - Level3 - Disabled - WIN32;_DEBUG;_LIB;%(PreprocessorDefinitions);GRAPHICS_API_OPENGL_ES2;PLATFORM_UWP - CompileAsC - $(SolutionDir)..\..\release\include;$(SolutionDir)..\..\src\external\include\ANGLE - - - Windows - - - %(AdditionalLibraryDirectories) - - - - - Level3 - - - MaxSpeed - true - true - WIN32;NDEBUG;_LIB;%(PreprocessorDefinitions);GRAPHICS_API_OPENGL_ES2;PLATFORM_UWP - $(SolutionDir)..\..\src\external\ANGLE;$(SolutionDir)..\..\release\include - CompileAsC - - - Windows - true - true - - - - - Level3 - - - MaxSpeed - true - true - WIN32;NDEBUG;_LIB;%(PreprocessorDefinitions);GRAPHICS_API_OPENGL_ES2;PLATFORM_UWP - $(SolutionDir)..\..\src\external\include\ANGLE;$(SolutionDir)..\..\release\include - CompileAsC - - - Windows - true - true - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/projects/VS2017.UWP/raylib.App.UWP/App.cpp b/projects/VS2017.UWP/raylib.App.UWP/App.cpp new file mode 100644 index 00000000..ae137ed2 --- /dev/null +++ b/projects/VS2017.UWP/raylib.App.UWP/App.cpp @@ -0,0 +1,78 @@ +#include "pch.h" +#include "app.h" + +#include "raylib.h" + +using namespace raylibUWP; + +// The main function creates an IFrameworkViewSource for our app, and runs the app. +[Platform::MTAThread] +int main(Platform::Array^) +{ + auto appSource = ref new ApplicationSource(); + CoreApplication::Run(appSource); + + return 0; +} + +App::App() +{ + //This does not work... need to fix this. + SetConfigFlags(0); + + Setup(640, 480); +} + +static int posX = 100; +static int posY = 100; +static int gTime = 0; + +// This method is called every frame +void App::Update() +{ + //return; + // Draw + BeginDrawing(); + + ClearBackground(RAYWHITE); + + posX += GetGamepadAxisMovement(GAMEPAD_PLAYER1, GAMEPAD_XBOX_AXIS_LEFT_X) * 5; + posY += GetGamepadAxisMovement(GAMEPAD_PLAYER1, GAMEPAD_XBOX_AXIS_LEFT_Y) * -5; + + DrawRectangle(posX, posY, 400, 100, RED); + + DrawLine(0, 0, GetScreenWidth(), GetScreenHeight(), BLUE); + + auto mPos = GetMousePosition(); + + DrawCircle(mPos.x, mPos.y, 40, BLUE); + + if (IsKeyDown(KEY_S)) DrawCircle(100, 100, 100, BLUE); + + if (IsKeyPressed(KEY_A)) + { + posX -= 50; + EnableCursor(); + } + + if (IsKeyPressed(KEY_D)) + { + posX += 50; + DisableCursor(); + } + + if (IsKeyDown(KEY_LEFT_ALT)) + DrawRectangle(250, 250, 20, 20, BLACK); + if (IsKeyDown(KEY_BACKSPACE)) + DrawRectangle(280, 250, 20, 20, BLACK); + if (IsMouseButtonDown(MOUSE_LEFT_BUTTON)) + DrawRectangle(280, 250, 20, 20, BLACK); + + static int pos = 0; + pos -= GetMouseWheelMove(); + + DrawRectangle(280, pos + 50, 20, 20, BLACK); + DrawRectangle(250, 280 + (gTime++ % 60), 10, 10, PURPLE); + + EndDrawing(); +} \ No newline at end of file diff --git a/projects/VS2017.UWP/raylib.App.UWP/App.h b/projects/VS2017.UWP/raylib.App.UWP/App.h new file mode 100644 index 00000000..26c1d400 --- /dev/null +++ b/projects/VS2017.UWP/raylib.App.UWP/App.h @@ -0,0 +1,25 @@ +#pragma once + +#include + +#include "pch.h" + +//Define what header we use for BaseApp.h +#define PCH "pch.h" + +//Enable hold hack +#define HOLDHACK + +#include "BaseApp.h" + +namespace raylibUWP +{ + ref class App sealed : public BaseApp + { + public: + App(); + + // IFrameworkView Methods. + void Update() override; + }; +} diff --git a/projects/VS2015.UWP/raylib.App.UWP/Assets/Logo.scale-100.png b/projects/VS2017.UWP/raylib.App.UWP/Assets/Logo.scale-100.png similarity index 100% rename from projects/VS2015.UWP/raylib.App.UWP/Assets/Logo.scale-100.png rename to projects/VS2017.UWP/raylib.App.UWP/Assets/Logo.scale-100.png diff --git a/projects/VS2015.UWP/raylib.App.UWP/Assets/SmallLogo.scale-100.png b/projects/VS2017.UWP/raylib.App.UWP/Assets/SmallLogo.scale-100.png similarity index 100% rename from projects/VS2015.UWP/raylib.App.UWP/Assets/SmallLogo.scale-100.png rename to projects/VS2017.UWP/raylib.App.UWP/Assets/SmallLogo.scale-100.png diff --git a/projects/VS2015.UWP/raylib.App.UWP/Assets/SplashScreen.scale-100.png b/projects/VS2017.UWP/raylib.App.UWP/Assets/SplashScreen.scale-100.png similarity index 100% rename from projects/VS2015.UWP/raylib.App.UWP/Assets/SplashScreen.scale-100.png rename to projects/VS2017.UWP/raylib.App.UWP/Assets/SplashScreen.scale-100.png diff --git a/projects/VS2015.UWP/raylib.App.UWP/Assets/StoreLogo.scale-100.png b/projects/VS2017.UWP/raylib.App.UWP/Assets/StoreLogo.scale-100.png similarity index 100% rename from projects/VS2015.UWP/raylib.App.UWP/Assets/StoreLogo.scale-100.png rename to projects/VS2017.UWP/raylib.App.UWP/Assets/StoreLogo.scale-100.png diff --git a/projects/VS2015.UWP/raylib.App.UWP/Assets/WideLogo.scale-100.png b/projects/VS2017.UWP/raylib.App.UWP/Assets/WideLogo.scale-100.png similarity index 100% rename from projects/VS2015.UWP/raylib.App.UWP/Assets/WideLogo.scale-100.png rename to projects/VS2017.UWP/raylib.App.UWP/Assets/WideLogo.scale-100.png diff --git a/projects/VS2017.UWP/raylib.App.UWP/BaseApp.h b/projects/VS2017.UWP/raylib.App.UWP/BaseApp.h new file mode 100644 index 00000000..e27909e2 --- /dev/null +++ b/projects/VS2017.UWP/raylib.App.UWP/BaseApp.h @@ -0,0 +1,567 @@ +/********************************************************************************************** +* +* raylib.BaseApp - UWP App generic code for managing interface between C and C++ +* +* LICENSE: zlib/libpng +* +* CONFIGURATION: +* +* #define PCH +* This defines what header is the PCH and needs to be included +* +* #define HOLDHACK +* This enables a hack to fix flickering key presses (Temporary) +* +* Copyright (c) 2013-2019 Ramon Santamaria (@raysan5) +* +* This software is provided "as-is", without any express or implied warranty. In no event +* will the authors be held liable for any damages arising from the use of this software. +* +* Permission is granted to anyone to use this software for any purpose, including commercial +* applications, and to alter it and redistribute it freely, subject to the following restrictions: +* +* 1. The origin of this software must not be misrepresented; you must not claim that you +* wrote the original software. If you use this software in a product, an acknowledgment +* in the product documentation would be appreciated but is not required. +* +* 2. Altered source versions must be plainly marked as such, and must not be misrepresented +* as being the original software. +* +* 3. This notice may not be removed or altered from any source distribution. +* +**********************************************************************************************/ + +#pragma once + +#if defined(PCH) +#include PCH +#endif + +#include +#include +#include + +//EGL +#include + +#include "raylib.h" +#include "utils.h" + +using namespace Windows::ApplicationModel::Core; +using namespace Windows::ApplicationModel::Activation; +using namespace Windows::UI::Core; +using namespace Windows::UI::Input; +using namespace Windows::Devices::Input; +using namespace Windows::Foundation; +using namespace Windows::Foundation::Collections; +using namespace Windows::Gaming::Input; +using namespace Windows::Graphics::Display; +using namespace Microsoft::WRL; +using namespace Platform; + +extern "C" { EGLNativeWindowType uwpWindow; }; + +/* +TODO list: + - Cache reference to our CoreWindow? + - Implement gestures support +*/ + +// Stand-ins for "core.c" variables +#define MAX_GAMEPADS 4 // Max number of gamepads supported +#define MAX_GAMEPAD_BUTTONS 32 // Max bumber of buttons supported (per gamepad) +#define MAX_GAMEPAD_AXIS 8 // Max number of axis supported (per gamepad) + +//Mouse cursor locking +bool cursorLocked = false; +Vector2 mouseDelta = {0, 0}; + +//Our mouse cursor +CoreCursor ^regularCursor = ref new CoreCursor(CoreCursorType::Arrow, 0); // The "visible arrow" cursor type + +//Base app implementation +ref class BaseApp : public Windows::ApplicationModel::Core::IFrameworkView +{ +public: + + // IFrameworkView Methods. + virtual void Initialize(Windows::ApplicationModel::Core::CoreApplicationView^ applicationView) + { + // Register event handlers for app lifecycle. This example includes Activated, so that we + // can make the CoreWindow active and start rendering on the window. + applicationView->Activated += ref new TypedEventHandler(this, &BaseApp::OnActivated); + + // Logic for other event handlers could go here. + // Information about the Suspending and Resuming event handlers can be found here: + // http://msdn.microsoft.com/en-us/library/windows/apps/xaml/hh994930.aspx + + CoreApplication::Resuming += ref new EventHandler(this, &BaseApp::OnResuming); + } + + virtual void SetWindow(Windows::UI::Core::CoreWindow^ window) + { + window->SizeChanged += ref new TypedEventHandler(this, &BaseApp::OnWindowSizeChanged); + window->VisibilityChanged += ref new TypedEventHandler(this, &BaseApp::OnVisibilityChanged); + window->Closed += ref new TypedEventHandler(this, &BaseApp::OnWindowClosed); + + window->PointerPressed += ref new TypedEventHandler(this, &BaseApp::PointerPressed); + window->PointerWheelChanged += ref new TypedEventHandler(this, &BaseApp::PointerWheelChanged); + window->KeyDown += ref new TypedEventHandler(this, &BaseApp::OnKeyDown); + window->KeyUp += ref new TypedEventHandler(this, &BaseApp::OnKeyUp); + + Windows::Devices::Input::MouseDevice::GetForCurrentView()->MouseMoved += ref new TypedEventHandler(this, &BaseApp::MouseMoved); + + DisplayInformation^ currentDisplayInformation = DisplayInformation::GetForCurrentView(); + currentDisplayInformation->DpiChanged += ref new TypedEventHandler(this, &BaseApp::OnDpiChanged); + currentDisplayInformation->OrientationChanged += ref new TypedEventHandler(this, &BaseApp::OnOrientationChanged); + + // The CoreWindow has been created, so EGL can be initialized. + + uwpWindow = (EGLNativeWindowType)window; + + InitWindow(width, height, NULL); + } + + virtual void Load(Platform::String^ entryPoint) {} + + void Setup(int width, int height) + { + //Set dimensions + this->width = width; + this->height = height; + } + + virtual void Run() + { + //Get display dimensions + DisplayInformation^ dInfo = DisplayInformation::GetForCurrentView(); + Vector2 screenSize = { dInfo->ScreenWidthInRawPixels, dInfo->ScreenHeightInRawPixels }; + + //Send display dimensions + UWPMessage* msg = CreateUWPMessage(); + msg->Type = SetDisplayDims; + msg->Vector0 = screenSize; + UWPSendMessage(msg); + + //Send the time to the core + using clock = std::chrono::high_resolution_clock; + auto timeStart = clock::now(); + + //Set fps if 0 + if (GetFPS() <= 0) + SetTargetFPS(60); + + while (!mWindowClosed) + { + if (mWindowVisible) + { + //Send time + auto delta = clock::now() - timeStart; + + UWPMessage* timeMsg = CreateUWPMessage(); + timeMsg->Type = SetGameTime; + timeMsg->Double0 = std::chrono::duration_cast(delta).count(); + UWPSendMessage(timeMsg); + + //Call update function + Update(); + + PollInput(); + + CoreWindow::GetForCurrentThread()->Dispatcher->ProcessEvents(CoreProcessEventsOption::ProcessAllIfPresent); + } + else + { + CoreWindow::GetForCurrentThread()->Dispatcher->ProcessEvents(CoreProcessEventsOption::ProcessOneAndAllPending); + } + } + + CloseWindow(); + } + + //Called every frame (Maybe add draw) + virtual void Update() {} + + virtual void Uninitialize() {} + +protected: + + // Input polling + void PollInput() + { + // Process Messages + { + //Loop over pending messages + while (UWPHasMessages()) + { + //Get the message + auto msg = UWPGetMessage(); + + //Carry out the command + switch(msg->Type) + { + case ShowMouse: //Do the same thing because of how UWP works... + case UnlockMouse: + { + CoreWindow::GetForCurrentThread()->PointerCursor = regularCursor; + cursorLocked = false; + MoveMouse(GetMousePosition()); + break; + } + case HideMouse: //Do the same thing because of how UWP works... + case LockMouse: + { + CoreWindow::GetForCurrentThread()->PointerCursor = nullptr; + cursorLocked = true; + break; + } + case SetMouseLocation: + { + MoveMouse(msg->Vector0); + break; + } + } + + //Delete the message + DeleteUWPMessage(msg); + } + } + + // Process Keyboard + { + for (int k = 0x08; k < 0xA6; k++) { + auto state = CoreWindow::GetForCurrentThread()->GetKeyState((Windows::System::VirtualKey) k); + +#ifdef HOLDHACK + //Super hacky way of waiting three frames to see if we are ready to register the key as deregistered + //This will wait an entire 4 frames before deregistering the key, this makes sure that the key is not flickering + if (KeyboardStateHack[k] == 2) + { + if ((state & CoreVirtualKeyStates::None) == CoreVirtualKeyStates::None) + { + KeyboardStateHack[k] = 3; + } + } + else if (KeyboardStateHack[k] == 3) + { + if ((state & CoreVirtualKeyStates::None) == CoreVirtualKeyStates::None) + { + KeyboardStateHack[k] = 4; + } + } + else if (KeyboardStateHack[k] == 4) + { + if ((state & CoreVirtualKeyStates::None) == CoreVirtualKeyStates::None) + { + //Reset key... + KeyboardStateHack[k] = 0; + + //Tell core + RegisterKey(k, 0); + } + } +#endif + //Left and right alt, KeyUp and KeyDown are not called for it + //No need to hack because this is not a character + + //TODO: Maybe do all other key registrations like this, no more key events? + + if (k == 0xA4 || k == 0xA5) + { + if ((state & CoreVirtualKeyStates::Down) == CoreVirtualKeyStates::Down) + { + RegisterKey(k, 1); + } + else + { + RegisterKey(k, 0); + } + } + } + } + + // Process Mouse + { + + if (CurrentPointerID > -1) { + auto point = PointerPoint::GetCurrentPoint(CurrentPointerID); + auto props = point->Properties; + + if (props->IsLeftButtonPressed) + { + RegisterClick(MOUSE_LEFT_BUTTON, 1); + } + else + { + RegisterClick(MOUSE_LEFT_BUTTON, 0); + } + + if (props->IsRightButtonPressed) + { + RegisterClick(MOUSE_RIGHT_BUTTON, 1); + } + else + { + RegisterClick(MOUSE_RIGHT_BUTTON, 0); + } + + if (props->IsMiddleButtonPressed) + { + RegisterClick(MOUSE_MIDDLE_BUTTON, 1); + } + else + { + RegisterClick(MOUSE_MIDDLE_BUTTON, 0); + } + } + + CoreWindow ^window = CoreWindow::GetForCurrentThread(); + + if (cursorLocked) + { + // Track cursor movement delta, recenter it on the client + auto curMousePos = GetMousePosition(); + + auto x = curMousePos.x + mouseDelta.x; + auto y = curMousePos.y + mouseDelta.y; + + UpdateMousePosition({ x, y }); + + // Why we're not using UWPSetMousePosition here... + // UWPSetMousePosition changes the "mousePosition" variable to match where the cursor actually is. + // Our cursor is locked to the middle of screen, and we don't want that reflected in "mousePosition" + Vector2 centerClient = { (float)(GetScreenWidth() / 2), (float)(GetScreenHeight() / 2) }; + window->PointerPosition = Point(centerClient.x + window->Bounds.X, centerClient.y + window->Bounds.Y); + } + else + { + // Record the cursor's position relative to the client + auto x = window->PointerPosition.X - window->Bounds.X; + auto y = window->PointerPosition.Y - window->Bounds.Y; + + UpdateMousePosition({ x, y }); + } + + mouseDelta = { 0 ,0 }; + } + + // Process Gamepads + { + // Check if gamepads are ready + for (int i = 0; i < MAX_GAMEPADS; i++) + { + // HACK: UWP keeps a contiguous list of gamepads. For the interest of time I'm just doing a 1:1 mapping of + // connected gamepads with their spot in the list, but this has serious robustness problems + // 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. + + UWPMessage* msg = CreateUWPMessage(); + msg->Type = MarkGamepadActive; + msg->Int0 = i; + msg->Bool0 = i < Gamepad::Gamepads->Size; + UWPSendMessage(msg); + } + + // Get current gamepad state + for (int i = 0; i < MAX_GAMEPADS; i++) + { + if (IsGamepadAvailable(i)) + { + // Get current gamepad state + auto gamepad = Gamepad::Gamepads->GetAt(i); + GamepadReading reading = gamepad->GetCurrentReading(); + + // NOTE: Maybe it would be wiser to redefine the gamepad button mappings in "raylib.h" for the UWP platform instead of remapping them manually + RegisterGamepadButton(i, GAMEPAD_XBOX_BUTTON_A, ((reading.Buttons & GamepadButtons::A) == GamepadButtons::A)); + RegisterGamepadButton(i, GAMEPAD_XBOX_BUTTON_B, ((reading.Buttons & GamepadButtons::B) == GamepadButtons::B)); + RegisterGamepadButton(i, GAMEPAD_XBOX_BUTTON_X, ((reading.Buttons & GamepadButtons::X) == GamepadButtons::X)); + RegisterGamepadButton(i, GAMEPAD_XBOX_BUTTON_Y, ((reading.Buttons & GamepadButtons::Y) == GamepadButtons::Y)); + RegisterGamepadButton(i, GAMEPAD_XBOX_BUTTON_LB, ((reading.Buttons & GamepadButtons::LeftShoulder) == GamepadButtons::LeftShoulder)); + RegisterGamepadButton(i, GAMEPAD_XBOX_BUTTON_RB, ((reading.Buttons & GamepadButtons::RightShoulder) == GamepadButtons::RightShoulder)); + RegisterGamepadButton(i, GAMEPAD_XBOX_BUTTON_SELECT, ((reading.Buttons & GamepadButtons::View) == GamepadButtons::View)); // Changed for XB1 Controller + RegisterGamepadButton(i, GAMEPAD_XBOX_BUTTON_START, ((reading.Buttons & GamepadButtons::Menu) == GamepadButtons::Menu)); // Changed for XB1 Controller + RegisterGamepadButton(i, GAMEPAD_XBOX_BUTTON_UP, ((reading.Buttons & GamepadButtons::DPadUp) == GamepadButtons::DPadUp)); + RegisterGamepadButton(i, GAMEPAD_XBOX_BUTTON_RIGHT, ((reading.Buttons & GamepadButtons::DPadRight) == GamepadButtons::DPadRight)); + RegisterGamepadButton(i, GAMEPAD_XBOX_BUTTON_DOWN, ((reading.Buttons & GamepadButtons::DPadDown) == GamepadButtons::DPadDown)); + RegisterGamepadButton(i, GAMEPAD_XBOX_BUTTON_LEFT, ((reading.Buttons & GamepadButtons::DPadLeft) == GamepadButtons::DPadLeft)); + RegisterGamepadButton(i, GAMEPAD_XBOX_BUTTON_HOME, false); // Home button not supported by UWP + + // Get current axis state + RegisterGamepadAxis(i, GAMEPAD_XBOX_AXIS_LEFT_X, (float)reading.LeftThumbstickX); + RegisterGamepadAxis(i, GAMEPAD_XBOX_AXIS_LEFT_Y, (float)reading.LeftThumbstickY); + RegisterGamepadAxis(i, GAMEPAD_XBOX_AXIS_RIGHT_X, (float)reading.RightThumbstickX); + RegisterGamepadAxis(i, GAMEPAD_XBOX_AXIS_RIGHT_Y, (float)reading.RightThumbstickY); + RegisterGamepadAxis(i, GAMEPAD_XBOX_AXIS_LT, (float)reading.LeftTrigger); + RegisterGamepadAxis(i, GAMEPAD_XBOX_AXIS_RT, (float)reading.RightTrigger); + } + } + } + } + + // Application lifecycle event handlers. + void OnActivated(Windows::ApplicationModel::Core::CoreApplicationView^ applicationView, Windows::ApplicationModel::Activation::IActivatedEventArgs^ args) + { + // Run() won't start until the CoreWindow is activated. + CoreWindow::GetForCurrentThread()->Activate(); + } + + void OnResuming(Platform::Object^ sender, Platform::Object^ args) {} + + // Window event handlers. + void OnWindowSizeChanged(Windows::UI::Core::CoreWindow^ sender, Windows::UI::Core::WindowSizeChangedEventArgs^ args) + { + UWPMessage* msg = CreateUWPMessage(); + msg->Type = HandleResize; + UWPSendMessage(msg); + } + + void OnVisibilityChanged(Windows::UI::Core::CoreWindow^ sender, Windows::UI::Core::VisibilityChangedEventArgs^ args) + { + mWindowVisible = args->Visible; + } + + void OnWindowClosed(Windows::UI::Core::CoreWindow^ sender, Windows::UI::Core::CoreWindowEventArgs^ args) + { + mWindowClosed = true; + } + + // DisplayInformation event handlers. + void OnDpiChanged(Windows::Graphics::Display::DisplayInformation^ sender, Platform::Object^ args) {} + void OnOrientationChanged(Windows::Graphics::Display::DisplayInformation^ sender, Platform::Object^ args) {} + + // Input event handlers + void PointerPressed(Windows::UI::Core::CoreWindow^ sender, Windows::UI::Core::PointerEventArgs^ args) + { + //Get the current active pointer ID for our loop + CurrentPointerID = args->CurrentPoint->PointerId; + args->Handled = true; + } + + void PointerWheelChanged(Windows::UI::Core::CoreWindow ^sender, Windows::UI::Core::PointerEventArgs^ args) + { + UWPMessage* msg = CreateUWPMessage(); + msg->Type = ScrollWheelUpdate; + msg->Float0 = args->CurrentPoint->Properties->MouseWheelDelta; + UWPSendMessage(msg); + } + + void MouseMoved(Windows::Devices::Input::MouseDevice^ mouseDevice, Windows::Devices::Input::MouseEventArgs^ args) + { + mouseDelta.x += args->MouseDelta.X; + mouseDelta.y += args->MouseDelta.Y; + } + + void OnKeyDown(Windows::UI::Core::CoreWindow ^ sender, Windows::UI::Core::KeyEventArgs ^ args) + { +#ifdef HOLDHACK + //Start the hack + KeyboardStateHack[(int)args->VirtualKey] = 1; +#endif + + RegisterKey((int)args->VirtualKey, 1); + } + + void OnKeyUp(Windows::UI::Core::CoreWindow ^ sender, Windows::UI::Core::KeyEventArgs ^ args) + { +#ifdef HOLDHACK + //The same hack + if (KeyboardStateHack[(int)args->VirtualKey] == 1) + { + KeyboardStateHack[(int)args->VirtualKey] = 2; + } + else if (KeyboardStateHack[(int)args->VirtualKey] == 2) + { + KeyboardStateHack[(int)args->VirtualKey] = 3; + } + else if (KeyboardStateHack[(int)args->VirtualKey] == 3) + { + KeyboardStateHack[(int)args->VirtualKey] = 4; + } + else if (KeyboardStateHack[(int)args->VirtualKey] == 4) + { + RegisterKey((int)args->VirtualKey, 0); + KeyboardStateHack[(int)args->VirtualKey] = 0; + } +#else + //No hack, allow flickers + RegisterKey((int)args->VirtualKey, 0); +#endif + } + +private: + + void RegisterKey(int key, char status) + { + UWPMessage* msg = CreateUWPMessage(); + msg->Type = UWPMessageType::RegisterKey; + msg->Int0 = key; + msg->Char0 = status; + UWPSendMessage(msg); + } + + void MoveMouse(Vector2 pos) + { + CoreWindow ^window = CoreWindow::GetForCurrentThread(); + Point mousePosScreen = Point(pos.x + window->Bounds.X, pos.y + window->Bounds.Y); + window->PointerPosition = mousePosScreen; + } + + void RegisterGamepadButton(int gamepad, int button, char status) + { + UWPMessage* msg = CreateUWPMessage(); + msg->Type = MarkGamepadButton; + msg->Int0 = gamepad; + msg->Int1 = button; + msg->Char0 = status; + UWPSendMessage(msg); + } + + void RegisterGamepadAxis(int gamepad, int axis, float value) + { + UWPMessage* msg = CreateUWPMessage(); + msg->Type = MarkGamepadAxis; + msg->Int0 = gamepad; + msg->Int1 = axis; + msg->Float0 = value; + UWPSendMessage(msg); + } + + void UpdateMousePosition(Vector2 pos) + { + UWPMessage* msg = CreateUWPMessage(); + msg->Type = UpdateMouseLocation; + msg->Vector0 = pos; + UWPSendMessage(msg); + } + + void RegisterClick(int button, char status) + { + UWPMessage* msg = CreateUWPMessage(); + msg->Type = UWPMessageType::RegisterClick; + msg->Int0 = button; + msg->Char0 = status; + UWPSendMessage(msg); + } + + bool mWindowClosed = false; + bool mWindowVisible = true; + + int width = 640; + int height = 480; + + int CurrentPointerID = -1; + +#ifdef HOLDHACK + char KeyboardStateHack[0xA6]; //0xA6 because the highest key we compare against is 0xA5 +#endif +}; + +//Application source for creating the program +template +ref class ApplicationSource sealed : Windows::ApplicationModel::Core::IFrameworkViewSource +{ +public: + virtual Windows::ApplicationModel::Core::IFrameworkView^ CreateView() + { + return ref new AppType(); + } +}; \ No newline at end of file diff --git a/projects/VS2015.UWP/raylib.App.UWP/Package.appxmanifest b/projects/VS2017.UWP/raylib.App.UWP/Package.appxmanifest similarity index 100% rename from projects/VS2015.UWP/raylib.App.UWP/Package.appxmanifest rename to projects/VS2017.UWP/raylib.App.UWP/Package.appxmanifest diff --git a/projects/VS2015.UWP/raylib.App.UWP/packages.config b/projects/VS2017.UWP/raylib.App.UWP/packages.config similarity index 100% rename from projects/VS2015.UWP/raylib.App.UWP/packages.config rename to projects/VS2017.UWP/raylib.App.UWP/packages.config diff --git a/projects/VS2015.UWP/raylib.App.UWP/pch.cpp b/projects/VS2017.UWP/raylib.App.UWP/pch.cpp similarity index 100% rename from projects/VS2015.UWP/raylib.App.UWP/pch.cpp rename to projects/VS2017.UWP/raylib.App.UWP/pch.cpp diff --git a/projects/VS2015.UWP/raylib.App.UWP/pch.h b/projects/VS2017.UWP/raylib.App.UWP/pch.h similarity index 100% rename from projects/VS2015.UWP/raylib.App.UWP/pch.h rename to projects/VS2017.UWP/raylib.App.UWP/pch.h diff --git a/projects/VS2015.UWP/raylib.App.UWP/raylib.App.UWP.TemporaryKey.pfx b/projects/VS2017.UWP/raylib.App.UWP/raylib.App.UWP.TemporaryKey.pfx similarity index 100% rename from projects/VS2015.UWP/raylib.App.UWP/raylib.App.UWP.TemporaryKey.pfx rename to projects/VS2017.UWP/raylib.App.UWP/raylib.App.UWP.TemporaryKey.pfx diff --git a/projects/VS2015.UWP/raylib.App.UWP/raylib.App.UWP.filters b/projects/VS2017.UWP/raylib.App.UWP/raylib.App.UWP.filters similarity index 100% rename from projects/VS2015.UWP/raylib.App.UWP/raylib.App.UWP.filters rename to projects/VS2017.UWP/raylib.App.UWP/raylib.App.UWP.filters diff --git a/projects/VS2015.UWP/raylib.App.UWP/raylib.App.UWP.vcxproj b/projects/VS2017.UWP/raylib.App.UWP/raylib.App.UWP.vcxproj similarity index 89% rename from projects/VS2015.UWP/raylib.App.UWP/raylib.App.UWP.vcxproj rename to projects/VS2017.UWP/raylib.App.UWP/raylib.App.UWP.vcxproj index f20a276e..421d7209 100644 --- a/projects/VS2015.UWP/raylib.App.UWP/raylib.App.UWP.vcxproj +++ b/projects/VS2017.UWP/raylib.App.UWP/raylib.App.UWP.vcxproj @@ -33,8 +33,8 @@ 14.0 true Windows Store - 10.0.14393.0 - 10.0.14393.0 + 10.0.17763.0 + 10.0.17763.0 10.0 raylib.App.UWP @@ -42,7 +42,7 @@ Application true - v140 + v141 Application @@ -64,19 +64,19 @@ - mincore.lib;raylib.lib;%(AdditionalDependencies) + mincore.lib;%(AdditionalDependencies) %(AdditionalLibraryDirectories);$(VCInstallDir)\lib\store\arm;$(VCInstallDir)\lib\arm;$(SolutionDir)\raylib\Debug - mincore.lib;raylib.lib;%(AdditionalDependencies) + mincore.lib;%(AdditionalDependencies) $(SolutionDir)raylib\Debug;%(AdditionalLibraryDirectories); $(VCInstallDir)\lib\store; $(VCInstallDir)\lib - mincore.lib;raylib.lib;%(AdditionalDependencies) + mincore.lib;%(AdditionalDependencies) C:\Users\Sam\Documents\GitHub\raylib\project\vs2015.UWP\x64\Debug;C:\Users\Alumno\Downloads\angle\UWP_OpenGLES2\raylib;%(AdditionalLibraryDirectories);$(VCInstallDir)\lib\store\amd64;$(VCInstallDir)\lib\amd64 @@ -87,7 +87,7 @@ $(SolutionDir)..\..\src;$(ProjectDir);$(IntermediateOutputPath);%(AdditionalIncludeDirectories) /bigobj %(AdditionalOptions) 4453;28204 - _DEBUG;%(PreprocessorDefinitions) + PLATFORM_UWP;_DEBUG;%(PreprocessorDefinitions) true @@ -100,7 +100,7 @@ $(SolutionDir)..\..\src;$(ProjectDir);$(IntermediateOutputPath);%(AdditionalIncludeDirectories) /bigobj %(AdditionalOptions) 4453;28204 - NDEBUG;%(PreprocessorDefinitions) + PLATFORM_UWP;NDEBUG;%(PreprocessorDefinitions) Default false @@ -117,6 +117,7 @@ + @@ -132,6 +133,11 @@ + + + {ea91e088-7c71-4f32-b761-e054305cd519} + + diff --git a/projects/VS2015.UWP/raylib.UWP.sln b/projects/VS2017.UWP/raylib.UWP.sln similarity index 64% rename from projects/VS2015.UWP/raylib.UWP.sln rename to projects/VS2017.UWP/raylib.UWP.sln index 087e84f4..fb528655 100644 --- a/projects/VS2015.UWP/raylib.UWP.sln +++ b/projects/VS2017.UWP/raylib.UWP.sln @@ -1,11 +1,11 @@  Microsoft Visual Studio Solution File, Format Version 12.00 -# Visual Studio 14 -VisualStudioVersion = 14.0.25420.1 +# Visual Studio 15 +VisualStudioVersion = 15.0.28307.438 MinimumVisualStudioVersion = 10.0.40219.1 Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "raylib.App.UWP", "raylib.App.UWP\raylib.App.UWP.vcxproj", "{B842558C-C034-4E4B-9457-A286F26E83CC}" EndProject -Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "raylib", "raylib\raylib.vcxproj", "{E89D61AC-55DE-4482-AFD4-DF7242EBC859}" +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "raylib.UWP", "raylib.UWP\raylib.UWP.vcxproj", "{EA91E088-7C71-4F32-B761-E054305CD519}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution @@ -35,17 +35,23 @@ Global {B842558C-C034-4E4B-9457-A286F26E83CC}.Release|x86.ActiveCfg = Release|Win32 {B842558C-C034-4E4B-9457-A286F26E83CC}.Release|x86.Build.0 = Release|Win32 {B842558C-C034-4E4B-9457-A286F26E83CC}.Release|x86.Deploy.0 = Release|Win32 - {E89D61AC-55DE-4482-AFD4-DF7242EBC859}.Debug|ARM.ActiveCfg = Debug|Win32 - {E89D61AC-55DE-4482-AFD4-DF7242EBC859}.Debug|ARM.Build.0 = Debug|Win32 - {E89D61AC-55DE-4482-AFD4-DF7242EBC859}.Debug|x64.ActiveCfg = Debug|x64 - {E89D61AC-55DE-4482-AFD4-DF7242EBC859}.Debug|x86.ActiveCfg = Debug|Win32 - {E89D61AC-55DE-4482-AFD4-DF7242EBC859}.Debug|x86.Build.0 = Debug|Win32 - {E89D61AC-55DE-4482-AFD4-DF7242EBC859}.Release|ARM.ActiveCfg = Release|Win32 - {E89D61AC-55DE-4482-AFD4-DF7242EBC859}.Release|x64.ActiveCfg = Release|Win32 - {E89D61AC-55DE-4482-AFD4-DF7242EBC859}.Release|x86.ActiveCfg = Release|Win32 - {E89D61AC-55DE-4482-AFD4-DF7242EBC859}.Release|x86.Build.0 = Release|Win32 + {EA91E088-7C71-4F32-B761-E054305CD519}.Debug|ARM.ActiveCfg = Debug|ARM + {EA91E088-7C71-4F32-B761-E054305CD519}.Debug|ARM.Build.0 = Debug|ARM + {EA91E088-7C71-4F32-B761-E054305CD519}.Debug|x64.ActiveCfg = Debug|x64 + {EA91E088-7C71-4F32-B761-E054305CD519}.Debug|x64.Build.0 = Debug|x64 + {EA91E088-7C71-4F32-B761-E054305CD519}.Debug|x86.ActiveCfg = Debug|Win32 + {EA91E088-7C71-4F32-B761-E054305CD519}.Debug|x86.Build.0 = Debug|Win32 + {EA91E088-7C71-4F32-B761-E054305CD519}.Release|ARM.ActiveCfg = Release|ARM + {EA91E088-7C71-4F32-B761-E054305CD519}.Release|ARM.Build.0 = Release|ARM + {EA91E088-7C71-4F32-B761-E054305CD519}.Release|x64.ActiveCfg = Release|x64 + {EA91E088-7C71-4F32-B761-E054305CD519}.Release|x64.Build.0 = Release|x64 + {EA91E088-7C71-4F32-B761-E054305CD519}.Release|x86.ActiveCfg = Release|Win32 + {EA91E088-7C71-4F32-B761-E054305CD519}.Release|x86.Build.0 = Release|Win32 EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {E32C7998-071A-419B-8869-E957374307CA} + EndGlobalSection EndGlobal diff --git a/projects/VS2017.UWP/raylib.UWP/raylib.UWP.vcxproj b/projects/VS2017.UWP/raylib.UWP/raylib.UWP.vcxproj new file mode 100644 index 00000000..f05f829c --- /dev/null +++ b/projects/VS2017.UWP/raylib.UWP/raylib.UWP.vcxproj @@ -0,0 +1,231 @@ + + + + + Debug + ARM + + + Debug + Win32 + + + Debug + x64 + + + Release + ARM + + + Release + Win32 + + + Release + x64 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + {ea91e088-7c71-4f32-b761-e054305cd519} + StaticLibrary + raylib_UWP + en-US + 14.0 + true + Windows Store + 10.0.17763.0 + 10.0.15063.0 + 10.0 + + + + StaticLibrary + true + v141 + + + StaticLibrary + true + v141 + + + StaticLibrary + true + v141 + + + StaticLibrary + false + true + v141 + + + StaticLibrary + false + true + v141 + + + StaticLibrary + false + true + v141 + + + + + + + + + + + + + + + + + + + + + + + + + + + + false + + + false + + + false + + + false + + + false + + + false + + + + NotUsing + false + true + _CRT_SECURE_NO_WARNINGS;GRAPHICS_API_OPENGL_ES2;PLATFORM_UWP;_UNICODE;UNICODE;%(PreprocessorDefinitions) + $(SolutionDir)..\..\release\include;$(SolutionDir)..\..\src\external\ANGLE;$(ProjectDir);$(GeneratedFilesDir);$(IntDir);%(AdditionalIncludeDirectories) + + + Console + false + false + + + + + NotUsing + false + true + _CRT_SECURE_NO_WARNINGS;GRAPHICS_API_OPENGL_ES2;PLATFORM_UWP;_UNICODE;UNICODE;%(PreprocessorDefinitions) + $(SolutionDir)..\..\release\include;$(SolutionDir)..\..\src\external\ANGLE;$(ProjectDir);$(GeneratedFilesDir);$(IntDir);%(AdditionalIncludeDirectories) + + + Console + false + false + + + + + NotUsing + false + true + _CRT_SECURE_NO_WARNINGS;GRAPHICS_API_OPENGL_ES2;PLATFORM_UWP;_ARM_WINAPI_PARTITION_DESKTOP_SDK_AVAILABLE=1;%(ClCompile.PreprocessorDefinitions) + $(SolutionDir)..\..\release\include;$(SolutionDir)..\..\src\external\ANGLE;$(ProjectDir);$(GeneratedFilesDir);$(IntDir);%(AdditionalIncludeDirectories) + + + Console + false + false + + + + + NotUsing + false + true + _CRT_SECURE_NO_WARNINGS;GRAPHICS_API_OPENGL_ES2;PLATFORM_UWP;_ARM_WINAPI_PARTITION_DESKTOP_SDK_AVAILABLE=1;%(ClCompile.PreprocessorDefinitions) + $(SolutionDir)..\..\release\include;$(SolutionDir)..\..\src\external\ANGLE;$(ProjectDir);$(GeneratedFilesDir);$(IntDir);%(AdditionalIncludeDirectories) + + + Console + false + false + + + + + NotUsing + false + true + _CRT_SECURE_NO_WARNINGS;GRAPHICS_API_OPENGL_ES2;PLATFORM_UWP;_UNICODE;UNICODE;%(PreprocessorDefinitions) + $(SolutionDir)..\..\release\include;$(SolutionDir)..\..\src\external\ANGLE;$(ProjectDir);$(GeneratedFilesDir);$(IntDir);%(AdditionalIncludeDirectories) + + + Console + false + false + + + + + NotUsing + false + true + _CRT_SECURE_NO_WARNINGS;GRAPHICS_API_OPENGL_ES2;PLATFORM_UWP;_UNICODE;UNICODE;%(PreprocessorDefinitions) + $(SolutionDir)..\..\release\include;$(SolutionDir)..\..\src\external\ANGLE;$(ProjectDir);$(GeneratedFilesDir);$(IntDir);%(AdditionalIncludeDirectories) + + + Console + false + false + + + + + + \ No newline at end of file diff --git a/projects/VS2017.UWP/raylib.UWP/raylib.UWP.vcxproj.filters b/projects/VS2017.UWP/raylib.UWP/raylib.UWP.vcxproj.filters new file mode 100644 index 00000000..cbad7c9b --- /dev/null +++ b/projects/VS2017.UWP/raylib.UWP/raylib.UWP.vcxproj.filters @@ -0,0 +1,29 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/src/camera.h b/src/camera.h index e103b293..d80f8346 100644 --- a/src/camera.h +++ b/src/camera.h @@ -256,7 +256,7 @@ void SetCameraMode(Camera camera, int mode) //cameraAngle.y = -60.0f*DEG2RAD; // Camera angle in plane XY (0 aligned with X, move positive CW) playerEyesPosition = camera.position.y; - + // Lock cursor for first person and third person cameras if ((mode == CAMERA_FIRST_PERSON) || (mode == CAMERA_THIRD_PERSON)) DisableCursor(); else EnableCursor(); diff --git a/src/core.c b/src/core.c index 448ad668..7977d0ad 100644 --- a/src/core.c +++ b/src/core.c @@ -134,7 +134,7 @@ #include // Required for: tolower() [Used in IsFileExtension()] #include // Required for stat() [Used in GetLastWriteTime()] -#if defined(PLATFORM_DESKTOP) && defined(_WIN32) && (defined(_MSC_VER) || defined(__TINYC__)) +#if (defined(PLATFORM_DESKTOP) || defined(PLATFORM_UWP)) && defined(_WIN32) && (defined(_MSC_VER) || defined(__TINYC__)) #include "external/dirent.h" // Required for: DIR, opendir(), closedir() [Used in GetDirectoryFiles()] #else #include // Required for: DIR, opendir(), closedir() [Used in GetDirectoryFiles()] @@ -391,6 +391,7 @@ static int gamepadStream[MAX_GAMEPADS] = { -1 };// Gamepad device file descripto static pthread_t gamepadThreadId; // Gamepad reading thread id static char gamepadName[64]; // Gamepad name holder #endif + //----------------------------------------------------------------------------------- // Timming system variables @@ -401,6 +402,7 @@ static double updateTime = 0.0; // Time measure for frame update static double drawTime = 0.0; // Time measure for frame draw static double frameTime = 0.0; // Time measure for one frame static double targetTime = 0.0; // Desired time for one frame, if 0 not applied + //----------------------------------------------------------------------------------- // Config internal variables @@ -486,10 +488,6 @@ static void InitGamepad(void); // Init raw gamepad inpu static void *GamepadThread(void *arg); // Mouse reading thread #endif -#if defined(PLATFORM_UWP) -// TODO: Define functions required to manage inputs -#endif - #if defined(_WIN32) // NOTE: We include Sleep() function signature here to avoid windows.h inclusion void __stdcall Sleep(unsigned long msTimeout); // Required for Wait() @@ -810,6 +808,7 @@ void SetWindowIcon(Image image) // Set title for window (only PLATFORM_DESKTOP) void SetWindowTitle(const char *title) { + windowTitle = title; #if defined(PLATFORM_DESKTOP) glfwSetWindowTitle(window, title); #endif @@ -887,7 +886,7 @@ int GetScreenHeight(void) // Get native window handle void *GetWindowHandle(void) { -#if defined(_WIN32) +#if defined(PLATFORM_DESKTOP) && defined(_WIN32) // NOTE: Returned handle is: void *HWND (windows.h) return glfwGetWin32Window(window); #elif defined(__linux__) @@ -1026,6 +1025,11 @@ void ShowCursor(void) { #if defined(PLATFORM_DESKTOP) glfwSetInputMode(window, GLFW_CURSOR, GLFW_CURSOR_NORMAL); +#endif +#if defined(PLATFORM_UWP) + UWPMessage* msg = CreateUWPMessage(); + msg->Type = ShowMouse; + SendMessageToUWP(msg); #endif cursorHidden = false; } @@ -1035,6 +1039,11 @@ void HideCursor(void) { #if defined(PLATFORM_DESKTOP) glfwSetInputMode(window, GLFW_CURSOR, GLFW_CURSOR_HIDDEN); +#endif +#if defined(PLATFORM_UWP) + UWPMessage* msg = CreateUWPMessage(); + msg->Type = HideMouse; + SendMessageToUWP(msg); #endif cursorHidden = true; } @@ -1053,6 +1062,11 @@ void EnableCursor(void) #endif #if defined(PLATFORM_WEB) toggleCursorLock = true; +#endif +#if defined(PLATFORM_UWP) + UWPMessage* msg = CreateUWPMessage(); + msg->Type = LockMouse; + SendMessageToUWP(msg); #endif cursorHidden = false; } @@ -1065,6 +1079,11 @@ void DisableCursor(void) #endif #if defined(PLATFORM_WEB) toggleCursorLock = true; +#endif +#if defined(PLATFORM_UWP) + UWPMessage* msg = CreateUWPMessage(); + msg->Type = UnlockMouse; + SendMessageToUWP(msg); #endif cursorHidden = true; } @@ -1145,6 +1164,8 @@ void EndDrawing(void) frameTime += extraTime; } + + return; } // Initialize 2D mode with custom camera (2D) @@ -1421,6 +1442,11 @@ double GetTime(void) return (double)(time - baseTime)*1e-9; // Elapsed time since InitTimer() #endif + +#if defined(PLATFORM_UWP) + //Updated through messages + return currentTime; +#endif } // Returns hexadecimal value for a Color @@ -2209,6 +2235,13 @@ void SetMousePosition(int x, int y) // NOTE: emscripten not implemented glfwSetCursorPos(window, mousePosition.x, mousePosition.y); #endif +#if defined(PLATFORM_UWP) + UWPMessage* msg = CreateUWPMessage(); + msg->Type = SetMouseLocation; + msg->Vector0.x = mousePosition.x; + msg->Vector0.y = mousePosition.y; + SendMessageToUWP(msg); +#endif } // Set mouse offset @@ -2736,6 +2769,8 @@ static bool InitGraphicsDevice(int width, int height) eglQuerySurface(display, surface, EGL_WIDTH, &screenWidth); eglQuerySurface(display, surface, EGL_HEIGHT, &screenHeight); + //SetupFramebuffer(displayWidth, displayHeight); //Borked + #else // PLATFORM_ANDROID, PLATFORM_RPI EGLint numConfigs; @@ -2906,8 +2941,8 @@ static void SetupFramebuffer(int width, int height) TraceLog(LOG_WARNING, "DOWNSCALING: Required screen size (%ix%i) is bigger than display size (%ix%i)", screenWidth, screenHeight, displayWidth, displayHeight); // Downscaling to fit display with border-bars - float widthRatio = (float)displayWidth/(float)screenWidth; - float heightRatio = (float)displayHeight/(float)screenHeight; + float widthRatio = (float)displayWidth / (float)screenWidth; + float heightRatio = (float)displayHeight / (float)screenHeight; if (widthRatio <= heightRatio) { @@ -2925,7 +2960,7 @@ static void SetupFramebuffer(int width, int height) } // Screen scaling required - float scaleRatio = (float)renderWidth/(float)screenWidth; + float scaleRatio = (float)renderWidth / (float)screenWidth; screenScaling = MatrixScale(scaleRatio, scaleRatio, scaleRatio); // NOTE: We render to full display resolution! @@ -2941,13 +2976,13 @@ static void SetupFramebuffer(int width, int height) TraceLog(LOG_INFO, "UPSCALING: Required screen size: %i x %i -> Display size: %i x %i", screenWidth, screenHeight, displayWidth, displayHeight); // Upscaling to fit display with border-bars - float displayRatio = (float)displayWidth/(float)displayHeight; - float screenRatio = (float)screenWidth/(float)screenHeight; + float displayRatio = (float)displayWidth / (float)displayHeight; + float screenRatio = (float)screenWidth / (float)screenHeight; if (displayRatio <= screenRatio) { renderWidth = screenWidth; - renderHeight = (int)round((float)screenWidth/displayRatio); + renderHeight = (int)round((float)screenWidth / displayRatio); renderOffsetX = 0; renderOffsetY = (renderHeight - screenHeight); } @@ -2996,7 +3031,7 @@ static void InitTimer(void) // http://stackoverflow.com/questions/43057578/c-programming-win32-games-sleep-taking-longer-than-expected static void Wait(float ms) { -#if defined(SUPPORT_BUSY_WAIT_LOOP) +#if defined(SUPPORT_BUSY_WAIT_LOOP) && !defined(PLATFORM_UWP) double prevTime = GetTime(); double nextTime = 0.0; @@ -3029,7 +3064,7 @@ static bool GetKeyStatus(int key) // NOTE: Android supports up to 260 keys if (key < 0 || key > 260) return false; else return currentKeyState[key]; -#elif defined(PLATFORM_RPI) +#elif defined(PLATFORM_RPI) || defined(PLATFORM_UWP) // NOTE: Keys states are filled in PollInputEvents() if (key < 0 || key > 511) return false; else return currentKeyState[key]; @@ -3044,7 +3079,7 @@ static bool GetMouseButtonStatus(int button) #elif defined(PLATFORM_ANDROID) // TODO: Check for virtual mouse? return false; -#elif defined(PLATFORM_RPI) +#elif defined(PLATFORM_RPI) || defined(PLATFORM_UWP) // NOTE: Mouse buttons states are filled in PollInputEvents() return currentMouseState[button]; #endif @@ -3170,6 +3205,197 @@ static void PollInputEvents(void) } #endif +#if defined(PLATFORM_UWP) + + // Register previous keys states + for (int i = 0; i < 512; i++) previousKeyState[i] = currentKeyState[i]; + + for (int i = 0; i < MAX_GAMEPADS; i++) + { + if (gamepadReady[i]) + { + for (int k = 0; k < MAX_GAMEPAD_BUTTONS; k++) previousGamepadState[i][k] = currentGamepadState[i][k]; + } + } + + // Register previous mouse states + previousMouseWheelY = currentMouseWheelY; + currentMouseWheelY = 0; + for (int i = 0; i < 3; i++) + { + previousMouseState[i] = currentMouseState[i]; + + } + + // Loop over pending messages + while (HasMessageFromUWP()) + { + UWPMessage* msg = GetMessageFromUWP(); + + switch (msg->Type) + { + case RegisterKey: + { + //Convert from virtualKey + int actualKey = -1; + + switch (msg->Int0) + { + case 0x08: actualKey = KEY_BACKSPACE; break; + case 0x20: actualKey = KEY_SPACE; break; + case 0x1B: actualKey = KEY_ESCAPE; break; + case 0x0D: actualKey = KEY_ENTER; break; + case 0x2E: actualKey = KEY_DELETE; break; + case 0x27: actualKey = KEY_RIGHT; break; + case 0x25: actualKey = KEY_LEFT; break; + case 0x28: actualKey = KEY_DOWN; break; + case 0x26: actualKey = KEY_UP; break; + case 0x70: actualKey = KEY_F1; break; + case 0x71: actualKey = KEY_F2; break; + case 0x72: actualKey = KEY_F3; break; + case 0x73: actualKey = KEY_F4; break; + case 0x74: actualKey = KEY_F5; break; + case 0x75: actualKey = KEY_F6; break; + case 0x76: actualKey = KEY_F7; break; + case 0x77: actualKey = KEY_F8; break; + case 0x78: actualKey = KEY_F9; break; + case 0x79: actualKey = KEY_F10; break; + case 0x7A: actualKey = KEY_F11; break; + case 0x7B: actualKey = KEY_F12; break; + case 0xA0: actualKey = KEY_LEFT_SHIFT; break; + case 0xA2: actualKey = KEY_LEFT_CONTROL; break; + case 0xA4: actualKey = KEY_LEFT_ALT; break; + case 0xA1: actualKey = KEY_RIGHT_SHIFT; break; + case 0xA3: actualKey = KEY_RIGHT_CONTROL; break; + case 0xA5: actualKey = KEY_RIGHT_ALT; break; + case 0x30: actualKey = KEY_ZERO; break; + case 0x31: actualKey = KEY_ONE; break; + case 0x32: actualKey = KEY_TWO; break; + case 0x33: actualKey = KEY_THREE; break; + case 0x34: actualKey = KEY_FOUR; break; + case 0x35: actualKey = KEY_FIVE; break; + case 0x36: actualKey = KEY_SIX; break; + case 0x37: actualKey = KEY_SEVEN; break; + case 0x38: actualKey = KEY_EIGHT; break; + case 0x39: actualKey = KEY_NINE; break; + case 0x41: actualKey = KEY_A; break; + case 0x42: actualKey = KEY_B; break; + case 0x43: actualKey = KEY_C; break; + case 0x44: actualKey = KEY_D; break; + case 0x45: actualKey = KEY_E; break; + case 0x46: actualKey = KEY_F; break; + case 0x47: actualKey = KEY_G; break; + case 0x48: actualKey = KEY_H; break; + case 0x49: actualKey = KEY_I; break; + case 0x4A: actualKey = KEY_J; break; + case 0x4B: actualKey = KEY_K; break; + case 0x4C: actualKey = KEY_L; break; + case 0x4D: actualKey = KEY_M; break; + case 0x4E: actualKey = KEY_N; break; + case 0x4F: actualKey = KEY_O; break; + case 0x50: actualKey = KEY_P; break; + case 0x51: actualKey = KEY_Q; break; + case 0x52: actualKey = KEY_R; break; + case 0x53: actualKey = KEY_S; break; + case 0x54: actualKey = KEY_T; break; + case 0x55: actualKey = KEY_U; break; + case 0x56: actualKey = KEY_V; break; + case 0x57: actualKey = KEY_W; break; + case 0x58: actualKey = KEY_X; break; + case 0x59: actualKey = KEY_Y; break; + case 0x5A: actualKey = KEY_Z; break; + } + + if (actualKey > -1) + currentKeyState[actualKey] = msg->Char0; + break; + } + + case RegisterClick: + { + currentMouseState[msg->Int0] = msg->Char0; + break; + } + + case ScrollWheelUpdate: + { + currentMouseWheelY += msg->Int0; + break; + } + + case UpdateMouseLocation: + { + mousePosition = msg->Vector0; + break; + } + + case MarkGamepadActive: + { + if (msg->Int0 < MAX_GAMEPADS) + gamepadReady[msg->Int0] = msg->Bool0; + break; + } + + case MarkGamepadButton: + { + if (msg->Int0 < MAX_GAMEPADS && msg->Int1 < MAX_GAMEPAD_BUTTONS) + currentGamepadState[msg->Int0][msg->Int1] = msg->Char0; + break; + } + + case MarkGamepadAxis: + { + if (msg->Int0 < MAX_GAMEPADS && msg->Int1 < MAX_GAMEPAD_AXIS) + gamepadAxisState[msg->Int0][msg->Int1] = msg->Float0; + break; + } + + case SetDisplayDims: + { + displayWidth = msg->Vector0.x; + displayHeight = msg->Vector0.y; + break; + } + + case HandleResize: + { + eglQuerySurface(display, surface, EGL_WIDTH, &screenWidth); + eglQuerySurface(display, surface, EGL_HEIGHT, &screenHeight); + + // If window is resized, viewport and projection matrix needs to be re-calculated + rlViewport(0, 0, screenWidth, screenHeight); // Set viewport width and height + rlMatrixMode(RL_PROJECTION); // Switch to PROJECTION matrix + rlLoadIdentity(); // Reset current matrix (PROJECTION) + rlOrtho(0, screenWidth, screenHeight, 0, 0.0f, 1.0f); // Orthographic projection mode with top-left corner at (0,0) + rlMatrixMode(RL_MODELVIEW); // Switch back to MODELVIEW matrix + rlLoadIdentity(); // Reset current matrix (MODELVIEW) + rlClearScreenBuffers(); // Clear screen buffers (color and depth) + + // Window size must be updated to be used on 3D mode to get new aspect ratio (BeginMode3D()) + // NOTE: Be careful! GLFW3 will choose the closest fullscreen resolution supported by current monitor, + // for example, if reescaling back to 800x450 (desired), it could set 720x480 (closest fullscreen supported) + currentWidth = screenWidth; + currentHeight = screenHeight; + + // NOTE: Postprocessing texture is not scaled to new size + + windowResized = true; + break; + } + + case SetGameTime: + { + currentTime = msg->Double0; + break; + } + + } + + DeleteUWPMessage(msg); //Delete, we are done + } + +#endif + #if defined(PLATFORM_DESKTOP) || defined(PLATFORM_WEB) // Mouse input polling double mouseX; @@ -4663,7 +4889,7 @@ static void *GamepadThread(void *arg) // Plays raylib logo appearing animation static void LogoAnimation(void) { -#if !defined(PLATFORM_WEB) +#if !defined(PLATFORM_WEB) && !defined(PLATFORM_UWP) int logoPositionX = screenWidth/2 - 128; int logoPositionY = screenHeight/2 - 128; @@ -4772,4 +4998,4 @@ static void LogoAnimation(void) #endif showLogo = false; // Prevent for repeating when reloading window (Android) -} +} \ No newline at end of file diff --git a/src/external/ANGLE/EGL/eglplatform.h b/src/external/ANGLE/EGL/eglplatform.h index eb3ea70c..7e542ff7 100644 --- a/src/external/ANGLE/EGL/eglplatform.h +++ b/src/external/ANGLE/EGL/eglplatform.h @@ -74,11 +74,16 @@ //#include // raylib edit!!! +#ifndef PLATFORM_UWP typedef void *PVOID; // PVOID is a pointer to any type. This type is declared in WinNT.h typedef PVOID HANDLE; // HANDLE is handle to an object. This type is declared in WinNT.h typedef HANDLE HWND; // HWND is a handle to a window. This type is declared in WinDef.h typedef HANDLE HDC; // HDC is a handle to a device context (DC). This type is declared in WinDef.h typedef HANDLE HBITMAP; // HBITMAP is a handle to a bitmap. This type is declared in WinDef.h +#else +//UWP Fix +#include "Windows.h" +#endif // HDC, HBITMAP and HWND are actually pointers to void. You can cast a long to a HWND like this: HWND h = (HWND)my_long_var; // but very careful of what information is stored in my_long_var. You have to make sure that you have a pointer in there. diff --git a/src/rlgl.h b/src/rlgl.h index 71a1dc4b..ae92f149 100644 --- a/src/rlgl.h +++ b/src/rlgl.h @@ -999,17 +999,17 @@ void rlMultMatrixf(float *matf) } // Multiply the current matrix by a perspective matrix generated by parameters -void rlFrustum(double left, double right, double bottom, double top, double near, double far) +void rlFrustum(double left, double right, double bottom, double top, double znear, double zfar) { - Matrix matPerps = MatrixFrustum(left, right, bottom, top, near, far); + Matrix matPerps = MatrixFrustum(left, right, bottom, top, znear, zfar); *currentMatrix = MatrixMultiply(*currentMatrix, matPerps); } // Multiply the current matrix by an orthographic matrix generated by parameters -void rlOrtho(double left, double right, double bottom, double top, double near, double far) +void rlOrtho(double left, double right, double bottom, double top, double znear, double zfar) { - Matrix matOrtho = MatrixOrtho(left, right, bottom, top, near, far); + Matrix matOrtho = MatrixOrtho(left, right, bottom, top, znear, zfar); *currentMatrix = MatrixMultiply(*currentMatrix, matOrtho); } @@ -1619,7 +1619,7 @@ void rlglInit(int width, int height) if (strcmp(extList[i], (const char *)"GL_EXT_debug_marker") == 0) debugMarkerSupported = true; } -#if defined(_WIN32) && defined(_MSC_VER) +#if defined(_WIN32) && defined(_MSC_VER) && !defined(PLATFORM_UWP) //is this a hotfix? I may need to find out why this is broken RL_FREE(extList); #endif diff --git a/src/utils.c b/src/utils.c index 3cff472b..c886d2a7 100644 --- a/src/utils.c +++ b/src/utils.c @@ -132,7 +132,7 @@ void TraceLog(int logType, const char *text, ...) #else char buffer[MAX_TRACELOG_BUFFER_SIZE] = { 0 }; - switch(logType) + switch (logType) { case LOG_TRACE: strcpy(buffer, "TRACE: "); break; case LOG_DEBUG: strcpy(buffer, "DEBUG: "); break; @@ -150,7 +150,7 @@ void TraceLog(int logType, const char *text, ...) va_end(args); - if (logType >= logTypeExit) exit(1); // If exit message, exit program + if (logType >= logTypeExit) exit(1); // If exit message, exit program #endif // SUPPORT_TRACELOG } @@ -202,3 +202,91 @@ static int android_close(void *cookie) return 0; } #endif + +#if defined(PLATFORM_UWP) + +#define MAX_MESSAGES 512 //If there are over 128 messages, I will cry... either way, this may be too much EDIT: Welp, 512 + +static int UWPOutMessageId = -1; //Stores the last index for the message +static UWPMessage* UWPOutMessages[MAX_MESSAGES]; //Messages out to UWP + +static int UWPInMessageId = -1; //Stores the last index for the message +static UWPMessage* UWPInMessages[MAX_MESSAGES]; //Messages in from UWP + +UWPMessage* CreateUWPMessage(void) +{ + UWPMessage* msg = (UWPMessage*)RL_MALLOC(sizeof(UWPMessage)); + msg->Type = None; + Vector2 v0 = {0, 0}; + msg->Vector0 = v0; + msg->Int0 = 0; + msg->Int1 = 0; + msg->Char0 = 0; + msg->Float0 = 0; + msg->Double0 = 0; + msg->Bool0 = false; + return msg; +} + +void DeleteUWPMessage(UWPMessage* msg) +{ + RL_FREE(msg); +} + +bool UWPHasMessages(void) +{ + return UWPOutMessageId > -1; +} + +UWPMessage* UWPGetMessage(void) +{ + if (UWPHasMessages()) + { + return UWPOutMessages[UWPOutMessageId--]; + } + + return NULL; +} + +void UWPSendMessage(UWPMessage* msg) +{ + if (UWPInMessageId + 1 < MAX_MESSAGES) + { + UWPInMessageId++; + UWPInMessages[UWPInMessageId] = msg; + } + else + { + TraceLog(LOG_WARNING, "[UWP Messaging] Not enough array space to register new UWP inbound Message."); + } +} + +void SendMessageToUWP(UWPMessage* msg) +{ + if (UWPOutMessageId + 1 < MAX_MESSAGES) + { + UWPOutMessageId++; + UWPOutMessages[UWPOutMessageId] = msg; + } + else + { + TraceLog(LOG_WARNING, "[UWP Messaging] Not enough array space to register new UWP outward Message."); + } +} + +bool HasMessageFromUWP(void) +{ + return UWPInMessageId > -1; +} + +UWPMessage* GetMessageFromUWP(void) +{ + if (HasMessageFromUWP()) + { + return UWPInMessages[UWPInMessageId--]; + } + + return NULL; +} + +#endif diff --git a/src/utils.h b/src/utils.h index d7ab8829..14e6bf70 100644 --- a/src/utils.h +++ b/src/utils.h @@ -59,6 +59,81 @@ void InitAssetManager(AAssetManager *manager); // Initialize asset manager from FILE *android_fopen(const char *fileName, const char *mode); // Replacement for fopen() #endif +#if defined(PLATFORM_UWP) + +// UWP Messages System + +typedef enum +{ + None = 0, + + //Send + ShowMouse, + HideMouse, + LockMouse, + UnlockMouse, + SetMouseLocation, //Vector0 (pos) + + //Recieve (Into C) + RegisterKey, //Int0 (key), Char0 (status) + RegisterClick, //Int0 (button), Char0 (status) + ScrollWheelUpdate, //Int0 (delta) + UpdateMouseLocation, //Vector0 (pos) + MarkGamepadActive, //Int0 (gamepad), Bool0 (active or not) + MarkGamepadButton, //Int0 (gamepad), Int1 (button), Char0 (status) + MarkGamepadAxis,//Int0 (gamepad), int1 (axis), Float0 (value) + SetDisplayDims, //Vector0 (display dimensions) + HandleResize, //Vector0 (new dimensions) - Onresized event + SetGameTime, //Int0 +} UWPMessageType; + +typedef struct UWPMessage +{ + //The message type + UWPMessageType Type; + + //Vector parameters + Vector2 Vector0; + + //Int parameters + int Int0; + int Int1; + + //Char parameters + char Char0; + + //Float parameters + float Float0; + + //Double parameters + double Double0; + + //Bool parameters + bool Bool0; + + //More parameters can be added and fed to functions +} UWPMessage; + +//Allocate UWP Message +RLAPI UWPMessage* CreateUWPMessage(void); + +//Free UWP Message +RLAPI void DeleteUWPMessage(UWPMessage* msg); + +//Get messages into C++ +RLAPI bool UWPHasMessages(void); +RLAPI UWPMessage* UWPGetMessage(void); +RLAPI void UWPSendMessage(UWPMessage* msg); + +//For C to call +#ifndef _cplusplus //Hide from C++ code +void SendMessageToUWP(UWPMessage* msg); +bool HasMessageFromUWP(void); +UWPMessage* GetMessageFromUWP(void); +#endif + +#endif + #ifdef __cplusplus } #endif