store device-independent coordinates inside drawings

[?]
May 12, 2022, 3:29 PM
JVRL5TWLBTWMTHJDZSDN5XQDMEIIPVAZBKUP75HMO7JHURAYWG5QC

Dependencies

  • [2] L5USRTY2 inline
  • [3] MNWHXPBL more lightweight; select just the stroke at the mouse
  • [4] 3XD6M3CF refactor
  • [5] 2C7CTIQY make space for multiple kinds of width
  • [6] YHQC72JX slightly tweak boundary between concerns
  • [7] EFMLTMZG bugfix: restrict strokes to the drawing they started in
  • [8] POT3XFCT rename
  • [9] G77XIN7M selecting a stroke
  • [10] WAZVXUV2 simplest possible way to straighten strokes
  • [11] R3WSFYGY spacing
  • [12] OTIBCAUJ love2d scaffold
  • [13] T76KKDWZ turn strokes into horizontal and vertical lines
  • [14] Z2CJVAPV lighter border for figures
  • [15] XX7G2FFJ intermingle freehand line drawings with text
  • [16] TRCAEE2A clip drawings inside the border
  • [*] IZZVOCLB confirm that we have access to all of the love API

Change contents

  • edit in main.lua at line 8
    [5.45]
    [18.2]
    -- All drawings span 100% of some conceptual 'page width' and divide it up
    -- into 256 parts. `drawingw` describes their width in pixels.
    drawingw = 400 -- pixels
    function pixels(n) -- parts to pixels
    return n*drawingw/256
    end
    function coord(n) -- pixels to parts
    return math.floor(n*256/drawingw)
    end
  • replacement in main.lua at line 48
    [7.500][7.500:588]()
    table.insert(lines, i, {y=y, w=400, h=200, pending={}, shapes={}})
    [7.500]
    [7.588]
    table.insert(lines, i, {y=y, h=256/2, pending={}, shapes={}})
  • replacement in main.lua at line 54
    [7.785][7.785:804](),[7.804][6.3:67]()
    y = y+line.h
    love.graphics.rectangle('line', 12,line.y, line.w,line.h)
    [7.726]
    [7.804]
    y = y+pixels(line.h)
    love.graphics.rectangle('line', 12,line.y, drawingw,pixels(line.h))
    local mx,my = coord(love.mouse.getX()-12), coord(love.mouse.getY()-line.y)
  • replacement in main.lua at line 60
    [7.849][3.3:75]()
    if on_freehand(love.mouse.getX(),love.mouse.getY(), shape) then
    [7.849]
    [7.45]
    if on_freehand(mx,my, shape) then
  • replacement in main.lua at line 68
    [7.931][7.931:994]()
    love.graphics.line(prev.x,prev.y, point.x,point.y)
    [7.931]
    [7.994]
    love.graphics.line(pixels(prev.x)+12,pixels(prev.y)+line.y, pixels(point.x)+12,pixels(point.y)+line.y)
  • replacement in main.lua at line 76
    [7.1136][7.1136:1197]()
    love.graphics.line(prev.x,prev.y, point.x,point.y)
    [7.1136]
    [7.1197]
    love.graphics.line(pixels(prev.x)+12,pixels(prev.y)+line.y, pixels(point.x)+12,pixels(point.y)+line.y)
  • replacement in main.lua at line 99
    [7.60][7.33:127](),[7.161][2.3:87]()
    if y >= drawing.y and y < drawing.y + drawing.h and x >= 12 and x < 12+drawing.w then
    table.insert(drawing.pending, {x=love.mouse.getX(), y=love.mouse.getY()})
    [7.60]
    [7.1647]
    if y >= drawing.y and y < drawing.y + pixels(drawing.h) and x >= 12 and x < 12+drawingw then
    table.insert(drawing.pending, {x=coord(love.mouse.getX()-12), y=coord(love.mouse.getY()-drawing.y)})
  • replacement in main.lua at line 116
    [7.316][7.316:408]()
    if y >= drawing.y and y < drawing.y + drawing.h and x >= 12 and x < 12+drawing.w then
    [7.316]
    [7.408]
    if y >= drawing.y and y < drawing.y + pixels(drawing.h) and x >= 12 and x < 12+drawingw then
  • replacement in main.lua at line 207
    [4.292][4.292:384]()
    if y >= drawing.y and y < drawing.y + drawing.h and x >= 12 and x < 12+drawing.w then
    [4.292]
    [4.384]
    if y >= drawing.y and y < drawing.y + pixels(drawing.h) and x >= 12 and x < 12+drawingw then
    local mx,my = coord(love.mouse.getX()-12), coord(love.mouse.getY()-drawing.y)
  • replacement in main.lua at line 210
    [4.433][4.433:507]()
    if on_freehand(love.mouse.getX(),love.mouse.getY(), shape) then
    [4.433]
    [4.507]
    if on_freehand(mx,my, shape) then