ruler = {}
ruler.active = false
ruler.mouse_down = false
ruler.rx = 0
ruler.ry = 0
local function draw()
local mx, my = tpt.mousex, tpt.mousey
local x, y = sim.adjustCoords(ruler.rx,ruler.ry)
local x1, y1 = sim.adjustCoords(mx, my)
local str = tostring(1+math.floor(((x - x1) ^ 2 + (y - y1) ^ 2) ^ 0.5 * 100) / 100) .. "\nX=" ..
tostring(1+math.floor(((x - x1) ^ 2) ^ 0.5 * 100) / 100) .. "\nY=" ..
tostring(1+math.floor(((y - y1) ^ 2) ^ 0.5 * 100) / 100)
gfx.fillRect(mx + 1,my + 1,gfx.textSize(str)+8,40,200,0,0,127) -- color 200 0 0
gfx.drawText(mx + 5, my + 5, str, 200, 200, 200)
end
function ruler.draw()
if ruler.active and ruler.mouse_down then
pcall(draw)
end
end
function ruler.key(_, key, _,event)
-- F4 - 285
if key == 285 and event == 1 then
if ruler.active == true then
ruler.active = false
tpt.log("ruler off")
else
ruler.active = true
tpt.log("ruler on")
end
end
end
function ruler.mouse(mx, my, _, event)
if ruler.active then
ruler.mouse_down = false
if event == 1 then
ruler.rx = mx
ruler.ry = my
end
if event == 3 then
ruler.mouse_down = true
end
end
end
tpt.register_mouseclick(ruler.mouse)
tpt.register_keypress(ruler.key)
tpt.register_step(ruler.draw)
tpt.log("ruler loaded")