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.197 by root, Fri May 12 01:47:04 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 }
388 $self->check_size 389 $self->check_size
389 unless exists $self->{req_w}; 390 unless exists $self->{req_w};
390} 391}
391 392
392sub check_size { 393sub check_size {
393 my ($self) = @_; 394 my ($self, $forced) = @_;
394 395
396 $self->{force_alloc} = 1 if $forced;
395 $CFClient::UI::ROOT->{check_size}{$self} = $self; 397 $CFClient::UI::ROOT->{check_size}{$self} = $self;
396} 398}
397 399
398sub update { 400sub update {
399 my ($self) = @_; 401 my ($self) = @_;
509 $self->{children} = [ 511 $self->{children} = [
510 sort { $a->{z} <=> $b->{z} } 512 sort { $a->{z} <=> $b->{z} }
511 @{$self->{children}}, @widgets 513 @{$self->{children}}, @widgets
512 ]; 514 ];
513 515
514 $self->check_size; 516 $self->check_size (1);
515 $self->update; 517 $self->update;
516} 518}
517 519
518sub children { 520sub children {
519 @{ $_[0]{children} } 521 @{ $_[0]{children} }
785 787
786our @ISA = CFClient::UI::Bin::; 788our @ISA = CFClient::UI::Bin::;
787 789
788use CFClient::OpenGL; 790use CFClient::OpenGL;
789 791
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############################################################################# 792#############################################################################
828 793
829package CFClient::UI::FancyFrame; 794package CFClient::UI::FancyFrame;
830 795
831our @ISA = CFClient::UI::Bin::; 796our @ISA = CFClient::UI::Bin::;
945 my ($self) = @_; 910 my ($self) = @_;
946 911
947 my ($w, $h ) = ($self->{w}, $self->{h}); 912 my ($w, $h ) = ($self->{w}, $self->{h});
948 my ($cw, $ch) = ($self->child->{w}, $self->child->{h}); 913 my ($cw, $ch) = ($self->child->{w}, $self->child->{h});
949 914
950 glEnable GL_BLEND;
951 glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA;
952 glEnable GL_TEXTURE_2D; 915 glEnable GL_TEXTURE_2D;
953 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE; 916 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE;
954 917
955 my $border = $self->border; 918 my $border = $self->border;
956 919
957 glColor @{ $self->{border_bg} }; 920 glColor @{ $self->{border_bg} };
958 $tex[1]->draw_quad (0, 0, $w, $border); 921 $tex[1]->draw_quad_alpha (0, 0, $w, $border);
959 $tex[3]->draw_quad (0, $border, $border, $ch); 922 $tex[3]->draw_quad_alpha (0, $border, $border, $ch);
960 $tex[2]->draw_quad ($w - $border, $border, $border, $ch); 923 $tex[2]->draw_quad_alpha ($w - $border, $border, $border, $ch);
961 $tex[4]->draw_quad (0, $h - $border, $w, $border); 924 $tex[4]->draw_quad_alpha (0, $h - $border, $w, $border);
962 925
963 if (@{$self->{bg}} < 4 || $self->{bg}[3]) { 926 if (@{$self->{bg}} < 4 || $self->{bg}[3]) {
964 my $bg = $tex[0]; 927 my $bg = $tex[0];
965 928
966 # TODO: repeat texture not scale 929 # TODO: repeat texture not scale
970 glColor @{ $self->{bg} }; 933 glColor @{ $self->{bg} };
971 934
972 $bg->{s} = $rep_x; 935 $bg->{s} = $rep_x;
973 $bg->{t} = $rep_y; 936 $bg->{t} = $rep_y;
974 $bg->{wrap_mode} = 1; 937 $bg->{wrap_mode} = 1;
975 $bg->draw_quad ($border, $border, $cw, $ch); 938 $bg->draw_quad_alpha ($border, $border, $cw, $ch);
939 }
976 940
977 glDisable GL_TEXTURE_2D; 941 glDisable GL_TEXTURE_2D;
978 glDisable GL_BLEND;
979 }
980 942
981 $self->{title}->draw if $self->{title}; 943 $self->{title}->draw if $self->{title};
982 944
983 $self->child->draw; 945 $self->child->draw;
984} 946}
1735 1697
1736 my $s = (List::Util::min @$self{qw(w h)}) - $self->{padding} * 2; 1698 my $s = (List::Util::min @$self{qw(w h)}) - $self->{padding} * 2;
1737 1699
1738 glColor @{ $FOCUS == $self ? $self->{active_fg} : $self->{fg} }; 1700 glColor @{ $FOCUS == $self ? $self->{active_fg} : $self->{fg} };
1739 1701
1702 my $tex = $self->{state} ? $tex[1] : $tex[0];
1703
1740 glEnable GL_TEXTURE_2D; 1704 glEnable GL_TEXTURE_2D;
1741
1742 my $tex = $self->{state} ? $tex[1] : $tex[0];
1743
1744 $tex->draw_quad_alpha (0, 0, $s, $s); 1705 $tex->draw_quad_alpha (0, 0, $s, $s);
1745
1746 glDisable GL_TEXTURE_2D; 1706 glDisable GL_TEXTURE_2D;
1747} 1707}
1748 1708
1749############################################################################# 1709#############################################################################
1750 1710
2367 @_, 2327 @_,
2368 can_events => 0, 2328 can_events => 0,
2369 ) 2329 )
2370} 2330}
2371 2331
2372sub set_markup { 2332sub set_tooltip_from {
2373 my ($self, $text, $font) = @_; 2333 my ($self, $widget) = @_;
2374 2334
2375 $self->{label} = new CFClient::UI::Label 2335 $self->add (new CFClient::UI::Label
2336 markup => $widget->{tooltip},
2337 max_w => ($widget->{tooltip_width} || 0.25) * $::WIDTH,
2376 fontsize => 0.8, 2338 fontsize => 0.8,
2377 fg => [0, 0, 0], 2339 fg => [0, 0, 0, 1],
2378 font => ($font || $::FONT_PROP); 2340 font => ($widget->{tooltip_font} || $::FONT_PROP),
2379 2341 );
2380 $self->{label}->set_max_size ($::WIDTH * 0.3);
2381 $self->{label}->set_markup ($text);
2382 $self->add ($self->{label});
2383} 2342}
2384 2343
2385sub size_request { 2344sub size_request {
2386 my ($self) = @_; 2345 my ($self) = @_;
2387 2346
2397} 2356}
2398 2357
2399sub _draw { 2358sub _draw {
2400 my ($self) = @_; 2359 my ($self) = @_;
2401 2360
2402 glPushMatrix;
2403 glTranslate 0.375, 0.375; 2361 glTranslate 0.375, 0.375;
2404 2362
2405 my ($w, $h) = @$self{qw(w h)}; 2363 my ($w, $h) = @$self{qw(w h)};
2406 2364
2407 glColor 1, 0.8, 0.4; 2365 glColor 1, 0.8, 0.4;
2418 glVertex 0 , $h; 2376 glVertex 0 , $h;
2419 glVertex $w, $h; 2377 glVertex $w, $h;
2420 glVertex $w, 0; 2378 glVertex $w, 0;
2421 glEnd; 2379 glEnd;
2422 2380
2423 glPopMatrix; 2381 glTranslate 2 - 0.375, 2 - 0.375;
2424
2425 glTranslate 2, 2;
2426 $self->SUPER::_draw; 2382 $self->SUPER::_draw;
2427} 2383}
2428 2384
2429############################################################################# 2385#############################################################################
2430 2386
2657 while (my ($k, $v) = each %{ $self->{item} }) { 2613 while (my ($k, $v) = each %{ $self->{item} }) {
2658 delete $self->{item}{$k} if $v->{timeout} < $NOW; 2614 delete $self->{item}{$k} if $v->{timeout} < $NOW;
2659 } 2615 }
2660 2616
2661 my @widgets; 2617 my @widgets;
2662 my @items = sort { $a->{time} <=> $b->{time} } values %{ $self->{item} }; 2618
2619 my @items = sort {
2620 $a->{pri} <=> $b->{pri}
2621 or $b->{id} <=> $a->{id}
2622 } values %{ $self->{item} };
2623
2663 my $count = 10 + 1; 2624 my $count = 10 + 1;
2664 for my $item (@items) { 2625 for my $item (@items) {
2665 last unless --$count; 2626 last unless --$count;
2666 2627
2667 push @widgets, $item->{label} ||= do { 2628 push @widgets, $item->{label} ||= do {
2668 # TODO: doesn't handle markup well (read as: at all) 2629 # TODO: doesn't handle markup well (read as: at all)
2669 my $short = delete $item->{text}; 2630 my $short = $item->{count} > 1
2631 ? "<b>$item->{count} ×</b> $item->{text}"
2632 : $item->{text};
2633
2670 for ($short) { 2634 for ($short) {
2671 s/^\s+//; 2635 s/^\s+//;
2672 s/\012.*//s; 2636 s/\012.*//s;
2673 my $len = int 30 / $item->{fontsize}; 2637 my $len = int 30 / $item->{fontsize};
2674 substr $_, $len, length, "…" if $len < length; 2638 substr $_, $len, length, "…" if $len < length;
2675 } 2639 }
2676 2640
2677 new CFClient::UI::Label 2641 new CFClient::UI::Label
2678 markup => $short, 2642 markup => $short,
2679 tooltip => delete $item->{tooltip}, 2643 tooltip => $item->{tooltip},
2644 tooltip_font => $::FONT_PROP,
2645 tooltip_width => 0.67,
2680 fontsize => delete $item->{fontsize}, 2646 fontsize => $item->{fontsize},
2681 color => delete $item->{color}, 2647 color => $item->{color},
2682 can_events => 1, 2648 can_events => 1,
2683 can_hover => 1, 2649 can_hover => 1
2684 }; 2650 };
2685 } 2651 }
2686 2652
2687 $self->clear; 2653 $self->clear;
2688 $self->SUPER::add (@widgets); 2654 $self->SUPER::add (reverse @widgets);
2689} 2655}
2690 2656
2691sub add { 2657sub add {
2692 my ($self, $text, %arg) = @_; 2658 my ($self, $text, %arg) = @_;
2693 2659
2694 my $item = { 2660 my $timeout = time + ((delete $arg{timeout}) || 60);
2695 time => time, 2661
2662 my $group = exists $arg{group} ? $arg{group} : ++$self->{id};
2663
2664 if (my $item = $self->{item}{$group}) {
2665 if ($item->{text} eq $text) {
2666 $item->{count}++;
2667 } else {
2668 $item->{count} = 1;
2669 $item->{text} = $item->{tooltip} = $text;
2670 }
2671 $item->{timeout} = $timeout;
2672 delete $item->{label};
2673 } else {
2674 $self->{item}{$group} = {
2675 id => ++$self->{id},
2696 text => $text, 2676 text => $text,
2697 timeout => 60, 2677 timeout => $timeout,
2698 tooltip => $text, 2678 tooltip => $text,
2699 fontsize => 0.8, 2679 fontsize => 0.8,
2700 color => [0.8, 0.8, 0.8, 0.8], 2680 color => [0.8, 0.8, 0.8, 0.8],
2681 pri => 0,
2682 count => 1,
2701 %arg, 2683 %arg,
2684 };
2702 }; 2685 }
2703
2704 $item->{timeout} += time;
2705 $item->{group} ||= $item+0;
2706
2707 $item = $self->{item}{$item->{group}} ||= $item;
2708 2686
2709 $self->reorder; 2687 $self->reorder;
2710} 2688}
2711 2689
2712############################################################################# 2690#############################################################################
2828 2806
2829 my ($w, $h) = $widget->{user_w} && $widget->{user_h} 2807 my ($w, $h) = $widget->{user_w} && $widget->{user_h}
2830 ? @$widget{qw(user_w user_h)} 2808 ? @$widget{qw(user_w user_h)}
2831 : $widget->size_request; 2809 : $widget->size_request;
2832 2810
2811 if (delete $widget->{force_alloc}
2833 if ($w != $widget->{req_w} || $h != $widget->{req_h}) { 2812 or $w != $widget->{req_w} or $h != $widget->{req_h}) {
2834 Carp::confess "$widget: size_request is negative" if $w < 0 || $h < 0;#d# 2813 Carp::confess "$widget: size_request is negative" if $w < 0 || $h < 0;#d#
2835 2814
2836 $widget->{req_w} = $w; 2815 $widget->{req_w} = $w;
2837 $widget->{req_h} = $h; 2816 $widget->{req_h} = $h;
2838 2817
2839 $self->{size_alloc}{$widget} = [$widget, $widget->{w}, $widget->{h}]; 2818 $self->{size_alloc}{$widget} = [$widget, $widget->{w} || $w, $widget->{h} || $h];
2840 2819
2841 $widget->{parent}->check_size 2820 $widget->{parent}->check_size
2842 if $widget->{parent}; 2821 if $widget->{parent};
2843 } 2822 }
2844 } 2823 }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines