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.196 by root, Fri May 12 00:16:34 2006 UTC vs.
Revision 1.203 by root, Sun May 14 21:13:11 2006 UTC

11our ($FOCUS, $HOVER, $GRAB); # various widgets 11our ($FOCUS, $HOVER, $GRAB); # various widgets
12 12
13our $ROOT; 13our $ROOT;
14our $TOOLTIP; 14our $TOOLTIP;
15our $BUTTON_STATE; 15our $BUTTON_STATE;
16
17our %WIDGET; # all widgets, weak-referenced
16 18
17sub check_tooltip { 19sub check_tooltip {
18 if (!$GRAB) { 20 if (!$GRAB) {
19 for (my $widget = $HOVER; $widget; $widget = $widget->{parent}) { 21 for (my $widget = $HOVER; $widget; $widget = $widget->{parent}) {
20 if (length $widget->{tooltip}) { 22 if (length $widget->{tooltip}) {
34 if ($x + $TOOLTIP->{w} > $::WIDTH) { 36 if ($x + $TOOLTIP->{w} > $::WIDTH) {
35 ($x, $y) = $widget->coord2global (-$TOOLTIP->{w}, 0); 37 ($x, $y) = $widget->coord2global (-$TOOLTIP->{w}, 0);
36 } 38 }
37 39
38 $TOOLTIP->move ($x, $y); 40 $TOOLTIP->move ($x, $y);
41 $TOOLTIP->check_size;
42 $TOOLTIP->update;
39 } 43 }
40 44
41 return; 45 return;
42 } 46 }
43 } 47 }
130 134
131 for (@$vals) { 135 for (@$vals) {
132 my $i = int $_ + $rem; 136 my $i = int $_ + $rem;
133 $rem += $_ - $i; 137 $rem += $_ - $i;
134 $_ = $i; 138 $_ = $i;
139 }
140}
141
142# call when resolution changes etc.
143sub rescale_widgets {
144 my ($sx, $sy) = @_;
145
146 for my $widget (values %WIDGET) {
147 if ($widget->{toplevel}) {
148 $widget->{x} = int 0.5 + $widget->{x} * $sx if exists $widget->{x};
149 $widget->{w} = int 0.5 + $widget->{w} * $sx if exists $widget->{w};
150 $widget->{req_w} = int 0.5 + $widget->{req_w} * $sx if exists $widget->{req_w};
151 $widget->{user_w} = int 0.5 + $widget->{user_w} * $sx if exists $widget->{user_w};
152 $widget->{y} = int 0.5 + $widget->{y} * $sy if exists $widget->{y};
153 $widget->{h} = int 0.5 + $widget->{h} * $sy if exists $widget->{h};
154 $widget->{req_h} = int 0.5 + $widget->{req_h} * $sy if exists $widget->{req_h};
155 $widget->{user_h} = int 0.5 + $widget->{user_h} * $sy if exists $widget->{user_h};
156 }
157
158 $widget->reconfigure;
135 } 159 }
136} 160}
137 161
138############################################################################# 162#############################################################################
139 163
158 if (/^connect_(.*)$/) { 182 if (/^connect_(.*)$/) {
159 $self->connect ($1 => delete $self->{$_}); 183 $self->connect ($1 => delete $self->{$_});
160 } 184 }
161 } 185 }
162 186
187 Scalar::Util::weaken ($CFClient::UI::WIDGET{$self+0} = $self);
188
163 $self 189 $self
164} 190}
165 191
166sub destroy { 192sub destroy {
167 my ($self) = @_; 193 my ($self) = @_;
240 266
241sub size_allocate { 267sub size_allocate {
242 # nothing to be done 268 # nothing to be done
243} 269}
244 270
271sub reconfigure {
272 my ($self) = @_;
273
274 $self->check_size (1);
275 $self->update;
276}
277
245sub children { 278sub children {
246}
247
248# call when resolution changes etc.
249sub reconfigure {
250 my ($self) = @_;
251
252 $_->reconfigure
253 for $self->children;
254
255 $self->check_size;
256 $CFClient::UI::ROOT->{size_alloc}{$self} = [$self, $self->{w}, $self->{h}];
257 $self->update;
258} 279}
259 280
260sub set_max_size { 281sub set_max_size {
261 my ($self, $w, $h) = @_; 282 my ($self, $w, $h) = @_;
262 283
382sub set_parent { 403sub set_parent {
383 my ($self, $parent) = @_; 404 my ($self, $parent) = @_;
384 405
385 Scalar::Util::weaken ($self->{parent} = $parent); 406 Scalar::Util::weaken ($self->{parent} = $parent);
386 407
408 # TODO: req_w _does_change after ->reconfigure
387 $self->check_size 409 $self->check_size
388 unless exists $self->{req_w}; 410 unless exists $self->{req_w};
389} 411}
390 412
391sub check_size { 413sub check_size {
392 my ($self) = @_; 414 my ($self, $forced) = @_;
393 415
416 $self->{force_alloc} = 1 if $forced;
394 $CFClient::UI::ROOT->{check_size}{$self} = $self; 417 $CFClient::UI::ROOT->{check_size}{$self} = $self;
395} 418}
396 419
397sub update { 420sub update {
398 my ($self) = @_; 421 my ($self) = @_;
414} 437}
415 438
416sub DESTROY { 439sub DESTROY {
417 my ($self) = @_; 440 my ($self) = @_;
418 441
442 delete $WIDGET{$self+0};
419 #$self->deactivate; 443 #$self->deactivate;
420} 444}
421 445
422############################################################################# 446#############################################################################
423 447
508 $self->{children} = [ 532 $self->{children} = [
509 sort { $a->{z} <=> $b->{z} } 533 sort { $a->{z} <=> $b->{z} }
510 @{$self->{children}}, @widgets 534 @{$self->{children}}, @widgets
511 ]; 535 ];
512 536
513 $self->check_size; 537 $self->check_size (1);
514 $self->update; 538 $self->update;
515} 539}
516 540
517sub children { 541sub children {
518 @{ $_[0]{children} } 542 @{ $_[0]{children} }
625} 649}
626 650
627sub update { 651sub update {
628 my ($self) = @_; 652 my ($self) = @_;
629 653
630 $ROOT->on_refresh ($self => sub { $self->render_child }); 654 $ROOT->on_post_alloc ($self => sub { $self->render_child });
631 $self->SUPER::update; 655 $self->SUPER::update;
632} 656}
633 657
634sub size_allocate { 658sub size_allocate {
635 my ($self, $w, $h) = @_; 659 my ($self, $w, $h) = @_;
773 $self->add ($self->{slider}); 797 $self->add ($self->{slider});
774 798
775 $self 799 $self
776} 800}
777 801
778#TODO# update range on size_allocate depeneing on child 802#TODO# update range on size_allocate depending on child
779# update viewport offset on scroll 803# update viewport offset on scroll
780 804
781############################################################################# 805#############################################################################
782 806
783package CFClient::UI::Frame; 807package CFClient::UI::Frame;
787use CFClient::OpenGL; 811use CFClient::OpenGL;
788 812
789sub new { 813sub new {
790 my $class = shift; 814 my $class = shift;
791 815
792 my $self = $class->SUPER::new ( 816 $class->SUPER::new (
793 bg => [1, 1, 1, 1], 817 bg => undef,
794 border_bg => [1, 1, 1, 1],
795 border => 0.8,
796 @_ 818 @_,
797 ); 819 )
798
799 $self
800} 820}
801 821
802sub _draw { 822sub _draw {
803 my ($self) = @_; 823 my ($self) = @_;
804 824
805 my ($w, $h) = ($self->{w}, $self->{h}); 825 if ($self->{bg}) {
826 my ($w, $h) = @$self{qw(w h)};
806 827
807 glEnable GL_BLEND; 828 glEnable GL_BLEND;
808 glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA; 829 glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA;
809 glEnable GL_TEXTURE_2D; 830 glColor @{ $self->{bg} };
810 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE;
811 831
812# glBegin GL_QUADS; 832 glBegin GL_QUADS;
813# glColor 0, 0, 0, 0;
814# glVertex 0 , 0; 833 glVertex 0 , 0;
815# glVertex 0 , $h; 834 glVertex 0 , $h;
816# glVertex $w, $h; 835 glVertex $w, $h;
817# glVertex $w, 0; 836 glVertex $w, 0;
818# glEnd; 837 glEnd;
819 838
820
821 $self->child->draw;
822 glDisable GL_BLEND; 839 glDisable GL_BLEND;
823 glDisable GL_TEXTURE_2D; 840 }
841
842 $self->SUPER::_draw;
824} 843}
825 844
826############################################################################# 845#############################################################################
827 846
828package CFClient::UI::FancyFrame; 847package CFClient::UI::FancyFrame;
842 861
843 my $self = $class->SUPER::new ( 862 my $self = $class->SUPER::new (
844 bg => [1, 1, 1, 1], 863 bg => [1, 1, 1, 1],
845 border_bg => [1, 1, 1, 1], 864 border_bg => [1, 1, 1, 1],
846 border => 0.6, 865 border => 0.6,
866 toplevel => 1,
847 can_events => 1, 867 can_events => 1,
848 @_ 868 @_
849 ); 869 );
850 870
851 $self->{title} &&= new CFClient::UI::Label 871 $self->{title} &&= new CFClient::UI::Label
944 my ($self) = @_; 964 my ($self) = @_;
945 965
946 my ($w, $h ) = ($self->{w}, $self->{h}); 966 my ($w, $h ) = ($self->{w}, $self->{h});
947 my ($cw, $ch) = ($self->child->{w}, $self->child->{h}); 967 my ($cw, $ch) = ($self->child->{w}, $self->child->{h});
948 968
949 glEnable GL_BLEND;
950 glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA;
951 glEnable GL_TEXTURE_2D; 969 glEnable GL_TEXTURE_2D;
952 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE; 970 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE;
953 971
954 my $border = $self->border; 972 my $border = $self->border;
955 973
956 glColor @{ $self->{border_bg} }; 974 glColor @{ $self->{border_bg} };
957 $tex[1]->draw_quad (0, 0, $w, $border); 975 $tex[1]->draw_quad_alpha (0, 0, $w, $border);
958 $tex[3]->draw_quad (0, $border, $border, $ch); 976 $tex[3]->draw_quad_alpha (0, $border, $border, $ch);
959 $tex[2]->draw_quad ($w - $border, $border, $border, $ch); 977 $tex[2]->draw_quad_alpha ($w - $border, $border, $border, $ch);
960 $tex[4]->draw_quad (0, $h - $border, $w, $border); 978 $tex[4]->draw_quad_alpha (0, $h - $border, $w, $border);
961 979
962 if (@{$self->{bg}} < 4 || $self->{bg}[3]) { 980 if (@{$self->{bg}} < 4 || $self->{bg}[3]) {
963 my $bg = $tex[0]; 981 my $bg = $tex[0];
964 982
965 # TODO: repeat texture not scale 983 # TODO: repeat texture not scale
969 glColor @{ $self->{bg} }; 987 glColor @{ $self->{bg} };
970 988
971 $bg->{s} = $rep_x; 989 $bg->{s} = $rep_x;
972 $bg->{t} = $rep_y; 990 $bg->{t} = $rep_y;
973 $bg->{wrap_mode} = 1; 991 $bg->{wrap_mode} = 1;
974 $bg->draw_quad ($border, $border, $cw, $ch); 992 $bg->draw_quad_alpha ($border, $border, $cw, $ch);
993 }
975 994
976 glDisable GL_TEXTURE_2D; 995 glDisable GL_TEXTURE_2D;
977 glDisable GL_BLEND;
978 }
979 996
980 $self->{title}->draw if $self->{title}; 997 $self->{title}->draw if $self->{title};
981 998
982 $self->child->draw; 999 $self->child->draw;
983} 1000}
1485 my $sym = $ev->{sym}; 1502 my $sym = $ev->{sym};
1486 my $uni = $ev->{unicode}; 1503 my $uni = $ev->{unicode};
1487 1504
1488 my $text = $self->get_text; 1505 my $text = $self->get_text;
1489 1506
1490 if ($sym == 8) { 1507 if ($uni == 8) {
1491 substr $text, --$self->{cursor}, 1, "" if $self->{cursor}; 1508 substr $text, --$self->{cursor}, 1, "" if $self->{cursor};
1492 } elsif ($sym == 127) { 1509 } elsif ($uni == 127) {
1493 substr $text, $self->{cursor}, 1, ""; 1510 substr $text, $self->{cursor}, 1, "";
1494 } elsif ($sym == CFClient::SDLK_LEFT) { 1511 } elsif ($sym == CFClient::SDLK_LEFT) {
1495 --$self->{cursor} if $self->{cursor}; 1512 --$self->{cursor} if $self->{cursor};
1496 } elsif ($sym == CFClient::SDLK_RIGHT) { 1513 } elsif ($sym == CFClient::SDLK_RIGHT) {
1497 ++$self->{cursor} if $self->{cursor} < length $self->{text}; 1514 ++$self->{cursor} if $self->{cursor} < length $self->{text};
1498 } elsif ($sym == CFClient::SDLK_HOME) { 1515 } elsif ($sym == CFClient::SDLK_HOME) {
1499 $self->{cursor} = 0; 1516 $self->{cursor} = 0;
1500 } elsif ($sym == CFClient::SDLK_END) { 1517 } elsif ($sym == CFClient::SDLK_END) {
1501 $self->{cursor} = length $text; 1518 $self->{cursor} = length $text;
1502 } elsif ($sym == 27) { 1519 } elsif ($uni == 27) {
1503 $self->emit ('escape'); 1520 $self->emit ('escape');
1504 } elsif ($uni) { 1521 } elsif ($uni) {
1505 substr $text, $self->{cursor}++, 0, chr $uni; 1522 substr $text, $self->{cursor}++, 0, chr $uni;
1506 } 1523 }
1507 1524
1734 1751
1735 my $s = (List::Util::min @$self{qw(w h)}) - $self->{padding} * 2; 1752 my $s = (List::Util::min @$self{qw(w h)}) - $self->{padding} * 2;
1736 1753
1737 glColor @{ $FOCUS == $self ? $self->{active_fg} : $self->{fg} }; 1754 glColor @{ $FOCUS == $self ? $self->{active_fg} : $self->{fg} };
1738 1755
1756 my $tex = $self->{state} ? $tex[1] : $tex[0];
1757
1739 glEnable GL_TEXTURE_2D; 1758 glEnable GL_TEXTURE_2D;
1740
1741 my $tex = $self->{state} ? $tex[1] : $tex[0];
1742
1743 $tex->draw_quad_alpha (0, 0, $s, $s); 1759 $tex->draw_quad_alpha (0, 0, $s, $s);
1744
1745 glDisable GL_TEXTURE_2D; 1760 glDisable GL_TEXTURE_2D;
1746} 1761}
1747 1762
1748############################################################################# 1763#############################################################################
1749 1764
2204 2219
2205 return unless $self->{h} > 0; 2220 return unless $self->{h} > 0;
2206 2221
2207 delete $self->{texture}; 2222 delete $self->{texture};
2208 2223
2209 $ROOT->on_refresh ($self, sub { 2224 $ROOT->on_post_alloc ($self, sub {
2210 if (delete $self->{need_reflow}) { 2225 if (delete $self->{need_reflow}) {
2211 my $height = 0; 2226 my $height = 0;
2212 2227
2213 $height += $_->[0] = $self->text_height ($_->[2]) 2228 $height += $_->[0] = $self->text_height ($_->[2])
2214 for @{$self->{par}}; 2229 for @{$self->{par}};
2369} 2384}
2370 2385
2371sub set_tooltip_from { 2386sub set_tooltip_from {
2372 my ($self, $widget) = @_; 2387 my ($self, $widget) = @_;
2373 2388
2374 $self->{label} = new CFClient::UI::Label 2389 $self->add (new CFClient::UI::Label
2375 markup => $widget->{tooltip}, 2390 markup => $widget->{tooltip},
2376 max_w => ($widget->{tooltip_width} || 0.25) * $::WIDTH, 2391 max_w => ($widget->{tooltip_width} || 0.25) * $::WIDTH,
2377 fontsize => 0.8, 2392 fontsize => 0.8,
2378 fg => [0, 0, 0, 1], 2393 fg => [0, 0, 0, 1],
2379 font => ($widget->{tooltip_font} || $::FONT_PROP); 2394 font => ($widget->{tooltip_font} || $::FONT_PROP),
2380 2395 );
2381 $self->add ($self->{label});
2382} 2396}
2383 2397
2384sub size_request { 2398sub size_request {
2385 my ($self) = @_; 2399 my ($self) = @_;
2386 2400
2396} 2410}
2397 2411
2398sub _draw { 2412sub _draw {
2399 my ($self) = @_; 2413 my ($self) = @_;
2400 2414
2401 glPushMatrix;
2402 glTranslate 0.375, 0.375; 2415 glTranslate 0.375, 0.375;
2403 2416
2404 my ($w, $h) = @$self{qw(w h)}; 2417 my ($w, $h) = @$self{qw(w h)};
2405 2418
2406 glColor 1, 0.8, 0.4; 2419 glColor 1, 0.8, 0.4;
2417 glVertex 0 , $h; 2430 glVertex 0 , $h;
2418 glVertex $w, $h; 2431 glVertex $w, $h;
2419 glVertex $w, 0; 2432 glVertex $w, 0;
2420 glEnd; 2433 glEnd;
2421 2434
2422 glPopMatrix; 2435 glTranslate 2 - 0.375, 2 - 0.375;
2423
2424 glTranslate 2, 2;
2425 $self->SUPER::_draw; 2436 $self->SUPER::_draw;
2426} 2437}
2427 2438
2428############################################################################# 2439#############################################################################
2429 2440
2549 my ($self, $items) = @_; 2560 my ($self, $items) = @_;
2550 2561
2551 $self->{scrolled}->clear; 2562 $self->{scrolled}->clear;
2552 return unless $items; 2563 return unless $items;
2553 2564
2554 my @items = sort { $a->{type} <=> $b->{type} } @$items; 2565 my @items = sort {
2566 ($a->{type} <=> $b->{type})
2567 or ($a->{name} cmp $b->{name})
2568 } @$items;
2555 2569
2556 $self->{real_items} = \@items; 2570 $self->{real_items} = \@items;
2557 2571
2558 for my $item (@items) { 2572 for my $item (@items) {
2559 my $desc = $item->{nrof} < 2 2573 my $desc = $item->{nrof} < 2
2560 ? $item->{name} 2574 ? $item->{name}
2561 : "$item->{nrof} $item->{name_pl}"; 2575 : "$item->{nrof} $item->{name_pl}";
2562 2576
2563 $self->{scrolled}->add ($item->{widget} ||= new CFClient::UI::InventoryItem item => $item); 2577 $item = $item->{widget} ||= new CFClient::UI::InventoryItem item => $item;
2564 } 2578 }
2579
2580 $self->{scrolled}->add (@items);
2565 2581
2566# $range->{range} = [$self->{pos}, 0, $self->{max_pos}, $page]; 2582# $range->{range} = [$self->{pos}, 0, $self->{max_pos}, $page];
2567} 2583}
2568 2584
2569sub size_request { 2585sub size_request {
2656 while (my ($k, $v) = each %{ $self->{item} }) { 2672 while (my ($k, $v) = each %{ $self->{item} }) {
2657 delete $self->{item}{$k} if $v->{timeout} < $NOW; 2673 delete $self->{item}{$k} if $v->{timeout} < $NOW;
2658 } 2674 }
2659 2675
2660 my @widgets; 2676 my @widgets;
2661 my @items = sort { $a->{time} <=> $b->{time} } values %{ $self->{item} }; 2677
2678 my @items = sort {
2679 $a->{pri} <=> $b->{pri}
2680 or $b->{id} <=> $a->{id}
2681 } values %{ $self->{item} };
2682
2662 my $count = 10 + 1; 2683 my $count = 10 + 1;
2663 for my $item (@items) { 2684 for my $item (@items) {
2664 last unless --$count; 2685 last unless --$count;
2665 2686
2666 push @widgets, $item->{label} ||= do { 2687 push @widgets, $item->{label} ||= do {
2667 # TODO: doesn't handle markup well (read as: at all) 2688 # TODO: doesn't handle markup well (read as: at all)
2668 my $short = delete $item->{text}; 2689 my $short = $item->{count} > 1
2690 ? "<b>$item->{count} ×</b> $item->{text}"
2691 : $item->{text};
2692
2669 for ($short) { 2693 for ($short) {
2670 s/^\s+//; 2694 s/^\s+//;
2671 s/\012.*//s; 2695 s/\012.*//s;
2672 my $len = int 30 / $item->{fontsize}; 2696 my $len = int 40 / $item->{fontsize};
2673 substr $_, $len, length, "…" if $len < length; 2697 substr $_, $len, length, "…" if $len < length;
2674 } 2698 }
2675 2699
2676 new CFClient::UI::Label 2700 new CFClient::UI::Label
2677 markup => $short, 2701 markup => $short,
2678 tooltip => delete $item->{tooltip}, 2702 tooltip => $item->{tooltip},
2679 tooltip_font => $::FONT_PROP, 2703 tooltip_font => $::FONT_PROP,
2680 tooltip_width => 0.75, 2704 tooltip_width => 0.67,
2681 fontsize => delete $item->{fontsize}, 2705 fontsize => $item->{fontsize},
2682 color => delete $item->{color}, 2706 color => $item->{color},
2683 can_events => 1, 2707 can_events => 1,
2684 can_hover => 1, 2708 can_hover => 1
2685 }; 2709 };
2686 } 2710 }
2687 2711
2688 $self->clear; 2712 $self->clear;
2689 $self->SUPER::add (@widgets); 2713 $self->SUPER::add (reverse @widgets);
2690} 2714}
2691 2715
2692sub add { 2716sub add {
2693 my ($self, $text, %arg) = @_; 2717 my ($self, $text, %arg) = @_;
2694 2718
2695 my $item = { 2719 $text =~ s/^\s+//;
2696 time => time, 2720 $text =~ s/\s+$//;
2721
2722 my $timeout = time + ((delete $arg{timeout}) || 60);
2723
2724 my $group = exists $arg{group} ? $arg{group} : ++$self->{id};
2725
2726 if (my $item = $self->{item}{$group}) {
2727 if ($item->{text} eq $text) {
2728 $item->{count}++;
2729 } else {
2730 $item->{count} = 1;
2731 $item->{text} = $item->{tooltip} = $text;
2732 }
2733 $item->{id} = ++$self->{id};
2734 $item->{timeout} = $timeout;
2735 delete $item->{label};
2736 } else {
2737 $self->{item}{$group} = {
2738 id => ++$self->{id},
2697 text => $text, 2739 text => $text,
2698 timeout => 60, 2740 timeout => $timeout,
2699 tooltip => $text, 2741 tooltip => $text,
2700 fontsize => 0.8, 2742 fontsize => 0.8,
2701 color => [0.8, 0.8, 0.8, 0.8], 2743 color => [0.8, 0.8, 0.8, 0.8],
2744 pri => 0,
2745 count => 1,
2702 %arg, 2746 %arg,
2747 };
2703 }; 2748 }
2704
2705 $item->{timeout} += time;
2706 $item->{group} ||= $item+0;
2707
2708 $item = $self->{item}{$item->{group}} ||= $item;
2709 2749
2710 $self->reorder; 2750 $self->reorder;
2711} 2751}
2712 2752
2713############################################################################# 2753#############################################################################
2747} 2787}
2748 2788
2749sub size_allocate { 2789sub size_allocate {
2750 my ($self, $w, $h) = @_; 2790 my ($self, $w, $h) = @_;
2751 2791
2752 my $old_w = $self->{old_w}; 2792 my $old_w = $self->{old_w}; $self->{old_w} = $w;
2753 my $old_h = $self->{old_h}; 2793 my $old_h = $self->{old_h}; $self->{old_h} = $h;
2754 2794
2755 if ($old_w && $old_h) { 2795 CFClient::UI::rescale_widgets $w / $old_w, $h / $old_h
2756 for my $child ($self->children) { 2796 if $old_w && $old_h && ($old_w != $w || $old_h != $h);
2757 $child->{x} = int 0.5 + $child->{x} * $w / $old_w;
2758 $child->{w} = int 0.5 + $child->{w} * $w / $old_w;
2759 $child->{req_w} = int 0.5 + $child->{req_w} * $w / $old_w if exists $child->{req_w};
2760 $child->{user_w} = int 0.5 + $child->{user_w} * $w / $old_w if exists $child->{user_w};
2761 $child->{y} = int 0.5 + $child->{y} * $h / $old_h;
2762 $child->{h} = int 0.5 + $child->{h} * $h / $old_h;
2763 $child->{req_h} = int 0.5 + $child->{req_h} * $h / $old_h if exists $child->{req_h};
2764 $child->{user_h} = int 0.5 + $child->{user_h} * $h / $old_h if exists $child->{user_h};
2765 }
2766 }
2767 2797
2768 for my $child ($self->children) { 2798 for my $child ($self->children) {
2769 my ($X, $Y, $W, $H) = @$child{qw(x y req_w req_h)}; 2799 my ($X, $Y, $W, $H) = @$child{qw(x y req_w req_h)};
2770 2800
2771 $X = List::Util::max 0, List::Util::min $w - $W, $X; 2801 $X = List::Util::max 0, List::Util::min $w - $W, $X;
2772 $Y = List::Util::max 0, List::Util::min $h - $H, $Y; 2802 $Y = List::Util::max 0, List::Util::min $h - $H, $Y;
2773 $child->configure ($X, $Y, $W, $H); 2803 $child->configure ($X, $Y, $W, $H);
2774 } 2804 }
2775
2776 $self->{old_w} = $w;
2777 $self->{old_h} = $h;
2778} 2805}
2779 2806
2780sub coord2local { 2807sub coord2local {
2781 my ($self, $x, $y) = @_; 2808 my ($self, $x, $y) = @_;
2782 2809
2795 $self->check_size; 2822 $self->check_size;
2796 $::WANT_REFRESH++; 2823 $::WANT_REFRESH++;
2797} 2824}
2798 2825
2799sub add { 2826sub add {
2800 my ($self, $child) = @_; 2827 my ($self, @children) = @_;
2801 2828
2829 for my $child (@children) {
2830 $child->{toplevel} = 1;
2831
2802 # integerise window positions 2832 # integerise window positions
2803 $child->{x} = int $child->{x}; 2833 $child->{x} = int $child->{x};
2804 $child->{y} = int $child->{y}; 2834 $child->{y} = int $child->{y};
2835 }
2805 2836
2806 $self->SUPER::add ($child); 2837 $self->SUPER::add (@children);
2807} 2838}
2808 2839
2809sub on_refresh { 2840sub on_refresh {
2810 my ($self, $id, $cb) = @_; 2841 my ($self, $id, $cb) = @_;
2811 2842
2812 $self->{refresh_hook}{$id} = $cb; 2843 $self->{refresh_hook}{$id} = $cb;
2813} 2844}
2814 2845
2846sub on_post_alloc {
2847 my ($self, $id, $cb) = @_;
2848
2849 $self->{post_alloc_hook}{$id} = $cb;
2850}
2851
2815sub draw { 2852sub draw {
2816 my ($self) = @_; 2853 my ($self) = @_;
2854
2855 while ($self->{refresh_hook}) {
2856 $_->()
2857 for values %{delete $self->{refresh_hook}};
2858 }
2817 2859
2818 if ($self->{check_size}) { 2860 if ($self->{check_size}) {
2819 my @queue = ([], []); 2861 my @queue = ([], []);
2820 2862
2821 for (;;) { 2863 for (;;) {
2829 2871
2830 my ($w, $h) = $widget->{user_w} && $widget->{user_h} 2872 my ($w, $h) = $widget->{user_w} && $widget->{user_h}
2831 ? @$widget{qw(user_w user_h)} 2873 ? @$widget{qw(user_w user_h)}
2832 : $widget->size_request; 2874 : $widget->size_request;
2833 2875
2876 if (delete $widget->{force_alloc}
2834 if ($w != $widget->{req_w} || $h != $widget->{req_h}) { 2877 or $w != $widget->{req_w} or $h != $widget->{req_h}) {
2835 Carp::confess "$widget: size_request is negative" if $w < 0 || $h < 0;#d# 2878 Carp::confess "$widget: size_request is negative" if $w < 0 || $h < 0;#d#
2836 2879
2837 $widget->{req_w} = $w; 2880 $widget->{req_w} = $w;
2838 $widget->{req_h} = $h; 2881 $widget->{req_h} = $h;
2839 2882
2840 $self->{size_alloc}{$widget} = [$widget, $widget->{w}, $widget->{h}]; 2883 $self->{size_alloc}{$widget} = [$widget, $widget->{w} || $w, $widget->{h} || $h];
2841 2884
2842 $widget->{parent}->check_size 2885 $widget->{parent}->check_size
2843 if $widget->{parent}; 2886 if $widget->{parent};
2844 } 2887 }
2845 } 2888 }
2857 $widget->size_allocate ($w, $h); 2900 $widget->size_allocate ($w, $h);
2858 $widget->emit (size_allocate => $w, $h); 2901 $widget->emit (size_allocate => $w, $h);
2859 } 2902 }
2860 } 2903 }
2861 2904
2862 while ($self->{refresh_hook}) { 2905 while ($self->{post_alloc_hook}) {
2863 $_->() 2906 $_->()
2864 for values %{delete $self->{refresh_hook}}; 2907 for values %{delete $self->{post_alloc_hook}};
2865 } 2908 }
2866 2909
2867 glViewport 0, 0, $::WIDTH, $::HEIGHT; 2910 glViewport 0, 0, $::WIDTH, $::HEIGHT;
2868 glClearColor +($::CFG->{fow_intensity}) x 3, 1; 2911 glClearColor +($::CFG->{fow_intensity}) x 3, 1;
2869 glClear GL_COLOR_BUFFER_BIT; 2912 glClear GL_COLOR_BUFFER_BIT;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines