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.199 by root, Fri May 12 15:45:42 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 # TODO: req_w _does_change after ->reconfigure
389 $self->check_size 389 $self->check_size
390 unless exists $self->{req_w}; 390 unless exists $self->{req_w};
391} 391}
392 392
393sub check_size { 393sub check_size {
628} 628}
629 629
630sub update { 630sub update {
631 my ($self) = @_; 631 my ($self) = @_;
632 632
633 $ROOT->on_refresh ($self => sub { $self->render_child }); 633 $ROOT->on_post_alloc ($self => sub { $self->render_child });
634 $self->SUPER::update; 634 $self->SUPER::update;
635} 635}
636 636
637sub size_allocate { 637sub size_allocate {
638 my ($self, $w, $h) = @_; 638 my ($self, $w, $h) = @_;
776 $self->add ($self->{slider}); 776 $self->add ($self->{slider});
777 777
778 $self 778 $self
779} 779}
780 780
781#TODO# update range on size_allocate depeneing on child 781#TODO# update range on size_allocate depending on child
782# update viewport offset on scroll 782# update viewport offset on scroll
783 783
784############################################################################# 784#############################################################################
785 785
786package CFClient::UI::Frame; 786package CFClient::UI::Frame;
787 787
788our @ISA = CFClient::UI::Bin::; 788our @ISA = CFClient::UI::Bin::;
789 789
790use CFClient::OpenGL; 790use CFClient::OpenGL;
791
792sub new {
793 my $class = shift;
794
795 $class->SUPER::new (
796 bg => undef,
797 @_,
798 )
799}
800
801sub _draw {
802 my ($self) = @_;
803
804 if ($self->{bg}) {
805 my ($w, $h) = @$self{qw(w h)};
806
807 glEnable GL_BLEND;
808 glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA;
809 glColor @{ $self->{bg} };
810
811 glBegin GL_QUADS;
812 glVertex 0 , 0;
813 glVertex 0 , $h;
814 glVertex $w, $h;
815 glVertex $w, 0;
816 glEnd;
817
818 glDisable GL_BLEND;
819 }
820
821 $self->SUPER::_draw;
822}
791 823
792############################################################################# 824#############################################################################
793 825
794package CFClient::UI::FancyFrame; 826package CFClient::UI::FancyFrame;
795 827
2165 2197
2166 return unless $self->{h} > 0; 2198 return unless $self->{h} > 0;
2167 2199
2168 delete $self->{texture}; 2200 delete $self->{texture};
2169 2201
2170 $ROOT->on_refresh ($self, sub { 2202 $ROOT->on_post_alloc ($self, sub {
2171 if (delete $self->{need_reflow}) { 2203 if (delete $self->{need_reflow}) {
2172 my $height = 0; 2204 my $height = 0;
2173 2205
2174 $height += $_->[0] = $self->text_height ($_->[2]) 2206 $height += $_->[0] = $self->text_height ($_->[2])
2175 for @{$self->{par}}; 2207 for @{$self->{par}};
2632 : $item->{text}; 2664 : $item->{text};
2633 2665
2634 for ($short) { 2666 for ($short) {
2635 s/^\s+//; 2667 s/^\s+//;
2636 s/\012.*/…/s; 2668 s/\012.*/…/s;
2637 my $len = int 30 / $item->{fontsize}; 2669 my $len = int 40 / $item->{fontsize};
2638 substr $_, $len, length, "…" if $len < length; 2670 substr $_, $len, length, "…" if $len < length;
2639 } 2671 }
2640 2672
2641 new CFClient::UI::Label 2673 new CFClient::UI::Label
2642 markup => $short, 2674 markup => $short,
2655} 2687}
2656 2688
2657sub add { 2689sub add {
2658 my ($self, $text, %arg) = @_; 2690 my ($self, $text, %arg) = @_;
2659 2691
2692 $text =~ s/^\s+//;
2693 $text =~ s/\s+$//;
2694
2660 my $timeout = time + ((delete $arg{timeout}) || 60); 2695 my $timeout = time + ((delete $arg{timeout}) || 60);
2661 2696
2662 my $group = exists $arg{group} ? $arg{group} : ++$self->{id}; 2697 my $group = exists $arg{group} ? $arg{group} : ++$self->{id};
2663 2698
2664 if (my $item = $self->{item}{$group}) { 2699 if (my $item = $self->{item}{$group}) {
2666 $item->{count}++; 2701 $item->{count}++;
2667 } else { 2702 } else {
2668 $item->{count} = 1; 2703 $item->{count} = 1;
2669 $item->{text} = $item->{tooltip} = $text; 2704 $item->{text} = $item->{tooltip} = $text;
2670 } 2705 }
2706 $item->{id} = ++$self->{id};
2671 $item->{timeout} = $timeout; 2707 $item->{timeout} = $timeout;
2672 delete $item->{label}; 2708 delete $item->{label};
2673 } else { 2709 } else {
2674 $self->{item}{$group} = { 2710 $self->{item}{$group} = {
2675 id => ++$self->{id}, 2711 id => ++$self->{id},
2787 my ($self, $id, $cb) = @_; 2823 my ($self, $id, $cb) = @_;
2788 2824
2789 $self->{refresh_hook}{$id} = $cb; 2825 $self->{refresh_hook}{$id} = $cb;
2790} 2826}
2791 2827
2828sub on_post_alloc {
2829 my ($self, $id, $cb) = @_;
2830
2831 $self->{post_alloc_hook}{$id} = $cb;
2832}
2833
2792sub draw { 2834sub draw {
2793 my ($self) = @_; 2835 my ($self) = @_;
2836
2837 while ($self->{refresh_hook}) {
2838 $_->()
2839 for values %{delete $self->{refresh_hook}};
2840 }
2794 2841
2795 if ($self->{check_size}) { 2842 if ($self->{check_size}) {
2796 my @queue = ([], []); 2843 my @queue = ([], []);
2797 2844
2798 for (;;) { 2845 for (;;) {
2835 $widget->size_allocate ($w, $h); 2882 $widget->size_allocate ($w, $h);
2836 $widget->emit (size_allocate => $w, $h); 2883 $widget->emit (size_allocate => $w, $h);
2837 } 2884 }
2838 } 2885 }
2839 2886
2840 while ($self->{refresh_hook}) { 2887 while ($self->{post_alloc_hook}) {
2841 $_->() 2888 $_->()
2842 for values %{delete $self->{refresh_hook}}; 2889 for values %{delete $self->{post_alloc_hook}};
2843 } 2890 }
2844 2891
2845 glViewport 0, 0, $::WIDTH, $::HEIGHT; 2892 glViewport 0, 0, $::WIDTH, $::HEIGHT;
2846 glClearColor +($::CFG->{fow_intensity}) x 3, 1; 2893 glClearColor +($::CFG->{fow_intensity}) x 3, 1;
2847 glClear GL_COLOR_BUFFER_BIT; 2894 glClear GL_COLOR_BUFFER_BIT;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines