diff --git a/Applications/3D Print.app/Main.lua b/Applications/3D Print.app/Main.lua index 45c073e2..ed562c3d 100644 --- a/Applications/3D Print.app/Main.lua +++ b/Applications/3D Print.app/Main.lua @@ -533,10 +533,14 @@ toolLayout.eventHandler = function(workspace, toolLayout, e1, e2, e3, e4, e5) end local shapeX, shapeY, shapeZ + view.eventHandler = function(workspace, view, e1, e2, e3, e4, e5) if e1 == "touch" or e1 == "drag" then + e3, e4 = math.ceil(e3), math.ceil(e4) + if e5 == 0 then local selectedShape = getSelectedShapeIndex() + if selectedShape then local shape = model.shapes[selectedShape] local x = math.floor((e3 - view.x) / view.width * 16) @@ -546,6 +550,7 @@ view.eventHandler = function(workspace, view, e1, e2, e3, e4, e5) shapeX, shapeY, shapeZ = x, y, currentLayer shape[1], shape[2], shape[3] = x, y, currentLayer shape[4], shape[5], shape[6] = x + 1, y + 1, currentLayer + 1 + elseif shapeX then shape[1], shape[2], shape[3] = shapeX, shapeY, shapeZ shape[4], shape[5], shape[6] = x, y, currentLayer @@ -562,6 +567,7 @@ view.eventHandler = function(workspace, view, e1, e2, e3, e4, e5) shape = model.shapes[i] local focused, x, y, width, height = getShapeDrawingData(shape) + if focused and e3 >= x and e3 <= x + width - 1 and e4 >= y and e4 <= y + height - 1 then for j = 1, shapesComboBox:count() do if shapesComboBox:getItem(j).shapeIndex == i then diff --git a/Applications/App Market.app/Main.lua b/Applications/App Market.app/Main.lua index a1d9b08e..00ecce1d 100644 --- a/Applications/App Market.app/Main.lua +++ b/Applications/App Market.app/Main.lua @@ -788,11 +788,13 @@ local function overview() iconsContainer.eventHandler = function(workspace, object, e1, e2, e3, e4) if e1 == "touch" or e1 == "drag" then local child, deltaX, deltaY, vectorLength + for i = 1, #iconsContainer.children do child = iconsContainer.children[i] - deltaX, deltaY = e3 - child.x, e4 - child.y + deltaX, deltaY = math.ceil(e3) - child.x, math.ceil(e4) - child.y vectorLength = math.sqrt(deltaX ^ 2 + deltaY ^ 2) + if vectorLength > 0 then child.forceX = deltaX / vectorLength * math.random(overviewMaximumTouchAcceleration) child.forceY = deltaY / vectorLength * math.random(overviewMaximumTouchAcceleration) @@ -1251,7 +1253,7 @@ newPublicationInfo = function(file_id) local cyka = pizda:addChild(newRatingWidget(eblo.width + 1, 1, 4)) cyka.eventHandler = function(workspace, object, e1, e2, e3) if e1 == "touch" then - cyka.rating = number.round((e3 - object.x + 1) / object.width * 5) + cyka.rating = number.round((math.ceil(e3) - object.x + 1) / object.width * 5) workspace:draw() end end diff --git a/Applications/Finder.app/Main.lua b/Applications/Finder.app/Main.lua index d4b3461c..554db726 100644 --- a/Applications/Finder.app/Main.lua +++ b/Applications/Finder.app/Main.lua @@ -145,7 +145,7 @@ end local function sidebarItemEventHandler(workspace, object, e1, e2, e3, ...) if e1 == "touch" then - if object.onRemove and e3 == object.x + object.width - 2 then + if object.onRemove and math.ceil(e3) == object.x + object.width - 2 then object.onRemove() elseif object.onTouch then object.onTouch(e1, e2, e3, ...) diff --git a/Applications/HEX.app/Main.lua b/Applications/HEX.app/Main.lua index bb5ddd4d..273dffa5 100755 --- a/Applications/HEX.app/Main.lua +++ b/Applications/HEX.app/Main.lua @@ -105,7 +105,7 @@ end local function byteFieldEventHandler(workspace, object, e1, e2, e3, e4, e5) if e1 == "touch" or e1 == "drag" then if e5 == 1 then - local menu = GUI.addContextMenu(workspace, e3, e4) + local menu = GUI.addContextMenu(workspace, math.ceil(e3), math.ceil(e4)) menu:addItem("Select all").onTouch = function() selection.from = 1 diff --git a/Applications/MineCode IDE.app/Main.lua b/Applications/MineCode IDE.app/Main.lua index 08c49bfa..dfa85817 100755 --- a/Applications/MineCode IDE.app/Main.lua +++ b/Applications/MineCode IDE.app/Main.lua @@ -1363,7 +1363,13 @@ end local uptime = computer.uptime() codeView.eventHandler = function(workspace, object, e1, e2, e3, e4, e5) - if e1 == "touch" and checkScrollbar(e4) then + if e1 == "touch" then + e3, e4 = math.ceil(e3), math.ceil(e4) + + if not checkScrollbar(e4) then + return + end + if e5 == 1 then createEditOrRightClickMenu(GUI.addContextMenu(workspace, e3, e4)) else @@ -1371,10 +1377,18 @@ codeView.eventHandler = function(workspace, object, e1, e2, e3, e4, e5) end tick(true) + elseif e1 == "double_touch" then selectWord() tick(true) - elseif e1 == "drag" and checkScrollbar(e4) then + + elseif e1 == "drag" then + e3, e4 = math.ceil(e3), math.ceil(e4) + + if not checkScrollbar(e4) then + return + end + codeView.selections[1] = codeView.selections[1] or {from = {}, to = {}} codeView.selections[1].from.symbol, codeView.selections[1].from.line = cursorPositionSymbol, cursorPositionLine codeView.selections[1].to.symbol, codeView.selections[1].to.line = fixCursorPosition(convertScreenCoordinatesToTextPosition(e3, e4)) @@ -1382,6 +1396,7 @@ codeView.eventHandler = function(workspace, object, e1, e2, e3, e4, e5) if codeView.selections[1].from.line > codeView.selections[1].to.line then codeView.selections[1].from.line, codeView.selections[1].to.line = codeView.selections[1].to.line, codeView.selections[1].from.line codeView.selections[1].from.symbol, codeView.selections[1].to.symbol = codeView.selections[1].to.symbol, codeView.selections[1].from.symbol + elseif codeView.selections[1].from.line == codeView.selections[1].to.line then if codeView.selections[1].from.symbol > codeView.selections[1].to.symbol then codeView.selections[1].from.symbol, codeView.selections[1].to.symbol = codeView.selections[1].to.symbol, codeView.selections[1].from.symbol @@ -1389,6 +1404,7 @@ codeView.eventHandler = function(workspace, object, e1, e2, e3, e4, e5) end tick(true) + elseif e1 == "key_down" and GUI.focusedObject == window then -- Ctrl or CMD if keyboard.isControlDown() or keyboard.isCommandDown() then @@ -1561,14 +1577,17 @@ codeView.eventHandler = function(workspace, object, e1, e2, e3, e4, e5) end tick(true) + elseif e1 == "scroll" then scroll(e5, config.scrollSpeed) tick(cursorBlinkState) + elseif e1 == "clipboard" then local lines = splitStringIntoLines(e3) paste(lines) tick(cursorBlinkState) + elseif not e1 and cursorUptime + config.cursorBlinkDelay < computer.uptime() then tick(not cursorBlinkState) end diff --git a/Applications/Picture Edit.app/Tools/1.lua b/Applications/Picture Edit.app/Tools/1.lua index 984701bc..196c4fc1 100644 --- a/Applications/Picture Edit.app/Tools/1.lua +++ b/Applications/Picture Edit.app/Tools/1.lua @@ -158,9 +158,12 @@ end tool.eventHandler = function(workspace, object, e1, e2, e3, e4) if e1 == "touch" then + e3, e4 = math.ceil(e3), math.ceil(e4) touchX, touchY, dragX, dragY = e3, e4, e3, e4 repositionSelector() + elseif e1 == "drag" then + e3, e4 = math.ceil(e3), math.ceil(e4) dragX, dragY = e3, e4 repositionSelector() end diff --git a/Applications/Picture Edit.app/Tools/2.lua b/Applications/Picture Edit.app/Tools/2.lua index 8af9c14f..a177153b 100644 --- a/Applications/Picture Edit.app/Tools/2.lua +++ b/Applications/Picture Edit.app/Tools/2.lua @@ -1,5 +1,6 @@ local image = require("Image") +local number = require("Number") ------------------------------------------------------ @@ -14,15 +15,20 @@ tool.about = locale.tool2 local xOld, yOld tool.eventHandler = function(workspace, object, e1, e2, e3, e4) if e1 == "touch" then - xOld, yOld = e3, e4 + xOld, yOld = math.ceil(e3), math.ceil(e4) + elseif e1 == "drag" and xOld and yOld then + e3, e4 = math.ceil(e3), math.ceil(e4) + window.image.setPosition( - window.image.localX + (e3 - xOld), - window.image.localY + (e4 - yOld) + window.image.localX + e3 - xOld), + window.image.localY + e4 - yOld) ) + xOld, yOld = e3, e4 workspace:draw() + elseif e1 == "drop" then xOld, yOld = nil, nil end diff --git a/Applications/Picture Edit.app/Tools/4.lua b/Applications/Picture Edit.app/Tools/4.lua index 5d165ed4..2fd364a3 100644 --- a/Applications/Picture Edit.app/Tools/4.lua +++ b/Applications/Picture Edit.app/Tools/4.lua @@ -22,8 +22,9 @@ end tool.eventHandler = function(workspace, object, e1, e2, e3, e4) if e1 == "touch" or e1 == "drag" then - local x, y = e3 - window.image.x + 1, e4 - window.image.y + 1 + e3, e4 = math.ceil(e3), math.ceil(e4) + local x, y = e3 - window.image.x + 1, e4 - window.image.y + 1 local background, foreground = image.get(window.image.data, x, y) if pickBackgroundSwitch.switch.state then diff --git a/Applications/Picture Edit.app/Tools/5.lua b/Applications/Picture Edit.app/Tools/5.lua index add747c0..7d5cf9b6 100644 --- a/Applications/Picture Edit.app/Tools/5.lua +++ b/Applications/Picture Edit.app/Tools/5.lua @@ -39,7 +39,7 @@ end tool.eventHandler = function(workspace, object, e1, e2, e3, e4) if e1 == "touch" or e1 == "drag" then - local x, y = e3 - window.image.x + 1, e4 - window.image.y + 1 + local x, y = math.ceil(e3) - window.image.x + 1, math.ceil(e4) - window.image.y + 1 local meow = math.floor(radiusSlider.value) for j = y - meow + 1, y + meow - 1 do diff --git a/Applications/Picture Edit.app/Tools/6.lua b/Applications/Picture Edit.app/Tools/6.lua index 9744f23d..13b0aa98 100644 --- a/Applications/Picture Edit.app/Tools/6.lua +++ b/Applications/Picture Edit.app/Tools/6.lua @@ -29,7 +29,7 @@ end tool.eventHandler = function(workspace, object, e1, e2, e3, e4) if e1 == "touch" or e1 == "drag" then - local x, y = e3 - window.image.x + 1, e4 - window.image.y + 1 + local x, y = math.ceil(e3) - window.image.x + 1, math.ceil(e4) - window.image.y + 1 local meow = math.floor(radiusSlider.value) for j = y - meow + 1, y + meow - 1 do diff --git a/Applications/Picture Edit.app/Tools/7.lua b/Applications/Picture Edit.app/Tools/7.lua index 3271db49..1504e207 100644 --- a/Applications/Picture Edit.app/Tools/7.lua +++ b/Applications/Picture Edit.app/Tools/7.lua @@ -14,6 +14,8 @@ tool.about = locale.tool7 tool.eventHandler = function(workspace, object, e1, e2, e3, e4) if e1 == "touch" then + e3, e4 = math.ceil(e3), math.ceil(e4) + local input = workspace:addChild(GUI.input( e3 - 1, e4, @@ -30,6 +32,7 @@ tool.eventHandler = function(workspace, object, e1, e2, e3, e4) input.onInputFinished = function() if #input.text > 0 then local x, y = e3 - window.image.x + 1, e4 - window.image.y + 1 + for i = 1, unicode.len(input.text) do if x <= window.image.width then local background, foreground, alpha = image.get(window.image.data, x, y) diff --git a/Applications/Picture Edit.app/Tools/8.lua b/Applications/Picture Edit.app/Tools/8.lua index 8a42e289..8fc8838f 100644 --- a/Applications/Picture Edit.app/Tools/8.lua +++ b/Applications/Picture Edit.app/Tools/8.lua @@ -34,7 +34,7 @@ end tool.eventHandler = function(workspace, object, e1, e2, e3, e4) if e1 == "touch" then - local x, y = e3 - window.image.x + 1, e4 - window.image.y + 1 + local x, y = math.ceil(e3) - window.image.x + 1, math.ceil(e4) - window.image.y + 1 local sourceB, sourceF, sourceA, sourceS = image.get(window.image.data, x, y) pizda(x, y, window.image.data, sourceB, sourceF, sourceA, sourceS, window.primaryColorSelector.color, 0x0, 0, " ") diff --git a/Applications/Picture Edit.app/Tools/9.lua b/Applications/Picture Edit.app/Tools/9.lua index 0742597b..db357a65 100644 --- a/Applications/Picture Edit.app/Tools/9.lua +++ b/Applications/Picture Edit.app/Tools/9.lua @@ -18,7 +18,9 @@ local container, char, step = layout:addChild(GUI.container(1, 1, 8, 8)), " ", f for y = 1, 8, 2 do for x = 1, 8, 4 do local button = container:addChild(GUI.button(x, y, 4, 2, step and 0xFFFFFF or 0xD2D2D2, 0x0, step and 0x0 or 0x1E1E1E, 0x0, " ")) + button.switchMode = true + button.onTouch = function() local data = {} for i = 1, #container.children do @@ -43,7 +45,7 @@ end tool.eventHandler = function(workspace, object, e1, e2, e3, e4) if e1 == "touch" or e1 == "drag" then - local x, y = e3 - window.image.x + 1, e4 - window.image.y + 1 + local x, y = math.ceil(e3) - window.image.x + 1, math.ceil(e4) - window.image.y + 1 local background, foreground, alpha, symbol = image.get(window.image.data, x, y) image.set(window.image.data, x, y, diff --git a/Applications/Picture View.app/Main.lua b/Applications/Picture View.app/Main.lua index 2d58d7ae..79a6c80f 100644 --- a/Applications/Picture View.app/Main.lua +++ b/Applications/Picture View.app/Main.lua @@ -184,6 +184,7 @@ window.eventHandler = function(workspace, window, e1, ...) if e1 == "double_touch" then setUIHidden(not panel.hidden) workspace:draw() + elseif e1 == "touch" or e1 == "key_down" then if slideShowDeadline then setUIHidden(false) @@ -191,6 +192,7 @@ window.eventHandler = function(workspace, window, e1, ...) workspace:draw() end + else if slideShowDelay and computer.uptime() > slideShowDeadline then loadIncremented(1) diff --git a/Applications/Shooting.app/Main.lua b/Applications/Shooting.app/Main.lua index c5428a4f..b8922a0f 100644 --- a/Applications/Shooting.app/Main.lua +++ b/Applications/Shooting.app/Main.lua @@ -75,6 +75,8 @@ end circle.eventHandler = function(workspace, circle, e1, e2, e3, e4, e5, e6) if e1 == "touch" then + e3, e4 = math.ceil(e3), math.ceil(e4) + lastPlayer = e6 players[lastPlayer] = players[lastPlayer] or { color = color.HSBToInteger(math.random(360), 1, 1), diff --git a/Applications/Stargate.app/Main.lua b/Applications/Stargate.app/Main.lua index 4bafc4df..3e962c75 100755 --- a/Applications/Stargate.app/Main.lua +++ b/Applications/Stargate.app/Main.lua @@ -240,12 +240,14 @@ workspace.addContactButton.onTouch = function() if e1 == "touch" then if input1.text and input2.text then local exists = false + for i = 1, #contacts do if contacts[i].address == input2.text then exists = true break end end + if not exists then table.insert(contacts, {name = input1.text, address = input2.text}) updateContacts() diff --git a/Libraries/GUI.lua b/Libraries/GUI.lua index 32df5a19..ee0e97ac 100755 --- a/Libraries/GUI.lua +++ b/Libraries/GUI.lua @@ -363,85 +363,90 @@ end -------------------------------------------------------------------------------- local function workspaceStart(workspace, eventPullTimeout) - local animation, animationIndex, animationOnFinishMethodsIndex, animationOnFinishMethods, e1, e2, e3, e4, e5, e6, e7, e8, e9, e10, e11, e12, e13, e14, e15, e16, e17, e18, e19, e20, e21, e22, e23, e24, e25, e26, e27, e28, e29, e30, e31, e32 + local animation, animationIndex, animationOnFinishMethodsIndex, animationOnFinishMethods, roundedX, roundedY, e1, e2, e3, e4, e5, e6, e7, e8, e9, e10, e11, e12, e13, e14, e15, e16, e17, e18, e19, e20, e21, e22, e23, e24, e25, e26, e27, e28, e29, e30, e31, e32 - local function handle(isScreenEvent, currentContainer, intersectionX1, intersectionY1, intersectionX2, intersectionY2) - if - not isScreenEvent or - intersectionX1 and - e3 >= intersectionX1 and - e3 <= intersectionX2 and - e4 >= intersectionY1 and - e4 <= intersectionY2 - then - local currentContainerPassed, child, newIntersectionX1, newIntersectionY1, newIntersectionX2, newIntersectionY2 + local function handleContainer(isScreenEvent, currentContainer, intersectionX1, intersectionY1, intersectionX2, intersectionY2) + local currentContainerPassed, child, newIntersectionX1, newIntersectionY1, newIntersectionX2, newIntersectionY2 + + if isScreenEvent then + roundedX, roundedY = math.ceil(e3), math.ceil(e4) - if isScreenEvent then - if currentContainer.eventHandler and not currentContainer.disabled then - currentContainer.eventHandler(workspace, currentContainer, e1, e2, e3, e4, e5, e6, e7, e8, e9, e10, e11, e12, e13, e14, e15, e16, e17, e18, e19, e20, e21, e22, e23, e24, e25, e26, e27, e28, e29, e30, e31, e32) - end + if + roundedX < intersectionX1 + or roundedX > intersectionX2 + or roundedY < intersectionY1 + or roundedY > intersectionY2 + then + return + end - currentContainerPassed = not currentContainer.passScreenEvents - elseif currentContainer.eventHandler then + if currentContainer.eventHandler and not currentContainer.disabled then currentContainer.eventHandler(workspace, currentContainer, e1, e2, e3, e4, e5, e6, e7, e8, e9, e10, e11, e12, e13, e14, e15, e16, e17, e18, e19, e20, e21, e22, e23, e24, e25, e26, e27, e28, e29, e30, e31, e32) end - for i = #currentContainer.children, 1, -1 do - child = currentContainer.children[i] + currentContainerPassed = not currentContainer.passScreenEvents + + elseif currentContainer.eventHandler then + currentContainer.eventHandler(workspace, currentContainer, e1, e2, e3, e4, e5, e6, e7, e8, e9, e10, e11, e12, e13, e14, e15, e16, e17, e18, e19, e20, e21, e22, e23, e24, e25, e26, e27, e28, e29, e30, e31, e32) + end - if not child.hidden then - if child.children then - newIntersectionX1, newIntersectionY1, newIntersectionX2, newIntersectionY2 = getRectangleIntersection( - intersectionX1, - intersectionY1, - intersectionX2, - intersectionY2, - child.x, - child.y, - child.x + child.width - 1, - child.y + child.height - 1 + for i = #currentContainer.children, 1, -1 do + child = currentContainer.children[i] + + if not child.hidden then + if child.children then + newIntersectionX1, newIntersectionY1, newIntersectionX2, newIntersectionY2 = getRectangleIntersection( + intersectionX1, + intersectionY1, + intersectionX2, + intersectionY2, + child.x, + child.y, + child.x + child.width - 1, + child.y + child.height - 1 + ) + + if + newIntersectionX1 + and handleContainer( + isScreenEvent, + child, + newIntersectionX1, + newIntersectionY1, + newIntersectionX2, + newIntersectionY2, + e1, e2, e3, e4, e5, e6, e7, e8, e9, e10, e11, e12, e13, e14, e15, e16, e17, e18, e19, e20, e21, e22, e23, e24, e25, e26, e27, e28, e29, e30, e31, e32 ) + then + return true + end + else + if workspace.needConsume then + workspace.needConsume = nil - if - newIntersectionX1 and - handle( - isScreenEvent, - child, - newIntersectionX1, - newIntersectionY1, - newIntersectionX2, - newIntersectionY2, - e1, e2, e3, e4, e5, e6, e7, e8, e9, e10, e11, e12, e13, e14, e15, e16, e17, e18, e19, e20, e21, e22, e23, e24, e25, e26, e27, e28, e29, e30, e31, e32 - ) - then - return true - end - else - if workspace.needConsume then - workspace.needConsume = nil - return true - end + return true + end - if isScreenEvent then - if child:isPointInside(e3, e4) then - if child.eventHandler and not child.disabled then - child.eventHandler(workspace, child, e1, e2, e3, e4, e5, e6, e7, e8, e9, e10, e11, e12, e13, e14, e15, e16, e17, e18, e19, e20, e21, e22, e23, e24, e25, e26, e27, e28, e29, e30, e31, e32) - end - - if not child.passScreenEvents then - return true - end + if isScreenEvent then + if child:isPointInside(roundedX, roundedY) then + if child.eventHandler and not child.disabled then + child.eventHandler(workspace, child, e1, e2, e3, e4, e5, e6, e7, e8, e9, e10, e11, e12, e13, e14, e15, e16, e17, e18, e19, e20, e21, e22, e23, e24, e25, e26, e27, e28, e29, e30, e31, e32) + end + + if not child.passScreenEvents then + return true end - elseif child.eventHandler then - child.eventHandler(workspace, child, e1, e2, e3, e4, e5, e6, e7, e8, e9, e10, e11, e12, e13, e14, e15, e16, e17, e18, e19, e20, e21, e22, e23, e24, e25, e26, e27, e28, e29, e30, e31, e32) end + + elseif child.eventHandler then + child.eventHandler(workspace, child, e1, e2, e3, e4, e5, e6, e7, e8, e9, e10, e11, e12, e13, e14, e15, e16, e17, e18, e19, e20, e21, e22, e23, e24, e25, e26, e27, e28, e29, e30, e31, e32) end end end + end - if currentContainerPassed then - return true - end + if currentContainerPassed then + return true end end @@ -450,7 +455,7 @@ local function workspaceStart(workspace, eventPullTimeout) repeat e1, e2, e3, e4, e5, e6, e7, e8, e9, e10, e11, e12, e13, e14, e15, e16, e17, e18, e19, e20, e21, e22, e23, e24, e25, e26, e27, e28, e29, e30, e31, e32 = event.pull(workspace.animations and 0 or workspace.eventPullTimeout) - handle( + handleContainer( e1 == "touch" or e1 == "drag" or e1 == "drop" or @@ -474,6 +479,7 @@ local function workspaceStart(workspace, eventPullTimeout) if #workspace.animations == 0 then workspace.animations = nil + break end else @@ -1270,23 +1276,31 @@ local function drawChart(object) -- Max, min, deltas local xMin, xMax, yMin, yMax = valuesCopy[1][1], valuesCopy[#valuesCopy][1], valuesCopy[1][2], valuesCopy[1][2] - for i = 1, #valuesCopy do yMin, yMax = math.min(yMin, valuesCopy[i][2]), math.max(yMax, valuesCopy[i][2]) end + + for i = 1, #valuesCopy do + yMin, yMax = math.min(yMin, valuesCopy[i][2]), math.max(yMax, valuesCopy[i][2]) + end + local dx, dy = xMax - xMin, yMax - yMin -- y axis values and helpers local value, chartHeight, yAxisValueMaxWidth, yAxisValues = yMin, object.height - 1 - (object.showXAxisValues and 1 or 0), 0, {} + for y = object.y + object.height - 3, object.y + 1, -chartHeight * object.yAxisValueInterval do local stringValue = getAxisValue(value, object.yAxisPostfix, object.roundValues) + yAxisValueMaxWidth = math.max(yAxisValueMaxWidth, unicode.len(stringValue)) table.insert(yAxisValues, {y = math.ceil(y), value = stringValue}) value = value + dy * object.yAxisValueInterval end + local stringValue = getAxisValue(yMax, object.yAxisPostfix, object.roundValues) table.insert(yAxisValues, {y = object.y, value = stringValue}) yAxisValueMaxWidth = math.max(yAxisValueMaxWidth, unicode.len(stringValue)) local chartWidth = object.width - (object.showYAxisValues and yAxisValueMaxWidth + 2 or 0) local chartX = object.x + object.width - chartWidth + for i = 1, #yAxisValues do if object.showYAxisValues then screen.drawText(chartX - unicode.len(yAxisValues[i].value) - 2, yAxisValues[i].y, object.colors.axisValue, yAxisValues[i].value) @@ -1419,9 +1433,9 @@ local function sliderEventHandler(workspace, object, e1, e2, e3, e4, e5, ...) if e1 == "touch" or e1 == "drag" then local clickPosition = e3 - object.x - if clickPosition == 0 then + if clickPosition <= 0 then object.value = object.minimumValue - elseif clickPosition == object.width - 1 then + elseif clickPosition >= object.width - 1 then object.value = object.maximumValue else object.value = object.minimumValue + (clickPosition / object.width * (object.maximumValue - object.minimumValue)) @@ -1496,6 +1510,7 @@ local function switchEventHandler(workspace, switch, e1, ...) local eventData = {...} switch.state = not switch.state + switch:addAnimation( function(animation) if switch.state then @@ -1504,6 +1519,7 @@ local function switchEventHandler(workspace, switch, e1, ...) switch.pipePosition = number.round(1 + (1 - animation.position) * (switch.width - 2)) end end, + function(animation) animation:remove() if switch.onStateChanged then @@ -2203,15 +2219,19 @@ end local function resizerEventHandler(workspace, object, e1, e2, e3, e4) if e1 == "touch" then - object.lastTouchX, object.lastTouchY = e3, e4 + object.lastTouchX, object.lastTouchY = math.ceil(e3), math.ceil(e4) workspace:draw() - elseif e1 == "drag" and object.lastTouchX then + + elseif e1 == "drag" and object.lastTouchX then + e3, e4 = math.ceil(e3), math.ceil(e4) + if object.onResize then object.onResize(e3 - object.lastTouchX, e4 - object.lastTouchY) end object.lastTouchX, object.lastTouchY = e3, e4 workspace:draw() + elseif e1 == "drop" then if object.onResizeFinished then object.onResizeFinished() @@ -2304,6 +2324,8 @@ local function scrollBarEventHandler(workspace, object, e1, e2, e3, e4, e5, ...) local newValue = object.value if e1 == "touch" or e1 == "drag" then + e3, e4 = math.ceil(e3), math.ceil(e4) + if object.height > object.width then if e4 == object.y + object.height - 1 then newValue = object.maximumValue @@ -2317,6 +2339,7 @@ local function scrollBarEventHandler(workspace, object, e1, e2, e3, e4, e5, ...) newValue = object.minimumValue + (e3 - object.x) / object.width * (object.maximumValue - object.minimumValue) end end + elseif e1 == "scroll" then if e5 == 1 then if object.value >= object.minimumValue + object.onScrollValueIncrement then @@ -2335,6 +2358,7 @@ local function scrollBarEventHandler(workspace, object, e1, e2, e3, e4, e5, ...) if e1 == "touch" or e1 == "drag" or e1 == "scroll" then object.value = newValue + if object.onTouch then object.onTouch(workspace, object, e1, e2, e3, e4, e5, ...) end @@ -2420,7 +2444,10 @@ end local function treeEventHandler(workspace, tree, e1, e2, e3, e4, e5, ...) if e1 == "touch" then + e3, e4 = math.ceil(e3), math.ceil(e4) + local i = e4 - tree.y + tree.fromItem + if tree.items[i] then if tree.items[i].expandable and @@ -2456,6 +2483,7 @@ local function treeEventHandler(workspace, tree, e1, e2, e3, e4, e5, ...) workspace:draw() end + elseif e1 == "scroll" then if e5 == 1 then if tree.fromItem > 1 then @@ -2868,13 +2896,14 @@ end local function inputEventHandler(workspace, input, e1, e2, e3, e4, e5, e6, ...) if e1 == "touch" or e1 == "drag" then - input:setCursorPosition(input.textCutFrom + e3 - input.x - input.textOffset) + input:setCursorPosition(input.textCutFrom + math.ceil(e3) - input.x - input.textOffset) if input.focused then inputCursorBlink(workspace, input, true) else input:startInput() end + elseif e1 == "key_down" and input.focused then workspace:consumeEvent() @@ -2900,6 +2929,7 @@ local function inputEventHandler(workspace, input, e1, e2, e3, e4, e5, e6, ...) end return + -- Arrows up/down/left/right elseif e4 == 200 then if input.historyEnabled and #input.history > 0 then @@ -2918,6 +2948,7 @@ local function inputEventHandler(workspace, input, e1, e2, e3, e4, e5, e6, ...) input.text = input.history[input.historyIndex] input:setCursorPosition(unicode.len(input.text) + 1) end + elseif e4 == 208 then if input.historyEnabled and #input.history > 0 then input.historyIndex = input.historyIndex + 1 @@ -2930,25 +2961,33 @@ local function inputEventHandler(workspace, input, e1, e2, e3, e4, e5, e6, ...) input.text = input.history[input.historyIndex] input:setCursorPosition(unicode.len(input.text) + 1) end + elseif e4 == 203 then input:setCursorPosition(input.cursorPosition - 1) + elseif e4 == 205 then input:setCursorPosition(input.cursorPosition + 1) + -- Backspace elseif e4 == 14 then input.text = unicode.sub(unicode.sub(input.text, 1, input.cursorPosition - 1), 1, -2) .. unicode.sub(input.text, input.cursorPosition, -1) input:setCursorPosition(input.cursorPosition - 1) + -- Delete elseif e4 == 211 then input.text = unicode.sub(input.text, 1, input.cursorPosition - 1) .. unicode.sub(input.text, input.cursorPosition + 1, -1) + -- Home elseif e4 == 199 then input:setCursorPosition(1) + -- End elseif e4 == 207 then input:setCursorPosition(unicode.len(input.text) + 1) + else local char = unicode.char(e3) + if not keyboard.isControl(e3) then input.text = unicode.sub(input.text, 1, input.cursorPosition - 1) .. char .. unicode.sub(input.text, input.cursorPosition, -1) input:setCursorPosition(input.cursorPosition + 1) @@ -2960,12 +2999,14 @@ local function inputEventHandler(workspace, input, e1, e2, e3, e4, e5, e6, ...) end inputCursorBlink(workspace, input, true) + elseif e1 == "clipboard" and input.focused then input.text = unicode.sub(input.text, 1, input.cursorPosition - 1) .. e3 .. unicode.sub(input.text, input.cursorPosition, -1) input:setCursorPosition(input.cursorPosition + unicode.len(e3)) inputCursorBlink(workspace, input, true) workspace:consumeEvent() + elseif not e1 and input.focused and computer.uptime() - input.cursorBlinkUptime > input.cursorBlinkDelay then inputCursorBlink(workspace, input, not input.cursorBlinkState) end @@ -3009,7 +3050,7 @@ function GUI.input(x, y, width, height, backgroundColor, textColor, placeholderT input.stopInputObject = GUI.object(1, 1, 1, 1) input.stopInputObject.eventHandler = function(workspace, object, e1, e2, e3, e4, ...) if e1 == "touch" or e1 == "drop" then - if input:isPointInside(e3, e4) then + if input:isPointInside(math.ceil(e3), math.ceil(e4)) then input.eventHandler(workspace, input, e1, e2, e3, e4, ...) else inputStopInput(workspace, input) @@ -3043,6 +3084,7 @@ local function autoCompleteDraw(object) screen.drawText(object.x + object.matchTextLength + 1, y, textColor, unicode.sub(object.items[i], object.matchTextLength + 1, object.matchTextLength + object.width - object.matchTextLength - 2)) y = y + 1 + if y > yEnd then break end @@ -3073,21 +3115,24 @@ end local function autoCompleteEventHandler(workspace, object, e1, e2, e3, e4, e5, ...) if e1 == "touch" then - object.selectedItem = e4 - object.y + object.fromItem + object.selectedItem = math.ceil(e4) - object.y + object.fromItem workspace:draw() if object.onItemSelected then event.sleep(0.2) object.onItemSelected(workspace, object, e1, e2, e3, e4, e5, ...) end + elseif e1 == "scroll" then autoCompleteScroll(workspace, object, -e5) workspace:draw() + elseif e1 == "key_down" then if e4 == 28 then if object.onItemSelected then object.onItemSelected(workspace, object, e1, e2, e3, e4, e5, ...) end + elseif e4 == 200 then object.selectedItem = object.selectedItem - 1 if object.selectedItem < 1 then @@ -3099,6 +3144,7 @@ local function autoCompleteEventHandler(workspace, object, e1, e2, e3, e4, e5, . end workspace:draw() + elseif e4 == 208 then object.selectedItem = object.selectedItem + 1 if object.selectedItem > object.itemCount then @@ -3313,11 +3359,13 @@ function GUI.palette(x, y, startColor) paletteDrawBigCrestPixel(object.x + 2, object.y, "│") paletteDrawBigCrestPixel(object.x + 2, object.y + 2, "│") end + bigCrest.passScreenEvents = true local miniImage = palette:addChild(GUI.image(53, 1, image.create(3, 25))) local miniCrest = palette:addChild(GUI.object(52, 1, 5, 1)) + miniCrest.draw = function(object) screen.drawText(object.x, object.y, 0x0, ">") screen.drawText(object.x + 4, object.y, 0x0, "<") @@ -3329,21 +3377,25 @@ function GUI.palette(x, y, startColor) local function paletteRefreshBigImage() local saturationStep, brightnessStep, saturation, brightness = 1 / bigImage.width, 1 / bigImage.height, 0, 1 + for j = 1, bigImage.height do for i = 1, bigImage.width do image.set(bigImage.image, i, j, color.optimize(color.HSBToInteger(palette.color.hsb.hue, saturation, brightness)), 0x0, 0x0, " ") saturation = saturation + saturationStep end + saturation, brightness = 0, brightness - brightnessStep end end local function paletteRefreshMiniImage() local hueStep, hue = 360 / miniImage.height, 0 + for j = 1, miniImage.height do for i = 1, miniImage.width do image.set(miniImage.image, i, j, color.optimize(color.HSBToInteger(hue, 1, 1)), 0x0, 0, " ") end + hue = hue + hueStep end end @@ -3495,17 +3547,23 @@ function GUI.palette(x, y, startColor) bigImage.eventHandler = function(workspace, object, e1, e2, e3, e4) if e1 == "touch" or e1 == "drag" then + e3, e4 = math.ceil(e3), math.ceil(e4) + bigCrest.localX, bigCrest.localY = e3 - palette.x - 1, e4 - palette.y paletteSwitchColorFromHex(select(3, component.invoke(screen.getGPUAddress(), "get", e3, e4))) + workspace:draw() end end miniImage.eventHandler = function(workspace, object, e1, e2, e3, e4) if e1 == "touch" or e1 == "drag" then + e4 = math.ceil(e4) + miniCrest.localY = e4 - palette.y + 1 paletteSwitchColorFromHsb((e4 - miniImage.y) * 360 / miniImage.height, palette.color.hsb.saturation, palette.color.hsb.brightness) paletteRefreshBigImage() + workspace:draw() end end @@ -4276,7 +4334,8 @@ local function windowDraw(window) end local function windowCheck(window, x, y) - local child + local child, result + for i = #window.children, 1, -1 do child = window.children[i] @@ -4287,11 +4346,14 @@ local function windowCheck(window, x, y) then if not child.passScreenEvents and child.eventHandler then return true + elseif child.children then - local result = windowCheck(child, x, y) + result = windowCheck(child, x, y) + -- Nil causes next child processing if result == true then return true + elseif result == false then return false end @@ -4303,6 +4365,8 @@ end local function windowEventHandler(workspace, window, e1, e2, e3, e4, ...) if window.movingEnabled then if e1 == "touch" then + e3, e4 = math.ceil(e3), math.ceil(e4) + if not windowCheck(window, e3, e4) then window.lastTouchX, window.lastTouchY = e3, e4 end @@ -4312,15 +4376,19 @@ local function windowEventHandler(workspace, window, e1, e2, e3, e4, ...) workspace:draw() end - elseif e1 == "drag" and window.lastTouchX and not windowCheck(window, e3, e4) then - local xOffset, yOffset = e3 - window.lastTouchX, e4 - window.lastTouchY - - if xOffset ~= 0 or yOffset ~= 0 then - window.localX, window.localY = window.localX + xOffset, window.localY + yOffset - window.lastTouchX, window.lastTouchY = e3, e4 - - workspace:draw() + + elseif e1 == "drag" and window.lastTouchX then + e3, e4 = math.ceil(e3), math.ceil(e4) + + if windowCheck(window, e3, e4) then + return end + + window.localX, window.localY = window.localX + e3 - window.lastTouchX, window.localY + e4 - window.lastTouchY + window.lastTouchX, window.lastTouchY = e3, e4 + + workspace:draw() + elseif e1 == "drop" then window.lastTouchX, window.lastTouchY = nil, nil end @@ -4730,8 +4798,9 @@ end function GUI.tableEventHandler(workspace, self, e1, e2, e3, e4, e5, ...) if e1 == "touch" then local itemTouched = false + for i = 1, #self.children do - if self.children[i]:isPointInside(e3, e4) then + if self.children[i]:isPointInside(math.ceil(e3), math.ceil(e4)) then itemTouched = true break end diff --git a/Libraries/System.lua b/Libraries/System.lua index d411d12e..65039087 100755 --- a/Libraries/System.lua +++ b/Libraries/System.lua @@ -570,7 +570,7 @@ local function iconDeselectAndSelect(icon) end local function iconOnRightClick(selectedIcons, icon, e1, e2, e3, e4) - local contextMenu = GUI.addContextMenu(workspace, e3, e4) + local contextMenu = GUI.addContextMenu(workspace, math.ceil(e3), math.ceil(e4)) if #selectedIcons > 1 then contextMenu:addItem(localization.newFolderFromChosen .. " (" .. #selectedIcons .. ")").onTouch = function() @@ -1235,7 +1235,7 @@ local function listIconFieldUpdateFileList(iconField) end local function iconFieldBackgroundClick(iconField, e1, e2, e3, e4, e5, ...) - local contextMenu = GUI.addContextMenu(workspace, e3, e4) + local contextMenu = GUI.addContextMenu(workspace, math.ceil(e3), math.ceil(e4)) local subMenu = contextMenu:addSubMenuItem(localization.create) @@ -1468,11 +1468,19 @@ local function gridIconFieldBackgroundObjectEventHandler(workspace, object, e1, elseif e1 == "drag" then if iconField.selection then local selection = iconField.selection + selection.x2Raw, selection.y2Raw = e3, e4 -- Creating ordered representation of selection - selection.x1, selection.y1, selection.x2, selection.y2 = - selection.x1Raw, selection.y1Raw, selection.x2Raw, selection.y2Raw + selection.x1, + selection.y1, + selection.x2, + selection.y2 = + + math.ceil(selection.x1Raw), + math.ceil(selection.y1Raw), + math.ceil(selection.x2Raw), + math.ceil(selection.y2Raw) if selection.x2 < selection.x1 then selection.x1, selection.x2 = selection.x2, selection.x1 @@ -1976,9 +1984,11 @@ function system.error(path, line, traceback) -- Obtain from- and to- lines that need to be shown codeView.fromLine = line - math.floor((window.height - 3) / 2) + 1 + if codeView.fromLine <= 0 then codeView.fromLine = 1 end + local toLine, lineCounter = codeView.fromLine + codeView.height - 1, 1 -- Read part of file to display error line @@ -2050,7 +2060,6 @@ function system.execute(path, ...) GUI.alert("File \"" .. tostring(path) .. "\" doesn't exists") end - component.invoke(screen.getScreenAddress(), "setPrecise", false) screen.setResolution(oldScreenWidth, oldScreenHeight) if not success then @@ -2286,7 +2295,7 @@ function system.updateDesktop() icon.onRightClick = function(icon, e1, e2, e3, e4, ...) local indexOf = icon:indexOf() - local contextMenu = GUI.addContextMenu(workspace, e3, e4) + local contextMenu = GUI.addContextMenu(workspace, math.ceil(e3), math.ceil(e4)) contextMenu.onMenuClosed = function() icon.selected = false @@ -2373,7 +2382,7 @@ function system.updateDesktop() end icon.onRightClick = function(icon, e1, e2, e3, e4) - local contextMenu = GUI.addContextMenu(workspace, e3, e4) + local contextMenu = GUI.addContextMenu(workspace, math.ceil(e3), math.ceil(e4)) contextMenu.onMenuClosed = function() icon.selected = false