@@ -44,23 +44,23 @@ func (tk *ToolKit) PlayImage(i image.Image, delay time.Duration) error {
44
44
}
45
45
46
46
type Animation interface {
47
- Next () (image.Image , time.Duration , error )
47
+ Next () (image.Image , <- chan time.Time , error )
48
48
}
49
49
50
50
// PlayAnimation play the image during the delay returned by Next, until an err
51
51
// is returned, if io.EOF is returned, PlayAnimation finish without an error
52
52
func (tk * ToolKit ) PlayAnimation (a Animation ) error {
53
53
var err error
54
54
var i image.Image
55
- var d time.Duration
55
+ var n <- chan time.Time
56
56
57
57
for {
58
- i , d , err = a .Next ()
58
+ i , n , err = a .Next ()
59
59
if err != nil {
60
60
break
61
61
}
62
62
63
- if err := tk .PlayImage (i , d ); err != nil {
63
+ if err := tk .PlayImageUntil (i , n ); err != nil {
64
64
return err
65
65
}
66
66
}
@@ -72,6 +72,20 @@ func (tk *ToolKit) PlayAnimation(a Animation) error {
72
72
return err
73
73
}
74
74
75
+ // PlayImageUntil draws the given image until is notified to stop
76
+ func (tk * ToolKit ) PlayImageUntil (i image.Image , notify <- chan time.Time ) error {
77
+ defer func () {
78
+ <- notify
79
+ }()
80
+
81
+ if tk .Transform != nil {
82
+ i = tk .Transform (i )
83
+ }
84
+
85
+ draw .Draw (tk .Canvas , tk .Canvas .Bounds (), i , image .ZP , draw .Over )
86
+ return tk .Canvas .Render ()
87
+ }
88
+
75
89
// PlayImages draws a sequence of images during the given delays, the len of
76
90
// images should be equal to the len of delay. If loop is true the function
77
91
// loops over images until a true is sent to the returned chan
0 commit comments