From 3b01592e85af505a35aca494dea2570b87c417a7 Mon Sep 17 00:00:00 2001 From: Noah Petherbridge Date: Thu, 11 Jul 2019 19:07:46 -0700 Subject: [PATCH] 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. --- label.go | 5 +++++ supervisor.go | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/label.go b/label.go index cf18910..86a9f1d 100644 --- a/label.go +++ b/label.go @@ -20,6 +20,7 @@ type Label struct { // Configurable fields for the constructor. Text string TextVariable *string + IntVariable *int Font render.Text width int32 @@ -32,6 +33,7 @@ func NewLabel(c Label) *Label { w := &Label{ Text: c.Text, TextVariable: c.TextVariable, + IntVariable: c.IntVariable, Font: DefaultFont, } if !c.Font.IsZero() { @@ -49,6 +51,9 @@ func (w *Label) text() render.Text { if w.TextVariable != nil { w.Font.Text = *w.TextVariable return w.Font + } else if w.IntVariable != nil { + w.Font.Text = fmt.Sprintf("%d", *w.IntVariable) + return w.Font } w.Font.Text = w.Text return w.Font diff --git a/supervisor.go b/supervisor.go index 8c69a73..ac78a51 100644 --- a/supervisor.go +++ b/supervisor.go @@ -173,7 +173,7 @@ func (s *Supervisor) Hovering(cursor render.Point) (hovering, outside []WidgetSl } ) - if XY.X >= P.X && XY.X <= P2.X && XY.Y >= P.Y && XY.Y <= P2.Y { + if XY.X >= P.X && XY.X < P2.X && XY.Y >= P.Y && XY.Y < P2.Y { // Cursor intersects the widget. hovering = append(hovering, child) } else {