mirror of
				https://github.com/kepler155c/opus
				synced 2025-10-31 15:43:00 +00:00 
			
		
		
		
	mouse up events
This commit is contained in:
		| @@ -75,6 +75,7 @@ local Manager = class() | |||||||
| function Manager:init(args) | function Manager:init(args) | ||||||
|   local control = false |   local control = false | ||||||
|   local shift = false |   local shift = false | ||||||
|  |   local mouseDragged = false | ||||||
|   local pages = { } |   local pages = { } | ||||||
|  |  | ||||||
|   Event.addHandler('term_resize', function(h, side) |   Event.addHandler('term_resize', function(h, side) | ||||||
| @@ -117,11 +118,25 @@ function Manager:init(args) | |||||||
|  |  | ||||||
|   Event.addHandler('mouse_click', function(h, button, x, y) |   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) |       local event = self:pointToChild(self.target, x, y) | ||||||
|       multishell.openTab({ path = 'sys/apps/Lua.lua', args = { event.element }, focused = true }) |       multishell.openTab({ path = 'sys/apps/Lua.lua', args = { event.element }, focused = true }) | ||||||
|  |  | ||||||
|     elseif self.currentPage then |     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 |       if not self.currentPage.parent.device.side then | ||||||
|         self:click(button, x, y) |         self:click(button, x, y) | ||||||
|       end |       end | ||||||
| @@ -130,6 +145,7 @@ function Manager:init(args) | |||||||
|  |  | ||||||
|   Event.addHandler('mouse_drag', function(h, button, x, y) |   Event.addHandler('mouse_drag', function(h, button, x, y) | ||||||
|  |  | ||||||
|  |     mouseDragged = true | ||||||
|     if self.target then |     if self.target then | ||||||
|       local event = self:pointToChild(self.target, x, y) |       local event = self:pointToChild(self.target, x, y) | ||||||
|  |  | ||||||
| @@ -3334,7 +3350,7 @@ function UI.NftImage:setImage(image) | |||||||
| end | end | ||||||
|  |  | ||||||
| UI:loadTheme('usr/config/ui.theme') | 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') |   UI:loadTheme('sys/etc/ext.theme') | ||||||
| end | end | ||||||
|  |  | ||||||
|   | |||||||
| @@ -11,7 +11,7 @@ UI:configure('Turtles', ...) | |||||||
| local options = { | local options = { | ||||||
|   turtle      = { arg = 'i', type = 'number', value = -1, |   turtle      = { arg = 'i', type = 'number', value = -1, | ||||||
|                  desc = 'Turtle ID' }, |                  desc = 'Turtle ID' }, | ||||||
|   tab         = { arg = 's', type = 'string', value = 'inventory', |   tab         = { arg = 's', type = 'string', value = 'turtles', | ||||||
|                  desc = 'Selected tab to display' }, |                  desc = 'Selected tab to display' }, | ||||||
|   help        = { arg = 'h', type = 'flag',   value = false, |   help        = { arg = 'h', type = 'flag',   value = false, | ||||||
|                  desc = 'Displays the options' }, |                  desc = 'Displays the options' }, | ||||||
| @@ -22,6 +22,7 @@ local SYS_SCRIPTS_PATH = 'sys/etc/scripts' | |||||||
|  |  | ||||||
| local nullTerm = Terminal.getNullTerm(term.current()) | local nullTerm = Terminal.getNullTerm(term.current()) | ||||||
| local turtles = { } | local turtles = { } | ||||||
|  | local socket | ||||||
| local policies = {  | local policies = {  | ||||||
|   { label = 'none' }, |   { label = 'none' }, | ||||||
|   { label = 'digOnly' }, |   { label = 'digOnly' }, | ||||||
| @@ -37,36 +38,6 @@ local itemInfoDB = TableDB({ | |||||||
| itemInfoDB:load() | itemInfoDB:load() | ||||||
|  |  | ||||||
| local page = UI.Page { | 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 { |   policy = UI.Chooser { | ||||||
|     x = 2, y = 8, |     x = 2, y = 8, | ||||||
| @@ -77,10 +48,10 @@ local page = UI.Page { | |||||||
|   }, |   }, | ||||||
| ]] | ]] | ||||||
|   coords = UI.Window { |   coords = UI.Window { | ||||||
|     x = 14, y = 2, height = 5, rex = -2, |     x = 2, y = 2, height = 3, rex = -2, | ||||||
|   }, |   }, | ||||||
|   tabs = UI.Tabs { |   tabs = UI.Tabs { | ||||||
|     x = 1, y = 8, rey = -2, |     x = 1, y = 5, rey = -2, | ||||||
|     scripts = UI.Grid { |     scripts = UI.Grid { | ||||||
|       tabTitle = 'Run', |       tabTitle = 'Run', | ||||||
|       backgroundColor = UI.TabBar.defaults.selectedBackgroundColor, |       backgroundColor = UI.TabBar.defaults.selectedBackgroundColor, | ||||||
| @@ -108,8 +79,9 @@ local page = UI.Page { | |||||||
|       backgroundColor = UI.TabBar.defaults.selectedBackgroundColor, |       backgroundColor = UI.TabBar.defaults.selectedBackgroundColor, | ||||||
|       tabTitle = 'Inv', |       tabTitle = 'Inv', | ||||||
|       columns = { |       columns = { | ||||||
|  |         { heading = '',          key = 'index', width = 2 }, | ||||||
|         { heading = '',          key = 'qty', 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, |       disableHeader = true, | ||||||
|       sortColumn = 'index', |       sortColumn = 'index', | ||||||
| @@ -125,6 +97,39 @@ local page = UI.Page { | |||||||
|       sortColumn = 'label', |       sortColumn = 'label', | ||||||
|       autospace = true, |       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(), |   statusBar = UI.StatusBar(), | ||||||
|   notification = UI.Notification(), |   notification = UI.Notification(), | ||||||
| @@ -139,18 +144,18 @@ function page:enable(turtle) | |||||||
| end | end | ||||||
|  |  | ||||||
| function page:runFunction(script, nowrap) | function page:runFunction(script, nowrap) | ||||||
|  |  | ||||||
|   local socket = Socket.connect(self.turtle.id, 161) |  | ||||||
|   if not socket then |   if not socket then | ||||||
|     self.notification:error('Unable to connect') |     socket = Socket.connect(self.turtle.id, 161) | ||||||
|     return |     if not socket then | ||||||
|  |       self.notification:error('Unable to connect') | ||||||
|  |       return | ||||||
|  |     end | ||||||
|   end |   end | ||||||
|  |  | ||||||
|   if not nowrap then |   if not nowrap then | ||||||
|     script = 'turtle.run(' .. script .. ')' |     script = 'turtle.run(' .. script .. ')' | ||||||
|   end |   end | ||||||
|   socket:write({ type = 'script', args = script }) |   socket:write({ type = 'script', args = script }) | ||||||
|   socket:close() |  | ||||||
| end | end | ||||||
|  |  | ||||||
| function page:runScript(scriptName) | function page:runScript(scriptName) | ||||||
| @@ -167,8 +172,12 @@ function page.coords:draw() | |||||||
|   if t then |   if t then | ||||||
|     self:clear() |     self:clear() | ||||||
|     self:setCursorPos(1, 1) |     self:setCursorPos(1, 1) | ||||||
|     self:print(string.format('%s\nx: %d\ny: %d\nz: %d\nFuel: %s\n',  |     local ind = 'GPS' | ||||||
|       t.coordSystem, t.point.x, t.point.y, t.point.z, Util.toBytes(t.fuel))) |     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 | ||||||
| end | end | ||||||
|  |  | ||||||
| @@ -274,6 +283,10 @@ end | |||||||
| function page.tabs.turtles:eventHandler(event) | function page.tabs.turtles:eventHandler(event) | ||||||
|   if event.type == 'grid_select' then |   if event.type == 'grid_select' then | ||||||
|     page.turtle = event.selected |     page.turtle = event.selected | ||||||
|  |     if socket then | ||||||
|  |       socket:close() | ||||||
|  |       socket = nil | ||||||
|  |     end | ||||||
|   else |   else | ||||||
|     return UI.Grid.eventHandler(self, event) |     return UI.Grid.eventHandler(self, event) | ||||||
|   end |   end | ||||||
|   | |||||||
| @@ -513,6 +513,8 @@ end | |||||||
|  |  | ||||||
| draw() | draw() | ||||||
|  |  | ||||||
|  | local lastClicked | ||||||
|  |  | ||||||
| while true do | while true do | ||||||
|  |  | ||||||
|   -- Get the event |   -- Get the event | ||||||
| @@ -552,6 +554,7 @@ while true do | |||||||
|    |    | ||||||
|   elseif sEvent == "mouse_click" then |   elseif sEvent == "mouse_click" then | ||||||
|     local button, x, y = tEventData[1], tEventData[2], tEventData[3] |     local button, x, y = tEventData[1], tEventData[2], tEventData[3] | ||||||
|  |     lastClicked = nil | ||||||
|     if y == 1 and os.locked then |     if y == 1 and os.locked then | ||||||
|       -- ignore |       -- ignore | ||||||
|     elseif y == 1 then |     elseif y == 1 then | ||||||
| @@ -575,6 +578,13 @@ while true do | |||||||
|       end |       end | ||||||
|     elseif currentTab then |     elseif currentTab then | ||||||
|       -- Passthrough to current process |       -- 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 }) |       resumeTab(currentTab, sEvent, { button, x, y-1 }) | ||||||
|     end |     end | ||||||
|  |  | ||||||
|   | |||||||
| @@ -52,7 +52,8 @@ ct.clear() | |||||||
| ct.setCursorPos(1, 1) | ct.setCursorPos(1, 1) | ||||||
|  |  | ||||||
| local filter = Util.transpose({ | 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 | while true do | ||||||
|   | |||||||
| @@ -54,6 +54,11 @@ end) | |||||||
| ct.clear() | ct.clear() | ||||||
| ct.setCursorPos(1, 1) | ct.setCursorPos(1, 1) | ||||||
|  |  | ||||||
|  | local filter = Util.transpose({ | ||||||
|  |   'char', 'paste', 'key', 'key_up',  | ||||||
|  |   'mouse_scroll', 'mouse_click', 'mouse_drag', 'mouse_up', | ||||||
|  | }) | ||||||
|  |  | ||||||
| while true do | while true do | ||||||
|   local e = { process:pullEvent() } |   local e = { process:pullEvent() } | ||||||
|   local event = e[1] |   local event = e[1] | ||||||
| @@ -66,14 +71,7 @@ while true do | |||||||
|     break |     break | ||||||
|   end |   end | ||||||
|  |  | ||||||
|   if event == 'char' or  |   if filter[event] then | ||||||
|      event == 'paste' or  |  | ||||||
|      event == 'key' or |  | ||||||
|      event == 'key_up' or |  | ||||||
|      event == 'mouse_scroll' or |  | ||||||
|      event == 'mouse_click' or |  | ||||||
|      event == 'mouse_drag' then |  | ||||||
|  |  | ||||||
|     socket:write({ |     socket:write({ | ||||||
|       type = 'shellRemote', |       type = 'shellRemote', | ||||||
|       event = e, |       event = e, | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user
	 kepler155c@gmail.com
					kepler155c@gmail.com