intermingle freehand line drawings with text
[?]
May 11, 2022, 4:17 AM
XX7G2FFJ4QCGQGD4REAW5QFHVYAKCFUPGZCK7L6DFGS5ISVBYBQQCDependencies
- [2]
NZ7V4BVSnote card - [3]
6PUNJS5Bbackspace - [4]
IZZVOCLBconfirm that we have access to all of the love API - [5]
6LJZN727handle chords - [6]
2KRK3OBVdon't rely on defaults - [7]
OTIBCAUJlove2d scaffold - [8]
QU7NHFOVshow cursor - [9]
6Q6XGOFLlittle Lua repl on hitting ctrl-r - [*]
R5QXEHUIsomebody stop me
Change contents
- edit in main.lua at line 2
require 'button' - edit in main.lua at line 17
button_handlers = {} - edit in main.lua at line 20
love.graphics.setColor(1, 1, 0)love.graphics.rectangle('fill', 1, 1, 400, 10*12) - edit in main.lua at line 22
local y = 0 - edit in main.lua at line 24
y = y+25 - replacement in main.lua at line 26
love.graphics.draw(text, 12, i*15)if line == '' thenbutton('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 drawinglove.graphics.setColor(0,0,0)line.y = ylove.graphics.rectangle('line', 12,y, line.w,line.h)y = y+line.hfor _,shape in ipairs(line.shapes) doprev = nilfor _,point in ipairs(shape) doif prev thenlove.graphics.line(prev.x,prev.y, point.x,point.y)endprev = pointendendprev = nilfor _,point in ipairs(line.pending) doif prev thenlove.graphics.line(prev.x,prev.y, point.x,point.y)endprev = pointendelselove.graphics.draw(text, 25,y, 0, 1.5)end - replacement in main.lua at line 66
love.graphics.print('_', 12+text:getWidth(), #lines*15)love.graphics.print('_', 25+text:getWidth()*1.5, y) - edit in main.lua at line 74
if love.mouse.isDown('1') thenfor i, line in ipairs(lines) doif type(line) == 'table' thenlocal y = love.mouse.getY()if y >= line.y and y < line.y + line.h thenlines.current = lineprocess_drag(line,love.mouse.getX(),love.mouse.getY())endendendendendfunction process_drag(drawing, x,y)table.insert(drawing.pending, {x=x, y=y}) - edit in main.lua at line 91
function love.mousereleased(x,y, button)if lines.current thenif lines.current.pending thentable.insert(lines.current.shapes, lines.current.pending)lines.current.pending = {}lines.current = nilendendend - replacement in main.lua at line 129
endfunction love.mousereleased(x, y, button)propagate_to_button_handers(x, y, button) - file addition: button.lua[11.2]
button_handlers = {}-- draw button and queue up event handlersfunction 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) endtable.insert(button_handlers, params)end-- process button event handlersfunction propagate_to_button_handers(x, y, button)for _,ev in ipairs(button_handlers) doif x>ev.x and x<ev.x+ev.w and y>ev.y and y<ev.y+ev.h thenif ev.onpress1 and button == 1 then ev.onpress1() endendendend