More efficient animation.

This commit is contained in:
Greg 2019-09-06 15:14:37 -04:00
parent df840dd0ab
commit a6dc5cbe18
1 changed files with 30 additions and 11 deletions

View File

@ -258,6 +258,11 @@ func eventLoop() {
}
listPage = func() {
// timing variables used for animation
fade1a, fade1b := 1.5, 2.0
start2 := float64(Config.ClearDelay)
fade2a, end := start2 + 1.5, start2 + 2.0
cs = flex.Flexible(1.0)
mux.Lock()
if lst.Dragging() {
@ -289,7 +294,11 @@ func eventLoop() {
overlay = copied
overlay.Color = black
overlay.Background = darkgray
animOn()
w.Invalidate()
go func() {
time.Sleep(time.Second * time.Duration(fade1a))
animOn()
}()
go func() {
time.Sleep(time.Second * time.Duration(Config.ClearDelay))
log(Info, "clearing clipboard")
@ -312,12 +321,19 @@ func eventLoop() {
}
flex.Layout(c1, c2)
x := time.Since(overlayStart).Seconds()
fade1a, fade1b := 1.5, 1.75
start2 := float64(Config.ClearDelay)
fade2a, end := start2 + 1.5, start2 + 1.75
switch {
case x > fade1a && x < fade1b ||
x > fade2a && x < end:
if x >= fade1b && x < start2 && animating {
animOff()
go func() {
time.Sleep(time.Millisecond * time.Duration((start2 - x)*1000))
w.Invalidate()
time.Sleep(time.Millisecond * time.Duration((fade2a - start2)*1000))
animOn()
}()
}
if (x >= fade1a && x < fade1b) || (x > fade2a && x < end) {
if !animating {
animOn()
}
var fade float64
switch {
case x < fade1b:
@ -333,9 +349,8 @@ func eventLoop() {
overlay.Background.G = uint8(float64(darkgray.G) * fade)
overlay.Background.B = uint8(float64(darkgray.B) * fade)
overlay.Background.A = uint8(float64(darkgray.A) * fade)
fallthrough
case x <= fade1b ||
x > start2 && x < end:
}
if x <= fade1b || (x > start2 && x < end) {
if x > start2 && overlay == copied {
overlay = cleared
overlay.Color = black
@ -346,7 +361,11 @@ func eventLoop() {
cs = al.Begin(ops, cs)
cs.Width.Min = cs.Width.Max
dims = al.End(overlay.Layout(c, ops, cs))
case animating && x > end:
}
if x > start2 && x < fade2a {
// animOff()
}
if animating && x > end {
animOff()
}
}