abort: switch to LÖVE's coordinate transforms

This is a big change, and I'd have to first modify lines.love to use the
coordinate transforms. And that fork doesn't really need a principled
coordinate system.
This commit is contained in:
Kartik K. Agaram 2023-10-25 09:28:14 -07:00
parent c2f765489a
commit f54e1ad064
10 changed files with 31 additions and 61 deletions

View File

@ -1,4 +0,0 @@
vx = function(sx)
-- turn surface coordinates into viewport coordinates
return scale(sx-Viewport.x)
end

View File

@ -1,3 +0,0 @@
scale = function(d)
return d*Viewport.zoom
end

View File

@ -1,4 +0,0 @@
vy = function(sy)
-- turn surface coordinates into viewport coordinates
return scale(sy-Viewport.y)
end

View File

@ -1,11 +1,12 @@
to_text = function(x,y)
local sx, sy = x/Viewport.zoom + Viewport.x, y/Viewport.zoom + Viewport.y
for _,node in ipairs(Surface) do
if node.type == 'text' then
if x >= vx(node.x) and node.w and x < vx(node.x + node.w) then
if y >= vy(node.y) and node.h and y < vy(node.y + node.h) then
if sx >= node.x and node.w and sx < node.x + node.w then
if sy >= node.y and node.h and sy < node.y + node.h then
return node
end
end
end
end
end
end

View File

@ -1,10 +1,8 @@
initialize_editor = function(obj)
if obj.w then
-- use an editor to wrap the text
local scaled_fontsize = scale(20)
local scaled_lineheight = math.floor(scaled_fontsize*1.3)
obj.editor = edit.initialize_state(vy(obj.y), math.floor(vx(obj.x)), math.ceil(vx(obj.x+obj.w)), scaled_fontsize, scaled_lineheight)
obj.editor = edit.initialize_state(obj.y, obj.x, obj.x+obj.w, 20, math.floor(20*1.3))
obj.editor.lines = load_array(obj.data)
Text.redraw_all(obj.editor)
end
end
end

View File

@ -1,3 +1,4 @@
on.initialize = function()
love.graphics.setFont(love.graphics.newFont(20))
A()
end
end

24
0019-B
View File

@ -1,26 +1,2 @@
B = function()
print('B')
-- recompute various aspects based on the current viewport settings
for _,obj in ipairs(Surface) do
if obj.type == 'line' then
obj.zdata = {}
for i=1,#obj.data,2 do
table.insert(obj.zdata, vx(obj.data[i]))
table.insert(obj.zdata, vy(obj.data[i+1]))
end
elseif obj.type == 'bezier' then
zdata = {}
for i=1,#obj.data,2 do
table.insert(zdata, vx(obj.data[i]))
table.insert(zdata, vy(obj.data[i+1]))
end
obj.zdata = love.math.newBezierCurve(zdata):render()
elseif obj.type == 'text' then
if obj.w then
update_editor_box(obj)
else
obj.text = love.graphics.newText(love.graphics.getFont(), obj.data)
end
end
end
end

View File

@ -1,29 +1,33 @@
on.draw = function()
-- vx = x, vy = y
love.graphics.translate(-Viewport.x, -Viewport.y)
-- vx = x-Viewport.x, vy = y-Viewport.y
love.graphics.scale(Viewport.zoom)
-- vx = (x-Viewport.x)*Viewport.zoom, vy = (y-Viewport.y)*Viewport.zoom
love.graphics.setColor(0,0,0)
love.graphics.line(vx(0), vy(0), vx(0), vy(1000000))
love.graphics.line(vx(0), vy(0), vx(1000000), vy(0))
love.graphics.line(0, 0, 0, 1000000)
love.graphics.line(0, 0, 1000000, 0)
for i=1,100 do
love.graphics.print(tostring(i), vx(0), vy(i*1000))
love.graphics.print(tostring(i), 0, i*1000)
end
for _,obj in ipairs(Surface) do
love.graphics.setColor(obj.r or 0, obj.g or 0, obj.b or 0)
if obj.type == 'rectangle' then
love.graphics.rectangle(obj.drawmode or 'fill', vx(obj.x),vy(obj.y), scale(obj.w),scale(obj.h), scale(obj.rx or 0),scale(obj.ry or obj.rx or 0))
love.graphics.rectangle(obj.drawmode or 'fill', obj.x,obj.y, obj.w,obj.h, obj.rx or 0,obj.ry or obj.rx or 0)
elseif obj.type == 'line' then
love.graphics.line(unpack(obj.zdata))
love.graphics.line(unpack(obj.data))
elseif obj.type == 'circle' then
love.graphics.circle(obj.drawmode or 'fill', vx(obj.x), vy(obj.y), scale(obj.radius))
love.graphics.circle(obj.drawmode or 'fill', obj.x, obj.y, obj.radius)
elseif obj.type == 'arc' then
love.graphics.arc(obj.drawmode or 'line', obj.arctype or 'open', vx(obj.x), vy(obj.y), scale(obj.radius), obj.angle1, obj.angle2, obj.segments)
love.graphics.arc(obj.drawmode or 'line', obj.arctype or 'open', obj.x, obj.y, obj.radius, obj.angle1, obj.angle2, obj.segments)
elseif obj.type == 'ellipse' then
love.graphics.ellipse(obj.drawmode or 'fill', vx(obj.x), vy(obj.y), scale(obj.radiusx), scale(obj.radiusy))
love.graphics.ellipse(obj.drawmode or 'fill', obj.x, obj.y, obj.radiusx, obj.radiusy)
elseif obj.type == 'bezier' then
love.graphics.line(unpack(obj.zdata))
love.graphics.line(unpack(obj.data))
elseif obj.type == 'text' then
if obj.w == nil then
love.graphics.draw(obj.text, vx(obj.x), vy(obj.y))
love.graphics.draw(obj.text, obj.x, obj.y)
else
print(obj.x, obj.y, obj.editor.top, obj.editor.screen_top1.line)
edit.draw(obj.editor, obj.fg or {r=0,g=0,b=0}, not obj.show_cursor)
end
end

13
0028-A
View File

@ -1,9 +1,10 @@
A = function()
print('A')
love.graphics.setFont(love.graphics.newFont(scale(20))) -- editor objects implicitly depend on current font
-- translate Page to Surface
compute_layout(Page, Page.x,Page.y, Surface)
-- continue the pipeline
B()
-- TODO: ugly that we're manipulating editor objects twice
local red = false
for x=-1000,2000,300 do
for y=-10000,10000,200 do
add_thick_line({type='line', data={x,y, x+200,y+200, x,y+400}, r=red and 1 or 0,g=red and 0 or 0.5,b=0}, 10)
red = not red
end
end
end

View File

@ -5,7 +5,7 @@ update_editor_box = function(node)
node.editor.screen_top1.line = 1
node.editor.screen_top1.pos = 1
end
node.editor.top = vy(node.y)
node.editor.top = node.y
else
node.editor.screen_top1, node.editor.top = schema1_of_y(node.editor, scale(Viewport.y-node.y))
end