- [NEW] mbtnp() added

This commit is contained in:
2023-01-27 19:50:49 +01:00
parent 5e4f0559c4
commit c335edee57
4 changed files with 19 additions and 1 deletions

View File

@@ -22,7 +22,7 @@ function normal_update()
quit() quit()
end end
if btnp(KEY_F2) then if btnp(KEY_F2) or mbtnp(1) then
local val = zoom() + 2 local val = zoom() + 2
if val >= 10 then val = 2 end if val >= 10 then val = 2 end
zoom(val) zoom(val)

View File

@@ -496,6 +496,12 @@ extern "C" {
return 1; 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) { static int cpp_time(lua_State *L) {
lua_pushnumber(L, time()); lua_pushnumber(L, time());
return 1; return 1;
@@ -833,6 +839,7 @@ void push_lua_funcs() {
lua_pushcfunction(L,cpp_mousey); lua_setglobal(L, "mousey"); lua_pushcfunction(L,cpp_mousey); lua_setglobal(L, "mousey");
lua_pushcfunction(L,cpp_mwheel); lua_setglobal(L, "mwheel"); lua_pushcfunction(L,cpp_mwheel); lua_setglobal(L, "mwheel");
lua_pushcfunction(L,cpp_mbtn); lua_setglobal(L, "mbtn"); 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_time); lua_setglobal(L, "time");
lua_pushcfunction(L,cpp_abs); lua_setglobal(L, "abs"); lua_pushcfunction(L,cpp_abs); lua_setglobal(L, "abs");

View File

@@ -79,6 +79,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;
SDL_GameController *gamepad = NULL; SDL_GameController *gamepad = NULL;
int8_t pad_just_pressed = SDL_CONTROLLER_BUTTON_INVALID; int8_t pad_just_pressed = SDL_CONTROLLER_BUTTON_INVALID;
@@ -274,6 +275,7 @@ int main(int argc,char*argv[]){
Uint32 dt=SDL_GetTicks(); Uint32 dt=SDL_GetTicks();
key_just_pressed = 0; key_just_pressed = 0;
pad_just_pressed = SDL_CONTROLLER_BUTTON_INVALID; pad_just_pressed = SDL_CONTROLLER_BUTTON_INVALID;
mouse_just_pressed = 0;
while(!should_exit) { while(!should_exit) {
mouse_wheel = 0; mouse_wheel = 0;
while(SDL_PollEvent(&mini_eve)) { while(SDL_PollEvent(&mini_eve)) {
@@ -311,6 +313,9 @@ int main(int argc,char*argv[]){
key_just_pressed = mini_eve.key.keysym.scancode; key_just_pressed = mini_eve.key.keysym.scancode;
#endif #endif
} }
if (mini_eve.type == SDL_MOUSEBUTTONUP) {
mouse_just_pressed = mini_eve.button.button;
}
if (mini_eve.type == SDL_MOUSEWHEEL) { if (mini_eve.type == SDL_MOUSEWHEEL) {
mouse_wheel = mini_eve.wheel.y; mouse_wheel = mini_eve.wheel.y;
} }
@@ -330,6 +335,7 @@ int main(int argc,char*argv[]){
loop(); loop();
} }
key_just_pressed = 0; key_just_pressed = 0;
mouse_just_pressed = 0;
pad_just_pressed = SDL_CONTROLLER_BUTTON_INVALID; pad_just_pressed = SDL_CONTROLLER_BUTTON_INVALID;
} }
SDL_LockTexture(mini_bak, NULL, (void**)&pixels, &pitch); SDL_LockTexture(mini_bak, NULL, (void**)&pixels, &pitch);
@@ -929,6 +935,10 @@ bool mbtn(uint8_t i) {
return mouse_buttons & SDL_BUTTON(i); return mouse_buttons & SDL_BUTTON(i);
} }
bool mbtnp(uint8_t i) {
return mouse_just_pressed == i;
}
float time() { float time() {
return float(SDL_GetTicks())/1000.0f; return float(SDL_GetTicks())/1000.0f;
} }

1
mini.h
View File

@@ -212,6 +212,7 @@ int mousex();
int mousey(); int mousey();
int mwheel(); int mwheel();
bool mbtn(uint8_t i); bool mbtn(uint8_t i);
bool mbtnp(uint8_t i);
float time(); float time();