- [NEW] mouse.discard()

This commit is contained in:
2025-06-20 13:49:59 +02:00
parent f154e1a36b
commit 7bff57c6fa
4 changed files with 20 additions and 1 deletions

View File

@@ -777,6 +777,11 @@ extern "C" {
return 1; return 1;
} }
static int cpp_mouse_discard(lua_State *L) {
mdiscard();
return 0;
}
// key // 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_wheel); lua_setfield(L, -2, "wheel");
lua_pushcfunction(L,cpp_mouse_down); lua_setfield(L, -2, "down"); 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_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, 1); lua_setfield(L, -2, "LEFT");
lua_pushinteger(L, 2); lua_setfield(L, -2, "MIDDLE"); lua_pushinteger(L, 2); lua_setfield(L, -2, "MIDDLE");

View File

@@ -103,6 +103,7 @@ Uint8 key_just_pressed = 0;
int mouse_x, mouse_y, mouse_wheel; int mouse_x, mouse_y, mouse_wheel;
Uint32 mouse_buttons; Uint32 mouse_buttons;
uint8_t mouse_just_pressed = 0; uint8_t mouse_just_pressed = 0;
bool mouse_discard = false;
SDL_Gamepad *gamepad = NULL; SDL_Gamepad *gamepad = NULL;
int8_t pad_just_pressed = SDL_GAMEPAD_BUTTON_INVALID; int8_t pad_just_pressed = SDL_GAMEPAD_BUTTON_INVALID;
@@ -484,6 +485,9 @@ int main(int argc,char*argv[]){
#endif #endif
} }
if (mini_eve.type == SDL_EVENT_MOUSE_BUTTON_UP) { if (mini_eve.type == SDL_EVENT_MOUSE_BUTTON_UP) {
if (mouse_discard)
mouse_discard = false;
else
mouse_just_pressed = mini_eve.button.button; mouse_just_pressed = mini_eve.button.button;
} }
if (mini_eve.type == SDL_EVENT_MOUSE_WHEEL) { if (mini_eve.type == SDL_EVENT_MOUSE_WHEEL) {
@@ -1188,6 +1192,7 @@ int mwheel() {
} }
bool mbtn(uint8_t i) { bool mbtn(uint8_t i) {
if (mouse_discard) return false;
return mouse_buttons & SDL_BUTTON_MASK(i); return mouse_buttons & SDL_BUTTON_MASK(i);
} }
@@ -1195,6 +1200,10 @@ bool mbtnp(uint8_t i) {
return mouse_just_pressed == i; return mouse_just_pressed == i;
} }
void mdiscard() {
mouse_discard = true;
}
float time() { float time() {
return float(SDL_GetTicks())/1000.0f; return float(SDL_GetTicks())/1000.0f;
} }

1
mini.h
View File

@@ -219,6 +219,7 @@ int mousey();
int mwheel(); int mwheel();
bool mbtn(uint8_t i); bool mbtn(uint8_t i);
bool mbtnp(uint8_t i); bool mbtnp(uint8_t i);
void mdiscard();
float time(); float time();
bool beat(int16_t i); bool beat(int16_t i);

View File

@@ -459,6 +459,9 @@ function mouse.down(btn) end
---Returns whether the specified mouse button has just been pressed ---Returns whether the specified mouse button has just been pressed
function mouse.press(btn) end function mouse.press(btn) end
---Ignores current down button, effectively not raising the next "press" event
function mouse.discard() end
mouse.LEFT = 1 mouse.LEFT = 1
mouse.MIDDLE = 2 mouse.MIDDLE = 2
mouse.RIGHT = 3 mouse.RIGHT = 3