Add initial implementation of mouse buttons
This commit is contained in:
parent
ce07c0539c
commit
ea6b535a40
34
src/main.c
34
src/main.c
|
@ -38,9 +38,7 @@ time_elapsed(Time since){
|
|||
typedef struct Mouse {
|
||||
s32 x;
|
||||
s32 y;
|
||||
bool left;
|
||||
bool mid;
|
||||
bool right;
|
||||
u8 buttons;
|
||||
bool update;
|
||||
} Mouse;
|
||||
|
||||
|
@ -110,9 +108,26 @@ poll_mouse(void) {
|
|||
in.mouse.y = CLAMP(
|
||||
in.mouse.y + (s32)mouse_event.value, 0, (s32)screen_height);
|
||||
}
|
||||
} else if (mouse_event.type == EV_KEY) {
|
||||
switch (mouse_event.code) {
|
||||
case BTN_LEFT: {
|
||||
if (mouse_event.value == 1) {
|
||||
in.mouse.buttons |= 0x01
|
||||
} else {
|
||||
in.mouse.buttons &= ~0x01
|
||||
}
|
||||
} break;
|
||||
case BTN_RIGHT: {
|
||||
if (mouse_event.value == 1) {
|
||||
in.mouse.buttons |= 0x10
|
||||
} else {
|
||||
in.mouse.buttons &= ~0x10
|
||||
}
|
||||
} break;
|
||||
default: break;
|
||||
}
|
||||
}
|
||||
in.mouse.update = true;
|
||||
// TODO: Handle mouse keys
|
||||
// DEBUG:
|
||||
// printf("MOUSE: (type: %d, code: %d, value: %d)\n",
|
||||
// mouse_event.type, mouse_event.code, mouse_event.value);
|
||||
|
@ -274,7 +289,16 @@ handle_keyboard(void) {
|
|||
void
|
||||
handle_mouse(void) {
|
||||
if (in.mouse.update) {
|
||||
// TODO: Handle mouse keys
|
||||
// Handle mouse keys.
|
||||
devmouse->dat[6] = in.mouse.buttons;
|
||||
if(in.mouse.buttons == 0x10 && (devmouse->dat[6] & 0x01)) {
|
||||
devmouse->dat[7] = 0x01;
|
||||
}
|
||||
if(in.mouse.buttons == 0x01 && (devmouse->dat[6] & 0x10)) {
|
||||
devmouse->dat[7] = 0x10;
|
||||
}
|
||||
|
||||
// Handle mouse location.
|
||||
mempoke16(devmouse->dat, 0x2, in.mouse.x);
|
||||
mempoke16(devmouse->dat, 0x4, in.mouse.y);
|
||||
uxn_eval(&u, mempeek16(devmouse->dat, 0));
|
||||
|
|
Loading…
Reference in New Issue