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.198 by root, Fri May 12 02:08:52 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
389 # TODO: req_w _does_change after ->reconfigure
387 $self->check_size 390 $self->check_size
388 unless exists $self->{req_w}; 391 unless exists $self->{req_w};
389} 392}
390 393
391sub check_size { 394sub check_size {
392 my ($self) = @_; 395 my ($self, $forced) = @_;
393 396
397 $self->{force_alloc} = 1 if $forced;
394 $CFClient::UI::ROOT->{check_size}{$self} = $self; 398 $CFClient::UI::ROOT->{check_size}{$self} = $self;
395} 399}
396 400
397sub update { 401sub update {
398 my ($self) = @_; 402 my ($self) = @_;
508 $self->{children} = [ 512 $self->{children} = [
509 sort { $a->{z} <=> $b->{z} } 513 sort { $a->{z} <=> $b->{z} }
510 @{$self->{children}}, @widgets 514 @{$self->{children}}, @widgets
511 ]; 515 ];
512 516
513 $self->check_size; 517 $self->check_size (1);
514 $self->update; 518 $self->update;
515} 519}
516 520
517sub children { 521sub children {
518 @{ $_[0]{children} } 522 @{ $_[0]{children} }
625} 629}
626 630
627sub update { 631sub update {
628 my ($self) = @_; 632 my ($self) = @_;
629 633
630 $ROOT->on_refresh ($self => sub { $self->render_child }); 634 $ROOT->on_post_alloc ($self => sub { $self->render_child });
631 $self->SUPER::update; 635 $self->SUPER::update;
632} 636}
633 637
634sub size_allocate { 638sub size_allocate {
635 my ($self, $w, $h) = @_; 639 my ($self, $w, $h) = @_;
784 788
785our @ISA = CFClient::UI::Bin::; 789our @ISA = CFClient::UI::Bin::;
786 790
787use CFClient::OpenGL; 791use CFClient::OpenGL;
788 792
789sub new {
790 my $class = shift;
791
792 my $self = $class->SUPER::new (
793 bg => [1, 1, 1, 1],
794 border_bg => [1, 1, 1, 1],
795 border => 0.8,
796 @_
797 );
798
799 $self
800}
801
802sub _draw {
803 my ($self) = @_;
804
805 my ($w, $h) = ($self->{w}, $self->{h});
806
807 glEnable GL_BLEND;
808 glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA;
809 glEnable GL_TEXTURE_2D;
810 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE;
811
812# glBegin GL_QUADS;
813# glColor 0, 0, 0, 0;
814# glVertex 0 , 0;
815# glVertex 0 , $h;
816# glVertex $w, $h;
817# glVertex $w, 0;
818# glEnd;
819
820
821 $self->child->draw;
822 glDisable GL_BLEND;
823 glDisable GL_TEXTURE_2D;
824}
825
826############################################################################# 793#############################################################################
827 794
828package CFClient::UI::FancyFrame; 795package CFClient::UI::FancyFrame;
829 796
830our @ISA = CFClient::UI::Bin::; 797our @ISA = CFClient::UI::Bin::;
944 my ($self) = @_; 911 my ($self) = @_;
945 912
946 my ($w, $h ) = ($self->{w}, $self->{h}); 913 my ($w, $h ) = ($self->{w}, $self->{h});
947 my ($cw, $ch) = ($self->child->{w}, $self->child->{h}); 914 my ($cw, $ch) = ($self->child->{w}, $self->child->{h});
948 915
949 glEnable GL_BLEND;
950 glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA;
951 glEnable GL_TEXTURE_2D; 916 glEnable GL_TEXTURE_2D;
952 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE; 917 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE;
953 918
954 my $border = $self->border; 919 my $border = $self->border;
955 920
956 glColor @{ $self->{border_bg} }; 921 glColor @{ $self->{border_bg} };
957 $tex[1]->draw_quad (0, 0, $w, $border); 922 $tex[1]->draw_quad_alpha (0, 0, $w, $border);
958 $tex[3]->draw_quad (0, $border, $border, $ch); 923 $tex[3]->draw_quad_alpha (0, $border, $border, $ch);
959 $tex[2]->draw_quad ($w - $border, $border, $border, $ch); 924 $tex[2]->draw_quad_alpha ($w - $border, $border, $border, $ch);
960 $tex[4]->draw_quad (0, $h - $border, $w, $border); 925 $tex[4]->draw_quad_alpha (0, $h - $border, $w, $border);
961 926
962 if (@{$self->{bg}} < 4 || $self->{bg}[3]) { 927 if (@{$self->{bg}} < 4 || $self->{bg}[3]) {
963 my $bg = $tex[0]; 928 my $bg = $tex[0];
964 929
965 # TODO: repeat texture not scale 930 # TODO: repeat texture not scale
969 glColor @{ $self->{bg} }; 934 glColor @{ $self->{bg} };
970 935
971 $bg->{s} = $rep_x; 936 $bg->{s} = $rep_x;
972 $bg->{t} = $rep_y; 937 $bg->{t} = $rep_y;
973 $bg->{wrap_mode} = 1; 938 $bg->{wrap_mode} = 1;
974 $bg->draw_quad ($border, $border, $cw, $ch); 939 $bg->draw_quad_alpha ($border, $border, $cw, $ch);
940 }
975 941
976 glDisable GL_TEXTURE_2D; 942 glDisable GL_TEXTURE_2D;
977 glDisable GL_BLEND;
978 }
979 943
980 $self->{title}->draw if $self->{title}; 944 $self->{title}->draw if $self->{title};
981 945
982 $self->child->draw; 946 $self->child->draw;
983} 947}
1734 1698
1735 my $s = (List::Util::min @$self{qw(w h)}) - $self->{padding} * 2; 1699 my $s = (List::Util::min @$self{qw(w h)}) - $self->{padding} * 2;
1736 1700
1737 glColor @{ $FOCUS == $self ? $self->{active_fg} : $self->{fg} }; 1701 glColor @{ $FOCUS == $self ? $self->{active_fg} : $self->{fg} };
1738 1702
1703 my $tex = $self->{state} ? $tex[1] : $tex[0];
1704
1739 glEnable GL_TEXTURE_2D; 1705 glEnable GL_TEXTURE_2D;
1740
1741 my $tex = $self->{state} ? $tex[1] : $tex[0];
1742
1743 $tex->draw_quad_alpha (0, 0, $s, $s); 1706 $tex->draw_quad_alpha (0, 0, $s, $s);
1744
1745 glDisable GL_TEXTURE_2D; 1707 glDisable GL_TEXTURE_2D;
1746} 1708}
1747 1709
1748############################################################################# 1710#############################################################################
1749 1711
2204 2166
2205 return unless $self->{h} > 0; 2167 return unless $self->{h} > 0;
2206 2168
2207 delete $self->{texture}; 2169 delete $self->{texture};
2208 2170
2209 $ROOT->on_refresh ($self, sub { 2171 $ROOT->on_post_alloc ($self, sub {
2210 if (delete $self->{need_reflow}) { 2172 if (delete $self->{need_reflow}) {
2211 my $height = 0; 2173 my $height = 0;
2212 2174
2213 $height += $_->[0] = $self->text_height ($_->[2]) 2175 $height += $_->[0] = $self->text_height ($_->[2])
2214 for @{$self->{par}}; 2176 for @{$self->{par}};
2369} 2331}
2370 2332
2371sub set_tooltip_from { 2333sub set_tooltip_from {
2372 my ($self, $widget) = @_; 2334 my ($self, $widget) = @_;
2373 2335
2374 $self->{label} = new CFClient::UI::Label 2336 $self->add (new CFClient::UI::Label
2375 markup => $widget->{tooltip}, 2337 markup => $widget->{tooltip},
2376 max_w => ($widget->{tooltip_width} || 0.25) * $::WIDTH, 2338 max_w => ($widget->{tooltip_width} || 0.25) * $::WIDTH,
2377 fontsize => 0.8, 2339 fontsize => 0.8,
2378 fg => [0, 0, 0, 1], 2340 fg => [0, 0, 0, 1],
2379 font => ($widget->{tooltip_font} || $::FONT_PROP); 2341 font => ($widget->{tooltip_font} || $::FONT_PROP),
2380 2342 );
2381 $self->add ($self->{label});
2382} 2343}
2383 2344
2384sub size_request { 2345sub size_request {
2385 my ($self) = @_; 2346 my ($self) = @_;
2386 2347
2396} 2357}
2397 2358
2398sub _draw { 2359sub _draw {
2399 my ($self) = @_; 2360 my ($self) = @_;
2400 2361
2401 glPushMatrix;
2402 glTranslate 0.375, 0.375; 2362 glTranslate 0.375, 0.375;
2403 2363
2404 my ($w, $h) = @$self{qw(w h)}; 2364 my ($w, $h) = @$self{qw(w h)};
2405 2365
2406 glColor 1, 0.8, 0.4; 2366 glColor 1, 0.8, 0.4;
2417 glVertex 0 , $h; 2377 glVertex 0 , $h;
2418 glVertex $w, $h; 2378 glVertex $w, $h;
2419 glVertex $w, 0; 2379 glVertex $w, 0;
2420 glEnd; 2380 glEnd;
2421 2381
2422 glPopMatrix; 2382 glTranslate 2 - 0.375, 2 - 0.375;
2423
2424 glTranslate 2, 2;
2425 $self->SUPER::_draw; 2383 $self->SUPER::_draw;
2426} 2384}
2427 2385
2428############################################################################# 2386#############################################################################
2429 2387
2656 while (my ($k, $v) = each %{ $self->{item} }) { 2614 while (my ($k, $v) = each %{ $self->{item} }) {
2657 delete $self->{item}{$k} if $v->{timeout} < $NOW; 2615 delete $self->{item}{$k} if $v->{timeout} < $NOW;
2658 } 2616 }
2659 2617
2660 my @widgets; 2618 my @widgets;
2661 my @items = sort { $a->{time} <=> $b->{time} } values %{ $self->{item} }; 2619
2620 my @items = sort {
2621 $a->{pri} <=> $b->{pri}
2622 or $b->{id} <=> $a->{id}
2623 } values %{ $self->{item} };
2624
2662 my $count = 10 + 1; 2625 my $count = 10 + 1;
2663 for my $item (@items) { 2626 for my $item (@items) {
2664 last unless --$count; 2627 last unless --$count;
2665 2628
2666 push @widgets, $item->{label} ||= do { 2629 push @widgets, $item->{label} ||= do {
2667 # TODO: doesn't handle markup well (read as: at all) 2630 # TODO: doesn't handle markup well (read as: at all)
2668 my $short = delete $item->{text}; 2631 my $short = $item->{count} > 1
2632 ? "<b>$item->{count} ×</b> $item->{text}"
2633 : $item->{text};
2634
2669 for ($short) { 2635 for ($short) {
2670 s/^\s+//; 2636 s/^\s+//;
2671 s/\012.*//s; 2637 s/\012.*//s;
2672 my $len = int 30 / $item->{fontsize}; 2638 my $len = int 40 / $item->{fontsize};
2673 substr $_, $len, length, "…" if $len < length; 2639 substr $_, $len, length, "…" if $len < length;
2674 } 2640 }
2675 2641
2676 new CFClient::UI::Label 2642 new CFClient::UI::Label
2677 markup => $short, 2643 markup => $short,
2678 tooltip => delete $item->{tooltip}, 2644 tooltip => $item->{tooltip},
2679 tooltip_font => $::FONT_PROP, 2645 tooltip_font => $::FONT_PROP,
2680 tooltip_width => 0.75, 2646 tooltip_width => 0.67,
2681 fontsize => delete $item->{fontsize}, 2647 fontsize => $item->{fontsize},
2682 color => delete $item->{color}, 2648 color => $item->{color},
2683 can_events => 1, 2649 can_events => 1,
2684 can_hover => 1, 2650 can_hover => 1
2685 }; 2651 };
2686 } 2652 }
2687 2653
2688 $self->clear; 2654 $self->clear;
2689 $self->SUPER::add (@widgets); 2655 $self->SUPER::add (reverse @widgets);
2690} 2656}
2691 2657
2692sub add { 2658sub add {
2693 my ($self, $text, %arg) = @_; 2659 my ($self, $text, %arg) = @_;
2694 2660
2695 my $item = { 2661 $text =~ s/^\s+//;
2696 time => time, 2662 $text =~ s/\s+$//;
2663
2664 my $timeout = time + ((delete $arg{timeout}) || 60);
2665
2666 my $group = exists $arg{group} ? $arg{group} : ++$self->{id};
2667
2668 if (my $item = $self->{item}{$group}) {
2669 if ($item->{text} eq $text) {
2670 $item->{count}++;
2671 } else {
2672 $item->{count} = 1;
2673 $item->{text} = $item->{tooltip} = $text;
2674 }
2675 $item->{id} = ++$self->{id};
2676 $item->{timeout} = $timeout;
2677 delete $item->{label};
2678 } else {
2679 $self->{item}{$group} = {
2680 id => ++$self->{id},
2697 text => $text, 2681 text => $text,
2698 timeout => 60, 2682 timeout => $timeout,
2699 tooltip => $text, 2683 tooltip => $text,
2700 fontsize => 0.8, 2684 fontsize => 0.8,
2701 color => [0.8, 0.8, 0.8, 0.8], 2685 color => [0.8, 0.8, 0.8, 0.8],
2686 pri => 0,
2687 count => 1,
2702 %arg, 2688 %arg,
2689 };
2703 }; 2690 }
2704
2705 $item->{timeout} += time;
2706 $item->{group} ||= $item+0;
2707
2708 $item = $self->{item}{$item->{group}} ||= $item;
2709 2691
2710 $self->reorder; 2692 $self->reorder;
2711} 2693}
2712 2694
2713############################################################################# 2695#############################################################################
2810 my ($self, $id, $cb) = @_; 2792 my ($self, $id, $cb) = @_;
2811 2793
2812 $self->{refresh_hook}{$id} = $cb; 2794 $self->{refresh_hook}{$id} = $cb;
2813} 2795}
2814 2796
2797sub on_post_alloc {
2798 my ($self, $id, $cb) = @_;
2799
2800 $self->{post_alloc_hook}{$id} = $cb;
2801}
2802
2815sub draw { 2803sub draw {
2816 my ($self) = @_; 2804 my ($self) = @_;
2805
2806 while ($self->{refresh_hook}) {
2807 $_->()
2808 for values %{delete $self->{refresh_hook}};
2809 }
2817 2810
2818 if ($self->{check_size}) { 2811 if ($self->{check_size}) {
2819 my @queue = ([], []); 2812 my @queue = ([], []);
2820 2813
2821 for (;;) { 2814 for (;;) {
2829 2822
2830 my ($w, $h) = $widget->{user_w} && $widget->{user_h} 2823 my ($w, $h) = $widget->{user_w} && $widget->{user_h}
2831 ? @$widget{qw(user_w user_h)} 2824 ? @$widget{qw(user_w user_h)}
2832 : $widget->size_request; 2825 : $widget->size_request;
2833 2826
2827 if (delete $widget->{force_alloc}
2834 if ($w != $widget->{req_w} || $h != $widget->{req_h}) { 2828 or $w != $widget->{req_w} or $h != $widget->{req_h}) {
2835 Carp::confess "$widget: size_request is negative" if $w < 0 || $h < 0;#d# 2829 Carp::confess "$widget: size_request is negative" if $w < 0 || $h < 0;#d#
2836 2830
2837 $widget->{req_w} = $w; 2831 $widget->{req_w} = $w;
2838 $widget->{req_h} = $h; 2832 $widget->{req_h} = $h;
2839 2833
2840 $self->{size_alloc}{$widget} = [$widget, $widget->{w}, $widget->{h}]; 2834 $self->{size_alloc}{$widget} = [$widget, $widget->{w} || $w, $widget->{h} || $h];
2841 2835
2842 $widget->{parent}->check_size 2836 $widget->{parent}->check_size
2843 if $widget->{parent}; 2837 if $widget->{parent};
2844 } 2838 }
2845 } 2839 }
2857 $widget->size_allocate ($w, $h); 2851 $widget->size_allocate ($w, $h);
2858 $widget->emit (size_allocate => $w, $h); 2852 $widget->emit (size_allocate => $w, $h);
2859 } 2853 }
2860 } 2854 }
2861 2855
2862 while ($self->{refresh_hook}) { 2856 while ($self->{post_alloc_hook}) {
2863 $_->() 2857 $_->()
2864 for values %{delete $self->{refresh_hook}}; 2858 for values %{delete $self->{post_alloc_hook}};
2865 } 2859 }
2866 2860
2867 glViewport 0, 0, $::WIDTH, $::HEIGHT; 2861 glViewport 0, 0, $::WIDTH, $::HEIGHT;
2868 glClearColor +($::CFG->{fow_intensity}) x 3, 1; 2862 glClearColor +($::CFG->{fow_intensity}) x 3, 1;
2869 glClear GL_COLOR_BUFFER_BIT; 2863 glClear GL_COLOR_BUFFER_BIT;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines