2019-07-03 23:22:30 +00:00
|
|
|
package uix
|
|
|
|
|
|
|
|
import (
|
|
|
|
"git.kirsle.net/apps/doodle/pkg/balance"
|
|
|
|
"git.kirsle.net/apps/doodle/pkg/drawtool"
|
|
|
|
"git.kirsle.net/apps/doodle/pkg/level"
|
|
|
|
"git.kirsle.net/apps/doodle/pkg/log"
|
2021-06-10 05:36:32 +00:00
|
|
|
"git.kirsle.net/apps/doodle/pkg/pattern"
|
2019-07-05 23:04:36 +00:00
|
|
|
"git.kirsle.net/apps/doodle/pkg/shmem"
|
2019-12-31 02:13:28 +00:00
|
|
|
"git.kirsle.net/go/render"
|
|
|
|
"git.kirsle.net/go/ui"
|
2019-07-03 23:22:30 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
// canvas_strokes.go: functions related to drawtool.Stroke and the Canvas.
|
|
|
|
|
|
|
|
// AddStroke installs a new Stroke to be superimposed over drawing data
|
|
|
|
// in the canvas.
|
|
|
|
//
|
|
|
|
// The stroke is added to the canvas's map by its ID so it can be removed later.
|
|
|
|
// The stroke must have a non-zero ID value set or this function will panic.
|
|
|
|
// drawtool.NewStroke() creates an initialized Stroke object to use here.
|
|
|
|
func (w *Canvas) AddStroke(stroke *drawtool.Stroke) {
|
|
|
|
if stroke.ID == 0 {
|
|
|
|
panic("Canvas.AddStroke: the Stroke is missing an ID; was it initialized properly?")
|
|
|
|
}
|
|
|
|
|
|
|
|
w.strokes[stroke.ID] = stroke
|
|
|
|
}
|
|
|
|
|
|
|
|
// RemoveStroke uninstalls a Stroke from the canvas using its ID.
|
|
|
|
//
|
|
|
|
// Returns true if the stroke existed to begin with, false if not.
|
|
|
|
func (w *Canvas) RemoveStroke(stroke *drawtool.Stroke) bool {
|
|
|
|
if _, ok := w.strokes[stroke.ID]; ok {
|
|
|
|
delete(w.strokes, stroke.ID)
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
|
|
|
// UndoStroke rolls back the level's UndoHistory and deletes the pixels last
|
|
|
|
// added to the level. Returns false and emits a warning to the log if the
|
|
|
|
// canvas has no level loaded properly.
|
|
|
|
func (w *Canvas) UndoStroke() bool {
|
2021-10-11 23:10:04 +00:00
|
|
|
var undoer *drawtool.History
|
|
|
|
if w.level != nil {
|
|
|
|
undoer = w.level.UndoHistory
|
|
|
|
} else if w.doodad != nil {
|
|
|
|
undoer = w.doodad.UndoHistory
|
|
|
|
} else {
|
|
|
|
log.Error("Canvas.UndoStroke: no Level or Doodad currently available to the canvas")
|
2019-07-03 23:22:30 +00:00
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
2021-10-11 23:10:04 +00:00
|
|
|
latest := undoer.Latest()
|
2019-07-03 23:22:30 +00:00
|
|
|
if latest != nil {
|
Eraser Tool, Brush Sizes
* Implement Brush Sizes for drawtool.Stroke and add a UI to the tools panel
to control the brush size.
* Brush sizes: 1, 2, 4, 8, 16, 24, 32, 48, 64
* Add the Eraser Tool to editor mode. It uses a default brush size of 16
and a max size of 32 due to some performance issues.
* The Undo/Redo system now remembers the original color of pixels when
you change them, so that Undo will set them back how they were instead
of deleting the pixel entirely. Due to performance issues, this only
happens when your Brush Size is 0 (drawing single-pixel shapes).
* UI: Add an IntVariable option to ui.Label to bind showing the value of
an int reference.
Aforementioned performance issues:
* When we try to remember whole rects of pixels for drawing thick
shapes, it requires a ton of scanning for each step of the shape. Even
de-duplicating pixel checks, tons of extra reads are constantly
checked.
* The Eraser is the only tool that absolutely needs to be able to
remember wiped pixels AND have large brush sizes. The performance
sucks and lags a bit if you erase a lot all at once, but it's a
trade-off for now.
* So pixels aren't remembered when drawing lines in your level with
thick brushes, so the Undo action will simply delete your pixels and not
reset them. Only the Eraser can bring back pixels.
2019-07-12 02:07:46 +00:00
|
|
|
// TODO: only single-thickness lines will restore the original color;
|
|
|
|
// thick lines just delete their pixels from the world due to performance.
|
|
|
|
// But the Eraser Tool is always thick, which always should restore its
|
|
|
|
// pixels. Can't do anything about that, so the inefficient thick rect
|
|
|
|
// restore is used only for Eraser at least.
|
|
|
|
if latest.Thickness > 0 {
|
|
|
|
if latest.Shape == drawtool.Eraser {
|
|
|
|
for rect := range latest.IterThickPoints() {
|
|
|
|
var (
|
|
|
|
xMin = rect.X
|
|
|
|
xMax = rect.X + rect.W
|
|
|
|
yMin = rect.Y
|
|
|
|
yMax = rect.Y + rect.H
|
|
|
|
)
|
|
|
|
for x := xMin; x < xMax; x++ {
|
|
|
|
for y := yMin; y < yMax; y++ {
|
|
|
|
if v, ok := latest.OriginalPoints[render.NewPoint(x, y)]; ok {
|
|
|
|
if swatch, ok := v.(*level.Swatch); ok {
|
|
|
|
w.chunks.Set(render.NewPoint(x, y), swatch)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
for rect := range latest.IterThickPoints() {
|
|
|
|
w.chunks.DeleteRect(rect)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
for point := range latest.IterPoints() {
|
|
|
|
// Was there a previous swatch at this point to restore?
|
|
|
|
if v, ok := latest.OriginalPoints[point]; ok {
|
|
|
|
if swatch, ok := v.(*level.Swatch); ok {
|
|
|
|
w.chunks.Set(point, swatch)
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
w.chunks.Delete(point)
|
|
|
|
}
|
|
|
|
|
2019-07-03 23:22:30 +00:00
|
|
|
}
|
|
|
|
}
|
2021-10-11 23:10:04 +00:00
|
|
|
return undoer.Undo()
|
2019-07-03 23:22:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// RedoStroke rolls the level's UndoHistory forwards again and replays the
|
|
|
|
// recently undone changes.
|
|
|
|
func (w *Canvas) RedoStroke() bool {
|
2021-10-11 23:10:04 +00:00
|
|
|
var undoer *drawtool.History
|
|
|
|
if w.level != nil {
|
|
|
|
undoer = w.level.UndoHistory
|
|
|
|
} else if w.doodad != nil {
|
|
|
|
undoer = w.doodad.UndoHistory
|
|
|
|
} else {
|
|
|
|
log.Error("Canvas.UndoStroke: no Level or Doodad currently available to the canvas")
|
2019-07-03 23:22:30 +00:00
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
2021-10-11 23:10:04 +00:00
|
|
|
ok := undoer.Redo()
|
2019-07-03 23:22:30 +00:00
|
|
|
if !ok {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
2021-10-11 23:10:04 +00:00
|
|
|
latest := undoer.Latest()
|
2019-07-03 23:22:30 +00:00
|
|
|
|
|
|
|
// We stored the ActiveSwatch on this stroke as we drew it. Recover it
|
|
|
|
// and place the pixels back down.
|
Eraser Tool, Brush Sizes
* Implement Brush Sizes for drawtool.Stroke and add a UI to the tools panel
to control the brush size.
* Brush sizes: 1, 2, 4, 8, 16, 24, 32, 48, 64
* Add the Eraser Tool to editor mode. It uses a default brush size of 16
and a max size of 32 due to some performance issues.
* The Undo/Redo system now remembers the original color of pixels when
you change them, so that Undo will set them back how they were instead
of deleting the pixel entirely. Due to performance issues, this only
happens when your Brush Size is 0 (drawing single-pixel shapes).
* UI: Add an IntVariable option to ui.Label to bind showing the value of
an int reference.
Aforementioned performance issues:
* When we try to remember whole rects of pixels for drawing thick
shapes, it requires a ton of scanning for each step of the shape. Even
de-duplicating pixel checks, tons of extra reads are constantly
checked.
* The Eraser is the only tool that absolutely needs to be able to
remember wiped pixels AND have large brush sizes. The performance
sucks and lags a bit if you erase a lot all at once, but it's a
trade-off for now.
* So pixels aren't remembered when drawing lines in your level with
thick brushes, so the Undo action will simply delete your pixels and not
reset them. Only the Eraser can bring back pixels.
2019-07-12 02:07:46 +00:00
|
|
|
w.currentStroke = latest
|
|
|
|
w.commitStroke(w.Tool, false)
|
2019-07-03 23:22:30 +00:00
|
|
|
|
|
|
|
return ok
|
|
|
|
}
|
|
|
|
|
|
|
|
// presentStrokes is called as part of Present() and draws the strokes whose
|
|
|
|
// pixels are currently visible within the viewport.
|
|
|
|
func (w *Canvas) presentStrokes(e render.Engine) {
|
2019-07-03 23:51:23 +00:00
|
|
|
// Turn stroke map into a list.
|
|
|
|
var strokes []*drawtool.Stroke
|
|
|
|
for _, stroke := range w.strokes {
|
|
|
|
strokes = append(strokes, stroke)
|
|
|
|
}
|
2021-06-03 03:41:53 +00:00
|
|
|
w.DrawStrokes(e, strokes)
|
2019-07-03 23:51:23 +00:00
|
|
|
|
|
|
|
// Dynamic actor links visible in the ActorTool and LinkTool.
|
2019-07-04 00:19:25 +00:00
|
|
|
if w.Tool == drawtool.ActorTool || w.Tool == drawtool.LinkTool {
|
2019-07-03 23:51:23 +00:00
|
|
|
w.presentActorLinks(e)
|
|
|
|
}
|
2022-03-05 23:31:09 +00:00
|
|
|
|
|
|
|
// Text Tool preview.
|
|
|
|
if w.Tool == drawtool.TextTool && drawtool.TT.Label != nil {
|
|
|
|
drawtool.TT.Label.Present(e, shmem.Cursor)
|
|
|
|
}
|
2019-07-03 23:51:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// presentActorLinks draws strokes connecting actors together by their links.
|
|
|
|
// TODO: the strokes are computed dynamically every tick in here, might be a
|
|
|
|
// way to better optimize later.
|
|
|
|
func (w *Canvas) presentActorLinks(e render.Engine) {
|
|
|
|
var (
|
|
|
|
strokes = []*drawtool.Stroke{}
|
|
|
|
actorMap = map[string]*Actor{}
|
|
|
|
)
|
|
|
|
|
|
|
|
// Loop over actors and collect linked ones into the map.
|
|
|
|
for _, actor := range w.actors {
|
|
|
|
if len(actor.Actor.Links) > 0 {
|
|
|
|
actorMap[actor.ID()] = actor
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-07-05 23:04:36 +00:00
|
|
|
// If no links, stop.
|
|
|
|
if len(actorMap) == 0 {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
// The glow colored line. Huge hacky block of code but makes for some
|
|
|
|
// basic visualization for now.
|
|
|
|
var color = balance.LinkLineColor
|
|
|
|
var lightenStep = float64(balance.LinkLighten) / 16
|
|
|
|
var step = shmem.Tick % balance.LinkAnimSpeed
|
|
|
|
if step < 32 {
|
|
|
|
for i := uint64(0); i < step; i++ {
|
|
|
|
color = color.Lighten(int(lightenStep))
|
|
|
|
}
|
|
|
|
if step > 16 {
|
|
|
|
for i := uint64(0); i < step-16; i++ {
|
|
|
|
color = color.Darken(int(lightenStep))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-07-03 23:51:23 +00:00
|
|
|
// Loop over the linked actors and draw stroke lines.
|
|
|
|
for _, actor := range actorMap {
|
|
|
|
for _, linkID := range actor.Actor.Links {
|
|
|
|
if _, ok := actorMap[linkID]; !ok {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
|
|
|
var (
|
|
|
|
aP = actor.Position()
|
|
|
|
aS = actor.Size()
|
|
|
|
bP = actorMap[linkID].Position()
|
|
|
|
bS = actorMap[linkID].Size()
|
|
|
|
)
|
|
|
|
|
2021-09-12 22:26:51 +00:00
|
|
|
// Adapt actor positions per the zoom level.
|
|
|
|
aP.X = w.ZoomMultiply(aP.X)
|
|
|
|
aP.Y = w.ZoomMultiply(aP.Y)
|
|
|
|
bP.X = w.ZoomMultiply(bP.X)
|
|
|
|
bP.Y = w.ZoomMultiply(bP.Y)
|
|
|
|
|
2019-07-03 23:51:23 +00:00
|
|
|
// Draw a line connecting the centers of each actor together.
|
2019-07-05 23:04:36 +00:00
|
|
|
stroke := drawtool.NewStroke(drawtool.Line, color)
|
2019-07-03 23:51:23 +00:00
|
|
|
stroke.PointA = render.Point{
|
|
|
|
X: aP.X + (aS.W / 2),
|
|
|
|
Y: aP.Y + (aS.H / 2),
|
|
|
|
}
|
|
|
|
stroke.PointB = render.Point{
|
|
|
|
X: bP.X + (bS.W / 2),
|
|
|
|
Y: bP.Y + (bS.H / 2),
|
|
|
|
}
|
|
|
|
|
|
|
|
strokes = append(strokes, stroke)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-06-03 03:41:53 +00:00
|
|
|
w.DrawStrokes(e, strokes)
|
2019-07-03 23:51:23 +00:00
|
|
|
}
|
|
|
|
|
2021-06-03 03:41:53 +00:00
|
|
|
// DrawStrokes is the common base function behind presentStrokes and
|
2019-07-03 23:51:23 +00:00
|
|
|
// presentActorLinks to actually draw the lines to the canvas.
|
2021-06-03 03:41:53 +00:00
|
|
|
func (w *Canvas) DrawStrokes(e render.Engine, strokes []*drawtool.Stroke) {
|
2019-07-03 23:22:30 +00:00
|
|
|
var (
|
Eraser Tool, Brush Sizes
* Implement Brush Sizes for drawtool.Stroke and add a UI to the tools panel
to control the brush size.
* Brush sizes: 1, 2, 4, 8, 16, 24, 32, 48, 64
* Add the Eraser Tool to editor mode. It uses a default brush size of 16
and a max size of 32 due to some performance issues.
* The Undo/Redo system now remembers the original color of pixels when
you change them, so that Undo will set them back how they were instead
of deleting the pixel entirely. Due to performance issues, this only
happens when your Brush Size is 0 (drawing single-pixel shapes).
* UI: Add an IntVariable option to ui.Label to bind showing the value of
an int reference.
Aforementioned performance issues:
* When we try to remember whole rects of pixels for drawing thick
shapes, it requires a ton of scanning for each step of the shape. Even
de-duplicating pixel checks, tons of extra reads are constantly
checked.
* The Eraser is the only tool that absolutely needs to be able to
remember wiped pixels AND have large brush sizes. The performance
sucks and lags a bit if you erase a lot all at once, but it's a
trade-off for now.
* So pixels aren't remembered when drawing lines in your level with
thick brushes, so the Undo action will simply delete your pixels and not
reset them. Only the Eraser can bring back pixels.
2019-07-12 02:07:46 +00:00
|
|
|
P = ui.AbsolutePosition(w) // Canvas point in UI
|
2019-07-03 23:22:30 +00:00
|
|
|
VP = w.ViewportRelative() // Canvas scroll viewport
|
|
|
|
)
|
|
|
|
|
2019-07-03 23:51:23 +00:00
|
|
|
for _, stroke := range strokes {
|
2019-07-07 03:31:50 +00:00
|
|
|
// If none of this stroke is in our viewport, don't waste time
|
|
|
|
// looping through it.
|
Eraser Tool, Brush Sizes
* Implement Brush Sizes for drawtool.Stroke and add a UI to the tools panel
to control the brush size.
* Brush sizes: 1, 2, 4, 8, 16, 24, 32, 48, 64
* Add the Eraser Tool to editor mode. It uses a default brush size of 16
and a max size of 32 due to some performance issues.
* The Undo/Redo system now remembers the original color of pixels when
you change them, so that Undo will set them back how they were instead
of deleting the pixel entirely. Due to performance issues, this only
happens when your Brush Size is 0 (drawing single-pixel shapes).
* UI: Add an IntVariable option to ui.Label to bind showing the value of
an int reference.
Aforementioned performance issues:
* When we try to remember whole rects of pixels for drawing thick
shapes, it requires a ton of scanning for each step of the shape. Even
de-duplicating pixel checks, tons of extra reads are constantly
checked.
* The Eraser is the only tool that absolutely needs to be able to
remember wiped pixels AND have large brush sizes. The performance
sucks and lags a bit if you erase a lot all at once, but it's a
trade-off for now.
* So pixels aren't remembered when drawing lines in your level with
thick brushes, so the Undo action will simply delete your pixels and not
reset them. Only the Eraser can bring back pixels.
2019-07-12 02:07:46 +00:00
|
|
|
if stroke.Shape == drawtool.Freehand || stroke.Shape == drawtool.Eraser {
|
2019-07-07 03:31:50 +00:00
|
|
|
if len(stroke.Points) >= 2 {
|
|
|
|
if !stroke.Points[0].Inside(VP) && !stroke.Points[len(stroke.Points)-1].Inside(VP) {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
// TODO: a very long line that starts and ends outside the viewport
|
|
|
|
// but passes thru it would disappear when both ends are out of
|
|
|
|
// view.
|
|
|
|
if !stroke.PointA.Inside(VP) && !stroke.PointB.Inside(VP) {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Iter the points and draw what's visible.
|
Eraser Tool, Brush Sizes
* Implement Brush Sizes for drawtool.Stroke and add a UI to the tools panel
to control the brush size.
* Brush sizes: 1, 2, 4, 8, 16, 24, 32, 48, 64
* Add the Eraser Tool to editor mode. It uses a default brush size of 16
and a max size of 32 due to some performance issues.
* The Undo/Redo system now remembers the original color of pixels when
you change them, so that Undo will set them back how they were instead
of deleting the pixel entirely. Due to performance issues, this only
happens when your Brush Size is 0 (drawing single-pixel shapes).
* UI: Add an IntVariable option to ui.Label to bind showing the value of
an int reference.
Aforementioned performance issues:
* When we try to remember whole rects of pixels for drawing thick
shapes, it requires a ton of scanning for each step of the shape. Even
de-duplicating pixel checks, tons of extra reads are constantly
checked.
* The Eraser is the only tool that absolutely needs to be able to
remember wiped pixels AND have large brush sizes. The performance
sucks and lags a bit if you erase a lot all at once, but it's a
trade-off for now.
* So pixels aren't remembered when drawing lines in your level with
thick brushes, so the Undo action will simply delete your pixels and not
reset them. Only the Eraser can bring back pixels.
2019-07-12 02:07:46 +00:00
|
|
|
if stroke.Thickness > 0 {
|
|
|
|
for rect := range stroke.IterThickPoints() {
|
|
|
|
if !rect.Intersects(VP) {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
2021-06-10 05:36:32 +00:00
|
|
|
// Does the swatch have a pattern to sample?
|
|
|
|
color := stroke.Color
|
|
|
|
if stroke.Pattern != "" {
|
|
|
|
color = pattern.SampleColor(stroke.Pattern, color, rect.Point())
|
|
|
|
}
|
|
|
|
|
Eraser Tool, Brush Sizes
* Implement Brush Sizes for drawtool.Stroke and add a UI to the tools panel
to control the brush size.
* Brush sizes: 1, 2, 4, 8, 16, 24, 32, 48, 64
* Add the Eraser Tool to editor mode. It uses a default brush size of 16
and a max size of 32 due to some performance issues.
* The Undo/Redo system now remembers the original color of pixels when
you change them, so that Undo will set them back how they were instead
of deleting the pixel entirely. Due to performance issues, this only
happens when your Brush Size is 0 (drawing single-pixel shapes).
* UI: Add an IntVariable option to ui.Label to bind showing the value of
an int reference.
Aforementioned performance issues:
* When we try to remember whole rects of pixels for drawing thick
shapes, it requires a ton of scanning for each step of the shape. Even
de-duplicating pixel checks, tons of extra reads are constantly
checked.
* The Eraser is the only tool that absolutely needs to be able to
remember wiped pixels AND have large brush sizes. The performance
sucks and lags a bit if you erase a lot all at once, but it's a
trade-off for now.
* So pixels aren't remembered when drawing lines in your level with
thick brushes, so the Undo action will simply delete your pixels and not
reset them. Only the Eraser can bring back pixels.
2019-07-12 02:07:46 +00:00
|
|
|
// Destination rectangle to draw to screen, taking into account
|
|
|
|
// the position of the Canvas itself.
|
|
|
|
dest := render.Rect{
|
|
|
|
X: rect.X + P.X + w.Scroll.X + w.BoxThickness(1),
|
|
|
|
Y: rect.Y + P.Y + w.Scroll.Y + w.BoxThickness(1),
|
|
|
|
W: rect.W,
|
|
|
|
H: rect.H,
|
|
|
|
}
|
2019-07-03 23:22:30 +00:00
|
|
|
|
Eraser Tool, Brush Sizes
* Implement Brush Sizes for drawtool.Stroke and add a UI to the tools panel
to control the brush size.
* Brush sizes: 1, 2, 4, 8, 16, 24, 32, 48, 64
* Add the Eraser Tool to editor mode. It uses a default brush size of 16
and a max size of 32 due to some performance issues.
* The Undo/Redo system now remembers the original color of pixels when
you change them, so that Undo will set them back how they were instead
of deleting the pixel entirely. Due to performance issues, this only
happens when your Brush Size is 0 (drawing single-pixel shapes).
* UI: Add an IntVariable option to ui.Label to bind showing the value of
an int reference.
Aforementioned performance issues:
* When we try to remember whole rects of pixels for drawing thick
shapes, it requires a ton of scanning for each step of the shape. Even
de-duplicating pixel checks, tons of extra reads are constantly
checked.
* The Eraser is the only tool that absolutely needs to be able to
remember wiped pixels AND have large brush sizes. The performance
sucks and lags a bit if you erase a lot all at once, but it's a
trade-off for now.
* So pixels aren't remembered when drawing lines in your level with
thick brushes, so the Undo action will simply delete your pixels and not
reset them. Only the Eraser can bring back pixels.
2019-07-12 02:07:46 +00:00
|
|
|
// Cap the render square so it doesn't leave the Canvas and
|
|
|
|
// overlap other UI elements!
|
|
|
|
if dest.X < P.X {
|
|
|
|
// Left edge. TODO: right edge
|
|
|
|
delta := P.X - dest.X
|
|
|
|
dest.X = P.X
|
|
|
|
dest.W -= delta
|
|
|
|
}
|
|
|
|
if dest.Y < P.Y {
|
|
|
|
// Top edge. TODO: bottom edge
|
|
|
|
delta := P.Y - dest.Y
|
|
|
|
dest.Y = P.Y
|
|
|
|
dest.H -= delta
|
|
|
|
}
|
|
|
|
|
|
|
|
if balance.DebugCanvasStrokeColor != render.Invisible {
|
|
|
|
e.DrawBox(balance.DebugCanvasStrokeColor, dest)
|
|
|
|
} else {
|
2021-06-10 05:36:32 +00:00
|
|
|
e.DrawBox(color, dest)
|
Eraser Tool, Brush Sizes
* Implement Brush Sizes for drawtool.Stroke and add a UI to the tools panel
to control the brush size.
* Brush sizes: 1, 2, 4, 8, 16, 24, 32, 48, 64
* Add the Eraser Tool to editor mode. It uses a default brush size of 16
and a max size of 32 due to some performance issues.
* The Undo/Redo system now remembers the original color of pixels when
you change them, so that Undo will set them back how they were instead
of deleting the pixel entirely. Due to performance issues, this only
happens when your Brush Size is 0 (drawing single-pixel shapes).
* UI: Add an IntVariable option to ui.Label to bind showing the value of
an int reference.
Aforementioned performance issues:
* When we try to remember whole rects of pixels for drawing thick
shapes, it requires a ton of scanning for each step of the shape. Even
de-duplicating pixel checks, tons of extra reads are constantly
checked.
* The Eraser is the only tool that absolutely needs to be able to
remember wiped pixels AND have large brush sizes. The performance
sucks and lags a bit if you erase a lot all at once, but it's a
trade-off for now.
* So pixels aren't remembered when drawing lines in your level with
thick brushes, so the Undo action will simply delete your pixels and not
reset them. Only the Eraser can bring back pixels.
2019-07-12 02:07:46 +00:00
|
|
|
}
|
2019-07-03 23:22:30 +00:00
|
|
|
}
|
Eraser Tool, Brush Sizes
* Implement Brush Sizes for drawtool.Stroke and add a UI to the tools panel
to control the brush size.
* Brush sizes: 1, 2, 4, 8, 16, 24, 32, 48, 64
* Add the Eraser Tool to editor mode. It uses a default brush size of 16
and a max size of 32 due to some performance issues.
* The Undo/Redo system now remembers the original color of pixels when
you change them, so that Undo will set them back how they were instead
of deleting the pixel entirely. Due to performance issues, this only
happens when your Brush Size is 0 (drawing single-pixel shapes).
* UI: Add an IntVariable option to ui.Label to bind showing the value of
an int reference.
Aforementioned performance issues:
* When we try to remember whole rects of pixels for drawing thick
shapes, it requires a ton of scanning for each step of the shape. Even
de-duplicating pixel checks, tons of extra reads are constantly
checked.
* The Eraser is the only tool that absolutely needs to be able to
remember wiped pixels AND have large brush sizes. The performance
sucks and lags a bit if you erase a lot all at once, but it's a
trade-off for now.
* So pixels aren't remembered when drawing lines in your level with
thick brushes, so the Undo action will simply delete your pixels and not
reset them. Only the Eraser can bring back pixels.
2019-07-12 02:07:46 +00:00
|
|
|
} else {
|
2021-09-12 22:26:51 +00:00
|
|
|
var color = stroke.Color
|
|
|
|
if balance.DebugCanvasStrokeColor != render.Invisible {
|
|
|
|
color = balance.DebugCanvasStrokeColor
|
|
|
|
}
|
|
|
|
|
|
|
|
// TODO: iterating all the points is very costly!
|
|
|
|
// Strokes don't properly render your Pattern anyway (glitchy mess),
|
|
|
|
// so let them just be simple DrawLine etc. calls.
|
|
|
|
// This optimization specifically speeds up the Actor Link Lines.
|
|
|
|
if stroke.Shape == drawtool.Line {
|
|
|
|
var (
|
|
|
|
pointA = render.Point{
|
|
|
|
X: P.X + w.Scroll.X + w.BoxThickness(1) + stroke.PointA.X,
|
|
|
|
Y: P.Y + w.Scroll.Y + w.BoxThickness(1) + stroke.PointA.Y,
|
|
|
|
}
|
|
|
|
pointB = render.Point{
|
|
|
|
X: P.X + w.Scroll.X + w.BoxThickness(1) + stroke.PointB.X,
|
|
|
|
Y: P.Y + w.Scroll.Y + w.BoxThickness(1) + stroke.PointB.Y,
|
|
|
|
}
|
|
|
|
)
|
|
|
|
e.DrawLine(color, pointA, pointB)
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
Eraser Tool, Brush Sizes
* Implement Brush Sizes for drawtool.Stroke and add a UI to the tools panel
to control the brush size.
* Brush sizes: 1, 2, 4, 8, 16, 24, 32, 48, 64
* Add the Eraser Tool to editor mode. It uses a default brush size of 16
and a max size of 32 due to some performance issues.
* The Undo/Redo system now remembers the original color of pixels when
you change them, so that Undo will set them back how they were instead
of deleting the pixel entirely. Due to performance issues, this only
happens when your Brush Size is 0 (drawing single-pixel shapes).
* UI: Add an IntVariable option to ui.Label to bind showing the value of
an int reference.
Aforementioned performance issues:
* When we try to remember whole rects of pixels for drawing thick
shapes, it requires a ton of scanning for each step of the shape. Even
de-duplicating pixel checks, tons of extra reads are constantly
checked.
* The Eraser is the only tool that absolutely needs to be able to
remember wiped pixels AND have large brush sizes. The performance
sucks and lags a bit if you erase a lot all at once, but it's a
trade-off for now.
* So pixels aren't remembered when drawing lines in your level with
thick brushes, so the Undo action will simply delete your pixels and not
reset them. Only the Eraser can bring back pixels.
2019-07-12 02:07:46 +00:00
|
|
|
for point := range stroke.IterPoints() {
|
|
|
|
if !point.Inside(VP) {
|
|
|
|
continue
|
|
|
|
}
|
2019-07-03 23:22:30 +00:00
|
|
|
|
2021-06-10 05:36:32 +00:00
|
|
|
// Does the swatch have a pattern to sample?
|
|
|
|
if stroke.Pattern != "" {
|
|
|
|
color = pattern.SampleColor(stroke.Pattern, color, point)
|
|
|
|
}
|
|
|
|
|
Eraser Tool, Brush Sizes
* Implement Brush Sizes for drawtool.Stroke and add a UI to the tools panel
to control the brush size.
* Brush sizes: 1, 2, 4, 8, 16, 24, 32, 48, 64
* Add the Eraser Tool to editor mode. It uses a default brush size of 16
and a max size of 32 due to some performance issues.
* The Undo/Redo system now remembers the original color of pixels when
you change them, so that Undo will set them back how they were instead
of deleting the pixel entirely. Due to performance issues, this only
happens when your Brush Size is 0 (drawing single-pixel shapes).
* UI: Add an IntVariable option to ui.Label to bind showing the value of
an int reference.
Aforementioned performance issues:
* When we try to remember whole rects of pixels for drawing thick
shapes, it requires a ton of scanning for each step of the shape. Even
de-duplicating pixel checks, tons of extra reads are constantly
checked.
* The Eraser is the only tool that absolutely needs to be able to
remember wiped pixels AND have large brush sizes. The performance
sucks and lags a bit if you erase a lot all at once, but it's a
trade-off for now.
* So pixels aren't remembered when drawing lines in your level with
thick brushes, so the Undo action will simply delete your pixels and not
reset them. Only the Eraser can bring back pixels.
2019-07-12 02:07:46 +00:00
|
|
|
dest := render.Point{
|
|
|
|
X: P.X + w.Scroll.X + w.BoxThickness(1) + point.X,
|
|
|
|
Y: P.Y + w.Scroll.Y + w.BoxThickness(1) + point.Y,
|
|
|
|
}
|
|
|
|
|
2021-09-12 22:26:51 +00:00
|
|
|
e.DrawPoint(color, dest)
|
2019-07-03 23:22:30 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|