Removed Device struct from mouse device

This commit is contained in:
Devine Lu Linvega 2023-01-01 11:31:14 -08:00
parent 6317b5cf18
commit 062bbac37d
4 changed files with 32 additions and 30 deletions

View File

@ -2,8 +2,7 @@
#include "mouse.h"
/*
Copyright (c) 2021 Devine Lu Linvega
Copyright (c) 2021 Andrew Alderwick
Copyright (c) 2021 Devine Lu Linvega, Andrew Alderwick
Permission to use, copy, modify, and distribute this software for any
purpose with or without fee is hereby granted, provided that the above
@ -14,33 +13,33 @@ WITH REGARD TO THIS SOFTWARE.
*/
void
mouse_down(Device *d, Uint8 mask)
mouse_down(Uxn *u, Uint8 *d, Uint8 mask)
{
d->dat[6] |= mask;
uxn_eval(d->u, GETVECTOR(d));
d[6] |= mask;
uxn_eval(u, GETVEC(d));
}
void
mouse_up(Device *d, Uint8 mask)
mouse_up(Uxn *u, Uint8 *d, Uint8 mask)
{
d->dat[6] &= (~mask);
uxn_eval(d->u, GETVECTOR(d));
d[6] &= (~mask);
uxn_eval(u, GETVEC(d));
}
void
mouse_pos(Device *d, Uint16 x, Uint16 y)
mouse_pos(Uxn *u, Uint8 *d, Uint16 x, Uint16 y)
{
DEVPOKE16(0x2, x);
DEVPOKE16(0x4, y);
uxn_eval(d->u, GETVECTOR(d));
POKDEV(0x2, x);
POKDEV(0x4, y);
uxn_eval(u, GETVEC(d));
}
void
mouse_scroll(Device *d, Uint16 x, Uint16 y)
mouse_scroll(Uxn *u, Uint8 *d, Uint16 x, Uint16 y)
{
DEVPOKE16(0xa, x);
DEVPOKE16(0xc, -y);
uxn_eval(d->u, GETVECTOR(d));
DEVPOKE16(0xa, 0);
DEVPOKE16(0xc, 0);
POKDEV(0xa, x);
POKDEV(0xc, -y);
uxn_eval(u, GETVEC(d));
POKDEV(0xa, 0);
POKDEV(0xc, 0);
}

View File

@ -1,6 +1,5 @@
/*
Copyright (c) 2021 Devine Lu Linvega
Copyright (c) 2021 Andrew Alderwick
Copyright (c) 2021 Devine Lu Linvega, Andrew Alderwick
Permission to use, copy, modify, and distribute this software for any
purpose with or without fee is hereby granted, provided that the above
@ -10,7 +9,7 @@ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
WITH REGARD TO THIS SOFTWARE.
*/
void mouse_down(Device *d, Uint8 mask);
void mouse_up(Device *d, Uint8 mask);
void mouse_pos(Device *d, Uint16 x, Uint16 y);
void mouse_scroll(Device *d, Uint16 x, Uint16 y);
void mouse_down(Uxn *u, Uint8 *d, Uint8 mask);
void mouse_up(Uxn *u, Uint8 *d, Uint8 mask);
void mouse_pos(Uxn *u, Uint8 *d, Uint16 x, Uint16 y);
void mouse_scroll(Uxn *u, Uint8 *d, Uint16 x, Uint16 y);

View File

@ -26,6 +26,12 @@ typedef unsigned int Uint32;
#define DEVPOKE16(x, y) { d->dat[(x)] = (y) >> 8; d->dat[(x) + 1] = (y); }
#define GETVECTOR(d) ((d)->dat[0] << 8 | (d)->dat[1])
/* new macros */
#define GETVEC(d) ((d)[0] << 8 | (d)[1])
#define POKDEV(x, y) { d[(x)] = (y) >> 8; d[(x) + 1] = (y); }
#define PEKDEV(o, x) { (o) = (d[(x)] << 8) + d[(x) + 1]; }
/* clang-format on */
typedef struct {

View File

@ -402,15 +402,13 @@ handle_events(Uxn *u)
}
/* Mouse */
else if(event.type == SDL_MOUSEMOTION)
mouse_pos(devmouse,
clamp(event.motion.x - PAD, 0, uxn_screen.width - 1),
clamp(event.motion.y - PAD, 0, uxn_screen.height - 1));
mouse_pos(u, devmouse->dat, clamp(event.motion.x - PAD, 0, uxn_screen.width - 1), clamp(event.motion.y - PAD, 0, uxn_screen.height - 1));
else if(event.type == SDL_MOUSEBUTTONUP)
mouse_up(devmouse, SDL_BUTTON(event.button.button));
mouse_up(u, devmouse->dat, SDL_BUTTON(event.button.button));
else if(event.type == SDL_MOUSEBUTTONDOWN)
mouse_down(devmouse, SDL_BUTTON(event.button.button));
mouse_down(u, devmouse->dat, SDL_BUTTON(event.button.button));
else if(event.type == SDL_MOUSEWHEEL)
mouse_scroll(devmouse, event.wheel.x, event.wheel.y);
mouse_scroll(u, devmouse->dat, event.wheel.x, event.wheel.y);
/* Controller */
else if(event.type == SDL_TEXTINPUT)
controller_key(devctrl, event.text.text[0]);