Core: Support dragging
Vicki Pfau vi@endrift.com
Sat, 04 Mar 2017 11:16:06 -0800
5 files changed,
47 insertions(+),
10 deletions(-)
M
include/mgba/core/core.h
→
include/mgba/core/core.h
@@ -105,7 +105,8 @@ void (*setKeys)(struct mCore*, uint32_t keys);
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*);
M
src/ds/core.c
→
src/ds/core.c
@@ -328,13 +328,18 @@ struct DSCore* dscore = (struct DSCore*) core;
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) {@@ -522,7 +527,8 @@ core->saveState = _DSCoreSaveState;
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;
M
src/gb/core.c
→
src/gb/core.c
@@ -368,10 +368,14 @@ struct GBCore* gbcore = (struct GBCore*) core;
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 @@ core->saveState = _GBCoreSaveState;
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;
M
src/gba/core.c
→
src/gba/core.c
@@ -381,10 +381,14 @@ struct GBACore* gbacore = (struct GBACore*) core;
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 @@ core->saveState = _GBACoreSaveState;
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;
M
src/platform/sdl/sdl-events.c
→
src/platform/sdl/sdl-events.c
@@ -532,7 +532,24 @@ core->desiredVideoDimensions(core, &coreW, &coreH);
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) {@@ -601,6 +618,9 @@ break;
case SDL_MOUSEBUTTONDOWN: 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: