mirror of
https://github.com/esimov/caire.git
synced 2025-09-26 20:41:14 +08:00
gui: extended supported draw methods
This commit is contained in:
22
draw.go
22
draw.go
@@ -1,12 +1,15 @@
|
||||
package caire
|
||||
|
||||
import (
|
||||
"image"
|
||||
"image/color"
|
||||
"math"
|
||||
|
||||
"gioui.org/f32"
|
||||
"gioui.org/op/clip"
|
||||
"gioui.org/op/paint"
|
||||
"gioui.org/unit"
|
||||
"gioui.org/widget"
|
||||
)
|
||||
|
||||
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.
|
||||
func (g *Gui) drawCircle(x, y, s float64) {
|
||||
var (
|
||||
|
39
gui.go
39
gui.go
@@ -10,6 +10,7 @@ import (
|
||||
"gioui.org/io/system"
|
||||
"gioui.org/layout"
|
||||
"gioui.org/op"
|
||||
"gioui.org/op/clip"
|
||||
"gioui.org/op/paint"
|
||||
"gioui.org/unit"
|
||||
"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)
|
||||
win.Invalidate()
|
||||
|
||||
color := g.setColor(g.cfg.color.background)
|
||||
paint.Fill(g.ctx.Ops, color)
|
||||
c := g.setColor(g.cfg.color.background)
|
||||
paint.Fill(g.ctx.Ops, c)
|
||||
|
||||
if g.proc.img != nil {
|
||||
src := paint.NewImageOp(g.proc.img)
|
||||
src.Add(g.ctx.Ops)
|
||||
|
||||
imgWidget := widget.Image{
|
||||
Src: src,
|
||||
Scale: 1 / float32(g.ctx.Px(unit.Dp(1))),
|
||||
Fit: widget.Contain,
|
||||
}
|
||||
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,
|
||||
Scale: 1 / float32(g.ctx.Px(unit.Dp(1))),
|
||||
Fit: widget.Contain,
|
||||
}.Layout(gtx)
|
||||
|
||||
imgWidget.Layout(g.ctx)
|
||||
if g.cp.Debug {
|
||||
for _, s := range g.proc.seams {
|
||||
g.DrawSeam(circle, float64(s.X), float64(s.Y), 2)
|
||||
}
|
||||
}
|
||||
return layout.Dimensions{Size: gtx.Constraints.Max}
|
||||
})
|
||||
}),
|
||||
)
|
||||
|
||||
if g.cp.Debug {
|
||||
for _, s := range g.proc.seams {
|
||||
g.DrawSeam(line, float64(s.X), float64(s.Y), 1)
|
||||
}
|
||||
}
|
||||
}
|
||||
e.Frame(g.ctx.Ops)
|
||||
}
|
||||
|
Reference in New Issue
Block a user