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