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.197 by root, Fri May 12 01:47:04 2006 UTC vs.
Revision 1.198 by root, Fri May 12 02:08:52 2006 UTC

252 my ($self) = @_; 252 my ($self) = @_;
253 253
254 $_->reconfigure 254 $_->reconfigure
255 for $self->children; 255 for $self->children;
256 256
257 $self->check_size; 257 $self->check_size (1);
258 $CFClient::UI::ROOT->{size_alloc}{$self} = [$self, $self->{w}, $self->{h}];
259 $self->update; 258 $self->update;
260} 259}
261 260
262sub set_max_size { 261sub set_max_size {
263 my ($self, $w, $h) = @_; 262 my ($self, $w, $h) = @_;
384sub set_parent { 383sub set_parent {
385 my ($self, $parent) = @_; 384 my ($self, $parent) = @_;
386 385
387 Scalar::Util::weaken ($self->{parent} = $parent); 386 Scalar::Util::weaken ($self->{parent} = $parent);
388 387
388
389 # TODO: req_w _does_change after ->reconfigure
389 $self->check_size 390 $self->check_size
390 unless exists $self->{req_w}; 391 unless exists $self->{req_w};
391} 392}
392 393
393sub check_size { 394sub check_size {
628} 629}
629 630
630sub update { 631sub update {
631 my ($self) = @_; 632 my ($self) = @_;
632 633
633 $ROOT->on_refresh ($self => sub { $self->render_child }); 634 $ROOT->on_post_alloc ($self => sub { $self->render_child });
634 $self->SUPER::update; 635 $self->SUPER::update;
635} 636}
636 637
637sub size_allocate { 638sub size_allocate {
638 my ($self, $w, $h) = @_; 639 my ($self, $w, $h) = @_;
2165 2166
2166 return unless $self->{h} > 0; 2167 return unless $self->{h} > 0;
2167 2168
2168 delete $self->{texture}; 2169 delete $self->{texture};
2169 2170
2170 $ROOT->on_refresh ($self, sub { 2171 $ROOT->on_post_alloc ($self, sub {
2171 if (delete $self->{need_reflow}) { 2172 if (delete $self->{need_reflow}) {
2172 my $height = 0; 2173 my $height = 0;
2173 2174
2174 $height += $_->[0] = $self->text_height ($_->[2]) 2175 $height += $_->[0] = $self->text_height ($_->[2])
2175 for @{$self->{par}}; 2176 for @{$self->{par}};
2632 : $item->{text}; 2633 : $item->{text};
2633 2634
2634 for ($short) { 2635 for ($short) {
2635 s/^\s+//; 2636 s/^\s+//;
2636 s/\012.*/…/s; 2637 s/\012.*/…/s;
2637 my $len = int 30 / $item->{fontsize}; 2638 my $len = int 40 / $item->{fontsize};
2638 substr $_, $len, length, "…" if $len < length; 2639 substr $_, $len, length, "…" if $len < length;
2639 } 2640 }
2640 2641
2641 new CFClient::UI::Label 2642 new CFClient::UI::Label
2642 markup => $short, 2643 markup => $short,
2655} 2656}
2656 2657
2657sub add { 2658sub add {
2658 my ($self, $text, %arg) = @_; 2659 my ($self, $text, %arg) = @_;
2659 2660
2661 $text =~ s/^\s+//;
2662 $text =~ s/\s+$//;
2663
2660 my $timeout = time + ((delete $arg{timeout}) || 60); 2664 my $timeout = time + ((delete $arg{timeout}) || 60);
2661 2665
2662 my $group = exists $arg{group} ? $arg{group} : ++$self->{id}; 2666 my $group = exists $arg{group} ? $arg{group} : ++$self->{id};
2663 2667
2664 if (my $item = $self->{item}{$group}) { 2668 if (my $item = $self->{item}{$group}) {
2666 $item->{count}++; 2670 $item->{count}++;
2667 } else { 2671 } else {
2668 $item->{count} = 1; 2672 $item->{count} = 1;
2669 $item->{text} = $item->{tooltip} = $text; 2673 $item->{text} = $item->{tooltip} = $text;
2670 } 2674 }
2675 $item->{id} = ++$self->{id};
2671 $item->{timeout} = $timeout; 2676 $item->{timeout} = $timeout;
2672 delete $item->{label}; 2677 delete $item->{label};
2673 } else { 2678 } else {
2674 $self->{item}{$group} = { 2679 $self->{item}{$group} = {
2675 id => ++$self->{id}, 2680 id => ++$self->{id},
2787 my ($self, $id, $cb) = @_; 2792 my ($self, $id, $cb) = @_;
2788 2793
2789 $self->{refresh_hook}{$id} = $cb; 2794 $self->{refresh_hook}{$id} = $cb;
2790} 2795}
2791 2796
2797sub on_post_alloc {
2798 my ($self, $id, $cb) = @_;
2799
2800 $self->{post_alloc_hook}{$id} = $cb;
2801}
2802
2792sub draw { 2803sub draw {
2793 my ($self) = @_; 2804 my ($self) = @_;
2805
2806 while ($self->{refresh_hook}) {
2807 $_->()
2808 for values %{delete $self->{refresh_hook}};
2809 }
2794 2810
2795 if ($self->{check_size}) { 2811 if ($self->{check_size}) {
2796 my @queue = ([], []); 2812 my @queue = ([], []);
2797 2813
2798 for (;;) { 2814 for (;;) {
2835 $widget->size_allocate ($w, $h); 2851 $widget->size_allocate ($w, $h);
2836 $widget->emit (size_allocate => $w, $h); 2852 $widget->emit (size_allocate => $w, $h);
2837 } 2853 }
2838 } 2854 }
2839 2855
2840 while ($self->{refresh_hook}) { 2856 while ($self->{post_alloc_hook}) {
2841 $_->() 2857 $_->()
2842 for values %{delete $self->{refresh_hook}}; 2858 for values %{delete $self->{post_alloc_hook}};
2843 } 2859 }
2844 2860
2845 glViewport 0, 0, $::WIDTH, $::HEIGHT; 2861 glViewport 0, 0, $::WIDTH, $::HEIGHT;
2846 glClearColor +($::CFG->{fow_intensity}) x 3, 1; 2862 glClearColor +($::CFG->{fow_intensity}) x 3, 1;
2847 glClear GL_COLOR_BUFFER_BIT; 2863 glClear GL_COLOR_BUFFER_BIT;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines