Use absolute mouse position instead of grabbing the cursor

This commit is contained in:
Ry 2022-10-26 16:55:11 -07:00
parent 072cb452e1
commit 23478340d2
4 changed files with 12 additions and 35 deletions

View File

@ -42,6 +42,8 @@ int main(int argc, char *argv[]) {
return 1;
}
SDL_ShowCursor(SDL_DISABLE);
fox32_init(&vm);
vm.io_read = bus_io_read;
vm.io_write = bus_io_write;

View File

@ -13,9 +13,9 @@
mouse_t mouse;
void mouse_moved(int dx, int dy) {
mouse.x += dx;
mouse.y += dy;
void mouse_moved(int x, int y) {
mouse.x = x;
mouse.y = y;
if (mouse.x > 0x8000) mouse.x = 0;
if (mouse.x > 640) mouse.x = 640;

View File

@ -9,20 +9,15 @@
#include "screen.h"
#define WINDOW_TITLE_UNGRABBED "fox32 emulator"
#define WINDOW_TITLE_GRABBED "fox32 emulator - strike F1 to uncapture mouse"
#define SCREEN_ZOOM 1
struct Screen MainScreen;
int WindowWidth = 0;
int WindowHeight = 0;
int ScreenZoom = 1;
bool ScreenFirstDraw = true;
bool ScreenMouseGrabbed = false;
SDL_Window *ScreenWindow;
SDL_Renderer *ScreenRenderer;
@ -30,10 +25,10 @@ SDL_Rect WindowRect;
void ScreenInit() {
ScreenWindow = SDL_CreateWindow(
WINDOW_TITLE_UNGRABBED,
"fox32 emulator",
SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED,
(int)(WindowWidth * ScreenZoom),
(int)(WindowHeight * ScreenZoom),
(int)(WindowWidth * SCREEN_ZOOM),
(int)(WindowHeight * SCREEN_ZOOM),
SDL_WINDOW_HIDDEN
);
@ -109,23 +104,12 @@ int ScreenProcessEvents() {
}
case SDL_MOUSEMOTION: {
if (ScreenMouseGrabbed) {
if (MainScreen.MouseMoved)
MainScreen.MouseMoved(event.motion.xrel, event.motion.yrel);
}
MainScreen.MouseMoved(event.motion.x, event.motion.y);
break;
}
case SDL_MOUSEBUTTONDOWN: {
if (!ScreenMouseGrabbed) {
SDL_SetWindowGrab(ScreenWindow, true);
SDL_ShowCursor(false);
SDL_SetWindowTitle(ScreenWindow, WINDOW_TITLE_GRABBED);
SDL_SetRelativeMouseMode(true);
ScreenMouseGrabbed = true;
break;
}
if (MainScreen.MousePressed)
MainScreen.MousePressed(event.button.button);
break;
@ -139,15 +123,6 @@ int ScreenProcessEvents() {
}
case SDL_KEYDOWN:
if ((event.key.keysym.scancode == SDL_SCANCODE_F1) && ScreenMouseGrabbed) {
SDL_SetWindowGrab(ScreenWindow, false);
SDL_ShowCursor(true);
SDL_SetWindowTitle(ScreenWindow, WINDOW_TITLE_UNGRABBED);
SDL_SetRelativeMouseMode(false);
ScreenMouseGrabbed = false;
break;
}
if (MainScreen.KeyPressed)
MainScreen.KeyPressed(event.key.keysym.scancode);
break;