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.195 by root, Thu May 11 23:54:31 2006 UTC vs.
Revision 1.198 by root, Fri May 12 02:08:52 2006 UTC

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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines