From bc34748107f1ed8608f5a665f34577764cc65bbb Mon Sep 17 00:00:00 2001 From: orangerot Date: Tue, 14 Oct 2025 04:11:36 +0200 Subject: feat: mouse support --- game.c | 26 ++++++++++++++++++-------- 1 file changed, 18 insertions(+), 8 deletions(-) (limited to 'game.c') diff --git a/game.c b/game.c index 49f2feb..1cfc1a1 100644 --- a/game.c +++ b/game.c @@ -1,16 +1,15 @@ - -#include #include #include -#include #include "game.h" -void character_callback(GLFWwindow* window, unsigned int codepoint) { - printf("%c\n", codepoint); -} +#define MIN(a,b) (((a)<(b))?(a):(b)) +#define MAX(a,b) (((a)>(b))?(a):(b)) +#define CLAMP(x,a,b) (MIN(MAX(x,a),b)) -void key_callback(GLFWwindow* window, int key, int scancode, int action, int mods) { +int mouse_x = 0, mouse_y = 0; + +void key_callback(int key, int scancode, int action, int mods) { if (action != GLFW_PRESS) return; switch (key) { case GLFW_KEY_ENTER: @@ -20,6 +19,17 @@ void key_callback(GLFWwindow* window, int key, int scancode, int action, int mod } } +void cursor_position_callback(int xpos, int ypos) { + mouse_x = xpos; + mouse_y = ypos; +} + +void mouse_button_callback(int button, int action, int mods) { + if (button == GLFW_MOUSE_BUTTON_RIGHT && action == GLFW_PRESS) {} +} + void draw_image(decoded_image img) { - for (int i = 0; i < img.buf_size; i++) img.buf[i] = i; + // for (int i = 0; i < img.buf_size; i++) img.buf[i] = i; + img.buf[CLAMP(mouse_y, 0, img.height) * img.width + + CLAMP(mouse_x, 0, img.width)] = -1; } -- cgit v1.2.3