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.199 by root, Fri May 12 15:45:42 2006 UTC

34 if ($x + $TOOLTIP->{w} > $::WIDTH) { 34 if ($x + $TOOLTIP->{w} > $::WIDTH) {
35 ($x, $y) = $widget->coord2global (-$TOOLTIP->{w}, 0); 35 ($x, $y) = $widget->coord2global (-$TOOLTIP->{w}, 0);
36 } 36 }
37 37
38 $TOOLTIP->move ($x, $y); 38 $TOOLTIP->move ($x, $y);
39 $TOOLTIP->check_size;
40 $TOOLTIP->update;
39 } 41 }
40 42
41 return; 43 return;
42 } 44 }
43 } 45 }
250 my ($self) = @_; 252 my ($self) = @_;
251 253
252 $_->reconfigure 254 $_->reconfigure
253 for $self->children; 255 for $self->children;
254 256
255 $self->check_size; 257 $self->check_size (1);
256 $CFClient::UI::ROOT->{size_alloc}{$self} = [$self, $self->{w}, $self->{h}];
257 $self->update; 258 $self->update;
258} 259}
259 260
260sub set_max_size { 261sub set_max_size {
261 my ($self, $w, $h) = @_; 262 my ($self, $w, $h) = @_;
382sub set_parent { 383sub set_parent {
383 my ($self, $parent) = @_; 384 my ($self, $parent) = @_;
384 385
385 Scalar::Util::weaken ($self->{parent} = $parent); 386 Scalar::Util::weaken ($self->{parent} = $parent);
386 387
388 # TODO: req_w _does_change after ->reconfigure
387 $self->check_size 389 $self->check_size
388 unless exists $self->{req_w}; 390 unless exists $self->{req_w};
389} 391}
390 392
391sub check_size { 393sub check_size {
392 my ($self) = @_; 394 my ($self, $forced) = @_;
393 395
396 $self->{force_alloc} = 1 if $forced;
394 $CFClient::UI::ROOT->{check_size}{$self} = $self; 397 $CFClient::UI::ROOT->{check_size}{$self} = $self;
395} 398}
396 399
397sub update { 400sub update {
398 my ($self) = @_; 401 my ($self) = @_;
508 $self->{children} = [ 511 $self->{children} = [
509 sort { $a->{z} <=> $b->{z} } 512 sort { $a->{z} <=> $b->{z} }
510 @{$self->{children}}, @widgets 513 @{$self->{children}}, @widgets
511 ]; 514 ];
512 515
513 $self->check_size; 516 $self->check_size (1);
514 $self->update; 517 $self->update;
515} 518}
516 519
517sub children { 520sub children {
518 @{ $_[0]{children} } 521 @{ $_[0]{children} }
625} 628}
626 629
627sub update { 630sub update {
628 my ($self) = @_; 631 my ($self) = @_;
629 632
630 $ROOT->on_refresh ($self => sub { $self->render_child }); 633 $ROOT->on_post_alloc ($self => sub { $self->render_child });
631 $self->SUPER::update; 634 $self->SUPER::update;
632} 635}
633 636
634sub size_allocate { 637sub size_allocate {
635 my ($self, $w, $h) = @_; 638 my ($self, $w, $h) = @_;
773 $self->add ($self->{slider}); 776 $self->add ($self->{slider});
774 777
775 $self 778 $self
776} 779}
777 780
778#TODO# update range on size_allocate depeneing on child 781#TODO# update range on size_allocate depending on child
779# update viewport offset on scroll 782# update viewport offset on scroll
780 783
781############################################################################# 784#############################################################################
782 785
783package CFClient::UI::Frame; 786package CFClient::UI::Frame;
787use CFClient::OpenGL; 790use CFClient::OpenGL;
788 791
789sub new { 792sub new {
790 my $class = shift; 793 my $class = shift;
791 794
792 my $self = $class->SUPER::new ( 795 $class->SUPER::new (
793 bg => [1, 1, 1, 1], 796 bg => undef,
794 border_bg => [1, 1, 1, 1],
795 border => 0.8,
796 @_ 797 @_,
797 ); 798 )
798
799 $self
800} 799}
801 800
802sub _draw { 801sub _draw {
803 my ($self) = @_; 802 my ($self) = @_;
804 803
805 my ($w, $h) = ($self->{w}, $self->{h}); 804 if ($self->{bg}) {
805 my ($w, $h) = @$self{qw(w h)};
806 806
807 glEnable GL_BLEND; 807 glEnable GL_BLEND;
808 glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA; 808 glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA;
809 glEnable GL_TEXTURE_2D; 809 glColor @{ $self->{bg} };
810 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE;
811 810
812# glBegin GL_QUADS; 811 glBegin GL_QUADS;
813# glColor 0, 0, 0, 0;
814# glVertex 0 , 0; 812 glVertex 0 , 0;
815# glVertex 0 , $h; 813 glVertex 0 , $h;
816# glVertex $w, $h; 814 glVertex $w, $h;
817# glVertex $w, 0; 815 glVertex $w, 0;
818# glEnd; 816 glEnd;
819 817
820
821 $self->child->draw;
822 glDisable GL_BLEND; 818 glDisable GL_BLEND;
823 glDisable GL_TEXTURE_2D; 819 }
820
821 $self->SUPER::_draw;
824} 822}
825 823
826############################################################################# 824#############################################################################
827 825
828package CFClient::UI::FancyFrame; 826package CFClient::UI::FancyFrame;
944 my ($self) = @_; 942 my ($self) = @_;
945 943
946 my ($w, $h ) = ($self->{w}, $self->{h}); 944 my ($w, $h ) = ($self->{w}, $self->{h});
947 my ($cw, $ch) = ($self->child->{w}, $self->child->{h}); 945 my ($cw, $ch) = ($self->child->{w}, $self->child->{h});
948 946
949 glEnable GL_BLEND;
950 glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA;
951 glEnable GL_TEXTURE_2D; 947 glEnable GL_TEXTURE_2D;
952 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE; 948 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE;
953 949
954 my $border = $self->border; 950 my $border = $self->border;
955 951
956 glColor @{ $self->{border_bg} }; 952 glColor @{ $self->{border_bg} };
957 $tex[1]->draw_quad (0, 0, $w, $border); 953 $tex[1]->draw_quad_alpha (0, 0, $w, $border);
958 $tex[3]->draw_quad (0, $border, $border, $ch); 954 $tex[3]->draw_quad_alpha (0, $border, $border, $ch);
959 $tex[2]->draw_quad ($w - $border, $border, $border, $ch); 955 $tex[2]->draw_quad_alpha ($w - $border, $border, $border, $ch);
960 $tex[4]->draw_quad (0, $h - $border, $w, $border); 956 $tex[4]->draw_quad_alpha (0, $h - $border, $w, $border);
961 957
962 if (@{$self->{bg}} < 4 || $self->{bg}[3]) { 958 if (@{$self->{bg}} < 4 || $self->{bg}[3]) {
963 my $bg = $tex[0]; 959 my $bg = $tex[0];
964 960
965 # TODO: repeat texture not scale 961 # TODO: repeat texture not scale
969 glColor @{ $self->{bg} }; 965 glColor @{ $self->{bg} };
970 966
971 $bg->{s} = $rep_x; 967 $bg->{s} = $rep_x;
972 $bg->{t} = $rep_y; 968 $bg->{t} = $rep_y;
973 $bg->{wrap_mode} = 1; 969 $bg->{wrap_mode} = 1;
974 $bg->draw_quad ($border, $border, $cw, $ch); 970 $bg->draw_quad_alpha ($border, $border, $cw, $ch);
971 }
975 972
976 glDisable GL_TEXTURE_2D; 973 glDisable GL_TEXTURE_2D;
977 glDisable GL_BLEND;
978 }
979 974
980 $self->{title}->draw if $self->{title}; 975 $self->{title}->draw if $self->{title};
981 976
982 $self->child->draw; 977 $self->child->draw;
983} 978}
1734 1729
1735 my $s = (List::Util::min @$self{qw(w h)}) - $self->{padding} * 2; 1730 my $s = (List::Util::min @$self{qw(w h)}) - $self->{padding} * 2;
1736 1731
1737 glColor @{ $FOCUS == $self ? $self->{active_fg} : $self->{fg} }; 1732 glColor @{ $FOCUS == $self ? $self->{active_fg} : $self->{fg} };
1738 1733
1734 my $tex = $self->{state} ? $tex[1] : $tex[0];
1735
1739 glEnable GL_TEXTURE_2D; 1736 glEnable GL_TEXTURE_2D;
1740
1741 my $tex = $self->{state} ? $tex[1] : $tex[0];
1742
1743 $tex->draw_quad_alpha (0, 0, $s, $s); 1737 $tex->draw_quad_alpha (0, 0, $s, $s);
1744
1745 glDisable GL_TEXTURE_2D; 1738 glDisable GL_TEXTURE_2D;
1746} 1739}
1747 1740
1748############################################################################# 1741#############################################################################
1749 1742
2204 2197
2205 return unless $self->{h} > 0; 2198 return unless $self->{h} > 0;
2206 2199
2207 delete $self->{texture}; 2200 delete $self->{texture};
2208 2201
2209 $ROOT->on_refresh ($self, sub { 2202 $ROOT->on_post_alloc ($self, sub {
2210 if (delete $self->{need_reflow}) { 2203 if (delete $self->{need_reflow}) {
2211 my $height = 0; 2204 my $height = 0;
2212 2205
2213 $height += $_->[0] = $self->text_height ($_->[2]) 2206 $height += $_->[0] = $self->text_height ($_->[2])
2214 for @{$self->{par}}; 2207 for @{$self->{par}};
2369} 2362}
2370 2363
2371sub set_tooltip_from { 2364sub set_tooltip_from {
2372 my ($self, $widget) = @_; 2365 my ($self, $widget) = @_;
2373 2366
2374 $self->{label} = new CFClient::UI::Label 2367 $self->add (new CFClient::UI::Label
2375 markup => $widget->{tooltip}, 2368 markup => $widget->{tooltip},
2376 max_w => ($widget->{tooltip_width} || 0.25) * $::WIDTH, 2369 max_w => ($widget->{tooltip_width} || 0.25) * $::WIDTH,
2377 fontsize => 0.8, 2370 fontsize => 0.8,
2378 fg => [0, 0, 0, 1], 2371 fg => [0, 0, 0, 1],
2379 font => ($widget->{tooltip_font} || $::FONT_PROP); 2372 font => ($widget->{tooltip_font} || $::FONT_PROP),
2380 2373 );
2381 $self->add ($self->{label});
2382} 2374}
2383 2375
2384sub size_request { 2376sub size_request {
2385 my ($self) = @_; 2377 my ($self) = @_;
2386 2378
2396} 2388}
2397 2389
2398sub _draw { 2390sub _draw {
2399 my ($self) = @_; 2391 my ($self) = @_;
2400 2392
2401 glPushMatrix;
2402 glTranslate 0.375, 0.375; 2393 glTranslate 0.375, 0.375;
2403 2394
2404 my ($w, $h) = @$self{qw(w h)}; 2395 my ($w, $h) = @$self{qw(w h)};
2405 2396
2406 glColor 1, 0.8, 0.4; 2397 glColor 1, 0.8, 0.4;
2417 glVertex 0 , $h; 2408 glVertex 0 , $h;
2418 glVertex $w, $h; 2409 glVertex $w, $h;
2419 glVertex $w, 0; 2410 glVertex $w, 0;
2420 glEnd; 2411 glEnd;
2421 2412
2422 glPopMatrix; 2413 glTranslate 2 - 0.375, 2 - 0.375;
2423
2424 glTranslate 2, 2;
2425 $self->SUPER::_draw; 2414 $self->SUPER::_draw;
2426} 2415}
2427 2416
2428############################################################################# 2417#############################################################################
2429 2418
2656 while (my ($k, $v) = each %{ $self->{item} }) { 2645 while (my ($k, $v) = each %{ $self->{item} }) {
2657 delete $self->{item}{$k} if $v->{timeout} < $NOW; 2646 delete $self->{item}{$k} if $v->{timeout} < $NOW;
2658 } 2647 }
2659 2648
2660 my @widgets; 2649 my @widgets;
2661 my @items = sort { $a->{time} <=> $b->{time} } values %{ $self->{item} }; 2650
2651 my @items = sort {
2652 $a->{pri} <=> $b->{pri}
2653 or $b->{id} <=> $a->{id}
2654 } values %{ $self->{item} };
2655
2662 my $count = 10 + 1; 2656 my $count = 10 + 1;
2663 for my $item (@items) { 2657 for my $item (@items) {
2664 last unless --$count; 2658 last unless --$count;
2665 2659
2666 push @widgets, $item->{label} ||= do { 2660 push @widgets, $item->{label} ||= do {
2667 # TODO: doesn't handle markup well (read as: at all) 2661 # TODO: doesn't handle markup well (read as: at all)
2668 my $short = delete $item->{text}; 2662 my $short = $item->{count} > 1
2663 ? "<b>$item->{count} ×</b> $item->{text}"
2664 : $item->{text};
2665
2669 for ($short) { 2666 for ($short) {
2670 s/^\s+//; 2667 s/^\s+//;
2671 s/\012.*//s; 2668 s/\012.*//s;
2672 my $len = int 30 / $item->{fontsize}; 2669 my $len = int 40 / $item->{fontsize};
2673 substr $_, $len, length, "…" if $len < length; 2670 substr $_, $len, length, "…" if $len < length;
2674 } 2671 }
2675 2672
2676 new CFClient::UI::Label 2673 new CFClient::UI::Label
2677 markup => $short, 2674 markup => $short,
2678 tooltip => delete $item->{tooltip}, 2675 tooltip => $item->{tooltip},
2679 tooltip_font => $::FONT_PROP, 2676 tooltip_font => $::FONT_PROP,
2680 tooltip_width => 0.75, 2677 tooltip_width => 0.67,
2681 fontsize => delete $item->{fontsize}, 2678 fontsize => $item->{fontsize},
2682 color => delete $item->{color}, 2679 color => $item->{color},
2683 can_events => 1, 2680 can_events => 1,
2684 can_hover => 1, 2681 can_hover => 1
2685 }; 2682 };
2686 } 2683 }
2687 2684
2688 $self->clear; 2685 $self->clear;
2689 $self->SUPER::add (@widgets); 2686 $self->SUPER::add (reverse @widgets);
2690} 2687}
2691 2688
2692sub add { 2689sub add {
2693 my ($self, $text, %arg) = @_; 2690 my ($self, $text, %arg) = @_;
2694 2691
2695 my $item = { 2692 $text =~ s/^\s+//;
2696 time => time, 2693 $text =~ s/\s+$//;
2694
2695 my $timeout = time + ((delete $arg{timeout}) || 60);
2696
2697 my $group = exists $arg{group} ? $arg{group} : ++$self->{id};
2698
2699 if (my $item = $self->{item}{$group}) {
2700 if ($item->{text} eq $text) {
2701 $item->{count}++;
2702 } else {
2703 $item->{count} = 1;
2704 $item->{text} = $item->{tooltip} = $text;
2705 }
2706 $item->{id} = ++$self->{id};
2707 $item->{timeout} = $timeout;
2708 delete $item->{label};
2709 } else {
2710 $self->{item}{$group} = {
2711 id => ++$self->{id},
2697 text => $text, 2712 text => $text,
2698 timeout => 60, 2713 timeout => $timeout,
2699 tooltip => $text, 2714 tooltip => $text,
2700 fontsize => 0.8, 2715 fontsize => 0.8,
2701 color => [0.8, 0.8, 0.8, 0.8], 2716 color => [0.8, 0.8, 0.8, 0.8],
2717 pri => 0,
2718 count => 1,
2702 %arg, 2719 %arg,
2720 };
2703 }; 2721 }
2704
2705 $item->{timeout} += time;
2706 $item->{group} ||= $item+0;
2707
2708 $item = $self->{item}{$item->{group}} ||= $item;
2709 2722
2710 $self->reorder; 2723 $self->reorder;
2711} 2724}
2712 2725
2713############################################################################# 2726#############################################################################
2810 my ($self, $id, $cb) = @_; 2823 my ($self, $id, $cb) = @_;
2811 2824
2812 $self->{refresh_hook}{$id} = $cb; 2825 $self->{refresh_hook}{$id} = $cb;
2813} 2826}
2814 2827
2828sub on_post_alloc {
2829 my ($self, $id, $cb) = @_;
2830
2831 $self->{post_alloc_hook}{$id} = $cb;
2832}
2833
2815sub draw { 2834sub draw {
2816 my ($self) = @_; 2835 my ($self) = @_;
2836
2837 while ($self->{refresh_hook}) {
2838 $_->()
2839 for values %{delete $self->{refresh_hook}};
2840 }
2817 2841
2818 if ($self->{check_size}) { 2842 if ($self->{check_size}) {
2819 my @queue = ([], []); 2843 my @queue = ([], []);
2820 2844
2821 for (;;) { 2845 for (;;) {
2829 2853
2830 my ($w, $h) = $widget->{user_w} && $widget->{user_h} 2854 my ($w, $h) = $widget->{user_w} && $widget->{user_h}
2831 ? @$widget{qw(user_w user_h)} 2855 ? @$widget{qw(user_w user_h)}
2832 : $widget->size_request; 2856 : $widget->size_request;
2833 2857
2858 if (delete $widget->{force_alloc}
2834 if ($w != $widget->{req_w} || $h != $widget->{req_h}) { 2859 or $w != $widget->{req_w} or $h != $widget->{req_h}) {
2835 Carp::confess "$widget: size_request is negative" if $w < 0 || $h < 0;#d# 2860 Carp::confess "$widget: size_request is negative" if $w < 0 || $h < 0;#d#
2836 2861
2837 $widget->{req_w} = $w; 2862 $widget->{req_w} = $w;
2838 $widget->{req_h} = $h; 2863 $widget->{req_h} = $h;
2839 2864
2840 $self->{size_alloc}{$widget} = [$widget, $widget->{w}, $widget->{h}]; 2865 $self->{size_alloc}{$widget} = [$widget, $widget->{w} || $w, $widget->{h} || $h];
2841 2866
2842 $widget->{parent}->check_size 2867 $widget->{parent}->check_size
2843 if $widget->{parent}; 2868 if $widget->{parent};
2844 } 2869 }
2845 } 2870 }
2857 $widget->size_allocate ($w, $h); 2882 $widget->size_allocate ($w, $h);
2858 $widget->emit (size_allocate => $w, $h); 2883 $widget->emit (size_allocate => $w, $h);
2859 } 2884 }
2860 } 2885 }
2861 2886
2862 while ($self->{refresh_hook}) { 2887 while ($self->{post_alloc_hook}) {
2863 $_->() 2888 $_->()
2864 for values %{delete $self->{refresh_hook}}; 2889 for values %{delete $self->{post_alloc_hook}};
2865 } 2890 }
2866 2891
2867 glViewport 0, 0, $::WIDTH, $::HEIGHT; 2892 glViewport 0, 0, $::WIDTH, $::HEIGHT;
2868 glClearColor +($::CFG->{fow_intensity}) x 3, 1; 2893 glClearColor +($::CFG->{fow_intensity}) x 3, 1;
2869 glClear GL_COLOR_BUFFER_BIT; 2894 glClear GL_COLOR_BUFFER_BIT;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines