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