2018-08-11 00:19:47 +00:00
|
|
|
package level
|
|
|
|
|
2019-12-23 02:21:58 +00:00
|
|
|
import "git.kirsle.net/go/render"
|
2018-08-11 00:19:47 +00:00
|
|
|
|
|
|
|
// DefaultPalette returns a sensible default palette.
|
|
|
|
func DefaultPalette() *Palette {
|
|
|
|
return &Palette{
|
|
|
|
Swatches: []*Swatch{
|
|
|
|
&Swatch{
|
|
|
|
Name: "solid",
|
|
|
|
Color: render.Black,
|
|
|
|
Solid: true,
|
|
|
|
},
|
|
|
|
&Swatch{
|
|
|
|
Name: "decoration",
|
|
|
|
Color: render.Grey,
|
|
|
|
},
|
|
|
|
&Swatch{
|
|
|
|
Name: "fire",
|
|
|
|
Color: render.Red,
|
|
|
|
Fire: true,
|
|
|
|
},
|
|
|
|
&Swatch{
|
|
|
|
Name: "water",
|
2019-07-14 21:18:44 +00:00
|
|
|
Color: render.RGBA(0, 0, 255, 180),
|
2018-08-11 00:19:47 +00:00
|
|
|
Water: true,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-06-26 00:43:23 +00:00
|
|
|
// NewBlueprintPalette returns the blueprint theme's color palette.
|
|
|
|
func NewBlueprintPalette() *Palette {
|
|
|
|
return &Palette{
|
|
|
|
Swatches: []*Swatch{
|
|
|
|
&Swatch{
|
|
|
|
Name: "solid",
|
|
|
|
Color: render.RGBA(254, 254, 254, 255),
|
|
|
|
Solid: true,
|
|
|
|
},
|
|
|
|
&Swatch{
|
|
|
|
Name: "decoration",
|
|
|
|
Color: render.Grey,
|
|
|
|
},
|
|
|
|
&Swatch{
|
|
|
|
Name: "fire",
|
|
|
|
Color: render.RGBA(255, 80, 0, 255),
|
|
|
|
Fire: true,
|
|
|
|
},
|
|
|
|
&Swatch{
|
|
|
|
Name: "water",
|
|
|
|
Color: render.RGBA(0, 153, 255, 255),
|
|
|
|
Water: true,
|
|
|
|
},
|
|
|
|
&Swatch{
|
|
|
|
Name: "electric",
|
|
|
|
Color: render.RGBA(255, 255, 0, 255),
|
|
|
|
Solid: true,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-08-17 03:37:19 +00:00
|
|
|
// NewPalette initializes a blank palette.
|
|
|
|
func NewPalette() *Palette {
|
|
|
|
return &Palette{
|
|
|
|
Swatches: []*Swatch{},
|
|
|
|
byName: map[string]int{},
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-08-11 00:19:47 +00:00
|
|
|
// Palette holds an index of colors used in a drawing.
|
|
|
|
type Palette struct {
|
|
|
|
Swatches []*Swatch `json:"swatches"`
|
|
|
|
|
|
|
|
// Private runtime values
|
2018-08-17 03:37:19 +00:00
|
|
|
ActiveSwatch *Swatch `json:"-"` // name of the actively selected color
|
2018-08-11 00:19:47 +00:00
|
|
|
byName map[string]int // Cache map of swatches by name
|
|
|
|
}
|
|
|
|
|
Menu Toolbar for Editor + Shell Prompts + Theme
* Added a "menu toolbar" to the top of the Edit Mode with useful buttons
that work: New Level, New Doodad (same thing), Save, Save as, Open.
* Added ability for the dev console to prompt the user for a question,
which opens the console automatically. "Save", "Save as" and "Load"
ask for their filenames this way.
* Started groundwork for theming the app. The palette window is a light
brown with an orange title bar, the Menu Toolbar has a black
background, etc.
* Added support for multiple fonts instead of just monospace. DejaVu
Sans (normal and bold) are used now for most labels and window titles,
respectively. The dev console uses DejaVu Sans Mono as before.
* Update ui.Label to accept PadX and PadY separately instead of only
having the Padding option which did both.
* Improvements to Frame packing algorithm.
* Set the SDL draw mode to BLEND so we can use alpha colors properly,
so now the dev console is semi-translucent.
2018-08-12 00:30:00 +00:00
|
|
|
// Inflate the palette swatch caches. Always call this method after you have
|
|
|
|
// initialized the palette (i.e. loaded it from JSON); this will update the
|
|
|
|
// "color by name" cache and assign the index numbers to each swatch.
|
|
|
|
func (p *Palette) Inflate() {
|
|
|
|
p.update()
|
|
|
|
}
|
|
|
|
|
2018-08-11 00:19:47 +00:00
|
|
|
// Get a swatch by name.
|
|
|
|
func (p *Palette) Get(name string) (result *Swatch, exists bool) {
|
|
|
|
p.update()
|
|
|
|
|
|
|
|
if index, ok := p.byName[name]; ok && index < len(p.Swatches) {
|
|
|
|
result = p.Swatches[index]
|
|
|
|
exists = true
|
|
|
|
}
|
|
|
|
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
// update the internal caches and such.
|
|
|
|
func (p *Palette) update() {
|
|
|
|
// Initialize the name cache if nil or if the size disagrees with the
|
|
|
|
// length of the swatches available.
|
|
|
|
if p.byName == nil || len(p.byName) != len(p.Swatches) {
|
|
|
|
// Initialize the name cache.
|
|
|
|
p.byName = map[string]int{}
|
|
|
|
for i, swatch := range p.Swatches {
|
|
|
|
swatch.index = i
|
|
|
|
p.byName[swatch.Name] = i
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|