Skip to content

Commit

Permalink
implemented basic rubber band sprite rendering and object moving in v…
Browse files Browse the repository at this point in the history
…ector
  • Loading branch information
kkoreilly committed Feb 28, 2024
1 parent 687da38 commit e96e61f
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 24 deletions.
19 changes: 9 additions & 10 deletions vector/manip.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ import (
"math"
"strings"

"cogentcore.org/core/events"
"cogentcore.org/core/events/key"
"cogentcore.org/core/mat32"
)

Expand Down Expand Up @@ -300,12 +302,11 @@ func (sv *SVGView) ConstrainPoint(st, rawpt mat32.Vec2) (mat32.Vec2, bool) {
return cp, diag
}

/*
// DragMove is when dragging a selection for moving
func (sv *SVGView) DragMove(win *gi.Window, me *mouse.DragEvent) {
func (sv *SVGView) DragMove(e events.Event) {
es := sv.EditState()

InactivateSprites(win, SpAlignMatch)
InactivateSprites(sv, SpAlignMatch)

if !es.InAction() {
sv.ManipStart("Move", es.SelectedNamesString())
Expand All @@ -314,8 +315,8 @@ func (sv *SVGView) DragMove(win *gi.Window, me *mouse.DragEvent) {

svoff := mat32.V2FromPoint(sv.Geom.ContentBBox.Min)
spt := mat32.V2FromPoint(es.DragStartPos)
mpt := mat32.V2FromPoint(me.Where)
if me.HasAnyModifier(key.Control) {
mpt := mat32.V2FromPoint(e.Pos())
if e.HasAnyModifier(key.Control) {
mpt, _ = sv.ConstrainPoint(spt, mpt)
}
dv := mpt.Sub(spt)
Expand All @@ -333,16 +334,14 @@ func (sv *SVGView) DragMove(win *gi.Window, me *mouse.DragEvent) {
pt := es.DragSelStartBBox.Min.Sub(svoff)
tdel := es.DragSelEffBBox.Min.Sub(es.DragSelStartBBox.Min)
for itm, ss := range es.Selected {
itm.ReadGeom(ss.InitGeom)
itm.ApplyDeltaTransform(tdel, mat32.V2(1, 1), 0, pt)
itm.ReadGeom(sv.SSVG(), ss.InitGeom)
itm.ApplyDeltaTransform(sv.SSVG(), tdel, mat32.V2(1, 1), 0, pt)
}
sv.SetBBoxSpritePos(SpReshapeBBox, 0, es.DragSelEffBBox)
sv.SetSelSpritePos()
go sv.ManipUpdate()
win.UpdateSig()
// win.UpdateSig()
}
*/

func SquareBBox(bb mat32.Box2) mat32.Box2 {
del := bb.Size()
Expand Down
3 changes: 2 additions & 1 deletion vector/select.go
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,7 @@ func (sv *SVGView) SelSpriteEvent(sp Sprites, et events.EventType, d any) {

// SetRubberBand updates the rubber band postion
func (sv *SVGView) SetRubberBand(cur image.Point) {
updt := sv.UpdateStart()
es := sv.EditState()

if !es.InAction() {
Expand Down Expand Up @@ -291,7 +292,7 @@ func (sv *SVGView) SetRubberBand(cur image.Point) {
SetSpritePos(rr, image.Point{bbox.Max.X, bbox.Min.Y})
SetSpritePos(rl, bbox.Min)

// win.UpdateSig()
sv.UpdateEndRender(updt)
}

///////////////////////////////////////////////////////////////////////
Expand Down
7 changes: 2 additions & 5 deletions vector/sprites.go
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,6 @@ 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, colors.C(colors.Scheme.Primary.Base), image.Point{}, draw.Src)
}

Expand Down Expand Up @@ -341,11 +340,10 @@ func DrawRubberBandHoriz(sp *gi.Sprite, trgsz image.Point) {
bbd := ibd
bbd.Min.Y += bsz
bbd.Max.Y -= bsz
draw.Draw(sp.Pixels, ibd, &image.Uniform{color.White}, image.ZP, draw.Src)
for x := 0; x < ssz.X; x += sz * 2 {
bbd.Min.X = x
bbd.Max.X = x + sz
draw.Draw(sp.Pixels, bbd, &image.Uniform{color.Black}, image.ZP, draw.Src)
draw.Draw(sp.Pixels, bbd, colors.C(colors.Scheme.Primary.Base), image.ZP, draw.Src)
}
}

Expand All @@ -360,11 +358,10 @@ func DrawRubberBandVert(sp *gi.Sprite, trgsz image.Point) {
bbd := ibd
bbd.Min.X += bsz
bbd.Max.X -= bsz
draw.Draw(sp.Pixels, ibd, &image.Uniform{color.White}, image.ZP, draw.Src)
for y := sz; y < ssz.Y; y += sz * 2 {
bbd.Min.Y = y
bbd.Max.Y = y + sz
draw.Draw(sp.Pixels, bbd, &image.Uniform{color.Black}, image.ZP, draw.Src)
draw.Draw(sp.Pixels, bbd, colors.C(colors.Scheme.Primary.Base), image.ZP, draw.Src)
}
}

Expand Down
13 changes: 5 additions & 8 deletions vector/svgview.go
Original file line number Diff line number Diff line change
Expand Up @@ -180,8 +180,6 @@ func (sv *SVGView) HandleEvents() {
}
if !es.InAction() {
switch es.Tool {
case SelectTool:
sv.SetRubberBand(e.PrevPos())
case RectTool:
sv.NewElDrag(svg.RectType, es.DragStartPos, e.Pos())
es.SelBBox.Min.X += 1
Expand All @@ -197,11 +195,6 @@ func (sv *SVGView) HandleEvents() {
case BezierTool:
sv.NewPath(es.DragStartPos, e.Pos())
}
} else {
switch {
case es.Action == "BoxSelect":
sv.SetRubberBand(e.Pos())
}
}
}
// if e.MouseButton() == events.Right {
Expand All @@ -227,9 +220,13 @@ func (sv *SVGView) HandleEvents() {
}
if es.HasSelected() {
if !es.NewTextMade {
// sv.DragMove(win, me) // in manip
sv.DragMove(e)
return
}
}
if es.Action == "BoxSelect" || (!es.InAction() && es.Tool == SelectTool) {
sv.SetRubberBand(e.Pos())
}
})
}

Expand Down

0 comments on commit e96e61f

Please sign in to comment.