op/clip: automatically close Path in Outlines

Unclosed path segments in Path will be automatically
closed by a line.

Fixes: https://todo.sr.ht/~eliasnaur/gio/320
Signed-off-by: Pierre Curto <pierre.curto@gmail.com>
This commit is contained in:
Pierre Curto
2021-12-19 17:09:54 +01:00
committed by Elias Naur
parent 0117de71d3
commit 11bb86166a
10 changed files with 123 additions and 28 deletions
+24 -1
View File
@@ -18,7 +18,7 @@ type Op uint32
type Command [sceneElemSize / 4]uint32
// GPU commands from scene.h
// GPU commands from piet/scene.h in package gioui.org/shaders.
const (
OpNop Op = iota
OpLine
@@ -31,6 +31,7 @@ const (
OpEndClip
OpFillImage
OpSetFillMode
OpGap
)
// FillModes, from setup.h.
@@ -56,6 +57,9 @@ func (c Command) String() string {
case OpLine:
from, to := DecodeLine(c)
return fmt.Sprintf("line(%v, %v)", from, to)
case OpGap:
from, to := DecodeLine(c)
return fmt.Sprintf("gap(%v, %v)", from, to)
case OpQuad:
from, ctrl, to := DecodeQuad(c)
return fmt.Sprintf("quad(%v, %v, %v)", from, ctrl, to)
@@ -107,6 +111,16 @@ func Line(start, end f32.Point) Command {
}
}
func Gap(start, end f32.Point) Command {
return Command{
0: uint32(OpGap),
1: math.Float32bits(start.X),
2: math.Float32bits(start.Y),
3: math.Float32bits(end.X),
4: math.Float32bits(end.Y),
}
}
func Cubic(start, ctrl0, ctrl1, end f32.Point) Command {
return Command{
0: uint32(OpCubic),
@@ -206,6 +220,15 @@ func DecodeLine(cmd Command) (from, to f32.Point) {
return
}
func DecodeGap(cmd Command) (from, to f32.Point) {
if cmd[0] != uint32(OpGap) {
panic("invalid command")
}
from = f32.Pt(math.Float32frombits(cmd[1]), math.Float32frombits(cmd[2]))
to = f32.Pt(math.Float32frombits(cmd[3]), math.Float32frombits(cmd[4]))
return
}
func DecodeQuad(cmd Command) (from, ctrl, to f32.Point) {
if cmd[0] != uint32(OpQuad) {
panic("invalid command")