Foray Library
rapid prototyping framework for crossplatform development of vulkan hardware ray tracing applications
Loading...
Searching...
No Matches
foray_event.hpp
Go to the documentation of this file.
1#pragma once
2#include "../foray_basics.hpp"
3#include "../foray_vulkan.hpp"
4#include "foray_helpers.hpp"
5#include "foray_input.hpp"
7#include <memory>
8#include <sdl2/SDL.h>
9
10namespace foray::osi {
12 class Event : public Polymorphic
13 {
14 public:
41
42 inline Event() = default;
43 inline Event(Window* const source, const uint32_t timestamp, const EType type) : Source(source), Timestamp(timestamp), Type(type), CustomType(0) {}
44 inline Event(Window* const source, const uint32_t timestamp, const int8_t customtype) : Source(source), Timestamp(timestamp), Type(EType::Custom), CustomType(customtype) {}
45 inline virtual ~Event() {}
46
48 Window* Source = nullptr;
50 uint32_t Timestamp = 0;
54 int16_t CustomType = 0;
56 SDL_Event RawSdlEventData = {};
57 };
58
60 class EventInput : public Event
61 {
62 public:
63 inline EventInput() = default;
64 inline EventInput(Window* const source, const uint32_t timestamp, const EType type, InputDevice* const device) : Event(source, timestamp, type), SourceDevice(device) {}
65
68 };
69
72 {
73 public:
74 inline EventInputDeviceAvailability(const uint32_t timestamp, InputDevice* const device, const bool added)
75 : EventInput(nullptr, timestamp, Event::EType::InputDeviceAvailability, device), Added(added)
76 {
77 }
78
80 bool Added = false;
81 };
82
85 {
86 public:
87 inline EventInputAnalogue() = default;
88 inline EventInputAnalogue(Window* const source, const uint32_t timestamp, InputDevice* device, const InputAnalogue* axis, int16_t current)
89 : EventInput(source, timestamp, EType::InputAnalogue, device), SourceInput(axis), State(current)
90 {
91 }
92
94 const InputAnalogue* SourceInput = nullptr;
96 int16_t State = 0;
97 };
98
101 {
102 public:
103 inline EventInputBinary() = default;
104 inline EventInputBinary(Window* const source, const uint32_t timestamp, InputDevice* device, const InputBinary* button, bool pressed)
105 : EventInput(source, timestamp, EType::InputBinary, device), SourceInput(button), State(pressed)
106 {
107 }
108
110 const InputBinary* SourceInput = nullptr;
112 bool State = 0;
113 };
114
117 {
118 public:
119 inline EventInputDirectional() = default;
120 inline EventInputDirectional(Window* const source, const uint32_t timestamp, InputDevice* device, const InputDirectional* inputsource, int32_t offsetX, int32_t offsetY)
121 : EventInput(source, timestamp, EType::InputBinary, device), SourceInput(inputsource), OffsetX(offsetX), OffsetY(offsetY)
122 {
123 }
124
128 int32_t OffsetX = 0;
130 int32_t OffsetY = 0;
131 };
132
135 {
136 public:
137 inline EventInputMouseMoved() = default;
138 inline EventInputMouseMoved(Window* const source, const uint32_t timestamp, InputDevice* const device, fp32_t currentx, fp32_t currenty, fp32_t relativeX, fp32_t relativeY)
139 : EventInput(source, timestamp, EType::InputMouseMoved, device), CurrentX(currentx), CurrentY(currenty), RelativeX(relativeX), RelativeY(relativeY)
140 {
141 }
142
151 };
152
155 {
156 public:
157 inline EventWindowResized() = default;
158 inline EventWindowResized(Window* const source, const uint32_t timestamp, VkExtent2D current) : Event(source, timestamp, EType::WindowResized), Current(current) {}
159
161 VkExtent2D Current = {};
162 };
163
166 {
167 public:
168 inline EventWindowFocusChanged() = default;
169 inline EventWindowFocusChanged(Window* source, const uint32_t timestamp, bool mouseFocus, bool inputFocus)
170 : Event(source, timestamp, EType::WindowFocusChanged), MouseFocus(mouseFocus), InputFocus(inputFocus)
171 {
172 }
173
175 bool MouseFocus = false;
177 bool InputFocus = false;
178 };
179
182 {
183 public:
184 inline EventWindowCloseRequested() = default;
185 inline EventWindowCloseRequested(Window* const source, const uint32_t timestamp) : Event(source, timestamp, EType::WindowCloseRequested) {}
186 };
187} // namespace foray
Simple type for forcing a type to be polymorphic.
Definition foray_basics.hpp:29
Event type for an analogue input.
Definition foray_event.hpp:85
const InputAnalogue * SourceInput
axis that was moved
Definition foray_event.hpp:94
int16_t State
Current reading from the axis.
Definition foray_event.hpp:96
EventInputAnalogue(Window *const source, const uint32_t timestamp, InputDevice *device, const InputAnalogue *axis, int16_t current)
Definition foray_event.hpp:88
Event type describing a binary input event.
Definition foray_event.hpp:101
const InputBinary * SourceInput
The button that was pressed or released.
Definition foray_event.hpp:110
EventInputBinary(Window *const source, const uint32_t timestamp, InputDevice *device, const InputBinary *button, bool pressed)
Definition foray_event.hpp:104
bool State
If true, the button was pressed - released otherwise.
Definition foray_event.hpp:112
Event type describing input devices being added or removed.
Definition foray_event.hpp:72
bool Added
True if device was added, false if device was removed.
Definition foray_event.hpp:80
EventInputDeviceAvailability(const uint32_t timestamp, InputDevice *const device, const bool added)
Definition foray_event.hpp:74
Event type describing a directional input event.
Definition foray_event.hpp:117
int32_t OffsetY
The offset in Y direction.
Definition foray_event.hpp:130
EventInputDirectional(Window *const source, const uint32_t timestamp, InputDevice *device, const InputDirectional *inputsource, int32_t offsetX, int32_t offsetY)
Definition foray_event.hpp:120
const InputDirectional * SourceInput
The directional input that was triggered.
Definition foray_event.hpp:126
int32_t OffsetX
The offset in X direction.
Definition foray_event.hpp:128
Event type describing a mouse cursor movement event.
Definition foray_event.hpp:135
fp32_t CurrentX
Current mouse x position.
Definition foray_event.hpp:144
EventInputMouseMoved(Window *const source, const uint32_t timestamp, InputDevice *const device, fp32_t currentx, fp32_t currenty, fp32_t relativeX, fp32_t relativeY)
Definition foray_event.hpp:138
fp32_t RelativeX
Mouse x relative movement since last event.
Definition foray_event.hpp:148
fp32_t RelativeY
Mouse y relative movement since last event.
Definition foray_event.hpp:150
fp32_t CurrentY
Current mouse y position.
Definition foray_event.hpp:146
Base class for events originating from input devices.
Definition foray_event.hpp:61
InputDevice * SourceDevice
Input Device that the input was read from.
Definition foray_event.hpp:67
EventInput(Window *const source, const uint32_t timestamp, const EType type, InputDevice *const device)
Definition foray_event.hpp:64
Event type fired when the windows closure is requested (by OS or user through OS)
Definition foray_event.hpp:182
EventWindowCloseRequested(Window *const source, const uint32_t timestamp)
Definition foray_event.hpp:185
Event type fired when a window gains or loses focus.
Definition foray_event.hpp:166
bool MouseFocus
True, if window has mouse focus (The window itself may not be focused, but mouse hovering above)
Definition foray_event.hpp:175
EventWindowFocusChanged(Window *source, const uint32_t timestamp, bool mouseFocus, bool inputFocus)
Definition foray_event.hpp:169
bool InputFocus
True, if window has full focus.
Definition foray_event.hpp:177
Event type fired when a window is resized.
Definition foray_event.hpp:155
VkExtent2D Current
Current window extent.
Definition foray_event.hpp:161
EventWindowResized(Window *const source, const uint32_t timestamp, VkExtent2D current)
Definition foray_event.hpp:158
Base class for operating system events.
Definition foray_event.hpp:13
Event(Window *const source, const uint32_t timestamp, const int8_t customtype)
Definition foray_event.hpp:44
Event(Window *const source, const uint32_t timestamp, const EType type)
Definition foray_event.hpp:43
SDL_Event RawSdlEventData
Raw SDL_Event data this event was derived from.
Definition foray_event.hpp:56
int16_t CustomType
For custom event type overloads, this value may be set.
Definition foray_event.hpp:54
uint32_t Timestamp
Timestamp when the action was recorded.
Definition foray_event.hpp:50
EType Type
Event type.
Definition foray_event.hpp:52
Window * Source
Source window that recorded the event, if applicable.
Definition foray_event.hpp:48
virtual ~Event()
Definition foray_event.hpp:45
EType
Event type enum, allows handling events in switch structures.
Definition foray_event.hpp:17
@ InputDeviceAvailability
An input device was connected or removed.
@ InputDirectional
Directional stateless inputs, ex. scroll wheel, joystick hatswitches, etc.
@ WindowCloseRequested
User requested window closed.
@ WindowFocusChanged
WindowPtr lost/gained focus.
@ WindowItemDropped
File/Folder was dragged on top of the window.
@ InputMouseMoved
Mouse position input type.
@ InputAnalogue
Analogue inputs, ex. controller stick axis.
@ WindowResized
WindowPtr resized.
@ InputBinary
Binary inputs, ex. buttons, keys.
Represents a single input with a state represented by a signed 16bit integer.
Definition foray_input.hpp:28
Represents a single input with a state represented by a boolean value.
Definition foray_input.hpp:45
Wraps a generic input device (mouse, keyboard, joystick, controller ...) in a hardware agnostic way.
Definition foray_inputdevice.hpp:13
Represents a stateless directional input.
Definition foray_input.hpp:62
Window class. Provides access to common properties of operating system level windows.
Definition foray_window.hpp:15
Definition foray_env.hpp:7
float fp32_t
stdint.h style 32 bit floating point type alias (float)
Definition foray_basics.hpp:13