Migrated the clock
This commit is contained in:
parent
a0e57921a4
commit
6cc0f36000
@ -4,21 +4,24 @@ import "time"
|
|||||||
import "math"
|
import "math"
|
||||||
import "image"
|
import "image"
|
||||||
import "git.tebibyte.media/sashakoshka/tomo/theme"
|
import "git.tebibyte.media/sashakoshka/tomo/theme"
|
||||||
|
import "git.tebibyte.media/sashakoshka/tomo/config"
|
||||||
import "git.tebibyte.media/sashakoshka/tomo/artist"
|
import "git.tebibyte.media/sashakoshka/tomo/artist"
|
||||||
import "git.tebibyte.media/sashakoshka/tomo/elements/core"
|
import "git.tebibyte.media/sashakoshka/tomo/elements/core"
|
||||||
|
|
||||||
var clockCase = theme.C("fun", "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 {
|
||||||
*core.Core
|
*core.Core
|
||||||
core core.CoreControl
|
core core.CoreControl
|
||||||
time time.Time
|
time time.Time
|
||||||
|
|
||||||
|
config config.Wrapped
|
||||||
|
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 = theme.C("fun", "clock")
|
||||||
element.Core, element.core = core.NewCore(element.draw)
|
element.Core, element.core = core.NewCore(element.draw)
|
||||||
element.core.SetMinimumSize(64, 64)
|
element.core.SetMinimumSize(64, 64)
|
||||||
return
|
return
|
||||||
@ -28,6 +31,24 @@ func NewAnalogClock (newTime time.Time) (element *AnalogClock) {
|
|||||||
func (element *AnalogClock) SetTime (newTime time.Time) {
|
func (element *AnalogClock) SetTime (newTime time.Time) {
|
||||||
if newTime == element.time { return }
|
if newTime == element.time { return }
|
||||||
element.time = newTime
|
element.time = newTime
|
||||||
|
element.redo()
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetTheme sets the element's theme.
|
||||||
|
func (element *AnalogClock) SetTheme (new theme.Theme) {
|
||||||
|
if new == element.theme.Theme { return }
|
||||||
|
element.theme.Theme = new
|
||||||
|
element.redo()
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetConfig sets the element's configuration.
|
||||||
|
func (element *AnalogClock) SetConfig (new config.Config) {
|
||||||
|
if new == element.config.Config { return }
|
||||||
|
element.config.Config = new
|
||||||
|
element.redo()
|
||||||
|
}
|
||||||
|
|
||||||
|
func (element *AnalogClock) redo () {
|
||||||
if element.core.HasImage() {
|
if element.core.HasImage() {
|
||||||
element.draw()
|
element.draw()
|
||||||
element.core.DamageAll()
|
element.core.DamageAll()
|
||||||
@ -37,19 +58,15 @@ func (element *AnalogClock) SetTime (newTime time.Time) {
|
|||||||
func (element *AnalogClock) draw () {
|
func (element *AnalogClock) draw () {
|
||||||
bounds := element.Bounds()
|
bounds := element.Bounds()
|
||||||
|
|
||||||
pattern, inset := theme.SunkenPattern(theme.PatternState {
|
state := theme.PatternState { }
|
||||||
Case: clockCase,
|
pattern := element.theme.Pattern(theme.PatternSunken, state)
|
||||||
})
|
inset := element.theme.Inset(theme.PatternSunken)
|
||||||
artist.FillRectangle(element, pattern, bounds)
|
artist.FillRectangle(element, pattern, bounds)
|
||||||
|
|
||||||
bounds = inset.Apply(bounds)
|
bounds = inset.Apply(bounds)
|
||||||
|
|
||||||
foreground, _ := theme.ForegroundPattern(theme.PatternState {
|
foreground := element.theme.Pattern(theme.PatternForeground, state)
|
||||||
Case: clockCase,
|
accent := element.theme.Pattern(theme.PatternAccent, state)
|
||||||
})
|
|
||||||
accent, _ := theme.AccentPattern(theme.PatternState {
|
|
||||||
Case: clockCase,
|
|
||||||
})
|
|
||||||
|
|
||||||
for hour := 0; hour < 12; hour ++ {
|
for hour := 0; hour < 12; hour ++ {
|
||||||
element.radialLine (
|
element.radialLine (
|
||||||
@ -71,7 +88,7 @@ func (element *AnalogClock) FlexibleHeightFor (width int) (height int) {
|
|||||||
return width
|
return width
|
||||||
}
|
}
|
||||||
|
|
||||||
// OnFlexibleHeightChange sets a function to be calle dwhen the parameters
|
// OnFlexibleHeightChange sets a function to be called when the parameters
|
||||||
// affecting the clock's flexible height change.
|
// affecting the clock's flexible height change.
|
||||||
func (element *AnalogClock) OnFlexibleHeightChange (func ()) { }
|
func (element *AnalogClock) OnFlexibleHeightChange (func ()) { }
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user