Skip to content

Commit

Permalink
Merge pull request #723 from gucio321/image-quad
Browse files Browse the repository at this point in the history
Image quad
  • Loading branch information
gucio321 authored Oct 24, 2023
2 parents 0cc79b2 + 6769c74 commit d7370f8
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 10 deletions.
4 changes: 4 additions & 0 deletions Canvas.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))
}
31 changes: 21 additions & 10 deletions examples/canvas/canvas.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,37 +17,48 @@ 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))
p3 = pos.Add(image.Pt(200, 500))
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},
)
}
}),
)
Expand Down

0 comments on commit d7370f8

Please sign in to comment.