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