summaryrefslogtreecommitdiff
path: root/main.lua
diff options
context:
space:
mode:
Diffstat (limited to 'main.lua')
-rw-r--r--main.lua58
1 files changed, 48 insertions, 10 deletions
diff --git a/main.lua b/main.lua
index fa41c00..3ffd33b 100644
--- a/main.lua
+++ b/main.lua
@@ -59,6 +59,11 @@ function Wire.make(cls, p1,p2, color)
}, cls)
end
function Wire.draw(self, istate)
+ if istate == 'normal' then
+ G.setLineWidth(0.01)
+ else
+ G.setLineWidth(0.02)
+ end
G.setColor(self.color)
G.line(self.curve)
end
@@ -105,23 +110,29 @@ function PortGraph.add(self,...)
local p = Port:make(...)
self.ports[p] = true
end
-function PortGraph.istate_of_port(self,port)
+function PortGraph.istate_of_port(self,port,emph)
if self.state == 'joining' and self.selected == port then
return 'selected'
elseif self.state == 'editing' and self.selected == port then
return 'editing'
- elseif port:contains(util.mouse_pos()) then
+ elseif emph[port] then
return 'hover'
else
return 'normal'
end
end
-function PortGraph.istate_of_wire(self, wire)
- return 'normal'
+function PortGraph.istate_of_wire(self, wire, emph)
+ if emph[wire] then return 'hover' else return 'normal' end
end
function PortGraph.draw(self)
+ local hp = hovered(self.ports)
+ local emph_ports = {}
+ local emph_wires = {}
+ if hp then
+ emph_ports, emph_wires = self:trans_conns(hp)
+ end
for p in pairs(self.ports) do
- local istate = self:istate_of_port(p)
+ local istate = self:istate_of_port(p, emph_ports)
p:draw(istate)
end
for w in pairs(self.wires) do
@@ -130,7 +141,7 @@ function PortGraph.draw(self)
goto next
end
end
- local istate = self:istate_of_wire(w)
+ local istate = self:istate_of_wire(w, emph_wires)
w:draw(istate)
::next::
end
@@ -148,6 +159,23 @@ function PortGraph.draw(self)
end
end
end
+function PortGraph.trans_conns(self, port)
+ local seen = {}
+ local queue = {[port]=true}
+ local wires = {}
+ while next(queue) do
+ local p = next(queue)
+ queue[p] = nil
+ seen[p] = true
+ for q,w in pairs(p.conns) do
+ if not seen[q] then
+ queue[q] = true
+ wires[w] = true
+ end
+ end
+ end
+ return seen, wires
+end
function PortGraph.make_edit_handles(self)
local p = self.selected
@@ -252,11 +280,21 @@ function PortGraph.remove_conn(self,p1,p2)
end
local pg = PortGraph:make()
-local n = 10
-for i = 1,n do
- local theta = tau * i/n
- pg:add(math.cos(theta), math.sin(theta), i)
+local i = 1
+local S = math.sqrt(3)
+for q = -3,2 do
+ for r = -3,3 do
+ local x = q*S + r*S/2
+ local y = r*3/2
+ pg:add(x/4,y/4,i)
+ i=i+1
+ end
end
+-- local n = 10
+-- for i = 1,n do
+-- local theta = tau * i/n
+-- pg:add(math.cos(theta), math.sin(theta), i)
+-- end
function love.mousepressed(x,y,b)
local ok, err = pcall(pg.click, pg, b)