@@ -91,6 +91,7 @@ func (p *eventSink) call(wait bool, data interface{}, doSth func(*eventSink)) {
91
91
92
92
type eventSinkMgr struct {
93
93
allWhenStart * eventSink
94
+ allWhenTimer * eventSink
94
95
allWhenKeyPressed * eventSink
95
96
allWhenIReceive * eventSink
96
97
allWhenBackdropChanged * eventSink
@@ -102,10 +103,12 @@ type eventSinkMgr struct {
102
103
allWhenMoving * eventSink
103
104
allWhenTurning * eventSink
104
105
calledStart bool
106
+ calledTimer bool
105
107
}
106
108
107
109
func (p * eventSinkMgr ) reset () {
108
110
p .allWhenStart = nil
111
+ p .allWhenTimer = nil
109
112
p .allWhenKeyPressed = nil
110
113
p .allWhenIReceive = nil
111
114
p .allWhenBackdropChanged = nil
@@ -121,6 +124,7 @@ func (p *eventSinkMgr) reset() {
121
124
122
125
func (p * eventSinkMgr ) doDeleteClone (this interface {}) {
123
126
p .allWhenStart = p .allWhenStart .doDeleteClone (this )
127
+ p .allWhenTimer = p .allWhenTimer .doDeleteClone (this )
124
128
p .allWhenKeyPressed = p .allWhenKeyPressed .doDeleteClone (this )
125
129
p .allWhenIReceive = p .allWhenIReceive .doDeleteClone (this )
126
130
p .allWhenBackdropChanged = p .allWhenBackdropChanged .doDeleteClone (this )
@@ -145,6 +149,17 @@ func (p *eventSinkMgr) doWhenStart() {
145
149
}
146
150
}
147
151
152
+ func (p * eventSinkMgr ) doWhenTimer (time float64 ) {
153
+ if ! p .calledTimer {
154
+ p .allWhenTimer .asyncCall (false , time , func (ev * eventSink ) {
155
+ if ev .cond != nil && ev .cond (time ) {
156
+ ev .sink .(func (float64 ))(time )
157
+ p .calledTimer = true
158
+ }
159
+ })
160
+ }
161
+ }
162
+
148
163
func (p * eventSinkMgr ) doWhenKeyPressed (key Key ) {
149
164
p .allWhenKeyPressed .asyncCall (false , key , func (ev * eventSink ) {
150
165
ev .sink .(func (Key ))(key )
@@ -232,6 +247,7 @@ type IEventSinks interface {
232
247
OnMsg__0 (onMsg func (msg string , data interface {}))
233
248
OnMsg__1 (msg string , onMsg func ())
234
249
OnStart (onStart func ())
250
+ OnTimer (time float64 , onTimer func ())
235
251
Stop (kind StopKind )
236
252
}
237
253
@@ -274,6 +290,22 @@ func (p *eventSinks) OnStart(onStart func()) {
274
290
}
275
291
}
276
292
293
+ func (p * eventSinks ) OnTimer (time float64 , onTimer func ()) {
294
+ p .allWhenTimer = & eventSink {
295
+ prev : p .allWhenTimer ,
296
+ pthis : p .pthis ,
297
+ sink : func (float64 ) {
298
+ if debugEvent {
299
+ log .Println ("==> OnTimer" , time , nameOf (p .pthis ))
300
+ }
301
+ onTimer ()
302
+ },
303
+ cond : func (data interface {}) bool {
304
+ return data .(float64 ) >= time
305
+ },
306
+ }
307
+ }
308
+
277
309
func (p * eventSinks ) OnClick (onClick func ()) {
278
310
pthis := p .pthis
279
311
p .allWhenClick = & eventSink {
0 commit comments