mirror of https://github.com/mgba-emu/mgba.git
Core: Support dragging
This commit is contained in:
parent
0ff5f43eb0
commit
97f915e617
|
@ -105,7 +105,8 @@ struct mCore {
|
||||||
void (*addKeys)(struct mCore*, uint32_t keys);
|
void (*addKeys)(struct mCore*, uint32_t keys);
|
||||||
void (*clearKeys)(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 (*frameCounter)(const struct mCore*);
|
||||||
int32_t (*frameCycles)(const struct mCore*);
|
int32_t (*frameCycles)(const struct mCore*);
|
||||||
|
|
|
@ -328,15 +328,20 @@ static void _DSCoreClearKeys(struct mCore* core, uint32_t keys) {
|
||||||
dscore->keys &= ~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;
|
struct DSCore* dscore = (struct DSCore*) core;
|
||||||
dscore->cursorX = x;
|
dscore->cursorX = x;
|
||||||
dscore->cursorY = y - DS_VIDEO_VERTICAL_PIXELS;
|
dscore->cursorY = y - DS_VIDEO_VERTICAL_PIXELS;
|
||||||
if ((down && y >= 0) || !down) {
|
if (dscore->cursorY < 0) {
|
||||||
dscore->touchDown = down;
|
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) {
|
static int32_t _DSCoreFrameCounter(const struct mCore* core) {
|
||||||
struct DS* ds = core->board;
|
struct DS* ds = core->board;
|
||||||
return ds->video.frameCounter;
|
return ds->video.frameCounter;
|
||||||
|
@ -522,7 +527,8 @@ struct mCore* DSCoreCreate(void) {
|
||||||
core->setKeys = _DSCoreSetKeys;
|
core->setKeys = _DSCoreSetKeys;
|
||||||
core->addKeys = _DSCoreAddKeys;
|
core->addKeys = _DSCoreAddKeys;
|
||||||
core->clearKeys = _DSCoreClearKeys;
|
core->clearKeys = _DSCoreClearKeys;
|
||||||
core->setCursor = _DSCoreSetCursor;
|
core->setCursorLocation = _DSCoreSetCursorLocation;
|
||||||
|
core->setCursorDown = _DSCoreSetCursorDown;
|
||||||
core->frameCounter = _DSCoreFrameCounter;
|
core->frameCounter = _DSCoreFrameCounter;
|
||||||
core->frameCycles = _DSCoreFrameCycles;
|
core->frameCycles = _DSCoreFrameCycles;
|
||||||
core->frequency = _DSCoreFrequency;
|
core->frequency = _DSCoreFrequency;
|
||||||
|
|
|
@ -368,10 +368,14 @@ static void _GBCoreClearKeys(struct mCore* core, uint32_t keys) {
|
||||||
gbcore->keys &= ~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(core);
|
||||||
UNUSED(x);
|
UNUSED(x);
|
||||||
UNUSED(y);
|
UNUSED(y);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void _GBCoreSetCursorDown(struct mCore* core, bool down) {
|
||||||
|
UNUSED(core);
|
||||||
UNUSED(down);
|
UNUSED(down);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -610,7 +614,8 @@ struct mCore* GBCoreCreate(void) {
|
||||||
core->setKeys = _GBCoreSetKeys;
|
core->setKeys = _GBCoreSetKeys;
|
||||||
core->addKeys = _GBCoreAddKeys;
|
core->addKeys = _GBCoreAddKeys;
|
||||||
core->clearKeys = _GBCoreClearKeys;
|
core->clearKeys = _GBCoreClearKeys;
|
||||||
core->setCursor = _GBCoreSetCursor;
|
core->setCursorLocation = _GBCoreSetCursorLocation;
|
||||||
|
core->setCursorDown = _GBCoreSetCursorDown;
|
||||||
core->frameCounter = _GBCoreFrameCounter;
|
core->frameCounter = _GBCoreFrameCounter;
|
||||||
core->frameCycles = _GBCoreFrameCycles;
|
core->frameCycles = _GBCoreFrameCycles;
|
||||||
core->frequency = _GBCoreFrequency;
|
core->frequency = _GBCoreFrequency;
|
||||||
|
|
|
@ -381,10 +381,14 @@ static void _GBACoreClearKeys(struct mCore* core, uint32_t keys) {
|
||||||
gbacore->keys &= ~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(core);
|
||||||
UNUSED(x);
|
UNUSED(x);
|
||||||
UNUSED(y);
|
UNUSED(y);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void _GBACoreSetCursorDown(struct mCore* core, int x, int y, bool down) {
|
||||||
|
UNUSED(core);
|
||||||
UNUSED(down);
|
UNUSED(down);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -624,7 +628,8 @@ struct mCore* GBACoreCreate(void) {
|
||||||
core->setKeys = _GBACoreSetKeys;
|
core->setKeys = _GBACoreSetKeys;
|
||||||
core->addKeys = _GBACoreAddKeys;
|
core->addKeys = _GBACoreAddKeys;
|
||||||
core->clearKeys = _GBACoreClearKeys;
|
core->clearKeys = _GBACoreClearKeys;
|
||||||
core->setCursor = _GBACoreSetCursor;
|
core->setCursorLocation = _GBACoreSetCursorLocation;
|
||||||
|
core->setCursorDown = _GBACoreSetCursorDown;
|
||||||
core->frameCounter = _GBACoreFrameCounter;
|
core->frameCounter = _GBACoreFrameCounter;
|
||||||
core->frameCycles = _GBACoreFrameCycles;
|
core->frameCycles = _GBACoreFrameCycles;
|
||||||
core->frequency = _GBACoreFrequency;
|
core->frequency = _GBACoreFrequency;
|
||||||
|
|
|
@ -532,7 +532,24 @@ static void _mSDLHandleMouseButton(struct mCore* core, struct mSDLPlayer* sdlCon
|
||||||
x = x * coreW / windowW;
|
x = x * coreW / windowW;
|
||||||
y = y * coreH / windowH;
|
y = y * coreH / windowH;
|
||||||
#endif
|
#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) {
|
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:
|
case SDL_MOUSEBUTTONUP:
|
||||||
_mSDLHandleMouseButton(context->core, sdlContext, &event->button);
|
_mSDLHandleMouseButton(context->core, sdlContext, &event->button);
|
||||||
break;
|
break;
|
||||||
|
case SDL_MOUSEMOTION:
|
||||||
|
_mSDLHandleMouseMotion(context->core, sdlContext, &event->motion);
|
||||||
|
break;
|
||||||
case SDL_JOYBUTTONDOWN:
|
case SDL_JOYBUTTONDOWN:
|
||||||
case SDL_JOYBUTTONUP:
|
case SDL_JOYBUTTONUP:
|
||||||
_mSDLHandleJoyButton(context->core, sdlContext, &event->jbutton);
|
_mSDLHandleJoyButton(context->core, sdlContext, &event->jbutton);
|
||||||
|
|
Loading…
Reference in New Issue