2018-10-20 22:42:49 +00:00
|
|
|
package doodle
|
|
|
|
|
|
|
|
import (
|
2019-07-05 22:02:22 +00:00
|
|
|
"fmt"
|
|
|
|
|
2019-04-10 00:35:44 +00:00
|
|
|
"git.kirsle.net/apps/doodle/pkg/balance"
|
|
|
|
"git.kirsle.net/apps/doodle/pkg/log"
|
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)
|
|
|
|
|
|
|
|
// 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
|
|
|
}
|
|
|
|
|
2020-07-10 02:38:37 +00:00
|
|
|
var buttonSize = 32
|
|
|
|
|
2018-10-20 22:42:49 +00:00
|
|
|
// Draw the radio buttons for the palette.
|
|
|
|
if u.Canvas != nil && u.Canvas.Palette != nil {
|
|
|
|
for _, swatch := range u.Canvas.Palette.Swatches {
|
2019-07-05 22:02:22 +00:00
|
|
|
swFrame := ui.NewFrame(fmt.Sprintf("Swatch(%s) Button Frame", swatch.Name))
|
2020-07-10 02:38:37 +00:00
|
|
|
swFrame.Configure(ui.Config{
|
|
|
|
Width: buttonSize,
|
|
|
|
Height: buttonSize,
|
|
|
|
Background: swatch.Color,
|
2019-07-05 22:02:22 +00:00
|
|
|
})
|
2018-10-20 22:42:49 +00:00
|
|
|
|
2019-07-05 22:02:22 +00:00
|
|
|
btn := ui.NewRadioButton("palette", &u.selectedSwatch, swatch.Name, swFrame)
|
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()),
|
2020-03-10 05:22:22 +00:00
|
|
|
Edge: ui.Left,
|
|
|
|
})
|
|
|
|
|
2019-07-05 22:02:22 +00:00
|
|
|
btn.Compute(u.d.Engine)
|
|
|
|
|
2018-10-20 22:42:49 +00:00
|
|
|
frame.Pack(btn, ui.Pack{
|
2019-12-29 05:48:49 +00:00
|
|
|
Side: ui.N,
|
2019-12-31 02:13:28 +00:00
|
|
|
Fill: true,
|
|
|
|
PadY: 4,
|
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 {
|
|
|
|
// TODO: recompute the window so the actual loaded level palette gets in
|
|
|
|
u.paletteEditor.Hide()
|
|
|
|
u.paletteEditor = nil
|
|
|
|
u.SetupPopups(u.d)
|
|
|
|
u.paletteEditor.Show()
|
|
|
|
return nil
|
|
|
|
})
|
|
|
|
u.Supervisor.Add(btn)
|
|
|
|
|
|
|
|
btn.Compute(u.d.Engine)
|
|
|
|
frame.Pack(btn, ui.Pack{
|
|
|
|
Side: ui.N,
|
|
|
|
Fill: true,
|
|
|
|
PadY: 4,
|
|
|
|
})
|
|
|
|
|
2018-10-20 22:42:49 +00:00
|
|
|
return frame
|
|
|
|
}
|