intermingle freehand line drawings with text

[?]
May 11, 2022, 4:17 AM
XX7G2FFJ4QCGQGD4REAW5QFHVYAKCFUPGZCK7L6DFGS5ISVBYBQQC

Dependencies

Change contents

  • edit in main.lua at line 2
    [5.21]
    [3.2]
    require 'button'
  • edit in main.lua at line 17
    [5.209]
    [5.209]
    button_handlers = {}
  • edit in main.lua at line 20
    [5.302][2.2:88]()
    love.graphics.setColor(1, 1, 0)
    love.graphics.rectangle('fill', 1, 1, 400, 10*12)
  • edit in main.lua at line 22
    [5.15]
    [5.336]
    local y = 0
  • edit in main.lua at line 24
    [5.370]
    [5.16]
    y = y+25
  • replacement in main.lua at line 26
    [5.80][5.80:119]()
    love.graphics.draw(text, 12, i*15)
    [5.80]
    [5.410]
    if line == '' then
    button('draw', {x=4,y=y+4, w=12,h=12, color={1,1,0},
    icon = function(x, y)
    love.graphics.setColor(0.7,0.7,0.7)
    love.graphics.rectangle('line', x,y, 12,12)
    love.graphics.line(4,y+6, 16,y+6)
    love.graphics.line(10,y, 10,y+12)
    love.graphics.setColor(0, 0, 0)
    end,
    onpress1 = function()
    table.insert(lines, i, {y=y, w=400, h=200, pending={}, shapes={}})
    end})
    elseif type(line) == 'table' then
    -- line drawing
    love.graphics.setColor(0,0,0)
    line.y = y
    love.graphics.rectangle('line', 12,y, line.w,line.h)
    y = y+line.h
    for _,shape in ipairs(line.shapes) do
    prev = nil
    for _,point in ipairs(shape) do
    if prev then
    love.graphics.line(prev.x,prev.y, point.x,point.y)
    end
    prev = point
    end
    end
    prev = nil
    for _,point in ipairs(line.pending) do
    if prev then
    love.graphics.line(prev.x,prev.y, point.x,point.y)
    end
    prev = point
    end
    else
    love.graphics.draw(text, 25,y, 0, 1.5)
    end
  • replacement in main.lua at line 66
    [5.132][5.132:190]()
    love.graphics.print('_', 12+text:getWidth(), #lines*15)
    [5.132]
    [4.22]
    love.graphics.print('_', 25+text:getWidth()*1.5, y)
  • edit in main.lua at line 74
    [5.446]
    [5.446]
    if love.mouse.isDown('1') then
    for i, line in ipairs(lines) do
    if type(line) == 'table' then
    local y = love.mouse.getY()
    if y >= line.y and y < line.y + line.h then
    lines.current = line
    process_drag(line,love.mouse.getX(),love.mouse.getY())
    end
    end
    end
    end
    end
    function process_drag(drawing, x,y)
    table.insert(drawing.pending, {x=x, y=y})
  • edit in main.lua at line 91
    [5.451]
    [5.23]
    function love.mousereleased(x,y, button)
    if lines.current then
    if lines.current.pending then
    table.insert(lines.current.shapes, lines.current.pending)
    lines.current.pending = {}
    lines.current = nil
    end
    end
    end
  • replacement in main.lua at line 129
    [5.417][5.607:612](),[5.607][5.607:612](),[5.612][5.418:460]()
    end
    function love.mousereleased(x, y, button)
    [5.417]
    [5.460]
    propagate_to_button_handers(x, y, button)
  • file addition: button.lua (----------)
    [11.2]
    button_handlers = {}
    -- draw button and queue up event handlers
    function button(name, params)
    love.graphics.setColor(params.color[1], params.color[2], params.color[3])
    love.graphics.rectangle('fill', params.x,params.y, params.w,params.h, 5,5)
    if params.icon then params.icon(params.x, params.y) end
    table.insert(button_handlers, params)
    end
    -- process button event handlers
    function propagate_to_button_handers(x, y, button)
    for _,ev in ipairs(button_handlers) do
    if x>ev.x and x<ev.x+ev.w and y>ev.y and y<ev.y+ev.h then
    if ev.onpress1 and button == 1 then ev.onpress1() end
    end
    end
    end