File tree Expand file tree Collapse file tree 10 files changed +67
-28
lines changed Expand file tree Collapse file tree 10 files changed +67
-28
lines changed Original file line number Diff line number Diff line change 5
5
6
6
#include < cstdint>
7
7
8
- #include < array>
9
8
#include < string_view>
10
9
#include < variant>
11
10
@@ -174,24 +173,24 @@ namespace gf {
174
173
struct GF_CORE_API MouseMovedEvent {
175
174
WindowId window_id;
176
175
MouseId mouse_id;
177
- Vec2I position;
178
- Vec2I motion;
176
+ Vec2F position;
177
+ Vec2F motion;
179
178
};
180
179
181
180
struct GF_CORE_API MouseButtonPressedEvent {
182
181
WindowId window_id;
183
182
MouseId mouse_id;
184
183
MouseButton button;
185
- Vec2F position;
186
184
uint8_t clicks;
185
+ Vec2F position;
187
186
};
188
187
189
188
struct GF_CORE_API MouseButtonReleasedEvent {
190
189
WindowId window_id;
191
190
MouseId mouse_id;
192
191
MouseButton button;
193
- Vec2F position;
194
192
uint8_t clicks;
193
+ Vec2F position;
195
194
};
196
195
197
196
struct GF_CORE_API MouseWheelScrolledEvent {
Original file line number Diff line number Diff line change 5
5
6
6
#include < cstdint>
7
7
8
+ #include < limits>
9
+ #include < type_traits>
10
+
8
11
namespace gf {
9
12
10
- enum class MouseButton : uint32_t { // NOLINT(performance-enum-size)
13
+ enum class MouseButton : uint8_t {
11
14
None,
12
15
Left,
13
16
Middle,
@@ -18,13 +21,13 @@ namespace gf {
18
21
Touch2,
19
22
};
20
23
21
- constexpr MouseButton AnyMouseButton = static_cast < MouseButton>( 0xFFFFFFFF ) ;
24
+ constexpr MouseButton AnyMouseButton = MouseButton{ std::numeric_limits<std:: underlying_type_t < MouseButton>>:: max () } ;
22
25
23
26
enum class MouseId : uint32_t ;
24
27
25
- constexpr MouseId TouchMouseId = static_cast < MouseId>( 0xFFFFFFFF ) ;
28
+ constexpr MouseId TouchMouseId = MouseId{ std::numeric_limits<std:: underlying_type_t < MouseId>>:: max () } ;
26
29
27
- enum class MouseWheelDirection : uint32_t { // NOLINT(performance-enum-size)
30
+ enum class MouseWheelDirection { // NOLINT(performance-enum-size)
28
31
Normal,
29
32
Flipped,
30
33
};
Original file line number Diff line number Diff line change @@ -14,6 +14,13 @@ namespace gf {
14
14
15
15
constexpr TouchId MouseTouchId = TouchId{ std::numeric_limits<std::underlying_type_t <TouchId>>::max () };
16
16
17
+ enum class TouchDeviceType { // NOLINT(performance-enum-size)
18
+ Invalid = -1 ,
19
+ Direct,
20
+ IndirectAbsolute,
21
+ IndirectRelative,
22
+ };
23
+
17
24
enum class FingerId : uint64_t ;
18
25
19
26
} // namespace gf
Original file line number Diff line number Diff line change @@ -44,6 +44,8 @@ namespace gf {
44
44
SDL_Cursor* m_cursor = nullptr ;
45
45
};
46
46
47
+ void capture_mouse (bool captured = true );
48
+
47
49
}
48
50
49
51
#endif // GF_CURSOR_H
Original file line number Diff line number Diff line change @@ -47,13 +47,12 @@ namespace gf {
47
47
void close ();
48
48
49
49
private:
50
- friend class Gamepad ;
50
+ friend struct Gamepad ;
51
51
GamepadDevice (SDL_Gamepad* gamepad);
52
52
SDL_Gamepad* m_gamepad = nullptr ;
53
53
};
54
54
55
- class GF_GRAPHICS_API Gamepad {
56
- public:
55
+ struct GF_GRAPHICS_API Gamepad {
57
56
static GamepadDevice open (GamepadId id);
58
57
static GamepadDevice from_id (GamepadId id);
59
58
Original file line number Diff line number Diff line change 3
3
#ifndef GF_KEYBOARD_H
4
4
#define GF_KEYBOARD_H
5
5
6
+ #include < tuple>
7
+
8
+ #include < gf2/core/Flags.h>
6
9
#include < gf2/core/Keycode.h>
7
10
#include < gf2/core/Modifier.h>
8
11
#include < gf2/core/Scancode.h>
@@ -18,8 +21,8 @@ namespace gf {
18
21
static const char * keycode_name (Keycode keycode);
19
22
static Keycode keycode_from_name (const char * name);
20
23
21
- static Keycode localize (Scancode scancode);
22
- static Scancode unlocalize (Keycode keycode);
24
+ static Keycode localize (Scancode scancode, Flags<Modifier> modifiers );
25
+ static std::tuple< Scancode, Flags<Modifier>> unlocalize (Keycode keycode);
23
26
};
24
27
25
28
} // namespace gf
Original file line number Diff line number Diff line change @@ -79,7 +79,15 @@ namespace gf {
79
79
return ;
80
80
}
81
81
82
+ // TODO: [SDL3] check return
82
83
SDL_SetCursor (cursor->m_cursor );
83
84
}
84
85
86
+ void capture_mouse (bool captured)
87
+ {
88
+ if (!SDL_CaptureMouse (captured)) {
89
+ Log::error (" Failed to capture the mouse: {}" , SDL_GetError ());
90
+ }
91
+ }
92
+
85
93
}
Original file line number Diff line number Diff line change 3
3
4
4
#include < gf2/graphics/Keyboard.h>
5
5
6
+ #include < type_traits>
7
+
6
8
#include < SDL3/SDL.h>
9
+ #include " gf2/core/Modifier.h"
7
10
8
11
namespace gf {
9
12
10
13
namespace {
11
14
15
+ static_assert (std::is_same_v<std::underlying_type_t <Modifier>, SDL_Keymod>);
16
+
12
17
template <Modifier Mod, SDL_Keymod Value>
13
18
constexpr void modifier_check ()
14
19
{
@@ -493,14 +498,16 @@ namespace gf {
493
498
return static_cast <Keycode>(SDL_GetKeyFromName (name));
494
499
}
495
500
496
- Keycode Keyboard::localize (Scancode scancode)
501
+ Keycode Keyboard::localize (Scancode scancode, Flags<Modifier> modifiers )
497
502
{
498
- return static_cast <Keycode>(SDL_GetKeyFromScancode (static_cast <SDL_Scancode>(scancode), SDL_KMOD_NONE , true ));
503
+ return static_cast <Keycode>(SDL_GetKeyFromScancode (static_cast <SDL_Scancode>(scancode), modifiers. value () , true ));
499
504
}
500
505
501
- Scancode Keyboard::unlocalize (Keycode keycode)
506
+ std::tuple< Scancode, Flags<Modifier>> Keyboard::unlocalize (Keycode keycode)
502
507
{
503
- return static_cast <Scancode>(SDL_GetScancodeFromKey (static_cast <SDL_Keycode>(keycode), nullptr ));
508
+ SDL_Keymod modifiers = 0 ;
509
+ SDL_Scancode scancode = SDL_GetScancodeFromKey (static_cast <SDL_Keycode>(keycode), &modifiers);
510
+ return { static_cast <Scancode>(scancode), static_cast <Modifier>(modifiers) };
504
511
}
505
512
506
513
} // namespace gf
Original file line number Diff line number Diff line change @@ -11,10 +11,14 @@ namespace gf {
11
11
12
12
namespace {
13
13
14
- template <MouseButton Button, uint32_t Value>
14
+ static_assert (std::is_same_v<std::underlying_type_t <MouseId>, SDL_MouseID>);
15
+ static_assert (std::is_same_v<std::underlying_type_t <MouseWheelDirection>, std::make_signed_t <SDL_MouseWheelDirection>>);
16
+ static_assert (TouchMouseId == static_cast <MouseId>(SDL_TOUCH_MOUSEID));
17
+
18
+ template <MouseButton Button, uint8_t Value>
15
19
constexpr void mouse_button_check ()
16
20
{
17
- static_assert (static_cast <uint32_t >(Button) == Value, " Check gf::Mouse " );
21
+ static_assert (static_cast <uint8_t >(Button) == Value);
18
22
}
19
23
20
24
[[maybe_unused]] constexpr void mouse_check ()
@@ -24,9 +28,6 @@ namespace gf {
24
28
mouse_button_check<MouseButton::Right, SDL_BUTTON_RIGHT>();
25
29
mouse_button_check<MouseButton::XButton1, SDL_BUTTON_X1>();
26
30
mouse_button_check<MouseButton::XButton2, SDL_BUTTON_X2>();
27
-
28
- static_assert (std::is_same_v<std::underlying_type_t <MouseId>, decltype (SDL_TOUCH_MOUSEID)>, " Check gf::Mouse" );
29
- static_assert (TouchMouseId == static_cast <MouseId>(SDL_TOUCH_MOUSEID), " Check gf::Mouse" );
30
31
}
31
32
32
33
} // namespace
Original file line number Diff line number Diff line change 2
2
// Copyright (c) 2023-2025 Julien Bernard
3
3
4
4
#include < type_traits>
5
- #include < utility>
6
5
7
6
#include < SDL3/SDL.h>
8
7
11
10
namespace gf {
12
11
13
12
namespace {
13
+ static_assert (std::is_same_v<std::underlying_type_t <TouchId>, SDL_TouchID>);
14
+ static_assert (MouseTouchId == static_cast <TouchId>(SDL_MOUSE_TOUCHID));
15
+ static_assert (std::is_same_v<std::underlying_type_t <TouchDeviceType>, std::underlying_type_t <SDL_TouchDeviceType>>);
14
16
15
- [[maybe_unused]] constexpr void touch_check ()
17
+ static_assert (std::is_same_v<std::underlying_type_t <FingerId>, SDL_FingerID>);
18
+
19
+ template <TouchDeviceType Type, SDL_TouchDeviceType Value>
20
+ constexpr void touch_device_type_check ()
16
21
{
17
- static_assert (std::is_same_v<std:: underlying_type_t <TouchId>, decltype (SDL_MOUSE_TOUCHID)> );
18
- static_assert (MouseTouchId == static_cast <TouchId>(SDL_MOUSE_TOUCHID));
22
+ static_assert (static_cast <SDL_TouchDeviceType>(Type) == Value );
23
+ }
19
24
20
- static_assert (std::is_same_v<std::underlying_type_t <FingerId>, decltype (std::declval<SDL_Finger>().id )>);
25
+ [[maybe_unused]] constexpr void touch_check ()
26
+ {
27
+ touch_device_type_check<TouchDeviceType::Invalid, SDL_TOUCH_DEVICE_INVALID>();
28
+ touch_device_type_check<TouchDeviceType::Direct, SDL_TOUCH_DEVICE_DIRECT>();
29
+ touch_device_type_check<TouchDeviceType::IndirectAbsolute, SDL_TOUCH_DEVICE_INDIRECT_ABSOLUTE>();
30
+ touch_device_type_check<TouchDeviceType::IndirectRelative, SDL_TOUCH_DEVICE_INDIRECT_RELATIVE>();
21
31
}
22
32
23
33
} // namespace
You can’t perform that action at this time.
0 commit comments