mirror of
https://codeberg.org/WinDurango/WinDurango.git
synced 2026-04-18 02:23:34 -04:00
feat: added defs for some stubs in gamepad
This commit is contained in:
@@ -6,6 +6,8 @@ set(CMAKE_CXX_STANDARD 20)
|
||||
|
||||
find_package(cppwinrt CONFIG REQUIRED HINTS "${CMAKE_SOURCE_DIR}/vcpkg_installed/vcpkg/pkgs/cppwinrt_x64-windows/share/cppwinrt")
|
||||
|
||||
add_compile_definitions(_AMD64_)
|
||||
|
||||
make_directory(${CMAKE_BINARY_DIR}/WinMetadata)
|
||||
file(GLOB IDL_FILES CONFIGURE_DEPENDS "${CMAKE_SOURCE_DIR}/idl/*.idl")
|
||||
cmake_path(CONVERT "${IDL_FILES}" TO_NATIVE_PATH_LIST IDL_FILES)
|
||||
|
||||
@@ -1,8 +1,11 @@
|
||||
#pragma once
|
||||
#include <winrt/Windows.Foundation.Collections.h>
|
||||
#include <Xinput.h>
|
||||
#include "Windows.Xbox.Input.Gamepad.g.h"
|
||||
#include "Windows.Xbox.Input.GamepadAddedEventArgs.g.h"
|
||||
#include "Windows.Xbox.Input.GamepadRemovedEventArgs.g.h"
|
||||
#include "Windows.Xbox.Input.GamepadReading.g.h"
|
||||
#include "Windows.Xbox.System.User.h"
|
||||
|
||||
namespace winrt::Windows::Xbox::Input::implementation
|
||||
{
|
||||
@@ -29,8 +32,8 @@ namespace winrt::Windows::Xbox::Input::implementation
|
||||
struct GamepadReading : GamepadReadingT<GamepadReading>
|
||||
{
|
||||
GamepadReading() = default;
|
||||
GamepadReading(winrt::Windows::Foundation::DateTime time, winrt::Windows::Xbox::Input::GamepadButtons buttons)
|
||||
: time(time), buttons(buttons) {}
|
||||
GamepadReading(winrt::Windows::Foundation::DateTime time, winrt::Windows::Xbox::Input::RawGamepadReading reading)
|
||||
: time(time), reading(reading) {}
|
||||
|
||||
winrt::Windows::Foundation::DateTime Timestamp();
|
||||
winrt::Windows::Xbox::Input::GamepadButtons Buttons();
|
||||
@@ -56,13 +59,13 @@ namespace winrt::Windows::Xbox::Input::implementation
|
||||
float RightThumbstickY();
|
||||
private:
|
||||
winrt::Windows::Foundation::DateTime time;
|
||||
winrt::Windows::Xbox::Input::GamepadButtons buttons = winrt::Windows::Xbox::Input::GamepadButtons::None;
|
||||
winrt::Windows::Xbox::Input::RawGamepadReading reading;
|
||||
};
|
||||
|
||||
struct Gamepad : GamepadT<Gamepad>
|
||||
{
|
||||
Gamepad() = default;
|
||||
Gamepad(uint64_t id) : id(id) {}
|
||||
Gamepad(uint64_t id, bool gamepad) : id(id) {}
|
||||
|
||||
static winrt::Windows::Foundation::Collections::IVectorView<winrt::Windows::Xbox::Input::Gamepad> Gamepads();
|
||||
static winrt::event_token GamepadAdded(winrt::Windows::Foundation::EventHandler<winrt::Windows::Xbox::Input::GamepadAddedEventArgs> const& handler);
|
||||
@@ -79,8 +82,10 @@ namespace winrt::Windows::Xbox::Input::implementation
|
||||
winrt::Windows::Xbox::Input::RawGamepadReading GetRawCurrentReading();
|
||||
private:
|
||||
uint64_t id = 0;
|
||||
bool gamepad = false;
|
||||
static winrt::event<winrt::Windows::Foundation::EventHandler<winrt::Windows::Xbox::Input::GamepadAddedEventArgs>> e_GamepadAdded;
|
||||
static winrt::event<winrt::Windows::Foundation::EventHandler<winrt::Windows::Xbox::Input::GamepadRemovedEventArgs>> e_GamepadRemoved;
|
||||
static winrt::Windows::Foundation::Collections::IVector<winrt::Windows::Xbox::Input::Gamepad> a_gamepads;
|
||||
};
|
||||
}
|
||||
namespace winrt::Windows::Xbox::Input::factory_implementation
|
||||
|
||||
@@ -83,6 +83,7 @@ namespace winrt::Windows::Xbox::System::implementation
|
||||
static winrt::event<winrt::Windows::Foundation::EventHandler<winrt::Windows::Xbox::System::SignOutStartedEventArgs>> m_SignOutStarted;
|
||||
static winrt::event<winrt::Windows::Foundation::EventHandler<winrt::Windows::Xbox::System::SignOutCompletedEventArgs>> m_SignOutCompleted;
|
||||
static winrt::event<winrt::Windows::Foundation::EventHandler<winrt::Windows::Xbox::System::UserDisplayInfoChangedEventArgs>> m_UserDisplayInfoChanged;
|
||||
static winrt::Windows::Foundation::Collections::IVector<winrt::Windows::Xbox::System::User> a_users;
|
||||
};
|
||||
}
|
||||
namespace winrt::Windows::Xbox::System::factory_implementation
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
#include "WinDurangoWinRT.h"
|
||||
|
||||
std::shared_ptr<wd::common::WinDurango> p_wd;
|
||||
std::shared_ptr<wd::common::WinDurango> p_wd = nullptr;
|
||||
|
||||
/*
|
||||
* https://learn.microsoft.com/en-us/windows/win32/dlls/dllmain
|
||||
@@ -9,8 +9,11 @@ BOOL WINAPI DllMain(HINSTANCE hinstDLL, // handle to DLL module
|
||||
DWORD fdwReason, // reason for calling function
|
||||
LPVOID lpvReserved) // reserved
|
||||
{
|
||||
p_wd = wd::common::WinDurango::GetInstance();
|
||||
p_wd->log.Log("WinDurango::WinRT", "Initialized");
|
||||
if (p_wd == nullptr)
|
||||
{
|
||||
p_wd = wd::common::WinDurango::GetInstance();
|
||||
p_wd->log.Log("WinDurango::WinRT", "Initialized");
|
||||
}
|
||||
return TRUE; // Successful DLL_PROCESS_ATTACH.
|
||||
}
|
||||
|
||||
|
||||
@@ -20,119 +20,141 @@ namespace winrt::Windows::Xbox::Input::implementation
|
||||
|
||||
winrt::Windows::Xbox::Input::GamepadButtons GamepadReading::Buttons()
|
||||
{
|
||||
return buttons;
|
||||
return reading.Buttons;
|
||||
}
|
||||
|
||||
bool GamepadReading::IsDPadUpPressed()
|
||||
{
|
||||
return (buttons & GamepadButtons::DPadUp) != GamepadButtons::None;
|
||||
return (reading.Buttons & GamepadButtons::DPadUp) != GamepadButtons::None;
|
||||
}
|
||||
|
||||
bool GamepadReading::IsDPadDownPressed()
|
||||
{
|
||||
return (buttons & GamepadButtons::DPadDown) != GamepadButtons::None;
|
||||
return (reading.Buttons & GamepadButtons::DPadDown) != GamepadButtons::None;
|
||||
}
|
||||
|
||||
bool GamepadReading::IsDPadLeftPressed()
|
||||
{
|
||||
return (buttons & GamepadButtons::DPadLeft) != GamepadButtons::None;
|
||||
return (reading.Buttons & GamepadButtons::DPadLeft) != GamepadButtons::None;
|
||||
}
|
||||
|
||||
bool GamepadReading::IsDPadRightPressed()
|
||||
{
|
||||
return (buttons & GamepadButtons::DPadRight) != GamepadButtons::None;
|
||||
return (reading.Buttons & GamepadButtons::DPadRight) != GamepadButtons::None;
|
||||
}
|
||||
|
||||
bool GamepadReading::IsMenuPressed()
|
||||
{
|
||||
return (buttons & GamepadButtons::Menu) != GamepadButtons::None;
|
||||
return (reading.Buttons & GamepadButtons::Menu) != GamepadButtons::None;
|
||||
}
|
||||
|
||||
bool GamepadReading::IsViewPressed()
|
||||
{
|
||||
return (buttons & GamepadButtons::View) != GamepadButtons::None;
|
||||
return (reading.Buttons & GamepadButtons::View) != GamepadButtons::None;
|
||||
}
|
||||
|
||||
bool GamepadReading::IsLeftThumbstickPressed()
|
||||
{
|
||||
return (buttons & GamepadButtons::LeftThumbstick) != GamepadButtons::None;
|
||||
return (reading.Buttons & GamepadButtons::LeftThumbstick) != GamepadButtons::None;
|
||||
}
|
||||
|
||||
bool GamepadReading::IsRightThumbstickPressed()
|
||||
{
|
||||
return (buttons & GamepadButtons::RightThumbstick) != GamepadButtons::None;
|
||||
return (reading.Buttons & GamepadButtons::RightThumbstick) != GamepadButtons::None;
|
||||
}
|
||||
|
||||
bool GamepadReading::IsLeftShoulderPressed()
|
||||
{
|
||||
return (buttons & GamepadButtons::LeftShoulder) != GamepadButtons::None;
|
||||
return (reading.Buttons & GamepadButtons::LeftShoulder) != GamepadButtons::None;
|
||||
}
|
||||
|
||||
bool GamepadReading::IsRightShoulderPressed()
|
||||
{
|
||||
return (buttons & GamepadButtons::RightShoulder) != GamepadButtons::None;
|
||||
return (reading.Buttons & GamepadButtons::RightShoulder) != GamepadButtons::None;
|
||||
}
|
||||
|
||||
bool GamepadReading::IsAPressed()
|
||||
{
|
||||
return (buttons & GamepadButtons::A) != GamepadButtons::None;
|
||||
return (reading.Buttons & GamepadButtons::A) != GamepadButtons::None;
|
||||
}
|
||||
|
||||
bool GamepadReading::IsBPressed()
|
||||
{
|
||||
return (buttons & GamepadButtons::B) != GamepadButtons::None;
|
||||
return (reading.Buttons & GamepadButtons::B) != GamepadButtons::None;
|
||||
}
|
||||
|
||||
bool GamepadReading::IsXPressed()
|
||||
{
|
||||
return (buttons & GamepadButtons::X) != GamepadButtons::None;
|
||||
return (reading.Buttons & GamepadButtons::X) != GamepadButtons::None;
|
||||
}
|
||||
|
||||
bool GamepadReading::IsYPressed()
|
||||
{
|
||||
return (buttons & GamepadButtons::Y) != GamepadButtons::None;
|
||||
return (reading.Buttons & GamepadButtons::Y) != GamepadButtons::None;
|
||||
}
|
||||
|
||||
float GamepadReading::LeftTrigger()
|
||||
{
|
||||
p_wd->log.Warn("WinDurango::WinRT::Windows::Xbox::Input", "Unimplemented: LeftTrigger");
|
||||
return 0.0f;
|
||||
return reading.LeftTrigger;
|
||||
}
|
||||
|
||||
float GamepadReading::RightTrigger()
|
||||
{
|
||||
p_wd->log.Warn("WinDurango::WinRT::Windows::Xbox::Input", "Unimplemented: RightTrigger");
|
||||
return 0.0f;
|
||||
return reading.RightTrigger;
|
||||
}
|
||||
|
||||
float GamepadReading::LeftThumbstickX()
|
||||
{
|
||||
p_wd->log.Warn("WinDurango::WinRT::Windows::Xbox::Input", "Unimplemented: LeftThumbstickX");
|
||||
return 0.0f;
|
||||
return reading.LeftTrigger;
|
||||
}
|
||||
|
||||
float GamepadReading::LeftThumbstickY()
|
||||
{
|
||||
p_wd->log.Warn("WinDurango::WinRT::Windows::Xbox::Input", "Unimplemented: LeftThumbstickY");
|
||||
return 0.0f;
|
||||
return reading.LeftThumbstickY;
|
||||
}
|
||||
|
||||
float GamepadReading::RightThumbstickX()
|
||||
{
|
||||
p_wd->log.Warn("WinDurango::WinRT::Windows::Xbox::Input", "Unimplemented: RightThumbstickX");
|
||||
return 0.0f;
|
||||
return reading.RightThumbstickX;
|
||||
}
|
||||
|
||||
float GamepadReading::RightThumbstickY()
|
||||
{
|
||||
p_wd->log.Warn("WinDurango::WinRT::Windows::Xbox::Input", "Unimplemented: RightThumbstickY");
|
||||
return 0.0f;
|
||||
return reading.RightThumbstickY;
|
||||
}
|
||||
|
||||
winrt::Windows::Foundation::Collections::IVectorView<winrt::Windows::Xbox::Input::Gamepad> Gamepad::Gamepads()
|
||||
{
|
||||
p_wd->log.Warn("WinDurango::WinRT::Windows::Xbox::Input", "Unimplemented: Gamepads");
|
||||
throw hresult_not_implemented();
|
||||
if (a_gamepads == winrt::Windows::Foundation::Collections::IVector<winrt::Windows::Xbox::Input::Gamepad>(nullptr) || a_gamepads.Size() == 0)
|
||||
{
|
||||
a_gamepads = winrt::single_threaded_vector<winrt::Windows::Xbox::Input::Gamepad>();
|
||||
|
||||
p_wd->log.Log("WinDurango::WinRT::Windows::Xbox::Input", "Creating static a_gamepads");
|
||||
|
||||
for (size_t i = 0; i < 4; i++)
|
||||
{
|
||||
XINPUT_STATE state{};
|
||||
DWORD result = XInputGetState(0, &state);
|
||||
|
||||
if (result == ERROR_SUCCESS)
|
||||
{
|
||||
p_wd->log.Log("WinDurango::WinRT::Windows::Xbox::Input", "Creating gamepad");
|
||||
winrt::Windows::Xbox::Input::Gamepad gamepad = winrt::make<Gamepad>(i, true);
|
||||
a_gamepads.Append(gamepad);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (a_gamepads.Size() == 0)
|
||||
{
|
||||
p_wd->log.Log("WinDurango::WinRT::Windows::Xbox::Input", "Creating Virtual gamepad");
|
||||
winrt::Windows::Xbox::Input::Gamepad gamepad = winrt::make<Gamepad>(0, false);
|
||||
a_gamepads.Append(gamepad);
|
||||
}
|
||||
|
||||
// I think I need to add mouse capture here
|
||||
|
||||
return a_gamepads.GetView();
|
||||
}
|
||||
|
||||
winrt::event_token Gamepad::GamepadAdded(winrt::Windows::Foundation::EventHandler<winrt::Windows::Xbox::Input::GamepadAddedEventArgs> const& handler)
|
||||
@@ -162,46 +184,47 @@ namespace winrt::Windows::Xbox::Input::implementation
|
||||
|
||||
hstring Gamepad::Type()
|
||||
{
|
||||
p_wd->log.Warn("WinDurango::WinRT::Windows::Xbox::Input", "Unimplemented: RightThumbstickY");
|
||||
p_wd->log.Warn("WinDurango::WinRT::Windows::Xbox::Input", "Unimplemented: Type");
|
||||
throw hresult_not_implemented();
|
||||
}
|
||||
|
||||
winrt::Windows::Xbox::System::User Gamepad::User()
|
||||
{
|
||||
p_wd->log.Warn("WinDurango::WinRT::Windows::Xbox::Input", "Unimplemented: RightThumbstickY");
|
||||
throw hresult_not_implemented();
|
||||
p_wd->log.Log("WinDurango::WinRT::Windows::Xbox::Input", "Creating Getting User");
|
||||
return winrt::Windows::Xbox::System::User::Users().GetAt(id);
|
||||
}
|
||||
|
||||
winrt::Windows::Xbox::Input::INavigationReading Gamepad::GetNavigationReading()
|
||||
{
|
||||
p_wd->log.Warn("WinDurango::WinRT::Windows::Xbox::Input", "Unimplemented: RightThumbstickY");
|
||||
p_wd->log.Warn("WinDurango::WinRT::Windows::Xbox::Input", "Unimplemented: GetNavigationReading");
|
||||
throw hresult_not_implemented();
|
||||
}
|
||||
|
||||
winrt::Windows::Xbox::Input::RawNavigationReading Gamepad::GetRawNavigationReading()
|
||||
{
|
||||
p_wd->log.Warn("WinDurango::WinRT::Windows::Xbox::Input", "Unimplemented: RightThumbstickY");
|
||||
p_wd->log.Warn("WinDurango::WinRT::Windows::Xbox::Input", "Unimplemented: GetRawNavigationReading");
|
||||
throw hresult_not_implemented();
|
||||
}
|
||||
|
||||
winrt::Windows::Xbox::Input::GamepadVibration Gamepad::SetVibration()
|
||||
{
|
||||
p_wd->log.Warn("WinDurango::WinRT::Windows::Xbox::Input", "Unimplemented: RightThumbstickY");
|
||||
p_wd->log.Warn("WinDurango::WinRT::Windows::Xbox::Input", "Unimplemented: SetVibration");
|
||||
throw hresult_not_implemented();
|
||||
}
|
||||
|
||||
winrt::Windows::Xbox::Input::GamepadReading Gamepad::GetCurrentReading()
|
||||
{
|
||||
p_wd->log.Warn("WinDurango::WinRT::Windows::Xbox::Input", "Unimplemented: RightThumbstickY");
|
||||
p_wd->log.Warn("WinDurango::WinRT::Windows::Xbox::Input", "Unimplemented: GetCurrentReading");
|
||||
throw hresult_not_implemented();
|
||||
}
|
||||
|
||||
winrt::Windows::Xbox::Input::RawGamepadReading Gamepad::GetRawCurrentReading()
|
||||
{
|
||||
p_wd->log.Warn("WinDurango::WinRT::Windows::Xbox::Input", "Unimplemented: RightThumbstickY");
|
||||
p_wd->log.Warn("WinDurango::WinRT::Windows::Xbox::Input", "Unimplemented: GetRawCurrentReading");
|
||||
throw hresult_not_implemented();
|
||||
}
|
||||
|
||||
winrt::event<winrt::Windows::Foundation::EventHandler<winrt::Windows::Xbox::Input::GamepadAddedEventArgs>> Gamepad::e_GamepadAdded{};
|
||||
winrt::event<winrt::Windows::Foundation::EventHandler<winrt::Windows::Xbox::Input::GamepadRemovedEventArgs>> Gamepad::e_GamepadRemoved{};
|
||||
winrt::Windows::Foundation::Collections::IVector<winrt::Windows::Xbox::Input::Gamepad> Gamepad::a_gamepads;
|
||||
}
|
||||
|
||||
@@ -32,7 +32,21 @@ namespace winrt::Windows::Xbox::System::implementation
|
||||
winrt::Windows::Foundation::Collections::IVectorView<winrt::Windows::Xbox::System::User> User::Users()
|
||||
{
|
||||
p_wd->log.Warn("WinDurango::WinRT::Windows::Xbox::System", "Unimplemented: Users");
|
||||
throw hresult_not_implemented();
|
||||
if (a_users == winrt::Windows::Foundation::Collections::IVector<winrt::Windows::Xbox::System::User>(nullptr) || a_users.Size() == 0)
|
||||
{
|
||||
a_users = winrt::single_threaded_vector<winrt::Windows::Xbox::System::User>();
|
||||
|
||||
p_wd->log.Log("WinDurango::WinRT::Windows::Xbox::System", "Creating static a_users");
|
||||
|
||||
for (size_t i = 0; i < 4; i++)
|
||||
{
|
||||
p_wd->log.Log("WinDurango::WinRT::Windows::Xbox::System", "Creating user");
|
||||
winrt::Windows::Xbox::System::User user = winrt::make<User>(i);
|
||||
a_users.Append(user);
|
||||
}
|
||||
}
|
||||
|
||||
return a_users.GetView();
|
||||
}
|
||||
|
||||
winrt::event_token User::UserAdded(winrt::Windows::Foundation::EventHandler<winrt::Windows::Xbox::System::UserAddedEventArgs> const& handler)
|
||||
@@ -239,4 +253,5 @@ namespace winrt::Windows::Xbox::System::implementation
|
||||
winrt::event<winrt::Windows::Foundation::EventHandler<winrt::Windows::Xbox::System::SignOutStartedEventArgs>> User::m_SignOutStarted{};
|
||||
winrt::event<winrt::Windows::Foundation::EventHandler<winrt::Windows::Xbox::System::SignOutCompletedEventArgs>> User::m_SignOutCompleted{};
|
||||
winrt::event<winrt::Windows::Foundation::EventHandler<winrt::Windows::Xbox::System::UserDisplayInfoChangedEventArgs>> User::m_UserDisplayInfoChanged{};
|
||||
winrt::Windows::Foundation::Collections::IVector<winrt::Windows::Xbox::System::User> User::a_users{};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user