Skip to content

InputManager

Class handling all GLUT interaction events (mouse and keyboard) and starting the label editor. More...

#include "Core/Input/InputManager.h"

Public Types

Name
enumKeyState { UP, JUST_UP, DOWN, JUST_DOWN}

Public Functions

Name
voidaddInputController(InputController * controller)
boolareModifiersActive(const Modifiers mods)
voidbeginFrame()<br>Updates mouse position and buttons.
voidbindGlobalAction(const char * action, EKeyState state, KeyCallback fn)
ModifierscreateModifiers(ModifiersList & list)<br>If you change order of modifiers, change it also in InputManager::areModifiersActive function.
voidendFrame()<br>Updates the stored statuses of the keys in the keyMap array (JUST_UP -> UP, JUST_DOWN -> DOWN).
glm::vec2getMouseDelta()
glm::vec2getMousePos()
voidinit()
boolisActionTriggered(const char * name, EKeyState state)
boolisAxisActive(const char * name)
boolisInputActive(const WPtr< InputController > & input)<br>Check if the specified input controller is active.
boolisKeyJustPressed(const Keys::Code code)
boolisKeyJustUp(const Keys::Code code)
boolisKeyPressed(const Keys::Code code)
boolisMouseClicked()
boolisMouseDown()
voidkeyDown(int keyPressed)<br>Helper function for handling pressed keys.
voidkeyUp(int keyReleased)<br>Helper function for handling released keys.
voidsetActiveInput(const WPtr< InputController > & input)<br>Set active input controller (for focused window).
voidsetInputAction(const char * action, Keys::Code code, ModifiersList mods =ModifiersList())
voidsetInputAxis(const char * action, float scale, Keys::Code code, ModifiersList mods =ModifiersList())
voidsetPressed(const Keys::Code code)<br>Sets an entry in the keyMap to justPressed (JUST_DOWN)
voidsetUnpressed(const Keys::Code code)
voidtriggerAction(const char * action, EKeyState state)

Public Attributes

Name
boolm_ignoreImGuiEvents
std::map< Keys::Code, KeyState >m_keyMap <br>States of all keys, modifiers, and mouse buttons - enum value KeyState.
floatm_mouseWheelOffset <br>Immediate mouse scroll change.
floatm_mouseX
floatm_mouseXDelta
floatm_mouseXDragDelta
floatm_mouseXPrev
floatm_mouseY <br>Current mouse cursor position in screen coordinates (0 is corner of the monitor)
floatm_mouseYDelta <br>Change of the cursor position across last two frames.
floatm_mouseYDragDelta <br>Same as mouse delta but only non-zero during some mouse press.
floatm_mouseYPrev <br>Previous frame's cursor position.

Detailed Description

cpp
class InputManager;
class InputManager;

Class handling all GLUT interaction events (mouse and keyboard) and starting the label editor.

This class stores state of all keys and mouse buttons in a map keyMap - used for controlling all interaction. It also updates the stored statuses of the keys from JUST pressed/released to pressed/release. The update() is called regularly from the end of main.cpp: logicUpdate()

Public Types Documentation

enum KeyState

EnumeratorValueDescription
UP
JUST_UP
DOWN
JUST_DOWN

Public Functions Documentation

function addInputController

cpp
static inline void addInputController(
    InputController * controller
)
static inline void addInputController(
    InputController * controller
)

function areModifiersActive

cpp
static bool areModifiersActive(
    const Modifiers mods
)
static bool areModifiersActive(
    const Modifiers mods
)

function beginFrame

cpp
static void beginFrame()
static void beginFrame()

Updates mouse position and buttons.

function bindGlobalAction

cpp
static void bindGlobalAction(
    const char * action,
    EKeyState state,
    KeyCallback fn
)
static void bindGlobalAction(
    const char * action,
    EKeyState state,
    KeyCallback fn
)

function createModifiers

cpp
static Modifiers createModifiers(
    ModifiersList & list
)
static Modifiers createModifiers(
    ModifiersList & list
)

If you change order of modifiers, change it also in InputManager::areModifiersActive function.

function endFrame

cpp
static void endFrame()
static void endFrame()

Updates the stored statuses of the keys in the keyMap array (JUST_UP -> UP, JUST_DOWN -> DOWN).

Processes events.

function getMouseDelta

cpp
static inline glm::vec2 getMouseDelta()
static inline glm::vec2 getMouseDelta()

function getMousePos

cpp
static inline glm::vec2 getMousePos()
static inline glm::vec2 getMousePos()

function init

cpp
static void init()
static void init()

function isActionTriggered

cpp
static bool isActionTriggered(
    const char * name,
    EKeyState state
)
static bool isActionTriggered(
    const char * name,
    EKeyState state
)

function isAxisActive

cpp
static bool isAxisActive(
    const char * name
)
static bool isAxisActive(
    const char * name
)

function isInputActive

cpp
static bool isInputActive(
    const WPtr< InputController > & input
)
static bool isInputActive(
    const WPtr< InputController > & input
)

Check if the specified input controller is active.

Window input controller will be active when the window is focused.

function isKeyJustPressed

cpp
static inline bool isKeyJustPressed(
    const Keys::Code code
)
static inline bool isKeyJustPressed(
    const Keys::Code code
)

function isKeyJustUp

cpp
static inline bool isKeyJustUp(
    const Keys::Code code
)
static inline bool isKeyJustUp(
    const Keys::Code code
)

function isKeyPressed

cpp
static inline bool isKeyPressed(
    const Keys::Code code
)
static inline bool isKeyPressed(
    const Keys::Code code
)

function isMouseClicked

cpp
static bool isMouseClicked()
static bool isMouseClicked()

Return: Whether any of the mouse buttons was clicked

function isMouseDown

cpp
static bool isMouseDown()
static bool isMouseDown()

Return: Whether any of the mouse buttons is pressed

function keyDown

cpp
static void keyDown(
    int keyPressed
)
static void keyDown(
    int keyPressed
)

Helper function for handling pressed keys.

Parameters:

  • keyPressed The key pressed.

function keyUp

cpp
static void keyUp(
    int keyReleased
)
static void keyUp(
    int keyReleased
)

Helper function for handling released keys.

Parameters:

  • keyReleased The key released.

function setActiveInput

cpp
static void setActiveInput(
    const WPtr< InputController > & input
)
static void setActiveInput(
    const WPtr< InputController > & input
)

Set active input controller (for focused window).

function setInputAction

cpp
static void setInputAction(
    const char * action,
    Keys::Code code,
    ModifiersList mods =ModifiersList()
)
static void setInputAction(
    const char * action,
    Keys::Code code,
    ModifiersList mods =ModifiersList()
)

function setInputAxis

cpp
static void setInputAxis(
    const char * action,
    float scale,
    Keys::Code code,
    ModifiersList mods =ModifiersList()
)
static void setInputAxis(
    const char * action,
    float scale,
    Keys::Code code,
    ModifiersList mods =ModifiersList()
)

function setPressed

cpp
static inline void setPressed(
    const Keys::Code code
)
static inline void setPressed(
    const Keys::Code code
)

Sets an entry in the keyMap to justPressed (JUST_DOWN)

Parameters:

  • code The enum code of the key.

function setUnpressed

cpp
static inline void setUnpressed(
    const Keys::Code code
)
static inline void setUnpressed(
    const Keys::Code code
)

function triggerAction

cpp
static void triggerAction(
    const char * action,
    EKeyState state
)
static void triggerAction(
    const char * action,
    EKeyState state
)

Public Attributes Documentation

variable m_ignoreImGuiEvents

cpp
static bool m_ignoreImGuiEvents = false;
static bool m_ignoreImGuiEvents = false;

variable m_keyMap

cpp
static std::map< Keys::Code, KeyState > m_keyMap;
static std::map< Keys::Code, KeyState > m_keyMap;

States of all keys, modifiers, and mouse buttons - enum value KeyState.

Todo: passed to all handlers, but probably not used

changed in update()

variable m_mouseWheelOffset

cpp
static float m_mouseWheelOffset = 0;
static float m_mouseWheelOffset = 0;

Immediate mouse scroll change.

variable m_mouseX

cpp
static float m_mouseX = 0;
static float m_mouseX = 0;

variable m_mouseXDelta

cpp
static float m_mouseXDelta = 0;
static float m_mouseXDelta = 0;

variable m_mouseXDragDelta

cpp
static float m_mouseXDragDelta = 0;
static float m_mouseXDragDelta = 0;

variable m_mouseXPrev

cpp
static float m_mouseXPrev = 0;
static float m_mouseXPrev = 0;

variable m_mouseY

cpp
static float m_mouseY = 0;
static float m_mouseY = 0;

Current mouse cursor position in screen coordinates (0 is corner of the monitor)

variable m_mouseYDelta

cpp
static float m_mouseYDelta = 0;
static float m_mouseYDelta = 0;

Change of the cursor position across last two frames.

variable m_mouseYDragDelta

cpp
static float m_mouseYDragDelta = 0;
static float m_mouseYDragDelta = 0;

Same as mouse delta but only non-zero during some mouse press.

variable m_mouseYPrev

cpp
static float m_mouseYPrev = 0;
static float m_mouseYPrev = 0;

Previous frame's cursor position.


Updated on 2024-11-06 at 20:16:53 +0000