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
|
|
|
package uix
|
|
|
|
|
|
|
|
import (
|
2019-12-28 03:16:34 +00:00
|
|
|
"git.kirsle.net/apps/doodle/pkg/shmem"
|
2019-12-23 02:21:58 +00:00
|
|
|
"git.kirsle.net/go/render"
|
2019-12-28 00:31:58 +00:00
|
|
|
"git.kirsle.net/go/ui"
|
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
|
|
|
)
|
|
|
|
|
|
|
|
// IsCursorOver returns true if the mouse cursor is physically over top
|
|
|
|
// of the canvas's widget space.
|
|
|
|
func (w *Canvas) IsCursorOver() bool {
|
|
|
|
var (
|
|
|
|
P = ui.AbsolutePosition(w)
|
|
|
|
S = w.Size()
|
|
|
|
)
|
|
|
|
return shmem.Cursor.Inside(render.Rect{
|
|
|
|
X: P.X,
|
|
|
|
Y: P.Y,
|
|
|
|
W: S.W,
|
|
|
|
H: S.H,
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
// presentCursor draws something at the mouse cursor on the Canvas.
|
|
|
|
//
|
|
|
|
// This is currently used in Edit Mode when you're drawing a shape with a thick
|
|
|
|
// brush size, and draws a "preview rect" under the cursor of how big a click
|
|
|
|
// will be at that size.
|
|
|
|
func (w *Canvas) presentCursor(e render.Engine) {
|
|
|
|
if !w.IsCursorOver() {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
// Are we editing with a thick brush?
|
|
|
|
if w.BrushSize > 0 {
|
2019-12-28 03:16:34 +00:00
|
|
|
var r = w.BrushSize
|
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
|
|
|
rect := render.Rect{
|
|
|
|
X: shmem.Cursor.X - r,
|
|
|
|
Y: shmem.Cursor.Y - r,
|
|
|
|
W: r * 2,
|
|
|
|
H: r * 2,
|
|
|
|
}
|
|
|
|
e.DrawRect(render.Black, rect)
|
|
|
|
rect.X++
|
|
|
|
rect.Y++
|
|
|
|
rect.W -= 2
|
|
|
|
rect.H -= 2
|
|
|
|
e.DrawRect(render.RGBA(153, 153, 153, 153), rect)
|
|
|
|
}
|
|
|
|
}
|