ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/server/ext/widget.ext
(Generate patch)

Comparing deliantra/server/ext/widget.ext (file contents):
Revision 1.10 by root, Sat Jul 21 15:04:36 2007 UTC vs.
Revision 1.13 by root, Mon Jul 23 21:02:50 2007 UTC

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
15our $DEBUG = 1;
16
15cf::client->attach ( 17cf::client->attach (
16 on_connect => sub { 18 on_connect => sub {
17 my ($ns) = @_; 19 my ($ns) = @_;
18 20
19 Scalar::Util::weaken (my $weakns = $ns); 21 Scalar::Util::weaken (my $weakns = $ns);
30 my ($ns) = @_; 32 my ($ns) = @_;
31 33
32 while (my ($k, $v) = each %{ $ns->{csc}{stat} }) { 34 while (my ($k, $v) = each %{ $ns->{csc}{stat} }) {
33 $v->set_text ($ns->pl->ob->stats->$k); 35 $v->set_text ($ns->pl->ob->stats->$k);
34 } 36 }
35}
36
37sub 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} 37}
64 38
65sub csc_start { 39sub csc_start {
66 my ($ns) = @_; 40 my ($ns) = @_;
67 41
118 return unless $cf::CFG{devel}; 92 return unless $cf::CFG{devel};
119 93
120 my $ns = $pl->ns; 94 my $ns = $pl->ns;
121 95
122 return unless $ns->{can_widget}; 96 return unless $ns->{can_widget};
123
124 demo_map $ns;
125 #csc_start $ns; 97 #csc_start $ns;
126 }, 98 },
127); 99);
128 100
129cf::register_exticmd w_e => sub { 101cf::register_exticmd w_e => sub {
155 my $id = ++$self->{id}; 127 my $id = ++$self->{id};
156 128
157 my $ws = bless { 129 my $ws = bless {
158 id => $id, 130 id => $id,
159 ns => $self, 131 ns => $self,
160 w => {}, 132 _w => {},
161 }, "ext::widget::set"; 133 }, "ext::widget::set";
162 134
163 $ws->msg (ws_n => id => $id); 135 $ws->msg (ws_n => id => $id);
164 136
165 $ws 137 $ws
185sub msg { 157sub msg {
186 my ($self, $type, %msg) = @_; 158 my ($self, $type, %msg) = @_;
187 159
188 if (my $ns = shift->{ns}) { 160 if (my $ns = shift->{ns}) {
189 $msg{msgtype} = $type; 161 $msg{msgtype} = $type;
162 warn "msg " . $ns->{json_coder}->encode (\%msg) if $DEBUG;#d#
190 $ns->send_packet ("ext " . $ns->{json_coder}->encode (\%msg)); 163 $ns->send_packet ("ext " . $ns->{json_coder}->encode (\%msg));
191 } 164 }
192} 165}
193 166
194sub new { 167sub new {
195 my ($self, $class, %args) = @_; 168 my ($self, $class, %args) = @_;
196 169
197 my $id = ++$self->{ns}{id}; 170 my $id = ++$self->{ns}{id};
198 171
199 my $proxy = $self->{w}{$id} = bless { 172 my $proxy = bless {
200 id => $id, 173 id => $id,
201 }, "ext::widget::proxy"; 174 }, "ext::widget::proxy";
202 175
176 Scalar::Util::weaken ($self->{_w}{$id} = $proxy);
203 Scalar::Util::weaken ($proxy->{ws} = $self); 177 Scalar::Util::weaken ($proxy->{ws} = $self);
204 Scalar::Util::weaken ($proxy->{ns} = $self->{ns}); 178 Scalar::Util::weaken ($proxy->{ns} = $self->{ns});
205 Scalar::Util::weaken ($self->{ns}{widget}{$id} = $proxy); 179 Scalar::Util::weaken ($self->{ns}{widget}{$id} = $proxy);
206 180
207 for my $ev (grep /^on_/, keys %args) { 181 for my $ev (grep /^on_/, keys %args) {
208 push @{$proxy->{ev}{$ev}}, $args{$ev}; 182 push @{$proxy->{ev}{$ev}}, $args{$ev};
209 $args{$ev} = 0; 183 $args{$ev} = 0;
210 } 184 }
211 185
212 $self->msg (ws_c => 186 $self->msg (ws_c =>
213 ws => $self->{w}{id}, 187 ws => $proxy->{id},
214 id => $id, 188 id => $id,
215 class => $class, 189 class => $class,
216 args => \%args, 190 args => \%args,
217 ); 191 );
218 192
227 my ($self) = @_; 201 my ($self) = @_;
228 202
229 delete $self->{ns}{widget}{$self->{id}}; 203 delete $self->{ns}{widget}{$self->{id}};
230 204
231 if (my $ws = $self->{ws}) { 205 if (my $ws = $self->{ws}) {
232 delete $ws->{w}{$self->{id}};
233 $self->msg (w_c => name => "destroy"); 206 $self->msg (w_c => name => "destroy");
207 delete $ws->{_w}{$self->{id}};
234 } 208 }
235} 209}
236 210
237sub msg { 211sub msg {
238 my ($self, $type, %msg) = @_; 212 my ($self, $type, %msg) = @_;
273 247
274 () 248 ()
275} 249}
276 250
277sub set { 251sub set {
278 my ($self, $member, $value) = @_; 252 my ($self, @kv) = @_;
279 253
280 $self->msg (w_s => attr => [ [$member, $value] ]); 254 $self->msg (w_s => attr => \@kv);
281} 255}
282 256
283sub get { 257sub get {
284 my ($self, $member, $cb) = @_; 258 my ($self, $member, $cb) = @_;
285 259

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines