resolve conflicts

akkartik
May 6, 2025, 10:26 PM
BRBXUGRGKUXWDUB667VHZJDEGNWGQH4YOOHQ23Y6HHLHOZZHN5AQC

Dependencies

Change contents

  • file deletion: drawing.lua (----------)drawing.lua (----------)
    [8.2][8.1542:1577](),[8.2][8.1542:1577](),[8.1577][8.98:98]()
    pmx,pmy = px(mx), py(my)
    local shape = drawing.pending
    if shape.mode == nil then
    -- nothing pending
    elseif shape.mode == 'freehand' then
    local shape_copy = deepcopy(shape)
    Drawing.smoothen(shape_copy)
    Drawing.draw_shape(drawing, shape_copy, top, left,right)
    elseif shape.mode == 'line' then
    if mx < 0 or mx >= 256 or my < 0 or my >= drawing.h then
    return
    end
    local p1 = drawing.points[shape.p1]
    love.graphics.line(px(p1.x),py(p1.y), pmx,pmy)
    elseif shape.mode == 'manhattan' then
    if mx < 0 or mx >= 256 or my < 0 or my >= drawing.h then
    return
    end
    local p1 = drawing.points[shape.p1]
    if math.abs(mx-p1.x) > math.abs(my-p1.y) then
    love.graphics.line(px(p1.x),py(p1.y), pmx, py(p1.y))
    else
    love.graphics.line(px(p1.x),py(p1.y), px(p1.x),pmy)
    end
    elseif shape.mode == 'polygon' then
    -- don't close the loop on a pending polygon
    local prev = nil
    for _,point in ipairs(shape.vertices) do
    local curr = drawing.points[point]
    if prev then
    love.graphics.line(px(prev.x),py(prev.y), px(curr.x),py(curr.y))
    end
    prev = curr
    end
    love.graphics.line(px(prev.x),py(prev.y), pmx,pmy)
    elseif shape.mode == 'rectangle' then
    local first = drawing.points[shape.vertices[1]]
    if #shape.vertices == 1 then
    love.graphics.line(px(first.x),py(first.y), pmx,pmy)
    return
    end
    local second = drawing.points[shape.vertices[2]]
    local thirdx,thirdy, fourthx,fourthy = Drawing.complete_rectangle(first.x,first.y, second.x,second.y, mx,my)
    love.graphics.line(px(first.x),py(first.y), px(second.x),py(second.y))
    love.graphics.line(px(second.x),py(second.y), px(thirdx),py(thirdy))
    love.graphics.line(px(thirdx),py(thirdy), px(fourthx),py(fourthy))
    love.graphics.line(px(fourthx),py(fourthy), px(first.x),py(first.y))
    elseif shape.mode == 'square' then
    local first = drawing.points[shape.vertices[1]]
    if #shape.vertices == 1 then
    love.graphics.line(px(first.x),py(first.y), pmx,pmy)
    return
    end
    local second = drawing.points[shape.vertices[2]]
    local thirdx,thirdy, fourthx,fourthy = Drawing.complete_square(first.x,first.y, second.x,second.y, mx,my)
    love.graphics.line(px(first.x),py(first.y), px(second.x),py(second.y))
    love.graphics.line(px(second.x),py(second.y), px(thirdx),py(thirdy))
    love.graphics.line(px(thirdx),py(thirdy), px(fourthx),py(fourthy))
    love.graphics.line(px(fourthx),py(fourthy), px(first.x),py(first.y))
    elseif shape.mode == 'circle' then
    local center = drawing.points[shape.center]
    if mx < 0 or mx >= 256 or my < 0 or my >= drawing.h then
    return
    end
    local cx,cy = px(center.x), py(center.y)
    elseif shape.mode == 'arc' then
    local center = drawing.points[shape.center]
    if mx < 0 or mx >= 256 or my < 0 or my >= drawing.h then
    return
    end
    shape.end_angle = geom.angle_with_hint(center.x,center.y, mx,my, shape.end_angle)
    local cx,cy = px(center.x), py(center.y)
    love.graphics.arc('line', 'open', cx,cy, Drawing.pixels(shape.radius, width), shape.start_angle, shape.end_angle, 360)
    elseif shape.mode == 'move' then
    -- nothing pending; changes are immediately committed
    elseif shape.mode == 'name' then
    -- nothing pending; changes are immediately committed
    else
    end
    end
    end
    function Drawing.mouse_press(State, drawing_index, x,y, mouse_button, is_touch, presses)
    local drawing = State.lines[drawing_index]
    local cx = Drawing.coord(x-State.left, State.width)
    if State.current_drawing_mode == 'freehand' then
    drawing.pending = {mode=State.current_drawing_mode, points={{x=cx, y=cy}}}
    elseif State.current_drawing_mode == 'line' or State.current_drawing_mode == 'manhattan' then
    local j = Drawing.find_or_insert_point(drawing.points, cx, cy, State.width)
    drawing.pending = {mode=State.current_drawing_mode, p1=j}
    elseif State.current_drawing_mode == 'polygon' or State.current_drawing_mode == 'rectangle' or State.current_drawing_mode == 'square' then
    local j = Drawing.find_or_insert_point(drawing.points, cx, cy, State.width)
    drawing.pending = {mode=State.current_drawing_mode, vertices={j}}
    elseif State.current_drawing_mode == 'circle' then
    local j = Drawing.find_or_insert_point(drawing.points, cx, cy, State.width)
    drawing.pending = {mode=State.current_drawing_mode, center=j}
    elseif State.current_drawing_mode == 'move' then
    elseif State.current_drawing_mode == 'name' then
    -- nothing
    else
    end
    end
    -- a couple of operations on drawings need to constantly check the state of the mouse
    function Drawing.update(State)
    if State.lines.current_drawing == nil then return end
    local drawing = State.lines.current_drawing
    local pmx, pmy = App.mouse_x(), App.mouse_y()
    local mx = Drawing.coord(pmx-State.left, State.width)
    if App.mouse_down(1) then
    if drawing.pending.mode == 'freehand' then
    table.insert(drawing.pending.points, {x=mx, y=my})
    elseif drawing.pending.mode == 'move' then
    drawing.pending.target_point.x = mx
    drawing.pending.target_point.y = my
    Drawing.relax_constraints(drawing, drawing.pending.target_point_index)
    end
    end
    elseif State.current_drawing_mode == 'move' then
    drawing.pending.target_point.x = mx
    drawing.pending.target_point.y = my
    Drawing.relax_constraints(drawing, drawing.pending.target_point_index)
    end
    else
    -- do nothing
    end
    end
    function Drawing.relax_constraints(drawing, p)
    for _,shape in ipairs(drawing.shapes) do
    if shape.mode == 'manhattan' then
    if shape.p1 == p then
    shape.mode = 'line'
    elseif shape.p2 == p then
    shape.mode = 'line'
    end
    elseif shape.mode == 'rectangle' or shape.mode == 'square' then
    for _,v in ipairs(shape.vertices) do
    if v == p then
    shape.mode = 'polygon'
    end
    end
    end
    end
    end
    function Drawing.mouse_release(State, x,y, mouse_button, is_touch, presses)
    if State.current_drawing_mode == 'move' then
    State.current_drawing_mode = State.previous_drawing_mode
    State.previous_drawing_mode = nil
    if State.lines.current_drawing then
    State.lines.current_drawing.pending = {}
    State.lines.current_drawing = nil
    end
    elseif State.lines.current_drawing then
    local drawing = State.lines.current_drawing
    if drawing.pending then
    if drawing.pending.mode == nil then
    -- nothing pending
    elseif drawing.pending.mode == 'freehand' then
    -- the last point added during update is good enough
    Drawing.smoothen(drawing.pending)
    table.insert(drawing.shapes, drawing.pending)
    elseif drawing.pending.mode == 'line' then
    if mx >= 0 and mx < 256 and my >= 0 and my < drawing.h then
    drawing.pending.p2 = Drawing.find_or_insert_point(drawing.points, mx,my, State.width)
    table.insert(drawing.shapes, drawing.pending)
    end
    elseif drawing.pending.mode == 'manhattan' then
    local p1 = drawing.points[drawing.pending.p1]
    if mx >= 0 and mx < 256 and my >= 0 and my < drawing.h then
    if math.abs(mx-p1.x) > math.abs(my-p1.y) then
    drawing.pending.p2 = Drawing.find_or_insert_point(drawing.points, mx, p1.y, State.width)
    else
    drawing.pending.p2 = Drawing.find_or_insert_point(drawing.points, p1.x, my, State.width)
    end
    local p2 = drawing.points[drawing.pending.p2]
    table.insert(drawing.shapes, drawing.pending)
    end
    elseif drawing.pending.mode == 'polygon' then
    if mx >= 0 and mx < 256 and my >= 0 and my < drawing.h then
    table.insert(drawing.pending.vertices, Drawing.find_or_insert_point(drawing.points, mx,my, State.width))
    table.insert(drawing.shapes, drawing.pending)
    end
    elseif drawing.pending.mode == 'rectangle' then
    if #drawing.pending.vertices == 2 then
    if mx >= 0 and mx < 256 and my >= 0 and my < drawing.h then
    local first = drawing.points[drawing.pending.vertices[1]]
    local second = drawing.points[drawing.pending.vertices[2]]
    local thirdx,thirdy, fourthx,fourthy = Drawing.complete_rectangle(first.x,first.y, second.x,second.y, mx,my)
    table.insert(drawing.pending.vertices, Drawing.find_or_insert_point(drawing.points, thirdx,thirdy, State.width))
    table.insert(drawing.pending.vertices, Drawing.find_or_insert_point(drawing.points, fourthx,fourthy, State.width))
    table.insert(drawing.shapes, drawing.pending)
    end
    else
    -- too few points; draw nothing
    end
    elseif drawing.pending.mode == 'square' then
    if #drawing.pending.vertices == 2 then
    if mx >= 0 and mx < 256 and my >= 0 and my < drawing.h then
    local first = drawing.points[drawing.pending.vertices[1]]
    local second = drawing.points[drawing.pending.vertices[2]]
    local thirdx,thirdy, fourthx,fourthy = Drawing.complete_square(first.x,first.y, second.x,second.y, mx,my)
    table.insert(drawing.pending.vertices, Drawing.find_or_insert_point(drawing.points, thirdx,thirdy, State.width))
    table.insert(drawing.pending.vertices, Drawing.find_or_insert_point(drawing.points, fourthx,fourthy, State.width))
    table.insert(drawing.shapes, drawing.pending)
    end
    end
    elseif drawing.pending.mode == 'circle' then
    if mx >= 0 and mx < 256 and my >= 0 and my < drawing.h then
    local center = drawing.points[drawing.pending.center]
    drawing.pending.radius = round(geom.dist(center.x,center.y, mx,my))
    table.insert(drawing.shapes, drawing.pending)
    end
    elseif drawing.pending.mode == 'arc' then
    if mx >= 0 and mx < 256 and my >= 0 and my < drawing.h then
    local center = drawing.points[drawing.pending.center]
    drawing.pending.end_angle = geom.angle_with_hint(center.x,center.y, mx,my, drawing.pending.end_angle)
    table.insert(drawing.shapes, drawing.pending)
    end
    elseif drawing.pending.mode == 'name' then
    -- drop it
    else
    end
    State.lines.current_drawing.pending = {}
    State.lines.current_drawing = nil
    end
    end
    end
    function Drawing.keychord_press(State, chord, key, scancode, is_repeat)
    if chord == 'C-p' and not App.mouse_down(1) then
    State.current_drawing_mode = 'freehand'
    elseif App.mouse_down(1) and chord == 'l' then
    State.current_drawing_mode = 'line'
    local _,drawing = Drawing.current_drawing(State)
    if drawing.pending.mode == 'freehand' then
    drawing.pending.p1 = Drawing.find_or_insert_point(drawing.points, drawing.pending.points[1].x, drawing.pending.points[1].y, State.width)
    elseif drawing.pending.mode == 'polygon' or drawing.pending.mode == 'rectangle' or drawing.pending.mode == 'square' then
    drawing.pending.p1 = drawing.pending.vertices[1]
    elseif drawing.pending.mode == 'circle' or drawing.pending.mode == 'arc' then
    drawing.pending.p1 = drawing.pending.center
    end
    drawing.pending.mode = 'line'
    elseif chord == 'C-l' and not App.mouse_down(1) then
    State.current_drawing_mode = 'line'
    elseif App.mouse_down(1) and chord == 'm' then
    State.current_drawing_mode = 'manhattan'
    local drawing = Drawing.select_drawing_at_mouse(State)
    if drawing.pending.mode == 'freehand' then
    drawing.pending.p1 = Drawing.find_or_insert_point(drawing.points, drawing.pending.points[1].x, drawing.pending.points[1].y, State.width)
    elseif drawing.pending.mode == 'line' then
    -- do nothing
    elseif drawing.pending.mode == 'polygon' or drawing.pending.mode == 'rectangle' or drawing.pending.mode == 'square' then
    drawing.pending.p1 = drawing.pending.vertices[1]
    elseif drawing.pending.mode == 'circle' or drawing.pending.mode == 'arc' then
    drawing.pending.p1 = drawing.pending.center
    end
    drawing.pending.mode = 'manhattan'
    elseif chord == 'C-m' and not App.mouse_down(1) then
    State.current_drawing_mode = 'manhattan'
    elseif chord == 'C-g' and not App.mouse_down(1) then
    State.current_drawing_mode = 'polygon'
    elseif App.mouse_down(1) and chord == 'g' then
    State.current_drawing_mode = 'polygon'
    local _,drawing = Drawing.current_drawing(State)
    if drawing.pending.mode == 'freehand' then
    drawing.pending.vertices = {Drawing.find_or_insert_point(drawing.points, drawing.pending.points[1].x, drawing.pending.points[1].y, State.width)}
    elseif drawing.pending.mode == 'line' or drawing.pending.mode == 'manhattan' then
    if drawing.pending.vertices == nil then
    drawing.pending.vertices = {drawing.pending.p1}
    end
    elseif drawing.pending.mode == 'rectangle' or drawing.pending.mode == 'square' then
    -- reuse existing vertices
    elseif drawing.pending.mode == 'circle' or drawing.pending.mode == 'arc' then
    drawing.pending.vertices = {drawing.pending.center}
    end
    drawing.pending.mode = 'polygon'
    elseif chord == 'C-r' and not App.mouse_down(1) then
    State.current_drawing_mode = 'rectangle'
    elseif App.mouse_down(1) and chord == 'r' then
    State.current_drawing_mode = 'rectangle'
    local _,drawing = Drawing.current_drawing(State)
    if drawing.pending.mode == 'freehand' then
    drawing.pending.vertices = {Drawing.find_or_insert_point(drawing.points, drawing.pending.points[1].x, drawing.pending.points[1].y, State.width)}
    elseif drawing.pending.mode == 'line' or drawing.pending.mode == 'manhattan' then
    if drawing.pending.vertices == nil then
    drawing.pending.vertices = {drawing.pending.p1}
    end
    elseif drawing.pending.mode == 'polygon' or drawing.pending.mode == 'square' then
    -- reuse existing (1-2) vertices
    elseif drawing.pending.mode == 'circle' or drawing.pending.mode == 'arc' then
    drawing.pending.vertices = {drawing.pending.center}
    end
    drawing.pending.mode = 'rectangle'
    elseif chord == 'C-s' and not App.mouse_down(1) then
    State.current_drawing_mode = 'square'
    elseif App.mouse_down(1) and chord == 's' then
    State.current_drawing_mode = 'square'
    local _,drawing = Drawing.current_drawing(State)
    if drawing.pending.mode == 'freehand' then
    drawing.pending.vertices = {Drawing.find_or_insert_point(drawing.points, drawing.pending.points[1].x, drawing.pending.points[1].y, State.width)}
    elseif drawing.pending.mode == 'line' or drawing.pending.mode == 'manhattan' then
    if drawing.pending.vertices == nil then
    drawing.pending.vertices = {drawing.pending.p1}
    end
    elseif drawing.pending.mode == 'polygon' then
    while #drawing.pending.vertices > 2 do
    table.remove(drawing.pending.vertices)
    end
    elseif drawing.pending.mode == 'rectangle' then
    -- reuse existing (1-2) vertices
    elseif drawing.pending.mode == 'circle' or drawing.pending.mode == 'arc' then
    drawing.pending.vertices = {drawing.pending.center}
    end
    drawing.pending.mode = 'square'
    elseif App.mouse_down(1) and chord == 'p' and State.current_drawing_mode == 'polygon' then
    local j = Drawing.find_or_insert_point(drawing.points, mx,my, State.width)
    table.insert(drawing.pending.vertices, j)
    elseif App.mouse_down(1) and chord == 'p' and (State.current_drawing_mode == 'rectangle' or State.current_drawing_mode == 'square') then
    local j = Drawing.find_or_insert_point(drawing.points, mx,my, State.width)
    while #drawing.pending.vertices >= 2 do
    table.remove(drawing.pending.vertices)
    end
    table.insert(drawing.pending.vertices, j)
    elseif chord == 'C-o' and not App.mouse_down(1) then
    State.current_drawing_mode = 'circle'
    elseif App.mouse_down(1) and chord == 'a' and State.current_drawing_mode == 'circle' then
    drawing.pending.mode = 'arc'
    local center = drawing.points[drawing.pending.center]
    drawing.pending.radius = round(geom.dist(center.x,center.y, mx,my))
    drawing.pending.start_angle = geom.angle(center.x,center.y, mx,my)
    elseif App.mouse_down(1) and chord == 'o' then
    State.current_drawing_mode = 'circle'
    local _,drawing = Drawing.current_drawing(State)
    if drawing.pending.mode == 'freehand' then
    drawing.pending.center = Drawing.find_or_insert_point(drawing.points, drawing.pending.points[1].x, drawing.pending.points[1].y, State.width)
    elseif drawing.pending.mode == 'line' or drawing.pending.mode == 'manhattan' then
    drawing.pending.center = drawing.pending.p1
    elseif drawing.pending.mode == 'polygon' or drawing.pending.mode == 'rectangle' or drawing.pending.mode == 'square' then
    drawing.pending.center = drawing.pending.vertices[1]
    end
    drawing.pending.mode = 'circle'
    elseif chord == 'C-u' and not App.mouse_down(1) then
    if drawing then
    if State.previous_drawing_mode == nil then
    State.previous_drawing_mode = State.current_drawing_mode
    end
    State.current_drawing_mode = 'move'
    drawing.pending = {mode=State.current_drawing_mode, target_point=p, target_point_index=i}
    State.lines.current_drawing_index = drawing_index
    State.lines.current_drawing = drawing
    end
    elseif chord == 'C-n' and not App.mouse_down(1) then
    if drawing then
    if State.previous_drawing_mode == nil then
    -- don't clobber
    State.previous_drawing_mode = State.current_drawing_mode
    end
    State.current_drawing_mode = 'name'
    p.name = ''
    drawing.pending = {mode=State.current_drawing_mode, target_point=point_index}
    State.lines.current_drawing_index = drawing_index
    State.lines.current_drawing = drawing
    end
    elseif chord == 'C-d' and not App.mouse_down(1) then
    local _,drawing,_,i,p = Drawing.select_point_at_mouse(State)
    if drawing then
    for _,shape in ipairs(drawing.shapes) do
    if Drawing.contains_point(shape, i) then
    if shape.mode == 'polygon' then
    local idx = table.find(shape.vertices, i)
    table.remove(shape.vertices, idx)
    if #shape.vertices < 3 then
    shape.mode = 'deleted'
    end
    else
    shape.mode = 'deleted'
    end
    end
    end
    drawing.points[i].deleted = true
    end
    local drawing,_,_,shape = Drawing.select_shape_at_mouse(State)
    if drawing then
    shape.mode = 'deleted'
    end
    elseif chord == 'C-h' and not App.mouse_down(1) then
    local drawing = Drawing.select_drawing_at_mouse(State)
    if drawing then
    drawing.show_help = true
    end
    elseif chord == 'escape' and App.mouse_down(1) then
    local _,drawing = Drawing.current_drawing(State)
    drawing.pending = {}
    end
    end
    function Drawing.complete_rectangle(firstx,firsty, secondx,secondy, x,y)
    if firstx == secondx then
    return x,secondy, x,firsty
    end
    if firsty == secondy then
    return secondx,y, firstx,y
    end
    local first_slope = (secondy-firsty)/(secondx-firstx)
    -- slope of second edge:
    -- -1/first_slope
    -- equation of line containing the second edge:
    -- y-secondy = -1/first_slope*(x-secondx)
    -- => 1/first_slope*x + y + (- secondy - secondx/first_slope) = 0
    -- now we want to find the point on this line that's closest to the mouse pointer.
    -- https://en.wikipedia.org/wiki/Distance_from_a_point_to_a_line#Line_defined_by_an_equation
    local a = 1/first_slope
    local c = -secondy - secondx/first_slope
    local thirdx = round(((x-a*y) - a*c) / (a*a + 1))
    local thirdy = round((a*(-x + a*y) - c) / (a*a + 1))
    -- slope of third edge = first_slope
    -- equation of line containing third edge:
    -- y - thirdy = first_slope*(x-thirdx)
    -- => -first_slope*x + y + (-thirdy + thirdx*first_slope) = 0
    -- now we want to find the point on this line that's closest to the first point
    local a = -first_slope
    local c = -thirdy + thirdx*first_slope
    local fourthx = round(((firstx-a*firsty) - a*c) / (a*a + 1))
    local fourthy = round((a*(-firstx + a*firsty) - c) / (a*a + 1))
    return thirdx,thirdy, fourthx,fourthy
    end
    function Drawing.complete_square(firstx,firsty, secondx,secondy, x,y)
    -- use x,y only to decide which side of the first edge to complete the square on
    local deltax = secondx-firstx
    local deltay = secondy-firsty
    local thirdx = secondx+deltay
    local thirdy = secondy-deltax
    if not geom.same_side(firstx,firsty, secondx,secondy, thirdx,thirdy, x,y) then
    deltax = -deltax
    deltay = -deltay
    thirdx = secondx+deltay
    thirdy = secondy-deltax
    end
    local fourthx = firstx+deltay
    local fourthy = firsty-deltax
    return thirdx,thirdy, fourthx,fourthy
    end
    function Drawing.current_drawing(State)
    local x, y = App.mouse_x(), App.mouse_y()
    for drawing_index,drawing in ipairs(State.lines) do
    if drawing.mode == 'drawing' then
    end
    end
    end
    return nil
    end
    function Drawing.select_shape_at_mouse(State)
    for drawing_index,drawing in ipairs(State.lines) do
    if drawing.mode == 'drawing' then
    local x, y = App.mouse_x(), App.mouse_y()
    for i,shape in ipairs(drawing.shapes) do
    if geom.on_shape(mx,my, drawing, shape) then
    end
    end
    end
    end
    end
    end
    function Drawing.select_point_at_mouse(State)
    for drawing_index,drawing in ipairs(State.lines) do
    if drawing.mode == 'drawing' then
    local x, y = App.mouse_x(), App.mouse_y()
    for i,point in ipairs(drawing.points) do
    if Drawing.near(point, mx,my, State.width) then
    end
    end
    end
    end
    end
    end
    function Drawing.select_drawing_at_mouse(State)
    for drawing_index,drawing in ipairs(State.lines) do
    if drawing.mode == 'drawing' then
    local x, y = App.mouse_x(), App.mouse_y()
    return drawing
    end
    end
    end
    end
    function Drawing.contains_point(shape, p)
    if shape.mode == 'freehand' then
    -- not supported
    elseif shape.mode == 'line' or shape.mode == 'manhattan' then
    return shape.p1 == p or shape.p2 == p
    elseif shape.mode == 'polygon' or shape.mode == 'rectangle' or shape.mode == 'square' then
    return table.find(shape.vertices, p)
    elseif shape.mode == 'circle' then
    return shape.center == p
    elseif shape.mode == 'arc' then
    return shape.center == p
    -- ugh, how to support angles
    elseif shape.mode == 'deleted' then
    -- already done
    else
    end
    end
    function Drawing.smoothen(shape)
    for _=1,7 do
    for i=2,#shape.points-1 do
    local a = shape.points[i-1]
    local b = shape.points[i]
    local c = shape.points[i+1]
    b.x = round((a.x + b.x + c.x)/3)
    b.y = round((a.y + b.y + c.y)/3)
    end
    end
    end
    function round(num)
    return math.floor(num+.5)
    end
    function Drawing.find_or_insert_point(points, x,y, width)
    -- check if UI would snap the two points together
    for i,point in ipairs(points) do
    if Drawing.near(point, x,y, width) then
    return i
    end
    end
    table.insert(points, {x=x, y=y})
    return #points
    end
    function Drawing.near(point, x,y, width)
    local px,py = Drawing.pixels(x, width),Drawing.pixels(y, width)
    local cx,cy = Drawing.pixels(point.x, width), Drawing.pixels(point.y, width)
    return (cx-px)*(cx-px) + (cy-py)*(cy-py) < Same_point_distance*Same_point_distance
    end
    function Drawing.pixels(n, width) -- parts to pixels
    return math.floor(n*width/256)
    end
    function Drawing.coord(n, width) -- pixels to parts
    return math.floor(n*256/width)
    end
    function table.find(h, x)
    for k,v in pairs(h) do
    if v == x then
    return k
    end
    end
    end
  • file deletion: source_text.lua (----------)source_text.lua (----------)
    [8.2][8.147125:147164](),[8.2][8.147125:147164](),[8.147164][8.83786:83786]()
    function Text.keychord_press(State, chord, key, scancode, is_repeat)
    --? print('chord', chord, State.selection1.line, State.selection1.pos)
  • file deletion: source_edit.lua (----------)source_edit.lua (----------)
    [8.2][8.165788:165827](),[8.2][8.165788:165827](),[8.165827][8.152503:152503]()
    function edit.mouse_press(State, x,y, mouse_button, is_touch, presses)
    Drawing.mouse_press(State, line_index, x,y, mouse_button, is_touch, presses)
    function edit.mouse_release(State, x,y, mouse_button, is_touch, presses)
    Drawing.mouse_release(State, x,y, mouse_button, is_touch, presses)
    function edit.keychord_press(State, chord, key, scancode, is_repeat)
    Drawing.keychord_press(State, chord, key, scancode, is_repeat)
    Text.keychord_press(State, chord, key, scancode, is_repeat)
    end
    end
    record_undo_event(State, {before=before, after=snapshot(State, drawing_index)})
    schedule_save(State)
    end
    elseif chord == 'escape' and not App.mouse_down(1) then
    for _,line in ipairs(State.lines) do
    if line.mode == 'drawing' then
    line.show_help = false
    end
    end
    if State.selection1.line and
    not State.lines.current_drawing and
    -- printable character created using shift key => delete selection
    -- (we're not creating any ctrl-shift- or alt-shift- combinations using regular/printable keys)
    (not App.shift_down() or utf8.len(key) == 1) and
    if Drawing.before then
    record_undo_event(State, {before=Drawing.before, after=snapshot(State, State.lines.current_drawing_index)})
    Drawing.before = nil
    end
    if State.search_term then return end
    return
    if State.search_term then return end
  • file deletion: source.lua (----------)source.lua (----------)
    [8.2][8.177715:177749](),[8.2][8.177715:177749](),[8.177749][8.165829:165829]()
    function source.initialize(arg, unfiltered_arg)
    function source.resize(w,h)
    function source.mouse_press(x,y, mouse_button, is_touch, presses)
    edit.mouse_press(Editor_state, x,y, mouse_button, is_touch, presses)
    edit.mouse_press(Editor_state, x,y, mouse_button, is_touch, presses)
    log_browser.mouse_press(Log_browser_state, x,y, mouse_button, is_touch, presses)
    function source.mouse_release(x,y, mouse_button, is_touch, presses)
    return edit.mouse_release(Editor_state, x,y, mouse_button, is_touch, presses)
    return log_browser.mouse_release(Log_browser_state, x,y, mouse_button, is_touch, presses)
    function source.keychord_press(chord, key, scancode, is_repeat)
    return edit.keychord_press(Editor_state, chord, key, scancode, is_repeat)
    return log_browser.keychord_press(Log_browser_state, chord, key, scancode, is_repeat)
    return log_browser.key_release(Log_browser_state, key, scancode)
    end
    end
    end
    else
    Cursor_time = 0 -- ensure cursor is visible immediately after it moves
    --? print('source keychord')
    if Show_file_navigator then
    end
    end
    else
    Cursor_time = 0 -- ensure cursor is visible immediately after it moves
    if Focus == 'edit' then
    end
    end
    elseif Show_log_browser_side and Log_browser_state.left <= x and x < Log_browser_state.right then
    --? print('click on log_browser side')
    if Focus ~= 'log_browser' then
    Focus = 'log_browser'
    return
    end
    Cursor_time = 0 -- ensure cursor is visible immediately after it moves
    --? print(("Window resized to width: %d and height: %d."):format(w, h))
    App.screen.width, App.screen.height = w, h
    Text.redraw_all(Editor_state)
    Editor_state.selection1 = {} -- no support for shift drag while we're resizing
    if Show_log_browser_side then
    Editor_state.right = App.screen.width/2 - Margin_right
    else
    Editor_state.right = App.screen.width-Margin_right
    end
    Log_browser_state.left = App.screen.width/2 + Margin_right
    Log_browser_state.right = App.screen.width-Margin_right
    Editor_state.width = Editor_state.right-Editor_state.left
    Text.tweak_screen_top_and_cursor(Editor_state, Editor_state.left, Editor_state.right)
    --? print('end resize')
    end
    log_new('source')
  • file deletion: run.lua (----------)run.lua (----------)
    [8.2][8.183867:183898](),[8.2][8.183867:183898](),[8.183898][8.178107:178107]()
    function run.initialize(arg, unfiltered_arg)
    function run.resize(w,h)
    function run.mouse_press(x,y, mouse_button, is_touch, presses)
    return edit.mouse_press(Editor_state, x,y, mouse_button, is_touch, presses)
    function run.mouse_release(x,y, mouse_button, is_touch, presses)
    return edit.mouse_release(Editor_state, x,y, mouse_button, is_touch, presses)
    function run.keychord_press(chord, key, scancode, is_repeat)
    return edit.keychord_press(Editor_state, chord, key, scancode, is_repeat)
    end
    Cursor_time = 0 -- ensure cursor is visible immediately after it moves
    end
    Cursor_time = 0 -- ensure cursor is visible immediately after it moves
    end
    Cursor_time = 0 -- ensure cursor is visible immediately after it moves
    --? print(("Window resized to width: %d and height: %d."):format(w, h))
    App.screen.width, App.screen.height = w, h
    Text.redraw_all(Editor_state)
    Editor_state.selection1 = {} -- no support for shift drag while we're resizing
    Editor_state.right = App.screen.width-Margin_right
    Editor_state.width = Editor_state.right-Editor_state.left
    Text.tweak_screen_top_and_cursor(Editor_state, Editor_state.left, Editor_state.right)
    end
    log_new('run')
  • file deletion: log_browser.lua (----------)log_browser.lua (----------)
    [8.2][8.202684:202723](),[8.2][8.202684:202723](),[8.202723][8.191243:191243]()
    function log_browser.mouse_press(State, x,y, mouse_button, is_touch, presses)
    function log_browser.mouse_release(State, x,y, mouse_button, is_touch, presses)
    function log_browser.keychord_press(State, chord, key, scancode, is_repeat)
    -- move
    if chord == 'up' then
    end
    function log_browser.mouse_wheel_move(State, dx,dy)
    if dy > 0 then
    for i=1,math.floor(dy) do
    log_browser.up(State)
    end
    elseif dy < 0 then
    for i=1,math.floor(-dy) do
    log_browser.down(State)
    end
    end
    local line_index = log_browser.line_index(State, x,y)
    if line_index == nil then
    -- below lower margin
    return
    end
    -- leave some space to click without focusing
    local line = State.lines[line_index]
    local xleft = log_browser.left_margin(State, line)
    local xright = log_browser.right_margin(State, line)
    if x < xleft or x > xright then
    return
    end
    -- if it's a section begin/end and the section is collapsed, expand it
    -- TODO: how to collapse?
    if line.section_begin or line.section_end then
    -- HACK: get section reference from next/previous line
    local new_section
    if line.section_begin then
    if line_index < #State.lines then
    local next_section_stack = State.lines[line_index+1].section_stack
    if next_section_stack then
    new_section = next_section_stack[#next_section_stack]
    end
    end
    elseif line.section_end then
    if line_index > 1 then
    local previous_section_stack = State.lines[line_index-1].section_stack
    if previous_section_stack then
    new_section = previous_section_stack[#previous_section_stack]
    end
    end
    end
    if new_section and new_section.expanded == nil then
    new_section.expanded = true
    return
    end
    end
    -- open appropriate file in source side
    if line.filename ~= Editor_state.filename then
    source.switch_to_file(line.filename)
    end
    -- set cursor
  • resurrect zombie in main.lua at line 39
    [8.1016][8.134:162](),[8.1016][8.134:162]()
    -- called only for real run
  • edit in main.lua at line 40
    [8.162]
    [8.2424]
    function App.initialize(arg, unfiltered_arg)
  • edit in main.lua at line 47
    [8.2567][8.164:164](),[8.1016][8.2011:2056](),[8.1016][8.2011:2056](),[8.187174][8.2057:2097](),[8.187174][8.2057:2097](),[8.187236][8.2098:2141](),[8.187236][8.2098:2141](),[8.187236][8.2098:2141]()
    function App.initialize(arg, unfiltered_arg)
    run.initialize(arg, unfiltered_arg)
    source.initialize(arg, unfiltered_arg)
  • resolve order conflict in main.lua at line 47
    [8.2567]
    [8.187263]
  • replacement in main.lua at line 227
    [8.6775][8.6775:6820]()
    function App.mousepressed(x,y, mouse_button)
    [8.6775]
    [8.6820]
    function App.mousepressed(x,y, mouse_button, is_touch, presses)
  • replacement in main.lua at line 230
    [4.84][8.8:67](),[8.6894][8.8:67]()
    return edit.mouse_press(Editor_state, x,y, mouse_button)
    [4.84]
    [8.6955]
    return edit.mouse_press(Editor_state, x,y, mouse_button, is_touch, presses)
  • replacement in main.lua at line 233
    [8.6960][8.6960:7006]()
    function App.mousereleased(x,y, mouse_button)
    [8.6960]
    [8.7006]
    function App.mousereleased(x,y, mouse_button, is_touch, presses)
  • replacement in main.lua at line 235
    [8.7080][8.68:129]()
    return edit.mouse_release(Editor_state, x,y, mouse_button)
    [8.7080]
    [8.7142]
    return edit.mouse_release(Editor_state, x,y, mouse_button, is_touch, presses)
  • replacement in main.lua at line 255
    [8.7306][8.11:11](),[8.11][8.12:67]()
    return edit.keychord_press(Editor_state, chord, key)
    [8.7306]
    [2.12]
    return edit.keychord_press(Editor_state, chord, key, scancode, is_repeat)
  • edit in main.lua at line 271
    [8.213][7.2094:2094](),[8.213][7.2094:2094](),[8.213][7.2094:2094](),[8.361][7.2095:2159](),[8.361][7.2095:2159](),[8.361][7.2095:2159](),[8.190137][7.2160:2246](),[8.190137][7.2160:2246](),[8.190246][7.2248:2248](),[8.190246][7.2248:2248](),[7.2248][7.2249:2341](),[7.2248][7.2249:2341](),[7.2248][7.2249:2341](),[8.842][8.823:883](),[8.946][8.823:883](),[7.2341][8.823:883](),[8.2884][8.823:883](),[8.5101][8.823:883](),[8.842][8.823:883](),[8.5101][8.823:883]()
    function App.mousepressed(x,y, mouse_button, is_touch, presses)
    if run.mouse_press then run.mouse_press(x,y, mouse_button, is_touch, presses) end
    if source.mouse_press then source.mouse_press(x,y, mouse_button, is_touch, presses) end
    else
    assert(false, 'unknown app "'..Current_app..'"')
  • resurrect zombie in main.lua at line 271
    [8.883][8.883:889](),[8.883][8.883:889](),[8.883][8.883:889](),[8.883][8.883:889](),[8.883][8.883:889](),[8.883][8.883:889](),[8.883][8.883:889]()
    end
  • edit in main.lua at line 272
    [8.889][8.889:893](),[8.172][8.889:893](),[8.889][8.889:893](),[8.889][8.889:893](),[8.889][8.889:893](),[8.893][8.893:894](),[8.893][8.893:894](),[8.893][8.893:894](),[8.894][7.2342:2407](),[8.894][7.2342:2407](),[8.894][7.2342:2407](),[7.2407][8.21:21](),[8.889][8.21:21](),[8.143][7.2408:2498](),[8.143][7.2408:2498](),[8.93][8.196:234](),[7.2498][8.196:234](),[8.2953][8.196:234](),[8.196][8.196:234](),[8.93][8.196:234](),[8.196][8.196:234](),[8.466][8.634:634](),[8.634][8.201:207](),[8.466][8.201:207]()
    end
    function App.mousereleased(x,y, mouse_button, is_touch, presses)
    if run.mouse_release then run.mouse_release(x,y, mouse_button, is_touch, presses) end
    elseif Current_app == 'source' then
    end
  • resolve order conflict in main.lua at line 272
    [8.889]
    [8.207]
  • edit in main.lua at line 274
    [8.336][3.12:12](),[8.234][7.2499:2595](),[8.234][7.2499:2595](),[8.171][8.293:359](),[7.2595][8.293:359](),[8.3028][8.293:359](),[8.293][8.293:359](),[8.171][8.293:359](),[8.293][8.293:359]()
    if source.mouse_release then source.mouse_release(x,y, mouse_button, is_touch, presses) end
    else
    assert(false, 'unknown app "'..Current_app..'"')
    end
  • resurrect zombie in main.lua at line 274
    [8.359][8.359:363](),[8.359][8.359:363](),[8.359][8.359:363](),[8.359][8.359:363](),[8.359][8.359:363](),[8.359][8.359:363]()
    end
  • edit in main.lua at line 275
    [8.363][8.363:364](),[8.363][8.363:364](),[8.889][8.925:956](),[8.1144][8.925:956](),[8.1404][8.925:956](),[8.925][8.925:956](),[8.889][8.925:956](),[8.925][8.925:956](),[8.956][7.2596:2664](),[8.956][7.2596:2664](),[8.272][8.1021:1059](),[8.961][8.1021:1059](),[7.2664][8.1021:1059](),[8.1021][8.1021:1059](),[8.961][8.1021:1059](),[8.1021][8.1021:1059](),[8.1059][7.2665:2739](),[8.1059][7.2665:2739](),[8.1059][7.2665:2739](),[3.12][8.151:155](),[8.12][8.151:155](),[8.12][8.151:155](),[8.151][8.151:155](),[8.155][7.2741:2741](),[8.189628][8.2204:2291](),[8.189628][8.2204:2291](),[8.189736][8.2292:2385](),[8.189736][8.2292:2385]()
    if Current_app == 'run' then
    if run.mouse_move then run.mouse_move(x,y, dx,dy, is_touch) end
    elseif Current_app == 'source' then
    if source.mouse_move then source.mouse_move(x,y, dx,dy, is_touch) end
    end
    if run.keychord_press then run.keychord_press(chord, key, scancode, is_repeat) end
    if source.keychord_press then source.keychord_press(chord, key, scancode, is_repeat) end
  • resolve order conflict in main.lua at line 275
    [8.363]