CeresEngine 0.2.0
A game development framework
Loading...
Searching...
No Matches
InputManager.hpp
Go to the documentation of this file.
1//
2// CeresEngine - A game development framework
3//
4// Created by Rogiel Sulzbach.
5// Copyright (c) 2018-2022 Rogiel Sulzbach. All rights reserved.
6//
7
8#pragma once
9
10#include "InputEvent.hpp"
11#include "InputState.hpp"
12
14
18
19namespace CeresEngine {
20
21 class InputAction;
22 class InputRange;
23
24 class InputContext;
25 enum class CursorMode;
26
27 class InputProvider;
28
30 private:
33
36
40
41 public:
43
44 Event<void(const KeyEvent&)> onKeyDown;
45 Event<void(const KeyEvent&)> onKeyUp;
46
48 Event<void(const MouseEvent&)> onMouseUp;
52
54
55 public:
58 explicit InputManager(InputProvider& provider) noexcept;
59
60 InputManager(const InputManager&) = delete;
62
65
66 public:
70 [[nodiscard]] CE_SCRIPT_EXPORT()
71 InputAction& action(const StringView& name);
72
76 [[nodiscard]] const InputAction& action(const StringView& name) const;
77
81 [[nodiscard]] CE_SCRIPT_EXPORT()
82 InputRange& range(const StringView& name);
83
87 [[nodiscard]] const InputRange& range(const StringView& name) const;
88
89 public:
94 InputContext& add(const StringView& contextName);
95
99 void remove(const StringView& contextName);
100
104 [[nodiscard]] CE_SCRIPT_EXPORT()
105 InputContext& context(const StringView& contextName);
106
110 [[nodiscard]] const InputContext& context(const StringView& contextName) const;
111
112 public:
115 void update();
116
119 void setCursorMode(CursorMode mode);
120
122 const InputState& getInputState() const noexcept { return mInputState; }
123 };
124
125} // namespace CeresEngine
#define CE_SCRIPT_EXPORT(...)
The CE_SCRIPT_EXPORT macro marks a class or method as exportable and available in scripting environme...
Definition Macros.hpp:247
A type that describes any possible event type.
Definition InputEvent.hpp:142
Definition Action.hpp:23
Definition InputContext.hpp:24
Definition InputManager.hpp:29
Event< void(const KeyEvent &)> onKeyUp
Definition InputManager.hpp:45
Event< void(const MouseEvent &)> onMouseDown
Definition InputManager.hpp:47
InputState mInputState
The current state of input.
Definition InputManager.hpp:39
InputProvider & provider
The input provider to fetch input state from.
Definition InputManager.hpp:35
Event< void(const MouseEvent &)> onMouseDrag
Definition InputManager.hpp:50
Event< void(const TextEvent &)> onTextInput
Definition InputManager.hpp:53
Event< void(const MouseEvent &)> onMouseUp
Definition InputManager.hpp:48
InputManager(const InputManager &)=delete
Event< void(const AnyInputEvent &)> didReceiveEvent
Definition InputManager.hpp:42
InputManager & operator=(const InputManager &)=delete
Event< void(const KeyEvent &)> onKeyDown
Definition InputManager.hpp:44
Event< void(const MouseEvent &)> onMouseScroll
Definition InputManager.hpp:51
Event< void(const MouseEvent &)> onMouseMove
Definition InputManager.hpp:49
Map< String, InputContext > contexts
A map of all active contexts.
Definition InputManager.hpp:32
~InputManager()
Destroys the input manager.
InputManager(InputProvider &provider) noexcept
Create a new input manager.
Definition InputProvider.hpp:21
Definition Range.hpp:18
Definition InputState.hpp:20
Base template for the event class.
Definition Event.hpp:27
Definition Application.hpp:19
CursorMode
A enumeration of supported cursor modes.
Definition Input.hpp:428
constexpr size_t hash(const T &v)
Generates a hash for the provided type.
Definition Hash.hpp:25
std::map< Key, T, Compare, ScopedAllocatorAdaptor< StdAllocator< Pair< const Key, T >, RawAllocator > > > Map
Map is a sorted associative container that contains key-value pairs with unique keys.
Definition Map.hpp:24
A structure that describes a key press event.
Definition InputEvent.hpp:55
A structure that describes a mouse event.
Definition InputEvent.hpp:98
A structure that describes a text input event.
Definition InputEvent.hpp:124