[WIP] Add mouse click input

This commit is contained in:
Bad Diode 2022-10-12 14:36:28 +02:00
parent 39b47de235
commit e101b44b98
1 changed files with 8 additions and 4 deletions

View File

@ -118,7 +118,6 @@ poll_mouse(void) {
struct input_event mouse_event; struct input_event mouse_event;
if (read(in.mouse_fd, &mouse_event, sizeof(mouse_event)) != -1) { if (read(in.mouse_fd, &mouse_event, sizeof(mouse_event)) != -1) {
if (mouse_event.type == EV_REL) { if (mouse_event.type == EV_REL) {
printf("MOUSE REL EVENT\n");
if (mouse_event.code == REL_X) { if (mouse_event.code == REL_X) {
in.mouse.x = CLAMP( in.mouse.x = CLAMP(
in.mouse.x / zoom + (s32)mouse_event.value, 0, (s32)screen_width); in.mouse.x / zoom + (s32)mouse_event.value, 0, (s32)screen_width);
@ -127,14 +126,12 @@ poll_mouse(void) {
in.mouse.y / zoom + (s32)mouse_event.value, 0, (s32)screen_height); in.mouse.y / zoom + (s32)mouse_event.value, 0, (s32)screen_height);
} }
} else if (mouse_event.type == EV_ABS) { } else if (mouse_event.type == EV_ABS) {
printf("MOUSE ABS EVENT\n");
if (mouse_event.code == ABS_X) { if (mouse_event.code == ABS_X) {
in.mouse.x = CLAMP((s32)mouse_event.value / zoom, 0, (s32)screen_width); in.mouse.x = CLAMP((s32)mouse_event.value / zoom, 0, (s32)screen_width);
} else if (mouse_event.code == ABS_Y) { } else if (mouse_event.code == ABS_Y) {
in.mouse.y = CLAMP((s32)mouse_event.value / zoom, 0, (s32)screen_height); in.mouse.y = CLAMP((s32)mouse_event.value / zoom, 0, (s32)screen_height);
} }
} else if (mouse_event.type == EV_KEY) { } else if (mouse_event.type == EV_KEY) {
printf("MOUSE KEY EVENT\n");
switch (mouse_event.code) { switch (mouse_event.code) {
case BTN_LEFT: { case BTN_LEFT: {
if (mouse_event.value == 1) { if (mouse_event.value == 1) {
@ -150,7 +147,14 @@ poll_mouse(void) {
in.mouse.buttons &= ~0x10; in.mouse.buttons &= ~0x10;
} }
} break; } break;
default: break; default: {
// NOTE: nook press.
if (mouse_event.value == 1) {
in.mouse.buttons |= 0x01;
} else {
in.mouse.buttons &= ~0x01;
}
} break;
} }
} }
in.mouse.update = true; in.mouse.update = true;