2017-11-04 21:29:15 +00:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/mediocregopher/ginger/gim/geo"
|
|
|
|
"github.com/mediocregopher/ginger/gim/terminal"
|
|
|
|
)
|
|
|
|
|
2018-03-03 17:32:40 +00:00
|
|
|
type line struct {
|
2018-03-04 14:35:01 +00:00
|
|
|
from, to *box
|
|
|
|
fromI, toI int
|
2018-06-07 22:35:18 +00:00
|
|
|
bodyBuf *terminal.Buffer
|
2017-11-23 19:19:32 +00:00
|
|
|
}
|
|
|
|
|
2018-06-03 08:26:42 +00:00
|
|
|
func (l line) draw(buf *terminal.Buffer, flowDir, secFlowDir geo.XY) {
|
2018-03-03 17:32:40 +00:00
|
|
|
from, to := *(l.from), *(l.to)
|
2018-03-04 14:35:01 +00:00
|
|
|
start := from.rect().Edge(flowDir, secFlowDir)[0].Add(secFlowDir.Scale(l.fromI*2 + 1))
|
2018-06-07 22:35:18 +00:00
|
|
|
end := to.rect().Edge(flowDir.Inv(), secFlowDir)[0]
|
|
|
|
end = end.Add(flowDir.Inv())
|
|
|
|
end = end.Add(secFlowDir.Scale(l.toI*2 + 1))
|
2017-11-04 21:29:15 +00:00
|
|
|
|
2018-06-07 22:35:18 +00:00
|
|
|
buf.SetPos(start)
|
|
|
|
buf.WriteRune(terminal.SingleLine.Perpendicular(flowDir))
|
|
|
|
buf.DrawLine(start.Add(flowDir), end.Add(flowDir.Inv()), flowDir, terminal.SingleLine)
|
|
|
|
buf.SetPos(end)
|
|
|
|
buf.WriteRune(terminal.SingleLine.Arrow(flowDir))
|
2018-06-02 04:35:12 +00:00
|
|
|
|
|
|
|
// draw the body
|
2018-06-07 22:35:18 +00:00
|
|
|
if l.bodyBuf != nil {
|
2018-06-07 22:50:01 +00:00
|
|
|
mid := start.Midpoint(end)
|
2018-06-07 22:35:18 +00:00
|
|
|
bodyBufRect := geo.Rect{Size: l.bodyBuf.Size()}
|
2018-06-07 22:50:01 +00:00
|
|
|
buf.DrawBuffer(bodyBufRect.Centered(mid).TopLeft, l.bodyBuf)
|
2018-06-02 04:35:12 +00:00
|
|
|
}
|
2017-11-04 21:29:15 +00:00
|
|
|
}
|