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