Core: Support dragging

This commit is contained in:
Vicki Pfau 2017-03-04 11:16:06 -08:00
parent 0ff5f43eb0
commit 97f915e617
5 changed files with 47 additions and 10 deletions

View File

@ -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*);

View File

@ -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;

View File

@ -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;

View File

@ -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;

View File

@ -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);