diff options
-rw-r--r-- | main.lua | 34 | ||||
-rw-r--r-- | texts.lua | 1 |
2 files changed, 25 insertions, 10 deletions
@@ -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 @@ -3,6 +3,7 @@ local util = require 'util' local texts = {} local function add(text,x,y) + print('(texts): '..text) table.insert(texts,{ x=x,y=y,life=3,text=text }) |