Engine²
Open-source game engine written in C++.
Loading...
Searching...
No Matches
Input::Resource::InputManager Class Reference

#include <InputManager.hpp>

Public Member Functions

 InputManager (Engine::Core &core)
 ~InputManager ()=default
template<typename TCallable>
FunctionUtils::FunctionID RegisterKeyCallback (TCallable callback)
 Register a key callback.
template<typename TCallable>
FunctionUtils::FunctionID RegisterCharCallback (TCallable callback)
 Register a char callback.
template<typename TCallable>
FunctionUtils::FunctionID RegisterCharModsCallback (TCallable callback)
 Register a char mods callback.
template<typename TCallable>
FunctionUtils::FunctionID RegisterMouseButtonCallback (TCallable callback)
 Register a mouse button callback.
template<typename TCallable>
FunctionUtils::FunctionID RegisterCursorPosCallback (TCallable callback)
 Register a cursor position callback.
template<typename TCallable>
FunctionUtils::FunctionID RegisterCursorEnterCallback (TCallable callback)
 Register a cursor enter callback.
template<typename TCallable>
FunctionUtils::FunctionID RegisterScrollCallback (TCallable callback)
 Register a scroll callback.
template<typename TCallable>
FunctionUtils::FunctionID RegisterDropCallback (TCallable callback)
 Register a drop callback.
void CallKeyCallbacks (Engine::Core &core, int key, int scancode, int action, int mods)
 Call the key callbacks.
void CallCharCallbacks (Engine::Core &core, unsigned int codepoint)
 Call the char callbacks.
void CallCharModsCallbacks (Engine::Core &core, unsigned int codepoint, int mods) const
 Call the char mods callbacks.
void CallMouseButtonCallbacks (Engine::Core &core, int button, int action, int mods) const
 Call the mouse button callbacks.
void CallCursorPosCallbacks (Engine::Core &core, double xpos, double ypos) const
 Call the cursor position callbacks.
void CallCursorEnterCallbacks (Engine::Core &core, int entered) const
 Call the cursor enter callbacks.
void CallScrollCallbacks (Engine::Core &core, double xoffset, double yoffset) const
 Call the scroll callbacks.
void CallDropCallbacks (Engine::Core &core, int count, const char **paths) const
 Call the drop callbacks.
bool DeleteKeyCallback (FunctionUtils::FunctionID id)
 Delete a key callback.
bool DeleteCharCallback (FunctionUtils::FunctionID id)
 Delete a char callback.
bool DeleteCharModsCallback (FunctionUtils::FunctionID id)
 Delete a char mods callback.
bool DeleteMouseButtonCallback (FunctionUtils::FunctionID id)
 Delete a mouse button callback.
bool DeleteCursorPosCallback (FunctionUtils::FunctionID id)
 Delete a cursor position callback.
bool DeleteCursorEnterCallback (FunctionUtils::FunctionID id)
 Delete a cursor enter callback.
bool DeleteScrollCallback (FunctionUtils::FunctionID id)
 Delete a scroll callback.
bool DeleteDropCallback (FunctionUtils::FunctionID id)
 Delete a drop callback.
bool IsKeyPressed (int key) noexcept

Private Types

using KeyCallbackContainer = FunctionUtils::FunctionContainer<void, Engine::Core &, int, int, int, int>
using CharCallbackContainer = FunctionUtils::FunctionContainer<void, Engine::Core &, unsigned int>
using CharModsCallbackContainer = FunctionUtils::FunctionContainer<void, Engine::Core &, unsigned int, int>
using MouseButtonCallbackContainer = FunctionUtils::FunctionContainer<void, Engine::Core &, int, int, int>
using CursorPosCallbackContainer = FunctionUtils::FunctionContainer<void, Engine::Core &, double, double>
using CursorEnterCallbackContainer = FunctionUtils::FunctionContainer<void, Engine::Core &, int>
using ScrollCallbackContainer = FunctionUtils::FunctionContainer<void, Engine::Core &, double, double>
using DropCallbackContainer = FunctionUtils::FunctionContainer<void, Engine::Core &, int, const char **>

Private Attributes

Engine::Core_core
std::shared_ptr< KeyCallbackContainer_keyCallbacks
std::shared_ptr< CharCallbackContainer_charCallbacks
std::shared_ptr< CharModsCallbackContainer_charModsCallbacks
std::shared_ptr< MouseButtonCallbackContainer_mouseButtonCallbacks
std::shared_ptr< CursorPosCallbackContainer_cursorPosCallbacks
std::shared_ptr< CursorEnterCallbackContainer_cursorEnterCallbacks
std::shared_ptr< ScrollCallbackContainer_scrollCallbacks
std::shared_ptr< DropCallbackContainer_dropCallbacks

Detailed Description

InputManager is a singleton class that wraps the GLFW callback functions.

Member Typedef Documentation

◆ CharCallbackContainer

◆ CharModsCallbackContainer

◆ CursorEnterCallbackContainer

◆ CursorPosCallbackContainer

◆ DropCallbackContainer

◆ KeyCallbackContainer

◆ MouseButtonCallbackContainer

◆ ScrollCallbackContainer

Constructor & Destructor Documentation

◆ InputManager()

Input::Resource::InputManager::InputManager ( Engine::Core & core)
inlineexplicit

◆ ~InputManager()

Input::Resource::InputManager::~InputManager ( )
default

Member Function Documentation

◆ CallCharCallbacks()

void Input::Resource::InputManager::CallCharCallbacks ( Engine::Core & core,
unsigned int codepoint )
inline

Call the char callbacks.

Parameters
coreThe core.
codepointThe codepoint. (Raw input, like 'a', 'b', 'c', etc.)
Returns
void

◆ CallCharModsCallbacks()

void Input::Resource::InputManager::CallCharModsCallbacks ( Engine::Core & core,
unsigned int codepoint,
int mods ) const
inline

Call the char mods callbacks.

Parameters
coreThe core.
codepointThe codepoint. (Raw input, like 'a', 'b', 'c', etc.)
modsThe mods. (Matches with GLFW_MOD_* constants)
Returns
void

◆ CallCursorEnterCallbacks()

void Input::Resource::InputManager::CallCursorEnterCallbacks ( Engine::Core & core,
int entered ) const
inline

Call the cursor enter callbacks.

Parameters
coreThe core.
enteredThe entered state. (1 if the cursor entered the window, 0 if it left)
Returns
void

◆ CallCursorPosCallbacks()

void Input::Resource::InputManager::CallCursorPosCallbacks ( Engine::Core & core,
double xpos,
double ypos ) const
inline

Call the cursor position callbacks.

Parameters
coreThe core.
xposThe x position.
yposThe y position.
Returns
void

◆ CallDropCallbacks()

void Input::Resource::InputManager::CallDropCallbacks ( Engine::Core & core,
int count,
const char ** paths ) const
inline

Call the drop callbacks.

Parameters
coreThe core.
countThe number of paths in the C array.
pathsThe paths. (C array of strings)
Returns
void

◆ CallKeyCallbacks()

void Input::Resource::InputManager::CallKeyCallbacks ( Engine::Core & core,
int key,
int scancode,
int action,
int mods )
inline

Call the key callbacks.

Parameters
coreThe core.
keyThe key. (Raw input, like 'a', 'b', 'c', etc.)
scancodeThe scancode. (Matches with GLFW_KEY_* constants)
actionThe action. (One of GLFW_PRESS, GLFW_RELEASE, GLFW_REPEAT)
modsThe mods. (Matches with GLFW_MOD_* constants)
Returns
void

◆ CallMouseButtonCallbacks()

void Input::Resource::InputManager::CallMouseButtonCallbacks ( Engine::Core & core,
int button,
int action,
int mods ) const
inline

Call the mouse button callbacks.

Parameters
coreThe core.
buttonThe button. (Matches with GLFW_MOUSE_BUTTON_* constants)
actionThe action. (One of GLFW_PRESS, GLFW_RELEASE)
modsThe mods. (Matches with GLFW_MOD_* constants)
Returns
void

◆ CallScrollCallbacks()

void Input::Resource::InputManager::CallScrollCallbacks ( Engine::Core & core,
double xoffset,
double yoffset ) const
inline

Call the scroll callbacks.

Parameters
coreThe core.
xoffsetThe x offset.
yoffsetThe y offset.
Returns
void

◆ DeleteCharCallback()

bool Input::Resource::InputManager::DeleteCharCallback ( FunctionUtils::FunctionID id)
inline

Delete a char callback.

Parameters
idThe ID of the callback to delete.
Returns
True if the callback was deleted, false otherwise.

◆ DeleteCharModsCallback()

bool Input::Resource::InputManager::DeleteCharModsCallback ( FunctionUtils::FunctionID id)
inline

Delete a char mods callback.

Parameters
idThe ID of the callback to delete.
Returns
True if the callback was deleted, false otherwise.

◆ DeleteCursorEnterCallback()

bool Input::Resource::InputManager::DeleteCursorEnterCallback ( FunctionUtils::FunctionID id)
inline

Delete a cursor enter callback.

Parameters
idThe ID of the callback to delete.
Returns
True if the callback was deleted, false otherwise.

◆ DeleteCursorPosCallback()

bool Input::Resource::InputManager::DeleteCursorPosCallback ( FunctionUtils::FunctionID id)
inline

Delete a cursor position callback.

Parameters
idThe ID of the callback to delete.
Returns
True if the callback was deleted, false otherwise.

◆ DeleteDropCallback()

bool Input::Resource::InputManager::DeleteDropCallback ( FunctionUtils::FunctionID id)
inline

Delete a drop callback.

Parameters
idThe ID of the callback to delete.
Returns
True if the callback was deleted, false otherwise.

◆ DeleteKeyCallback()

bool Input::Resource::InputManager::DeleteKeyCallback ( FunctionUtils::FunctionID id)
inline

Delete a key callback.

Parameters
idThe ID of the callback to delete.
Returns
True if the callback was deleted, false otherwise.

◆ DeleteMouseButtonCallback()

bool Input::Resource::InputManager::DeleteMouseButtonCallback ( FunctionUtils::FunctionID id)
inline

Delete a mouse button callback.

Parameters
idThe ID of the callback to delete.
Returns
True if the callback was deleted, false otherwise.

◆ DeleteScrollCallback()

bool Input::Resource::InputManager::DeleteScrollCallback ( FunctionUtils::FunctionID id)
inline

Delete a scroll callback.

Parameters
idThe ID of the callback to delete.
Returns
True if the callback was deleted, false otherwise.

◆ IsKeyPressed()

bool Input::Resource::InputManager::IsKeyPressed ( int key)
inlinenoexcept

◆ RegisterCharCallback()

template<typename TCallable>
FunctionUtils::FunctionID Input::Resource::InputManager::RegisterCharCallback ( TCallable callback)
inline

Register a char callback.

Parameters
callbackThe callback to register.
Note
The callback will be called when a character is typed.

◆ RegisterCharModsCallback()

template<typename TCallable>
FunctionUtils::FunctionID Input::Resource::InputManager::RegisterCharModsCallback ( TCallable callback)
inline

Register a char mods callback.

Parameters
callbackThe callback to register.
Note
The callback will be called when a character is typed with modifiers.

◆ RegisterCursorEnterCallback()

template<typename TCallable>
FunctionUtils::FunctionID Input::Resource::InputManager::RegisterCursorEnterCallback ( TCallable callback)
inline

Register a cursor enter callback.

Parameters
callbackThe callback to register.
Note
The callback will be called when the cursor enters or leaves the window.

◆ RegisterCursorPosCallback()

template<typename TCallable>
FunctionUtils::FunctionID Input::Resource::InputManager::RegisterCursorPosCallback ( TCallable callback)
inline

Register a cursor position callback.

Parameters
callbackThe callback to register.
Note
The callback will be called when the cursor position changes.

◆ RegisterDropCallback()

template<typename TCallable>
FunctionUtils::FunctionID Input::Resource::InputManager::RegisterDropCallback ( TCallable callback)
inline

Register a drop callback.

Parameters
callbackThe callback to register.
Note
The callback will be called when a file is dropped on the window.

◆ RegisterKeyCallback()

template<typename TCallable>
FunctionUtils::FunctionID Input::Resource::InputManager::RegisterKeyCallback ( TCallable callback)
inline

Register a key callback.

Parameters
callbackThe callback to register.
Note
The callback will be called when a key is pressed or released.

◆ RegisterMouseButtonCallback()

template<typename TCallable>
FunctionUtils::FunctionID Input::Resource::InputManager::RegisterMouseButtonCallback ( TCallable callback)
inline

Register a mouse button callback.

Parameters
callbackThe callback to register.
Note
The callback will be called when a mouse button is pressed or released.

◆ RegisterScrollCallback()

template<typename TCallable>
FunctionUtils::FunctionID Input::Resource::InputManager::RegisterScrollCallback ( TCallable callback)
inline

Register a scroll callback.

Parameters
callbackThe callback to register.
Note
The callback will be called when the mouse wheel is scrolled.

Member Data Documentation

◆ _charCallbacks

std::shared_ptr<CharCallbackContainer> Input::Resource::InputManager::_charCallbacks
private

◆ _charModsCallbacks

std::shared_ptr<CharModsCallbackContainer> Input::Resource::InputManager::_charModsCallbacks
private

◆ _core

Engine::Core& Input::Resource::InputManager::_core
private

◆ _cursorEnterCallbacks

std::shared_ptr<CursorEnterCallbackContainer> Input::Resource::InputManager::_cursorEnterCallbacks
private

◆ _cursorPosCallbacks

std::shared_ptr<CursorPosCallbackContainer> Input::Resource::InputManager::_cursorPosCallbacks
private

◆ _dropCallbacks

std::shared_ptr<DropCallbackContainer> Input::Resource::InputManager::_dropCallbacks
private

◆ _keyCallbacks

std::shared_ptr<KeyCallbackContainer> Input::Resource::InputManager::_keyCallbacks
private

◆ _mouseButtonCallbacks

std::shared_ptr<MouseButtonCallbackContainer> Input::Resource::InputManager::_mouseButtonCallbacks
private

◆ _scrollCallbacks

std::shared_ptr<ScrollCallbackContainer> Input::Resource::InputManager::_scrollCallbacks
private

The documentation for this class was generated from the following file: