From 61301a96d309fe2deef0d0dc2e2bc2f3d4003bf9 Mon Sep 17 00:00:00 2001 From: chai Date: Sat, 28 Jul 2018 09:58:37 +0800 Subject: *update --- src/lua/event/luaopen_event.cpp | 27 +++++---------------------- src/lua/filesystem/luaopen_filesystem.cpp | 2 +- src/lua/graphics/luaopen_graphics.cpp | 4 ++-- src/lua/mouse/luaopen_mouse.cpp | 8 ++++++-- 4 files changed, 14 insertions(+), 27 deletions(-) (limited to 'src/lua') diff --git a/src/lua/event/luaopen_event.cpp b/src/lua/event/luaopen_event.cpp index 2d1e52f..a53863d 100644 --- a/src/lua/event/luaopen_event.cpp +++ b/src/lua/event/luaopen_event.cpp @@ -4,28 +4,12 @@ #include "lua/luax.h" #include "libjin/jin.h" -using namespace jin::input; - namespace jin { namespace lua { - static inline const char* buttonstr(int id) { - switch (id) { - case 1: return "left"; - case 2: return "middle"; - case 3: return "right"; - case 4: return "wheelup"; - case 5: return "wheeldown"; - default: return "?"; - } - } - - static inline const char* wheelstr(int dir) - { - - } + using namespace jin::input; /** * Load event poll, return a iterator(a table). @@ -49,12 +33,12 @@ namespace lua case EventType::KEYDOWN: luax_setfield_string(L, "type", "keydown"); - luax_setfield_string(L, "key", SDL_GetKeyName(e.key.keysym.sym)); + luax_setfield_string(L, "key", getKeyName(e.key.keysym.sym)); break; case EventType::KEYUP: luax_setfield_string(L, "type", "keyup"); - luax_setfield_string(L, "key", SDL_GetKeyName(e.key.keysym.sym)); + luax_setfield_string(L, "key", getKeyName(e.key.keysym.sym)); break; case EventType::MOUSEMOTION: @@ -65,14 +49,14 @@ namespace lua case EventType::MOUSEBUTTONDOWN: luax_setfield_string(L, "type", "mousebuttondown"); - luax_setfield_string(L, "button", buttonstr(e.button.button)); + luax_setfield_string(L, "button", getButtonName(e.button.button)); luax_setfield_number(L, "x", e.button.x); luax_setfield_number(L, "y", e.button.y); break; case EventType::MOUSEBUTTONUP: luax_setfield_string(L, "type", "mousebuttonup"); - luax_setfield_string(L, "button", buttonstr(e.button.button)); + luax_setfield_string(L, "button", getButtonName(e.button.button)); luax_setfield_number(L, "x", e.button.x); luax_setfield_number(L, "y", e.button.y); break; @@ -85,7 +69,6 @@ namespace lua luax_setfield_string(L, "x", "right"); else luax_setfield_string(L, "x", "none"); - if (e.wheel.y == -1) luax_setfield_string(L, "y", "near"); else if (e.wheel.y == 1) diff --git a/src/lua/filesystem/luaopen_filesystem.cpp b/src/lua/filesystem/luaopen_filesystem.cpp index db0216b..3a19f12 100644 --- a/src/lua/filesystem/luaopen_filesystem.cpp +++ b/src/lua/filesystem/luaopen_filesystem.cpp @@ -2,7 +2,7 @@ #include "libjin/jin.h" #include -using namespace jin::fs; +using namespace jin::filesystem; namespace jin { diff --git a/src/lua/graphics/luaopen_graphics.cpp b/src/lua/graphics/luaopen_graphics.cpp index f0bae67..5cd0c8d 100644 --- a/src/lua/graphics/luaopen_graphics.cpp +++ b/src/lua/graphics/luaopen_graphics.cpp @@ -7,8 +7,8 @@ namespace jin { namespace lua { - using namespace render; - using namespace fs; + using namespace jin::render; + using namespace jin::filesystem; /** * jin.graphics context, storge some module diff --git a/src/lua/mouse/luaopen_mouse.cpp b/src/lua/mouse/luaopen_mouse.cpp index a013f3d..eb6a779 100644 --- a/src/lua/mouse/luaopen_mouse.cpp +++ b/src/lua/mouse/luaopen_mouse.cpp @@ -1,13 +1,17 @@ #include "lua/luax.h" -#include "SDL2/SDL.h" +#include "libjin/jin.h" + namespace jin { namespace lua { + using namespace jin::input; + static int l_pos(lua_State* L) { + static Mouse* mouse = Mouse::get(); int x, y; - SDL_GetMouseState(&x, &y); + mouse->getState(&x, &y); luax_pushnumber(L, x); luax_pushnumber(L, y); return 2; -- cgit v1.1-26-g67d0