Skip to content

Commit

Permalink
attempt to fix sprite offset
Browse files Browse the repository at this point in the history
  • Loading branch information
kkoreilly committed Feb 28, 2024
1 parent 581d47e commit 01aa5d3
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 10 deletions.
8 changes: 4 additions & 4 deletions vector/manip.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions vector/path.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down
5 changes: 3 additions & 2 deletions vector/sprites.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"image/color"
"image/draw"

"cogentcore.org/core/colors"
"cogentcore.org/core/gi"
"cogentcore.org/core/mat32"
)
Expand Down Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions vector/svgview.go
Original file line number Diff line number Diff line change
Expand Up @@ -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..
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 01aa5d3

Please sign in to comment.