better cursor handling

main
Henri Vasserman 2025-01-10 17:46:30 +02:00
parent 931ec082b8
commit d45ae565a7
1 changed files with 4 additions and 1 deletions

View File

@ -5,6 +5,7 @@
#include "platform.h" #include "platform.h"
#include "types.h" #include "types.h"
#include <SDL3/SDL_mouse.h>
#include <SDL3/SDL_render.h> #include <SDL3/SDL_render.h>
#include <stdio.h> #include <stdio.h>
#include <inttypes.h> #include <inttypes.h>
@ -87,18 +88,20 @@ int main() {
break; break;
} }
} }
SDL_HideCursor();
break; break;
} }
case SDL_EVENT_MOUSE_BUTTON_DOWN: case SDL_EVENT_MOUSE_BUTTON_DOWN:
case SDL_EVENT_MOUSE_BUTTON_UP: { case SDL_EVENT_MOUSE_BUTTON_UP: {
dragging = event.button.down; dragging = event.button.down;
SDL_SetWindowRelativeMouseMode(window, dragging);
break; break;
} }
case SDL_EVENT_MOUSE_MOTION: { case SDL_EVENT_MOUSE_MOTION: {
if (dragging) { if (dragging) {
f.offset.x -= event.motion.xrel; f.offset.x -= event.motion.xrel;
f.offset.y -= event.motion.yrel; f.offset.y -= event.motion.yrel;
} else {
SDL_ShowCursor();
} }
break; break;
} }