GLFWInputAdapter.ixx File
GLFW-based InputAdapter implementation. More...
Included Headers
#include <GLFW/glfw3.h>
#include <array>
#include <memory>
#include <format>
#include <stdexcept>
#include <utility>
#include <cmath>
#include <helios.ext.glfw.window.GLFWWindow>
#include <helios.ext.glfw.input.GLFWGamepadLookup>
#include <helios.input.gamepad.GamepadSettings>
#include <helios.input.types.Key>
#include <helios.ext.glfw.input.GLFWKeyLookup>
#include <helios.input.types.Gamepad>
#include <helios.input.InputAdapter>
#include <helios.input.gamepad.DeadzoneStrategy>
#include <helios.window.Window>
#include <helios.input.gamepad.GamepadState>
Namespaces Index
| namespace | helios |
| namespace | ext |
|
Platform-specific extensions and backend implementations. More... | |
| namespace | glfw |
|
GLFW-specific implementations. More... | |
| namespace | input |
|
GLFW input handling. More... | |
Classes Index
| class | GLFWInputAdapter |
|
InputAdapter implementation for a GLFWWindow. More... | |
Description
GLFW-based InputAdapter implementation.
File Listing
The file content with the documentation metadata removed is:
29export namespace helios::ext::glfw::input {
46 class GLFWInputAdapter final : public helios::input::InputAdapter {
57 std::array<helios::input::gamepad::GamepadState, std::to_underlying(helios::input::types::Gamepad::size_)> gamepadStates_= {};
67 GLFWInputAdapter(std::unique_ptr<helios::input::gamepad::DeadzoneStrategy> deadzoneStrategy) :
68 helios::input::InputAdapter(std::move(deadzoneStrategy))
77 [[nodiscard]] bool isKeyPressed(helios::input::types::Key key,
78 const helios::window::Window& win) const noexcept override {
79 auto const* win_ptr = dynamic_cast<helios::ext::glfw::window::GLFWWindow const*>(&win);
82 logger_.warn("GLFWInput requires GLFWWindow");
86 return isKeyPressed(key, *win_ptr);
96 [[nodiscard]] bool isKeyReleased(helios::input::types::Key key,
97 const helios::window::Window& win) const noexcept override {
98 auto const* win_ptr = dynamic_cast<helios::ext::glfw::window::GLFWWindow const*>(&win);
101 logger_.warn("GLFWInput requires GLFWWindow");
105 return isKeyReleased(key, *win_ptr);
116 [[nodiscard]] bool isKeyPressed(helios::input::types::Key key,
117 const helios::ext::glfw::window::GLFWWindow& win) const noexcept {
132 [[nodiscard]] bool isKeyReleased(helios::input::types::Key key,
133 const helios::ext::glfw::window::GLFWWindow& win) const noexcept {
143 [[nodiscard]] const helios::input::gamepad::GamepadState& gamepadState(
144 helios::input::types::Gamepad gamepadId) const noexcept override {
146 helios::ext::glfw::input::GLFWGamepadLookup::toArrayIndex(gamepadId)
153 void updateGamepadState(unsigned int gamepadMask) noexcept override {
161 const auto gamepadId = static_cast<helios::input::types::Gamepad>(static_cast<unsigned int>(std::pow(2, index)));
163 int glfwGamepadId = helios::ext::glfw::input::GLFWGamepadLookup::from(gamepadId);
165 auto& gamepadSettings = InputAdapter::gamepadSettings(gamepadId);
176 float leftX = (gamepadSettings.invertLeftX() ? -1.0f : 1.0f) * axes[GLFW_GAMEPAD_AXIS_LEFT_X];
178 float leftY = (gamepadSettings.invertLeftY() ? -1.0f : 1.0f) * -axes[GLFW_GAMEPAD_AXIS_LEFT_Y];
179 deadzoneStrategy_->normalize(gamepadSettings.leftStickDeadzone(), leftX, leftY);
182 float rightX = (gamepadSettings.invertRightX() ? -1.0f : 1.0f) * axes[GLFW_GAMEPAD_AXIS_RIGHT_X];
184 float rightY = (gamepadSettings.invertRightY() ? -1.0f : 1.0f) * -axes[GLFW_GAMEPAD_AXIS_RIGHT_Y];
185 deadzoneStrategy_->normalize(gamepadSettings.rightStickDeadzone(), rightX, rightY);
238 [[nodiscard]] bool isConnected(
239 helios::input::types::Gamepad gamepadId) const noexcept override {
240 const int glfwGamepadId = helios::ext::glfw::input::GLFWGamepadLookup::from(gamepadId);
Generated via doxygen2docusaurus 2.0.0 by Doxygen 1.15.0.