2022-10-16 03:25:33 +08:00
|
|
|
/************************************************************************************//*!
|
|
|
|
\file Input.cxx
|
|
|
|
\author Tng Kah Wei, kahwei.tng, 390009620
|
|
|
|
\par email: kahwei.tng\@digipen.edu
|
|
|
|
\date Oct 16, 2022
|
|
|
|
\brief Contains the definition of the managed Input static class.
|
|
|
|
|
|
|
|
Note: This file is written in C++17/CLI.
|
|
|
|
|
|
|
|
Copyright (C) 2022 DigiPen Institute of Technology.
|
|
|
|
Reproduction or disclosure of this file or its contents without the prior written consent
|
|
|
|
of DigiPen Institute of Technology is prohibited.
|
|
|
|
*//*************************************************************************************/
|
|
|
|
#include "SHpch.h"
|
|
|
|
#include "Input.hxx"
|
|
|
|
#include "Utility/Convert.hxx"
|
|
|
|
|
|
|
|
namespace SHADE
|
|
|
|
{
|
|
|
|
/*---------------------------------------------------------------------------------*/
|
|
|
|
/* Properties */
|
|
|
|
/*---------------------------------------------------------------------------------*/
|
|
|
|
Vector3 Input::MousePosition::get()
|
|
|
|
{
|
|
|
|
int x, y;
|
|
|
|
SHInputManager::GetMouseWindowPosition(&x, &y);
|
|
|
|
return Vector3(static_cast<float>(x), static_cast<float>(y), 0.0f);
|
|
|
|
}
|
|
|
|
int Input::MouseScrollDelta::get()
|
|
|
|
{
|
|
|
|
return SHInputManager::GetMouseWheelVerticalDelta();
|
|
|
|
}
|
2023-02-22 23:50:39 +08:00
|
|
|
bool Input::ControllerInUse::get()
|
|
|
|
{
|
|
|
|
return SHInputManager::GetControllerInUse();
|
|
|
|
}
|
2022-10-16 03:25:33 +08:00
|
|
|
|
|
|
|
/*---------------------------------------------------------------------------------*/
|
|
|
|
/* Usage Functions */
|
|
|
|
/*---------------------------------------------------------------------------------*/
|
2023-02-22 23:50:39 +08:00
|
|
|
bool Input::AnyKey()
|
|
|
|
{
|
|
|
|
return SHInputManager::AnyKey();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool Input::AnyKeyDown()
|
|
|
|
{
|
|
|
|
return SHInputManager::AnyKeyDown();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool Input::AnyKeyUp()
|
|
|
|
{
|
|
|
|
return SHInputManager::AnyKeyUp();
|
|
|
|
}
|
|
|
|
|
2022-10-16 03:25:33 +08:00
|
|
|
bool Input::GetKey(KeyCode key)
|
|
|
|
{
|
|
|
|
return SHInputManager::GetKey(static_cast<SHInputManager::SH_KEYCODE>(key));
|
|
|
|
}
|
|
|
|
|
|
|
|
bool Input::GetKeyDown(KeyCode key)
|
|
|
|
{
|
|
|
|
return SHInputManager::GetKeyDown(static_cast<SHInputManager::SH_KEYCODE>(key));
|
|
|
|
}
|
|
|
|
|
|
|
|
bool Input::GetKeyUp(KeyCode key)
|
|
|
|
{
|
|
|
|
return SHInputManager::GetKeyUp(static_cast<SHInputManager::SH_KEYCODE>(key));
|
|
|
|
}
|
|
|
|
|
|
|
|
bool Input::GetMouseButton(MouseCode mouseButton)
|
|
|
|
{
|
|
|
|
return SHInputManager::GetKey(static_cast<SHInputManager::SH_KEYCODE>(mouseButton));
|
|
|
|
}
|
|
|
|
|
|
|
|
bool Input::GetMouseButtonDown(MouseCode mouseButton)
|
|
|
|
{
|
|
|
|
return SHInputManager::GetKeyDown(static_cast<SHInputManager::SH_KEYCODE>(mouseButton));
|
|
|
|
}
|
|
|
|
|
|
|
|
bool Input::GetMouseButtonUp(MouseCode mouseButton)
|
|
|
|
{
|
|
|
|
return SHInputManager::GetKeyUp(static_cast<SHInputManager::SH_KEYCODE>(mouseButton));
|
|
|
|
}
|
|
|
|
|
2023-02-22 23:50:39 +08:00
|
|
|
bool Input::AnyControllerInput()
|
|
|
|
{
|
|
|
|
return SHInputManager::AnyControllerInput();
|
|
|
|
}
|
|
|
|
bool Input::AnyControllerInputDown()
|
|
|
|
{
|
|
|
|
return SHInputManager::AnyControllerInputDown();
|
|
|
|
}
|
|
|
|
bool Input::AnyControllerInputUp()
|
|
|
|
{
|
|
|
|
return SHInputManager::AnyControllerInputUp();
|
|
|
|
}
|
|
|
|
bool Input::AnyControllerButton()
|
|
|
|
{
|
|
|
|
return SHInputManager::AnyControllerButton();
|
|
|
|
}
|
|
|
|
bool Input::AnyControllerButtonDown()
|
|
|
|
{
|
|
|
|
return SHInputManager::AnyControllerButtonDown();
|
|
|
|
}
|
|
|
|
bool Input::AnyControllerButtonUp()
|
|
|
|
{
|
|
|
|
return SHInputManager::AnyControllerButtonUp();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool Input::GetControllerInput(Input::ControllerCode code)
|
|
|
|
{
|
|
|
|
return SHInputManager::GetControllerInput(static_cast<SHInputManager::SH_CONTROLLERCODE>(code));
|
|
|
|
}
|
|
|
|
double Input::GetControllerInputNormalisedValue(Input::ControllerCode code)
|
|
|
|
{
|
|
|
|
double toReturn = 0.0;
|
|
|
|
SHInputManager::GetControllerInput(static_cast<SHInputManager::SH_CONTROLLERCODE>(code), &toReturn);
|
|
|
|
return toReturn;
|
|
|
|
}
|
|
|
|
bool Input::GetControllerInputDown(Input::ControllerCode code)
|
|
|
|
{
|
|
|
|
return SHInputManager::GetControllerInputDown(static_cast<SHInputManager::SH_CONTROLLERCODE>(code));
|
|
|
|
}
|
|
|
|
bool Input::GetControllerInputUp(Input::ControllerCode code)
|
|
|
|
{
|
|
|
|
return SHInputManager::GetControllerInputUp(static_cast<SHInputManager::SH_CONTROLLERCODE>(code));
|
|
|
|
}
|
|
|
|
|
2022-10-16 03:25:33 +08:00
|
|
|
/*---------------------------------------------------------------------------------*/
|
|
|
|
/* Cursor Functions */
|
|
|
|
/*---------------------------------------------------------------------------------*/
|
|
|
|
void Input::SetMousePosition(Vector2 pos)
|
|
|
|
{
|
|
|
|
SHInputManager::SetMouseWindowPosition
|
|
|
|
(
|
|
|
|
static_cast<int>(pos.x),
|
|
|
|
static_cast<int>(pos.y)
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2023-02-22 23:50:39 +08:00
|
|
|
Vector2 Input::GetMousePosition()
|
|
|
|
{
|
|
|
|
int x = 0;
|
|
|
|
int y = 0;
|
|
|
|
SHInputManager::GetMouseWindowPosition(&x, &y);
|
|
|
|
return Convert::ToCLI(SHVec2{ (float)x,(float)y });
|
|
|
|
}
|
|
|
|
|
|
|
|
void Input::SetMouseCentering(bool state)
|
|
|
|
{
|
2023-03-05 21:11:24 +08:00
|
|
|
SHInputManager::SetMouseCentering(state);
|
2023-02-22 23:50:39 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
bool Input::GetMouseCentering()
|
|
|
|
{
|
|
|
|
return SHInputManager::GetMouseCentering();
|
|
|
|
}
|
|
|
|
|
2022-10-16 03:25:33 +08:00
|
|
|
/*---------------------------------------------------------------------------------*/
|
|
|
|
/* Time Functions */
|
|
|
|
/*---------------------------------------------------------------------------------*/
|
|
|
|
double Input::GetKeyHeldTime(KeyCode key)
|
|
|
|
{
|
|
|
|
return SHInputManager::GetKeyHeldTime(static_cast<SHInputManager::SH_KEYCODE>(key));
|
|
|
|
}
|
|
|
|
|
|
|
|
double Input::GetKeyReleasedTime(KeyCode key)
|
|
|
|
{
|
|
|
|
return SHInputManager::GetKeyReleasedTime(static_cast<SHInputManager::SH_KEYCODE>(key));
|
|
|
|
}
|
|
|
|
|
|
|
|
double Input::GetMouseHeldTime(MouseCode key)
|
|
|
|
{
|
|
|
|
return SHInputManager::GetKeyHeldTime(static_cast<SHInputManager::SH_KEYCODE>(key));
|
|
|
|
}
|
|
|
|
|
|
|
|
double Input::GetMouseReleasedTime(MouseCode key)
|
|
|
|
{
|
|
|
|
return SHInputManager::GetKeyReleasedTime(static_cast<SHInputManager::SH_KEYCODE>(key));
|
|
|
|
}
|
|
|
|
|
2022-11-01 15:30:13 +08:00
|
|
|
Vector2 Input::GetMouseVelocity()
|
|
|
|
{
|
|
|
|
double velX, velY;
|
|
|
|
SHInputManager::GetMouseVelocity(&velX, &velY);
|
|
|
|
|
|
|
|
return Convert::ToCLI(SHVec2{ (float)velX,(float)velY });
|
|
|
|
}
|
2023-02-22 23:50:39 +08:00
|
|
|
|
|
|
|
double Input::GetControllerInputHeldTime(Input::ControllerCode code)
|
|
|
|
{
|
|
|
|
return SHInputManager::GetControllerInputHeldTime(static_cast<SHInputManager::SH_CONTROLLERCODE>(code));
|
|
|
|
}
|
|
|
|
double Input::GetControllerInputReleasedTime(Input::ControllerCode code)
|
|
|
|
{
|
|
|
|
return SHInputManager::GetControllerInputReleasedTime(static_cast<SHInputManager::SH_CONTROLLERCODE>(code));
|
|
|
|
}
|
|
|
|
|
|
|
|
/*-----------------------------------------------------------------------------*/
|
|
|
|
/* Binding Functions */
|
|
|
|
/*-----------------------------------------------------------------------------*/
|
|
|
|
void Input::SaveBindings()
|
|
|
|
{
|
|
|
|
SHInputManager::SaveBindings();
|
|
|
|
}
|
|
|
|
|
|
|
|
void Input::SaveBindings(System::String^ targetFile)
|
|
|
|
{
|
|
|
|
SHInputManager::SaveBindings(Convert::ToNative(targetFile));
|
|
|
|
}
|
|
|
|
|
|
|
|
void Input::LoadBindings()
|
|
|
|
{
|
|
|
|
SHInputManager::LoadBindings();
|
|
|
|
}
|
|
|
|
|
|
|
|
void Input::LoadBindings(System::String^ sourceFile)
|
|
|
|
{
|
|
|
|
SHInputManager::LoadBindings(Convert::ToNative(sourceFile));
|
|
|
|
}
|
|
|
|
|
|
|
|
bool Input::GetBindingInverted(System::String^ bindingName)
|
|
|
|
{
|
|
|
|
return SHInputManager::GetBindingInverted(Convert::ToNative(bindingName));
|
|
|
|
}
|
|
|
|
void Input::SetBindingInverted(System::String^ bindingName, bool newValue)
|
|
|
|
{
|
|
|
|
SHInputManager::SetBindingInverted(Convert::ToNative(bindingName), newValue);
|
|
|
|
}
|
|
|
|
double Input::GetBindingGravity(System::String^ bindingName)
|
|
|
|
{
|
|
|
|
return SHInputManager::GetBindingGravity(Convert::ToNative(bindingName));
|
|
|
|
}
|
|
|
|
void Input::SetBindingGravity(System::String^ bindingName, double newValue)
|
|
|
|
{
|
|
|
|
SHInputManager::SetBindingGravity(Convert::ToNative(bindingName), newValue);
|
|
|
|
}
|
|
|
|
double Input::GetBindingDead(System::String^ bindingName)
|
|
|
|
{
|
|
|
|
return SHInputManager::GetBindingDead(Convert::ToNative(bindingName));
|
|
|
|
}
|
|
|
|
void Input::SetBindingDead(System::String^ bindingName, double newValue)
|
|
|
|
{
|
|
|
|
SHInputManager::SetBindingDead(Convert::ToNative(bindingName), newValue);
|
|
|
|
}
|
|
|
|
double Input::GetBindingSensitivity(System::String^ bindingName)
|
|
|
|
{
|
|
|
|
return SHInputManager::GetBindingSensitivity(Convert::ToNative(bindingName));
|
|
|
|
}
|
|
|
|
void Input::SetBindingSensitivity(System::String^ bindingName, double newValue)
|
|
|
|
{
|
|
|
|
SHInputManager::SetBindingSensitivity(Convert::ToNative(bindingName), newValue);
|
|
|
|
}
|
|
|
|
bool Input::GetBindingSnap(System::String^ bindingName)
|
|
|
|
{
|
|
|
|
return SHInputManager::GetBindingSnap(Convert::ToNative(bindingName));
|
|
|
|
}
|
|
|
|
void Input::SetBindingSnap(System::String^ bindingName, bool newValue)
|
|
|
|
{
|
|
|
|
SHInputManager::SetBindingSnap(Convert::ToNative(bindingName), newValue);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
System::Collections::Generic::HashSet<Input::KeyCode>^ Input::GetBindingPositiveKeyCodes(System::String^ bindingName)
|
|
|
|
{
|
|
|
|
System::Collections::Generic::HashSet<Input::KeyCode>^ toReturn = gcnew System::Collections::Generic::HashSet<Input::KeyCode>();
|
|
|
|
std::set<SHInputManager::SH_KEYCODE> list = SHInputManager::GetBindingPositiveKeyCodes(Convert::ToNative(bindingName));
|
|
|
|
for (auto kc : list)
|
|
|
|
{
|
|
|
|
toReturn->Add(static_cast<Input::KeyCode>(kc));
|
|
|
|
}
|
|
|
|
return toReturn;
|
|
|
|
}
|
|
|
|
void Input::AddBindingPositiveKeyCode(System::String^ bindingName, Input::KeyCode toAdd)
|
|
|
|
{
|
|
|
|
SHInputManager::AddBindingPositiveKeyCode(Convert::ToNative(bindingName), static_cast<SHInputManager::SH_KEYCODE>(toAdd));
|
|
|
|
}
|
|
|
|
void Input::RemoveBindingPositiveKeyCode(System::String^ bindingName, Input::KeyCode toRemove)
|
|
|
|
{
|
|
|
|
SHInputManager::RemoveBindingPositiveKeyCode(Convert::ToNative(bindingName), static_cast<SHInputManager::SH_KEYCODE>(toRemove));
|
|
|
|
}
|
|
|
|
void Input::ClearBindingPositiveKeyCodes(System::String^ bindingName)
|
|
|
|
{
|
|
|
|
SHInputManager::ClearBindingPositiveKeyCodes(Convert::ToNative(bindingName));
|
|
|
|
}
|
|
|
|
|
|
|
|
System::Collections::Generic::HashSet<Input::KeyCode>^ Input::GetBindingNegativeKeyCodes(System::String^ bindingName)
|
|
|
|
{
|
|
|
|
System::Collections::Generic::HashSet<Input::KeyCode>^ toReturn = gcnew System::Collections::Generic::HashSet<Input::KeyCode>();
|
|
|
|
std::set<SHInputManager::SH_KEYCODE> list = SHInputManager::GetBindingNegativeKeyCodes(Convert::ToNative(bindingName));
|
|
|
|
for (auto kc : list)
|
|
|
|
{
|
|
|
|
toReturn->Add(static_cast<Input::KeyCode>(kc));
|
|
|
|
}
|
|
|
|
return toReturn;
|
|
|
|
}
|
|
|
|
void Input::AddBindingNegativeKeyCode(System::String^ bindingName, Input::KeyCode toAdd)
|
|
|
|
{
|
|
|
|
SHInputManager::AddBindingNegativeKeyCode(Convert::ToNative(bindingName), static_cast<SHInputManager::SH_KEYCODE>(toAdd));
|
|
|
|
}
|
|
|
|
void Input::RemoveBindingNegativeKeyCode(System::String^ bindingName, Input::KeyCode toRemove)
|
|
|
|
{
|
|
|
|
SHInputManager::RemoveBindingNegativeKeyCode(Convert::ToNative(bindingName), static_cast<SHInputManager::SH_KEYCODE>(toRemove));
|
|
|
|
}
|
|
|
|
void Input::ClearBindingNegativeKeyCodes(System::String^ bindingName)
|
|
|
|
{
|
|
|
|
SHInputManager::ClearBindingNegativeKeyCodes(Convert::ToNative(bindingName));
|
|
|
|
}
|
|
|
|
|
|
|
|
System::Collections::Generic::HashSet<Input::ControllerCode>^ Input::GetBindingPositiveControllerCodes(System::String^ bindingName)
|
|
|
|
{
|
|
|
|
System::Collections::Generic::HashSet<Input::ControllerCode>^ toReturn = gcnew System::Collections::Generic::HashSet<Input::ControllerCode>();
|
|
|
|
std::set<SHInputManager::SH_CONTROLLERCODE> list = SHInputManager::GetBindingPositiveControllerCodes(Convert::ToNative(bindingName));
|
|
|
|
for (auto kc : list)
|
|
|
|
{
|
|
|
|
toReturn->Add(static_cast<Input::ControllerCode>(kc));
|
|
|
|
}
|
|
|
|
return toReturn;
|
|
|
|
}
|
|
|
|
void Input::AddBindingPositiveControllerCode(System::String^ bindingName, Input::ControllerCode toAdd)
|
|
|
|
{
|
|
|
|
SHInputManager::AddBindingPositiveControllerCode(Convert::ToNative(bindingName), static_cast<SHInputManager::SH_CONTROLLERCODE>(toAdd));
|
|
|
|
}
|
|
|
|
void Input::RemoveBindingPositiveControllerCode(System::String^ bindingName, Input::ControllerCode toRemove)
|
|
|
|
{
|
|
|
|
SHInputManager::RemoveBindingPositiveControllerCode(Convert::ToNative(bindingName), static_cast<SHInputManager::SH_CONTROLLERCODE>(toRemove));
|
|
|
|
}
|
|
|
|
void Input::ClearBindingPositiveControllerCodes(System::String^ bindingName)
|
|
|
|
{
|
|
|
|
SHInputManager::ClearBindingPositiveControllerCodes(Convert::ToNative(bindingName));
|
|
|
|
}
|
|
|
|
|
|
|
|
System::Collections::Generic::HashSet<Input::ControllerCode>^ Input::GetBindingNegativeControllerCodes(System::String^ bindingName)
|
|
|
|
{
|
|
|
|
System::Collections::Generic::HashSet<Input::ControllerCode>^ toReturn = gcnew System::Collections::Generic::HashSet<Input::ControllerCode>();
|
|
|
|
std::set<SHInputManager::SH_CONTROLLERCODE> list = SHInputManager::GetBindingNegativeControllerCodes(Convert::ToNative(bindingName));
|
|
|
|
for (auto kc : list)
|
|
|
|
{
|
|
|
|
toReturn->Add(static_cast<Input::ControllerCode>(kc));
|
|
|
|
}
|
|
|
|
return toReturn;
|
|
|
|
}
|
|
|
|
void Input::AddBindingNegativeControllerCode(System::String^ bindingName, Input::ControllerCode toAdd)
|
|
|
|
{
|
|
|
|
SHInputManager::AddBindingNegativeControllerCode(Convert::ToNative(bindingName), static_cast<SHInputManager::SH_CONTROLLERCODE>(toAdd));
|
|
|
|
}
|
|
|
|
void Input::RemoveBindingNegativeControllerCode(System::String^ bindingName, Input::ControllerCode toRemove)
|
|
|
|
{
|
|
|
|
SHInputManager::RemoveBindingNegativeControllerCode(Convert::ToNative(bindingName), static_cast<SHInputManager::SH_CONTROLLERCODE>(toRemove));
|
|
|
|
}
|
|
|
|
void Input::ClearBindingNegativeControllerCodes(System::String^ bindingName)
|
|
|
|
{
|
|
|
|
SHInputManager::ClearBindingNegativeControllerCodes(Convert::ToNative(bindingName));
|
|
|
|
}
|
|
|
|
|
|
|
|
double Input::GetBindingAxis(System::String^ bindingName)
|
|
|
|
{
|
|
|
|
return SHInputManager::GetBindingAxis(Convert::ToNative(bindingName));
|
|
|
|
}
|
|
|
|
double Input::GetBindingAxisRaw(System::String^ bindingName)
|
|
|
|
{
|
|
|
|
return SHInputManager::GetBindingAxisRaw(Convert::ToNative(bindingName));
|
|
|
|
}
|
|
|
|
bool Input::GetBindingPositiveButton(System::String^ bindingName)
|
|
|
|
{
|
|
|
|
return SHInputManager::GetBindingPositiveButton(Convert::ToNative(bindingName));
|
|
|
|
}
|
|
|
|
bool Input::GetBindingNegativeButton(System::String^ bindingName)
|
|
|
|
{
|
|
|
|
return SHInputManager::GetBindingNegativeButton(Convert::ToNative(bindingName));
|
|
|
|
}
|
|
|
|
bool Input::GetBindingPositiveButtonDown(System::String^ bindingName)
|
|
|
|
{
|
|
|
|
return SHInputManager::GetBindingPositiveButtonDown(Convert::ToNative(bindingName));
|
|
|
|
}
|
|
|
|
bool Input::GetBindingNegativeButtonDown(System::String^ bindingName)
|
|
|
|
{
|
|
|
|
return SHInputManager::GetBindingNegativeButtonDown(Convert::ToNative(bindingName));
|
|
|
|
}
|
|
|
|
bool Input::GetBindingPositiveButtonUp(System::String^ bindingName)
|
|
|
|
{
|
|
|
|
return SHInputManager::GetBindingPositiveButtonUp(Convert::ToNative(bindingName));
|
|
|
|
}
|
|
|
|
bool Input::GetBindingNegativeButtonUp(System::String^ bindingName)
|
|
|
|
{
|
|
|
|
return SHInputManager::GetBindingNegativeButtonUp(Convert::ToNative(bindingName));
|
|
|
|
}
|
|
|
|
|
|
|
|
double Input::GetBindingPositiveHeldTime(System::String^ bindingName)
|
|
|
|
{
|
|
|
|
return SHInputManager::GetBindingPositiveHeldTime(Convert::ToNative(bindingName));
|
|
|
|
}
|
|
|
|
double Input::GetBindingNegativeHeldTime(System::String^ bindingName)
|
|
|
|
{
|
|
|
|
return SHInputManager::GetBindingNegativeHeldTime(Convert::ToNative(bindingName));
|
|
|
|
}
|
|
|
|
double Input::GetBindingPositiveReleasedTime(System::String^ bindingName)
|
|
|
|
{
|
|
|
|
return SHInputManager::GetBindingPositiveReleasedTime(Convert::ToNative(bindingName));
|
|
|
|
}
|
|
|
|
double Input::GetBindingNegativeReleasedTime(System::String^ bindingName)
|
|
|
|
{
|
|
|
|
return SHInputManager::GetBindingNegativeReleasedTime(Convert::ToNative(bindingName));
|
|
|
|
}
|
2022-10-16 03:25:33 +08:00
|
|
|
}
|