mirror of
https://github.com/esimov/caire.git
synced 2026-04-23 00:07:11 +08:00
gui: converting px unit to dp unit on seams drawing
This commit is contained in:
@@ -19,15 +19,15 @@ const (
|
||||
)
|
||||
|
||||
// DrawSeam visualizes the seam carver in action when the preview mode is activated.
|
||||
// It receives as parameters the shape type, the seam (x,y) coordinate and a size.
|
||||
func (g *Gui) DrawSeam(shape string, x, y, s float32) {
|
||||
// It receives as parameters the shape type, the seam (x,y) coordinates and a dimmension.
|
||||
func (g *Gui) DrawSeam(shape string, x, y, dim float32) {
|
||||
r := getRatio(g.cfg.window.w, g.cfg.window.h)
|
||||
|
||||
switch shape {
|
||||
case circle:
|
||||
g.drawCircle(x*r, y*r, s)
|
||||
g.drawCircle(x*r, y*r, dim)
|
||||
case line:
|
||||
g.drawLine(x*r, y*r, s)
|
||||
g.drawLine(x*r, y*r, dim)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -83,7 +83,7 @@ func (g *Gui) drawCircle(x, y, s float32) {
|
||||
}
|
||||
|
||||
// drawLine draws a line at the seam (x,y) coordinate with the provided line thickness.
|
||||
func (g *Gui) drawLine(x, y, s float32) {
|
||||
func (g *Gui) drawLine(x, y, thickness float32) {
|
||||
var (
|
||||
p1 = g.point(x, y)
|
||||
p2 = g.point(x, y+1)
|
||||
@@ -98,7 +98,7 @@ func (g *Gui) drawLine(x, y, s float32) {
|
||||
col := utils.HexToRGBA(g.cp.SeamColor)
|
||||
g.setFillColor(col)
|
||||
|
||||
defer clip.Stroke{Path: path.End(), Width: float32(s)}.Op().Push(g.ctx.Ops).Pop()
|
||||
defer clip.Stroke{Path: path.End(), Width: float32(thickness)}.Op().Push(g.ctx.Ops).Pop()
|
||||
paint.ColorOp{Color: g.setColor(g.getFillColor())}.Add(g.ctx.Ops)
|
||||
paint.PaintOp{}.Add(g.ctx.Ops)
|
||||
}
|
||||
|
||||
@@ -24,10 +24,13 @@ import (
|
||||
)
|
||||
|
||||
const (
|
||||
// The starting colors for the linear gradient, used when the image is resized both horzontally and vertically.
|
||||
// In this case the preview mode is deactivated and a dynamic gradient overlay is shown.
|
||||
redStart = 137
|
||||
greenStart = 47
|
||||
blueStart = 54
|
||||
|
||||
// The ending colors for the linear gradient. The starting colors and ending colors are lerped.
|
||||
redEnd = 255
|
||||
greenEnd = 112
|
||||
blueEnd = 105
|
||||
@@ -214,7 +217,6 @@ func (g *Gui) Run() error {
|
||||
descBlue = !descBlue
|
||||
}
|
||||
}
|
||||
|
||||
g.draw(w, e, color.NRGBA{R: rc, G: gc, B: bc})
|
||||
case key.Event:
|
||||
switch e.Name {
|
||||
@@ -269,7 +271,7 @@ func (g *Gui) draw(win *app.Window, e system.FrameEvent, bgCol color.NRGBA) {
|
||||
paint.FillShape(gtx.Ops, c,
|
||||
clip.Rect{Max: g.ctx.Constraints.Max}.Op(),
|
||||
)
|
||||
return layout.UniformInset(unit.Px(0)).Layout(gtx,
|
||||
return layout.UniformInset(unit.Dp(0)).Layout(gtx,
|
||||
func(gtx C) D {
|
||||
widget.Image{
|
||||
Src: src,
|
||||
@@ -309,7 +311,11 @@ func (g *Gui) draw(win *app.Window, e system.FrameEvent, bgCol color.NRGBA) {
|
||||
op.Affine(tr).Add(gtx.Ops)
|
||||
|
||||
for _, s := range g.proc.seams {
|
||||
g.DrawSeam(g.cp.ShapeType, float32(s.X), float32(s.Y), 1)
|
||||
dpx := unit.Dp(float32(s.X))
|
||||
dpy := unit.Dp(float32(s.Y))
|
||||
// Convert px unit to dp.
|
||||
px := float32(g.cfg.window.h) * (float32(0.5) / float32(160))
|
||||
g.DrawSeam(g.cp.ShapeType, dpx.V, dpy.Scale(px).V, 1)
|
||||
}
|
||||
}
|
||||
return layout.Dimensions{Size: gtx.Constraints.Max}
|
||||
|
||||
Reference in New Issue
Block a user