Skip to content

Commit

Permalink
added back in more sprites logic to vector; sprites are now rendering…
Browse files Browse the repository at this point in the history
…, albeit quite poorly
  • Loading branch information
kkoreilly committed Feb 28, 2024
1 parent 5bfeeb8 commit 581d47e
Show file tree
Hide file tree
Showing 5 changed files with 151 additions and 150 deletions.
4 changes: 2 additions & 2 deletions code/code/settings.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import (
)

func init() {
gi.TheApp.SetName("CogentCode")
gi.TheApp.SetName("Cogent Code")
gi.AllSettings = slices.Insert(gi.AllSettings, 1, gi.Settings(Settings))
DefaultKeyMap = "MacEmacs" // todo
SetActiveKeyMapName(DefaultKeyMap)
Expand All @@ -33,7 +33,7 @@ func init() {
var Settings = &SettingsData{
SettingsBase: gi.SettingsBase{
Name: "Code",
File: filepath.Join(gi.TheApp.DataDir(), "CogentCode", "settings.toml"),
File: filepath.Join(gi.TheApp.DataDir(), "Cogent Code", "settings.toml"),
},
}

Expand Down
77 changes: 38 additions & 39 deletions vector/path.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ package vector

import (
"fmt"
"image"

"cogentcore.org/core/events"
"cogentcore.org/core/gi"
Expand Down Expand Up @@ -166,53 +167,51 @@ func (sv *SVGView) PathNodes(path *svg.Path) ([]*PathNode, []int) {
}

func (sv *SVGView) UpdateNodeSprites() {
/*
es := sv.EditState()
prvn := es.NNodeSprites
es := sv.EditState()
prvn := es.NNodeSprites

path := es.FirstSelectedPath()
path := es.FirstSelectedPath()

if path == nil {
sv.RemoveNodeSprites(win)
win.UpdateSig()
return
}
if path == nil {
sv.RemoveNodeSprites()
// win.UpdateSig()
return
}

es.PathNodes, es.PathCmds = sv.PathNodes(path)
es.NNodeSprites = len(es.PathNodes)
es.ActivePath = path
for i, pn := range es.PathNodes {
idx := i // key to get local var
sp := SpriteConnectEvent(win, SpNodePoint, SpUnk, i, image.ZP, sv.This(), func(recv, send ki.Ki, sig int64, d any) {
ssvg := recv.Embed(KiT_SVGView).(*SVGView)
ssvg.NodeSpriteEvent(idx, events.EventType(sig), d)
})
SetSpritePos(sp, image.Point{int(pn.WinPt.X), int(pn.WinPt.Y)})
}
es.PathNodes, es.PathCmds = sv.PathNodes(path)
es.NNodeSprites = len(es.PathNodes)
es.ActivePath = path

for i, pn := range es.PathNodes {
// sp := SpriteConnectEvent(win, SpNodePoint, SpUnk, i, image.ZP, sv.This(), func(recv, send ki.Ki, sig int64, d any) {
// ssvg := recv.Embed(KiT_SVGView).(*SVGView)
// ssvg.NodeSpriteEvent(idx, events.EventType(sig), d)
// })
sp := Sprite(sv, SpNodePoint, SpUnk, i, image.Point{})
SetSpritePos(sp, image.Point{int(pn.WinPt.X), int(pn.WinPt.Y)})
}

// remove extra
for i := es.NNodeSprites; i < prvn; i++ {
spnm := SpriteName(SpNodePoint, SpUnk, i)
win.InactivateSprite(spnm)
}
// remove extra
sprites := &sv.Scene.Stage.Sprites
for i := es.NNodeSprites; i < prvn; i++ {
spnm := SpriteName(SpNodePoint, SpUnk, i)
sprites.InactivateSprite(spnm)
}

sv.VectorView.UpdateNodeToolbar()
*/
sv.VectorView.UpdateNodeToolbar()
}

func (sv *SVGView) RemoveNodeSprites() {
/*
es := sv.EditState()
for i := 0; i < es.NNodeSprites; i++ {
spnm := SpriteName(SpNodePoint, SpUnk, i)
win.InactivateSprite(spnm)
}
es.NNodeSprites = 0
es.PathNodes = nil
es.PathCmds = nil
es.ActivePath = nil
*/
es := sv.EditState()
sprites := &sv.Scene.Stage.Sprites
for i := 0; i < es.NNodeSprites; i++ {
spnm := SpriteName(SpNodePoint, SpUnk, i)
sprites.InactivateSprite(spnm)
}
es.NNodeSprites = 0
es.PathNodes = nil
es.PathCmds = nil
es.ActivePath = nil
}

/*
Expand Down
1 change: 1 addition & 0 deletions vector/prefs.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ var Prefs = Preferences{}

// InitPrefs must be called at startup in mainrun()
func InitPrefs() {
gi.TheApp.SetName("Cogent Vector")
Prefs.Defaults()
Prefs.Open()
// OpenPaths() // todo
Expand Down
190 changes: 95 additions & 95 deletions vector/select.go
Original file line number Diff line number Diff line change
Expand Up @@ -136,10 +136,10 @@ func (sv *SVGView) UpdateSelect() {
}

func (sv *SVGView) RemoveSelSprites() {
// InactivateSprites(win, SpReshapeBBox)
// InactivateSprites(win, SpSelBBox)
// es := sv.EditState()
// es.NSelSprites = 0
InactivateSprites(sv, SpReshapeBBox)
InactivateSprites(sv, SpSelBBox)
es := sv.EditState()
es.NSelSprites = 0
// win.UpdateSig()
}

Expand All @@ -148,84 +148,85 @@ func (sv *SVGView) UpdateSelSprites() {
// updt := win.UpdateStart()
// defer win.UpdateEnd(updt)

// es := sv.EditState()
// es.UpdateSelBBox()
// if !es.HasSelected() {
// sv.RemoveSelSprites(win)
// return
// }
updt := sv.UpdateStart()
defer sv.UpdateEnd(updt)

// for i := SpBBoxUpL; i <= SpBBoxRtM; i++ {
// spi := i // key to get a unique local var
// SpriteConnectEvent(win, SpReshapeBBox, spi, 0, image.ZP, sv.This(), func(recv, send ki.Ki, sig int64, d any) {
// ssvg := recv.Embed(KiT_SVGView).(*SVGView)
// ssvg.SelSpriteEvent(spi, events.EventType(sig), d)
// })
// }
// sv.SetBBoxSpritePos(SpReshapeBBox, 0, es.SelBBox)
// sv.SetSelSpritePos()
es := sv.EditState()
es.UpdateSelBBox()
if !es.HasSelected() {
sv.RemoveSelSprites()
return
}

for i := SpBBoxUpL; i <= SpBBoxRtM; i++ {
// SpriteConnectEvent(win, SpReshapeBBox, spi, 0, image.ZP, sv.This(), func(recv, send ki.Ki, sig int64, d any) {
// ssvg := recv.Embed(KiT_SVGView).(*SVGView)
// ssvg.SelSpriteEvent(spi, events.EventType(sig), d)
// })
Sprite(sv, SpReshapeBBox, i, 0, image.Point{})
}
sv.SetBBoxSpritePos(SpReshapeBBox, 0, es.SelBBox)
sv.SetSelSpritePos()

// win.UpdateSig()
}

func (sv *SVGView) SetSelSpritePos() {
// win := sv.VectorView.ParentWindow()
// es := sv.EditState()
// nsel := es.NSelSprites

// es.NSelSprites = 0
// if len(es.Selected) > 1 {
// nbox := 0
// sl := es.SelectedList(false)
// for si, sii := range sl {
// sn := sii.AsNodeBase()
// if sn.BBox.Size() == image.ZP {
// continue
// }
// bb := mat32.Box2{}
// bb.SetFromRect(sn.BBox)
// sv.SetBBoxSpritePos(SpSelBBox, si, bb)
// nbox++
// }
// es.NSelSprites = nbox
// }
es := sv.EditState()
nsel := es.NSelSprites

es.NSelSprites = 0
if len(es.Selected) > 1 {
nbox := 0
sl := es.SelectedList(false)
for si, sii := range sl {
sn := sii.AsNodeBase()
if sn.BBox.Size() == image.ZP {
continue
}
bb := mat32.Box2{}
bb.SetFromRect(sn.BBox)
sv.SetBBoxSpritePos(SpSelBBox, si, bb)
nbox++
}
es.NSelSprites = nbox
}

// for si := es.NSelSprites; si < nsel; si++ {
// for i := SpBBoxUpL; i <= SpBBoxRtM; i++ {
// spnm := SpriteName(SpSelBBox, i, si)
// win.InactivateSprite(spnm)
// }
// }
sprites := &sv.Scene.Stage.Sprites
for si := es.NSelSprites; si < nsel; si++ {
for i := SpBBoxUpL; i <= SpBBoxRtM; i++ {
spnm := SpriteName(SpSelBBox, i, si)
sprites.InactivateSprite(spnm)
}
}
}

// SetBBoxSpritePos sets positions of given type of sprites
func (sv *SVGView) SetBBoxSpritePos(typ Sprites, idx int, bbox mat32.Box2) {
// win := sv.VectorView.ParentWindow()
// _, spsz := HandleSpriteSize(1)
// midX := int(0.5 * (bbox.Min.X + bbox.Max.X - float32(spsz.X)))
// midY := int(0.5 * (bbox.Min.Y + bbox.Max.Y - float32(spsz.Y)))
// for i := SpBBoxUpL; i <= SpBBoxRtM; i++ {
// spi := i // key to get a unique local var
// sp := Sprite(win, typ, spi, idx, image.ZP)
// switch spi {
// case SpBBoxUpL:
// SetSpritePos(sp, image.Point{int(bbox.Min.X), int(bbox.Min.Y)})
// case SpBBoxUpC:
// SetSpritePos(sp, image.Point{midX, int(bbox.Min.Y)})
// case SpBBoxUpR:
// SetSpritePos(sp, image.Point{int(bbox.Max.X), int(bbox.Min.Y)})
// case SpBBoxDnL:
// SetSpritePos(sp, image.Point{int(bbox.Min.X), int(bbox.Max.Y)})
// case SpBBoxDnC:
// SetSpritePos(sp, image.Point{midX, int(bbox.Max.Y)})
// case SpBBoxDnR:
// SetSpritePos(sp, image.Point{int(bbox.Max.X), int(bbox.Max.Y)})
// case SpBBoxLfM:
// SetSpritePos(sp, image.Point{int(bbox.Min.X), midY})
// case SpBBoxRtM:
// SetSpritePos(sp, image.Point{int(bbox.Max.X), midY})
// }
// }
_, spsz := HandleSpriteSize(1)
midX := int(0.5 * (bbox.Min.X + bbox.Max.X - float32(spsz.X)))
midY := int(0.5 * (bbox.Min.Y + bbox.Max.Y - float32(spsz.Y)))
for i := SpBBoxUpL; i <= SpBBoxRtM; i++ {
sp := Sprite(sv, typ, i, idx, image.ZP)
switch i {
case SpBBoxUpL:
SetSpritePos(sp, image.Point{int(bbox.Min.X), int(bbox.Min.Y)})
case SpBBoxUpC:
SetSpritePos(sp, image.Point{midX, int(bbox.Min.Y)})
case SpBBoxUpR:
SetSpritePos(sp, image.Point{int(bbox.Max.X), int(bbox.Min.Y)})
case SpBBoxDnL:
SetSpritePos(sp, image.Point{int(bbox.Min.X), int(bbox.Max.Y)})
case SpBBoxDnC:
SetSpritePos(sp, image.Point{midX, int(bbox.Max.Y)})
case SpBBoxDnR:
SetSpritePos(sp, image.Point{int(bbox.Max.X), int(bbox.Max.Y)})
case SpBBoxLfM:
SetSpritePos(sp, image.Point{int(bbox.Min.X), midY})
case SpBBoxRtM:
SetSpritePos(sp, image.Point{int(bbox.Max.X), midY})
}
}
}

/*
Expand Down Expand Up @@ -260,33 +261,32 @@ func (sv *SVGView) SelSpriteEvent(sp Sprites, et events.EventType, d any) {

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

// if !es.InAction() {
// es.ActStart("BoxSelect", fmt.Sprintf("%v", es.DragStartPos))
// es.ActUnlock()
// }
// es.DragCurPos = cur
if !es.InAction() {
es.ActStart("BoxSelect", fmt.Sprintf("%v", es.DragStartPos))
es.ActUnlock()
}
es.DragCurPos = cur

// bbox := image.Rectangle{Min: es.DragStartPos, Max: es.DragCurPos}
// bbox = bbox.Canon()
bbox := image.Rectangle{Min: es.DragStartPos, Max: es.DragCurPos}
bbox = bbox.Canon()

// sz := bbox.Size()
// if sz.X < 4 {
// sz.X = 4
// }
// if sz.Y < 4 {
// sz.Y = 4
// }
// rt := Sprite(win, SpRubberBand, SpBBoxUpC, 0, sz)
// rb := Sprite(win, SpRubberBand, SpBBoxDnC, 0, sz)
// rr := Sprite(win, SpRubberBand, SpBBoxRtM, 0, sz)
// rl := Sprite(win, SpRubberBand, SpBBoxLfM, 0, sz)
// SetSpritePos(rt, bbox.Min)
// SetSpritePos(rb, image.Point{bbox.Min.X, bbox.Max.Y})
// SetSpritePos(rr, image.Point{bbox.Max.X, bbox.Min.Y})
// SetSpritePos(rl, bbox.Min)
sz := bbox.Size()
if sz.X < 4 {
sz.X = 4
}
if sz.Y < 4 {
sz.Y = 4
}
rt := Sprite(sv, SpRubberBand, SpBBoxUpC, 0, sz)
rb := Sprite(sv, SpRubberBand, SpBBoxDnC, 0, sz)
rr := Sprite(sv, SpRubberBand, SpBBoxRtM, 0, sz)
rl := Sprite(sv, SpRubberBand, SpBBoxLfM, 0, sz)
SetSpritePos(rt, bbox.Min)
SetSpritePos(rb, image.Point{bbox.Min.X, bbox.Max.Y})
SetSpritePos(rr, image.Point{bbox.Max.X, bbox.Min.Y})
SetSpritePos(rl, bbox.Min)

// win.UpdateSig()
}
Expand Down
Loading

0 comments on commit 581d47e

Please sign in to comment.