2019-07-04 03:24:04 +00:00
|
|
|
package doodle
|
|
|
|
|
|
|
|
import (
|
2022-03-05 23:31:09 +00:00
|
|
|
"fmt"
|
|
|
|
|
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
|
|
|
"git.kirsle.net/apps/doodle/pkg/balance"
|
2019-07-04 03:24:04 +00:00
|
|
|
"git.kirsle.net/apps/doodle/pkg/drawtool"
|
2020-11-17 07:20:24 +00:00
|
|
|
"git.kirsle.net/apps/doodle/pkg/enum"
|
2019-07-04 03:24:04 +00:00
|
|
|
"git.kirsle.net/apps/doodle/pkg/sprites"
|
2021-06-20 05:14:41 +00:00
|
|
|
"git.kirsle.net/apps/doodle/pkg/usercfg"
|
2019-12-28 03:16:34 +00:00
|
|
|
"git.kirsle.net/go/render"
|
|
|
|
"git.kirsle.net/go/ui"
|
2021-06-14 04:23:26 +00:00
|
|
|
"git.kirsle.net/go/ui/style"
|
2019-07-04 03:24:04 +00:00
|
|
|
)
|
|
|
|
|
2022-03-05 23:31:09 +00:00
|
|
|
// Global toolbarWidth, TODO: editor_ui.go wants it
|
|
|
|
var toolbarWidth int
|
2019-07-04 03:24:04 +00:00
|
|
|
|
|
|
|
// SetupToolbar configures the UI for the Tools panel.
|
|
|
|
func (u *EditorUI) SetupToolbar(d *Doodle) *ui.Frame {
|
2021-06-14 04:23:26 +00:00
|
|
|
// Horizontal toolbar instead of vertical?
|
|
|
|
var (
|
2022-03-05 23:31:09 +00:00
|
|
|
toolbarSpriteSize = 24 // size of sprite images
|
|
|
|
frameSize render.Rect
|
|
|
|
isHoz = usercfg.Current.HorizontalToolbars
|
|
|
|
buttonsPerRow = 2
|
|
|
|
packAlign = ui.N
|
|
|
|
tooltipEdge = ui.Right
|
|
|
|
btnRowPack = ui.Pack{
|
2021-06-14 04:23:26 +00:00
|
|
|
Side: packAlign,
|
2022-03-05 23:31:09 +00:00
|
|
|
PadY: 1,
|
|
|
|
Fill: true,
|
|
|
|
}
|
|
|
|
btnPack = ui.Pack{
|
|
|
|
Side: ui.W,
|
|
|
|
PadX: 1,
|
2021-06-14 04:23:26 +00:00
|
|
|
}
|
|
|
|
)
|
|
|
|
if isHoz {
|
|
|
|
packAlign = ui.W
|
|
|
|
tooltipEdge = ui.Bottom
|
2022-03-05 23:31:09 +00:00
|
|
|
btnRowPack = ui.Pack{
|
2021-06-14 04:23:26 +00:00
|
|
|
Side: packAlign,
|
|
|
|
PadX: 2,
|
|
|
|
}
|
2022-03-05 23:31:09 +00:00
|
|
|
btnPack = ui.Pack{
|
|
|
|
Side: ui.N,
|
|
|
|
PadY: 1,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Button Layout Controls:
|
|
|
|
// We can draw 2 buttons per row, but for very small screens
|
|
|
|
// e.g. mobile in portrait orientation, draw 1 button per row.
|
|
|
|
buttonsPerRow = 1
|
2022-03-06 06:44:54 +00:00
|
|
|
if isHoz {
|
|
|
|
if d.width < enum.ScreenWidthSmall {
|
|
|
|
// Narrow screens
|
|
|
|
buttonsPerRow = 2
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if d.width >= enum.ScreenWidthSmall {
|
|
|
|
// Screen wider than 600px = can spare room for 2 buttons per row.
|
|
|
|
buttonsPerRow = 2
|
|
|
|
}
|
2021-06-14 04:23:26 +00:00
|
|
|
}
|
|
|
|
|
2022-03-05 23:31:09 +00:00
|
|
|
// Compute toolbar size to accommodate all buttons (+10 for borders/padding)
|
|
|
|
toolbarWidth = buttonsPerRow * (toolbarSpriteSize + 10)
|
|
|
|
frameSize = render.NewRect(toolbarWidth, 100)
|
|
|
|
|
2019-07-04 03:24:04 +00:00
|
|
|
frame := ui.NewFrame("Tool Bar")
|
2021-06-14 04:23:26 +00:00
|
|
|
frame.Resize(frameSize)
|
2019-07-04 03:24:04 +00:00
|
|
|
frame.Configure(ui.Config{
|
|
|
|
BorderSize: 2,
|
|
|
|
BorderStyle: ui.BorderRaised,
|
|
|
|
Background: render.Grey,
|
|
|
|
})
|
|
|
|
|
|
|
|
btnFrame := ui.NewFrame("Tool Buttons")
|
|
|
|
frame.Pack(btnFrame, ui.Pack{
|
2021-06-14 04:23:26 +00:00
|
|
|
Side: packAlign,
|
2019-07-04 03:24:04 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
// Buttons.
|
|
|
|
var buttons = []struct {
|
2020-03-10 05:22:22 +00:00
|
|
|
Value string
|
|
|
|
Icon string
|
|
|
|
Tooltip string
|
2021-06-14 04:23:26 +00:00
|
|
|
Style *style.Button
|
2020-03-10 05:22:22 +00:00
|
|
|
Click func()
|
2020-11-17 07:20:24 +00:00
|
|
|
|
|
|
|
// Optional fields.
|
|
|
|
NoDoodad bool // tool not available for Doodad editing (Levels only)
|
2019-07-04 03:24:04 +00:00
|
|
|
}{
|
2022-03-05 23:31:09 +00:00
|
|
|
{
|
|
|
|
Value: drawtool.PanTool.String(),
|
|
|
|
Icon: "assets/sprites/pan-tool.png",
|
|
|
|
Tooltip: "Pan Tool",
|
|
|
|
Click: func() {
|
|
|
|
u.Canvas.Tool = drawtool.PanTool
|
|
|
|
d.Flash("Pan Tool selected.")
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
2019-07-04 03:24:04 +00:00
|
|
|
{
|
2020-03-10 05:22:22 +00:00
|
|
|
Value: drawtool.PencilTool.String(),
|
|
|
|
Icon: "assets/sprites/pencil-tool.png",
|
|
|
|
Tooltip: "Pencil Tool",
|
2019-07-04 03:24:04 +00:00
|
|
|
Click: func() {
|
|
|
|
u.Canvas.Tool = drawtool.PencilTool
|
|
|
|
d.Flash("Pencil Tool selected.")
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
|
|
|
{
|
2020-03-10 05:22:22 +00:00
|
|
|
Value: drawtool.LineTool.String(),
|
|
|
|
Icon: "assets/sprites/line-tool.png",
|
|
|
|
Tooltip: "Line Tool",
|
2019-07-04 03:24:04 +00:00
|
|
|
Click: func() {
|
|
|
|
u.Canvas.Tool = drawtool.LineTool
|
|
|
|
d.Flash("Line Tool selected.")
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
|
|
|
{
|
2020-03-10 05:22:22 +00:00
|
|
|
Value: drawtool.RectTool.String(),
|
|
|
|
Icon: "assets/sprites/rect-tool.png",
|
|
|
|
Tooltip: "Rectangle Tool",
|
2019-07-04 03:24:04 +00:00
|
|
|
Click: func() {
|
|
|
|
u.Canvas.Tool = drawtool.RectTool
|
|
|
|
d.Flash("Rectangle Tool selected.")
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
2019-07-14 21:18:44 +00:00
|
|
|
{
|
2020-03-10 05:22:22 +00:00
|
|
|
Value: drawtool.EllipseTool.String(),
|
|
|
|
Icon: "assets/sprites/ellipse-tool.png",
|
|
|
|
Tooltip: "Ellipse Tool",
|
2019-07-14 21:18:44 +00:00
|
|
|
Click: func() {
|
|
|
|
u.Canvas.Tool = drawtool.EllipseTool
|
|
|
|
d.Flash("Ellipse Tool selected.")
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
2022-03-05 23:31:09 +00:00
|
|
|
{
|
|
|
|
Value: drawtool.TextTool.String(),
|
|
|
|
Icon: "assets/sprites/text-tool.png",
|
|
|
|
Tooltip: "Text Tool",
|
|
|
|
Click: func() {
|
|
|
|
u.Canvas.Tool = drawtool.TextTool
|
|
|
|
u.OpenTextTool()
|
|
|
|
d.Flash("Text Tool selected.")
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
2019-07-04 03:24:04 +00:00
|
|
|
{
|
2020-11-17 07:20:24 +00:00
|
|
|
Value: drawtool.ActorTool.String(),
|
|
|
|
Icon: "assets/sprites/actor-tool.png",
|
|
|
|
Tooltip: "Doodad Tool\nDrag-and-drop objects into your map",
|
|
|
|
NoDoodad: true,
|
2021-06-14 04:23:26 +00:00
|
|
|
Style: &balance.ButtonBabyBlue,
|
2019-07-04 03:24:04 +00:00
|
|
|
Click: func() {
|
|
|
|
u.Canvas.Tool = drawtool.ActorTool
|
2022-02-20 04:20:58 +00:00
|
|
|
u.OpenDoodadDropper()
|
2019-07-04 03:24:04 +00:00
|
|
|
d.Flash("Actor Tool selected. Drag a Doodad from the drawer into your level.")
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
|
|
|
{
|
2020-11-17 07:20:24 +00:00
|
|
|
Value: drawtool.LinkTool.String(),
|
|
|
|
Icon: "assets/sprites/link-tool.png",
|
|
|
|
Tooltip: "Link Tool\nConnect doodads to each other",
|
2021-06-14 04:23:26 +00:00
|
|
|
Style: &balance.ButtonPink,
|
2020-11-17 07:20:24 +00:00
|
|
|
NoDoodad: true,
|
2019-07-04 03:24:04 +00:00
|
|
|
Click: func() {
|
|
|
|
u.Canvas.Tool = drawtool.LinkTool
|
|
|
|
d.Flash("Link Tool selected. Click a doodad in your level to link it to another.")
|
|
|
|
},
|
|
|
|
},
|
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
|
|
|
|
|
|
|
{
|
2020-03-10 05:22:22 +00:00
|
|
|
Value: drawtool.EraserTool.String(),
|
|
|
|
Icon: "assets/sprites/eraser-tool.png",
|
|
|
|
Tooltip: "Eraser Tool",
|
2021-06-14 04:23:26 +00:00
|
|
|
Style: &balance.ButtonLightRed,
|
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
|
|
|
Click: func() {
|
|
|
|
u.Canvas.Tool = drawtool.EraserTool
|
|
|
|
|
|
|
|
// Set the brush size within range for the eraser.
|
|
|
|
if u.Canvas.BrushSize < balance.DefaultEraserBrushSize {
|
|
|
|
u.Canvas.BrushSize = balance.DefaultEraserBrushSize
|
|
|
|
} else if u.Canvas.BrushSize > balance.MaxEraserBrushSize {
|
|
|
|
u.Canvas.BrushSize = balance.MaxEraserBrushSize
|
|
|
|
}
|
|
|
|
|
|
|
|
d.Flash("Eraser Tool selected.")
|
|
|
|
},
|
|
|
|
},
|
2019-07-04 03:24:04 +00:00
|
|
|
}
|
2022-03-05 23:31:09 +00:00
|
|
|
|
|
|
|
// Arrange the buttons 2x2.
|
|
|
|
var btnRow *ui.Frame
|
|
|
|
for i, button := range buttons {
|
2019-07-04 03:24:04 +00:00
|
|
|
button := button
|
2020-11-17 07:20:24 +00:00
|
|
|
if button.NoDoodad && u.Scene.DrawingType == enum.DoodadDrawing {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
2022-03-05 23:31:09 +00:00
|
|
|
if buttonsPerRow == 1 || i%buttonsPerRow == 0 {
|
|
|
|
btnRow = ui.NewFrame(fmt.Sprintf("Button Row %d", i))
|
|
|
|
btnFrame.Pack(btnRow, btnRowPack)
|
|
|
|
}
|
|
|
|
|
2019-07-04 03:24:04 +00:00
|
|
|
image, err := sprites.LoadImage(d.Engine, button.Icon)
|
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
btn := ui.NewRadioButton(
|
|
|
|
button.Value,
|
2019-07-04 04:55:15 +00:00
|
|
|
&u.activeTool,
|
2019-07-04 03:24:04 +00:00
|
|
|
button.Value,
|
|
|
|
image,
|
|
|
|
)
|
2021-06-14 04:23:26 +00:00
|
|
|
if button.Style != nil {
|
|
|
|
btn.SetStyle(button.Style)
|
|
|
|
}
|
2019-07-04 03:24:04 +00:00
|
|
|
|
2019-12-28 03:16:34 +00:00
|
|
|
var btnSize = btn.BoxThickness(2) + toolbarSpriteSize
|
2022-03-05 23:31:09 +00:00
|
|
|
btn.SetBorderSize(1)
|
2019-07-04 03:24:04 +00:00
|
|
|
btn.Resize(render.NewRect(btnSize, btnSize))
|
|
|
|
|
2020-04-07 06:21:17 +00:00
|
|
|
btn.Handle(ui.Click, func(ed ui.EventData) error {
|
2019-07-04 03:24:04 +00:00
|
|
|
button.Click()
|
2020-04-07 06:21:17 +00:00
|
|
|
return nil
|
2019-07-04 03:24:04 +00:00
|
|
|
})
|
|
|
|
u.Supervisor.Add(btn)
|
|
|
|
|
2022-03-06 06:44:54 +00:00
|
|
|
tt := ui.NewTooltip(btn, ui.Tooltip{
|
2020-03-10 05:22:22 +00:00
|
|
|
Text: button.Tooltip,
|
2021-06-14 04:23:26 +00:00
|
|
|
Edge: tooltipEdge,
|
2020-03-10 05:22:22 +00:00
|
|
|
})
|
2022-03-06 06:44:54 +00:00
|
|
|
tt.Supervise(u.Supervisor)
|
2020-03-10 05:22:22 +00:00
|
|
|
|
2022-03-05 23:31:09 +00:00
|
|
|
btnRow.Pack(btn, btnPack)
|
2019-07-04 03:24:04 +00:00
|
|
|
}
|
|
|
|
|
2020-11-17 07:20:24 +00:00
|
|
|
// Doodad Editor: show the Layers button.
|
|
|
|
if u.Scene.DrawingType == enum.DoodadDrawing {
|
|
|
|
btn := ui.NewButton("Layers Button", ui.NewLabel(ui.Label{
|
|
|
|
Text: "Lyr.",
|
|
|
|
Font: balance.MenuFont,
|
|
|
|
}))
|
|
|
|
btn.Handle(ui.Click, func(ed ui.EventData) error {
|
|
|
|
u.OpenLayersWindow()
|
|
|
|
return nil
|
|
|
|
})
|
|
|
|
u.Supervisor.Add(btn)
|
|
|
|
btnFrame.Pack(btn, ui.Pack{
|
2021-06-14 04:23:26 +00:00
|
|
|
Side: packAlign,
|
2020-11-17 07:20:24 +00:00
|
|
|
PadY: 2,
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
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
|
|
|
// Spacer frame.
|
|
|
|
frame.Pack(ui.NewFrame("spacer"), ui.Pack{
|
2021-06-14 04:23:26 +00:00
|
|
|
Side: packAlign,
|
2019-12-31 02:13:28 +00:00
|
|
|
PadY: 8,
|
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
|
|
|
})
|
|
|
|
|
2021-06-14 04:23:26 +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
|
|
|
// "Brush Size" label
|
2021-06-14 04:23:26 +00:00
|
|
|
bsFrame := ui.NewFrame("Brush Size Frame")
|
|
|
|
frame.Pack(bsFrame, ui.Pack{
|
|
|
|
Side: packAlign,
|
|
|
|
})
|
|
|
|
|
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
|
|
|
bsLabel := ui.NewLabel(ui.Label{
|
|
|
|
Text: "Size:",
|
2021-06-14 04:23:26 +00:00
|
|
|
Font: balance.SmallFont,
|
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
|
|
|
})
|
2021-06-14 04:23:26 +00:00
|
|
|
bsFrame.Pack(bsLabel, ui.Pack{
|
2019-12-29 05:48:49 +00:00
|
|
|
Side: ui.N,
|
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
|
|
|
})
|
|
|
|
|
2020-03-10 05:22:22 +00:00
|
|
|
ui.NewTooltip(bsLabel, ui.Tooltip{
|
|
|
|
Text: "Set the line thickness for drawing",
|
2021-06-14 04:23:26 +00:00
|
|
|
Edge: tooltipEdge,
|
2020-03-10 05:22:22 +00:00
|
|
|
})
|
|
|
|
u.Supervisor.Add(bsLabel)
|
|
|
|
|
2021-06-14 04:23:26 +00:00
|
|
|
sizeLabel := ui.NewLabel(ui.Label{
|
|
|
|
IntVariable: &u.Canvas.BrushSize,
|
|
|
|
Font: balance.SmallFont,
|
|
|
|
})
|
|
|
|
sizeLabel.Configure(ui.Config{
|
|
|
|
BorderSize: 1,
|
|
|
|
BorderStyle: ui.BorderSunken,
|
|
|
|
Background: render.Grey,
|
|
|
|
})
|
|
|
|
bsFrame.Pack(sizeLabel, ui.Pack{
|
|
|
|
Side: ui.N,
|
|
|
|
// FillX: true,
|
|
|
|
PadY: 0,
|
|
|
|
})
|
|
|
|
|
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
|
|
|
// Brush Size widget
|
|
|
|
{
|
|
|
|
sizeFrame := ui.NewFrame("Brush Size Frame")
|
|
|
|
frame.Pack(sizeFrame, ui.Pack{
|
2021-06-14 04:23:26 +00:00
|
|
|
Side: packAlign,
|
2019-12-31 02:13:28 +00:00
|
|
|
PadY: 0,
|
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
|
|
|
})
|
|
|
|
|
|
|
|
sizeBtnFrame := ui.NewFrame("Size Increment Button Frame")
|
|
|
|
sizeFrame.Pack(sizeBtnFrame, ui.Pack{
|
2019-12-31 02:13:28 +00:00
|
|
|
Side: ui.N,
|
|
|
|
FillX: true,
|
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
|
|
|
})
|
|
|
|
|
|
|
|
var incButtons = []struct {
|
|
|
|
Label string
|
|
|
|
F func()
|
|
|
|
}{
|
|
|
|
{
|
|
|
|
Label: "-",
|
|
|
|
F: func() {
|
|
|
|
// Select next smaller brush size.
|
|
|
|
for i := len(balance.BrushSizeOptions) - 1; i >= 0; i-- {
|
|
|
|
if balance.BrushSizeOptions[i] < u.Canvas.BrushSize {
|
|
|
|
u.Canvas.BrushSize = balance.BrushSizeOptions[i]
|
|
|
|
break
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Label: "+",
|
|
|
|
F: func() {
|
|
|
|
// Select next bigger brush size.
|
|
|
|
for _, size := range balance.BrushSizeOptions {
|
|
|
|
if size > u.Canvas.BrushSize {
|
|
|
|
u.Canvas.BrushSize = size
|
|
|
|
break
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Limit the eraser brush size, too big and it's slow because
|
|
|
|
// the eraser has to scan and remember pixels to be able to
|
|
|
|
// Undo the erase and restore them.
|
|
|
|
if u.Canvas.Tool == drawtool.EraserTool && u.Canvas.BrushSize > balance.MaxEraserBrushSize {
|
|
|
|
u.Canvas.BrushSize = balance.MaxEraserBrushSize
|
|
|
|
}
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
for _, button := range incButtons {
|
|
|
|
button := button
|
|
|
|
btn := ui.NewButton("BrushSize"+button.Label, ui.NewLabel(ui.Label{
|
|
|
|
Text: button.Label,
|
|
|
|
Font: balance.SmallMonoFont,
|
|
|
|
}))
|
2022-03-06 06:44:54 +00:00
|
|
|
btn.SetBorderSize(1)
|
2020-04-07 06:21:17 +00:00
|
|
|
btn.Handle(ui.Click, func(ed ui.EventData) error {
|
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
|
|
|
button.F()
|
2020-04-07 06:21:17 +00:00
|
|
|
return 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
|
|
|
})
|
|
|
|
u.Supervisor.Add(btn)
|
2022-03-06 06:44:54 +00:00
|
|
|
|
|
|
|
// Which side to pack on?
|
|
|
|
var side = ui.W
|
|
|
|
if !isHoz && buttonsPerRow == 1 {
|
|
|
|
// Vertical layout w/ narrow one-button-per-row, the +-
|
|
|
|
// buttons stick out so stack them vertically.
|
|
|
|
side = ui.S
|
|
|
|
}
|
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
|
|
|
sizeBtnFrame.Pack(btn, ui.Pack{
|
2022-03-06 06:44:54 +00:00
|
|
|
Side: side,
|
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-04 03:24:04 +00:00
|
|
|
frame.Compute(d.Engine)
|
|
|
|
|
|
|
|
return frame
|
|
|
|
}
|