From 7bff57c6fa29285eae2b5515e9b7cbf8dc8214e6 Mon Sep 17 00:00:00 2001 From: Raimon Zamora Date: Fri, 20 Jun 2025 13:49:59 +0200 Subject: [PATCH] - [NEW] mouse.discard() --- lua.cpp | 6 ++++++ mini.cpp | 11 ++++++++++- mini.h | 1 + vscode/library.lua | 3 +++ 4 files changed, 20 insertions(+), 1 deletion(-) diff --git a/lua.cpp b/lua.cpp index 4dfadf7..d091504 100644 --- a/lua.cpp +++ b/lua.cpp @@ -777,6 +777,11 @@ extern "C" { return 1; } + static int cpp_mouse_discard(lua_State *L) { + mdiscard(); + return 0; + } + // key // =============================================== @@ -949,6 +954,7 @@ void push_lua_funcs() { lua_pushcfunction(L,cpp_mouse_wheel); lua_setfield(L, -2, "wheel"); lua_pushcfunction(L,cpp_mouse_down); lua_setfield(L, -2, "down"); lua_pushcfunction(L,cpp_mouse_press); lua_setfield(L, -2, "press"); + lua_pushcfunction(L,cpp_mouse_discard); lua_setfield(L, -2, "discard"); lua_pushinteger(L, 1); lua_setfield(L, -2, "LEFT"); lua_pushinteger(L, 2); lua_setfield(L, -2, "MIDDLE"); diff --git a/mini.cpp b/mini.cpp index 3ce8662..f716870 100644 --- a/mini.cpp +++ b/mini.cpp @@ -103,6 +103,7 @@ Uint8 key_just_pressed = 0; int mouse_x, mouse_y, mouse_wheel; Uint32 mouse_buttons; uint8_t mouse_just_pressed = 0; +bool mouse_discard = false; SDL_Gamepad *gamepad = NULL; int8_t pad_just_pressed = SDL_GAMEPAD_BUTTON_INVALID; @@ -484,7 +485,10 @@ int main(int argc,char*argv[]){ #endif } if (mini_eve.type == SDL_EVENT_MOUSE_BUTTON_UP) { - mouse_just_pressed = mini_eve.button.button; + if (mouse_discard) + mouse_discard = false; + else + mouse_just_pressed = mini_eve.button.button; } if (mini_eve.type == SDL_EVENT_MOUSE_WHEEL) { mouse_wheel = mini_eve.wheel.y; @@ -1188,6 +1192,7 @@ int mwheel() { } bool mbtn(uint8_t i) { + if (mouse_discard) return false; return mouse_buttons & SDL_BUTTON_MASK(i); } @@ -1195,6 +1200,10 @@ bool mbtnp(uint8_t i) { return mouse_just_pressed == i; } +void mdiscard() { + mouse_discard = true; +} + float time() { return float(SDL_GetTicks())/1000.0f; } diff --git a/mini.h b/mini.h index 0e716bd..4a15927 100644 --- a/mini.h +++ b/mini.h @@ -219,6 +219,7 @@ int mousey(); int mwheel(); bool mbtn(uint8_t i); bool mbtnp(uint8_t i); +void mdiscard(); float time(); bool beat(int16_t i); diff --git a/vscode/library.lua b/vscode/library.lua index ed94a02..d16536b 100644 --- a/vscode/library.lua +++ b/vscode/library.lua @@ -459,6 +459,9 @@ function mouse.down(btn) end ---Returns whether the specified mouse button has just been pressed function mouse.press(btn) end +---Ignores current down button, effectively not raising the next "press" event +function mouse.discard() end + mouse.LEFT = 1 mouse.MIDDLE = 2 mouse.RIGHT = 3