Migrated fun elements
This commit is contained in:
parent
6578480195
commit
8a8e63ba05
@ -5,22 +5,21 @@ import "math"
|
||||
import "image"
|
||||
import "image/color"
|
||||
import "git.tebibyte.media/sashakoshka/tomo"
|
||||
import "git.tebibyte.media/sashakoshka/tomo/canvas"
|
||||
import "git.tebibyte.media/sashakoshka/tomo/artist"
|
||||
import "git.tebibyte.media/sashakoshka/tomo/artist/shapes"
|
||||
import "git.tebibyte.media/sashakoshka/tomo/default/theme"
|
||||
|
||||
var clockCase = tomo.C("tomo", "clock")
|
||||
|
||||
// AnalogClock can display the time of day in an analog format.
|
||||
type AnalogClock struct {
|
||||
entity tomo.Entity
|
||||
time time.Time
|
||||
theme theme.Wrapped
|
||||
}
|
||||
|
||||
// NewAnalogClock creates a new analog clock that displays the specified time.
|
||||
func NewAnalogClock (newTime time.Time) (element *AnalogClock) {
|
||||
element = &AnalogClock { }
|
||||
element.theme.Case = tomo.C("tomo", "clock")
|
||||
element.entity = tomo.NewEntity(element)
|
||||
element.entity = tomo.GetBackend().NewEntity(element)
|
||||
element.entity.SetMinimumSize(64, 64)
|
||||
return
|
||||
}
|
||||
@ -31,18 +30,18 @@ func (element *AnalogClock) Entity () tomo.Entity {
|
||||
}
|
||||
|
||||
// Draw causes the element to draw to the specified destination canvas.
|
||||
func (element *AnalogClock) Draw (destination canvas.Canvas) {
|
||||
func (element *AnalogClock) Draw (destination artist.Canvas) {
|
||||
bounds := element.entity.Bounds()
|
||||
|
||||
state := tomo.State { }
|
||||
pattern := element.theme.Pattern(tomo.PatternSunken, state)
|
||||
padding := element.theme.Padding(tomo.PatternSunken)
|
||||
pattern := element.entity.Theme().Pattern(tomo.PatternSunken, state, clockCase)
|
||||
padding := element.entity.Theme().Padding(tomo.PatternSunken, clockCase)
|
||||
pattern.Draw(destination, bounds)
|
||||
|
||||
bounds = padding.Apply(bounds)
|
||||
|
||||
foreground := element.theme.Color(tomo.ColorForeground, state)
|
||||
accent := element.theme.Color(tomo.ColorAccent, state)
|
||||
foreground := element.entity.Theme().Color(tomo.ColorForeground, state, clockCase)
|
||||
accent := element.entity.Theme().Color(tomo.ColorAccent, state, clockCase)
|
||||
|
||||
for hour := 0; hour < 12; hour ++ {
|
||||
element.radialLine (
|
||||
@ -67,15 +66,12 @@ func (element *AnalogClock) SetTime (newTime time.Time) {
|
||||
element.entity.Invalidate()
|
||||
}
|
||||
|
||||
// SetTheme sets the element's theme.
|
||||
func (element *AnalogClock) SetTheme (new tomo.Theme) {
|
||||
if new == element.theme.Theme { return }
|
||||
element.theme.Theme = new
|
||||
func (element *AnalogClock) HandleThemeChange () {
|
||||
element.entity.Invalidate()
|
||||
}
|
||||
|
||||
func (element *AnalogClock) radialLine (
|
||||
destination canvas.Canvas,
|
||||
destination artist.Canvas,
|
||||
source color.RGBA,
|
||||
inner float64,
|
||||
outer float64,
|
||||
|
@ -3,12 +3,14 @@ package fun
|
||||
import "image"
|
||||
import "git.tebibyte.media/sashakoshka/tomo"
|
||||
import "git.tebibyte.media/sashakoshka/tomo/input"
|
||||
import "git.tebibyte.media/sashakoshka/tomo/canvas"
|
||||
import "git.tebibyte.media/sashakoshka/tomo/artist"
|
||||
import "git.tebibyte.media/sashakoshka/tomo/default/theme"
|
||||
import "git.tebibyte.media/sashakoshka/tomo/default/config"
|
||||
import "git.tebibyte.media/sashakoshka/tomo/artist/artutil"
|
||||
import "git.tebibyte.media/sashakoshka/tomo/elements/fun/music"
|
||||
|
||||
var pianoCase = tomo.C("tomo", "piano")
|
||||
var flatCase = tomo.C("tomo", "piano", "flatKey")
|
||||
var sharpCase = tomo.C("tomo", "piano", "sharpKey")
|
||||
|
||||
const pianoKeyWidth = 18
|
||||
|
||||
type pianoKey struct {
|
||||
@ -18,12 +20,7 @@ type pianoKey struct {
|
||||
|
||||
// Piano is an element that can be used to input midi notes.
|
||||
type Piano struct {
|
||||
entity tomo.FocusableEntity
|
||||
|
||||
config config.Wrapped
|
||||
theme theme.Wrapped
|
||||
flatTheme theme.Wrapped
|
||||
sharpTheme theme.Wrapped
|
||||
entity tomo.Entity
|
||||
|
||||
low, high music.Octave
|
||||
flatKeys []pianoKey
|
||||
@ -49,10 +46,7 @@ func NewPiano (low, high music.Octave) (element *Piano) {
|
||||
keynavPressed: make(map[music.Note] bool),
|
||||
}
|
||||
|
||||
element.theme.Case = tomo.C("tomo", "piano")
|
||||
element.flatTheme.Case = tomo.C("tomo", "piano", "flatKey")
|
||||
element.sharpTheme.Case = tomo.C("tomo", "piano", "sharpKey")
|
||||
element.entity = tomo.NewEntity(element).(tomo.FocusableEntity)
|
||||
element.entity = tomo.GetBackend().NewEntity(element)
|
||||
element.updateMinimumSize()
|
||||
return
|
||||
}
|
||||
@ -63,7 +57,7 @@ func (element *Piano) Entity () tomo.Entity {
|
||||
}
|
||||
|
||||
// Draw causes the element to draw to the specified destination canvas.
|
||||
func (element *Piano) Draw (destination canvas.Canvas) {
|
||||
func (element *Piano) Draw (destination artist.Canvas) {
|
||||
element.recalculate()
|
||||
|
||||
state := tomo.State {
|
||||
@ -90,8 +84,8 @@ func (element *Piano) Draw (destination canvas.Canvas) {
|
||||
state)
|
||||
}
|
||||
|
||||
pattern := element.theme.Pattern(tomo.PatternPinboard, state)
|
||||
artist.DrawShatter (
|
||||
pattern := element.entity.Theme().Pattern(tomo.PatternPinboard, state, pianoCase)
|
||||
artutil.DrawShatter (
|
||||
destination, pattern, element.entity.Bounds(),
|
||||
element.contentBounds)
|
||||
}
|
||||
@ -248,26 +242,13 @@ func (element *Piano) HandleKeyUp (key input.Key, modifiers input.Modifiers) {
|
||||
element.entity.Invalidate()
|
||||
}
|
||||
|
||||
// SetTheme sets the element's theme.
|
||||
func (element *Piano) SetTheme (new tomo.Theme) {
|
||||
if new == element.theme.Theme { return }
|
||||
element.theme.Theme = new
|
||||
element.flatTheme.Theme = new
|
||||
element.sharpTheme.Theme = new
|
||||
element.updateMinimumSize()
|
||||
element.entity.Invalidate()
|
||||
}
|
||||
|
||||
// SetConfig sets the element's configuration.
|
||||
func (element *Piano) SetConfig (new tomo.Config) {
|
||||
if new == element.config.Config { return }
|
||||
element.config.Config = new
|
||||
func (element *Piano) HandleThemeChange () {
|
||||
element.updateMinimumSize()
|
||||
element.entity.Invalidate()
|
||||
}
|
||||
|
||||
func (element *Piano) updateMinimumSize () {
|
||||
padding := element.theme.Padding(tomo.PatternPinboard)
|
||||
padding := element.entity.Theme().Padding(tomo.PatternPinboard, pianoCase)
|
||||
element.entity.SetMinimumSize (
|
||||
pianoKeyWidth * 7 * element.countOctaves() +
|
||||
padding.Horizontal(),
|
||||
@ -290,7 +271,7 @@ func (element *Piano) recalculate () {
|
||||
element.flatKeys = make([]pianoKey, element.countFlats())
|
||||
element.sharpKeys = make([]pianoKey, element.countSharps())
|
||||
|
||||
padding := element.theme.Padding(tomo.PatternPinboard)
|
||||
padding := element.entity.Theme().Padding(tomo.PatternPinboard, pianoCase)
|
||||
bounds := padding.Apply(element.entity.Bounds())
|
||||
|
||||
dot := bounds.Min
|
||||
@ -323,23 +304,23 @@ func (element *Piano) recalculate () {
|
||||
}
|
||||
|
||||
func (element *Piano) drawFlat (
|
||||
destination canvas.Canvas,
|
||||
destination artist.Canvas,
|
||||
bounds image.Rectangle,
|
||||
pressed bool,
|
||||
state tomo.State,
|
||||
) {
|
||||
state.Pressed = pressed
|
||||
pattern := element.flatTheme.Pattern(tomo.PatternButton, state)
|
||||
pattern := element.entity.Theme().Pattern(tomo.PatternButton, state, flatCase)
|
||||
pattern.Draw(destination, bounds)
|
||||
}
|
||||
|
||||
func (element *Piano) drawSharp (
|
||||
destination canvas.Canvas,
|
||||
destination artist.Canvas,
|
||||
bounds image.Rectangle,
|
||||
pressed bool,
|
||||
state tomo.State,
|
||||
) {
|
||||
state.Pressed = pressed
|
||||
pattern := element.sharpTheme.Pattern(tomo.PatternButton, state)
|
||||
pattern := element.entity.Theme().Pattern(tomo.PatternButton, state, sharpCase)
|
||||
pattern.Draw(destination, bounds)
|
||||
}
|
||||
|
Reference in New Issue
Block a user