Skip to content

Commit 2ecbf4b

Browse files
committed
[Core][SDL] Add mouse wheel support in SDL
1 parent 4ef90e6 commit 2ecbf4b

File tree

2 files changed

+22
-4
lines changed

2 files changed

+22
-4
lines changed

src/core/include/growl/core/input/event.h

+3-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ enum class InputEventType {
1717
Custom
1818
};
1919

20-
enum class PointerEventType { Unknown, Up, Down, Move };
20+
enum class PointerEventType { Unknown, Up, Down, Move, Scroll };
2121

2222
enum class MouseButton { Unknown, LeftClick, RightClick, MiddleClick };
2323

@@ -26,6 +26,8 @@ struct InputMouseEvent {
2626
MouseButton button;
2727
int mouseX;
2828
int mouseY;
29+
float scrollX;
30+
float scrollY;
2931
};
3032

3133
struct InputTouchEvent {

src/plugins/sdl3/src/sdl3_system.cpp

+19-3
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,7 @@ void SDL3SystemAPI::tick() {
9999
case SDL_EVENT_MOUSE_MOTION:
100100
case SDL_EVENT_MOUSE_BUTTON_DOWN:
101101
case SDL_EVENT_MOUSE_BUTTON_UP:
102+
case SDL_EVENT_MOUSE_WHEEL:
102103
if (scene_focused) {
103104
handleMouseEvent(event);
104105
}
@@ -222,8 +223,19 @@ void SDL3SystemAPI::handleMouseEvent(SDL_Event& event) {
222223
SDL_Window* window = SDL_GetWindowFromID(event.motion.windowID);
223224
SDL_GetWindowSize(window, &window_w, &window_h);
224225
SDL_GetWindowSizeInPixels(window, &display_w, &display_h);
225-
int x = event.motion.x * (display_w / (float)window_w);
226-
int y = event.motion.y * (display_h / (float)window_h);
226+
227+
int x = event.motion.x;
228+
int y = event.motion.y;
229+
float scroll_x = 0;
230+
float scroll_y = 0;
231+
if (event.type == SDL_EVENT_MOUSE_WHEEL) {
232+
x = event.wheel.mouse_x;
233+
y = event.wheel.mouse_y;
234+
scroll_x = -event.wheel.x;
235+
scroll_y = event.wheel.y;
236+
}
237+
x *= display_w / (float)window_w;
238+
y *= display_h / (float)window_h;
227239

228240
#ifdef GROWL_IMGUI
229241
if (api.imguiVisible()) {
@@ -246,6 +258,9 @@ void SDL3SystemAPI::handleMouseEvent(SDL_Event& event) {
246258
case SDL_EVENT_MOUSE_MOTION:
247259
event_type = PointerEventType::Move;
248260
break;
261+
case SDL_EVENT_MOUSE_WHEEL:
262+
event_type = PointerEventType::Scroll;
263+
break;
249264
}
250265

251266
MouseButton mouse_button = MouseButton::Unknown;
@@ -263,7 +278,8 @@ void SDL3SystemAPI::handleMouseEvent(SDL_Event& event) {
263278

264279
InputEvent e(
265280
InputEventType::Mouse,
266-
InputMouseEvent{event_type, mouse_button, x, y});
281+
InputMouseEvent{
282+
event_type, mouse_button, x, y, scroll_x, scroll_y});
267283
inputProcessor->onEvent(e);
268284
}
269285
}

0 commit comments

Comments
 (0)