2023-02-02 22:57:18 -07:00
|
|
|
package theme
|
|
|
|
|
|
|
|
import "image"
|
2023-02-27 10:48:44 -07:00
|
|
|
import "bytes"
|
|
|
|
import _ "embed"
|
|
|
|
import _ "image/png"
|
2023-02-26 20:20:17 -07:00
|
|
|
import "image/color"
|
2023-02-02 22:57:18 -07:00
|
|
|
import "golang.org/x/image/font"
|
|
|
|
import "git.tebibyte.media/sashakoshka/tomo/artist"
|
2023-02-12 08:55:32 -07:00
|
|
|
import "git.tebibyte.media/sashakoshka/tomo/canvas"
|
2023-02-02 22:57:18 -07:00
|
|
|
import "git.tebibyte.media/sashakoshka/tomo/defaultfont"
|
2023-02-25 22:44:44 -07:00
|
|
|
import "git.tebibyte.media/sashakoshka/tomo/artist/patterns"
|
2023-02-02 22:57:18 -07:00
|
|
|
|
2023-02-27 10:48:44 -07:00
|
|
|
//go:embed assets/wintergreen.png
|
|
|
|
var defaultAtlasBytes []byte
|
|
|
|
var defaultAtlas canvas.Canvas
|
2023-02-28 17:00:34 -07:00
|
|
|
var defaultTextures [14][9]artist.Pattern
|
2023-02-27 10:48:44 -07:00
|
|
|
|
|
|
|
func atlasCell (col, row int, border artist.Inset) {
|
|
|
|
bounds := image.Rect(0, 0, 16, 16).Add(image.Pt(col, row).Mul(16))
|
|
|
|
defaultTextures[col][row] = patterns.Border {
|
|
|
|
Canvas: canvas.Cut(defaultAtlas, bounds),
|
|
|
|
Inset: border,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func atlasCol (col int, border artist.Inset) {
|
|
|
|
for index, _ := range defaultTextures[col] {
|
|
|
|
atlasCell(col, index, border)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func init () {
|
|
|
|
defaultAtlasImage, _, _ := image.Decode(bytes.NewReader(defaultAtlasBytes))
|
|
|
|
defaultAtlas = canvas.FromImage(defaultAtlasImage)
|
|
|
|
|
|
|
|
// PatternDead
|
|
|
|
atlasCol(0, artist.Inset { })
|
|
|
|
// PatternRaised
|
2023-02-27 22:17:05 -07:00
|
|
|
atlasCol(1, artist.Inset { 6, 6, 6, 6 })
|
2023-02-27 10:48:44 -07:00
|
|
|
// PatternSunken
|
|
|
|
atlasCol(2, artist.Inset { 4, 4, 4, 4 })
|
|
|
|
// PatternPinboard
|
|
|
|
atlasCol(3, artist.Inset { 2, 2, 2, 2 })
|
|
|
|
// PatternButton
|
2023-02-27 22:17:05 -07:00
|
|
|
atlasCol(4, artist.Inset { 6, 6, 6, 6 })
|
2023-02-27 10:48:44 -07:00
|
|
|
// PatternInput
|
|
|
|
atlasCol(5, artist.Inset { 4, 4, 4, 4 })
|
|
|
|
// PatternGutter
|
2023-02-28 15:15:20 -07:00
|
|
|
atlasCol(6, artist.Inset { 7, 7, 7, 7 })
|
2023-02-27 10:48:44 -07:00
|
|
|
// PatternHandle
|
2023-03-01 11:06:34 -07:00
|
|
|
atlasCol(7, artist.Inset { 3, 3, 3, 3 })
|
2023-02-27 22:17:05 -07:00
|
|
|
// PatternLine
|
|
|
|
atlasCol(8, artist.Inset { 1, 1, 1, 1 })
|
2023-02-28 17:00:34 -07:00
|
|
|
// PatternMercury
|
|
|
|
atlasCol(13, artist.Inset { 2, 2, 2, 2 })
|
2023-02-27 22:17:05 -07:00
|
|
|
|
|
|
|
// PatternButton: basic.checkbox
|
|
|
|
atlasCol(9, artist.Inset { 3, 3, 3, 3 })
|
|
|
|
// PatternRaised: basic.listEntry
|
|
|
|
atlasCol(10, artist.Inset { 3, 3, 3, 3 })
|
|
|
|
// PatternRaised: fun.flatKey
|
|
|
|
atlasCol(11, artist.Inset { 3, 3, 5, 3 })
|
|
|
|
// PatternRaised: fun.sharpKey
|
|
|
|
atlasCol(12, artist.Inset { 3, 3, 4, 3 })
|
2023-02-27 10:48:44 -07:00
|
|
|
}
|
|
|
|
|
2023-02-02 22:57:18 -07:00
|
|
|
// Default is the default theme.
|
|
|
|
type Default struct { }
|
|
|
|
|
|
|
|
// FontFace returns the default font face.
|
|
|
|
func (Default) FontFace (style FontStyle, size FontSize, c Case) font.Face {
|
|
|
|
switch style {
|
|
|
|
case FontStyleBold:
|
|
|
|
return defaultfont.FaceBold
|
|
|
|
case FontStyleItalic:
|
|
|
|
return defaultfont.FaceItalic
|
|
|
|
case FontStyleBoldItalic:
|
|
|
|
return defaultfont.FaceBoldItalic
|
|
|
|
default:
|
|
|
|
return defaultfont.FaceRegular
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Icon returns an icon from the default set corresponding to the given name.
|
2023-02-12 08:58:23 -07:00
|
|
|
func (Default) Icon (string, IconSize, Case) canvas.Image {
|
2023-02-02 22:57:18 -07:00
|
|
|
// TODO
|
2023-02-12 08:55:32 -07:00
|
|
|
return nil
|
2023-02-02 22:57:18 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
// Pattern returns a pattern from the default theme corresponding to the given
|
|
|
|
// pattern ID.
|
2023-02-26 20:20:17 -07:00
|
|
|
func (Default) Pattern (id Pattern, state State, c Case) artist.Pattern {
|
2023-02-27 10:48:44 -07:00
|
|
|
offset := 0; switch {
|
|
|
|
case state.Disabled: offset = 1
|
2023-02-28 15:15:20 -07:00
|
|
|
case state.Pressed && state.On: offset = 4
|
2023-02-27 10:48:44 -07:00
|
|
|
case state.Focused && state.On: offset = 7
|
2023-02-28 15:15:20 -07:00
|
|
|
case state.Invalid && state.On: offset = 8
|
|
|
|
case state.On: offset = 2
|
|
|
|
case state.Pressed: offset = 3
|
|
|
|
case state.Focused: offset = 5
|
|
|
|
case state.Invalid: offset = 6
|
2023-02-27 10:48:44 -07:00
|
|
|
}
|
|
|
|
|
2023-02-26 20:20:17 -07:00
|
|
|
switch id {
|
2023-02-27 10:48:44 -07:00
|
|
|
case PatternBackground: return patterns.Uhex(0xaaaaaaFF)
|
|
|
|
case PatternDead: return defaultTextures[0][offset]
|
2023-02-27 22:17:05 -07:00
|
|
|
case PatternRaised:
|
|
|
|
if c == C("basic", "listEntry") {
|
|
|
|
return defaultTextures[10][offset]
|
|
|
|
} else {
|
|
|
|
return defaultTextures[1][offset]
|
|
|
|
}
|
2023-02-27 10:48:44 -07:00
|
|
|
case PatternSunken: return defaultTextures[2][offset]
|
|
|
|
case PatternPinboard: return defaultTextures[3][offset]
|
2023-02-27 22:17:05 -07:00
|
|
|
case PatternButton:
|
|
|
|
switch c {
|
|
|
|
case C("basic", "checkbox"): return defaultTextures[9][offset]
|
|
|
|
case C("fun", "flatKey"): return defaultTextures[11][offset]
|
|
|
|
case C("fun", "sharpKey"): return defaultTextures[12][offset]
|
|
|
|
default: return defaultTextures[4][offset]
|
|
|
|
}
|
2023-02-27 10:48:44 -07:00
|
|
|
case PatternInput: return defaultTextures[5][offset]
|
|
|
|
case PatternGutter: return defaultTextures[6][offset]
|
|
|
|
case PatternHandle: return defaultTextures[7][offset]
|
2023-02-27 22:17:05 -07:00
|
|
|
case PatternLine: return defaultTextures[8][offset]
|
2023-02-28 17:00:34 -07:00
|
|
|
case PatternMercury: return defaultTextures[13][offset]
|
2023-02-27 10:48:44 -07:00
|
|
|
default: return patterns.Uhex(0xFF00FFFF)
|
2023-02-02 22:57:18 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-02-26 20:20:17 -07:00
|
|
|
func (Default) Color (id Color, state State, c Case) color.RGBA {
|
2023-02-27 10:48:44 -07:00
|
|
|
if state.Disabled {
|
|
|
|
return artist.Hex(0x444444FF)
|
|
|
|
} else {
|
|
|
|
switch id {
|
|
|
|
case ColorAccent: return artist.Hex(0x408090FF)
|
|
|
|
case ColorForeground: return artist.Hex(0x000000FF)
|
|
|
|
default: return artist.Hex(0x888888FF)
|
|
|
|
}
|
2023-02-26 20:20:17 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-02-25 22:44:44 -07:00
|
|
|
// Padding returns the default padding value for the given pattern.
|
2023-02-27 15:00:28 -07:00
|
|
|
func (Default) Padding (id Pattern, c Case) artist.Inset {
|
|
|
|
switch id {
|
2023-02-27 22:17:05 -07:00
|
|
|
case PatternRaised:
|
|
|
|
if c == C("basic", "listEntry") {
|
2023-02-28 15:15:20 -07:00
|
|
|
return artist.Inset { 4, 8, 4, 8 }
|
2023-02-27 22:17:05 -07:00
|
|
|
} else {
|
|
|
|
return artist.Inset { 8, 8, 8, 8 }
|
|
|
|
}
|
2023-02-27 15:00:28 -07:00
|
|
|
case PatternSunken:
|
|
|
|
if c == C("basic", "list") {
|
2023-02-28 15:15:20 -07:00
|
|
|
return artist.Inset { 4, 0, 3, 0 }
|
2023-02-28 17:00:34 -07:00
|
|
|
} else if c == C("basic", "progressBar") {
|
|
|
|
return artist.Inset { 2, 1, 1, 2 }
|
2023-02-27 22:17:05 -07:00
|
|
|
} else {
|
|
|
|
return artist.Inset { 8, 8, 8, 8 }
|
|
|
|
}
|
|
|
|
case PatternPinboard:
|
|
|
|
if c == C("fun", "piano") {
|
2023-02-27 15:00:28 -07:00
|
|
|
return artist.Inset { 2, 2, 2, 2 }
|
|
|
|
} else {
|
|
|
|
return artist.Inset { 8, 8, 8, 8 }
|
|
|
|
}
|
|
|
|
case PatternGutter: return artist.Inset { }
|
2023-02-27 22:17:05 -07:00
|
|
|
case PatternLine: return artist.Inset { 1, 1, 1, 1 }
|
2023-02-28 17:00:34 -07:00
|
|
|
case PatternMercury: return artist.Inset { 5, 5, 5, 5 }
|
2023-02-27 15:00:28 -07:00
|
|
|
default: return artist.Inset { 8, 8, 8, 8 }
|
|
|
|
}
|
2023-02-25 22:44:44 -07:00
|
|
|
}
|
2023-02-09 09:38:01 -07:00
|
|
|
|
2023-02-25 22:44:44 -07:00
|
|
|
// Margin returns the default margin value for the given pattern.
|
|
|
|
func (Default) Margin (id Pattern, c Case) image.Point {
|
2023-02-27 10:48:44 -07:00
|
|
|
return image.Pt(8, 8)
|
2023-02-02 22:57:18 -07:00
|
|
|
}
|
|
|
|
|
2023-02-16 16:00:15 -07:00
|
|
|
// Hints returns rendering optimization hints for a particular pattern.
|
|
|
|
// These are optional, but following them may result in improved
|
|
|
|
// performance.
|
|
|
|
func (Default) Hints (pattern Pattern, c Case) (hints Hints) {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2023-02-02 22:57:18 -07:00
|
|
|
// Sink returns the default sink vector for the given pattern.
|
|
|
|
func (Default) Sink (pattern Pattern, c Case) image.Point {
|
|
|
|
return image.Point { 1, 1 }
|
|
|
|
}
|