8000 Newpaint: updates for new paint / rendering framework in core by rcoreilly · Pull Request #367 · cogentcore/cogent · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Newpaint: updates for new paint / rendering framework in core #367

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 43 commits into from
May 19, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
43 commits
Select commit Hold shift + click to select a range
0b11b74
scroll: added abilities.RemoteScrollable that determines whether a Fr…
rcoreilly Jan 24, 2025
1ca5467
newpaint: support for core newpaint
rcoreilly Feb 14, 2025
be316fd
Merge branch 'main' into newpaint
rcoreilly Feb 16, 2025
4a4dd21
newpaint: update to textcore.Editor etc instead of texteditor
rcoreilly Feb 17, 2025
4febadb
newpaint: updates for textcore -- all updated except lab has issues
rcoreilly Feb 19, 2025
1f11f50
newpaint: code mostly updated to new text framework -- a couple of ke…
rcoreilly Feb 21, 2025
369a570
newpaint: major update to directly maintain Lines for open files, ins…
rcoreilly Feb 22, 2025
a72ce10
newpaint: code building, running
rcoreilly Feb 22, 2025
76f405c
textcore: completer, lookup config updates; renames
rcoreilly Feb 22, 2025
35dec66
textcore: command output all working with latest
rcoreilly Feb 23, 2025
a948787
textcore: search updated to new api in text/search
rcoreilly Feb 24, 2025
8644ebf
textcore: search mostly working -- links and <mark> not
rcoreilly Feb 24, 2025
ea6de61
textcore: find panel markup and links mostly working
rcoreilly Feb 24, 2025
3516a6a
textcore: links logic all good.
rcoreilly Feb 24, 2025
f956573
textcore: find / replace logic fully functional finally
rcoreilly Feb 25, 2025
868befb
textcore: minor fixes
rcoreilly Feb 25, 2025
8e4f63d
safety fix
rcoreilly Feb 25, 2025
9347948
textcore: minor fixes
rcoreilly Feb 25, 2025
44251d1
textcore: openpaths minor fix
rcoreilly Feb 26, 2025
cb983df
newpaint: autosave logic, debug panel hangs, etc fixes.
rcoreilly Feb 27, 2025
6ac174c
newpaint: marbles updated to new canvas with direct rendering: pretty…
rcoreilly Feb 28, 2025
e452ba0
textcore: fix searching in open files: filepath separator suffix again..
rcoreilly Feb 28, 2025
ea4e643
marbles: try WindowPaint based approach for rendering
kkoreilly Feb 28, 2025
2eeed33
marbles: max = 100_000
rcoreilly Mar 1, 2025
44627b4
textcore: try to remember to use filepath.Dir() instead of Split when…
rcoreilly Mar 2, 2025
8787def
marbles: massive performance improvement for graph button: only compi…
kkoreilly Mar 3, 2025
c489c22
textcore: major update to new vcs / filetree for fast status updating…
rcoreilly Mar 5, 2025
e02c025
textcore: comment reformats
rcoreilly Mar 6, 2025
5f8ef1a
textcore: close open files logic
rcoreilly Mar 8, 2025
2d4748b
newpaint: misc updates to core newpaint, and FindFames takes a partia…
rcoreilly Apr 3, 2025
fb84869
mail: update to use better circle for unread indicator
kkoreilly Apr 18, 2025
cd65cf3
newpaint: code updates: fix preview updating logic, status and textbu…
rcoreilly Apr 26, 2025
082eb35
newpaint: regexp search uses Dir instead of Path and now works
rcoreilly May 7, 2025
e94e917
marbles: update to core newpaint renames
kkoreilly May 18, 2025
71cf200
marbles: use Animate
kkoreilly May 18, 2025
40ca3b1
marbles: remove old NFramesPer logic
kkoreilly May 18, 2025
8673715
marbles: improve time step logic and multiply by a.Dt
kkoreilly May 18, 2025
c05c9d6
marbles: more work on using dt
kkoreilly May 18, 2025
3555d92
newpaint: canvas builds, crashes
rcoreilly May 19, 2025
9853add
newpaint: go mod update
rcoreilly May 19, 2025
f67d082
newpaint: all building and tests passing..
rcoreilly May 19, 2025
5394f09
newpaint: update to lab, and canvas interim progress
rcoreilly May 19, 2025
e18afc9
newpaint: review comments
rcoreilly May 19, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion author/refs/bibtex.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import (
"strings"

"cogentcore.org/core/base/fsx"
"cogentcore.org/core/parse/languages/bibtex"
"cogentcore.org/core/text/parse/languages/bibtex"
)

// BibTexCited extracts markdown citations in the format [@Ref] from .md files and
Expand Down
3 changes: 2 additions & 1 deletion canvas/markers.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (

"cogentcore.org/core/base/reflectx"
"cogentcore.org/core/icons"
"cogentcore.org/core/math32"
"cogentcore.org/core/svg"
"cogentcore.org/core/tree"
)
Expand Down Expand Up @@ -121,7 +122,7 @@ func MarkerDeleteCtxtColors(mk *svg.Marker) {

// NewMarkerFromXML makes a new marker from given XML source.
func NewMarkerFromXML(name, xml string) *svg.Marker {
tmpsvg := svg.NewSVG(0, 0)
tmpsvg := svg.NewSVG(math32.Vec2(0, 0))
b := bytes.NewBufferString(xml)
err := tmpsvg.ReadXML(b)
if err != nil && err != io.EOF {
Expand Down
34 changes: 17 additions & 17 deletions canvas/paint.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ func (pv *PaintView) Init() {
})
})
tree.AddChild(w, func(w *core.Spinner) {
core.Bind(&pv.PaintStyle.StrokeStyle.Width.Value, w)
core.Bind(&pv.PaintStyle.Stroke.Width.Value, w)
w.SetMin(0).SetStep(0.05)
w.OnChange(func(e events.Event) {
if pv.IsStrokeOn() {
Expand All @@ -102,7 +102,7 @@ func (pv *PaintView) Init() {

// uncb.SetCurrentIndex(int(Settings.Size.Units))
tree.AddChild(w, func(w *core.Chooser) {
core.Bind(&pv.PaintStyle.StrokeStyle.Width.Unit, w)
core.Bind(&pv.PaintStyle.Stroke.Width.Unit, w)
w.OnChange(func(e events.Event) {
if pv.IsStrokeOn() {
pv.Canvas.SetStrokeWidth(pv.StrokeWidthProp(), false)
Expand Down Expand Up @@ -207,7 +207,7 @@ func (pv *PaintView) Init() {
tree.AddChild(w, func(w *core.Frame) {}) // "stroke-blank"

tree.AddChild(w, func(w *core.ColorPicker) {
core.Bind(&pv.PaintStyle.StrokeStyle.Color, w)
core.Bind(&pv.PaintStyle.Stroke.Color, w)
w.OnChange(func(e events.Event) {
if pv.StrokeType == PaintSolid {
pv.Canvas.SetStrokeColor(pv.StrokeProp(), false) // not manip
Expand Down Expand Up @@ -271,7 +271,7 @@ func (pv *PaintView) Init() {
tree.AddChild(w, func(w *core.Frame) {}) // "fill-blank"

tree.AddChild(w, func(w *core.ColorPicker) {
core.Bind(&pv.PaintStyle.FillStyle.Color, w)
core.Bind(&pv.PaintStyle.Fill.Color, w)
w.OnChange(func(e events.Event) {
if pv.FillType == PaintSolid {
pv.Canvas.SetFillColor(pv.FillProp(), false) // not manip
Expand Down Expand Up @@ -409,7 +409,7 @@ func (vv *Canvas) SetStrokeWidthNode(sii svg.Node, wp string) {
return
}
g := sii.AsNodeBase()
if g.Paint.StrokeStyle.Color != nil {
if g.Paint.Stroke.Color != nil {
g.SetProperty("stroke-width", wp)
}
}
Expand Down Expand Up @@ -495,7 +495,7 @@ func (vv *Canvas) SetDashNode(sii svg.Node, dary []float64) {
return
}
g := sii.AsNodeBase()
mary := DashMulWidth(float64(g.Paint.StrokeStyle.Width.Dots), dary)
mary := DashMulWidth(float64(g.Paint.Stroke.Width.Dots), dary)
ds := DashString(mary)
sii.AsTree().Properties["stroke-dasharray"] = ds
}
Expand Down Expand Up @@ -572,8 +572,8 @@ func (pv *PaintView) Update(pc *paint.Paint, kn tree.Node) {
update := pv.UpdateStart()
defer pv.UpdateEnd(update)

pv.StrokeType, pv.StrokeStops = pv.DecodeType(kn, &pc.StrokeStyle.Color, "stroke")
pv.FillType, pv.FillStops = pv.DecodeType(kn, &pc.FillStyle.Color, "fill")
pv.StrokeType, pv.StrokeStops = pv.DecodeType(kn, &pc.Stroke.Color, "stroke")
pv.FillType, pv.FillStops = pv.DecodeType(kn, &pc.Fill.Color, "fill")

es := &pv.Vector.EditState
grl := &es.Gradients
Expand All @@ -590,7 +590,7 @@ func (pv *PaintView) Update(pc *paint.Paint, kn tree.Node) {
}
ss.StackTop = 1
sc := ss.ChildByName("stroke-clr", 1).(*core.ColorPicker)
sc.SetColor(pc.StrokeStyle.Color.Color)
sc.SetColor(pc.Stroke.Color.Color)
case PaintLinear, PaintRadial:
if ss.StackTop != 2 {
ss.SetFullReRender()
Expand All @@ -608,12 +608,12 @@ func (pv *PaintView) Update(pc *paint.Paint, kn tree.Node) {

wr := pv.ChildByName("stroke-width", 2)
wsb := wr.ChildByName("width", 1).(*core.Spinner)
wsb.SetValue(pc.StrokeStyle.Width.Val)
wsb.SetValue(pc.Stroke.Width.Val)
uncb := wr.ChildByName("width-units", 2).(*core.Chooser)
uncb.SetCurrentIndex(int(pc.StrokeStyle.Width.Un))
uncb.SetCurrentIndex(int(pc.Stroke.Width.Un))

dshcb := wr.ChildByName("dashes", 3).(*core.Chooser)
nwdsh, dnm := DashMatchArray(float64(pc.StrokeStyle.Width.Dots), pc.StrokeStyle.Dashes)
nwdsh, dnm := DashMatchArray(float64(pc.Stroke.Width.Dots), pc.Stroke.Dashes)
if nwdsh {
dshcb.ItemsFromIconList(AllDashIcons, false, 0)
}
Expand Down Expand Up @@ -664,7 +664,7 @@ func (pv *PaintView) Update(pc *paint.Paint, kn tree.Node) {
}
fs.StackTop = 1
fc := fs.ChildByName("fill-clr", 1).(*core.ColorPicker)
fc.SetColor(pc.FillStyle.Color.Color)
fc.SetColor(pc.Fill.Color.Color)
case PaintLinear, PaintRadial:
if fs.StackTop != 2 {
fs.SetFullReRender()
Expand Down Expand Up @@ -777,7 +777,7 @@ func (pv *PaintView) StrokeProp() string {
case PaintOff:
return "none"
case PaintSolid:
return colors.AsHex(colors.ToUniform(pv.PaintStyle.StrokeStyle.Color))
return colors.AsHex(colors.ToUniform(pv.PaintStyle.Stroke.Color))
case PaintLinear:
return pv.StrokeStops
case PaintRadial:
Expand Down Expand Up @@ -818,8 +818,8 @@ func (pv *PaintView) IsStrokeOn() bool {

// StrokeWidthProp returns stroke-width property
func (pv *PaintView) StrokeWidthProp() string {
unnm := pv.PaintStyle.StrokeStyle.Width.Unit.String()
return fmt.Sprintf("%g%s", pv.PaintStyle.StrokeStyle.Width.Value, unnm)
unnm := pv.PaintStyle.Stroke.Width.Unit.String()
return fmt.Sprintf("%g%s", pv.PaintStyle.Stroke.Width.Value, unnm)
}

// StrokeDashProp returns stroke-dasharray property as an array (nil = none)
Expand Down Expand Up @@ -854,7 +854,7 @@ func (pv *PaintView) FillProp() string {
case PaintOff:
return "none"
case PaintSolid:
return colors.AsHex(colors.ToUniform(pv.PaintStyle.FillStyle.Color))
return colors.AsHex(colors.ToUniform(pv.PaintStyle.Fill.Color))
case PaintLinear:
return pv.FillStops
case PaintRadial:
Expand Down
123 changes: 63 additions & 60 deletions canvas/path.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (

"cogentcore.org/core/core"
"cogentcore.org/core/math32"
"cogentcore.org/core/paint/ppath"
"cogentcore.org/core/svg"
"cogentcore.org/core/tree"
)
Expand Down Expand Up @@ -99,10 +100,10 @@ func (vv *Canvas) NodeSetYPos(yp float32) {
type PathNode struct {

// path command
Cmd svg.PathCmds
Cmd ppath.Path

// previous path command
PrevCmd svg.PathCmds
PrevCmd ppath.Path

// starting index of command
CmdIndex int
Expand All @@ -128,28 +129,29 @@ type PathNode struct {

// PathNodes returns the PathNode data for given path data, and a lis CEB7 t of indexes where commands start
func (sv *SVG) PathNodes(path *svg.Path) ([]*PathNode, []int) {
svoff := math32.FromPoint(sv.Geom.ContentBBox.Min)
pxf := path.ParTransform(true) // include self

lstCmdIndex := 0
lstCmd := svg.PcErr
nc := make([]*PathNode, 0)
cidxs := make([]int, 0)
var pcp math32.Vector2
svg.PathDataIterFunc(path.Data, func(idx int, cmd svg.PathCmds, ptIndex int, cp math32.Vector2, ctrl []math32.Vector2) bool {
cw := pxf.MulVector2AsPoint(cp).Add(svoff)

if ptIndex == 0 {
lstCmdIndex = idx - 1
cidxs = append(cidxs, lstCmdIndex)
}
pn := &PathNode{Cmd: cmd, PrevCmd: lstCmd, CmdIndex: lstCmdIndex, Index: idx, PtIndex: ptIndex, PCp: pcp, Cp: cp, WinPt: cw, WinCtrls: ctrl}
nc = append(nc, pn)
pcp = cp
lstCmd = cmd
return tree.Continue
})
return nc, cidxs
return nil, nil
// svoff := math32.FromPoint(sv.Geom.ContentBBox.Min)
// pxf := path.ParentTransform(true) // include self
//
// lstCmdIndex := 0
// lstCmd := svg.PcErr
// nc := make([]*PathNode, 0)
// cidxs := make([]int, 0)
// var pcp math32.Vector2
// svg.PathDataIterFunc(path.Data, func(idx int, cmd svg.PathCmds, ptIndex int, cp math32.Vector2, ctrl []math32.Vector2) bool {
// cw := pxf.MulVector2AsPoint(cp).Add(svoff)
//
// if ptIndex == 0 {
// lstCmdIndex = idx - 1
// cidxs = append(cidxs, lstCmdIndex)
// }
// pn := &PathNode{Cmd: cmd, PrevCmd: lstCmd, CmdIndex: lstCmdIndex, Index: idx, PtIndex: ptIndex, PCp: pcp, Cp: cp, WinPt: cw, WinCtrls: ctrl}
// nc = append(nc, pn)
// pcp = cp
// lstCmd = cmd
// return tree.Continue
// })
// return nc, cidxs
}

func (sv *SVG) UpdateNodeSprites() {
Expand Down Expand Up @@ -227,48 +229,49 @@ func (sv *SVG) NodeSpriteEvent(idx int, et events.Type, d any) {
// direction to compensate, so only the one point is moved in effect.
// svoff is the window starting vector coordinate for view.
func (sv *SVG) PathNodeSetOnePoint(path *svg.Path, pts []*PathNode, pidx int, dv math32.Vector2, svoff math32.Vector2) {
for i := pidx; i < len(pts); i++ {
pn := pts[i]
wbmin := math32.FromPoint(path.BBox.Min)
pt := wbmin.Sub(svoff)
xf, lpt := path.DeltaTransform(dv, math32.Vec2(1, 1), 0, pt, true) // include self
npt := xf.MulVector2AsPointCenter(pn.Cp, lpt) // transform point to new abs coords
sv.PathNodeSetPoint(path, pn, npt)
if i == pidx {
dv = dv.MulScalar(-1)
} else {
if !svg.PathCmdIsRel(pn.Cmd) || pn.Cmd == svg.PcZ || pn.Cmd == svg.Pcz || pn.Cmd == svg.Pcm || pn.Cmd == svg.PcM {
break
}
}
}
return
// for i := pidx; i < len(pts); i++ {
// pn := pts[i]
// wbmin := math32.FromPoint(path.BBox.Min)
// pt := wbmin.Sub(svoff)
// xf, lpt := path.DeltaTransform(dv, math32.Vec2(1, 1), 0, pt, true) // include self
// npt := xf.MulVector2AsPointCenter(pn.Cp, lpt) // transform point to new abs coords
// sv.PathNodeSetPoint(path, pn, npt)
// if i == pidx {
// dv = dv.MulScalar(-1)
// } else {
// if !svg.PathCmdIsRel(pn.Cmd) || pn.Cmd == svg.PcZ || pn.Cmd == svg.Pcz || pn.Cmd == svg.Pcm || pn.Cmd == svg.PcM {
// break
// }
// }
// }
}

// PathNodeSetPoint sets data point for path node to given new point value
// which is in *absolute* (but local) coordinates -- translates into
// relative coordinates as needed.
func (sv *SVG) PathNodeSetPoint(path *svg.Path, pn *PathNode, npt math32.Vector2) {
if pn.Index == 1 || !svg.PathCmdIsRel(pn.Cmd) { // abs
switch pn.Cmd {
case svg.PcH:
path.Data[pn.Index] = svg.PathData(npt.X)
case svg.PcV:
path.Data[pn.Index] = svg.PathData(npt.Y)
default:
path.Data[pn.Index] = svg.PathData(npt.X)
path.Data[pn.Index+1] = svg.PathData(npt.Y)
}
} else {
switch pn.Cmd {
case svg.Pch:
path.Data[pn.Index] = svg.PathData(npt.X - pn.PCp.X)
case svg.Pcv:
path.Data[pn.Index] = svg.PathData(npt.Y - pn.PCp.Y)
default:
path.Data[pn.Index] = svg.PathData(npt.X - pn.PCp.X)
path.Data[pn.Index+1] = svg.PathData(npt.Y - pn.PCp.Y)
}
}
// if pn.Index == 1 || !svg.PathCmdIsRel(pn.Cmd) { // abs
// switch pn.Cmd {
// case svg.PcH:
// path.Data[pn.Index] = svg.PathData(npt.X)
// case svg.PcV:
// path.Data[pn.Index] = svg.PathData(npt.Y)
// default:
// path.Data[pn.Index] = svg.PathData(npt.X)
// path.Data[pn.Index+1] = svg.PathData(npt.Y)
// }
// } else {
// switch pn.Cmd {
// case svg.Pch:
// path.Data[pn.Index] = svg.PathData(npt.X - pn.PCp.X)
// case svg.Pcv:
// path.Data[pn.Index] = svg.PathData(npt.Y - pn.PCp.Y)
// default:
// path.Data[pn.Index] = svg.PathData(npt.X - pn.PCp.X)
// path.Data[pn.Index+1] = svg.PathData(npt.Y - pn.PCp.Y)
// }
// }
}

/*
Expand Down
1 change: 0 additions & 1 deletion canvas/select.go
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,6 @@ func (sv *SVG) SetSelSpritePos() {
sprites.InactivateSprite(spnm)
}
}
sprites.Modified = true
}

// SetBBoxSpritePos sets positions of given type of sprites
Expand Down
24 changes: 12 additions & 12 deletions canvas/settings.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,21 +73,21 @@ type SettingsData struct { //types:add
func (se *SettingsData) Defaults() {
se.Size.Defaults()
se.ShapeStyle.Defaults()
se.ShapeStyle.FontStyle.Family = string(core.AppearanceSettings.Font)
se.ShapeStyle.FontStyle.Size.Dp(16)
se.ShapeStyle.FillStyle.Color = colors.Scheme.OnSurface
// se.ShapeStyle.Font.Family = string(core.AppearanceSettings.Font)
// se.ShapeStyle.Font.Size = 1
se.ShapeStyle.Fill.Color = colors.Scheme.OnSurface
se.TextStyle.Defaults()
se.TextStyle.FontStyle.Family = string(core.AppearanceSettings.Font)
se.TextStyle.FontStyle.Size.Dp(16)
se.TextStyle.FillStyle.Color = colors.Scheme.OnSurface
// se.TextStyle.Font.Family = string(core.AppearanceSettings.Font)
// se.TextStyle.Font.Size.Dp(16)
se.TextStyle.Fill.Color = colors.Scheme.OnSurface
se.PathStyle.Defaults()
se.PathStyle.FontStyle.Family = string(core.AppearanceSettings.Font)
se.PathStyle.FontStyle.Size.Dp(16)
se.PathStyle.StrokeStyle.Color = colors.Scheme.OnSurface
// se.PathStyle.Font.Family = string(core.AppearanceSettings.Font)
// se.PathStyle.Font.Size.Dp(16)
se.PathStyle.Stroke.Color = colors.Scheme.OnSurface
se.LineStyle.Defaults()
se.LineStyle.FontStyle.Family = string(core.AppearanceSettings.Font)
se.LineStyle.FontStyle.Size.Dp(16)
se.LineStyle.StrokeStyle.Color = colors.Scheme.OnSurface
// se.LineStyle.Font.Family = string(core.AppearanceSettings.Font)
// se.LineStyle.Font.Size.Dp(16)
se.LineStyle.Stroke.Color = colors.Scheme.OnSurface
se.GridDisp = true
se.SnapTol = 3
se.SnapGrid = true
Expand Down
3 changes: 0 additions & 3 deletions canvas/sprites.go
Original file line number Diff line number Diff line change
Expand Up @@ -160,15 +160,13 @@ func Sprite(ctx core.Widget, typ, subtyp Sprites, idx int, trgsz image.Point, in
}
switch typ {
case SpRubberBand:
sprites.Modified = true
switch subtyp {
case SpBBoxUpC, SpBBoxDnC:
DrawRubberBandHoriz(sp, trgsz)
case SpBBoxLfM, SpBBoxRtM:
DrawRubberBandVert(sp, trgsz)
}
case SpAlignMatch:
sprites.Modified = true
switch {
case trgsz.X > trgsz.Y:
DrawAlignMatchHoriz(sp, trgsz)
Expand Down Expand Up @@ -235,7 +233,6 @@ func InactivateSprites(ctx core.Widget, typ Sprites) {
sprites.InactivateSprite(sp.Name)
}
}
sprites.Modified = true // needed to trigger redraw of sprites
}

///////////////////////////////////////////////////////////////////
Expand Down
Loading
Loading
0