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; return 1;
} }
SDL_ShowCursor(SDL_DISABLE);
fox32_init(&vm); fox32_init(&vm);
vm.io_read = bus_io_read; vm.io_read = bus_io_read;
vm.io_write = bus_io_write; vm.io_write = bus_io_write;

View File

@ -24,7 +24,7 @@ static size_t find_free_tlb_entry_index() {
} }
} }
return (replacement_index++)&63; return (replacement_index++) & 63;
} }
void set_and_flush_tlb(uint32_t virtual_address) { void set_and_flush_tlb(uint32_t virtual_address) {

View File

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

View File

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