diff --git a/include/mgba/core/core.h b/include/mgba/core/core.h index d1c497d8d..4954d12d1 100644 --- a/include/mgba/core/core.h +++ b/include/mgba/core/core.h @@ -105,7 +105,8 @@ struct mCore { void (*addKeys)(struct mCore*, uint32_t keys); void (*clearKeys)(struct mCore*, uint32_t keys); - void (*setCursor)(struct mCore*, int x, int y, bool down); + void (*setCursorLocation)(struct mCore*, int x, int y); + void (*setCursorDown)(struct mCore*, bool down); int32_t (*frameCounter)(const struct mCore*); int32_t (*frameCycles)(const struct mCore*); diff --git a/src/ds/core.c b/src/ds/core.c index 95e1a2b0d..d027527bf 100644 --- a/src/ds/core.c +++ b/src/ds/core.c @@ -328,15 +328,20 @@ static void _DSCoreClearKeys(struct mCore* core, uint32_t keys) { dscore->keys &= ~keys; } -static void _DSCoreSetCursor(struct mCore* core, int x, int y, bool down) { +static void _DSCoreSetCursorLocation(struct mCore* core, int x, int y) { struct DSCore* dscore = (struct DSCore*) core; dscore->cursorX = x; dscore->cursorY = y - DS_VIDEO_VERTICAL_PIXELS; - if ((down && y >= 0) || !down) { - dscore->touchDown = down; + if (dscore->cursorY < 0) { + dscore->cursorY = 0; } } +static void _DSCoreSetCursorDown(struct mCore* core, bool down) { + struct DSCore* dscore = (struct DSCore*) core; + dscore->touchDown = down; +} + static int32_t _DSCoreFrameCounter(const struct mCore* core) { struct DS* ds = core->board; return ds->video.frameCounter; @@ -522,7 +527,8 @@ struct mCore* DSCoreCreate(void) { core->setKeys = _DSCoreSetKeys; core->addKeys = _DSCoreAddKeys; core->clearKeys = _DSCoreClearKeys; - core->setCursor = _DSCoreSetCursor; + core->setCursorLocation = _DSCoreSetCursorLocation; + core->setCursorDown = _DSCoreSetCursorDown; core->frameCounter = _DSCoreFrameCounter; core->frameCycles = _DSCoreFrameCycles; core->frequency = _DSCoreFrequency; diff --git a/src/gb/core.c b/src/gb/core.c index be1208faf..6757c0929 100644 --- a/src/gb/core.c +++ b/src/gb/core.c @@ -368,10 +368,14 @@ static void _GBCoreClearKeys(struct mCore* core, uint32_t keys) { gbcore->keys &= ~keys; } -static void _GBCoreSetCursor(struct mCore* core, int x, int y, bool down) { +static void _GBCoreSetCursorLocation(struct mCore* core, int x, int y) { UNUSED(core); UNUSED(x); UNUSED(y); +} + +static void _GBCoreSetCursorDown(struct mCore* core, bool down) { + UNUSED(core); UNUSED(down); } @@ -610,7 +614,8 @@ struct mCore* GBCoreCreate(void) { core->setKeys = _GBCoreSetKeys; core->addKeys = _GBCoreAddKeys; core->clearKeys = _GBCoreClearKeys; - core->setCursor = _GBCoreSetCursor; + core->setCursorLocation = _GBCoreSetCursorLocation; + core->setCursorDown = _GBCoreSetCursorDown; core->frameCounter = _GBCoreFrameCounter; core->frameCycles = _GBCoreFrameCycles; core->frequency = _GBCoreFrequency; diff --git a/src/gba/core.c b/src/gba/core.c index c35074e88..1cb8c400c 100644 --- a/src/gba/core.c +++ b/src/gba/core.c @@ -381,10 +381,14 @@ static void _GBACoreClearKeys(struct mCore* core, uint32_t keys) { gbacore->keys &= ~keys; } -static void _GBACoreSetCursor(struct mCore* core, int x, int y, bool down) { +static void _GBACoreSetCursorLocation(struct mCore* core, int x, int y) { UNUSED(core); UNUSED(x); UNUSED(y); +} + +static void _GBACoreSetCursorDown(struct mCore* core, int x, int y, bool down) { + UNUSED(core); UNUSED(down); } @@ -624,7 +628,8 @@ struct mCore* GBACoreCreate(void) { core->setKeys = _GBACoreSetKeys; core->addKeys = _GBACoreAddKeys; core->clearKeys = _GBACoreClearKeys; - core->setCursor = _GBACoreSetCursor; + core->setCursorLocation = _GBACoreSetCursorLocation; + core->setCursorDown = _GBACoreSetCursorDown; core->frameCounter = _GBACoreFrameCounter; core->frameCycles = _GBACoreFrameCycles; core->frequency = _GBACoreFrequency; diff --git a/src/platform/sdl/sdl-events.c b/src/platform/sdl/sdl-events.c index 713e82340..18af3e005 100644 --- a/src/platform/sdl/sdl-events.c +++ b/src/platform/sdl/sdl-events.c @@ -532,7 +532,24 @@ static void _mSDLHandleMouseButton(struct mCore* core, struct mSDLPlayer* sdlCon x = x * coreW / windowW; y = y * coreH / windowH; #endif - core->setCursor(core, x, y, event->state == SDL_PRESSED); + core->setCursorLocation(core, x, y); + core->setCursorDown(core, event->state == SDL_PRESSED); +} + +static void _mSDLHandleMouseMotion(struct mCore* core, struct mSDLPlayer* sdlContext, const struct SDL_MouseMotionEvent* event) { + int x = event->x; + int y = event->y; +#if SDL_VERSION_ATLEAST(2, 0, 0) + int windowW; + int windowH; + SDL_GetWindowSize(sdlContext->window, &windowW, &windowH); + unsigned coreW; + unsigned coreH; + core->desiredVideoDimensions(core, &coreW, &coreH); + x = x * coreW / windowW; + y = y * coreH / windowH; +#endif + core->setCursorLocation(core, x, y); } static void _mSDLHandleJoyButton(struct mCore* core, struct mSDLPlayer* sdlContext, const struct SDL_JoyButtonEvent* event) { @@ -602,6 +619,9 @@ void mSDLHandleEvent(struct mCoreThread* context, struct mSDLPlayer* sdlContext, case SDL_MOUSEBUTTONUP: _mSDLHandleMouseButton(context->core, sdlContext, &event->button); break; + case SDL_MOUSEMOTION: + _mSDLHandleMouseMotion(context->core, sdlContext, &event->motion); + break; case SDL_JOYBUTTONDOWN: case SDL_JOYBUTTONUP: _mSDLHandleJoyButton(context->core, sdlContext, &event->jbutton);