diff --git a/data/game.lua b/data/game.lua index c0991e1..607a15a 100644 --- a/data/game.lua +++ b/data/game.lua @@ -22,7 +22,7 @@ function normal_update() quit() end - if btnp(KEY_F2) then + if btnp(KEY_F2) or mbtnp(1) then local val = zoom() + 2 if val >= 10 then val = 2 end zoom(val) diff --git a/lua.cpp b/lua.cpp index f5db39d..afe088b 100644 --- a/lua.cpp +++ b/lua.cpp @@ -496,6 +496,12 @@ extern "C" { return 1; } + static int cpp_mbtnp(lua_State *L) { + uint8_t i = luaL_checkinteger(L, 1); + lua_pushboolean(L, mbtnp(i)); + return 1; + } + static int cpp_time(lua_State *L) { lua_pushnumber(L, time()); return 1; @@ -833,6 +839,7 @@ void push_lua_funcs() { lua_pushcfunction(L,cpp_mousey); lua_setglobal(L, "mousey"); lua_pushcfunction(L,cpp_mwheel); lua_setglobal(L, "mwheel"); lua_pushcfunction(L,cpp_mbtn); lua_setglobal(L, "mbtn"); + lua_pushcfunction(L,cpp_mbtnp); lua_setglobal(L, "mbtnp"); lua_pushcfunction(L,cpp_time); lua_setglobal(L, "time"); lua_pushcfunction(L,cpp_abs); lua_setglobal(L, "abs"); diff --git a/mini.cpp b/mini.cpp index 68ec0c5..af1f27d 100644 --- a/mini.cpp +++ b/mini.cpp @@ -79,6 +79,7 @@ Uint8 key_just_pressed = 0; int mouse_x, mouse_y, mouse_wheel; Uint32 mouse_buttons; +uint8_t mouse_just_pressed = 0; SDL_GameController *gamepad = NULL; int8_t pad_just_pressed = SDL_CONTROLLER_BUTTON_INVALID; @@ -274,6 +275,7 @@ int main(int argc,char*argv[]){ Uint32 dt=SDL_GetTicks(); key_just_pressed = 0; pad_just_pressed = SDL_CONTROLLER_BUTTON_INVALID; + mouse_just_pressed = 0; while(!should_exit) { mouse_wheel = 0; while(SDL_PollEvent(&mini_eve)) { @@ -311,6 +313,9 @@ int main(int argc,char*argv[]){ key_just_pressed = mini_eve.key.keysym.scancode; #endif } + if (mini_eve.type == SDL_MOUSEBUTTONUP) { + mouse_just_pressed = mini_eve.button.button; + } if (mini_eve.type == SDL_MOUSEWHEEL) { mouse_wheel = mini_eve.wheel.y; } @@ -330,6 +335,7 @@ int main(int argc,char*argv[]){ loop(); } key_just_pressed = 0; + mouse_just_pressed = 0; pad_just_pressed = SDL_CONTROLLER_BUTTON_INVALID; } SDL_LockTexture(mini_bak, NULL, (void**)&pixels, &pitch); @@ -929,6 +935,10 @@ bool mbtn(uint8_t i) { return mouse_buttons & SDL_BUTTON(i); } +bool mbtnp(uint8_t i) { + return mouse_just_pressed == i; +} + float time() { return float(SDL_GetTicks())/1000.0f; } diff --git a/mini.h b/mini.h index 5c0e26b..2451e74 100644 --- a/mini.h +++ b/mini.h @@ -212,6 +212,7 @@ int mousex(); int mousey(); int mwheel(); bool mbtn(uint8_t i); +bool mbtnp(uint8_t i); float time();