mirror of
https://github.com/esimov/caire.git
synced 2025-09-27 12:52:12 +08:00
gui: extended supported draw methods
This commit is contained in:
22
draw.go
22
draw.go
@@ -1,12 +1,15 @@
|
|||||||
package caire
|
package caire
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"image"
|
||||||
"image/color"
|
"image/color"
|
||||||
"math"
|
"math"
|
||||||
|
|
||||||
"gioui.org/f32"
|
"gioui.org/f32"
|
||||||
"gioui.org/op/clip"
|
"gioui.org/op/clip"
|
||||||
"gioui.org/op/paint"
|
"gioui.org/op/paint"
|
||||||
|
"gioui.org/unit"
|
||||||
|
"gioui.org/widget"
|
||||||
)
|
)
|
||||||
|
|
||||||
type shapeType int
|
type shapeType int
|
||||||
@@ -27,6 +30,25 @@ func (g *Gui) DrawSeam(shape shapeType, x, y, s float64) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// EncodeSeamToImg draws the seams into an image widget.
|
||||||
|
func (g *Gui) EncodeSeamToImg() {
|
||||||
|
g.setFillColor(color.White)
|
||||||
|
|
||||||
|
img := image.NewNRGBA(image.Rect(0, 0, int(g.cfg.window.w), int(g.cfg.window.h)))
|
||||||
|
for _, s := range g.proc.seams {
|
||||||
|
img.Set(s.X, s.Y, g.getFillColor())
|
||||||
|
}
|
||||||
|
|
||||||
|
src := paint.NewImageOp(img)
|
||||||
|
src.Add(g.ctx.Ops)
|
||||||
|
|
||||||
|
widget.Image{
|
||||||
|
Src: src,
|
||||||
|
Scale: 1 / float32(g.ctx.Px(unit.Dp(1))),
|
||||||
|
Fit: widget.Contain,
|
||||||
|
}.Layout(g.ctx)
|
||||||
|
}
|
||||||
|
|
||||||
// drawCircle draws a circle at the seam (x,y) coordinate with the provided size.
|
// drawCircle draws a circle at the seam (x,y) coordinate with the provided size.
|
||||||
func (g *Gui) drawCircle(x, y, s float64) {
|
func (g *Gui) drawCircle(x, y, s float64) {
|
||||||
var (
|
var (
|
||||||
|
27
gui.go
27
gui.go
@@ -10,6 +10,7 @@ import (
|
|||||||
"gioui.org/io/system"
|
"gioui.org/io/system"
|
||||||
"gioui.org/layout"
|
"gioui.org/layout"
|
||||||
"gioui.org/op"
|
"gioui.org/op"
|
||||||
|
"gioui.org/op/clip"
|
||||||
"gioui.org/op/paint"
|
"gioui.org/op/paint"
|
||||||
"gioui.org/unit"
|
"gioui.org/unit"
|
||||||
"gioui.org/widget"
|
"gioui.org/widget"
|
||||||
@@ -142,26 +143,38 @@ func (g *Gui) draw(win *app.Window, e system.FrameEvent) {
|
|||||||
g.ctx = layout.NewContext(g.ctx.Ops, e)
|
g.ctx = layout.NewContext(g.ctx.Ops, e)
|
||||||
win.Invalidate()
|
win.Invalidate()
|
||||||
|
|
||||||
color := g.setColor(g.cfg.color.background)
|
c := g.setColor(g.cfg.color.background)
|
||||||
paint.Fill(g.ctx.Ops, color)
|
paint.Fill(g.ctx.Ops, c)
|
||||||
|
|
||||||
if g.proc.img != nil {
|
if g.proc.img != nil {
|
||||||
src := paint.NewImageOp(g.proc.img)
|
src := paint.NewImageOp(g.proc.img)
|
||||||
src.Add(g.ctx.Ops)
|
src.Add(g.ctx.Ops)
|
||||||
|
|
||||||
imgWidget := widget.Image{
|
layout.Flex{
|
||||||
|
Axis: layout.Horizontal,
|
||||||
|
}.Layout(g.ctx,
|
||||||
|
layout.Flexed(1, func(gtx layout.Context) layout.Dimensions {
|
||||||
|
paint.FillShape(gtx.Ops, c,
|
||||||
|
clip.Rect{Max: g.ctx.Constraints.Max}.Op(),
|
||||||
|
)
|
||||||
|
return layout.UniformInset(unit.Px(0)).Layout(gtx,
|
||||||
|
func(gtx layout.Context) layout.Dimensions {
|
||||||
|
widget.Image{
|
||||||
Src: src,
|
Src: src,
|
||||||
Scale: 1 / float32(g.ctx.Px(unit.Dp(1))),
|
Scale: 1 / float32(g.ctx.Px(unit.Dp(1))),
|
||||||
Fit: widget.Contain,
|
Fit: widget.Contain,
|
||||||
}
|
}.Layout(gtx)
|
||||||
|
|
||||||
imgWidget.Layout(g.ctx)
|
|
||||||
|
|
||||||
if g.cp.Debug {
|
if g.cp.Debug {
|
||||||
for _, s := range g.proc.seams {
|
for _, s := range g.proc.seams {
|
||||||
g.DrawSeam(line, float64(s.X), float64(s.Y), 1)
|
g.DrawSeam(circle, float64(s.X), float64(s.Y), 2)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
return layout.Dimensions{Size: gtx.Constraints.Max}
|
||||||
|
})
|
||||||
|
}),
|
||||||
|
)
|
||||||
|
|
||||||
}
|
}
|
||||||
e.Frame(g.ctx.Ops)
|
e.Frame(g.ctx.Ops)
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user