… | |
… | |
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 | } |
… | |
… | |
236 | |
244 | |
237 | sub size_allocate { |
245 | sub size_allocate { |
238 | # nothing to be done |
246 | # nothing to be done |
239 | } |
247 | } |
240 | |
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; |
|
|
260 | } |
|
|
261 | |
241 | sub set_max_size { |
262 | sub set_max_size { |
242 | my ($self, $w, $h) = @_; |
263 | my ($self, $w, $h) = @_; |
243 | |
264 | |
244 | delete $self->{max_w}; $self->{max_w} = $w if $w; |
265 | delete $self->{max_w}; $self->{max_w} = $w if $w; |
245 | delete $self->{max_h}; $self->{max_h} = $h if $h; |
266 | delete $self->{max_h}; $self->{max_h} = $h if $h; |
246 | } |
267 | } |
247 | |
268 | |
248 | # return top left coordinates |
269 | # return top left coordinates |
249 | sub _topleft { |
270 | sub _topleft { |
250 | my ($self, $x, $y) = @_; |
271 | my ($self, $x, $y) = @_; |
|
|
272 | |
|
|
273 | $self->{parent} |
|
|
274 | or Carp::confess "no parent widget in _topleft\n";#d# |
251 | |
275 | |
252 | $self->{parent}->_topleft ($x + $self->{x}, $y + $self->{y}); |
276 | $self->{parent}->_topleft ($x + $self->{x}, $y + $self->{y}); |
253 | } |
277 | } |
254 | |
278 | |
255 | # translate global coordinates to local coordinate system |
279 | # translate global coordinates to local coordinate system |
… | |
… | |
517 | ]; |
541 | ]; |
518 | |
542 | |
519 | $child->check_size; |
543 | $child->check_size; |
520 | } |
544 | } |
521 | |
545 | |
|
|
546 | sub children { |
|
|
547 | @{ $_[0]{children} } |
|
|
548 | } |
|
|
549 | |
522 | sub remove { |
550 | sub remove { |
523 | my ($self, $child) = @_; |
551 | my ($self, $child) = @_; |
524 | |
552 | |
525 | delete $child->{parent}; |
553 | delete $child->{parent}; |
526 | $child->hide; |
554 | $child->hide; |
… | |
… | |
623 | } |
651 | } |
624 | |
652 | |
625 | sub update { |
653 | sub update { |
626 | my ($self) = @_; |
654 | my ($self) = @_; |
627 | |
655 | |
628 | # we want to do this delayed... |
656 | $ROOT->on_refresh ($self => sub { $self->render_child }); |
629 | $self->render_chld; |
|
|
630 | $self->SUPER::update; |
657 | $self->SUPER::update; |
631 | } |
658 | } |
632 | |
659 | |
|
|
660 | sub size_allocate { |
|
|
661 | my ($self, $w, $h) = @_; |
|
|
662 | |
|
|
663 | $self->SUPER::size_allocate ($w, $h); |
|
|
664 | $self->update; |
|
|
665 | } |
|
|
666 | |
633 | sub render_chld { |
667 | sub render_child { |
634 | my ($self) = @_; |
668 | my ($self) = @_; |
635 | |
669 | |
636 | $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 { |
637 | glClearColor 0, 0, 0, 1; |
671 | glClearColor 0, 0, 0, 0; |
638 | glClear GL_COLOR_BUFFER_BIT; |
672 | glClear GL_COLOR_BUFFER_BIT; |
639 | $self->child->draw; |
673 | $self->child->draw; |
|
|
674 | # glColorMask 1, 1, 1, 0; |
|
|
675 | # glEnable GL_BLEND; |
|
|
676 | # glBlendFunc GL_SRC_ALPHA, GL_ZERO; |
|
|
677 | # glRasterPos 0, 0; |
|
|
678 | # glCopyPixels 0, 0, $self->{w}, $self->{h}; |
|
|
679 | # glDisable GL_BLEND; |
|
|
680 | # glColorMask 1, 1, 1, 1; |
640 | }; |
681 | }; |
641 | } |
|
|
642 | |
|
|
643 | sub size_allocate { |
|
|
644 | my ($self, $w, $h) = @_; |
|
|
645 | |
|
|
646 | $self->child->configure (0, 0, $w, $h); |
|
|
647 | |
|
|
648 | $self->render_chld; |
|
|
649 | } |
682 | } |
650 | |
683 | |
651 | sub _draw { |
684 | sub _draw { |
652 | my ($self) = @_; |
685 | my ($self) = @_; |
653 | |
686 | |
… | |
… | |
655 | |
688 | |
656 | my $tex = $self->{texture} |
689 | my $tex = $self->{texture} |
657 | or return; |
690 | or return; |
658 | |
691 | |
659 | glEnable GL_BLEND; |
692 | glEnable GL_BLEND; |
660 | glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA; |
693 | glBlendFunc GL_ONE, GL_ONE_MINUS_SRC_ALPHA; |
661 | glEnable GL_TEXTURE_2D; |
694 | glEnable GL_TEXTURE_2D; |
662 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; |
695 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; |
|
|
696 | glColor 0, 0, 0, 1; |
663 | |
697 | |
664 | $tex->draw_quad (0, 0, $w, $h); |
698 | $tex->draw_quad (0, 0, $w, $h); |
665 | |
699 | |
666 | glDisable GL_BLEND; |
700 | glDisable GL_BLEND; |
667 | glDisable GL_TEXTURE_2D; |
701 | glDisable GL_TEXTURE_2D; |
… | |
… | |
754 | # TODO: user_x, user_y, overwrite moveto? |
788 | # TODO: user_x, user_y, overwrite moveto? |
755 | |
789 | |
756 | my $self = $class->SUPER::new ( |
790 | my $self = $class->SUPER::new ( |
757 | bg => [1, 1, 1, 1], |
791 | bg => [1, 1, 1, 1], |
758 | border_bg => [1, 1, 1, 1], |
792 | border_bg => [1, 1, 1, 1], |
759 | border => 0.8, |
793 | border => 0.6, |
760 | can_events => 1, |
794 | can_events => 1, |
761 | @_ |
795 | @_ |
762 | ); |
796 | ); |
763 | |
797 | |
764 | $self->{title} &&= new CFClient::UI::Label |
798 | $self->{title} &&= new CFClient::UI::Label |
765 | align => 0, |
799 | align => 0, |
766 | valign => 1, |
800 | valign => 1, |
767 | text => $self->{title}, |
801 | text => $self->{title}, |
768 | fontsize => 1; |
802 | fontsize => $self->{border}; |
769 | |
803 | |
770 | $self |
804 | $self |
771 | } |
805 | } |
772 | |
806 | |
773 | sub border { |
807 | sub border { |
… | |
… | |
798 | } |
832 | } |
799 | |
833 | |
800 | sub button_down { |
834 | sub button_down { |
801 | my ($self, $ev, $x, $y) = @_; |
835 | my ($self, $ev, $x, $y) = @_; |
802 | |
836 | |
|
|
837 | my ($w, $h) = @$self{qw(w h)}; |
803 | my $border = $self->border; |
838 | my $border = $self->border; |
804 | |
839 | |
805 | if ($x < $self->{w} && $x >= $self->{w} - $border |
840 | my $lr = ($x >= 0 && $x < $border) || ($x > $w - $border && $x < $w); |
806 | && $y < $self->{h} && $y >= $self->{h} - $border) { |
841 | my $td = ($y >= 0 && $y < $border) || ($y > $h - $border && $y < $h); |
807 | |
842 | |
|
|
843 | if ($lr & $td) { |
|
|
844 | my ($wx, $wy) = ($self->{x}, $self->{y}); |
808 | my ($ox, $oy) = ($ev->{x}, $ev->{y}); |
845 | my ($ox, $oy) = ($ev->{x}, $ev->{y}); |
809 | my ($bw, $bh) = ($self->{w}, $self->{h}); |
846 | my ($bw, $bh) = ($self->{w}, $self->{h}); |
810 | |
847 | |
|
|
848 | my $mx = $x < $border; |
|
|
849 | my $my = $y < $border; |
|
|
850 | |
811 | $self->{motion} = sub { |
851 | $self->{motion} = sub { |
812 | my ($ev, $x, $y) = @_; |
852 | my ($ev, $x, $y) = @_; |
813 | |
853 | |
814 | ($x, $y) = ($ev->{x}, $ev->{y}); |
854 | my $dx = $ev->{x} - $ox; |
|
|
855 | my $dy = $ev->{y} - $oy; |
815 | |
856 | |
816 | $self->{user_w} = $bw + $x - $ox; |
857 | $self->{user_w} = $bw + $dx * ($mx ? -1 : 1); |
817 | $self->{user_h} = $bh + $y - $oy; |
858 | $self->{user_h} = $bh + $dy * ($my ? -1 : 1); |
|
|
859 | $self->move ($wx + $dx * $mx, $wy + $dy * $my); |
818 | $self->check_size; |
860 | $self->check_size; |
819 | }; |
861 | }; |
820 | |
862 | |
821 | } elsif ($x >= 0 && $x < $self->{w} |
863 | } elsif ($lr ^ $td) { |
822 | && $y >= 0 && $y < $border) { |
|
|
823 | |
|
|
824 | my ($ox, $oy) = ($ev->{x}, $ev->{y}); |
864 | my ($ox, $oy) = ($ev->{x}, $ev->{y}); |
825 | my ($bx, $by) = ($self->{x}, $self->{y}); |
865 | my ($bx, $by) = ($self->{x}, $self->{y}); |
826 | |
866 | |
827 | $self->{motion} = sub { |
867 | $self->{motion} = sub { |
828 | my ($ev, $x, $y) = @_; |
868 | my ($ev, $x, $y) = @_; |
… | |
… | |
864 | $tex[1]->draw_quad (0, 0, $w, $border); |
904 | $tex[1]->draw_quad (0, 0, $w, $border); |
865 | $tex[3]->draw_quad (0, $border, $border, $ch); |
905 | $tex[3]->draw_quad (0, $border, $border, $ch); |
866 | $tex[2]->draw_quad ($w - $border, $border, $border, $ch); |
906 | $tex[2]->draw_quad ($w - $border, $border, $border, $ch); |
867 | $tex[4]->draw_quad (0, $h - $border, $w, $border); |
907 | $tex[4]->draw_quad (0, $h - $border, $w, $border); |
868 | |
908 | |
|
|
909 | if (@{$self->{bg}} < 4 || $self->{bg}[3]) { |
869 | my $bg = $tex[0]; |
910 | my $bg = $tex[0]; |
870 | |
911 | |
871 | # TODO: repeat texture not scale |
912 | # TODO: repeat texture not scale |
872 | my $rep_x = $cw / $bg->{w}; |
913 | my $rep_x = $cw / $bg->{w}; |
873 | my $rep_y = $ch / $bg->{h}; |
914 | my $rep_y = $ch / $bg->{h}; |
874 | |
915 | |
875 | glColor @{ $self->{bg} }; |
916 | glColor @{ $self->{bg} }; |
876 | |
917 | |
877 | $bg->{s} = $rep_x; |
918 | $bg->{s} = $rep_x; |
878 | $bg->{t} = $rep_y; |
919 | $bg->{t} = $rep_y; |
879 | $bg->{wrap_mode} = 1; |
920 | $bg->{wrap_mode} = 1; |
880 | $bg->draw_quad ($border, $border, $cw, $ch); |
921 | $bg->draw_quad ($border, $border, $cw, $ch); |
881 | |
922 | |
882 | glDisable GL_TEXTURE_2D; |
923 | glDisable GL_TEXTURE_2D; |
883 | glDisable GL_BLEND; |
924 | glDisable GL_BLEND; |
|
|
925 | } |
884 | |
926 | |
885 | $self->{title}->draw if $self->{title}; |
927 | $self->{title}->draw if $self->{title}; |
|
|
928 | |
886 | $self->child->draw; |
929 | $self->child->draw; |
887 | } |
930 | } |
888 | |
931 | |
889 | ############################################################################# |
932 | ############################################################################# |
890 | |
933 | |
… | |
… | |
912 | $self->{children}[$y][$x] = $child; |
955 | $self->{children}[$y][$x] = $child; |
913 | |
956 | |
914 | $child->check_size; |
957 | $child->check_size; |
915 | } |
958 | } |
916 | |
959 | |
|
|
960 | sub children { |
|
|
961 | grep $_, map @$_, grep $_, @{ $_[0]{children} } |
|
|
962 | } |
|
|
963 | |
917 | # TODO: move to container class maybe? send childs a signal on removal? |
964 | # TODO: move to container class maybe? send childs a signal on removal? |
918 | sub clear { |
965 | sub clear { |
919 | my ($self) = @_; |
966 | my ($self) = @_; |
920 | |
967 | |
921 | my $children = delete $self->{children}; |
968 | my @children = $self->children; |
|
|
969 | delete $self->{children}; |
922 | |
970 | |
923 | for (grep $_, map @$_, grep $_, @$children) { |
971 | for (@children) { |
924 | delete $_->{parent}; |
972 | delete $_->{parent}; |
925 | $_->hide; |
973 | $_->hide; |
926 | } |
974 | } |
927 | |
975 | |
928 | $self->update; |
976 | $self->update; |
… | |
… | |
1189 | s/</</g; |
1237 | s/</</g; |
1190 | |
1238 | |
1191 | $_[1] |
1239 | $_[1] |
1192 | } |
1240 | } |
1193 | |
1241 | |
|
|
1242 | sub update { |
|
|
1243 | my ($self) = @_; |
|
|
1244 | |
|
|
1245 | delete $self->{texture}; |
|
|
1246 | $self->SUPER::update; |
|
|
1247 | } |
|
|
1248 | |
|
|
1249 | sub reconfigure { |
|
|
1250 | my ($self) = @_; |
|
|
1251 | |
|
|
1252 | delete $self->{texture}; |
|
|
1253 | } |
|
|
1254 | |
1194 | sub set_text { |
1255 | sub set_text { |
1195 | my ($self, $text) = @_; |
1256 | my ($self, $text) = @_; |
1196 | |
1257 | |
|
|
1258 | return if $self->{text} eq "T$text"; |
|
|
1259 | $self->{text} = "T$text"; |
|
|
1260 | |
1197 | $self->{layout}->set_text ($text); |
1261 | $self->{layout}->set_text ($text); |
1198 | |
1262 | |
1199 | delete $self->{texture}; |
1263 | delete $self->{texture}; |
|
|
1264 | $self->update; |
1200 | $self->check_size; |
1265 | $self->check_size; |
1201 | $self->update; |
|
|
1202 | } |
1266 | } |
1203 | |
1267 | |
1204 | sub set_markup { |
1268 | sub set_markup { |
1205 | my ($self, $markup) = @_; |
1269 | my ($self, $markup) = @_; |
1206 | |
1270 | |
|
|
1271 | return if $self->{text} eq "M$markup"; |
|
|
1272 | $self->{text} = "M$markup"; |
|
|
1273 | |
1207 | $self->{layout}->set_markup ($markup); |
1274 | $self->{layout}->set_markup ($markup); |
1208 | |
1275 | |
1209 | delete $self->{texture}; |
1276 | delete $self->{texture}; |
|
|
1277 | $self->update; |
1210 | $self->check_size; |
1278 | $self->check_size; |
1211 | $self->update; |
|
|
1212 | } |
1279 | } |
1213 | |
1280 | |
1214 | sub size_request { |
1281 | sub size_request { |
1215 | my ($self) = @_; |
1282 | my ($self) = @_; |
1216 | |
1283 | |
… | |
… | |
1469 | |
1536 | |
1470 | if ($sym == 13) { |
1537 | if ($sym == 13) { |
1471 | unshift @{$self->{history}}, |
1538 | unshift @{$self->{history}}, |
1472 | my $txt = $self->get_text; |
1539 | my $txt = $self->get_text; |
1473 | $self->{history_pointer} = -1; |
1540 | $self->{history_pointer} = -1; |
|
|
1541 | $self->{history_saveback} = ''; |
1474 | $self->emit (activate => $txt); |
1542 | $self->emit (activate => $txt); |
1475 | $self->update; |
1543 | $self->update; |
1476 | |
1544 | |
1477 | } elsif ($sym == CFClient::SDLK_UP) { |
1545 | } elsif ($sym == CFClient::SDLK_UP) { |
1478 | if ($self->{history_pointer} < 0) { |
1546 | if ($self->{history_pointer} < 0) { |
1479 | $self->{history_saveback} = $self->get_text; |
1547 | $self->{history_saveback} = $self->get_text; |
1480 | } |
1548 | } |
|
|
1549 | if (@{$self->{history} || []} > 0) { |
1481 | $self->{history_pointer}++; |
1550 | $self->{history_pointer}++; |
1482 | if ($self->{history_pointer} >= @{$self->{history}}) { |
1551 | if ($self->{history_pointer} >= @{$self->{history} || []}) { |
1483 | $self->{history_pointer} = @{$self->{history}} - 1; |
1552 | $self->{history_pointer} = @{$self->{history} || []} - 1; |
|
|
1553 | } |
|
|
1554 | $self->set_text ($self->{history}->[$self->{history_pointer}]); |
1484 | } |
1555 | } |
1485 | $self->set_text ($self->{history}->[$self->{history_pointer}]); |
|
|
1486 | |
1556 | |
1487 | } elsif ($sym == CFClient::SDLK_DOWN) { |
1557 | } elsif ($sym == CFClient::SDLK_DOWN) { |
1488 | $self->{history_pointer}--; |
1558 | $self->{history_pointer}--; |
1489 | $self->{history_pointer} = -1 if $self->{history_pointer} < 0; |
1559 | $self->{history_pointer} = -1 if $self->{history_pointer} < 0; |
1490 | |
1560 | |
… | |
… | |
1737 | } |
1807 | } |
1738 | |
1808 | |
1739 | sub set_max { |
1809 | sub set_max { |
1740 | my ($self, $max) = @_; |
1810 | my ($self, $max) = @_; |
1741 | |
1811 | |
|
|
1812 | return if $self->{max_val} == $max; |
|
|
1813 | |
1742 | $self->{max_val} = $max; |
1814 | $self->{max_val} = $max; |
|
|
1815 | $self->update; |
1743 | } |
1816 | } |
1744 | |
1817 | |
1745 | sub set_value { |
1818 | sub set_value { |
1746 | my ($self, $val, $max) = @_; |
1819 | my ($self, $val, $max) = @_; |
1747 | |
1820 | |
1748 | $self->set_max ($max) |
1821 | $self->set_max ($max) |
1749 | if defined $max; |
1822 | if defined $max; |
1750 | |
1823 | |
1751 | $max = $self->{max_val}; |
1824 | return if $self->{val} == $val; |
|
|
1825 | |
1752 | $self->{val} = $val; |
1826 | $self->{val} = $val; |
1753 | |
|
|
1754 | $self->update; |
1827 | $self->update; |
1755 | } |
1828 | } |
1756 | |
1829 | |
1757 | sub _draw { |
1830 | sub _draw { |
1758 | my ($self) = @_; |
1831 | my ($self) = @_; |
… | |
… | |
1821 | |
1894 | |
1822 | sub new { |
1895 | sub new { |
1823 | my ($class, %arg) = @_; |
1896 | my ($class, %arg) = @_; |
1824 | |
1897 | |
1825 | my $self = $class->SUPER::new ( |
1898 | my $self = $class->SUPER::new ( |
1826 | tooltip => $arg{type}, |
1899 | tooltip => $arg{type}, |
1827 | can_hover => 1, |
1900 | can_hover => 1, |
|
|
1901 | can_events => 1, |
1828 | %arg, |
1902 | %arg, |
1829 | ); |
1903 | ); |
1830 | |
1904 | |
1831 | $self->add ($self->{value} = new CFClient::UI::Label valign => +1, align => 0, template => "999"); |
1905 | $self->add ($self->{value} = new CFClient::UI::Label valign => +1, align => 0, template => "999"); |
1832 | $self->add ($self->{gauge} = new CFClient::UI::VGauge type => $self->{type}, expand => 1, can_hover => 1); |
1906 | $self->add ($self->{gauge} = new CFClient::UI::VGauge type => $self->{type}, expand => 1, can_hover => 1); |
… | |
… | |
1840 | |
1914 | |
1841 | $self->{value}->set_fontsize ($fsize); |
1915 | $self->{value}->set_fontsize ($fsize); |
1842 | $self->{max} ->set_fontsize ($fsize); |
1916 | $self->{max} ->set_fontsize ($fsize); |
1843 | } |
1917 | } |
1844 | |
1918 | |
|
|
1919 | sub set_max { |
|
|
1920 | my ($self, $max) = @_; |
|
|
1921 | |
|
|
1922 | $self->{gauge}->set_max ($max); |
|
|
1923 | $self->{max}->set_text ($max); |
|
|
1924 | } |
|
|
1925 | |
1845 | sub set_value { |
1926 | sub set_value { |
1846 | my ($self, $val, $max) = @_; |
1927 | my ($self, $val, $max) = @_; |
1847 | |
1928 | |
1848 | $self->set_max ($max) |
1929 | $self->set_max ($max) |
1849 | if defined $max; |
1930 | if defined $max; |
1850 | |
1931 | |
1851 | $self->{gauge}->set_value ($val, $max); |
1932 | $self->{gauge}->set_value ($val, $max); |
1852 | $self->{value}->set_text ($val); |
1933 | $self->{value}->set_text ($val); |
1853 | } |
|
|
1854 | |
|
|
1855 | sub set_max { |
|
|
1856 | my ($self, $max) = @_; |
|
|
1857 | |
|
|
1858 | $self->{gauge}->set_max ($max); |
|
|
1859 | $self->{max}->set_text ($max); |
|
|
1860 | } |
1934 | } |
1861 | |
1935 | |
1862 | ############################################################################# |
1936 | ############################################################################# |
1863 | |
1937 | |
1864 | package CFClient::UI::Slider; |
1938 | package CFClient::UI::Slider; |
… | |
… | |
2018 | (new CFClient::UI::Empty expand => 1), |
2092 | (new CFClient::UI::Empty expand => 1), |
2019 | (new CFClient::UI::Slider vertical => 1), |
2093 | (new CFClient::UI::Slider vertical => 1), |
2020 | ], |
2094 | ], |
2021 | ); |
2095 | ); |
2022 | |
2096 | |
2023 | $self->{children}[1]->connect (changed => sub { |
2097 | $self->{children}[1]->connect (changed => sub { $self->update }); |
2024 | $self->update; |
|
|
2025 | }); |
|
|
2026 | |
2098 | |
2027 | $self |
2099 | $self |
2028 | } |
2100 | } |
2029 | |
2101 | |
2030 | sub set_fontsize { |
2102 | sub set_fontsize { |
… | |
… | |
2038 | my ($self, $text) = @_; |
2110 | my ($self, $text) = @_; |
2039 | |
2111 | |
2040 | my $layout = $self->{layout}; |
2112 | my $layout = $self->{layout}; |
2041 | |
2113 | |
2042 | $layout->set_height ($self->{fontsize} * $::FONTSIZE); |
2114 | $layout->set_height ($self->{fontsize} * $::FONTSIZE); |
2043 | $layout->set_width ($self->{w}); |
2115 | $layout->set_width ($self->{children}[0]{w}); |
2044 | $layout->set_text ($text); |
2116 | $layout->set_text ($text); |
2045 | |
2117 | |
2046 | ($layout->size)[1] |
2118 | ($layout->size)[1] |
2047 | } |
2119 | } |
2048 | |
2120 | |
… | |
… | |
2101 | $self->{children}[1]{range} = [$height - $self->{h}, 0, $height, $self->{h}]; |
2173 | $self->{children}[1]{range} = [$height - $self->{h}, 0, $height, $self->{h}]; |
2102 | |
2174 | |
2103 | delete $self->{texture}; |
2175 | delete $self->{texture}; |
2104 | } |
2176 | } |
2105 | |
2177 | |
2106 | $self->{texture} ||= new_from_opengl CFClient::Texture $self->{w}, $self->{h}, sub { |
2178 | $self->{texture} ||= new_from_opengl CFClient::Texture $self->{children}[0]{w}, $self->{children}[0]{h}, sub { |
2107 | glClearColor 0, 0, 0, 1; |
2179 | glClearColor 0, 0, 0, 0; |
2108 | glClear GL_COLOR_BUFFER_BIT; |
2180 | glClear GL_COLOR_BUFFER_BIT; |
2109 | |
2181 | |
2110 | glEnable GL_BLEND; |
2182 | glEnable GL_BLEND; |
2111 | glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA; |
2183 | glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA; |
2112 | glEnable GL_TEXTURE_2D; |
2184 | glEnable GL_TEXTURE_2D; |
… | |
… | |
2144 | } |
2216 | } |
2145 | |
2217 | |
2146 | sub _draw { |
2218 | sub _draw { |
2147 | my ($self) = @_; |
2219 | my ($self) = @_; |
2148 | |
2220 | |
2149 | if ($self->{texture}) { |
2221 | glEnable GL_BLEND; |
|
|
2222 | glBlendFunc GL_ONE, GL_ONE_MINUS_SRC_ALPHA; |
2150 | glEnable GL_TEXTURE_2D; |
2223 | glEnable GL_TEXTURE_2D; |
2151 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; |
2224 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; |
|
|
2225 | glColor 1, 1, 1, 1; |
2152 | $self->{texture}->draw_quad (0, 0, $self->{w}, $self->{h}); |
2226 | $self->{texture}->draw_quad (0, 0, $self->{children}[0]{w}, $self->{children}[0]{h}); |
2153 | glDisable GL_TEXTURE_2D; |
2227 | glDisable GL_TEXTURE_2D; |
2154 | } |
2228 | glDisable GL_BLEND; |
2155 | |
2229 | |
2156 | $self->{children}[1]->draw; |
2230 | $self->{children}[1]->draw; |
2157 | |
2231 | |
2158 | } |
2232 | } |
2159 | |
2233 | |
… | |
… | |
2333 | sub draw { |
2407 | sub draw { |
2334 | my ($self) = @_; |
2408 | my ($self) = @_; |
2335 | |
2409 | |
2336 | my $tex = $::CONN->{texture}[$::CONN->{faceid}[$self->{face}]]; |
2410 | my $tex = $::CONN->{texture}[$::CONN->{faceid}[$self->{face}]]; |
2337 | |
2411 | |
|
|
2412 | # TODO animation |
2338 | if ($tex) { |
2413 | if ($tex) { |
2339 | glEnable GL_BLEND; |
2414 | glEnable GL_BLEND; |
2340 | glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA; |
2415 | glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA; |
2341 | glEnable GL_TEXTURE_2D; |
2416 | glEnable GL_TEXTURE_2D; |
2342 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; |
2417 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; |
… | |
… | |
2347 | } |
2422 | } |
2348 | } |
2423 | } |
2349 | |
2424 | |
2350 | ############################################################################# |
2425 | ############################################################################# |
2351 | |
2426 | |
|
|
2427 | package CFClient::UI::Menu; |
|
|
2428 | |
|
|
2429 | our @ISA = CFClient::UI::FancyFrame::; |
|
|
2430 | |
|
|
2431 | use CFClient::OpenGL; |
|
|
2432 | |
|
|
2433 | sub new { |
|
|
2434 | my $class = shift; |
|
|
2435 | |
|
|
2436 | my $self = $class->SUPER::new ( |
|
|
2437 | items => [], |
|
|
2438 | z => 100, |
|
|
2439 | @_, |
|
|
2440 | ); |
|
|
2441 | |
|
|
2442 | $self->add ($self->{vbox} = new CFClient::UI::VBox); |
|
|
2443 | |
|
|
2444 | for my $item (@{ $self->{items} }) { |
|
|
2445 | my ($widget, $cb) = @$item; |
|
|
2446 | |
|
|
2447 | # handle various types of items, only text for now |
|
|
2448 | if (!ref $widget) { |
|
|
2449 | $widget = new CFClient::UI::Label |
|
|
2450 | can_hover => 1, |
|
|
2451 | can_events => 1, |
|
|
2452 | text => $widget; |
|
|
2453 | } |
|
|
2454 | |
|
|
2455 | $self->{item}{$widget} = $item; |
|
|
2456 | |
|
|
2457 | $self->{vbox}->add ($widget); |
|
|
2458 | } |
|
|
2459 | |
|
|
2460 | $self |
|
|
2461 | } |
|
|
2462 | |
|
|
2463 | # popup given the event (must be a mouse button down event currently) |
|
|
2464 | sub popup { |
|
|
2465 | my ($self, $ev) = @_; |
|
|
2466 | |
|
|
2467 | $self->emit ("popdown"); |
|
|
2468 | |
|
|
2469 | # maybe save $GRAB? must be careful about events... |
|
|
2470 | $GRAB = $self; |
|
|
2471 | $self->{button} = $ev->{button}; |
|
|
2472 | |
|
|
2473 | $self->show; |
|
|
2474 | $self->move ($ev->{x} - $self->{w} * 0.5, $ev->{y} - $self->{h} * 0.5); |
|
|
2475 | } |
|
|
2476 | |
|
|
2477 | sub mouse_motion { |
|
|
2478 | my ($self, $ev, $x, $y) = @_; |
|
|
2479 | |
|
|
2480 | # TODO: should use vbox->fdind_widget or so |
|
|
2481 | $HOVER = $ROOT->find_widget ($ev->{x}, $ev->{y}); |
|
|
2482 | $self->{hover} = $self->{item}{$HOVER}; |
|
|
2483 | } |
|
|
2484 | |
|
|
2485 | sub button_up { |
|
|
2486 | my ($self, $ev, $x, $y) = @_; |
|
|
2487 | |
|
|
2488 | if ($ev->{button} == $self->{button}) { |
|
|
2489 | undef $GRAB; |
|
|
2490 | $self->hide; |
|
|
2491 | |
|
|
2492 | $self->emit ("popdown"); |
|
|
2493 | $self->{hover}[1]->() if $self->{hover}; |
|
|
2494 | } |
|
|
2495 | } |
|
|
2496 | |
|
|
2497 | ############################################################################# |
|
|
2498 | |
2352 | package CFClient::UI::Root; |
2499 | package CFClient::UI::Root; |
2353 | |
2500 | |
2354 | our @ISA = CFClient::UI::Container::; |
2501 | our @ISA = CFClient::UI::Container::; |
2355 | |
2502 | |
2356 | use CFClient::OpenGL; |
2503 | use CFClient::OpenGL; |