From 01aa5d3663f505ddab43ad6ce00beeea2022d8a6 Mon Sep 17 00:00:00 2001 From: Kai O'Reilly Date: Tue, 27 Feb 2024 16:59:55 -0800 Subject: [PATCH] attempt to fix sprite offset --- vector/manip.go | 8 ++++---- vector/path.go | 4 ++-- vector/sprites.go | 5 +++-- vector/svgview.go | 4 ++-- 4 files changed, 11 insertions(+), 10 deletions(-) diff --git a/vector/manip.go b/vector/manip.go index eda98ec3..5f55194e 100644 --- a/vector/manip.go +++ b/vector/manip.go @@ -62,7 +62,7 @@ func (sv *SVGView) ManipUpdate() { // VectorDots is the current grid spacing and offsets in dots func (sv *SVGView) VectorDots() (float32, mat32.Vec2) { - svoff := mat32.V2FromPoint(sv.Root().BBox.Min) + svoff := mat32.V2FromPoint(sv.Geom.ContentBBox.Min) grid := sv.VectorEff if grid <= 0 { grid = 12 @@ -312,7 +312,7 @@ func (sv *SVGView) DragMove(win *gi.Window, me *mouse.DragEvent) { sv.GatherAlignPoints() } - svoff := mat32.V2FromPoint(sv.BBox.Min) + svoff := mat32.V2FromPoint(sv.Geom.ContentBBox.Min) spt := mat32.V2FromPoint(es.DragStartPos) mpt := mat32.V2FromPoint(me.Where) if me.HasAnyModifier(key.Control) { @@ -446,7 +446,7 @@ func (sv *SVGView) SpriteReshapeDrag(sp Sprites, win *gi.Window, me *mouse.DragE npos := es.DragSelEffBBox.Min nsz := es.DragSelEffBBox.Size() - svoff := mat32.V2FromPoint(sv.BBox.Min) + svoff := mat32.V2FromPoint(sv.Geom.ContentBBox.Min) pt := es.DragSelStartBBox.Min.Sub(svoff) del := npos.Sub(stpos) sc := nsz.Div(stsz) @@ -527,7 +527,7 @@ func (sv *SVGView) SpriteRotateDrag(sp Sprites, delta image.Point) { ang := mat32.Atan2(dy, dx) ang, _ = SnapToIncr(mat32.RadToDeg(ang), 0, 15) ang = mat32.DegToRad(ang) - svoff := mat32.V2FromPoint(sv.Root().BBox.Min) + svoff := mat32.V2FromPoint(sv.Geom.ContentBBox.Min) pt = pt.Sub(svoff) del := mat32.Vec2{} sc := mat32.V2(1, 1) diff --git a/vector/path.go b/vector/path.go index ef35aab2..cfe66911 100644 --- a/vector/path.go +++ b/vector/path.go @@ -142,7 +142,7 @@ type PathNode struct { // PathNodes returns the PathNode data for given path data, and a list of indexes where commands start func (sv *SVGView) PathNodes(path *svg.Path) ([]*PathNode, []int) { - svoff := mat32.V2FromPoint(sv.Root().BBox.Min) + svoff := mat32.V2FromPoint(sv.Geom.ContentBBox.Min) pxf := path.ParTransform(true) // include self lstCmdIdx := 0 @@ -296,7 +296,7 @@ func (sv *SVGView) SpriteNodeDrag(idx int, win *gi.Window, me *mouse.DragEvent) sv.GatherAlignPoints() } - svoff := mat32.V2FromPoint(sv.BBox.Min) + svoff := mat32.V2FromPoint(sv.Geom.ContentBBox.Min) pn := es.PathNodes[idx] InactivateSprites(win, SpAlignMatch) diff --git a/vector/sprites.go b/vector/sprites.go index fcd300d8..ae65522a 100644 --- a/vector/sprites.go +++ b/vector/sprites.go @@ -10,6 +10,7 @@ import ( "image/color" "image/draw" + "cogentcore.org/core/colors" "cogentcore.org/core/gi" "cogentcore.org/core/mat32" ) @@ -263,8 +264,8 @@ func DrawSpriteReshape(sp *gi.Sprite, bbtyp Sprites) { bbd.Min.Y += bsz bbd.Max.X -= bsz bbd.Max.Y -= bsz - draw.Draw(sp.Pixels, ibd, &image.Uniform{color.White}, image.ZP, draw.Src) - draw.Draw(sp.Pixels, bbd, &image.Uniform{color.Black}, image.ZP, draw.Src) + // draw.Draw(sp.Pixels, ibd, &image.Uniform{color.White}, image.ZP, draw.Src) + draw.Draw(sp.Pixels, bbd, colors.C(colors.Scheme.Primary.Base), image.Point{}, draw.Src) } // DrawSpriteSel renders a Select sprite handle -- smaller diff --git a/vector/svgview.go b/vector/svgview.go index 179d0dd6..597d6357 100644 --- a/vector/svgview.go +++ b/vector/svgview.go @@ -722,7 +722,7 @@ func (sv *SVGView) NewText(start, end image.Point) svg.Node { tspan.Text = "Text" tspan.Width = 200 xfi := sv.Root().Paint.Transform.Inverse() - svoff := mat32.V2FromPoint(sv.Root().BBox.Min) + svoff := mat32.V2FromPoint(sv.Geom.ContentBBox.Min) pos := mat32.V2FromPoint(start).Sub(svoff) // minsz := float32(20) pos.Y += 20 // todo: need the font size.. @@ -754,7 +754,7 @@ func (sv *SVGView) NewPath(start, end image.Point) *svg.Path { // sv.SetFullReRender() nr := sv.NewEl(svg.PathType).(*svg.Path) xfi := sv.Root().Paint.Transform.Inverse() - svoff := mat32.V2FromPoint(sv.Root().BBox.Min) + svoff := mat32.V2FromPoint(sv.Geom.ContentBBox.Min) pos := mat32.V2FromPoint(start).Sub(svoff) pos = xfi.MulVec2AsPt(pos) sz := dv