summaryrefslogtreecommitdiff
path: root/main.lua
diff options
context:
space:
mode:
authorubq323 <ubq323@ubq323.website>2024-01-05 04:13:36 +0000
committerubq323 <ubq323@ubq323.website>2024-01-05 04:13:36 +0000
commit61eaceff25d668074ef09a003526e8f3280bd471 (patch)
treefc1b651e8f484abd6fd7fad294a0095c944d129a /main.lua
parentbf3fbc24a50c2f4d732fd559f1a81523eeb066c6 (diff)
connect wires to editing handles
Diffstat (limited to 'main.lua')
-rw-r--r--main.lua34
1 files changed, 24 insertions, 10 deletions
diff --git a/main.lua b/main.lua
index ff0d56d..fa41c00 100644
--- a/main.lua
+++ b/main.lua
@@ -65,9 +65,24 @@ end
local EditHandle = class()
EditHandle.R = 0.04
+EditHandle.D = 0.2
+function EditHandle.make(cls, theta,p,q,w,pg)
+ local self = setmetatable({
+ x = cls.D * math.cos(theta) + p.x,
+ y = cls.D * math.sin(theta) + p.y,
+ color = w.color,
+ here = p,
+ there = q,
+ pg = pg,
+ },cls)
+ self.curve = catenary.catenary(
+ self.x,self.y, self.there.x,self.there.y)
+ return self
+end
function EditHandle.draw(self)
G.setColor(self.color)
G.circle('fill',self.x,self.y,self.R)
+ G.line(self.curve)
end
function EditHandle.contains(self, px,py)
local d = math.sqrt((self.x - px)^2 + (self.y - py)^2)
@@ -77,7 +92,6 @@ function EditHandle.remove_wire(self)
self.pg:remove_conn(self.here,self.there)
end
-
local PortGraph = class()
function PortGraph.make(cls)
return setmetatable({
@@ -111,8 +125,14 @@ function PortGraph.draw(self)
p:draw(istate)
end
for w in pairs(self.wires) do
+ if self.state == 'editing' then
+ if self.selected == w.p1 or self.selected == w.p2 then
+ goto next
+ end
+ end
local istate = self:istate_of_wire(w)
w:draw(istate)
+ ::next::
end
if self.state == 'joining' then
@@ -140,14 +160,8 @@ function PortGraph.make_edit_handles(self)
for q,w in pairs(p.conns) do
local theta = tau * i/n
i = i + 1
- local h = setmetatable({
- x = D * math.cos(theta) + p.x,
- y = D * math.sin(theta) + p.y,
- color = w.color,
- here = p,
- there = q,
- pg = self,
- },EditHandle)
+ local h = EditHandle:make(theta,p,q,w,self)
+
hs[h] = true
end
@@ -162,9 +176,9 @@ function PortGraph.click(self,button)
self.state = 'joining'
self.selected = p
elseif button == 2 then
- self.state = 'editing'
self.selected = p
self.handles = self:make_edit_handles()
+ self.state = 'editing'
end
end
elseif self.state == 'joining' then