mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2025-01-27 11:12:44 +01:00
vector: Add FillOptions
This commit is contained in:
parent
4b63be0156
commit
1fdab58ff5
@ -98,7 +98,10 @@ func drawEbitenText(screen *ebiten.Image) {
|
|||||||
path.LineTo(320, 55)
|
path.LineTo(320, 55)
|
||||||
path.LineTo(290, 20)
|
path.LineTo(290, 20)
|
||||||
|
|
||||||
path.Fill(screen, color.RGBA{0xdb, 0x56, 0x20, 0xff})
|
op := &vector.FillOptions{
|
||||||
|
Color: color.RGBA{0xdb, 0x56, 0x20, 0xff},
|
||||||
|
}
|
||||||
|
path.Fill(screen, op)
|
||||||
}
|
}
|
||||||
|
|
||||||
func drawEbitenLogo(screen *ebiten.Image, x, y int) {
|
func drawEbitenLogo(screen *ebiten.Image, x, y int) {
|
||||||
@ -127,7 +130,10 @@ func drawEbitenLogo(screen *ebiten.Image, x, y int) {
|
|||||||
path.LineTo(xf+unit, yf+3*unit)
|
path.LineTo(xf+unit, yf+3*unit)
|
||||||
path.LineTo(xf+unit, yf+4*unit)
|
path.LineTo(xf+unit, yf+4*unit)
|
||||||
|
|
||||||
path.Fill(screen, color.RGBA{0xdb, 0x56, 0x20, 0xff})
|
op := &vector.FillOptions{
|
||||||
|
Color: color.RGBA{0xdb, 0x56, 0x20, 0xff},
|
||||||
|
}
|
||||||
|
path.Fill(screen, op)
|
||||||
}
|
}
|
||||||
|
|
||||||
func maxCounter(index int) int {
|
func maxCounter(index int) int {
|
||||||
@ -159,7 +165,10 @@ func drawWave(screen *ebiten.Image, counter int) {
|
|||||||
path.LineTo(screenWidth, screenHeight)
|
path.LineTo(screenWidth, screenHeight)
|
||||||
path.LineTo(0, screenHeight)
|
path.LineTo(0, screenHeight)
|
||||||
|
|
||||||
path.Fill(screen, color.RGBA{0x33, 0x66, 0xff, 0xff})
|
op := &vector.FillOptions{
|
||||||
|
Color: color.RGBA{0x33, 0x66, 0xff, 0xff},
|
||||||
|
}
|
||||||
|
path.Fill(screen, op)
|
||||||
}
|
}
|
||||||
|
|
||||||
var counter = 0
|
var counter = 0
|
||||||
|
@ -49,6 +49,7 @@ func InTriangle(pt, pt0, pt1, pt2 Point) bool {
|
|||||||
return (c0 <= 0 && c1 <= 0 && c2 <= 0) || (c0 >= 0 && c1 >= 0 && c2 >= 0)
|
return (c0 <= 0 && c1 <= 0 && c2 <= 0) || (c0 >= 0 && c1 >= 0 && c2 >= 0)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Triangulate triangulates the region surrounded by the points pts and returnes the point indices.
|
||||||
func Triangulate(pts []Point) []uint16 {
|
func Triangulate(pts []Point) []uint16 {
|
||||||
if len(pts) < 3 {
|
if len(pts) < 3 {
|
||||||
return nil
|
return nil
|
||||||
@ -78,6 +79,7 @@ func Triangulate(pts []Point) []uint16 {
|
|||||||
|
|
||||||
// Triangulation by Ear Clipping.
|
// Triangulation by Ear Clipping.
|
||||||
// https://www.geometrictools.com/Documentation/TriangulationByEarClipping.pdf
|
// https://www.geometrictools.com/Documentation/TriangulationByEarClipping.pdf
|
||||||
|
// TODO: Adopt a more efficient algorithm.
|
||||||
for len(currentIndices) >= 3 {
|
for len(currentIndices) >= 3 {
|
||||||
// Calculate cross-products and remove unneeded vertices.
|
// Calculate cross-products and remove unneeded vertices.
|
||||||
cs := make([]float32, len(currentIndices))
|
cs := make([]float32, len(currentIndices))
|
||||||
|
@ -92,18 +92,28 @@ func (p *Path) CubicTo(cp0x, cp0y, cp1x, cp1y, x, y float32) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *Path) Fill(dst *ebiten.Image, clr color.Color) {
|
type FillOptions struct {
|
||||||
|
Color color.Color
|
||||||
|
}
|
||||||
|
|
||||||
|
// Fill fills the region of the path with the given options op.
|
||||||
|
func (p *Path) Fill(dst *ebiten.Image, op *FillOptions) {
|
||||||
var vertices []ebiten.Vertex
|
var vertices []ebiten.Vertex
|
||||||
var indices []uint16
|
var indices []uint16
|
||||||
|
|
||||||
r, g, b, a := clr.RGBA()
|
if op.Color == nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
r, g, b, a := op.Color.RGBA()
|
||||||
var rf, gf, bf, af float32
|
var rf, gf, bf, af float32
|
||||||
if a > 0 {
|
if a == 0 {
|
||||||
|
return
|
||||||
|
}
|
||||||
rf = float32(r) / float32(a)
|
rf = float32(r) / float32(a)
|
||||||
gf = float32(g) / float32(a)
|
gf = float32(g) / float32(a)
|
||||||
bf = float32(b) / float32(a)
|
bf = float32(b) / float32(a)
|
||||||
af = float32(a) / 0xffff
|
af = float32(a) / 0xffff
|
||||||
}
|
|
||||||
|
|
||||||
var base uint16
|
var base uint16
|
||||||
for _, seg := range p.segs {
|
for _, seg := range p.segs {
|
||||||
|
Loading…
Reference in New Issue
Block a user