ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/Deliantra-Client/DC/UI.pm
(Generate patch)

Comparing deliantra/Deliantra-Client/DC/UI.pm (file contents):
Revision 1.246 by root, Sun May 28 00:40:51 2006 UTC vs.
Revision 1.250 by root, Sun May 28 02:31:03 2006 UTC

221 } 221 }
222 222
223 $self 223 $self
224} 224}
225 225
226sub toggle_visibility {
227 my ($self) = @_;
228
229 if ($self->{visible}) {
230 $self->hide;
231 } else {
232 $self->show;
233 }
234}
235
236sub destroy { 226sub destroy {
237 my ($self) = @_; 227 my ($self) = @_;
238 228
239 $self->hide; 229 $self->hide;
240 %$self = (); 230 %$self = ();
241} 231}
242 232
243sub show { 233sub show {
244 my ($self) = @_; 234 my ($self) = @_;
235
245 return if $self->{parent}; 236 return if $self->{parent};
246 237
247 $CFClient::UI::ROOT->add ($self); 238 $CFClient::UI::ROOT->add ($self);
248} 239}
249 240
250sub show_centered { 241sub center {
251 my ($self) = @_; 242 my ($self) = @_;
252 return if $self->{parent};
253
254 $self->show;
255 243
256 $CFClient::UI::ROOT->on_post_alloc ( 244 $CFClient::UI::ROOT->on_post_alloc (
257 "centered $self" => sub { 245 "center_$self" => sub {
258 $self->move (($::WIDTH - $self->{w}) * 0.5, ($::HEIGHT - $self->{h}) * 0.5); 246 $self->move (($self->{parent}{w} - $self->{w}) * 0.5, ($self->{parent}{h} - $self->{h}) * 0.5);
259 }, 247 },
260 ); 248 );
249
250 $self->update;
261} 251}
262 252
263sub set_visible { 253sub set_visible {
264 my ($self) = @_; 254 my ($self) = @_;
265 255
266 return if $self->{visible}; 256 return if $self->{visible};
267 257
268 $self->{root} = $self->{parent}{root}; 258 $self->{root} = $self->{parent}{root};
269 $self->{visible} = $self->{parent}{visible} + 1; 259 $self->{visible} = $self->{parent}{visible} + 1;
270 260
271 $self->emit (visibility_change => 1) 261 $self->emit (visibility_change => 1);
272} 262}
273 263
274sub set_invisible { 264sub set_invisible {
275 my ($self) = @_; 265 my ($self) = @_;
276 266
288 if $CFClient::UI::TOOLTIP->{owner} == $self; 278 if $CFClient::UI::TOOLTIP->{owner} == $self;
289 279
290 $self->focus_out; 280 $self->focus_out;
291 281
292 $self->emit (visibility_change => 0); 282 $self->emit (visibility_change => 0);
283}
284
285sub set_visibility {
286 my ($self, $visible) = @_;
287
288 return if $self->{visible} == $visible;
289
290 $visible ? $self->hide
291 : $self->show;
292}
293
294sub toggle_visibility {
295 my ($self) = @_;
296
297 $self->{visible}
298 ? $self->hide
299 : $self->show;
293} 300}
294 301
295sub hide { 302sub hide {
296 my ($self) = @_; 303 my ($self) = @_;
297 304
345 $self->{y} = $y; 352 $self->{y} = $y;
346 $self->update; 353 $self->update;
347 } 354 }
348 355
349 if ($self->{w} != $w || $self->{h} != $h) { 356 if ($self->{w} != $w || $self->{h} != $h) {
350 $CFClient::UI::ROOT->{size_alloc}{$self} = [$self, $w, $h]; 357 $CFClient::UI::ROOT->{size_alloc}{$self+0} = [$self, $w, $h];
351 } 358 }
352} 359}
353 360
354sub size_allocate { 361sub size_allocate {
355 # nothing to be done 362 # nothing to be done
509sub set_parent { 516sub set_parent {
510 my ($self, $parent) = @_; 517 my ($self, $parent) = @_;
511 518
512 Scalar::Util::weaken ($self->{parent} = $parent); 519 Scalar::Util::weaken ($self->{parent} = $parent);
513 520
514 $self->set_visible; 521 $self->set_visible; #TODO why breakssssss borked damn if $parent->{visible};
515 522
516 $self->check_size; 523 $self->check_size;
517 $self->show;
518} 524}
519 525
520sub check_size { 526sub check_size {
521 my ($self, $forced) = @_; 527 my ($self, $forced) = @_;
522 528
835} 841}
836 842
837sub size_request { 843sub size_request {
838 my ($self) = @_; 844 my ($self) = @_;
839 845
840 @$self{qw(child_w child_h)} = @{$self->child}{qw(req_w req_h)}; 846 my ($w, $h) = @$self{qw(child_w child_h)} = @{$self->child}{qw(req_w req_h)};
841 847
842 @$self{qw(child_w child_h)} 848 $w = 10 if $self->{scroll_x};
849 $h = 10 if $self->{scroll_y};
850
851 ($w, $h)
843} 852}
844 853
845sub size_allocate { 854sub size_allocate {
846 my ($self, $w, $h) = @_; 855 my ($self, $w, $h) = @_;
847 856
1324 my ($self, $w, $h) = @_; 1333 my ($self, $w, $h) = @_;
1325 1334
1326 my $space = $self->{vertical} ? $h : $w; 1335 my $space = $self->{vertical} ? $h : $w;
1327 my $children = $self->{children}; 1336 my $children = $self->{children};
1328 1337
1329 my @req = map $_->{$self->{vertical} ? "req_h" : "req_w"}, @$children; 1338 my @req;
1330 my $req = List::Util::sum @req;
1331 1339
1332 if ($req > $space) { 1340 if ($self->{homogeneous}) {
1333 # ah well, not enough space 1341 @req = ($space / (@$children || 1)) x @$children;
1334 $_ *= $space / $req for @req;
1335 } else { 1342 } else {
1343 @req = map $_->{$self->{vertical} ? "req_h" : "req_w"}, @$children;
1344 my $req = List::Util::sum @req;
1345
1346 if ($req > $space) {
1347 # ah well, not enough space
1348 $_ *= $space / $req for @req;
1349 } else {
1336 my $expand = (List::Util::sum map $_->{expand}, @$children) || 1; 1350 my $expand = (List::Util::sum map $_->{expand}, @$children) || 1;
1337 1351
1352 $space = ($space - $req) / $expand; # remaining space to give away
1353
1338 $req[$_] += ($space - $req) * $children->[$_]{expand} / $expand 1354 $req[$_] += $space * $children->[$_]{expand}
1339 for 0 .. $#$children; 1355 for 0 .. $#$children;
1356 }
1340 } 1357 }
1341 1358
1342 CFClient::UI::harmonize \@req; 1359 CFClient::UI::harmonize \@req;
1343 1360
1344 my $pos = 0; 1361 my $pos = 0;
2998 if exists $child->{req_x}; 3015 if exists $child->{req_x};
2999 3016
3000 $Y = $child->{req_y} > 0 ? $child->{req_y} : $h - $H - $child->{req_y} + 1 3017 $Y = $child->{req_y} > 0 ? $child->{req_y} : $h - $H - $child->{req_y} + 1
3001 if exists $child->{req_y}; 3018 if exists $child->{req_y};
3002 3019
3003 delete @$child{qw(req_x req_y)}; 3020 #delete @$child{qw(req_x req_y)};#d# def_x, def_y
3004 3021
3005 $X = List::Util::max 0, List::Util::min $w - $W, int $X + 0.5; 3022 $X = List::Util::max 0, List::Util::min $w - $W, int $X + 0.5;
3006 $Y = List::Util::max 0, List::Util::min $h - $H, int $Y + 0.5; 3023 $Y = List::Util::max 0, List::Util::min $h - $H, int $Y + 0.5;
3007 3024
3008 $child->configure ($X, $Y, $W, $H); 3025 $child->configure ($X, $Y, $W, $H);
3081 } 3098 }
3082 3099
3083 if ($self->{check_size}) { 3100 if ($self->{check_size}) {
3084 my @queue; 3101 my @queue;
3085 3102
3086 for (;;) { 3103 while () {
3087 if ($self->{check_size}) { 3104 if ($self->{check_size}) {
3088 #TODO use array-of-depth approach 3105 #TODO use array-of-depth approach
3089 3106
3090 @queue = sort { $a->{visible} <=> $b->{visible} } 3107 @queue = sort { $a->{visible} <=> $b->{visible} }
3091 @queue, values %{delete $self->{check_size}}; 3108 @queue, values %{delete $self->{check_size}};
3112 if $widget->{parent}; 3129 if $widget->{parent};
3113 } 3130 }
3114 } 3131 }
3115 } 3132 }
3116 3133
3117 while ($self->{size_alloc}) { 3134 while (my $size_alloc = delete $self->{size_alloc}) {
3118 for (values %{delete $self->{size_alloc}}) { 3135 my @queue = sort $b->[0]{visible} <=> $a->[0]{visible},
3119 my ($widget, $w, $h) = @$_; 3136 values %$size_alloc;
3137
3138 while () {
3139 my ($widget, $w, $h) = @{ pop @queue or last };
3120 3140
3121 $w = 0 if $w < 0; 3141 $w = 0 if $w < 0;
3122 $h = 0 if $h < 0; 3142 $h = 0 if $h < 0;
3123 3143
3124 $widget->{w} = $w; 3144 $widget->{w} = $w;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines