2018-10-20 22:42:49 +00:00
|
|
|
package doodle
|
|
|
|
|
|
|
|
import (
|
2019-07-05 22:02:22 +00:00
|
|
|
"fmt"
|
|
|
|
|
2022-09-24 22:17:25 +00:00
|
|
|
"git.kirsle.net/SketchyMaze/doodle/pkg/balance"
|
|
|
|
"git.kirsle.net/SketchyMaze/doodle/pkg/level"
|
|
|
|
"git.kirsle.net/SketchyMaze/doodle/pkg/log"
|
|
|
|
"git.kirsle.net/SketchyMaze/doodle/pkg/uix"
|
|
|
|
"git.kirsle.net/SketchyMaze/doodle/pkg/usercfg"
|
2022-05-05 05:38:26 +00:00
|
|
|
"git.kirsle.net/go/render"
|
2019-12-31 02:13:28 +00:00
|
|
|
"git.kirsle.net/go/ui"
|
2018-10-20 22:42:49 +00:00
|
|
|
)
|
|
|
|
|
2020-07-10 02:38:37 +00:00
|
|
|
// Width of the panel frame.
|
|
|
|
var paletteWidth = 50
|
|
|
|
|
2019-06-26 00:43:23 +00:00
|
|
|
// SetupPalette sets up the palette panel.
|
|
|
|
func (u *EditorUI) SetupPalette(d *Doodle) *ui.Window {
|
|
|
|
window := ui.NewWindow("Palette")
|
|
|
|
window.ConfigureTitle(balance.TitleConfig)
|
2020-07-10 02:38:37 +00:00
|
|
|
_, label := window.TitleBar()
|
|
|
|
label.Font = balance.TitleFont
|
2019-06-26 00:43:23 +00:00
|
|
|
window.Configure(ui.Config{
|
|
|
|
Background: balance.WindowBackground,
|
|
|
|
BorderColor: balance.WindowBorder,
|
|
|
|
})
|
|
|
|
|
|
|
|
// Color Palette Frame.
|
|
|
|
u.PaletteTab = u.setupPaletteFrame(window)
|
|
|
|
window.Pack(u.PaletteTab, ui.Pack{
|
2019-12-29 05:48:49 +00:00
|
|
|
Side: ui.N,
|
2019-12-31 02:13:28 +00:00
|
|
|
Fill: true,
|
2019-06-26 00:43:23 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
return window
|
|
|
|
}
|
|
|
|
|
2018-10-20 22:42:49 +00:00
|
|
|
// setupPaletteFrame configures the Color Palette tab for Edit Mode.
|
|
|
|
// This is a subroutine of editor_ui.go#SetupPalette()
|
|
|
|
func (u *EditorUI) setupPaletteFrame(window *ui.Window) *ui.Frame {
|
|
|
|
frame := ui.NewFrame("Palette Tab")
|
|
|
|
frame.SetBackground(balance.WindowBackground)
|
|
|
|
|
2021-06-14 04:23:26 +00:00
|
|
|
var (
|
|
|
|
packAlign = ui.N
|
|
|
|
packConfig = ui.Pack{
|
|
|
|
Side: packAlign,
|
|
|
|
Fill: true,
|
2021-10-13 03:49:48 +00:00
|
|
|
PadY: 1,
|
2021-06-14 04:23:26 +00:00
|
|
|
}
|
|
|
|
tooltipEdge = ui.Left
|
|
|
|
buttonSize = 32
|
2021-10-13 03:49:48 +00:00
|
|
|
twoColumn = true // To place in two columns, halves buttonSize to /2
|
2021-06-14 04:23:26 +00:00
|
|
|
)
|
2021-06-20 05:14:41 +00:00
|
|
|
if usercfg.Current.HorizontalToolbars {
|
2021-06-14 04:23:26 +00:00
|
|
|
packAlign = ui.W
|
|
|
|
packConfig = ui.Pack{
|
|
|
|
Side: packAlign,
|
|
|
|
Fill: true,
|
|
|
|
PadX: 2,
|
|
|
|
}
|
|
|
|
tooltipEdge = ui.Top
|
|
|
|
buttonSize = 24
|
2021-10-13 03:49:48 +00:00
|
|
|
twoColumn = false
|
2021-06-14 04:23:26 +00:00
|
|
|
}
|
|
|
|
|
2018-10-20 22:42:49 +00:00
|
|
|
// Handler function for the radio buttons being clicked.
|
2020-04-07 06:21:17 +00:00
|
|
|
onClick := func(ed ui.EventData) error {
|
2018-10-20 22:42:49 +00:00
|
|
|
name := u.selectedSwatch
|
|
|
|
swatch, ok := u.Canvas.Palette.Get(name)
|
|
|
|
if !ok {
|
|
|
|
log.Error("Palette onClick: couldn't get swatch named '%s' from palette", name)
|
2020-04-07 06:21:17 +00:00
|
|
|
return nil
|
2018-10-20 22:42:49 +00:00
|
|
|
}
|
|
|
|
log.Info("Set swatch: %s", swatch)
|
|
|
|
u.Canvas.SetSwatch(swatch)
|
2020-04-07 06:21:17 +00:00
|
|
|
return nil
|
2018-10-20 22:42:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Draw the radio buttons for the palette.
|
2021-10-13 03:49:48 +00:00
|
|
|
var row *ui.Frame
|
2018-10-20 22:42:49 +00:00
|
|
|
if u.Canvas != nil && u.Canvas.Palette != nil {
|
2021-10-13 03:49:48 +00:00
|
|
|
for i, swatch := range u.Canvas.Palette.Swatches {
|
|
|
|
swatch := swatch
|
|
|
|
var width = buttonSize
|
|
|
|
|
|
|
|
// Drawing buttons in two-column mode? (default right-side palette layout)
|
|
|
|
if twoColumn {
|
|
|
|
width = buttonSize / 2
|
|
|
|
if row == nil || i%2 == 0 {
|
|
|
|
row = ui.NewFrame(fmt.Sprintf("Swatch(%s) Button Frame", swatch.Name))
|
|
|
|
frame.Pack(row, packConfig)
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
row = ui.NewFrame(fmt.Sprintf("Swatch(%s) Button Frame", swatch.Name))
|
|
|
|
frame.Pack(row, packConfig)
|
|
|
|
}
|
|
|
|
|
2022-05-05 05:38:26 +00:00
|
|
|
// Fancy colorbox: show the color AND the texture of each swatch.
|
|
|
|
var (
|
|
|
|
colorbox = uix.NewCanvas(width, false)
|
|
|
|
chunker = level.NewChunker(width)
|
|
|
|
size = render.NewRect(width, width)
|
|
|
|
)
|
|
|
|
chunker.SetRect(size, swatch)
|
|
|
|
colorbox.Resize(size)
|
|
|
|
colorbox.Load(u.Canvas.Palette, chunker)
|
2018-10-20 22:42:49 +00:00
|
|
|
|
2021-10-13 03:49:48 +00:00
|
|
|
btn := ui.NewRadioButton("palette", &u.selectedSwatch, swatch.Name, colorbox)
|
|
|
|
btn.Configure(ui.Config{
|
|
|
|
BorderColor: swatch.Color.Darken(20),
|
|
|
|
BorderSize: 2,
|
|
|
|
OutlineSize: 0,
|
|
|
|
})
|
2018-10-20 22:42:49 +00:00
|
|
|
btn.Handle(ui.Click, onClick)
|
|
|
|
u.Supervisor.Add(btn)
|
|
|
|
|
2020-03-10 05:22:22 +00:00
|
|
|
// Add a tooltip showing the swatch attributes.
|
|
|
|
ui.NewTooltip(btn, ui.Tooltip{
|
2020-07-10 02:38:37 +00:00
|
|
|
Text: fmt.Sprintf("Name: %s\nAttributes: %s", swatch.Name, swatch.Attributes()),
|
2021-06-14 04:23:26 +00:00
|
|
|
Edge: tooltipEdge,
|
2020-03-10 05:22:22 +00:00
|
|
|
})
|
|
|
|
|
2019-07-05 22:02:22 +00:00
|
|
|
btn.Compute(u.d.Engine)
|
|
|
|
|
2021-10-13 03:49:48 +00:00
|
|
|
row.Pack(btn, ui.Pack{
|
|
|
|
Side: ui.W,
|
|
|
|
PadX: 1,
|
|
|
|
})
|
2018-10-20 22:42:49 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-07-10 02:38:37 +00:00
|
|
|
// Draw the Edit Palette button.
|
|
|
|
btn := ui.NewButton("Edit Palette", ui.NewLabel(ui.Label{
|
|
|
|
Text: "Edit",
|
|
|
|
Font: balance.MenuFont,
|
|
|
|
}))
|
|
|
|
btn.Handle(ui.Click, func(ed ui.EventData) error {
|
2020-11-17 07:20:24 +00:00
|
|
|
u.OpenPaletteWindow()
|
2020-07-10 02:38:37 +00:00
|
|
|
return nil
|
|
|
|
})
|
|
|
|
u.Supervisor.Add(btn)
|
|
|
|
|
|
|
|
btn.Compute(u.d.Engine)
|
2021-06-14 04:23:26 +00:00
|
|
|
frame.Pack(btn, packConfig)
|
2020-07-10 02:38:37 +00:00
|
|
|
|
2018-10-20 22:42:49 +00:00
|
|
|
return frame
|
|
|
|
}
|