… | |
… | |
24 | my $tip = $widget->{tooltip}; |
24 | my $tip = $widget->{tooltip}; |
25 | |
25 | |
26 | $tip = $tip->($widget) if CODE:: eq ref $tip; |
26 | $tip = $tip->($widget) if CODE:: eq ref $tip; |
27 | |
27 | |
28 | $TOOLTIP->set_markup ($widget->{tooltip}); |
28 | $TOOLTIP->set_markup ($widget->{tooltip}); |
29 | $TOOLTIP->move ($widget->coord2global ($widget->{w}, 0)); |
29 | |
30 | $TOOLTIP->show; |
30 | $TOOLTIP->show; |
|
|
31 | |
|
|
32 | my ($x, $y) = $widget->coord2global ($widget->{w}, 0); |
|
|
33 | |
|
|
34 | if ($x + $TOOLTIP->{w} > $::WIDTH) { |
|
|
35 | ($x, $y) = $widget->coord2global (-$TOOLTIP->{w}, 0); |
|
|
36 | } |
|
|
37 | |
|
|
38 | $TOOLTIP->move ($x, $y); |
31 | } |
39 | } |
32 | |
40 | |
33 | return; |
41 | return; |
34 | } |
42 | } |
35 | } |
43 | } |
… | |
… | |
234 | } |
242 | } |
235 | } |
243 | } |
236 | |
244 | |
237 | sub size_allocate { |
245 | sub size_allocate { |
238 | # nothing to be done |
246 | # nothing to be done |
|
|
247 | } |
|
|
248 | |
|
|
249 | sub children { |
|
|
250 | } |
|
|
251 | |
|
|
252 | # call when resoltuion changes etc. |
|
|
253 | sub reconfigure { |
|
|
254 | my ($self) = @_; |
|
|
255 | |
|
|
256 | $_->reconfigure |
|
|
257 | for $self->children; |
|
|
258 | |
|
|
259 | $_->check_size; |
239 | } |
260 | } |
240 | |
261 | |
241 | sub set_max_size { |
262 | sub set_max_size { |
242 | my ($self, $w, $h) = @_; |
263 | my ($self, $w, $h) = @_; |
243 | |
264 | |
… | |
… | |
520 | ]; |
541 | ]; |
521 | |
542 | |
522 | $child->check_size; |
543 | $child->check_size; |
523 | } |
544 | } |
524 | |
545 | |
|
|
546 | sub children { |
|
|
547 | @{ $_[0]{children} } |
|
|
548 | } |
|
|
549 | |
525 | sub remove { |
550 | sub remove { |
526 | my ($self, $child) = @_; |
551 | my ($self, $child) = @_; |
527 | |
552 | |
528 | delete $child->{parent}; |
553 | delete $child->{parent}; |
529 | $child->hide; |
554 | $child->hide; |
… | |
… | |
626 | } |
651 | } |
627 | |
652 | |
628 | sub update { |
653 | sub update { |
629 | my ($self) = @_; |
654 | my ($self) = @_; |
630 | |
655 | |
631 | # we want to do this delayed... |
656 | $ROOT->on_refresh ($self => sub { $self->render_child }); |
632 | $self->render_chld; |
|
|
633 | $self->SUPER::update; |
657 | $self->SUPER::update; |
634 | } |
658 | } |
635 | |
659 | |
|
|
660 | sub size_allocate { |
|
|
661 | my ($self, $w, $h) = @_; |
|
|
662 | |
|
|
663 | $self->SUPER::size_allocate ($w, $h); |
|
|
664 | $self->update; |
|
|
665 | } |
|
|
666 | |
636 | sub render_chld { |
667 | sub render_child { |
637 | my ($self) = @_; |
668 | my ($self) = @_; |
638 | |
669 | |
639 | $self->{texture} = new_from_opengl CFClient::Texture $self->{w}, $self->{h}, sub { |
670 | $self->{texture} = new_from_opengl CFClient::Texture $self->{w}, $self->{h}, sub { |
640 | glClearColor 0, 0, 0, 1; |
671 | glClearColor 0, 0, 0, 0; |
641 | glClear GL_COLOR_BUFFER_BIT; |
672 | glClear GL_COLOR_BUFFER_BIT; |
642 | $self->child->draw; |
673 | $self->child->draw; |
643 | }; |
674 | }; |
644 | } |
675 | } |
645 | |
676 | |
646 | sub size_allocate { |
|
|
647 | my ($self, $w, $h) = @_; |
|
|
648 | |
|
|
649 | $self->child->configure (0, 0, $w, $h); |
|
|
650 | |
|
|
651 | $self->render_chld; |
|
|
652 | } |
|
|
653 | |
|
|
654 | sub _draw { |
677 | sub _draw { |
655 | my ($self) = @_; |
678 | my ($self) = @_; |
656 | |
679 | |
657 | my ($w, $h) = ($self->w, $self->h); |
680 | my ($w, $h) = ($self->w, $self->h); |
658 | |
681 | |
659 | my $tex = $self->{texture} |
682 | my $tex = $self->{texture} |
660 | or return; |
683 | or return; |
661 | |
684 | |
662 | glEnable GL_BLEND; |
685 | glEnable GL_BLEND; |
663 | glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA; |
686 | glBlendFunc GL_ONE, GL_ONE_MINUS_SRC_ALPHA; |
664 | glEnable GL_TEXTURE_2D; |
687 | glEnable GL_TEXTURE_2D; |
665 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; |
688 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; |
|
|
689 | glColor 0, 0, 0, 1; |
666 | |
690 | |
667 | $tex->draw_quad (0, 0, $w, $h); |
691 | $tex->draw_quad (0, 0, $w, $h); |
668 | |
692 | |
669 | glDisable GL_BLEND; |
693 | glDisable GL_BLEND; |
670 | glDisable GL_TEXTURE_2D; |
694 | glDisable GL_TEXTURE_2D; |
… | |
… | |
915 | $self->{children}[$y][$x] = $child; |
939 | $self->{children}[$y][$x] = $child; |
916 | |
940 | |
917 | $child->check_size; |
941 | $child->check_size; |
918 | } |
942 | } |
919 | |
943 | |
|
|
944 | sub children { |
|
|
945 | grep $_, map @$_, grep $_, @{ $_[0]{children} } |
|
|
946 | } |
|
|
947 | |
920 | # TODO: move to container class maybe? send childs a signal on removal? |
948 | # TODO: move to container class maybe? send childs a signal on removal? |
921 | sub clear { |
949 | sub clear { |
922 | my ($self) = @_; |
950 | my ($self) = @_; |
923 | |
951 | |
924 | my $children = delete $self->{children}; |
952 | my @children = $self->children; |
|
|
953 | delete $self->{children}; |
925 | |
954 | |
926 | for (grep $_, map @$_, grep $_, @$children) { |
955 | for (@children) { |
927 | delete $_->{parent}; |
956 | delete $_->{parent}; |
928 | $_->hide; |
957 | $_->hide; |
929 | } |
958 | } |
930 | |
959 | |
931 | $self->update; |
960 | $self->update; |
… | |
… | |
1192 | s/</</g; |
1221 | s/</</g; |
1193 | |
1222 | |
1194 | $_[1] |
1223 | $_[1] |
1195 | } |
1224 | } |
1196 | |
1225 | |
|
|
1226 | sub update { |
|
|
1227 | my ($self) = @_; |
|
|
1228 | |
|
|
1229 | delete $self->{texture}; |
|
|
1230 | $self->SUPER::update; |
|
|
1231 | } |
|
|
1232 | |
|
|
1233 | sub reconfigure { |
|
|
1234 | my ($self) = @_; |
|
|
1235 | |
|
|
1236 | delete $self->{texture}; |
|
|
1237 | } |
|
|
1238 | |
1197 | sub set_text { |
1239 | sub set_text { |
1198 | my ($self, $text) = @_; |
1240 | my ($self, $text) = @_; |
1199 | |
1241 | |
|
|
1242 | return if $self->{text} eq "T$text"; |
|
|
1243 | $self->{text} = "T$text"; |
|
|
1244 | |
1200 | $self->{layout}->set_text ($text); |
1245 | $self->{layout}->set_text ($text); |
1201 | |
1246 | |
1202 | delete $self->{texture}; |
1247 | delete $self->{texture}; |
|
|
1248 | $self->update; |
1203 | $self->check_size; |
1249 | $self->check_size; |
1204 | $self->update; |
|
|
1205 | } |
1250 | } |
1206 | |
1251 | |
1207 | sub set_markup { |
1252 | sub set_markup { |
1208 | my ($self, $markup) = @_; |
1253 | my ($self, $markup) = @_; |
1209 | |
1254 | |
|
|
1255 | return if $self->{text} eq "M$markup"; |
|
|
1256 | $self->{text} = "M$markup"; |
|
|
1257 | |
1210 | $self->{layout}->set_markup ($markup); |
1258 | $self->{layout}->set_markup ($markup); |
1211 | |
1259 | |
1212 | delete $self->{texture}; |
1260 | delete $self->{texture}; |
|
|
1261 | $self->update; |
1213 | $self->check_size; |
1262 | $self->check_size; |
1214 | $self->update; |
|
|
1215 | } |
1263 | } |
1216 | |
1264 | |
1217 | sub size_request { |
1265 | sub size_request { |
1218 | my ($self) = @_; |
1266 | my ($self) = @_; |
1219 | |
1267 | |
… | |
… | |
1743 | } |
1791 | } |
1744 | |
1792 | |
1745 | sub set_max { |
1793 | sub set_max { |
1746 | my ($self, $max) = @_; |
1794 | my ($self, $max) = @_; |
1747 | |
1795 | |
|
|
1796 | return if $self->{max_val} == $max; |
|
|
1797 | |
1748 | $self->{max_val} = $max; |
1798 | $self->{max_val} = $max; |
|
|
1799 | $self->update; |
1749 | } |
1800 | } |
1750 | |
1801 | |
1751 | sub set_value { |
1802 | sub set_value { |
1752 | my ($self, $val, $max) = @_; |
1803 | my ($self, $val, $max) = @_; |
1753 | |
1804 | |
1754 | $self->set_max ($max) |
1805 | $self->set_max ($max) |
1755 | if defined $max; |
1806 | if defined $max; |
1756 | |
1807 | |
1757 | $max = $self->{max_val}; |
1808 | return if $self->{val} == $val; |
|
|
1809 | |
1758 | $self->{val} = $val; |
1810 | $self->{val} = $val; |
1759 | |
|
|
1760 | $self->update; |
1811 | $self->update; |
1761 | } |
1812 | } |
1762 | |
1813 | |
1763 | sub _draw { |
1814 | sub _draw { |
1764 | my ($self) = @_; |
1815 | my ($self) = @_; |
… | |
… | |
1827 | |
1878 | |
1828 | sub new { |
1879 | sub new { |
1829 | my ($class, %arg) = @_; |
1880 | my ($class, %arg) = @_; |
1830 | |
1881 | |
1831 | my $self = $class->SUPER::new ( |
1882 | my $self = $class->SUPER::new ( |
1832 | tooltip => $arg{type}, |
1883 | tooltip => $arg{type}, |
1833 | can_hover => 1, |
1884 | can_hover => 1, |
|
|
1885 | can_events => 1, |
1834 | %arg, |
1886 | %arg, |
1835 | ); |
1887 | ); |
1836 | |
1888 | |
1837 | $self->add ($self->{value} = new CFClient::UI::Label valign => +1, align => 0, template => "999"); |
1889 | $self->add ($self->{value} = new CFClient::UI::Label valign => +1, align => 0, template => "999"); |
1838 | $self->add ($self->{gauge} = new CFClient::UI::VGauge type => $self->{type}, expand => 1, can_hover => 1); |
1890 | $self->add ($self->{gauge} = new CFClient::UI::VGauge type => $self->{type}, expand => 1, can_hover => 1); |
… | |
… | |
1846 | |
1898 | |
1847 | $self->{value}->set_fontsize ($fsize); |
1899 | $self->{value}->set_fontsize ($fsize); |
1848 | $self->{max} ->set_fontsize ($fsize); |
1900 | $self->{max} ->set_fontsize ($fsize); |
1849 | } |
1901 | } |
1850 | |
1902 | |
|
|
1903 | sub set_max { |
|
|
1904 | my ($self, $max) = @_; |
|
|
1905 | |
|
|
1906 | $self->{gauge}->set_max ($max); |
|
|
1907 | $self->{max}->set_text ($max); |
|
|
1908 | } |
|
|
1909 | |
1851 | sub set_value { |
1910 | sub set_value { |
1852 | my ($self, $val, $max) = @_; |
1911 | my ($self, $val, $max) = @_; |
1853 | |
1912 | |
1854 | $self->set_max ($max) |
1913 | $self->set_max ($max) |
1855 | if defined $max; |
1914 | if defined $max; |
1856 | |
1915 | |
1857 | $self->{gauge}->set_value ($val, $max); |
1916 | $self->{gauge}->set_value ($val, $max); |
1858 | $self->{value}->set_text ($val); |
1917 | $self->{value}->set_text ($val); |
1859 | } |
|
|
1860 | |
|
|
1861 | sub set_max { |
|
|
1862 | my ($self, $max) = @_; |
|
|
1863 | |
|
|
1864 | $self->{gauge}->set_max ($max); |
|
|
1865 | $self->{max}->set_text ($max); |
|
|
1866 | } |
1918 | } |
1867 | |
1919 | |
1868 | ############################################################################# |
1920 | ############################################################################# |
1869 | |
1921 | |
1870 | package CFClient::UI::Slider; |
1922 | package CFClient::UI::Slider; |
… | |
… | |
2153 | my ($self) = @_; |
2205 | my ($self) = @_; |
2154 | |
2206 | |
2155 | if ($self->{texture}) { |
2207 | if ($self->{texture}) { |
2156 | glEnable GL_TEXTURE_2D; |
2208 | glEnable GL_TEXTURE_2D; |
2157 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; |
2209 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; |
|
|
2210 | glColor 1, 1, 1, 1; |
2158 | $self->{texture}->draw_quad (0, 0, $self->{w}, $self->{h}); |
2211 | $self->{texture}->draw_quad (0, 0, $self->{w}, $self->{h}); |
2159 | glDisable GL_TEXTURE_2D; |
2212 | glDisable GL_TEXTURE_2D; |
2160 | } |
2213 | } |
2161 | |
2214 | |
2162 | $self->{children}[1]->draw; |
2215 | $self->{children}[1]->draw; |