diff --git a/SHADE_Managed/src/Input/Input.cxx b/SHADE_Managed/src/Input/Input.cxx new file mode 100644 index 00000000..0a386f3a --- /dev/null +++ b/SHADE_Managed/src/Input/Input.cxx @@ -0,0 +1,102 @@ +/************************************************************************************//*! +\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(x), static_cast(y), 0.0f); + } + int Input::MouseScrollDelta::get() + { + return SHInputManager::GetMouseWheelVerticalDelta(); + } + + /*---------------------------------------------------------------------------------*/ + /* Usage Functions */ + /*---------------------------------------------------------------------------------*/ + bool Input::GetKey(KeyCode key) + { + return SHInputManager::GetKey(static_cast(key)); + } + + bool Input::GetKeyDown(KeyCode key) + { + return SHInputManager::GetKeyDown(static_cast(key)); + } + + bool Input::GetKeyUp(KeyCode key) + { + return SHInputManager::GetKeyUp(static_cast(key)); + } + + bool Input::GetMouseButton(MouseCode mouseButton) + { + return SHInputManager::GetKey(static_cast(mouseButton)); + } + + bool Input::GetMouseButtonDown(MouseCode mouseButton) + { + return SHInputManager::GetKeyDown(static_cast(mouseButton)); + } + + bool Input::GetMouseButtonUp(MouseCode mouseButton) + { + return SHInputManager::GetKeyUp(static_cast(mouseButton)); + } + + /*---------------------------------------------------------------------------------*/ + /* Cursor Functions */ + /*---------------------------------------------------------------------------------*/ + void Input::SetMousePosition(Vector2 pos) + { + SHInputManager::SetMouseWindowPosition + ( + static_cast(pos.x), + static_cast(pos.y) + ); + } + + /*---------------------------------------------------------------------------------*/ + /* Time Functions */ + /*---------------------------------------------------------------------------------*/ + double Input::GetKeyHeldTime(KeyCode key) + { + return SHInputManager::GetKeyHeldTime(static_cast(key)); + } + + double Input::GetKeyReleasedTime(KeyCode key) + { + return SHInputManager::GetKeyReleasedTime(static_cast(key)); + } + + double Input::GetMouseHeldTime(MouseCode key) + { + return SHInputManager::GetKeyHeldTime(static_cast(key)); + } + + double Input::GetMouseReleasedTime(MouseCode key) + { + return SHInputManager::GetKeyReleasedTime(static_cast(key)); + } + +} \ No newline at end of file diff --git a/SHADE_Managed/src/Input/Input.hxx b/SHADE_Managed/src/Input/Input.hxx new file mode 100644 index 00000000..f281e4c8 --- /dev/null +++ b/SHADE_Managed/src/Input/Input.hxx @@ -0,0 +1,325 @@ +/************************************************************************************//*! +\file Input.hxx +\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. +*//*************************************************************************************/ +#pragma once + +#include "Input/SHInputManager.h" +#include "Math/Vector2.hxx" +#include "Math/Vector3.hxx" + +namespace SHADE +{ + /// + /// Static class responsible for providing access to Input-related functionality. + /// + public ref class Input abstract sealed + { + public: + /*-----------------------------------------------------------------------------*/ + /* Type Definitions */ + /*-----------------------------------------------------------------------------*/ + /// + /// Represents the available supported keycodes that can be passed into the + /// key-based Input functions. + /// + enum class KeyCode : int + { + Space = static_cast(SHInputManager::SH_KEYCODE::SPACE), + //Apostrophe = static_cast(SHInputManager::SH_KEYCODE::APOSTROPHE), + Comma = static_cast(SHInputManager::SH_KEYCODE::OEM_COMMA), + Minus = static_cast(SHInputManager::SH_KEYCODE::OEM_MINUS), + Period = static_cast(SHInputManager::SH_KEYCODE::OEM_PERIOD), + //Slash = static_cast(SHInputManager::SH_KEYCODE::SLASH), + Key0 = static_cast(SHInputManager::SH_KEYCODE::NUMBER_0), + Key1 = static_cast(SHInputManager::SH_KEYCODE::NUMBER_1), + Key2 = static_cast(SHInputManager::SH_KEYCODE::NUMBER_2), + Key3 = static_cast(SHInputManager::SH_KEYCODE::NUMBER_3), + Key4 = static_cast(SHInputManager::SH_KEYCODE::NUMBER_4), + Key5 = static_cast(SHInputManager::SH_KEYCODE::NUMBER_5), + Key6 = static_cast(SHInputManager::SH_KEYCODE::NUMBER_6), + Key7 = static_cast(SHInputManager::SH_KEYCODE::NUMBER_7), + Key8 = static_cast(SHInputManager::SH_KEYCODE::NUMBER_8), + Key9 = static_cast(SHInputManager::SH_KEYCODE::NUMBER_9), + + //Semicolon = static_cast(SHInputManager::SH_KEYCODE::SEMICOLON), + //Equal = static_cast(SHInputManager::SH_KEYCODE::EQUAL), + + A = static_cast(SHInputManager::SH_KEYCODE::A), + B = static_cast(SHInputManager::SH_KEYCODE::B), + C = static_cast(SHInputManager::SH_KEYCODE::C), + D = static_cast(SHInputManager::SH_KEYCODE::D), + E = static_cast(SHInputManager::SH_KEYCODE::E), + F = static_cast(SHInputManager::SH_KEYCODE::F), + G = static_cast(SHInputManager::SH_KEYCODE::G), + H = static_cast(SHInputManager::SH_KEYCODE::H), + I = static_cast(SHInputManager::SH_KEYCODE::I), + J = static_cast(SHInputManager::SH_KEYCODE::J), + K = static_cast(SHInputManager::SH_KEYCODE::K), + L = static_cast(SHInputManager::SH_KEYCODE::L), + M = static_cast(SHInputManager::SH_KEYCODE::M), + N = static_cast(SHInputManager::SH_KEYCODE::N), + O = static_cast(SHInputManager::SH_KEYCODE::O), + P = static_cast(SHInputManager::SH_KEYCODE::P), + Q = static_cast(SHInputManager::SH_KEYCODE::Q), + R = static_cast(SHInputManager::SH_KEYCODE::R), + S = static_cast(SHInputManager::SH_KEYCODE::S), + T = static_cast(SHInputManager::SH_KEYCODE::T), + U = static_cast(SHInputManager::SH_KEYCODE::U), + V = static_cast(SHInputManager::SH_KEYCODE::V), + W = static_cast(SHInputManager::SH_KEYCODE::W), + X = static_cast(SHInputManager::SH_KEYCODE::X), + Y = static_cast(SHInputManager::SH_KEYCODE::Y), + Z = static_cast(SHInputManager::SH_KEYCODE::Z), + + //LeftBracket = static_cast(SHInputManager::SH_KEYCODE::LEFTBRACKET), + //BackSlash = static_cast(SHInputManager::SH_KEYCODE::BACKSLASH), + //RightBracket = static_cast(SHInputManager::SH_KEYCODE::RIGHTBRACKET), + //GraveAccent = static_cast(SHInputManager::SH_KEYCODE::GRAVEACCENT), + + //WORLD1 = static_cast(SHInputManager::SH_KEYCODE::WORLD1), + //WORLD2 = static_cast(SHInputManager::SH_KEYCODE::WORLD2), + + /* Function keys */ + Escape = static_cast(SHInputManager::SH_KEYCODE::ESCAPE), + Enter = static_cast(SHInputManager::SH_KEYCODE::ENTER), + Tab = static_cast(SHInputManager::SH_KEYCODE::TAB), + Backspace = static_cast(SHInputManager::SH_KEYCODE::BACKSPACE), + Insert = static_cast(SHInputManager::SH_KEYCODE::INSERT), + Delete = static_cast(SHInputManager::SH_KEYCODE::DEL), + Right = static_cast(SHInputManager::SH_KEYCODE::RIGHT_ARROW), + Left = static_cast(SHInputManager::SH_KEYCODE::LEFT_ARROW), + Down = static_cast(SHInputManager::SH_KEYCODE::DOWN_ARROW), + Up = static_cast(SHInputManager::SH_KEYCODE::UP_ARROW), + PageUp = static_cast(SHInputManager::SH_KEYCODE::PAGE_UP), + PageDown = static_cast(SHInputManager::SH_KEYCODE::PAGE_DOWN), + Home = static_cast(SHInputManager::SH_KEYCODE::HOME), + End = static_cast(SHInputManager::SH_KEYCODE::END), + CapsLock = static_cast(SHInputManager::SH_KEYCODE::CAPS_LOCK), + ScrollLock = static_cast(SHInputManager::SH_KEYCODE::SCROLL_LOCK), + NumLock = static_cast(SHInputManager::SH_KEYCODE::NUM_LOCK), + PrintScreen = static_cast(SHInputManager::SH_KEYCODE::PRINT_SCREEN), + Pause = static_cast(SHInputManager::SH_KEYCODE::PAUSE), + F1 = static_cast(SHInputManager::SH_KEYCODE::F1), + F2 = static_cast(SHInputManager::SH_KEYCODE::F2), + F3 = static_cast(SHInputManager::SH_KEYCODE::F3), + F4 = static_cast(SHInputManager::SH_KEYCODE::F4), + F5 = static_cast(SHInputManager::SH_KEYCODE::F5), + F6 = static_cast(SHInputManager::SH_KEYCODE::F6), + F7 = static_cast(SHInputManager::SH_KEYCODE::F7), + F8 = static_cast(SHInputManager::SH_KEYCODE::F8), + F9 = static_cast(SHInputManager::SH_KEYCODE::F9), + F10 = static_cast(SHInputManager::SH_KEYCODE::F10), + F11 = static_cast(SHInputManager::SH_KEYCODE::F11), + F12 = static_cast(SHInputManager::SH_KEYCODE::F12), + F13 = static_cast(SHInputManager::SH_KEYCODE::F13), + F14 = static_cast(SHInputManager::SH_KEYCODE::F14), + F15 = static_cast(SHInputManager::SH_KEYCODE::F15), + F16 = static_cast(SHInputManager::SH_KEYCODE::F16), + F17 = static_cast(SHInputManager::SH_KEYCODE::F17), + F18 = static_cast(SHInputManager::SH_KEYCODE::F18), + F19 = static_cast(SHInputManager::SH_KEYCODE::F19), + F20 = static_cast(SHInputManager::SH_KEYCODE::F20), + F21 = static_cast(SHInputManager::SH_KEYCODE::F21), + F22 = static_cast(SHInputManager::SH_KEYCODE::F22), + F23 = static_cast(SHInputManager::SH_KEYCODE::F23), + F24 = static_cast(SHInputManager::SH_KEYCODE::F24), + + /* Keypad */ + KeyPad0 = static_cast(SHInputManager::SH_KEYCODE::NUMPAD_0), + KeyPad1 = static_cast(SHInputManager::SH_KEYCODE::NUMPAD_1), + KeyPad2 = static_cast(SHInputManager::SH_KEYCODE::NUMPAD_2), + KeyPad3 = static_cast(SHInputManager::SH_KEYCODE::NUMPAD_3), + KeyPad4 = static_cast(SHInputManager::SH_KEYCODE::NUMPAD_4), + KeyPad5 = static_cast(SHInputManager::SH_KEYCODE::NUMPAD_5), + KeyPad6 = static_cast(SHInputManager::SH_KEYCODE::NUMPAD_6), + KeyPad7 = static_cast(SHInputManager::SH_KEYCODE::NUMPAD_7), + KeyPad8 = static_cast(SHInputManager::SH_KEYCODE::NUMPAD_8), + KeyPad9 = static_cast(SHInputManager::SH_KEYCODE::NUMPAD_9), + //KeyPadDecimal = static_cast(SHInputManager::SH_KEYCODE::KPDECIMAL), + //KeyPadDivide = static_cast(SHInputManager::SH_KEYCODE::KPDIVIDE), + //KeyPadMultiply = static_cast(SHInputManager::SH_KEYCODE::KPMULTIPLY), + //KeyPadSubtract = static_cast(SHInputManager::SH_KEYCODE::KPSUBTRACT), + //KeyPadAdd = static_cast(SHInputManager::SH_KEYCODE::KPADD), + //KeyPadEnter = static_cast(SHInputManager::SH_KEYCODE::KPENTER), + //KeyPadEqual = static_cast(SHInputManager::SH_KEYCODE::KEYPAD), + + Shift = static_cast(SHInputManager::SH_KEYCODE::SHIFT), + LeftControl = static_cast(SHInputManager::SH_KEYCODE::LEFT_CTRL), + LeftAlt = static_cast(SHInputManager::SH_KEYCODE::LEFT_ALT), + LeftSuper = static_cast(SHInputManager::SH_KEYCODE::LEFT_WINDOWS), + RightShift = static_cast(SHInputManager::SH_KEYCODE::RIGHT_SHIFT), + RightControl = static_cast(SHInputManager::SH_KEYCODE::RIGHT_CTRL), + RightAlt = static_cast(SHInputManager::SH_KEYCODE::RIGHT_ALT), + RightSuper = static_cast(SHInputManager::SH_KEYCODE::RIGHT_WINDOWS), + + /* Gamepad */ + JoystickA = static_cast(SHInputManager::SH_KEYCODE::GAMEPAD_A), + JoystickB = static_cast(SHInputManager::SH_KEYCODE::GAMEPAD_B), + JoystickX = static_cast(SHInputManager::SH_KEYCODE::GAMEPAD_X), + JoystickY = static_cast(SHInputManager::SH_KEYCODE::GAMEPAD_Y), + JoystickLeftBumper = static_cast(SHInputManager::SH_KEYCODE::GAMEPAD_LEFTSHOULDER), + JoystickRightBumper = static_cast(SHInputManager::SH_KEYCODE::GAMEPAD_RIGHTSHOULDER), + JoystickLeftTrigger = static_cast(SHInputManager::SH_KEYCODE::GAMEPAD_LEFTTRIGGER), + JoystickRightTrigger = static_cast(SHInputManager::SH_KEYCODE::GAMEPAD_RIGHTTRIGGER), + JoystickDPadUp = static_cast(SHInputManager::SH_KEYCODE::GAMEPAD_DPAD_UP), + JoystickDPadDown = static_cast(SHInputManager::SH_KEYCODE::GAMEPAD_DPAD_DOWN), + JoystickDPadLeft = static_cast(SHInputManager::SH_KEYCODE::GAMEPAD_DPAD_LEFT), + JoystickDPadRight = static_cast(SHInputManager::SH_KEYCODE::GAMEPAD_DPAD_RIGHT), + JoystickMenu = static_cast(SHInputManager::SH_KEYCODE::GAMEPAD_MENU), + JoystickView = static_cast(SHInputManager::SH_KEYCODE::GAMEPAD_VIEW), + JoystickLeftStick = static_cast(SHInputManager::SH_KEYCODE::GAMEPAD_LEFT_THUMBSTICK_BUTTON), + JoystickRightStick = static_cast(SHInputManager::SH_KEYCODE::GAMEPAD_RIGHT_THUMBSTICK_BUTTON), + + /* Unity Gamepad Mappings */ + JoystickButton0 = JoystickA, + JoystickButton1 = JoystickB, + JoystickButton2 = JoystickX, + JoystickButton3 = JoystickY, + JoystickButton4 = JoystickLeftBumper, + JoystickButton5 = JoystickRightBumper, + JoystickButton6 = JoystickView, + JoystickButton7 = JoystickMenu, + JoystickButton8 = JoystickLeftStick, + JoystickButton9 = JoystickRightStick + + }; + /// + /// Represents the available supported mouse keycodes that can be passed into the + /// mouse-button-based Input functions. + /// + enum class MouseCode : int + { + LeftButton = static_cast(SHInputManager::SH_KEYCODE::LMB), + RightButton = static_cast(SHInputManager::SH_KEYCODE::RMB), + MiddleButton = static_cast(SHInputManager::SH_KEYCODE::MMB), + Button3 = static_cast(SHInputManager::SH_KEYCODE::XMB1), + Button4 = static_cast(SHInputManager::SH_KEYCODE::XMB2) + }; + + /*-----------------------------------------------------------------------------*/ + /* Properites */ + /*-----------------------------------------------------------------------------*/ + /// + /// Mouse position in screen coordinates relative to the top left of the window. + /// This value is a Vector3 for compatibility with functions that have Vector3 + /// arguments. The z component of the Vector3 is always 0 + /// + static property Vector3 MousePosition + { + Vector3 get(); + } + /// + /// Amnount of vertical mouse scroll in this frame. + /// + static property int MouseScrollDelta + { + int get(); + } + + /*-----------------------------------------------------------------------------*/ + /* Usage Functions */ + /*-----------------------------------------------------------------------------*/ + /// + /// Checks if a specified key is being held down. + /// This will also be true if GetKeyDown() is true. + /// + /// KeyCode of the key to check. + /// True while the user holds down the key specified. + static bool GetKey(KeyCode key); + /// + /// Checks if a specified key is pressed and was not pressed before. + /// + /// KeyCode of the key to check. + /// + /// True during the frame the user starts pressing down the key specified. + /// + static bool GetKeyDown(KeyCode key); + /// + /// Checks if a specified key is no longer pressed pressed and was pressed + /// before. + /// + /// KeyCode of the key to check. + /// + /// True during the frame the user releases the key identified by name. + /// + static bool GetKeyUp(KeyCode key); + /// + /// Checks if a specified mouse button is being held down. + /// This will also be true if GetMouseButtonDown() is true. + /// + /// MouseCode of the mouse button to check. + /// True while the user holds down the mouse button specified. + static bool GetMouseButton(MouseCode mouseButton); + /// + /// Checks if a specified mouse button is pressed and was not pressed before. + /// + /// MouseCode of the mouse button to check. + /// + /// True during the frame the user pressed the given mouse button. + /// + static bool GetMouseButtonDown(MouseCode mouseButton); + /// + /// Checks if a specified mouse button is no longer pressed and was pressed + /// before. + /// + /// MouseCode of the mouse button to check. + /// + /// True during the frame the user releases the given mouse button. + /// + static bool GetMouseButtonUp(MouseCode mouseButton); + + /*-----------------------------------------------------------------------------*/ + /* Cursor Functions */ + /*-----------------------------------------------------------------------------*/ + /// + /// Sets the position of the mouse cursor relative to the top left corner of the + /// window. + /// + /// + /// Position of the mouse in window pixel coordinates to set. + /// + static void SetMousePosition(Vector2 pos); + + /*-----------------------------------------------------------------------------*/ + /* Timing Functions */ + /*-----------------------------------------------------------------------------*/ + /// + /// Retrieves the duration that the specified key has been held or was last held + /// for. + /// + /// The key to check. + /// Time in seconds that the key was held. + static double GetKeyHeldTime(KeyCode key); + /// + /// Retrieves the duration that the specified key has not been held or was last + /// not been held for. + /// + /// The key to check. + /// Time in seconds that the key was held. + static double GetKeyReleasedTime(KeyCode key); + /// + /// Retrieves the duration that the specified key has been held or was last held + /// for. + /// + /// The key to check. + /// Time in seconds that the key was held. + static double GetMouseHeldTime(MouseCode mouseButton); + /// + /// Retrieves the duration that the specified key has not been held or was last + /// not been held for. + /// + /// The key to check. + /// Time in seconds that the key was held. + static double GetMouseReleasedTime(MouseCode mouseButton); + }; +} \ No newline at end of file