… | |
… | |
3 | # sends the following ext message types |
3 | # sends the following ext message types |
4 | # ws_n id # widgetset new |
4 | # ws_n id # widgetset new |
5 | # ws_d id # widgetset destroy |
5 | # ws_d id # widgetset destroy |
6 | # ws_c ws id class args # widgetset create |
6 | # ws_c ws id class args # widgetset create |
7 | # w_c id [rid] name args # widget method call |
7 | # w_c id [rid] name args # widget method call |
8 | # w_s id name value # widget member set |
8 | # w_s id @attr # widget member set |
9 | # w_g id rid name # widget member get |
9 | # w_g id rid @attr # widget member get |
10 | # |
10 | # |
11 | # and expects the following exti message types |
11 | # and expects the following exti message types |
12 | # w_r rid res # widget call return |
12 | # w_r rid res # widget call return |
13 | # w_e id name args # widget_event |
13 | # w_e id name args # widget_event |
14 | |
14 | |
… | |
… | |
30 | my ($ns) = @_; |
30 | my ($ns) = @_; |
31 | |
31 | |
32 | while (my ($k, $v) = each %{ $ns->{csc}{stat} }) { |
32 | while (my ($k, $v) = each %{ $ns->{csc}{stat} }) { |
33 | $v->set_text ($ns->pl->ob->stats->$k); |
33 | $v->set_text ($ns->pl->ob->stats->$k); |
34 | } |
34 | } |
35 | } |
|
|
36 | |
|
|
37 | sub demo_map { |
|
|
38 | my ($ns) = @_; |
|
|
39 | |
|
|
40 | my $ws = $ns->{csc} = $ns->new_widgetset; |
|
|
41 | |
|
|
42 | my $w = $ws->new (Toplevel => |
|
|
43 | w => 200, |
|
|
44 | h => 200, |
|
|
45 | x => "center", |
|
|
46 | y => "center", |
|
|
47 | title => "Worldmap", |
|
|
48 | has_close_button => 1, |
|
|
49 | on_delete => sub { |
|
|
50 | $ws->destroy; |
|
|
51 | }, |
|
|
52 | ); |
|
|
53 | |
|
|
54 | my $face = cf::face::find "res/worldmap.jpg"; |
|
|
55 | $ns->send_face ($face); |
|
|
56 | |
|
|
57 | $w->add (my $sw = $ws->new (ScrolledWindow => scroll_x => 1, scroll_y => 1)); |
|
|
58 | $sw->add (my $fixed = $ws->new (Fixed => expand => 1)); |
|
|
59 | $fixed->add ($ws->new (Face => expand => 1, size_w => undef, size_h => undef, face => $face), abs => 0, 0, rel => 1, 1); |
|
|
60 | $fixed->add ($ws->new (Label => text => "lb1"), abs => 10, 10, rel => 1, 1); |
|
|
61 | |
|
|
62 | $w->show; |
|
|
63 | } |
35 | } |
64 | |
36 | |
65 | sub csc_start { |
37 | sub csc_start { |
66 | my ($ns) = @_; |
38 | my ($ns) = @_; |
67 | |
39 | |
… | |
… | |
118 | return unless $cf::CFG{devel}; |
90 | return unless $cf::CFG{devel}; |
119 | |
91 | |
120 | my $ns = $pl->ns; |
92 | my $ns = $pl->ns; |
121 | |
93 | |
122 | return unless $ns->{can_widget}; |
94 | return unless $ns->{can_widget}; |
123 | |
|
|
124 | demo_map $ns; |
|
|
125 | #csc_start $ns; |
95 | #csc_start $ns; |
126 | }, |
96 | }, |
127 | ); |
97 | ); |
128 | |
98 | |
129 | cf::register_exticmd w_e => sub { |
99 | cf::register_exticmd w_e => sub { |
… | |
… | |
155 | my $id = ++$self->{id}; |
125 | my $id = ++$self->{id}; |
156 | |
126 | |
157 | my $ws = bless { |
127 | my $ws = bless { |
158 | id => $id, |
128 | id => $id, |
159 | ns => $self, |
129 | ns => $self, |
160 | w => {}, |
130 | _w => {}, |
161 | }, "ext::widget::set"; |
131 | }, "ext::widget::set"; |
162 | |
132 | |
163 | $ws->msg (ws_n => id => $id); |
133 | $ws->msg (ws_n => id => $id); |
164 | |
134 | |
165 | $ws |
135 | $ws |
… | |
… | |
194 | sub new { |
164 | sub new { |
195 | my ($self, $class, %args) = @_; |
165 | my ($self, $class, %args) = @_; |
196 | |
166 | |
197 | my $id = ++$self->{ns}{id}; |
167 | my $id = ++$self->{ns}{id}; |
198 | |
168 | |
199 | my $proxy = $self->{w}{$id} = bless { |
169 | my $proxy = $self->{_w}{$id} = bless { |
200 | id => $id, |
170 | id => $id, |
201 | }, "ext::widget::proxy"; |
171 | }, "ext::widget::proxy"; |
202 | |
172 | |
203 | Scalar::Util::weaken ($proxy->{ws} = $self); |
173 | Scalar::Util::weaken ($proxy->{ws} = $self); |
204 | Scalar::Util::weaken ($proxy->{ns} = $self->{ns}); |
174 | Scalar::Util::weaken ($proxy->{ns} = $self->{ns}); |
… | |
… | |
208 | push @{$proxy->{ev}{$ev}}, $args{$ev}; |
178 | push @{$proxy->{ev}{$ev}}, $args{$ev}; |
209 | $args{$ev} = 0; |
179 | $args{$ev} = 0; |
210 | } |
180 | } |
211 | |
181 | |
212 | $self->msg (ws_c => |
182 | $self->msg (ws_c => |
213 | ws => $self->{w}{id}, |
183 | ws => $proxy->{id}, |
214 | id => $id, |
184 | id => $id, |
215 | class => $class, |
185 | class => $class, |
216 | args => \%args, |
186 | args => \%args, |
217 | ); |
187 | ); |
218 | |
188 | |
… | |
… | |
226 | sub DESTROY { |
196 | sub DESTROY { |
227 | my ($self) = @_; |
197 | my ($self) = @_; |
228 | |
198 | |
229 | delete $self->{ns}{widget}{$self->{id}}; |
199 | delete $self->{ns}{widget}{$self->{id}}; |
230 | |
200 | |
|
|
201 | #warn "DES<$self> $self->{ws}\n";#d# |
231 | if (my $ws = $self->{ws}) { |
202 | if (my $ws = $self->{ws}) { |
232 | delete $ws->{w}{$self->{id}}; |
|
|
233 | $self->msg (w_c => name => "destroy"); |
203 | $self->msg (w_c => name => "destroy"); |
|
|
204 | delete $ws->{_w}{$self->{id}}; |
234 | } |
205 | } |
235 | } |
206 | } |
236 | |
207 | |
237 | sub msg { |
208 | sub msg { |
238 | my ($self, $type, %msg) = @_; |
209 | my ($self, $type, %msg) = @_; |
… | |
… | |
273 | |
244 | |
274 | () |
245 | () |
275 | } |
246 | } |
276 | |
247 | |
277 | sub set { |
248 | sub set { |
278 | my ($self, $member, $value) = @_; |
249 | my ($self, @kv) = @_; |
279 | |
250 | |
280 | $self->msg (w_s => name => $member, value => $value); |
251 | $self->msg (w_s => attr => \@kv); |
281 | } |
252 | } |
282 | |
253 | |
283 | sub get { |
254 | sub get { |
284 | my ($self, $member, $cb) = @_; |
255 | my ($self, $member, $cb) = @_; |
285 | |
256 | |
286 | $self->msg_cb ($cb, w_g => name => $member); |
257 | $self->msg_cb ($cb, w_g => attr => [$member]); |
287 | } |
258 | } |
288 | |
259 | |
289 | sub TO_JSON { |
260 | sub TO_JSON { |
290 | { __widget_ref__ => $_[0]{id} } |
261 | { __widget_ref__ => $_[0]{id} } |
291 | } |
262 | } |