… | |
… | |
17 | |
17 | |
18 | cf::client->attach ( |
18 | cf::client->attach ( |
19 | on_connect => sub { |
19 | on_connect => sub { |
20 | my ($ns) = @_; |
20 | my ($ns) = @_; |
21 | |
21 | |
22 | Scalar::Util::weaken (my $weakns = $ns); |
|
|
23 | |
|
|
24 | $ns->{id} = "a"; |
22 | $ns->{id} = "a"; |
25 | $ns->{json_coder}->filter_json_single_key_object ("\fw" => sub { |
23 | $ns->{json_coder}->filter_json_single_key_object ("\fw" => sub { |
26 | $weakns->{widget}{$_[0]} |
24 | $ns->{widget}{$_[0]} |
27 | }); |
25 | }); |
|
|
26 | |
|
|
27 | cf::weaken $ns; |
28 | }, |
28 | }, |
29 | ); |
29 | ); |
30 | |
30 | |
31 | sub csc_update_stats { |
31 | sub csc_update_stats { |
32 | my ($ns) = @_; |
32 | my ($ns) = @_; |
… | |
… | |
96 | }, |
96 | }, |
97 | ] |
97 | ] |
98 | EOF |
98 | EOF |
99 | die if $@; |
99 | die if $@; |
100 | |
100 | |
101 | sub demo_start { |
|
|
102 | my ($ns) = @_; |
|
|
103 | |
|
|
104 | my $ws = $ns->{csc} = $ns->new_widgetset; |
|
|
105 | |
|
|
106 | my ($tl, $entry) = $ws->template (inline => $cg_template, |
|
|
107 | [ |
|
|
108 | toplevel => {}, |
|
|
109 | entry => { |
|
|
110 | text => "xyz", |
|
|
111 | on_changed => sub { |
|
|
112 | warn "changed<@_>\n";#d# |
|
|
113 | }, |
|
|
114 | }, |
|
|
115 | ], |
|
|
116 | ); |
|
|
117 | |
|
|
118 | $tl->show; |
|
|
119 | |
|
|
120 | $ns->{xxxw} = [$tl, $entry];#d# |
|
|
121 | |
|
|
122 | # $ws->find ("setup_notebook")->add ($ws->{tab}); |
|
|
123 | # $ws->find ("setup_dialog")->toggle_visibility; |
|
|
124 | } |
|
|
125 | |
|
|
126 | sub csc_start { |
101 | sub csc_start { |
127 | my ($ns) = @_; |
102 | my ($ns) = @_; |
128 | |
103 | |
129 | my $ws = $ns->{csc} = $ns->new_widgetset; |
104 | my $ws = $ns->{csc} = $ns->new_widgetset; |
130 | |
105 | |
… | |
… | |
169 | |
144 | |
170 | csc_update_stats $ns; |
145 | csc_update_stats $ns; |
171 | |
146 | |
172 | $ws->{tl} = $w; |
147 | $ws->{tl} = $w; |
173 | $w->show; |
148 | $w->show; |
|
|
149 | |
|
|
150 | # my ($tl, $entry) = $ws->template (inline => $cg_template, |
|
|
151 | # [ |
|
|
152 | # toplevel => {}, |
|
|
153 | # entry => { |
|
|
154 | # text => "xyz", |
|
|
155 | # on_changed => sub { |
|
|
156 | # warn "changed<@_>\n";#d# |
|
|
157 | # }, |
|
|
158 | # }, |
|
|
159 | # ], |
|
|
160 | # ); |
|
|
161 | # |
|
|
162 | # $tl->show; |
|
|
163 | # |
|
|
164 | # $ns->{xxxw} = [$tl, $entry];#d# |
|
|
165 | # |
|
|
166 | # $ws->find ("setup_notebook")->add ($ws->{tab}); |
|
|
167 | # $ws->find ("setup_dialog")->toggle_visibility; |
174 | } |
168 | } |
175 | |
169 | |
176 | cf::player->attach ( |
170 | cf::player->attach ( |
177 | on_login => sub { |
171 | on_login => sub { |
178 | my ($pl) = @_; |
172 | my ($pl) = @_; |
179 | |
173 | |
|
|
174 | my $ns = $pl->ns; |
|
|
175 | return unless $ns->{can_widget}; |
|
|
176 | |
180 | return unless $cf::CFG{devel}; |
177 | return unless $cf::CFG{devel}; |
181 | |
178 | |
182 | my $ns = $pl->ns; |
|
|
183 | |
|
|
184 | return unless $ns->{can_widget}; |
|
|
185 | #csc_start $ns; |
179 | #csc_start $ns; |
186 | demo_start $ns; |
|
|
187 | }, |
180 | }, |
188 | ); |
181 | ); |
189 | |
182 | |
190 | cf::register_exticmd w_e => sub { |
183 | cf::register_exticmd w_e => sub { |
191 | my ($ns, $id, @args) = @_; |
184 | my ($ns, $id, @args) = @_; |
… | |
… | |
206 | id => $id, |
199 | id => $id, |
207 | ns => $self, |
200 | ns => $self, |
208 | _w => {}, |
201 | _w => {}, |
209 | }, "ext::widget::set"; |
202 | }, "ext::widget::set"; |
210 | |
203 | |
|
|
204 | cf::weaken $ws->{ns}; |
|
|
205 | |
211 | $ws->msg (ws_n => $id); |
206 | $ws->msg (ws_n => $id); |
212 | |
207 | |
213 | $ws |
208 | $ws |
214 | } |
209 | } |
215 | |
210 | |
… | |
… | |
266 | sub new { |
261 | sub new { |
267 | my ($self, $class, %args) = @_; |
262 | my ($self, $class, %args) = @_; |
268 | |
263 | |
269 | my $proxy = $self->alloc; |
264 | my $proxy = $self->alloc; |
270 | |
265 | |
271 | Scalar::Util::weaken ($self->{_w}{$proxy->{id}} = $proxy); |
266 | cf::weaken |
272 | Scalar::Util::weaken ($proxy->{ws} = $self); |
267 | +($self->{_w}{$proxy->{id}} = $proxy), |
|
|
268 | +($proxy->{ws} = $self); |
273 | |
269 | |
274 | for my $ev (grep /^on_/, keys %args) { |
270 | for my $ev (grep /^on_/, keys %args) { |
275 | $args{$ev} = $proxy->{"_$ev"} = $proxy->cb ($args{$ev}); |
271 | $args{$ev} = $proxy->{"_$ev"} = $proxy->cb ($args{$ev}); |
276 | } |
272 | } |
277 | |
273 | |
… | |
… | |
287 | |
283 | |
288 | sub template { |
284 | sub template { |
289 | my ($self, $type, $template, $args, $done_cb) = @_; |
285 | my ($self, $type, $template, $args, $done_cb) = @_; |
290 | |
286 | |
291 | my %cfg; |
287 | my %cfg; |
292 | my @res; |
|
|
293 | |
288 | |
294 | while (@$args) { |
289 | while (@$args) { |
295 | my ($name, $args) = splice @$args, 0, 2, (); |
290 | my ($name, $args) = splice @$args, 0, 2, (); |
296 | |
291 | |
297 | my $proxy = $self->alloc; |
292 | my $proxy = $self->alloc; |
298 | |
293 | |
|
|
294 | $self->{delete $args->{alias} or $name} = $proxy; |
|
|
295 | |
|
|
296 | cf::weaken |
299 | Scalar::Util::weaken ($self->{_w}{$proxy->{id}} = $proxy); |
297 | +($self->{_w}{$proxy->{id}} = $proxy), |
300 | Scalar::Util::weaken ($proxy->{ws} = $self); |
298 | +($proxy->{ws} = $self); |
301 | |
299 | |
302 | for my $ev (grep /^on_/, keys %$args) { |
300 | for my $ev (grep /^on_/, keys %$args) { |
303 | $args->{$ev} = $proxy->{"_$ev"} = $proxy->cb ($args->{$ev}); |
301 | $args->{$ev} = $proxy->{"_$ev"} = $proxy->cb ($args->{$ev}); |
304 | } |
302 | } |
305 | |
303 | |
306 | $cfg{$name} = { |
304 | $cfg{$name} = { |
307 | %$args, |
305 | %$args, |
308 | id => $proxy->{id}, |
306 | id => $proxy->{id}, |
309 | }; |
307 | }; |
310 | |
|
|
311 | push @res, $proxy; |
|
|
312 | } |
308 | } |
313 | |
309 | |
314 | if ($done_cb) { |
310 | if ($done_cb) { |
315 | my $proxy = $self->alloc; |
311 | my $proxy = $self->alloc; |
316 | my $ocb = $done_cb; |
312 | my $ocb = $done_cb; |
… | |
… | |
319 | undef $done_cb; |
315 | undef $done_cb; |
320 | &$ocb |
316 | &$ocb |
321 | }); |
317 | }); |
322 | } |
318 | } |
323 | |
319 | |
|
|
320 | if ($type eq "face") { |
|
|
321 | $self->{ns}->send_face ($template, 100); |
|
|
322 | $self->{ns}->flush_fx; |
|
|
323 | } |
|
|
324 | |
324 | $self->msg (ws_ct => |
325 | $self->msg (ws_ct => |
325 | $self->{id}, |
326 | $self->{id}, |
326 | $type => $template, |
327 | $type => $template, |
327 | $done_cb, |
328 | $done_cb, |
328 | \%cfg, |
329 | \%cfg, |
329 | ); |
330 | ); |
330 | |
|
|
331 | @res |
|
|
332 | } |
331 | } |
333 | |
332 | |
334 | sub find { |
333 | sub find { |
335 | my ($self, @names) = @_; |
334 | my ($self, @names) = @_; |
336 | |
335 | |
… | |
… | |
354 | } |
353 | } |
355 | |
354 | |
356 | ############################################################################# |
355 | ############################################################################# |
357 | |
356 | |
358 | package ext::widget::proxy; |
357 | package ext::widget::proxy; |
359 | |
|
|
360 | sub DESTROY { |
|
|
361 | my ($self) = @_; |
|
|
362 | |
|
|
363 | delete $self->{ns}{widget}{$self->{id}}; |
|
|
364 | |
|
|
365 | if (my $ws = $self->{ws}) { |
|
|
366 | $self->msg (w_c => 0, "destroy"); |
|
|
367 | delete $ws->{_w}{$self->{id}}; |
|
|
368 | } |
|
|
369 | } |
|
|
370 | |
|
|
371 | sub cb { |
|
|
372 | my ($self, $cb) = @_; |
|
|
373 | |
|
|
374 | my $proxy = bless { |
|
|
375 | ns => $self->{ns}, |
|
|
376 | id => $self->{ns}->alloc_wid, |
|
|
377 | }, "ext::widget::callback"; |
|
|
378 | |
|
|
379 | Scalar::Util::weaken $proxy->{ns}; |
|
|
380 | |
|
|
381 | $self->{ns}{widget_cb}{$proxy->{id}} = $cb; |
|
|
382 | |
|
|
383 | $proxy |
|
|
384 | } |
|
|
385 | |
|
|
386 | sub oneshot_cb { |
|
|
387 | my ($self, $cb) = @_; |
|
|
388 | |
|
|
389 | if ("CODE" eq ref $cb) { |
|
|
390 | my $ocb = $cb; |
|
|
391 | $cb = $self->cb (sub { |
|
|
392 | undef $cb; |
|
|
393 | &$ocb |
|
|
394 | }); |
|
|
395 | } |
|
|
396 | |
|
|
397 | $cb |
|
|
398 | } |
|
|
399 | |
358 | |
400 | sub msg { |
359 | sub msg { |
401 | my ($self, $type, @arg) = @_; |
360 | my ($self, $type, @arg) = @_; |
402 | |
361 | |
403 | if (my $ns = $self->{ns}) { |
362 | if (my $ns = $self->{ns}) { |
… | |
… | |
441 | } |
400 | } |
442 | |
401 | |
443 | () |
402 | () |
444 | } |
403 | } |
445 | |
404 | |
|
|
405 | sub DESTROY { |
|
|
406 | my ($self) = @_; |
|
|
407 | |
|
|
408 | delete $self->{ns}{widget}{$self->{id}}; |
|
|
409 | |
|
|
410 | if (my $ws = $self->{ws}) { |
|
|
411 | $self->msg (w_c => 0, "destroy"); |
|
|
412 | delete $ws->{_w}{$self->{id}}; |
|
|
413 | } |
|
|
414 | } |
|
|
415 | |
|
|
416 | sub cb { |
|
|
417 | my ($self, $cb) = @_; |
|
|
418 | |
|
|
419 | my $proxy = bless { |
|
|
420 | ns => $self->{ns}, |
|
|
421 | id => $self->{ns}->alloc_wid, |
|
|
422 | }, "ext::widget::callback"; |
|
|
423 | |
|
|
424 | cf::weaken $proxy->{ns}; |
|
|
425 | |
|
|
426 | $self->{ns}{widget_cb}{$proxy->{id}} = $cb; |
|
|
427 | |
|
|
428 | $proxy |
|
|
429 | } |
|
|
430 | |
|
|
431 | sub oneshot_cb { |
|
|
432 | my ($self, $cb) = @_; |
|
|
433 | |
|
|
434 | if ("CODE" eq ref $cb) { |
|
|
435 | my $ocb = $cb; |
|
|
436 | $cb = cb $self, sub { |
|
|
437 | undef $cb; |
|
|
438 | &$ocb |
|
|
439 | }; |
|
|
440 | } |
|
|
441 | |
|
|
442 | $cb |
|
|
443 | } |
|
|
444 | |
446 | sub set { |
445 | sub set { |
447 | my ($self, @kv) = @_; |
446 | my ($self, @kv) = @_; |
448 | |
447 | |
449 | $self->msg (w_s => \@kv); |
448 | $self->msg (w_s => \@kv); |
450 | } |
449 | } |