Add image textures to theme

This commit is contained in:
Sasha Koshka
2023-02-27 12:48:44 -05:00
parent 449922851f
commit de10cde630
5 changed files with 87 additions and 28 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.2 KiB

View File

@@ -1,6 +1,9 @@
package theme
import "image"
import "bytes"
import _ "embed"
import _ "image/png"
import "image/color"
import "golang.org/x/image/font"
import "git.tebibyte.media/sashakoshka/tomo/artist"
@@ -8,6 +11,47 @@ import "git.tebibyte.media/sashakoshka/tomo/canvas"
import "git.tebibyte.media/sashakoshka/tomo/defaultfont"
import "git.tebibyte.media/sashakoshka/tomo/artist/patterns"
//go:embed assets/wintergreen.png
var defaultAtlasBytes []byte
var defaultAtlas canvas.Canvas
var defaultTextures [8][10]artist.Pattern
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
atlasCol(1, artist.Inset { 6, 6, 6, 6 })
// PatternSunken
atlasCol(2, artist.Inset { 4, 4, 4, 4 })
// PatternPinboard
atlasCol(3, artist.Inset { 2, 2, 2, 2 })
// PatternButton
atlasCol(4, artist.Inset { 6, 6, 6, 6 })
// PatternInput
atlasCol(5, artist.Inset { 4, 4, 4, 4 })
// PatternGutter
atlasCol(6, artist.Inset { 4, 4, 4, 4 })
// PatternHandle
atlasCol(7, artist.Inset { 6, 6, 6, 6 })
}
// Default is the default theme.
type Default struct { }
@@ -34,36 +78,52 @@ func (Default) Icon (string, IconSize, Case) canvas.Image {
// Pattern returns a pattern from the default theme corresponding to the given
// pattern ID.
func (Default) Pattern (id Pattern, state State, c Case) artist.Pattern {
offset := 0; switch {
case state.Disabled: offset = 1
case state.Focused && state.Pressed: offset = 6
case state.Focused && state.On: offset = 7
case state.Invalid && state.Pressed: offset = 8
case state.Invalid && state.On: offset = 9
case state.Invalid: offset = 5
case state.Focused: offset = 4
case state.Pressed: offset = 2
case state.On: offset = 3
}
switch id {
case PatternBackground: return patterns.Uhex(0x000000FF)
// case PatternDead:
// case PatternRaised:
// case PatternSunken:
// case PatternPinboard:
// case PatternButton:
// case PatternInput:
// case PatternGutter:
// case PatternHandle:
default: return patterns.Uhex(0x888888FF)
case PatternBackground: return patterns.Uhex(0xaaaaaaFF)
case PatternDead: return defaultTextures[0][offset]
case PatternRaised: return defaultTextures[1][offset]
case PatternSunken: return defaultTextures[2][offset]
case PatternPinboard: return defaultTextures[3][offset]
case PatternButton: return defaultTextures[4][offset]
case PatternInput: return defaultTextures[5][offset]
case PatternGutter: return defaultTextures[6][offset]
case PatternHandle: return defaultTextures[7][offset]
default: return patterns.Uhex(0xFF00FFFF)
}
}
func (Default) Color (id Color, state State, c Case) color.RGBA {
switch id {
case ColorAccent: return artist.Hex(0xFF8800FF)
case ColorForeground: return artist.Hex(0xFFFFFFFF)
default: return artist.Hex(0x888888FF)
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)
}
}
}
// Padding returns the default padding value for the given pattern.
func (Default) Padding (pattern Pattern, c Case) artist.Inset {
return artist.Inset { 4, 4, 4, 4}
return artist.Inset { 8, 8, 8, 8 }
}
// Margin returns the default margin value for the given pattern.
func (Default) Margin (id Pattern, c Case) image.Point {
return image.Pt(4, 4)
return image.Pt(8, 8)
}
// Hints returns rendering optimization hints for a particular pattern.