diff --git a/lib/Ray/CMakeLists.txt b/lib/Ray/CMakeLists.txt index 4cd45a25..04e88bb0 100644 --- a/lib/Ray/CMakeLists.txt +++ b/lib/Ray/CMakeLists.txt @@ -49,6 +49,7 @@ set(HEADERS include/Drawables/3D/Ray.hpp include/Drawables/3D/Sphere.hpp include/Drawables/3D/Triangle.hpp + include/Controllers/IController.hpp ) set(SRC diff --git a/lib/Ray/include/Controllers/Gamepad.hpp b/lib/Ray/include/Controllers/Gamepad.hpp index b250d5a3..f7b3157c 100644 --- a/lib/Ray/include/Controllers/Gamepad.hpp +++ b/lib/Ray/include/Controllers/Gamepad.hpp @@ -10,11 +10,13 @@ #include #include +#include "IController.hpp" -namespace RAY { +namespace RAY +{ //! @brief Entity representing a gamepad controller - class GamePad { + class GamePad : public IController { public: typedef ::GamepadButton Button; @@ -23,7 +25,7 @@ namespace RAY { GamePad(int id); //! @brief A default destructor - ~GamePad() = default; + ~GamePad() = override default; //! @brief A default copy constructor GamePad(const GamePad &) = default; @@ -34,29 +36,29 @@ namespace RAY { //! @brief Returns true if Button is pressed on the gamepad //! @param Button The keycode of the button - bool isPressed(Button); + bool isPressed(Button) override; //! @brief Returns true if Button is down on the gamepad //! @param Button The keycode of the button - bool isDown(Button); + bool isDown(Button) override; //! @brief Returns true if Button is released on the gamepad //! @param Button The keycode of the button - bool isReleased(Button); + bool isReleased(Button) override; //! @brief Returns true if Button is up on the gamepad //! @param Button The keycode of the button - bool isUp(Button); + bool isUp(Button) override; //! @brief Returns true if controller is available - bool isAvailable(Button); + bool isAvailable(Button) override; //! @brief Sets gamepad's id void setID(int id); //! @brief Fetch currently pressed buttons //! @return Returns a vector containing keycode of currently pressed buttons - std::vector getPressedButtons(void); + std::vector getPressedButtons(void) override; private: //! @brief The id of the controller, used to fetch buttons' states diff --git a/lib/Ray/include/Controllers/IController.hpp b/lib/Ray/include/Controllers/IController.hpp new file mode 100644 index 00000000..01290173 --- /dev/null +++ b/lib/Ray/include/Controllers/IController.hpp @@ -0,0 +1,38 @@ +// +// Created by cbihan on 17/05/2021. +// + +#pragma once + + +namespace RAY +{ + class IController + { + public: + //! @brief Returns true if Button is pressed on the gamepad + //! @param Button The keycode of the button + virtual bool isPressed(Button) = 0; + + //! @brief Returns true if Button is down on the gamepad + //! @param Button The keycode of the button + virtual bool isDown(Button) = 0; + + //! @brief Returns true if Button is released on the gamepad + //! @param Button The keycode of the button + virtual bool isReleased(Button) = 0; + + //! @brief Returns true if Button is up on the gamepad + //! @param Button The keycode of the button + virtual bool isUp(Button) = 0; + + //! @brief Returns true if controller is available + virtual bool isAvailable(Button) = 0; + + //! @brief Fetch currently pressed buttons + //! @return Returns a vector containing keycode of currently pressed buttons + virtual std::vector getPressedButtons(void) = 0; + + virtual ~IController() = default; + }; +} \ No newline at end of file