- [NEW] mouse.discard()
This commit is contained in:
6
lua.cpp
6
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");
|
||||
|
||||
11
mini.cpp
11
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;
|
||||
}
|
||||
|
||||
1
mini.h
1
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);
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user