|
|
- /*
- * Copyright (C) 2023 Christopher J. Howard
- *
- * This file is part of Antkeeper source code.
- *
- * Antkeeper source code is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * Antkeeper source code is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with Antkeeper source code. If not, see <http://www.gnu.org/licenses/>.
- */
-
- #ifndef ANTKEEPER_INPUT_EVENT_HPP
- #define ANTKEEPER_INPUT_EVENT_HPP
-
- #include "input/gamepad-axis.hpp"
- #include "input/gamepad-button.hpp"
- #include "input/mouse-motion-axis.hpp"
- #include "input/mouse-scroll-axis.hpp"
- #include "input/scancode.hpp"
- #include "input/mapping.hpp"
- #include "input/modifier-key.hpp"
- #include "math/vector.hpp"
- #include <cstdint>
- #include <memory>
-
- namespace input {
-
- class control;
- class device;
- class gamepad;
- class keyboard;
- class mouse;
-
- /**
- * Input events.
- */
- namespace event {
-
- /**
- * Event generated when a control has been activated.
- */
- struct control_activated
- {
- /// Control that was activated.
- control* control;
- };
-
- /**
- * Event generated while a control is active.
- */
- struct control_active
- {
- /// Active control.
- control* control;
-
- /// Control input value.
- float input_value;
- };
-
- /**
- * Event generated when a control has been deactivated.
- */
- struct control_deactivated
- {
- /// Control that was deactivated.
- control* control;
- };
-
- /**
- * Event generated when an input mapping has been generated.
- */
- struct input_mapped
- {
- /// Input mapping that was generated.
- std::shared_ptr<mapping> mapping;
- };
-
- /**
- * Event generated when an input device has been connected.
- */
- struct device_connected
- {
- /// Device that was connected.
- device* device;
- };
-
- /**
- * Event generated when an input device has been disconnected.
- */
- struct device_disconnected
- {
- /// Device that was disconnected.
- device* device;
- };
-
- /**
- * Event generated when a gamepad button has been pressed.
- */
- struct gamepad_button_pressed
- {
- /// Gamepad that generated the event.
- gamepad* gamepad;
-
- /// Gamepad button being pressed.
- gamepad_button button;
- };
-
- /**
- * Event generated when a gamepad button has been released.
- */
- struct gamepad_button_released
- {
- /// Gamepad that generated the event.
- gamepad* gamepad;
-
- /// Gamepad button being released.
- gamepad_button button;
- };
-
- /**
- * Event generated when a gamepad axis has been moved.
- */
- struct gamepad_axis_moved
- {
- /// Gamepad that generated the event.
- gamepad* gamepad;
-
- /// Gamepad axis being moved.
- gamepad_axis axis;
-
- /// Position of the gamepad axis, on `[-1, 1]`.
- float position;
- };
-
- /**
- * Event generated when a keyboard key has been pressed.
- */
- struct key_pressed
- {
- /// Keyboard that generated the event.
- keyboard* keyboard;
-
- /// Scancode of the key being pressed.
- scancode scancode;
-
- /// `true` if the key press was generated by a key repeat, `false` otherwise.
- bool repeat;
-
- /// Bit mask containing the active modifier keys.
- std::uint16_t modifiers;
- };
-
- /**
- * Event generated when a keyboard key has been released.
- */
- struct key_released
- {
- /// Keyboard that generated the event.
- keyboard* keyboard;
-
- /// Scancode of the key being released.
- scancode scancode;
-
- /// `true` if the key release was generated by a key repeat, `false` otherwise.
- bool repeat;
-
- /// Bit mask containing the active modifier keys.
- std::uint16_t modifiers;
- };
-
- /**
- * Event generated when a mouse has been moved.
- */
- struct mouse_moved
- {
- /// Mouse that generated the event.
- mouse* mouse;
-
- /// Mouse position, in pixels, relative to the window.
- math::vector<std::int32_t, 2> position;
-
- /// Relative movement of the mouse, in pixels.
- math::vector<std::int32_t, 2> difference;
- };
-
- /**
- * Event generated when a mouse button has been pressed.
- */
- struct mouse_button_pressed
- {
- /// Mouse that generated the event.
- mouse* mouse;
-
- /// Mouse position, in pixels, relative to the window, when the button was pressed.
- math::vector<std::int32_t, 2> position;
-
- /// Mouse button being pressed.
- mouse_button button;
- };
-
- /**
- * Event generated when a mouse button has been released.
- */
- struct mouse_button_released
- {
- /// Mouse that generated the event.
- mouse* mouse;
-
- /// Mouse position, in pixels, relative to the window, when the button was released.
- math::vector<std::int32_t, 2> position;
-
- /// Mouse button being released.
- mouse_button button;
- };
-
- /**
- * Event generated when a mouse has been scrolled.
- */
- struct mouse_scrolled
- {
- /// Mouse that generated the event.
- mouse* mouse;
-
- /// Mouse position, in pixels, relative to the window, when the mouse was scrolled.
- math::vector<std::int32_t, 2> position;
-
- /// Scroll velocity.
- math::vector<float, 2> velocity;
- };
-
- /**
- * Event generated when a window has been requested to close.
- */
- struct window_closed
- {
- /// Pointer to the window that has been requested to close.
- void* window;
- };
-
- /**
- * Event generated when a window has gained or lost focus.
- */
- struct window_focus_changed
- {
- /// Pointer to the window that has gained or lost focus.
- void* window;
-
- /// `true` if the window is in focus, `false` otherwise.
- bool in_focus;
- };
-
- /**
- * Event generated when a window has been moved.
- */
- struct window_moved
- {
- /// Pointer to the window that has been moved.
- void* window;
-
- /// Position of the window, in pixels.
- math::vector<std::int32_t, 2> position;
-
- /// `true` if the window is maximized, `false` otherwise.
- bool maximized;
-
- /// `true` if the window is fullscreen, `false` otherwise.
- bool fullscreen;
- };
-
- /**
- * Event generated when a window has been maximized.
- */
- struct window_maximized
- {
- /// Pointer to the window that has been maximized.
- void* window;
- };
-
- /**
- * Event generated when a window has been minimized.
- */
- struct window_minimized
- {
- /// Pointer to the window that has been minimized.
- void* window;
- };
-
- /**
- * Event generated when a window has been restored.
- */
- struct window_restored
- {
- /// Pointer to the window that has been restored.
- void* window;
- };
-
- /**
- * Event generated when a window has been resized.
- */
- struct window_resized
- {
- /// Pointer to the window that has been resized.
- void* window;
-
- /// Window size, in display units.
- math::vector<std::int32_t, 2> size;
-
- /// `true` if the window is maximized, `false` otherwise.
- bool maximized;
-
- /// `true` if the window is fullscreen, `false` otherwise.
- bool fullscreen;
-
- /// Window viewport size, in pixels.
- math::vector<std::int32_t, 2> viewport_size;
- };
-
- } // namespace event
- } // namespace input
-
- #endif // ANTKEEPER_INPUT_EVENT_HPP
|