Skip to content

Mouse support#15

Merged
waruqi merged 7 commits intotboox:devfrom
laelnasan:mouse_support
Oct 6, 2020
Merged

Mouse support#15
waruqi merged 7 commits intotboox:devfrom
laelnasan:mouse_support

Conversation

@laelnasan
Copy link
Copy Markdown
Contributor

  • Before adding new features and new modules, please go to issues to submit the relevant feature description first.
  • Write good commit messages and use the same coding conventions as the rest of the project.
  • Please commit code to dev branch and we will merge into master branch in feature
  • Ensure your edited codes with four spaces instead of TAB.

  • 增加新特性和新模块之前,请先到issues提交相关特性说明,经过讨论评估确认后,再进行相应的代码提交,避免做无用工作。
  • 编写友好可读的提交信息,并使用与工程代码相同的代码规范,代码请用4个空格字符代替tab缩进。
  • 请提交代码到dev分支,如果通过,我们会在特定时间合并到master分支上。
  • 为了规范化提交日志的格式,commit消息,不要用中文,请用英文描述。

If there is a curses library with support to mouse the `curses.KEY_MOUSE` constant
will be defined with other constants and functions.
-- Copyright (C) 2015-2020, TBOOX Open Source Group.
--
-- @author ruki
-- @file window.lua
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please modify file name and author.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And rename getch_test.lua to event.lua, all scripts in the tests directory are test cases, no need to add _test

function demo:on_event(e)
if e.type < event.ev_max then
self:teste():text_set('tp: ' ..
tostring(e.type) ..
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please use 4 whilte spaces instead of all tab characters.

local name
for n, v in pairs(curses) do
if v == s and n:match('BUTTON') then
name = n or name
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we need only name = n

--
event.keyboard = object {_init = { "key_code", "key_name", "key_meta" }, type = event.ev_keyboard}

event.mouse = object {_init = { "btn_code", "x", "y", "btn_name" }, type = event.ev_mouse}
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add some comments

e.y = luaL_checkint(L, 3);
e.z = luaL_checkint(L, 4);
e.id = luaL_checkint(L, 5);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please use 4 whilte spaces instead of all tab characters.

lc_getmouse(lua_State *L)
{
MEVENT e;
if(getmouse(&e) == OK)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if (

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
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that you should use map to avoid for-loop. like program:_key_map()

we can add program:_mouse_map() and get name from this map.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for your comments. Will do ASAP

MEVENT e;
e.bstate = luaL_checklong(L, 1);
e.x = luaL_checkint(L, 2);
e.y = luaL_checkint(L, 3);
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No indentation?

return 5;
}
MEVENT e;
if (getmouse(&e) == OK)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

and here.

-- 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
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if (a and b) or c then

if (n:match('MOUSE') and n ~= 'KEY_MOUSE') or n:match('BUTTON') then

@waruqi waruqi merged commit edc266a into tboox:dev Oct 6, 2020
@waruqi
Copy link
Copy Markdown
Member

waruqi commented Oct 6, 2020

I have merged it. Thanks!

@laelnasan
Copy link
Copy Markdown
Contributor Author

Thanks! And sorry for the trouble I may have caused. Really happy for being able to contribute, though.
Regards!

@waruqi waruqi mentioned this pull request Oct 6, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants