mirror of
https://git.sr.ht/~eliasnaur/gio
synced 2026-07-07 02:15:34 +00:00
gpu,op/clip: implement stroked paths
Flat and Square caps are implemented. Bevel joins are implemented. Round caps, Round joins and Miter joins are left for another PR. Signed-off-by: Sebastien Binet <s@sbinet.org>
This commit is contained in:
committed by
Elias Naur
parent
936eb52b7e
commit
33c5fb63db
@@ -39,6 +39,8 @@ func (p *Path) Pos() f32.Point { return p.pen }
|
||||
type Op struct {
|
||||
call op.CallOp
|
||||
bounds image.Rectangle
|
||||
width float32 // Width of the stroked path, 0 for outline paths.
|
||||
style StrokeStyle // Style of the stroked path, 0 for outline paths.
|
||||
}
|
||||
|
||||
func (p Op) Add(o *op.Ops) {
|
||||
@@ -50,6 +52,8 @@ func (p Op) Add(o *op.Ops) {
|
||||
bo.PutUint32(data[5:], uint32(p.bounds.Min.Y))
|
||||
bo.PutUint32(data[9:], uint32(p.bounds.Max.X))
|
||||
bo.PutUint32(data[13:], uint32(p.bounds.Max.Y))
|
||||
bo.PutUint32(data[17:], math.Float32bits(p.width))
|
||||
data[21] = uint8(p.style.Cap)
|
||||
}
|
||||
|
||||
// Begin the path, storing the path data and final Op into ops.
|
||||
@@ -321,6 +325,26 @@ func (p *Path) Outline() Op {
|
||||
}
|
||||
}
|
||||
|
||||
// Stroke returns a stroked path with the specified width
|
||||
// and configuration.
|
||||
// If the provided width is <= 0, the path won't be stroked.
|
||||
func (p *Path) Stroke(width float32, sty StrokeStyle) Op {
|
||||
if width <= 0 {
|
||||
// Explicitly discard the macro to ignore the path.
|
||||
p.macro.Stop()
|
||||
return Op{
|
||||
call: op.Record(p.ops).Stop(),
|
||||
}
|
||||
}
|
||||
|
||||
c := p.macro.Stop()
|
||||
return Op{
|
||||
call: c,
|
||||
width: width,
|
||||
style: sty,
|
||||
}
|
||||
}
|
||||
|
||||
// Rect represents the clip area of a pixel-aligned rectangle.
|
||||
type Rect image.Rectangle
|
||||
|
||||
|
||||
Reference in New Issue
Block a user