diff --git a/Canvas.go b/Canvas.go index 0f2b4828..30322f7c 100644 --- a/Canvas.go +++ b/Canvas.go @@ -157,6 +157,10 @@ func (c *Canvas) AddImage(texture *Texture, pMin, pMax image.Point) { c.DrawList.AddImage(texture.ID(), ToVec2(pMin), ToVec2(pMax)) } +func (c *Canvas) AddImageQuad(texture *Texture, p1, p2, p3, p4, uv1, uv2, uv3, uv4 image.Point, col color.Color) { + c.DrawList.AddImageQuadV(texture.tex.ID(), ToVec2(p1), ToVec2(p2), ToVec2(p3), ToVec2(p4), ToVec2(uv1), ToVec2(uv2), ToVec2(uv3), ToVec2(uv4), ColorToUint(col)) +} + func (c *Canvas) AddImageV(texture *Texture, pMin, pMax, uvMin, uvMax image.Point, col color.Color) { c.DrawList.AddImageV(texture.tex.ID(), ToVec2(pMin), ToVec2(pMax), ToVec2(uvMin), ToVec2(uvMax), ColorToUint(col)) } diff --git a/examples/canvas/canvas.go b/examples/canvas/canvas.go index 8e821c2c..5f50a7c1 100644 --- a/examples/canvas/canvas.go +++ b/examples/canvas/canvas.go @@ -17,26 +17,26 @@ func loop() { g.Custom(func() { canvas := g.GetCanvas() pos := g.GetCursorScreenPos() - color := color.RGBA{200, 75, 75, 255} - canvas.AddLine(pos, pos.Add(image.Pt(100, 100)), color, 1) - canvas.AddRect(pos.Add(image.Pt(110, 0)), pos.Add(image.Pt(200, 100)), color, 5, g.DrawFlagsRoundCornersAll, 1) - canvas.AddRectFilled(pos.Add(image.Pt(220, 0)), pos.Add(image.Pt(320, 100)), color, 0, 0) + col := color.RGBA{200, 75, 75, 255} + canvas.AddLine(pos, pos.Add(image.Pt(100, 100)), col, 1) + canvas.AddRect(pos.Add(image.Pt(110, 0)), pos.Add(image.Pt(200, 100)), col, 5, g.DrawFlagsRoundCornersAll, 1) + canvas.AddRectFilled(pos.Add(image.Pt(220, 0)), pos.Add(image.Pt(320, 100)), col, 0, 0) pos0 := pos.Add(image.Pt(0, 110)) cp0 := pos.Add(image.Pt(80, 110)) cp1 := pos.Add(image.Pt(50, 210)) pos1 := pos.Add(image.Pt(120, 210)) - canvas.AddBezierCubic(pos0, cp0, cp1, pos1, color, 1, 0) + canvas.AddBezierCubic(pos0, cp0, cp1, pos1, col, 1, 0) p1 := pos.Add(image.Pt(160, 110)) p2 := pos.Add(image.Pt(120, 210)) p3 := pos.Add(image.Pt(210, 210)) p4 := pos.Add(image.Pt(210, 150)) - // canvas.AddTriangle(p1, p2, p3, color, 2) - canvas.AddQuad(p1, p2, p3, p4, color, 1) + // canvas.AddTriangle(p1, p2, p3, col, 2) + canvas.AddQuad(p1, p2, p3, p4, col, 1) p1 = p1.Add(image.Pt(120, 60)) - canvas.AddCircleFilled(p1, 50, color) + canvas.AddCircleFilled(p1, 50, col) p1 = pos.Add(image.Pt(10, 400)) p2 = pos.Add(image.Pt(50, 440)) @@ -44,10 +44,21 @@ func loop() { canvas.PathLineTo(p1) canvas.PathLineTo(p2) canvas.PathBezierCubicCurveTo(p2.Add(image.Pt(40, 0)), p3.Add(image.Pt(-50, 0)), p3, 0) - canvas.PathStroke(color, 0, 1) + canvas.PathStroke(col, 0, 1) if texture != nil { - canvas.AddImage(texture, image.Pt(350, 25), image.Pt(500, 125)) + canvas.AddImage(texture, image.Pt(pos.X+350, pos.Y+25), image.Pt(pos.X+500, pos.Y+125)) + p1 = image.Pt(pos.X+350, pos.Y+200) + p2 = image.Pt(pos.X+350, pos.Y+400) + p3 = image.Pt(pos.X+550, pos.Y+300) + p4 = image.Pt(pos.X+500, pos.Y+200) + canvas.AddImageQuad(texture, p1, p2, p3, p4, + image.Pt(0, 0), + image.Pt(1, 0), + image.Pt(1, 1), + image.Pt(0, 1), + color.RGBA{255, 255, 255, 100}, + ) } }), )