From e96e61fb66d70ed347ab99be0d988fcf77856cec Mon Sep 17 00:00:00 2001 From: Kai O'Reilly Date: Tue, 27 Feb 2024 17:32:09 -0800 Subject: [PATCH] implemented basic rubber band sprite rendering and object moving in vector --- vector/manip.go | 19 +++++++++---------- vector/select.go | 3 ++- vector/sprites.go | 7 ++----- vector/svgview.go | 13 +++++-------- 4 files changed, 18 insertions(+), 24 deletions(-) diff --git a/vector/manip.go b/vector/manip.go index 5f55194e..7e5b6f22 100644 --- a/vector/manip.go +++ b/vector/manip.go @@ -10,6 +10,8 @@ import ( "math" "strings" + "cogentcore.org/core/events" + "cogentcore.org/core/events/key" "cogentcore.org/core/mat32" ) @@ -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()) @@ -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) @@ -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() diff --git a/vector/select.go b/vector/select.go index 6dc2e385..8c3cbaae 100644 --- a/vector/select.go +++ b/vector/select.go @@ -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() { @@ -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) } /////////////////////////////////////////////////////////////////////// diff --git a/vector/sprites.go b/vector/sprites.go index ae65522a..a8e3df54 100644 --- a/vector/sprites.go +++ b/vector/sprites.go @@ -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) } @@ -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) } } @@ -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) } } diff --git a/vector/svgview.go b/vector/svgview.go index 597d6357..e8c2ef53 100644 --- a/vector/svgview.go +++ b/vector/svgview.go @@ -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 @@ -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 { @@ -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()) + } }) }