mouse up events

This commit is contained in:
kepler155c@gmail.com 2017-05-25 21:06:17 -04:00
parent e6ee432997
commit 10cd1509fb
5 changed files with 91 additions and 53 deletions

View File

@ -75,6 +75,7 @@ local Manager = class()
function Manager:init(args)
local control = false
local shift = false
local mouseDragged = false
local pages = { }
Event.addHandler('term_resize', function(h, side)
@ -117,11 +118,25 @@ function Manager:init(args)
Event.addHandler('mouse_click', function(h, button, x, y)
if button == 1 and shift and control then -- hack
mouseDragged = false
if button == 1 and shift and control then -- debug hack
local event = self:pointToChild(self.target, x, y)
multishell.openTab({ path = 'sys/apps/Lua.lua', args = { event.element }, focused = true })
elseif self.currentPage then
if not self.currentPage.parent.device.side then
local event = self:pointToChild(self.target, x, y)
if event.element.focus then
self.currentPage:setFocus(event.element)
self.currentPage:sync()
end
end
end
end)
Event.addHandler('mouse_up', function(h, button, x, y)
if self.currentPage and not mouseDragged then
if not self.currentPage.parent.device.side then
self:click(button, x, y)
end
@ -130,6 +145,7 @@ function Manager:init(args)
Event.addHandler('mouse_drag', function(h, button, x, y)
mouseDragged = true
if self.target then
local event = self:pointToChild(self.target, x, y)
@ -3334,7 +3350,7 @@ function UI.NftImage:setImage(image)
end
UI:loadTheme('usr/config/ui.theme')
if os.getVersion() >= 1.79 then
if os.getVersion and os.getVersion() >= 1.79 then
UI:loadTheme('sys/etc/ext.theme')
end

View File

@ -11,7 +11,7 @@ UI:configure('Turtles', ...)
local options = {
turtle = { arg = 'i', type = 'number', value = -1,
desc = 'Turtle ID' },
tab = { arg = 's', type = 'string', value = 'inventory',
tab = { arg = 's', type = 'string', value = 'turtles',
desc = 'Selected tab to display' },
help = { arg = 'h', type = 'flag', value = false,
desc = 'Displays the options' },
@ -22,6 +22,7 @@ local SYS_SCRIPTS_PATH = 'sys/etc/scripts'
local nullTerm = Terminal.getNullTerm(term.current())
local turtles = { }
local socket
local policies = {
{ label = 'none' },
{ label = 'digOnly' },
@ -37,36 +38,6 @@ local itemInfoDB = TableDB({
itemInfoDB:load()
local page = UI.Page {
moveUp = UI.Button {
x = 5, y = 2,
text = '/\\',
fn = 'turtle.up',
},
moveDown = UI.Button {
x = 5, y = 4,
text = '\\/',
fn = 'turtle.down',
},
moveForward = UI.Button {
x = 9, y = 3,
text = '>',
fn = 'turtle.forward',
},
moveBack = UI.Button {
x = 2, y = 3,
text = '<',
fn = 'turtle.back',
},
turnLeft = UI.Button {
x = 2, y = 6,
text = '<-',
fn = 'turtle.turnLeft',
},
turnRight = UI.Button {
x = 8, y = 6,
text = '->',
fn = 'turtle.turnRight',
},
--[[
policy = UI.Chooser {
x = 2, y = 8,
@ -77,10 +48,10 @@ local page = UI.Page {
},
]]
coords = UI.Window {
x = 14, y = 2, height = 5, rex = -2,
x = 2, y = 2, height = 3, rex = -2,
},
tabs = UI.Tabs {
x = 1, y = 8, rey = -2,
x = 1, y = 5, rey = -2,
scripts = UI.Grid {
tabTitle = 'Run',
backgroundColor = UI.TabBar.defaults.selectedBackgroundColor,
@ -108,8 +79,9 @@ local page = UI.Page {
backgroundColor = UI.TabBar.defaults.selectedBackgroundColor,
tabTitle = 'Inv',
columns = {
{ heading = '', key = 'index', width = 2 },
{ heading = '', key = 'qty', width = 2 },
{ heading = 'Inventory', key = 'id', width = UI.term.width - 5 },
{ heading = 'Inventory', key = 'id', width = UI.term.width - 7 },
},
disableHeader = true,
sortColumn = 'index',
@ -125,6 +97,39 @@ local page = UI.Page {
sortColumn = 'label',
autospace = true,
},
action = UI.Window {
tabTitle = 'Act',
moveUp = UI.Button {
x = 5, y = 2,
text = '/\\',
fn = 'turtle.up',
},
moveDown = UI.Button {
x = 5, y = 4,
text = '\\/',
fn = 'turtle.down',
},
moveForward = UI.Button {
x = 9, y = 3,
text = '>',
fn = 'turtle.forward',
},
moveBack = UI.Button {
x = 2, y = 3,
text = '<',
fn = 'turtle.back',
},
turnLeft = UI.Button {
x = 2, y = 6,
text = '<-',
fn = 'turtle.turnLeft',
},
turnRight = UI.Button {
x = 8, y = 6,
text = '->',
fn = 'turtle.turnRight',
},
},
},
statusBar = UI.StatusBar(),
notification = UI.Notification(),
@ -139,18 +144,18 @@ function page:enable(turtle)
end
function page:runFunction(script, nowrap)
local socket = Socket.connect(self.turtle.id, 161)
if not socket then
self.notification:error('Unable to connect')
return
socket = Socket.connect(self.turtle.id, 161)
if not socket then
self.notification:error('Unable to connect')
return
end
end
if not nowrap then
script = 'turtle.run(' .. script .. ')'
end
socket:write({ type = 'script', args = script })
socket:close()
end
function page:runScript(scriptName)
@ -167,8 +172,12 @@ function page.coords:draw()
if t then
self:clear()
self:setCursorPos(1, 1)
self:print(string.format('%s\nx: %d\ny: %d\nz: %d\nFuel: %s\n',
t.coordSystem, t.point.x, t.point.y, t.point.z, Util.toBytes(t.fuel)))
local ind = 'GPS'
if t.coordSystem ~= 'GPS' then
ind = 'REL'
end
self:print(string.format('%s : %d,%d,%d\nFuel: %s\n',
ind, t.point.x, t.point.y, t.point.z, Util.toBytes(t.fuel)))
end
end
@ -274,6 +283,10 @@ end
function page.tabs.turtles:eventHandler(event)
if event.type == 'grid_select' then
page.turtle = event.selected
if socket then
socket:close()
socket = nil
end
else
return UI.Grid.eventHandler(self, event)
end

View File

@ -513,6 +513,8 @@ end
draw()
local lastClicked
while true do
-- Get the event
@ -552,6 +554,7 @@ while true do
elseif sEvent == "mouse_click" then
local button, x, y = tEventData[1], tEventData[2], tEventData[3]
lastClicked = nil
if y == 1 and os.locked then
-- ignore
elseif y == 1 then
@ -575,6 +578,13 @@ while true do
end
elseif currentTab then
-- Passthrough to current process
lastClicked = currentTab
resumeTab(currentTab, sEvent, { button, x, y-1 })
end
elseif sEvent == "mouse_up" then
if currentTab and lastClicked == currentTab then
local button, x, y = tEventData[1], tEventData[2], tEventData[3]
resumeTab(currentTab, sEvent, { button, x, y-1 })
end

View File

@ -52,7 +52,8 @@ ct.clear()
ct.setCursorPos(1, 1)
local filter = Util.transpose({
'char', 'paste', 'key', 'key_up', 'mouse_scroll', 'mouse_click', 'mouse_drag',
'char', 'paste', 'key', 'key_up',
'mouse_scroll', 'mouse_click', 'mouse_drag', 'mouse_up',
})
while true do

View File

@ -54,6 +54,11 @@ end)
ct.clear()
ct.setCursorPos(1, 1)
local filter = Util.transpose({
'char', 'paste', 'key', 'key_up',
'mouse_scroll', 'mouse_click', 'mouse_drag', 'mouse_up',
})
while true do
local e = { process:pullEvent() }
local event = e[1]
@ -66,14 +71,7 @@ while true do
break
end
if event == 'char' or
event == 'paste' or
event == 'key' or
event == 'key_up' or
event == 'mouse_scroll' or
event == 'mouse_click' or
event == 'mouse_drag' then
if filter[event] then
socket:write({
type = 'shellRemote',
event = e,
@ -85,4 +83,4 @@ while true do
ct.setCursorPos(1, 1)
break
end
end
end