Capycore Engine  0.1.0
A simple and lightweight game engine written in C++ based on the Unity API architecture.
Loading...
Searching...
No Matches
i_input_provider.h
Go to the documentation of this file.
1#pragma once
2
8
9#include <cstddef>
10#include <memory>
11#include <optional>
12#include <utility>
13
21 public:
22 virtual ~IInputProvider() = default;
23
24 void set_input(std::unique_ptr<IInput> input);
25 [[nodiscard]] std::optional<std::reference_wrapper<IInput>> input() const;
26
32 [[nodiscard]] virtual bool is_key_held(KeyCode key) const = 0;
33
39 [[nodiscard]] virtual bool is_key_pressed(KeyCode key) const = 0;
40
46 [[nodiscard]] virtual KeyCode get_pressed_key() const = 0;
47
53 [[nodiscard]] virtual bool is_key_released(KeyCode key) const = 0;
54
60 [[nodiscard]] virtual bool any_key_held() const = 0;
61
67 [[nodiscard]] virtual bool any_key_pressed() const = 0;
68
74 [[nodiscard]] virtual bool any_key_released() const = 0;
75
80 [[nodiscard]] virtual bool is_mouse_held(MouseButton button) const = 0;
81
87 [[nodiscard]] virtual bool is_mouse_pressed(MouseButton button) const = 0;
88
94 [[nodiscard]] virtual bool is_mouse_released(MouseButton button) const = 0;
95
100 [[nodiscard]] virtual bool any_mouse_held() const = 0;
101
106 [[nodiscard]] virtual bool any_mouse_pressed() const = 0;
107
112 [[nodiscard]] virtual bool any_mouse_released() const = 0;
113
120 [[nodiscard]] virtual const Point& mouse_position() const = 0;
121
122 // TODO: Replace std::pair<float, float> with a dedicated Vector2 type for
123 // clearer semantics and math operations.
131 [[nodiscard]] virtual std::pair<float, float> mouse_delta() const = 0;
132
139 [[nodiscard]] virtual bool mouse_moved() const = 0;
140
141 // TODO: Replace std::pair<float, float> with a dedicated Vector2 type for
142 // clearer semantics and math operations.
148 [[nodiscard]] virtual std::pair<float, float> mouse_scroll() const = 0;
149
150 // TODO: Replace std::pair<float, float> with a dedicated Vector2 type for
151 // clearer semantics and math operations.
157 [[nodiscard]] virtual std::pair<float, float> mouse_scroll_delta() const = 0;
158
165 [[nodiscard]] virtual MouseDirection mouse_scroll_direction() const = 0;
166
172 virtual void reset_state() = 0;
173
179 virtual void register_events() = 0;
180
186 virtual void update() = 0;
187
188 private:
189 std::unique_ptr<IInput> input_;
190};
Interface for querying low-level keyboard input.
Definition i_input_provider.h:20
virtual bool is_mouse_pressed(MouseButton button) const =0
Returns true on the frame the specified mouse button transitions to pressed.
std::optional< std::reference_wrapper< IInput > > input() const
virtual std::pair< float, float > mouse_scroll() const =0
Returns the accumulated scroll offset along X and Y axes.
virtual std::pair< float, float > mouse_delta() const =0
Returns the change in mouse position since the last frame (deltaX, deltaY).
virtual bool is_key_held(KeyCode key) const =0
Returns whether the specified key is currently held down.
virtual bool is_key_released(KeyCode key) const =0
Returns true on the frame the specified key transitions to released.
virtual bool is_key_pressed(KeyCode key) const =0
Returns true on the frame the specified key transitions to pressed.
virtual bool is_mouse_released(MouseButton button) const =0
Returns true on the frame the specified mouse button transitions to released.
virtual bool any_key_pressed() const =0
Returns true if any key was pressed this frame.
virtual bool any_key_held() const =0
Returns true if any key is currently held down.
virtual KeyCode get_pressed_key() const =0
Returns the first key pressed this frame.
virtual void register_events()=0
Registers necessary event listeners with the underlying system.
virtual std::pair< float, float > mouse_scroll_delta() const =0
Returns the scroll delta since the last frame (deltaX, deltaY).
virtual bool any_mouse_pressed() const =0
Returns true if any mouse button was pressed this frame.
virtual ~IInputProvider()=default
virtual void reset_state()=0
Clears all input states (useful when changing scenes or focus).
void set_input(std::unique_ptr< IInput > input)
virtual bool any_mouse_held() const =0
Returns true if any mouse button is currently held down.
virtual bool mouse_moved() const =0
Returns true if the mouse moved during the current frame.
virtual bool is_mouse_held(MouseButton button) const =0
Returns whether the specified mouse button is currently held down.
virtual const Point & mouse_position() const =0
Returns the current mouse cursor position (X, Y) in window coordinates.
virtual bool any_key_released() const =0
Returns true on the frame any key transitions to released.
virtual MouseDirection mouse_scroll_direction() const =0
Returns the last detected scroll direction as an integer enum.
virtual bool any_mouse_released() const =0
Returns true on the frame any mouse button transitions to released.
virtual void update()=0
Polls the underlying system for input updates.
Represents a point in 2D space.
Definition point.h:6
KeyCode
Definition key_code.h:5
MouseButton
Definition mouse_button.h:5
MouseDirection
Represents the primary directions of mouse wheel movement.
Definition mouse_state.h:14