themes and styles
This commit is contained in:
@@ -0,0 +1,93 @@
|
||||
package world
|
||||
|
||||
import (
|
||||
"image"
|
||||
"image/color"
|
||||
)
|
||||
|
||||
// BackgroundTileMode defines how the background image is tiled.
|
||||
type BackgroundTileMode uint8
|
||||
|
||||
const (
|
||||
BackgroundTileNone BackgroundTileMode = iota
|
||||
BackgroundTileRepeat
|
||||
)
|
||||
|
||||
// BackgroundAnchorMode defines whether the background image scrolls with the world or stays fixed to viewport.
|
||||
type BackgroundAnchorMode uint8
|
||||
|
||||
const (
|
||||
BackgroundAnchorWorld BackgroundAnchorMode = iota
|
||||
BackgroundAnchorViewport
|
||||
)
|
||||
|
||||
// BackgroundScaleMode defines how the background image is scaled.
|
||||
// (Step 1: defined for API completeness; used later when rendering background image.)
|
||||
type BackgroundScaleMode uint8
|
||||
|
||||
const (
|
||||
BackgroundScaleNone BackgroundScaleMode = iota
|
||||
BackgroundScaleFit
|
||||
BackgroundScaleFill
|
||||
)
|
||||
|
||||
// StyleTheme describes a cohesive style set (theme) for rendering.
|
||||
// Step 1: we store it in World and use it for background and default base styles.
|
||||
// Step 2+: theme-relative overrides and background image drawing.
|
||||
type StyleTheme interface {
|
||||
ID() string
|
||||
Name() string
|
||||
|
||||
BackgroundColor() color.Color
|
||||
BackgroundImage() image.Image
|
||||
|
||||
BackgroundTileMode() BackgroundTileMode
|
||||
BackgroundScaleMode() BackgroundScaleMode
|
||||
BackgroundAnchorMode() BackgroundAnchorMode
|
||||
|
||||
PointStyle() Style
|
||||
LineStyle() Style
|
||||
CircleStyle() Style
|
||||
|
||||
// Class overrides (relative to base kind style).
|
||||
// Return (override, true) when class is supported; (zero, false) means "no override".
|
||||
PointClassOverride(class PointClassID) (StyleOverride, bool)
|
||||
LineClassOverride(class LineClassID) (StyleOverride, bool)
|
||||
CircleClassOverride(class CircleClassID) (StyleOverride, bool)
|
||||
}
|
||||
|
||||
// DefaultTheme is a conservative theme matching built-in default styles.
|
||||
type DefaultTheme struct{}
|
||||
|
||||
func (DefaultTheme) ID() string { return "default" }
|
||||
func (DefaultTheme) Name() string { return "Default" }
|
||||
|
||||
func (DefaultTheme) BackgroundColor() color.Color { return color.RGBA{A: 255} }
|
||||
func (DefaultTheme) BackgroundImage() image.Image { return nil }
|
||||
|
||||
func (DefaultTheme) BackgroundTileMode() BackgroundTileMode { return BackgroundTileNone }
|
||||
func (DefaultTheme) BackgroundScaleMode() BackgroundScaleMode { return BackgroundScaleNone }
|
||||
func (DefaultTheme) BackgroundAnchorMode() BackgroundAnchorMode { return BackgroundAnchorWorld }
|
||||
|
||||
func (DefaultTheme) PointStyle() Style {
|
||||
s, _ := NewStyleTable().Get(StyleIDDefaultPoint)
|
||||
return s
|
||||
}
|
||||
func (DefaultTheme) LineStyle() Style {
|
||||
s, _ := NewStyleTable().Get(StyleIDDefaultLine)
|
||||
return s
|
||||
}
|
||||
func (DefaultTheme) CircleStyle() Style {
|
||||
s, _ := NewStyleTable().Get(StyleIDDefaultCircle)
|
||||
return s
|
||||
}
|
||||
|
||||
func (DefaultTheme) PointClassOverride(PointClassID) (StyleOverride, bool) {
|
||||
return StyleOverride{}, false
|
||||
}
|
||||
func (DefaultTheme) LineClassOverride(LineClassID) (StyleOverride, bool) {
|
||||
return StyleOverride{}, false
|
||||
}
|
||||
func (DefaultTheme) CircleClassOverride(CircleClassID) (StyleOverride, bool) {
|
||||
return StyleOverride{}, false
|
||||
}
|
||||
Reference in New Issue
Block a user