#FEATURE by cg
authorClaus Gittinger <cg@exept.de>
Mon, 16 May 2016 08:53:15 +0200
changeset 5749 d343e6f28915
parent 5746 813beb879bc9
child 5750 12b4fa216382
#FEATURE by cg class: Label changed: #doAnimate #startAnimation #stopAnimation
Label.st
--- a/Label.st	Sun May 15 17:50:56 2016 +0200
+++ b/Label.st	Mon May 16 08:53:15 2016 +0200
@@ -1471,43 +1471,58 @@
     "by slow scrolling the label, ensure that the label's text is readable.
      (stops when the cursor enters)"
     
-    |offset animator atTop atBottom|
+    |animatorAndOffset offset animator atTop atBottom nextOffset nextAnimationDelay focusView|
     
-    (animator := self objectAttributeAt:#animator) isNil ifTrue:[^ self "I have been stopped"].
-    drawableId isNil ifTrue:[^ self].
+    animatorAndOffset := self objectAttributeAt:#animator.
+    animatorAndOffset isNil ifTrue:[^ self "I have been stopped in the meanwhile"].
     
-    offset := self objectAttributeAt:#animatorOffset.
+    (drawableId notNil and:[shown]) ifFalse:[
+        "/ view has been closed.
+        self removeObjectAttribute:#animator.
+        ^ self
+    ].
+
+    animator := animatorAndOffset at:1.
+    offset := animatorAndOffset at:2.
+
     atTop := (offset == 0).
-    atBottom := (offset - self font ascent + labelHeight) > self height .
+    atBottom := (offset - self font ascent + self font height) > (self height + 1).
     
+    nextAnimationDelay := (atTop | atBottom)
+                                ifTrue:[ self animationDelayTopOrBottom ]
+                                ifFalse:[ self animationDelay ]. 
+
     atBottom ifTrue:[
         "/ after a longer delay, start again from top
-        self objectAttributeAt:#animatorOffset put:0.
-        Processor addTimedBlock:animator after:(self animationDelayTopOrBottom).
-        ^ self.
+        nextOffset := 0.
+    ] ifFalse:[    
+        nextOffset := offset + 1.
     ].
-    
+
+    "/ If I am not part of the active window, scroll back to top and wait longer...
+    ((focusView := Display focusView) notNil
+    and:[ focusView windowGroup == self windowGroup ]) ifFalse:[
+        nextOffset := offset := 0.
+        nextAnimationDelay := self animationDelayTopOrBottom.
+    ].
+
     labelOriginY := offset negated.
-    offset := offset + 1.
-    self objectAttributeAt:#animatorOffset put:offset.
+    animatorAndOffset at:2 put:nextOffset.
+
     self invalidate.
-    
-    Processor addTimedBlock:animator 
-              after:(atTop 
-                        ifTrue:[self animationDelayTopOrBottom] 
-                        ifFalse:[self animationDelay]).
+    Processor addTimedBlock:animator after:nextAnimationDelay.
 !
 
 startAnimation
-    "start an animator, which ensures that the label's text is visible
+    "start an animator, which scrolls the label's text.
      (slow scroll which stops when the cursor enters)"
     
     |animator|
     
     self stopAnimation.
+
     animator := [ self doAnimate ].
-    self objectAttributeAt:#animatorOffset put:0.
-    self objectAttributeAt:#animator put:animator.
+    self objectAttributeAt:#animator put:{ animator . 0 }.
     Processor addTimedBlock:animator after:(self animationDelay)
 
     "
@@ -1520,7 +1535,6 @@
 Line3
 Line4'.
      l openAndWait.
-     Delay waitForSeconds:10.
      l startAnimation.
      Delay waitForSeconds:10.
      l stopAnimation.
@@ -1528,15 +1542,18 @@
 !
 
 stopAnimation
-    |animator|
+    |animatorAndOffset animator|
     
-    (animator := (self objectAttributeAt:#animator) notNil) ifTrue:[
-        self objectAttributeAt:#animator put:nil.
+    animatorAndOffset := self removeObjectAttribute:#animator.
+    animatorAndOffset notNil ifTrue:[
+        animator := animatorAndOffset first.
         Processor removeTimedBlock:animator.
-        
-        "/ ensure that things are in their normal state again
-        self computeLabelOrigin.
-        self invalidate.
+
+        shown ifTrue:[
+            "/ ensure that things are in their normal state again
+            self computeLabelOrigin.
+            self invalidate.
+        ].
     ].
 ! !