From ea6b535a408e2218bd44b0e97881865096d00e23 Mon Sep 17 00:00:00 2001 From: Bad Diode Date: Sat, 5 Mar 2022 20:01:18 +0100 Subject: [PATCH] Add initial implementation of mouse buttons --- src/main.c | 34 +++++++++++++++++++++++++++++----- 1 file changed, 29 insertions(+), 5 deletions(-) diff --git a/src/main.c b/src/main.c index 22e9797..b9100ab 100644 --- a/src/main.c +++ b/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));