… | |
… | |
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}); |
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 | |
261 | sub set_max_size { |
261 | sub set_max_size { |
262 | my ($self, $w, $h) = @_; |
262 | my ($self, $w, $h) = @_; |
… | |
… | |
383 | sub set_parent { |
383 | sub 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 | # TODO: req_w _does_change after ->reconfigure |
388 | $self->check_size |
389 | $self->check_size |
389 | unless exists $self->{req_w}; |
390 | unless exists $self->{req_w}; |
390 | } |
391 | } |
391 | |
392 | |
392 | sub check_size { |
393 | sub 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 | |
398 | sub update { |
400 | sub 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 | |
518 | sub children { |
520 | sub children { |
519 | @{ $_[0]{children} } |
521 | @{ $_[0]{children} } |
… | |
… | |
626 | } |
628 | } |
627 | |
629 | |
628 | sub update { |
630 | sub update { |
629 | my ($self) = @_; |
631 | my ($self) = @_; |
630 | |
632 | |
631 | $ROOT->on_refresh ($self => sub { $self->render_child }); |
633 | $ROOT->on_post_alloc ($self => sub { $self->render_child }); |
632 | $self->SUPER::update; |
634 | $self->SUPER::update; |
633 | } |
635 | } |
634 | |
636 | |
635 | sub size_allocate { |
637 | sub size_allocate { |
636 | my ($self, $w, $h) = @_; |
638 | my ($self, $w, $h) = @_; |
… | |
… | |
774 | $self->add ($self->{slider}); |
776 | $self->add ($self->{slider}); |
775 | |
777 | |
776 | $self |
778 | $self |
777 | } |
779 | } |
778 | |
780 | |
779 | #TODO# update range on size_allocate depeneing on child |
781 | #TODO# update range on size_allocate depending on child |
780 | # update viewport offset on scroll |
782 | # update viewport offset on scroll |
781 | |
783 | |
782 | ############################################################################# |
784 | ############################################################################# |
783 | |
785 | |
784 | package CFClient::UI::Frame; |
786 | package CFClient::UI::Frame; |
… | |
… | |
788 | use CFClient::OpenGL; |
790 | use CFClient::OpenGL; |
789 | |
791 | |
790 | sub new { |
792 | sub new { |
791 | my $class = shift; |
793 | my $class = shift; |
792 | |
794 | |
793 | my $self = $class->SUPER::new ( |
795 | $class->SUPER::new ( |
794 | bg => [1, 1, 1, 1], |
796 | bg => undef, |
795 | border_bg => [1, 1, 1, 1], |
|
|
796 | border => 0.8, |
|
|
797 | @_ |
797 | @_, |
798 | ); |
798 | ) |
799 | |
|
|
800 | $self |
|
|
801 | } |
799 | } |
802 | |
800 | |
803 | sub _draw { |
801 | sub _draw { |
804 | my ($self) = @_; |
802 | my ($self) = @_; |
805 | |
803 | |
806 | my ($w, $h) = ($self->{w}, $self->{h}); |
804 | if ($self->{bg}) { |
|
|
805 | my ($w, $h) = @$self{qw(w h)}; |
807 | |
806 | |
808 | glEnable GL_BLEND; |
807 | glEnable GL_BLEND; |
809 | glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA; |
808 | glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA; |
810 | glEnable GL_TEXTURE_2D; |
809 | glColor @{ $self->{bg} }; |
811 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; |
|
|
812 | |
810 | |
813 | # glBegin GL_QUADS; |
811 | glBegin GL_QUADS; |
814 | # glColor 0, 0, 0, 0; |
|
|
815 | # glVertex 0 , 0; |
812 | glVertex 0 , 0; |
816 | # glVertex 0 , $h; |
813 | glVertex 0 , $h; |
817 | # glVertex $w, $h; |
814 | glVertex $w, $h; |
818 | # glVertex $w, 0; |
815 | glVertex $w, 0; |
819 | # glEnd; |
816 | glEnd; |
820 | |
817 | |
821 | |
|
|
822 | $self->child->draw; |
|
|
823 | glDisable GL_BLEND; |
818 | glDisable GL_BLEND; |
824 | glDisable GL_TEXTURE_2D; |
819 | } |
|
|
820 | |
|
|
821 | $self->SUPER::_draw; |
825 | } |
822 | } |
826 | |
823 | |
827 | ############################################################################# |
824 | ############################################################################# |
828 | |
825 | |
829 | package CFClient::UI::FancyFrame; |
826 | package CFClient::UI::FancyFrame; |
… | |
… | |
945 | my ($self) = @_; |
942 | my ($self) = @_; |
946 | |
943 | |
947 | my ($w, $h ) = ($self->{w}, $self->{h}); |
944 | my ($w, $h ) = ($self->{w}, $self->{h}); |
948 | my ($cw, $ch) = ($self->child->{w}, $self->child->{h}); |
945 | my ($cw, $ch) = ($self->child->{w}, $self->child->{h}); |
949 | |
946 | |
950 | glEnable GL_BLEND; |
|
|
951 | glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA; |
|
|
952 | glEnable GL_TEXTURE_2D; |
947 | glEnable GL_TEXTURE_2D; |
953 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE; |
948 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE; |
954 | |
949 | |
955 | my $border = $self->border; |
950 | my $border = $self->border; |
956 | |
951 | |
957 | glColor @{ $self->{border_bg} }; |
952 | glColor @{ $self->{border_bg} }; |
958 | $tex[1]->draw_quad (0, 0, $w, $border); |
953 | $tex[1]->draw_quad_alpha (0, 0, $w, $border); |
959 | $tex[3]->draw_quad (0, $border, $border, $ch); |
954 | $tex[3]->draw_quad_alpha (0, $border, $border, $ch); |
960 | $tex[2]->draw_quad ($w - $border, $border, $border, $ch); |
955 | $tex[2]->draw_quad_alpha ($w - $border, $border, $border, $ch); |
961 | $tex[4]->draw_quad (0, $h - $border, $w, $border); |
956 | $tex[4]->draw_quad_alpha (0, $h - $border, $w, $border); |
962 | |
957 | |
963 | if (@{$self->{bg}} < 4 || $self->{bg}[3]) { |
958 | if (@{$self->{bg}} < 4 || $self->{bg}[3]) { |
964 | my $bg = $tex[0]; |
959 | my $bg = $tex[0]; |
965 | |
960 | |
966 | # TODO: repeat texture not scale |
961 | # TODO: repeat texture not scale |
… | |
… | |
970 | glColor @{ $self->{bg} }; |
965 | glColor @{ $self->{bg} }; |
971 | |
966 | |
972 | $bg->{s} = $rep_x; |
967 | $bg->{s} = $rep_x; |
973 | $bg->{t} = $rep_y; |
968 | $bg->{t} = $rep_y; |
974 | $bg->{wrap_mode} = 1; |
969 | $bg->{wrap_mode} = 1; |
975 | $bg->draw_quad ($border, $border, $cw, $ch); |
970 | $bg->draw_quad_alpha ($border, $border, $cw, $ch); |
|
|
971 | } |
976 | |
972 | |
977 | glDisable GL_TEXTURE_2D; |
973 | glDisable GL_TEXTURE_2D; |
978 | glDisable GL_BLEND; |
|
|
979 | } |
|
|
980 | |
974 | |
981 | $self->{title}->draw if $self->{title}; |
975 | $self->{title}->draw if $self->{title}; |
982 | |
976 | |
983 | $self->child->draw; |
977 | $self->child->draw; |
984 | } |
978 | } |
… | |
… | |
1486 | my $sym = $ev->{sym}; |
1480 | my $sym = $ev->{sym}; |
1487 | my $uni = $ev->{unicode}; |
1481 | my $uni = $ev->{unicode}; |
1488 | |
1482 | |
1489 | my $text = $self->get_text; |
1483 | my $text = $self->get_text; |
1490 | |
1484 | |
1491 | if ($sym == 8) { |
1485 | if ($uni == 8) { |
1492 | substr $text, --$self->{cursor}, 1, "" if $self->{cursor}; |
1486 | substr $text, --$self->{cursor}, 1, "" if $self->{cursor}; |
1493 | } elsif ($sym == 127) { |
1487 | } elsif ($uni == 127) { |
1494 | substr $text, $self->{cursor}, 1, ""; |
1488 | substr $text, $self->{cursor}, 1, ""; |
1495 | } elsif ($sym == CFClient::SDLK_LEFT) { |
1489 | } elsif ($sym == CFClient::SDLK_LEFT) { |
1496 | --$self->{cursor} if $self->{cursor}; |
1490 | --$self->{cursor} if $self->{cursor}; |
1497 | } elsif ($sym == CFClient::SDLK_RIGHT) { |
1491 | } elsif ($sym == CFClient::SDLK_RIGHT) { |
1498 | ++$self->{cursor} if $self->{cursor} < length $self->{text}; |
1492 | ++$self->{cursor} if $self->{cursor} < length $self->{text}; |
1499 | } elsif ($sym == CFClient::SDLK_HOME) { |
1493 | } elsif ($sym == CFClient::SDLK_HOME) { |
1500 | $self->{cursor} = 0; |
1494 | $self->{cursor} = 0; |
1501 | } elsif ($sym == CFClient::SDLK_END) { |
1495 | } elsif ($sym == CFClient::SDLK_END) { |
1502 | $self->{cursor} = length $text; |
1496 | $self->{cursor} = length $text; |
1503 | } elsif ($sym == 27) { |
1497 | } elsif ($uni == 27) { |
1504 | $self->emit ('escape'); |
1498 | $self->emit ('escape'); |
1505 | } elsif ($uni) { |
1499 | } elsif ($uni) { |
1506 | substr $text, $self->{cursor}++, 0, chr $uni; |
1500 | substr $text, $self->{cursor}++, 0, chr $uni; |
1507 | } |
1501 | } |
1508 | |
1502 | |
… | |
… | |
1672 | |
1666 | |
1673 | if ($GRAB == $self) { |
1667 | if ($GRAB == $self) { |
1674 | $self->{fg} = $self->{active_fg}; |
1668 | $self->{fg} = $self->{active_fg}; |
1675 | } |
1669 | } |
1676 | |
1670 | |
1677 | glEnable GL_BLEND; |
|
|
1678 | glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA; |
|
|
1679 | glEnable GL_TEXTURE_2D; |
1671 | glEnable GL_TEXTURE_2D; |
1680 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; |
1672 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; |
1681 | glColor 0, 0, 0, 1; |
1673 | glColor 0, 0, 0, 1; |
1682 | |
1674 | |
1683 | $tex[0]->draw_quad (0, 0, $self->{w}, $self->{h}); |
1675 | $tex[0]->draw_quad_alpha (0, 0, $self->{w}, $self->{h}); |
1684 | |
1676 | |
1685 | glDisable GL_TEXTURE_2D; |
1677 | glDisable GL_TEXTURE_2D; |
1686 | glDisable GL_BLEND; |
|
|
1687 | |
1678 | |
1688 | $self->SUPER::_draw; |
1679 | $self->SUPER::_draw; |
1689 | } |
1680 | } |
1690 | |
1681 | |
1691 | ############################################################################# |
1682 | ############################################################################# |
… | |
… | |
1738 | |
1729 | |
1739 | 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; |
1740 | |
1731 | |
1741 | glColor @{ $FOCUS == $self ? $self->{active_fg} : $self->{fg} }; |
1732 | glColor @{ $FOCUS == $self ? $self->{active_fg} : $self->{fg} }; |
1742 | |
1733 | |
1743 | glEnable GL_BLEND; |
1734 | my $tex = $self->{state} ? $tex[1] : $tex[0]; |
|
|
1735 | |
1744 | glEnable GL_TEXTURE_2D; |
1736 | glEnable GL_TEXTURE_2D; |
1745 | glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA; |
|
|
1746 | |
|
|
1747 | my $tex = $self->{state} ? $tex[1] : $tex[0]; |
|
|
1748 | |
|
|
1749 | $tex->draw_quad (0, 0, $s, $s); |
1737 | $tex->draw_quad_alpha (0, 0, $s, $s); |
1750 | |
|
|
1751 | glDisable GL_TEXTURE_2D; |
1738 | glDisable GL_TEXTURE_2D; |
1752 | glDisable GL_BLEND; |
|
|
1753 | } |
1739 | } |
1754 | |
1740 | |
1755 | ############################################################################# |
1741 | ############################################################################# |
1756 | |
1742 | |
1757 | package CFClient::UI::Image; |
1743 | package CFClient::UI::Image; |
… | |
… | |
1800 | glTranslate 0, -$self->{w}, 0; |
1786 | glTranslate 0, -$self->{w}, 0; |
1801 | |
1787 | |
1802 | ($w, $h) = ($h, $w); |
1788 | ($w, $h) = ($h, $w); |
1803 | } |
1789 | } |
1804 | |
1790 | |
1805 | glEnable GL_BLEND; |
|
|
1806 | glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA; |
|
|
1807 | glEnable GL_TEXTURE_2D; |
1791 | glEnable GL_TEXTURE_2D; |
1808 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; |
1792 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; |
1809 | |
1793 | |
1810 | $tex->draw_quad (0, 0, $w, $h); |
1794 | $tex->draw_quad_alpha (0, 0, $w, $h); |
1811 | |
1795 | |
1812 | glDisable GL_BLEND; |
|
|
1813 | glDisable GL_TEXTURE_2D; |
1796 | glDisable GL_TEXTURE_2D; |
1814 | } |
1797 | } |
1815 | |
1798 | |
1816 | ############################################################################# |
1799 | ############################################################################# |
1817 | |
1800 | |
… | |
… | |
2109 | $page ||= 2; |
2092 | $page ||= 2; |
2110 | |
2093 | |
2111 | my $knob_a = $inner_pad_px + ($value - $page * 0.5); |
2094 | my $knob_a = $inner_pad_px + ($value - $page * 0.5); |
2112 | my $knob_b = $inner_pad_px + ($value + $page * 0.5); |
2095 | my $knob_b = $inner_pad_px + ($value + $page * 0.5); |
2113 | |
2096 | |
2114 | glEnable GL_BLEND; |
|
|
2115 | glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA; |
|
|
2116 | glEnable GL_TEXTURE_2D; |
2097 | glEnable GL_TEXTURE_2D; |
2117 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; |
2098 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; |
2118 | |
2099 | |
2119 | # draw background |
2100 | # draw background |
2120 | $tex[1]->draw_quad (0, 0, $w, $h); |
2101 | $tex[1]->draw_quad_alpha (0, 0, $w, $h); |
2121 | |
2102 | |
2122 | # draw handle |
2103 | # draw handle |
2123 | $tex[0]->draw_quad ($knob_a, 0, $knob_b - $knob_a, $h); |
2104 | $tex[0]->draw_quad_alpha ($knob_a, 0, $knob_b - $knob_a, $h); |
2124 | |
2105 | |
2125 | glDisable GL_BLEND; |
|
|
2126 | glDisable GL_TEXTURE_2D; |
2106 | glDisable GL_TEXTURE_2D; |
2127 | } |
2107 | } |
2128 | |
2108 | |
2129 | ############################################################################# |
2109 | ############################################################################# |
2130 | |
2110 | |
… | |
… | |
2141 | fontsize => 1, |
2121 | fontsize => 1, |
2142 | can_events => 0, |
2122 | can_events => 0, |
2143 | #font => default_font |
2123 | #font => default_font |
2144 | @_, |
2124 | @_, |
2145 | |
2125 | |
2146 | layout => (new CFClient::Layout), |
2126 | layout => (new CFClient::Layout 1), |
2147 | par => [], |
2127 | par => [], |
2148 | height => 0, |
2128 | height => 0, |
2149 | children => [ |
2129 | children => [ |
2150 | (new CFClient::UI::Empty expand => 1), |
2130 | (new CFClient::UI::Empty expand => 1), |
2151 | (new CFClient::UI::Slider vertical => 1), |
2131 | (new CFClient::UI::Slider vertical => 1), |
… | |
… | |
2169 | |
2149 | |
2170 | my $layout = $self->{layout}; |
2150 | my $layout = $self->{layout}; |
2171 | |
2151 | |
2172 | $layout->set_height ($self->{fontsize} * $::FONTSIZE); |
2152 | $layout->set_height ($self->{fontsize} * $::FONTSIZE); |
2173 | $layout->set_width ($self->{children}[0]{w}); |
2153 | $layout->set_width ($self->{children}[0]{w}); |
2174 | $layout->set_text ($text); |
2154 | $layout->set_markup ($text); |
2175 | |
2155 | |
2176 | ($layout->size)[1] |
2156 | ($layout->size)[1] |
2177 | } |
2157 | } |
2178 | |
2158 | |
2179 | sub reflow { |
2159 | sub reflow { |
… | |
… | |
2217 | |
2197 | |
2218 | return unless $self->{h} > 0; |
2198 | return unless $self->{h} > 0; |
2219 | |
2199 | |
2220 | delete $self->{texture}; |
2200 | delete $self->{texture}; |
2221 | |
2201 | |
2222 | $ROOT->on_refresh ($self, sub { |
2202 | $ROOT->on_post_alloc ($self, sub { |
2223 | if (delete $self->{need_reflow}) { |
2203 | if (delete $self->{need_reflow}) { |
2224 | my $height = 0; |
2204 | my $height = 0; |
2225 | |
2205 | |
2226 | $height += $_->[0] = $self->text_height ($_->[2]) |
2206 | $height += $_->[0] = $self->text_height ($_->[2]) |
2227 | for @{$self->{par}}; |
2207 | for @{$self->{par}}; |
… | |
… | |
2235 | |
2215 | |
2236 | $self->{texture} ||= new_from_opengl CFClient::Texture $self->{children}[0]{w}, $self->{children}[0]{h}, sub { |
2216 | $self->{texture} ||= new_from_opengl CFClient::Texture $self->{children}[0]{w}, $self->{children}[0]{h}, sub { |
2237 | glClearColor 0, 0, 0, 0; |
2217 | glClearColor 0, 0, 0, 0; |
2238 | glClear GL_COLOR_BUFFER_BIT; |
2218 | glClear GL_COLOR_BUFFER_BIT; |
2239 | |
2219 | |
2240 | glEnable GL_BLEND; |
|
|
2241 | glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA; |
|
|
2242 | glEnable GL_TEXTURE_2D; |
2220 | glEnable GL_TEXTURE_2D; |
2243 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; |
2221 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; |
2244 | |
2222 | |
2245 | my $top = int $self->{children}[1]{range}[0]; |
2223 | my $top = int $self->{children}[1]{range}[0]; |
2246 | |
2224 | |
… | |
… | |
2255 | |
2233 | |
2256 | for my $par (@{$self->{par}}) { |
2234 | for my $par (@{$self->{par}}) { |
2257 | my $h = $par->[0]; |
2235 | my $h = $par->[0]; |
2258 | |
2236 | |
2259 | if ($y0 < $y + $h && $y < $y1) { |
2237 | if ($y0 < $y + $h && $y < $y1) { |
|
|
2238 | $layout->set_foreground (@{ $par->[1] }); |
2260 | $layout->set_text ($par->[2]); |
2239 | $layout->set_markup ($par->[2]); |
2261 | |
2240 | |
2262 | glColor @{ $par->[1] }; |
|
|
2263 | my ($W, $H) = $layout->size; |
2241 | my ($W, $H) = $layout->size; |
2264 | CFClient::Texture->new_from_layout ($layout)->draw_quad (0, $y - $y0); |
2242 | CFClient::Texture->new_from_layout ($layout)->draw_quad_alpha_premultiplied (0, $y - $y0); |
2265 | } |
2243 | } |
2266 | |
2244 | |
2267 | $y += $h; |
2245 | $y += $h; |
2268 | } |
2246 | } |
2269 | |
2247 | |
2270 | glDisable GL_TEXTURE_2D; |
2248 | glDisable GL_TEXTURE_2D; |
2271 | glDisable GL_BLEND; |
|
|
2272 | }; |
2249 | }; |
2273 | }); |
2250 | }); |
2274 | } |
2251 | } |
2275 | |
2252 | |
2276 | sub _draw { |
2253 | sub _draw { |
2277 | my ($self) = @_; |
2254 | my ($self) = @_; |
2278 | |
2255 | |
2279 | glEnable GL_BLEND; |
|
|
2280 | glBlendFunc GL_ONE, GL_ONE_MINUS_SRC_ALPHA; |
|
|
2281 | glEnable GL_TEXTURE_2D; |
2256 | glEnable GL_TEXTURE_2D; |
2282 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; |
2257 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; |
2283 | glColor 1, 1, 1, 1; |
2258 | glColor 1, 1, 1, 1; |
2284 | $self->{texture}->draw_quad (0, 0, $self->{children}[0]{w}, $self->{children}[0]{h}); |
2259 | $self->{texture}->draw_quad_alpha_premultiplied (0, 0, $self->{children}[0]{w}, $self->{children}[0]{h}); |
2285 | glDisable GL_TEXTURE_2D; |
2260 | glDisable GL_TEXTURE_2D; |
2286 | glDisable GL_BLEND; |
|
|
2287 | |
2261 | |
2288 | $self->{children}[1]->draw; |
2262 | $self->{children}[1]->draw; |
2289 | |
2263 | |
2290 | } |
2264 | } |
2291 | |
2265 | |
… | |
… | |
2385 | @_, |
2359 | @_, |
2386 | can_events => 0, |
2360 | can_events => 0, |
2387 | ) |
2361 | ) |
2388 | } |
2362 | } |
2389 | |
2363 | |
2390 | sub set_markup { |
2364 | sub set_tooltip_from { |
2391 | my ($self, $text) = @_; |
2365 | my ($self, $widget) = @_; |
2392 | |
2366 | |
2393 | $self->{label} ||= new CFClient::UI::Label fontsize => 0.8, fg => [0, 0, 0]; |
2367 | $self->add (new CFClient::UI::Label |
2394 | $self->{label}->set_markup ($text); |
2368 | markup => $widget->{tooltip}, |
2395 | $self->add ($self->{label}); |
2369 | max_w => ($widget->{tooltip_width} || 0.25) * $::WIDTH, |
|
|
2370 | fontsize => 0.8, |
|
|
2371 | fg => [0, 0, 0, 1], |
|
|
2372 | font => ($widget->{tooltip_font} || $::FONT_PROP), |
|
|
2373 | ); |
2396 | } |
2374 | } |
2397 | |
2375 | |
2398 | sub size_request { |
2376 | sub size_request { |
2399 | my ($self) = @_; |
2377 | my ($self) = @_; |
2400 | |
|
|
2401 | $self->child->set_max_size ($::WIDTH * 0.3); |
|
|
2402 | |
2378 | |
2403 | my ($w, $h) = @{$self->child}{qw(req_w req_h)}; |
2379 | my ($w, $h) = @{$self->child}{qw(req_w req_h)}; |
2404 | |
2380 | |
2405 | ($w + 4, $h + 4) |
2381 | ($w + 4, $h + 4) |
2406 | } |
2382 | } |
… | |
… | |
2412 | } |
2388 | } |
2413 | |
2389 | |
2414 | sub _draw { |
2390 | sub _draw { |
2415 | my ($self) = @_; |
2391 | my ($self) = @_; |
2416 | |
2392 | |
2417 | glPushMatrix; |
|
|
2418 | glTranslate 0.375, 0.375; |
2393 | glTranslate 0.375, 0.375; |
2419 | |
2394 | |
2420 | my ($w, $h) = @$self{qw(w h)}; |
2395 | my ($w, $h) = @$self{qw(w h)}; |
2421 | |
2396 | |
2422 | glColor 1, 0.8, 0.4; |
2397 | glColor 1, 0.8, 0.4; |
… | |
… | |
2433 | glVertex 0 , $h; |
2408 | glVertex 0 , $h; |
2434 | glVertex $w, $h; |
2409 | glVertex $w, $h; |
2435 | glVertex $w, 0; |
2410 | glVertex $w, 0; |
2436 | glEnd; |
2411 | glEnd; |
2437 | |
2412 | |
2438 | glPopMatrix; |
2413 | glTranslate 2 - 0.375, 2 - 0.375; |
2439 | |
|
|
2440 | glTranslate 2, 2; |
|
|
2441 | $self->SUPER::_draw; |
2414 | $self->SUPER::_draw; |
2442 | } |
2415 | } |
2443 | |
2416 | |
2444 | ############################################################################# |
2417 | ############################################################################# |
2445 | |
2418 | |
… | |
… | |
2468 | return unless $::CONN;#d# manage and cache textures differently |
2441 | return unless $::CONN;#d# manage and cache textures differently |
2469 | my $tex = $::CONN->{texture}[$::CONN->{faceid}[$self->{face}]]; |
2442 | my $tex = $::CONN->{texture}[$::CONN->{faceid}[$self->{face}]]; |
2470 | |
2443 | |
2471 | # TODO animation |
2444 | # TODO animation |
2472 | if ($tex) { |
2445 | if ($tex) { |
2473 | glEnable GL_BLEND; |
|
|
2474 | glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA; |
|
|
2475 | glEnable GL_TEXTURE_2D; |
2446 | glEnable GL_TEXTURE_2D; |
2476 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; |
2447 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; |
2477 | glColor 1, 1, 1, 1; |
2448 | glColor 1, 1, 1, 1; |
2478 | $tex->draw_quad (0, 0, $self->{w}, $self->{h}); |
2449 | $tex->draw_quad_alpha (0, 0, $self->{w}, $self->{h}); |
2479 | glDisable GL_TEXTURE_2D; |
2450 | glDisable GL_TEXTURE_2D; |
2480 | glDisable GL_BLEND; |
|
|
2481 | } |
2451 | } |
2482 | } |
2452 | } |
2483 | |
2453 | |
2484 | ############################################################################# |
2454 | ############################################################################# |
2485 | |
2455 | |
… | |
… | |
2568 | my ($self, $items) = @_; |
2538 | my ($self, $items) = @_; |
2569 | |
2539 | |
2570 | $self->{scrolled}->clear; |
2540 | $self->{scrolled}->clear; |
2571 | return unless $items; |
2541 | return unless $items; |
2572 | |
2542 | |
2573 | my @items = sort { $a->{type} <=> $b->{type} } @$items; |
2543 | my @items = sort { |
|
|
2544 | ($a->{type} <=> $b->{type}) |
|
|
2545 | or ($a->{name} cmp $b->{name}) |
|
|
2546 | } @$items; |
2574 | |
2547 | |
2575 | $self->{real_items} = \@items; |
2548 | $self->{real_items} = \@items; |
2576 | |
2549 | |
2577 | for my $item (@items) { |
2550 | for my $item (@items) { |
2578 | my $desc = $item->{nrof} < 2 |
2551 | my $desc = $item->{nrof} < 2 |
2579 | ? $item->{name} |
2552 | ? $item->{name} |
2580 | : "$item->{nrof} $item->{name_pl}"; |
2553 | : "$item->{nrof} $item->{name_pl}"; |
2581 | |
2554 | |
2582 | $self->{scrolled}->add ($item->{widget} ||= new CFClient::UI::InventoryItem item => $item); |
2555 | $item = $item->{widget} ||= new CFClient::UI::InventoryItem item => $item; |
2583 | } |
2556 | } |
|
|
2557 | |
|
|
2558 | $self->{scrolled}->add (@items); |
2584 | |
2559 | |
2585 | # $range->{range} = [$self->{pos}, 0, $self->{max_pos}, $page]; |
2560 | # $range->{range} = [$self->{pos}, 0, $self->{max_pos}, $page]; |
2586 | } |
2561 | } |
2587 | |
2562 | |
2588 | sub size_request { |
2563 | sub size_request { |
… | |
… | |
2675 | while (my ($k, $v) = each %{ $self->{item} }) { |
2650 | while (my ($k, $v) = each %{ $self->{item} }) { |
2676 | delete $self->{item}{$k} if $v->{timeout} < $NOW; |
2651 | delete $self->{item}{$k} if $v->{timeout} < $NOW; |
2677 | } |
2652 | } |
2678 | |
2653 | |
2679 | my @widgets; |
2654 | my @widgets; |
2680 | my @items = sort { $a->{time} <=> $b->{time} } values %{ $self->{item} }; |
2655 | |
|
|
2656 | my @items = sort { |
|
|
2657 | $a->{pri} <=> $b->{pri} |
|
|
2658 | or $b->{id} <=> $a->{id} |
|
|
2659 | } values %{ $self->{item} }; |
|
|
2660 | |
2681 | my $count = 10 + 1; |
2661 | my $count = 10 + 1; |
2682 | for my $item (@items) { |
2662 | for my $item (@items) { |
2683 | last unless --$count; |
2663 | last unless --$count; |
2684 | |
2664 | |
2685 | push @widgets, $item->{label} ||= do { |
2665 | push @widgets, $item->{label} ||= do { |
2686 | # TODO: doesn't handle markup well (read as: at all) |
2666 | # TODO: doesn't handle markup well (read as: at all) |
2687 | my $short = delete $item->{text}; |
2667 | my $short = $item->{count} > 1 |
|
|
2668 | ? "<b>$item->{count} ×</b> $item->{text}" |
|
|
2669 | : $item->{text}; |
|
|
2670 | |
2688 | for ($short) { |
2671 | for ($short) { |
2689 | s/^\s+//; |
2672 | s/^\s+//; |
2690 | s/\012.*//s; |
2673 | s/\012.*/…/s; |
2691 | my $len = int 30 / $item->{fontsize}; |
2674 | my $len = int 40 / $item->{fontsize}; |
2692 | substr $_, $len, length, "…" if $len < length; |
2675 | substr $_, $len, length, "…" if $len < length; |
2693 | } |
2676 | } |
2694 | |
2677 | |
2695 | new CFClient::UI::Label |
2678 | new CFClient::UI::Label |
2696 | markup => $short, |
2679 | markup => $short, |
2697 | tooltip => delete $item->{tooltip}, |
2680 | tooltip => $item->{tooltip}, |
|
|
2681 | tooltip_font => $::FONT_PROP, |
|
|
2682 | tooltip_width => 0.67, |
2698 | fontsize => delete $item->{fontsize}, |
2683 | fontsize => $item->{fontsize}, |
2699 | color => delete $item->{color}, |
2684 | color => $item->{color}, |
2700 | can_events => 1, |
2685 | can_events => 1, |
2701 | can_hover => 1, |
2686 | can_hover => 1 |
2702 | }; |
2687 | }; |
2703 | } |
2688 | } |
2704 | |
2689 | |
2705 | $self->clear; |
2690 | $self->clear; |
2706 | $self->SUPER::add (@widgets); |
2691 | $self->SUPER::add (reverse @widgets); |
2707 | } |
2692 | } |
2708 | |
2693 | |
2709 | sub add { |
2694 | sub add { |
2710 | my ($self, $text, %arg) = @_; |
2695 | my ($self, $text, %arg) = @_; |
2711 | |
2696 | |
2712 | my $item = { |
2697 | $text =~ s/^\s+//; |
2713 | time => time, |
2698 | $text =~ s/\s+$//; |
|
|
2699 | |
|
|
2700 | my $timeout = time + ((delete $arg{timeout}) || 60); |
|
|
2701 | |
|
|
2702 | my $group = exists $arg{group} ? $arg{group} : ++$self->{id}; |
|
|
2703 | |
|
|
2704 | if (my $item = $self->{item}{$group}) { |
|
|
2705 | if ($item->{text} eq $text) { |
|
|
2706 | $item->{count}++; |
|
|
2707 | } else { |
|
|
2708 | $item->{count} = 1; |
|
|
2709 | $item->{text} = $item->{tooltip} = $text; |
|
|
2710 | } |
|
|
2711 | $item->{id} = ++$self->{id}; |
|
|
2712 | $item->{timeout} = $timeout; |
|
|
2713 | delete $item->{label}; |
|
|
2714 | } else { |
|
|
2715 | $self->{item}{$group} = { |
|
|
2716 | id => ++$self->{id}, |
2714 | text => $text, |
2717 | text => $text, |
2715 | timeout => 60, |
2718 | timeout => $timeout, |
2716 | tooltip => $text, |
2719 | tooltip => $text, |
2717 | fontsize => 0.8, |
2720 | fontsize => 0.8, |
2718 | color => [0.8, 0.8, 0.8, 0.8], |
2721 | color => [0.8, 0.8, 0.8, 0.8], |
|
|
2722 | pri => 0, |
|
|
2723 | count => 1, |
2719 | %arg, |
2724 | %arg, |
|
|
2725 | }; |
2720 | }; |
2726 | } |
2721 | |
|
|
2722 | $item->{timeout} += time; |
|
|
2723 | $item->{group} ||= $item+0; |
|
|
2724 | |
|
|
2725 | $item = $self->{item}{$item->{group}} ||= $item; |
|
|
2726 | |
2727 | |
2727 | $self->reorder; |
2728 | $self->reorder; |
2728 | } |
2729 | } |
2729 | |
2730 | |
2730 | ############################################################################# |
2731 | ############################################################################# |
… | |
… | |
2827 | my ($self, $id, $cb) = @_; |
2828 | my ($self, $id, $cb) = @_; |
2828 | |
2829 | |
2829 | $self->{refresh_hook}{$id} = $cb; |
2830 | $self->{refresh_hook}{$id} = $cb; |
2830 | } |
2831 | } |
2831 | |
2832 | |
|
|
2833 | sub on_post_alloc { |
|
|
2834 | my ($self, $id, $cb) = @_; |
|
|
2835 | |
|
|
2836 | $self->{post_alloc_hook}{$id} = $cb; |
|
|
2837 | } |
|
|
2838 | |
2832 | sub draw { |
2839 | sub draw { |
2833 | my ($self) = @_; |
2840 | my ($self) = @_; |
|
|
2841 | |
|
|
2842 | while ($self->{refresh_hook}) { |
|
|
2843 | $_->() |
|
|
2844 | for values %{delete $self->{refresh_hook}}; |
|
|
2845 | } |
2834 | |
2846 | |
2835 | if ($self->{check_size}) { |
2847 | if ($self->{check_size}) { |
2836 | my @queue = ([], []); |
2848 | my @queue = ([], []); |
2837 | |
2849 | |
2838 | for (;;) { |
2850 | for (;;) { |
… | |
… | |
2846 | |
2858 | |
2847 | my ($w, $h) = $widget->{user_w} && $widget->{user_h} |
2859 | my ($w, $h) = $widget->{user_w} && $widget->{user_h} |
2848 | ? @$widget{qw(user_w user_h)} |
2860 | ? @$widget{qw(user_w user_h)} |
2849 | : $widget->size_request; |
2861 | : $widget->size_request; |
2850 | |
2862 | |
|
|
2863 | if (delete $widget->{force_alloc} |
2851 | if ($w != $widget->{req_w} || $h != $widget->{req_h}) { |
2864 | or $w != $widget->{req_w} or $h != $widget->{req_h}) { |
2852 | Carp::confess "$widget: size_request is negative" if $w < 0 || $h < 0;#d# |
2865 | Carp::confess "$widget: size_request is negative" if $w < 0 || $h < 0;#d# |
2853 | |
2866 | |
2854 | $widget->{req_w} = $w; |
2867 | $widget->{req_w} = $w; |
2855 | $widget->{req_h} = $h; |
2868 | $widget->{req_h} = $h; |
2856 | |
2869 | |
2857 | $self->{size_alloc}{$widget} = [$widget, $widget->{w}, $widget->{h}]; |
2870 | $self->{size_alloc}{$widget} = [$widget, $widget->{w} || $w, $widget->{h} || $h]; |
2858 | |
2871 | |
2859 | $widget->{parent}->check_size |
2872 | $widget->{parent}->check_size |
2860 | if $widget->{parent}; |
2873 | if $widget->{parent}; |
2861 | } |
2874 | } |
2862 | } |
2875 | } |
… | |
… | |
2874 | $widget->size_allocate ($w, $h); |
2887 | $widget->size_allocate ($w, $h); |
2875 | $widget->emit (size_allocate => $w, $h); |
2888 | $widget->emit (size_allocate => $w, $h); |
2876 | } |
2889 | } |
2877 | } |
2890 | } |
2878 | |
2891 | |
2879 | while ($self->{refresh_hook}) { |
2892 | while ($self->{post_alloc_hook}) { |
2880 | $_->() |
2893 | $_->() |
2881 | for values %{delete $self->{refresh_hook}}; |
2894 | for values %{delete $self->{post_alloc_hook}}; |
2882 | } |
2895 | } |
2883 | |
2896 | |
2884 | glViewport 0, 0, $::WIDTH, $::HEIGHT; |
2897 | glViewport 0, 0, $::WIDTH, $::HEIGHT; |
2885 | glClearColor +($::CFG->{fow_intensity}) x 3, 1; |
2898 | glClearColor +($::CFG->{fow_intensity}) x 3, 1; |
2886 | glClear GL_COLOR_BUFFER_BIT; |
2899 | glClear GL_COLOR_BUFFER_BIT; |