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.188 by root, Mon May 8 21:16:09 2006 UTC vs.
Revision 1.193 by root, Wed May 10 21:12:26 2006 UTC

232 $self->{y} = $y; 232 $self->{y} = $y;
233 $self->update; 233 $self->update;
234 } 234 }
235 235
236 if ($self->{w} != $w || $self->{h} != $h) { 236 if ($self->{w} != $w || $self->{h} != $h) {
237 $self->{w} = $w; 237 $CFClient::UI::ROOT->{size_alloc}{$self} = [$self, $w, $h];
238 $self->{h} = $h;
239
240 $self->size_allocate ($w, $h);
241 $self->update;
242 $self->emit (size_allocate => $w, $h);
243 } 238 }
244} 239}
245 240
246sub size_allocate { 241sub size_allocate {
247 # nothing to be done 242 # nothing to be done
256 251
257 $_->reconfigure 252 $_->reconfigure
258 for $self->children; 253 for $self->children;
259 254
260 $self->check_size; 255 $self->check_size;
261 $self->size_allocate ($self->{w}, $self->{h}); 256 $CFClient::UI::ROOT->{size_alloc}{$self} = [$self, $self->{w}, $self->{h}];
262 $self->update; 257 $self->update;
263} 258}
264 259
265sub set_max_size { 260sub set_max_size {
266 my ($self, $w, $h) = @_; 261 my ($self, $w, $h) = @_;
267 262
268 delete $self->{max_w}; $self->{max_w} = $w if $w; 263 delete $self->{max_w}; $self->{max_w} = $w if $w;
269 delete $self->{max_h}; $self->{max_h} = $h if $h; 264 delete $self->{max_h}; $self->{max_h} = $h if $h;
270}
271
272# return top left coordinates
273sub _topleft {
274 my ($self, $x, $y) = @_;
275
276 $self->{parent}
277 or Carp::confess "no parent widget in _topleft\n";#d#
278
279 $self->{parent}->_topleft ($x + $self->{x}, $y + $self->{y});
280} 265}
281 266
282# translate global coordinates to local coordinate system 267# translate global coordinates to local coordinate system
283sub coord2local { 268sub coord2local {
284 my ($self, $x, $y) = @_; 269 my ($self, $x, $y) = @_;
285 270
286 my ($X, $Y) = $self->_topleft; 271 $self->{parent}->coord2local ($x - $self->{x}, $y - $self->{y})
287 ($x - $X, $y - $Y)
288} 272}
289 273
290# translate local coordinates to global coordinate system 274# translate local coordinates to global coordinate system
291sub coord2global { 275sub coord2global {
292 my ($self, $x, $y) = @_; 276 my ($self, $x, $y) = @_;
293 277
294 my ($X, $Y) = $self->_topleft; 278 $self->{parent}->coord2global ($x + $self->{x}, $y + $self->{y})
295 ($x + $X, $y + $Y)
296} 279}
297 280
298sub focus_in { 281sub focus_in {
299 my ($self) = @_; 282 my ($self) = @_;
300 283
398 381
399sub set_parent { 382sub set_parent {
400 my ($self, $parent) = @_; 383 my ($self, $parent) = @_;
401 384
402 Scalar::Util::weaken ($self->{parent} = $parent); 385 Scalar::Util::weaken ($self->{parent} = $parent);
386
387 $self->check_size
388 unless exists $self->{req_w};
403} 389}
404 390
405sub check_size { 391sub check_size {
406 my ($self) = @_; 392 my ($self) = @_;
407 393
408 $self->{parent} 394 $CFClient::UI::ROOT->{check_size}{$self} = $self;
409 or return 1;
410
411 my ($w, $h) = $self->{user_w} && $self->{user_h}
412 ? @$self{qw(user_w user_h)}
413 : $self->size_request;
414
415 if ($w != $self->{req_w} || $h != $self->{req_h}) {
416 $self->{req_w} = $w;
417 $self->{req_h} = $h;
418
419 $self->{parent}->check_size
420 or $self->size_allocate (
421 (List::Util::max $self->{w}, $w),
422 (List::Util::max $self->{h}, $h),
423 );
424
425 1
426 } else {
427 0
428 }
429} 395}
430 396
431sub update { 397sub update {
432 my ($self) = @_; 398 my ($self) = @_;
433 399
542 $self->{children} = [ 508 $self->{children} = [
543 sort { $a->{z} <=> $b->{z} } 509 sort { $a->{z} <=> $b->{z} }
544 @{$self->{children}}, @widgets 510 @{$self->{children}}, @widgets
545 ]; 511 ];
546 512
547 $_->check_size 513 $self->check_size;
548 for @widgets;
549
550 $self->update; 514 $self->update;
551} 515}
552 516
553sub children { 517sub children {
554 @{ $_[0]{children} } 518 @{ $_[0]{children} }
744 $self->{view_y} = int $y; 708 $self->{view_y} = int $y;
745 709
746 $self->update; 710 $self->update;
747} 711}
748 712
749# hmm, this does not work for topleft of $self... but we should not aks for that 713# hmm, this does not work for topleft of $self... but we should not ask for that
750sub _topleft { 714sub coord2local {
751 my ($self, $x, $y) = @_; 715 my ($self, $x, $y) = @_;
752 716
753 $self->SUPER::_topleft ($x - $self->{view_x}, $y - $self->{view_y}) 717 $self->SUPER::coord2local ($x + $self->{view_x}, $y + $self->{view_y})
718}
719
720sub coord2global {
721 my ($self, $x, $y) = @_;
722
723 $x = List::Util::min $self->{w}, $x - $self->{view_x};
724 $y = List::Util::min $self->{h}, $y - $self->{view_y};
725
726 $self->SUPER::coord2global ($x, $y)
754} 727}
755 728
756sub find_widget { 729sub find_widget {
757 my ($self, $x, $y) = @_; 730 my ($self, $x, $y) = @_;
758 731
1239 ) 1212 )
1240} 1213}
1241 1214
1242sub size_allocate { 1215sub size_allocate {
1243 my ($self, $w, $h) = @_; 1216 my ($self, $w, $h) = @_;
1217
1218 Carp::confess "negative size" if $w < 0 || $h < 0;#d#
1244 1219
1245 my $children = $self->{children}; 1220 my $children = $self->{children};
1246 1221
1247 my @h = map $_->{req_h}, @$children; 1222 my @h = map $_->{req_h}, @$children;
1248 1223
1335 return if $self->{text} eq "T$text"; 1310 return if $self->{text} eq "T$text";
1336 $self->{text} = "T$text"; 1311 $self->{text} = "T$text";
1337 1312
1338 $self->{layout}->set_text ($text); 1313 $self->{layout}->set_text ($text);
1339 1314
1340 delete $self->{texture};
1341 $self->update; 1315 $self->update;
1342 $self->check_size; 1316 $self->check_size;
1343} 1317}
1344 1318
1345sub set_markup { 1319sub set_markup {
1348 return if $self->{text} eq "M$markup"; 1322 return if $self->{text} eq "M$markup";
1349 $self->{text} = "M$markup"; 1323 $self->{text} = "M$markup";
1350 1324
1351 $self->{layout}->set_markup ($markup); 1325 $self->{layout}->set_markup ($markup);
1352 1326
1353 delete $self->{texture};
1354 $self->update; 1327 $self->update;
1355 $self->check_size; 1328 $self->check_size;
1356} 1329}
1357 1330
1358sub size_request { 1331sub size_request {
2510sub new { 2483sub new {
2511 my $class = shift; 2484 my $class = shift;
2512 2485
2513 my %args = @_; 2486 my %args = @_;
2514 2487
2515 my $item = $args{item}; 2488 my $item = delete $args{item};
2516 2489
2517 my $desc = $item->{nrof} < 2 2490 my $desc = $item->{nrof} < 2
2518 ? $item->{name} 2491 ? $item->{name}
2519 : "$item->{nrof} $item->{name_pl}"; 2492 : "$item->{nrof} $item->{name_pl}";
2520 2493
2549 2522
2550 1 2523 1
2551 }, 2524 },
2552 %args 2525 %args
2553 ); 2526 );
2527
2554 $self->add(new CFClient::UI::Face 2528 $self->add (new CFClient::UI::Face
2555 can_events => 0, 2529 can_events => 0,
2556 face => $item->{face}, 2530 face => $item->{face},
2557 anim => $item->{anim}, 2531 anim => $item->{anim},
2558 animspeed => $item->{animspeed}); 2532 animspeed => $item->{animspeed},
2533 );
2534
2559 $self->add(new CFClient::UI::Label 2535 $self->add (new CFClient::UI::Label
2560 can_events => 0, 2536 can_events => 0,
2561 text => $desc); 2537 text => $desc,
2538 );
2562 2539
2563 $self 2540 $self
2564} 2541}
2565 2542
2566############################################################################# 2543#############################################################################
2593 for my $item (@items) { 2570 for my $item (@items) {
2594 my $desc = $item->{nrof} < 2 2571 my $desc = $item->{nrof} < 2
2595 ? $item->{name} 2572 ? $item->{name}
2596 : "$item->{nrof} $item->{name_pl}"; 2573 : "$item->{nrof} $item->{name_pl}";
2597 2574
2598 $self->{scrolled}->add (new CFClient::UI::InventoryItem item => $item); 2575 $self->{scrolled}->add ($item->{widget} ||= new CFClient::UI::InventoryItem item => $item);
2599 } 2576 }
2600 2577
2601# $range->{range} = [$self->{pos}, 0, $self->{max_pos}, $page]; 2578# $range->{range} = [$self->{pos}, 0, $self->{max_pos}, $page];
2602} 2579}
2603 2580
2684 2661
2685our @ISA = CFClient::UI::Container::; 2662our @ISA = CFClient::UI::Container::;
2686 2663
2687use CFClient::OpenGL; 2664use CFClient::OpenGL;
2688 2665
2666sub new {
2667 my $class = shift;
2668
2669 $class->SUPER::new (
2670 @_,
2671 )
2672}
2673
2674sub configure {
2675 my ($self, $x, $y, $w, $h) = @_;
2676
2677 $self->{w} = $w;
2678 $self->{h} = $h;
2679}
2680
2689sub check_size { 2681sub check_size {
2690 my ($self) = @_; 2682 my ($self) = @_;
2691 2683
2692 $self->configure (0, 0, $self->{w}, $self->{h}); 2684 $self->size_allocate ($self->{w}, $self->{h})
2685 if $self->{w};
2693} 2686}
2694 2687
2695sub size_request { 2688sub size_request {
2696 my ($self) = @_; 2689 my ($self) = @_;
2697 2690
2715 $child->{req_h} = int 0.5 + $child->{req_h} * $h / $old_h if exists $child->{req_h}; 2708 $child->{req_h} = int 0.5 + $child->{req_h} * $h / $old_h if exists $child->{req_h};
2716 $child->{user_h} = int 0.5 + $child->{user_h} * $h / $old_h if exists $child->{user_h}; 2709 $child->{user_h} = int 0.5 + $child->{user_h} * $h / $old_h if exists $child->{user_h};
2717 } 2710 }
2718 } 2711 }
2719 2712
2720 $self->{old_w} = $w;
2721 $self->{old_h} = $h;
2722}
2723
2724sub configure {
2725 my ($self, $x, $y, $w, $h) = @_;
2726
2727 $self->SUPER::configure ($x, $y, $w, $h);
2728
2729 for my $child ($self->children) { 2713 for my $child ($self->children) {
2730 my ($X, $Y, $W, $H) = @$child{qw(x y req_w req_h)}; 2714 my ($X, $Y, $W, $H) = @$child{qw(x y req_w req_h)};
2731 2715
2732 $X = List::Util::max 0, List::Util::min $w - $W, $X; 2716 $X = List::Util::max 0, List::Util::min $w - $W, $X;
2733 $Y = List::Util::max 0, List::Util::min $h - $H, $Y; 2717 $Y = List::Util::max 0, List::Util::min $h - $H, $Y;
2734 $child->configure ($X, $Y, $W, $H); 2718 $child->configure ($X, $Y, $W, $H);
2735 } 2719 }
2736}
2737 2720
2738sub _topleft { 2721 $self->{old_w} = $w;
2722 $self->{old_h} = $h;
2723}
2724
2725sub coord2local {
2739 my ($self, $x, $y) = @_; 2726 my ($self, $x, $y) = @_;
2740 2727
2741 ($x, $y) 2728 ($x, $y)
2742} 2729}
2743 2730
2731sub coord2global {
2732 my ($self, $x, $y) = @_;
2733
2734 ($x, $y)
2735}
2736
2744sub update { 2737sub update {
2745 my ($self) = @_; 2738 my ($self) = @_;
2746 2739
2747 $self->check_size; 2740 $self->check_size;
2748 ::refresh (); 2741 $::WANT_REFRESH++;
2749} 2742}
2750 2743
2751sub add { 2744sub add {
2752 my ($self, $child) = @_; 2745 my ($self, $child) = @_;
2753 2746
2754 # integerize window positions 2747 # integerise window positions
2755 $child->{x} = int $child->{x}; 2748 $child->{x} = int $child->{x};
2756 $child->{y} = int $child->{y}; 2749 $child->{y} = int $child->{y};
2757 2750
2758 $self->SUPER::add ($child); 2751 $self->SUPER::add ($child);
2759} 2752}
2762 my ($self, $id, $cb) = @_; 2755 my ($self, $id, $cb) = @_;
2763 2756
2764 $self->{refresh_hook}{$id} = $cb; 2757 $self->{refresh_hook}{$id} = $cb;
2765} 2758}
2766 2759
2767sub draw { 2760sub draw {
2768 my ($self) = @_; 2761 my ($self) = @_;
2769 2762
2763 if ($self->{check_size}) {
2764 my @queue = ([], []);
2765
2766 for (;;) {
2767 if ($self->{check_size}) {
2768 # heuristic: check containers last
2769 push @{ $queue[ ! ! $_->isa ("CFClient::UI::Container") ] }, $_
2770 for values %{delete $self->{check_size}}
2771 }
2772
2773 my $widget = (pop @{ $queue[0] }) || (pop @{ $queue[1] }) || last;
2774
2775 my ($w, $h) = $widget->{user_w} && $widget->{user_h}
2776 ? @$widget{qw(user_w user_h)}
2777 : $widget->size_request;
2778
2779 if ($w != $widget->{req_w} || $h != $widget->{req_h}) {
2780 Carp::confess "$widget: size_request is negative" if $w < 0 || $h < 0;#d#
2781
2782 $widget->{req_w} = $w;
2783 $widget->{req_h} = $h;
2784
2785 $self->{size_alloc}{$widget} = [$widget, $widget->{w}, $widget->{h}];
2786
2787 $widget->{parent}->check_size
2788 if $widget->{parent};
2789 }
2790 }
2791 }
2792
2793 while ($self->{size_alloc}) {
2794 for (values %{delete $self->{size_alloc}}) {
2795 my ($widget, $w, $h) = @$_;
2796
2797 $w = 0 if $w < 0;
2798 $h = 0 if $h < 0;
2799
2800 $widget->{w} = $w;
2801 $widget->{h} = $h;
2802 $widget->size_allocate ($w, $h);
2803 $widget->emit (size_allocate => $w, $h);
2804 }
2805 }
2806
2770 while (my $rcb = delete $self->{refresh_hook}) { 2807 while ($self->{refresh_hook}) {
2771 $_->() for values %$rcb; 2808 $_->()
2809 for values %{delete $self->{refresh_hook}};
2772 } 2810 }
2773 2811
2774 glViewport 0, 0, $::WIDTH, $::HEIGHT; 2812 glViewport 0, 0, $::WIDTH, $::HEIGHT;
2775 glClearColor +($::CFG->{fow_intensity}) x 3, 1; 2813 glClearColor +($::CFG->{fow_intensity}) x 3, 1;
2776 glClear GL_COLOR_BUFFER_BIT; 2814 glClear GL_COLOR_BUFFER_BIT;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines