pull request review
This commit is contained in:
@@ -768,33 +768,33 @@ LC_NUMBER2(LINES, LINES)
|
|||||||
static int
|
static int
|
||||||
lc_ungetmouse(lua_State *L)
|
lc_ungetmouse(lua_State *L)
|
||||||
{
|
{
|
||||||
MEVENT e;
|
MEVENT e;
|
||||||
e.bstate = luaL_checklong(L, 1);
|
e.bstate = luaL_checklong(L, 1);
|
||||||
e.x = luaL_checkint(L, 2);
|
e.x = luaL_checkint(L, 2);
|
||||||
e.y = luaL_checkint(L, 3);
|
e.y = luaL_checkint(L, 3);
|
||||||
e.z = luaL_checkint(L, 4);
|
e.z = luaL_checkint(L, 4);
|
||||||
e.id = luaL_checkint(L, 5);
|
e.id = luaL_checkint(L, 5);
|
||||||
|
|
||||||
lua_pushboolean(L, !(!ungetmouse(&e)));
|
lua_pushboolean(L, !(!ungetmouse(&e)));
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int
|
||||||
lc_getmouse(lua_State *L)
|
lc_getmouse(lua_State *L)
|
||||||
{
|
{
|
||||||
MEVENT e;
|
MEVENT e;
|
||||||
if(getmouse(&e) == OK)
|
if (getmouse(&e) == OK)
|
||||||
{
|
{
|
||||||
lua_pushinteger(L, e.bstate);
|
lua_pushinteger(L, e.bstate);
|
||||||
lua_pushinteger(L, e.x);
|
lua_pushinteger(L, e.x);
|
||||||
lua_pushinteger(L, e.y);
|
lua_pushinteger(L, e.y);
|
||||||
lua_pushinteger(L, e.z);
|
lua_pushinteger(L, e.z);
|
||||||
lua_pushinteger(L, e.id);
|
lua_pushinteger(L, e.id);
|
||||||
return 5;
|
return 5;
|
||||||
}
|
}
|
||||||
|
|
||||||
lua_pushnil(L);
|
lua_pushnil(L);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int
|
||||||
|
@@ -76,6 +76,12 @@ event:register("cm_max", "cm_quit", "cm_exit", "cm_enter")
|
|||||||
--
|
--
|
||||||
event.keyboard = object {_init = { "key_code", "key_name", "key_meta" }, type = event.ev_keyboard}
|
event.keyboard = object {_init = { "key_code", "key_name", "key_meta" }, type = event.ev_keyboard}
|
||||||
|
|
||||||
|
-- define mouse event
|
||||||
|
--
|
||||||
|
-- btn_name = button number and event type
|
||||||
|
-- btn_code = mouse event code
|
||||||
|
-- x, y = coordinates
|
||||||
|
--
|
||||||
event.mouse = object {_init = { "btn_code", "x", "y", "btn_name" }, type = event.ev_mouse}
|
event.mouse = object {_init = { "btn_code", "x", "y", "btn_name" }, type = event.ev_mouse}
|
||||||
|
|
||||||
-- define command event
|
-- define command event
|
||||||
|
@@ -141,15 +141,9 @@ function program:event()
|
|||||||
local key_code, key_name, key_meta = self:_input_key()
|
local key_code, key_name, key_meta = self:_input_key()
|
||||||
if key_code then
|
if key_code then
|
||||||
if curses.KEY_MOUSE and key_code == curses.KEY_MOUSE then
|
if curses.KEY_MOUSE and key_code == curses.KEY_MOUSE then
|
||||||
local s, x, y = curses.getmouse()
|
local code, x, y = curses.getmouse()
|
||||||
local name
|
local name = self:_mouse_map()[code]
|
||||||
for n, v in pairs(curses) do
|
return event.mouse{code, x, y, name}
|
||||||
if v == s and n:match('BUTTON') then
|
|
||||||
name = n or name
|
|
||||||
break
|
|
||||||
end
|
|
||||||
end
|
|
||||||
return event.mouse{s, x, y, name}
|
|
||||||
end
|
end
|
||||||
return event.keyboard{key_code, key_name, key_meta}
|
return event.keyboard{key_code, key_name, key_meta}
|
||||||
end
|
end
|
||||||
@@ -349,6 +343,20 @@ function program:_key_map()
|
|||||||
return self._KEYMAP
|
return self._KEYMAP
|
||||||
end
|
end
|
||||||
|
|
||||||
|
-- get mouse map
|
||||||
|
function program:_mouse_map()
|
||||||
|
if not self._MOUSEMAP then
|
||||||
|
-- must be defined dynamically since it depends
|
||||||
|
-- on curses implementation
|
||||||
|
self._MOUSEMAP = {}
|
||||||
|
for n, v in pairs(curses) do
|
||||||
|
if n:match('MOUSE') and n ~= 'KEY_MOUSE' or n:match('BUTTON') then
|
||||||
|
self._MOUSEMAP[v] = n
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
return self._MOUSEMAP
|
||||||
|
end
|
||||||
-- get input key
|
-- get input key
|
||||||
function program:_input_key()
|
function program:_input_key()
|
||||||
|
|
||||||
@@ -415,6 +423,7 @@ function program:_input_key()
|
|||||||
end
|
end
|
||||||
|
|
||||||
-- return key info
|
-- return key info
|
||||||
|
|
||||||
return ch, key_name, alt
|
return ch, key_name, alt
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@@ -16,10 +16,10 @@
|
|||||||
-- See the License for the specific language governing permissions and
|
-- See the License for the specific language governing permissions and
|
||||||
-- limitations under the License.
|
-- limitations under the License.
|
||||||
--
|
--
|
||||||
-- Copyright (C) 2015-2020, TBOOX Open Source Group.
|
-- Copyright (C) 2020, TBOOX Open Source Group.
|
||||||
--
|
--
|
||||||
-- @author ruki
|
-- @author Lael N. Santos
|
||||||
-- @file window.lua
|
-- @file events.lua
|
||||||
--
|
--
|
||||||
require("tests/load")
|
require("tests/load")
|
||||||
|
|
||||||
@@ -75,7 +75,7 @@ end
|
|||||||
-- on event
|
-- on event
|
||||||
function demo:on_event(e)
|
function demo:on_event(e)
|
||||||
if e.type < event.ev_max then
|
if e.type < event.ev_max then
|
||||||
self:teste():text_set('tp: ' ..
|
self:teste():text_set('type: ' ..
|
||||||
tostring(e.type) ..
|
tostring(e.type) ..
|
||||||
'; name: ' ..
|
'; name: ' ..
|
||||||
tostring(e.key_name or e.btn_name) ..
|
tostring(e.key_name or e.btn_name) ..
|
Reference in New Issue
Block a user