Vision:
This commit adds the 2D surface with panning.
VHT5NALKBXY6CZ2AJPLIJ33OSP5X2TF6GTDMIYXVKNIXPZXPAMAAC
on.update = function(dt)
if Pan then
Viewport.x = Pan.x - love.mouse.getX()
Viewport.y = Pan.y - love.mouse.getY()
end
end
{"vx":5,"vy":8,"on":1,"on.mouse_released":13,"scale":7,"on.mouse_pressed":12,"Surface":3,"on.update":14,"on.draw":11,"parent":14,"Viewport":6}
on.mouse_released = function(x,y, mouse_button)
Pan = nil
end
{"vx":5,"vy":8,"on":1,"on.mouse_released":13,"scale":7,"on.mouse_pressed":12,"Surface":3,"on.draw":11,"parent":12,"Viewport":6}
on.mouse_pressed = function(x,y, mouse_button)
Pan = {x=Viewport.x+x,y=Viewport.y+y}
end
{"vx":5,"vy":8,"on":1,"scale":7,"on.mouse_pressed":12,"Surface":3,"on.draw":11,"parent":11,"Viewport":6}
on.draw = function()
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.width),scale(obj.height))
elseif obj.type == 'line' then
if obj.saved_zoom ~= Viewport.zoom or obj.saved_x ~= Viewport.x or obj.saved_y ~= Viewport.y then
obj.saved_zoom = Viewport.zoom
obj.saved_x = Viewport.x
obj.saved_y = Viewport.y
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
end
love.graphics.line(unpack(obj.zdata))
elseif obj.type == 'circle' then
love.graphics.circle(obj.drawmode or 'fill', vx(obj.x), vy(obj.y), scale(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)
elseif obj.type == 'ellipse' then
love.graphics.ellipse(obj.drawmode or 'fill', vx(obj.x), vy(obj.y), scale(obj.radiusx), scale(obj.radiusy))
elseif obj.type == 'text' then
local scaled_fontsize = scale(obj.fontsize or 20)
if obj.scaled_fontsize ~= scaled_fontsize then
obj.scaled_fontsize = scaled_fontsize
if Font == nil then Font = {} end
if Font[scaled_fontsize] == nil then
Font[scaled_fontsize] = love.graphics.newFont(scaled_fontsize)
end
obj.text = love.graphics.newText(Font[scaled_fontsize], obj.data)
end
love.graphics.draw(obj.text, vx(obj.x), vy(obj.y))
elseif obj.type == 'bezier' then
if obj.saved_zoom ~= Viewport.zoom or obj.saved_x ~= Viewport.x or obj.saved_y ~= Viewport.y then
obj.saved_zoom = Viewport.zoom
obj.saved_x = Viewport.x
obj.saved_y = Viewport.y
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()
end
love.graphics.line(unpack(obj.zdata))
end
end
end
{"on":1,"Surface":3,"vx":5,"vy":8,"Viewport":6,"on.draw":11,"parent":10,"scale":7}
on.draw = function()
for _,obj in ipairs(Surface) do
love.graphics.setColor(obj.r or 1, obj.g or 1, obj.b or 1)
if obj.type == 'rectangle' then
love.graphics.rectangle(obj.drawmode or 'fill', vx(obj.x),vy(obj.y), scale(obj.width),scale(obj.height))
elseif obj.type == 'line' then
if obj.saved_zoom ~= Viewport.zoom or obj.saved_x ~= Viewport.x or obj.saved_y ~= Viewport.y then
obj.saved_zoom = Viewport.zoom
obj.saved_x = Viewport.x
obj.saved_y = Viewport.y
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
end
love.graphics.line(unpack(obj.zdata))
elseif obj.type == 'circle' then
love.graphics.circle(obj.drawmode or 'fill', vx(obj.x), vy(obj.y), scale(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)
elseif obj.type == 'ellipse' then
love.graphics.ellipse(obj.drawmode or 'fill', vx(obj.x), vy(obj.y), scale(obj.radiusx), scale(obj.radiusy))
elseif obj.type == 'text' then
local scaled_fontsize = scale(obj.fontsize or 20)
if obj.scaled_fontsize ~= scaled_fontsize then
obj.scaled_fontsize = scaled_fontsize
if Font == nil then Font = {} end
if Font[scaled_fontsize] == nil then
Font[scaled_fontsize] = love.graphics.newFont(scaled_fontsize)
end
obj.text = love.graphics.newText(Font[scaled_fontsize], obj.data)
end
love.graphics.draw(obj.text, vx(obj.x), vy(obj.y))
elseif obj.type == 'bezier' then
if obj.saved_zoom ~= Viewport.zoom or obj.saved_x ~= Viewport.x or obj.saved_y ~= Viewport.y then
obj.saved_zoom = Viewport.zoom
obj.saved_x = Viewport.x
obj.saved_y = Viewport.y
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()
end
love.graphics.line(unpack(obj.zdata))
end
end
end
{"on":1,"Surface":3,"vx":5,"vy":8,"Viewport":6,"on.draw":10,"parent":9,"scale":7}
on.draw = function()
for _,obj in ipairs(Surface) do
color(obj.r or 1, obj.g or 1, obj.b or 1)
if obj.type == 'rectangle' then
love.graphics.rectangle(obj.drawmode or 'fill', vx(obj.x),vy(obj.y), scale(obj.width),scale(obj.height))
elseif obj.type == 'line' then
if obj.saved_zoom ~= Viewport.zoom or obj.saved_x ~= Viewport.x or obj.saved_y ~= Viewport.y then
obj.saved_zoom = Viewport.zoom
obj.saved_x = Viewport.x
obj.saved_y = Viewport.y
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
end
love.graphics.line(unpack(obj.zdata))
elseif obj.type == 'circle' then
love.graphics.circle(obj.drawmode or 'fill', vx(obj.x), vy(obj.y), scale(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)
elseif obj.type == 'ellipse' then
love.graphics.ellipse(obj.drawmode or 'fill', vx(obj.x), vy(obj.y), scale(obj.radiusx), scale(obj.radiusy))
elseif obj.type == 'text' then
local scaled_fontsize = scale(obj.fontsize or 20)
if obj.scaled_fontsize ~= scaled_fontsize then
obj.scaled_fontsize = scaled_fontsize
if Font == nil then Font = {} end
if Font[scaled_fontsize] == nil then
Font[scaled_fontsize] = love.graphics.newFont(scaled_fontsize)
end
obj.text = love.graphics.newText(Font[scaled_fontsize], obj.data)
end
love.graphics.draw(obj.text, vx(obj.x), vy(obj.y))
elseif obj.type == 'bezier' then
if obj.saved_zoom ~= Viewport.zoom or obj.saved_x ~= Viewport.x or obj.saved_y ~= Viewport.y then
obj.saved_zoom = Viewport.zoom
obj.saved_x = Viewport.x
obj.saved_y = Viewport.y
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()
end
love.graphics.line(unpack(obj.zdata))
end
end
end
{"on":1,"Surface":3,"vx":5,"vy":8,"Viewport":6,"on.draw":9,"parent":8,"scale":7}
vy = function(y)
return scale(y-Viewport.y)
end
{"on":1,"Surface":3,"vx":5,"vy":8,"Viewport":6,"on.draw":4,"parent":7,"scale":7}
scale = function(d)
return d*Viewport.zoom
end
{"Surface":3,"vx":5,"on":1,"Viewport":6,"on.draw":4,"parent":6,"scale":7}
{"Surface":3,"vx":5,"Viewport":6,"on.draw":4,"parent":5,"on":1}
Viewport = {x=-50, y=-50, w=800,h=600, zoom=1.5}
vx = function(x)
return scale(x-Viewport.x)
end
{"Surface":3,"vx":5,"on.draw":4,"parent":4,"on":1}
on.draw = function()
for _,obj in ipairs(Surface) do
color(obj.r or 1, obj.g or 1, obj.b or 1)
if obj.type == 'rect' then
rect(obj.drawmode or 'fill', vx(obj.x),vy(obj.y), scale(obj.width),scale(obj.height))
elseif obj.type == 'line' then
if obj.saved_zoom ~= Viewport.zoom or obj.saved_x ~= Viewport.x or obj.saved_y ~= Viewport.y then
obj.saved_zoom = Viewport.zoom
obj.saved_x = Viewport.x
obj.saved_y = Viewport.y
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
end
line(unpack(obj.zdata))
elseif obj.type == 'circle' then
circ(obj.drawmode or 'fill', vx(obj.x), vy(obj.y), scale(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)
elseif obj.type == 'ellipse' then
love.graphics.ellipse(obj.drawmode or 'fill', vx(obj.x), vy(obj.y), scale(obj.radiusx), scale(obj.radiusy))
elseif obj.type == 'text' then
local scaled_fontsize = scale(obj.fontsize or 20)
if obj.scaled_fontsize ~= scaled_fontsize then
obj.scaled_fontsize = scaled_fontsize
if Font == nil then Font = {} end
if Font[scaled_fontsize] == nil then
Font[scaled_fontsize] = love.graphics.newFont(scaled_fontsize)
end
obj.text = love.graphics.newText(Font[scaled_fontsize], obj.data)
end
love.graphics.draw(obj.text, vx(obj.x), vy(obj.y))
elseif obj.type == 'bezier' then
if obj.saved_zoom ~= Viewport.zoom or obj.saved_x ~= Viewport.x or obj.saved_y ~= Viewport.y then
obj.saved_zoom = Viewport.zoom
obj.saved_x = Viewport.x
obj.saved_y = Viewport.y
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()
end
line(unpack(obj.zdata))
end
end
end
{"on.draw":4,"on":1,"Surface":3,"parent":3}
{"on":1,"Surface":3,"parent":2}
Surface = {
-- test data
{type='rect', x=50,y=50, width=20,height=80, r=1,g=0,b=0},
{type='line', data={0,0, 0,600}},
{type='line', data={0,0, 800,0}},
{type='text', data='0', x=-20,y=-20},
{type='circle', x=300,y=200, radius=40, r=1,g=0,b=1},
{type='arc', x=0,y=0, radius=50, angle1=0, angle2=math.pi*2/3},
{type='ellipse', x=100,y=100, radiusx=10, radiusy=50},
{type='bezier', data={25,25, 25,125, 75,25, 125,25}},
}
{"on":1,"Surface":2,"parent":1}
Surface = {
{type='rect', x=50,y=50, width=20,height=80, r=1,g=0,b=0},
{type='line', data={0,0, 0,600}},
{type='line', data={0,0, 800,0}},
{type='text', data='0', x=-20,y=-20},
{type='circle', x=300,y=200, radius=40, r=1,g=0,b=1},
{type='arc', x=0,y=0, radius=50, angle1=0, angle2=math.pi*2/3},
{type='ellipse', x=100,y=100, radiusx=10, radiusy=50},
{type='bezier', data={25,25, 25,125, 75,25, 125,25}},
}