Skip to content

Commit

Permalink
got basic rectangle sizing working
Browse files Browse the repository at this point in the history
  • Loading branch information
kkoreilly committed Feb 25, 2024
1 parent fd060d6 commit d98d04c
Showing 1 changed file with 26 additions and 28 deletions.
54 changes: 26 additions & 28 deletions vector/svgview.go
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,31 @@ func (sv *SVGView) HandleEvents() {
sv.UpdateSelect()
}
}
return
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
es.SelBBox.Min.Y += 1
es.DragSelStartBBox = es.SelBBox
es.DragSelCurBBox = es.SelBBox
es.DragSelEffBBox = es.SelBBox
case EllipseTool:
sv.NewElDrag(svg.EllipseType, es.DragStartPos, e.Pos())
case TextTool:
sv.NewText(es.DragStartPos, e.Pos())
es.NewTextMade = true
case BezierTool:
sv.NewPath(es.DragStartPos, e.Pos())
}
} else {
switch {
case es.Action == "BoxSelect":
sv.SetRubberBand(e.Pos())
}
}
}
// if e.MouseButton() == events.Right {
// e.SetHandled()
Expand All @@ -205,32 +229,6 @@ func (sv *SVGView) HandleEvents() {
if !es.NewTextMade {
// sv.DragMove(win, me) // in manip
}
} else {
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
es.SelBBox.Min.Y += 1
es.DragSelStartBBox = es.SelBBox
es.DragSelCurBBox = es.SelBBox
es.DragSelEffBBox = es.SelBBox
case EllipseTool:
sv.NewElDrag(svg.EllipseType, es.DragStartPos, e.Pos())
case TextTool:
sv.NewText(es.DragStartPos, e.Pos())
es.NewTextMade = true
case BezierTool:
sv.NewPath(es.DragStartPos, e.Pos())
}
} else {
switch {
case es.Action == "BoxSelect":
sv.SetRubberBand(e.Pos())
}
}
}
})
}
Expand Down Expand Up @@ -701,7 +699,7 @@ func (sv *SVGView) NewElDrag(typ *gti.Type, start, end image.Point) svg.Node {
nr := sv.NewEl(typ)
if rect, ok := nr.(*svg.Rect); ok {
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)
rect.SetPos(xfi.MulVec2AsPt(pos))
sz := dv.Abs().Max(mat32.V2Scalar(minsz / 2))
Expand Down

0 comments on commit d98d04c

Please sign in to comment.