… | |
… | |
371 | sub size_allocate { |
371 | sub size_allocate { |
372 | # nothing to be done |
372 | # nothing to be done |
373 | } |
373 | } |
374 | |
374 | |
375 | sub children { |
375 | sub children { |
|
|
376 | # nop |
|
|
377 | } |
|
|
378 | |
|
|
379 | sub visible_children { |
|
|
380 | $_[0]->children |
376 | } |
381 | } |
377 | |
382 | |
378 | sub set_max_size { |
383 | sub set_max_size { |
379 | my ($self, $w, $h) = @_; |
384 | my ($self, $w, $h) = @_; |
380 | |
385 | |
… | |
… | |
439 | |
444 | |
440 | $::MAPWIDGET->focus_in #d# focus mapwidget if no other widget has focus |
445 | $::MAPWIDGET->focus_in #d# focus mapwidget if no other widget has focus |
441 | unless $FOCUS; |
446 | unless $FOCUS; |
442 | } |
447 | } |
443 | |
448 | |
444 | sub mouse_motion { } |
449 | sub mouse_motion { 0 } |
445 | sub button_up { } |
450 | sub button_up { 0 } |
446 | sub key_down { } |
451 | sub key_down { 0 } |
447 | sub key_up { } |
452 | sub key_up { 0 } |
448 | |
453 | |
449 | sub button_down { |
454 | sub button_down { |
450 | my ($self, $ev, $x, $y) = @_; |
455 | my ($self, $ev, $x, $y) = @_; |
451 | |
456 | |
452 | $self->focus_in; |
457 | $self->focus_in; |
|
|
458 | |
|
|
459 | 0 |
453 | } |
460 | } |
454 | |
461 | |
455 | sub find_widget { |
462 | sub find_widget { |
456 | my ($self, $x, $y) = @_; |
463 | my ($self, $x, $y) = @_; |
457 | |
464 | |
… | |
… | |
541 | return if ($draw_x + $self->{w} < 0) || ($draw_x >= $draw_w) |
548 | return if ($draw_x + $self->{w} < 0) || ($draw_x >= $draw_w) |
542 | || ($draw_y + $self->{h} < 0) || ($draw_y >= $draw_h); |
549 | || ($draw_y + $self->{h} < 0) || ($draw_y >= $draw_h); |
543 | |
550 | |
544 | glPushMatrix; |
551 | glPushMatrix; |
545 | glTranslate $self->{x}, $self->{y}, 0; |
552 | glTranslate $self->{x}, $self->{y}, 0; |
546 | $self->_draw; |
|
|
547 | glPopMatrix; |
|
|
548 | |
553 | |
549 | if ($self == $HOVER && $self->{can_hover}) { |
554 | if ($self == $HOVER && $self->{can_hover}) { |
550 | my ($x, $y) = @$self{qw(x y)}; |
|
|
551 | |
|
|
552 | glColor 1, 0.8, 0.5, 0.2; |
555 | glColor 1*0.2, 0.8*0.2, 0.5*0.2, 0.2; |
553 | glEnable GL_BLEND; |
556 | glEnable GL_BLEND; |
554 | glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA; |
557 | glBlendFunc GL_ONE, GL_ONE_MINUS_SRC_ALPHA; |
555 | glBegin GL_QUADS; |
558 | glBegin GL_QUADS; |
556 | glVertex $x , $y; |
559 | glVertex 0 , 0; |
557 | glVertex $x + $self->{w}, $y; |
560 | glVertex $self->{w}, 0; |
558 | glVertex $x + $self->{w}, $y + $self->{h}; |
561 | glVertex $self->{w}, $self->{h}; |
559 | glVertex $x , $y + $self->{h}; |
562 | glVertex 0 , $self->{h}; |
560 | glEnd; |
563 | glEnd; |
561 | glDisable GL_BLEND; |
564 | glDisable GL_BLEND; |
562 | } |
565 | } |
563 | |
566 | |
564 | if ($ENV{CFPLUS_DEBUG} & 1) { |
567 | if ($ENV{CFPLUS_DEBUG} & 1) { |
565 | glPushMatrix; |
568 | glPushMatrix; |
566 | glColor 1, 1, 0, 1; |
569 | glColor 1, 1, 0, 1; |
567 | glTranslate $self->{x} + 0.375, $self->{y} + 0.375; |
570 | glTranslate 0.375, 0.375; |
568 | glBegin GL_LINE_LOOP; |
571 | glBegin GL_LINE_LOOP; |
569 | glVertex 0 , 0; |
572 | glVertex 0 , 0; |
570 | glVertex $self->{w} - 1, 0; |
573 | glVertex $self->{w} - 1, 0; |
571 | glVertex $self->{w} - 1, $self->{h} - 1; |
574 | glVertex $self->{w} - 1, $self->{h} - 1; |
572 | glVertex 0 , $self->{h} - 1; |
575 | glVertex 0 , $self->{h} - 1; |
573 | glEnd; |
576 | glEnd; |
574 | glPopMatrix; |
577 | glPopMatrix; |
575 | #CFClient::UI::Label->new (w => $self->{w}, h => $self->{h}, text => $self, fontsize => 0)->_draw; |
578 | #CFClient::UI::Label->new (w => $self->{w}, h => $self->{h}, text => $self, fontsize => 0)->_draw; |
576 | } |
579 | } |
|
|
580 | |
|
|
581 | $self->_draw; |
|
|
582 | glPopMatrix; |
577 | } |
583 | } |
578 | |
584 | |
579 | sub _draw { |
585 | sub _draw { |
580 | my ($self) = @_; |
586 | my ($self) = @_; |
581 | |
587 | |
… | |
… | |
619 | |
625 | |
620 | if ($color && (@$color < 4 || $color->[3])) { |
626 | if ($color && (@$color < 4 || $color->[3])) { |
621 | my ($w, $h) = @$self{qw(w h)}; |
627 | my ($w, $h) = @$self{qw(w h)}; |
622 | |
628 | |
623 | glEnable GL_BLEND; |
629 | glEnable GL_BLEND; |
624 | glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA; |
630 | glBlendFunc GL_ONE, GL_ONE_MINUS_SRC_ALPHA; |
625 | glColor @$color; |
631 | glColor_premultiply @$color; |
626 | |
632 | |
627 | glBegin GL_QUADS; |
633 | glBegin GL_QUADS; |
628 | glVertex 0 , 0; |
634 | glVertex 0 , 0; |
629 | glVertex 0 , $h; |
635 | glVertex 0 , $h; |
630 | glVertex $w, $h; |
636 | glVertex $w, $h; |
… | |
… | |
661 | our @ISA = CFClient::UI::Base::; |
667 | our @ISA = CFClient::UI::Base::; |
662 | |
668 | |
663 | sub new { |
669 | sub new { |
664 | my ($class, %arg) = @_; |
670 | my ($class, %arg) = @_; |
665 | |
671 | |
666 | my $children = delete $arg{children} || []; |
672 | my $children = delete $arg{children}; |
667 | |
673 | |
668 | my $self = $class->SUPER::new ( |
674 | my $self = $class->SUPER::new ( |
669 | children => [], |
675 | children => [], |
670 | can_events => 0, |
676 | can_events => 0, |
671 | %arg, |
677 | %arg, |
672 | ); |
678 | ); |
|
|
679 | |
673 | $self->add ($_) for @$children; |
680 | $self->add (@$children) |
|
|
681 | if $children; |
674 | |
682 | |
675 | $self |
683 | $self |
676 | } |
684 | } |
677 | |
685 | |
678 | sub add { |
686 | sub add { |
… | |
… | |
726 | $x -= $self->{x}; |
734 | $x -= $self->{x}; |
727 | $y -= $self->{y}; |
735 | $y -= $self->{y}; |
728 | |
736 | |
729 | my $res; |
737 | my $res; |
730 | |
738 | |
731 | for (reverse @{ $self->{children} }) { |
739 | for (reverse $self->visible_children) { |
732 | $res = $_->find_widget ($x, $y) |
740 | $res = $_->find_widget ($x, $y) |
733 | and return $res; |
741 | and return $res; |
734 | } |
742 | } |
735 | |
743 | |
736 | $self->SUPER::find_widget ($x + $self->{x}, $y + $self->{y}) |
744 | $self->SUPER::find_widget ($x + $self->{x}, $y + $self->{y}) |
… | |
… | |
785 | $self->{children}[0]->configure (0, 0, $w, $h); |
793 | $self->{children}[0]->configure (0, 0, $w, $h); |
786 | } |
794 | } |
787 | |
795 | |
788 | ############################################################################# |
796 | ############################################################################# |
789 | |
797 | |
|
|
798 | # back-buffered drawing area |
|
|
799 | |
790 | package CFClient::UI::Window; |
800 | package CFClient::UI::Window; |
791 | |
801 | |
792 | our @ISA = CFClient::UI::Bin::; |
802 | our @ISA = CFClient::UI::Bin::; |
793 | |
803 | |
794 | use CFClient::OpenGL; |
804 | use CFClient::OpenGL; |
… | |
… | |
845 | my $tex = $self->{texture} |
855 | my $tex = $self->{texture} |
846 | or return; |
856 | or return; |
847 | |
857 | |
848 | glEnable GL_TEXTURE_2D; |
858 | glEnable GL_TEXTURE_2D; |
849 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; |
859 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; |
|
|
860 | glEnable GL_BLEND; |
|
|
861 | glBlendFunc GL_ONE, GL_ONE_MINUS_SRC_ALPHA; |
850 | glColor 1, 1, 1, 1; |
862 | glColor 0, 0, 0, 1; |
851 | |
863 | |
852 | $tex->draw_quad_alpha_premultiplied (0, 0, $w, $h); |
864 | $tex->draw_quad (0, 0, $w, $h); |
853 | |
865 | |
|
|
866 | glDisable GL_BLEND; |
854 | glDisable GL_TEXTURE_2D; |
867 | glDisable GL_TEXTURE_2D; |
855 | } |
868 | } |
856 | |
869 | |
857 | ############################################################################# |
870 | ############################################################################# |
858 | |
871 | |
… | |
… | |
946 | package CFClient::UI::ScrolledWindow; |
959 | package CFClient::UI::ScrolledWindow; |
947 | |
960 | |
948 | our @ISA = CFClient::UI::HBox::; |
961 | our @ISA = CFClient::UI::HBox::; |
949 | |
962 | |
950 | sub new { |
963 | sub new { |
951 | my $class = shift; |
964 | my ($class, %arg) = @_; |
|
|
965 | |
|
|
966 | my $child = delete $arg{child}; |
952 | |
967 | |
953 | my $self; |
968 | my $self; |
954 | |
969 | |
955 | my $slider = new CFClient::UI::Slider |
970 | my $slider = new CFClient::UI::Slider |
956 | vertical => 1, |
971 | vertical => 1, |
… | |
… | |
961 | ; |
976 | ; |
962 | |
977 | |
963 | $self = $class->SUPER::new ( |
978 | $self = $class->SUPER::new ( |
964 | vp => (new CFClient::UI::ViewPort expand => 1), |
979 | vp => (new CFClient::UI::ViewPort expand => 1), |
965 | slider => $slider, |
980 | slider => $slider, |
966 | @_, |
981 | %arg, |
967 | ); |
982 | ); |
968 | |
983 | |
969 | $self->{vp}->add ($self->{scrolled}); |
|
|
970 | $self->add ($self->{vp}); |
|
|
971 | $self->add ($self->{slider}); |
984 | $self->SUPER::add ($self->{vp}, $self->{slider}); |
|
|
985 | $self->add ($child) if $child; |
972 | |
986 | |
973 | $self |
987 | $self |
|
|
988 | } |
|
|
989 | |
|
|
990 | sub add { |
|
|
991 | my ($self, $widget) = @_; |
|
|
992 | |
|
|
993 | $self->{vp}->add ($self->{child} = $widget); |
974 | } |
994 | } |
975 | |
995 | |
976 | sub update { |
996 | sub update { |
977 | my ($self) = @_; |
997 | my ($self) = @_; |
978 | |
998 | |
… | |
… | |
1017 | |
1037 | |
1018 | if ($self->{bg}) { |
1038 | if ($self->{bg}) { |
1019 | my ($w, $h) = @$self{qw(w h)}; |
1039 | my ($w, $h) = @$self{qw(w h)}; |
1020 | |
1040 | |
1021 | glEnable GL_BLEND; |
1041 | glEnable GL_BLEND; |
1022 | glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA; |
1042 | glBlendFunc GL_ONE, GL_ONE_MINUS_SRC_ALPHA; |
1023 | glColor @{ $self->{bg} }; |
1043 | glColor_premultiply @{ $self->{bg} }; |
1024 | |
1044 | |
1025 | glBegin GL_QUADS; |
1045 | glBegin GL_QUADS; |
1026 | glVertex 0 , 0; |
1046 | glVertex 0 , 0; |
1027 | glVertex 0 , $h; |
1047 | glVertex 0 , $h; |
1028 | glVertex $w, $h; |
1048 | glVertex $w, $h; |
… | |
… | |
1142 | my $dy = $ev->{y} - $oy; |
1162 | my $dy = $ev->{y} - $oy; |
1143 | |
1163 | |
1144 | $self->{force_w} = $bw + $dx * ($mx ? -1 : 1); |
1164 | $self->{force_w} = $bw + $dx * ($mx ? -1 : 1); |
1145 | $self->{force_h} = $bh + $dy * ($my ? -1 : 1); |
1165 | $self->{force_h} = $bh + $dy * ($my ? -1 : 1); |
1146 | |
1166 | |
|
|
1167 | $self->move_abs ($wx + $dx * $mx, $wy + $dy * $my); |
1147 | $self->realloc; |
1168 | $self->realloc; |
1148 | $self->move_abs ($wx + $dx * $mx, $wy + $dy * $my); |
|
|
1149 | }; |
1169 | }; |
1150 | |
1170 | |
1151 | } elsif ($lr ^ $td) { |
1171 | } elsif ($lr ^ $td) { |
1152 | my ($ox, $oy) = ($ev->{x}, $ev->{y}); |
1172 | my ($ox, $oy) = ($ev->{x}, $ev->{y}); |
1153 | my ($bx, $by) = ($self->{x}, $self->{y}); |
1173 | my ($bx, $by) = ($self->{x}, $self->{y}); |
… | |
… | |
1156 | my ($ev, $x, $y) = @_; |
1176 | my ($ev, $x, $y) = @_; |
1157 | |
1177 | |
1158 | ($x, $y) = ($ev->{x}, $ev->{y}); |
1178 | ($x, $y) = ($ev->{x}, $ev->{y}); |
1159 | |
1179 | |
1160 | $self->move_abs ($bx + $x - $ox, $by + $y - $oy); |
1180 | $self->move_abs ($bx + $x - $ox, $by + $y - $oy); |
|
|
1181 | # HACK: the next line is required to enforce placement |
|
|
1182 | $self->{parent}->size_allocate ($self->{parent}{w}, $self->{parent}{h}); |
1161 | }; |
1183 | }; |
|
|
1184 | } else { |
|
|
1185 | return 0; |
|
|
1186 | } |
|
|
1187 | |
1162 | } |
1188 | 1 |
1163 | } |
1189 | } |
1164 | |
1190 | |
1165 | sub button_up { |
1191 | sub button_up { |
1166 | my ($self, $ev, $x, $y) = @_; |
1192 | my ($self, $ev, $x, $y) = @_; |
1167 | |
1193 | |
1168 | delete $self->{motion}; |
1194 | !!delete $self->{motion} |
1169 | } |
1195 | } |
1170 | |
1196 | |
1171 | sub mouse_motion { |
1197 | sub mouse_motion { |
1172 | my ($self, $ev, $x, $y) = @_; |
1198 | my ($self, $ev, $x, $y) = @_; |
1173 | |
1199 | |
1174 | $self->{motion}->($ev, $x, $y) if $self->{motion}; |
1200 | $self->{motion}->($ev, $x, $y) if $self->{motion}; |
|
|
1201 | |
|
|
1202 | !!$self->{motion} |
1175 | } |
1203 | } |
1176 | |
1204 | |
1177 | sub _draw { |
1205 | sub _draw { |
1178 | my ($self) = @_; |
1206 | my ($self) = @_; |
1179 | |
1207 | |
… | |
… | |
1652 | |
1680 | |
1653 | delete $self->{cur_h}; |
1681 | delete $self->{cur_h}; |
1654 | |
1682 | |
1655 | return if $self->{text} eq $text; |
1683 | return if $self->{text} eq $text; |
1656 | |
1684 | |
1657 | delete $self->{texture}; |
|
|
1658 | |
|
|
1659 | $self->{last_activity} = $::NOW; |
1685 | $self->{last_activity} = $::NOW; |
1660 | $self->{text} = $text; |
1686 | $self->{text} = $text; |
1661 | |
1687 | |
1662 | $text =~ s/./*/g if $self->{hidden}; |
1688 | $text =~ s/./*/g if $self->{hidden}; |
1663 | $self->{layout}->set_text ("$text "); |
1689 | $self->{layout}->set_text ("$text "); |
1664 | |
1690 | |
1665 | $self->_emit (changed => $self->{text}); |
1691 | $self->_emit (changed => $self->{text}); |
|
|
1692 | $self->update; |
1666 | } |
1693 | } |
1667 | |
1694 | |
1668 | sub set_text { |
1695 | sub set_text { |
1669 | my ($self, $text) = @_; |
1696 | my ($self, $text) = @_; |
1670 | |
1697 | |
… | |
… | |
1709 | $self->{cursor} = length $text; |
1736 | $self->{cursor} = length $text; |
1710 | } elsif ($uni == 27) { |
1737 | } elsif ($uni == 27) { |
1711 | $self->_emit ('escape'); |
1738 | $self->_emit ('escape'); |
1712 | } elsif ($uni) { |
1739 | } elsif ($uni) { |
1713 | substr $text, $self->{cursor}++, 0, chr $uni; |
1740 | substr $text, $self->{cursor}++, 0, chr $uni; |
|
|
1741 | } else { |
|
|
1742 | return 0; |
1714 | } |
1743 | } |
1715 | |
1744 | |
1716 | $self->_set_text ($text); |
1745 | $self->_set_text ($text); |
1717 | |
1746 | |
1718 | $self->realloc; |
1747 | $self->realloc; |
|
|
1748 | |
|
|
1749 | 1 |
1719 | } |
1750 | } |
1720 | |
1751 | |
1721 | sub focus_in { |
1752 | sub focus_in { |
1722 | my ($self) = @_; |
1753 | my ($self) = @_; |
1723 | |
1754 | |
… | |
… | |
1738 | utf8::encode $text; |
1769 | utf8::encode $text; |
1739 | $self->{cursor} = length substr $text, 0, $idx; |
1770 | $self->{cursor} = length substr $text, 0, $idx; |
1740 | |
1771 | |
1741 | $self->_set_text ($self->{text}); |
1772 | $self->_set_text ($self->{text}); |
1742 | $self->update; |
1773 | $self->update; |
|
|
1774 | |
|
|
1775 | 1 |
1743 | } |
1776 | } |
1744 | |
1777 | |
1745 | sub mouse_motion { |
1778 | sub mouse_motion { |
1746 | my ($self, $ev, $x, $y) = @_; |
1779 | my ($self, $ev, $x, $y) = @_; |
1747 | # printf "M %d,%d %d,%d\n", $ev->motion_x, $ev->motion_y, $x, $y;#d# |
1780 | # printf "M %d,%d %d,%d\n", $ev->motion_x, $ev->motion_y, $x, $y;#d# |
|
|
1781 | |
|
|
1782 | 0 |
1748 | } |
1783 | } |
1749 | |
1784 | |
1750 | sub _draw { |
1785 | sub _draw { |
1751 | my ($self) = @_; |
1786 | my ($self) = @_; |
1752 | |
1787 | |
1753 | local $self->{fg} = $self->{fg}; |
1788 | local $self->{fg} = $self->{fg}; |
1754 | |
1789 | |
1755 | if ($FOCUS == $self) { |
1790 | if ($FOCUS == $self) { |
1756 | glColor @{$self->{active_bg}}; |
1791 | glColor_premultiply @{$self->{active_bg}}; |
1757 | $self->{fg} = $self->{active_fg}; |
1792 | $self->{fg} = $self->{active_fg}; |
1758 | } else { |
1793 | } else { |
1759 | glColor @{$self->{bg}}; |
1794 | glColor_premultiply @{$self->{bg}}; |
1760 | } |
1795 | } |
1761 | |
1796 | |
1762 | glEnable GL_BLEND; |
1797 | glEnable GL_BLEND; |
1763 | glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA; |
1798 | glBlendFunc GL_ONE, GL_ONE_MINUS_SRC_ALPHA; |
1764 | glBegin GL_QUADS; |
1799 | glBegin GL_QUADS; |
1765 | glVertex 0 , 0; |
1800 | glVertex 0 , 0; |
1766 | glVertex 0 , $self->{h}; |
1801 | glVertex 0 , $self->{h}; |
1767 | glVertex $self->{w}, $self->{h}; |
1802 | glVertex $self->{w}, $self->{h}; |
1768 | glVertex $self->{w}, 0; |
1803 | glVertex $self->{w}, 0; |
… | |
… | |
1829 | } else { |
1864 | } else { |
1830 | $self->set_text ($self->{history_saveback}); |
1865 | $self->set_text ($self->{history_saveback}); |
1831 | } |
1866 | } |
1832 | |
1867 | |
1833 | } else { |
1868 | } else { |
1834 | $self->SUPER::key_down ($ev); |
1869 | return $self->SUPER::key_down ($ev) |
|
|
1870 | } |
|
|
1871 | |
1835 | } |
1872 | 1 |
1836 | |
|
|
1837 | } |
1873 | } |
1838 | |
1874 | |
1839 | ############################################################################# |
1875 | ############################################################################# |
1840 | |
1876 | |
1841 | package CFClient::UI::Button; |
1877 | package CFClient::UI::Button; |
… | |
… | |
1870 | my ($self, $ev, $x, $y) = @_; |
1906 | my ($self, $ev, $x, $y) = @_; |
1871 | |
1907 | |
1872 | $self->emit ("activate") |
1908 | $self->emit ("activate") |
1873 | if $x >= 0 && $x < $self->{w} |
1909 | if $x >= 0 && $x < $self->{w} |
1874 | && $y >= 0 && $y < $self->{h}; |
1910 | && $y >= 0 && $y < $self->{h}; |
|
|
1911 | |
|
|
1912 | 1 |
1875 | } |
1913 | } |
1876 | |
1914 | |
1877 | sub _draw { |
1915 | sub _draw { |
1878 | my ($self) = @_; |
1916 | my ($self) = @_; |
1879 | |
1917 | |
… | |
… | |
1933 | |
1971 | |
1934 | if ($x >= $self->{padding_x} && $x < $self->{w} - $self->{padding_x} |
1972 | if ($x >= $self->{padding_x} && $x < $self->{w} - $self->{padding_x} |
1935 | && $y >= $self->{padding_y} && $y < $self->{h} - $self->{padding_y}) { |
1973 | && $y >= $self->{padding_y} && $y < $self->{h} - $self->{padding_y}) { |
1936 | $self->{state} = !$self->{state}; |
1974 | $self->{state} = !$self->{state}; |
1937 | $self->_emit (changed => $self->{state}); |
1975 | $self->_emit (changed => $self->{state}); |
|
|
1976 | } else { |
|
|
1977 | return 0 |
|
|
1978 | } |
|
|
1979 | |
1938 | } |
1980 | 1 |
1939 | } |
1981 | } |
1940 | |
1982 | |
1941 | sub _draw { |
1983 | sub _draw { |
1942 | my ($self) = @_; |
1984 | my ($self) = @_; |
1943 | |
1985 | |
… | |
… | |
2110 | |
2152 | |
2111 | my $h1 = $self->{h} * (1 - $ycut1); |
2153 | my $h1 = $self->{h} * (1 - $ycut1); |
2112 | my $h2 = $self->{h} * (1 - $ycut2); |
2154 | my $h2 = $self->{h} * (1 - $ycut2); |
2113 | |
2155 | |
2114 | glEnable GL_BLEND; |
2156 | glEnable GL_BLEND; |
2115 | glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA; |
2157 | glBlendFuncSeparate GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA, |
|
|
2158 | GL_ONE, GL_ONE_MINUS_SRC_ALPHA; |
2116 | glEnable GL_TEXTURE_2D; |
2159 | glEnable GL_TEXTURE_2D; |
2117 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; |
2160 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; |
2118 | |
2161 | |
2119 | glBindTexture GL_TEXTURE_2D, $t1->{name}; |
2162 | glBindTexture GL_TEXTURE_2D, $t1->{name}; |
2120 | glBegin GL_QUADS; |
2163 | glBegin GL_QUADS; |
… | |
… | |
2281 | |
2324 | |
2282 | $self->SUPER::button_down ($ev, $x, $y); |
2325 | $self->SUPER::button_down ($ev, $x, $y); |
2283 | |
2326 | |
2284 | $self->{click} = [$self->{range}[0], $self->{vertical} ? $y : $x]; |
2327 | $self->{click} = [$self->{range}[0], $self->{vertical} ? $y : $x]; |
2285 | |
2328 | |
2286 | $self->mouse_motion ($ev, $x, $y); |
2329 | $self->mouse_motion ($ev, $x, $y) |
2287 | } |
2330 | } |
2288 | |
2331 | |
2289 | sub mouse_motion { |
2332 | sub mouse_motion { |
2290 | my ($self, $ev, $x, $y) = @_; |
2333 | my ($self, $ev, $x, $y) = @_; |
2291 | |
2334 | |
… | |
… | |
2295 | my (undef, $lo, $hi, $page) = @{$self->{range}}; |
2338 | my (undef, $lo, $hi, $page) = @{$self->{range}}; |
2296 | |
2339 | |
2297 | $x = ($x - $self->{click}[1]) / ($w * $self->{scale}); |
2340 | $x = ($x - $self->{click}[1]) / ($w * $self->{scale}); |
2298 | |
2341 | |
2299 | $self->set_value ($self->{click}[0] + $x * ($hi - $page - $lo)); |
2342 | $self->set_value ($self->{click}[0] + $x * ($hi - $page - $lo)); |
|
|
2343 | } else { |
|
|
2344 | return 0; |
|
|
2345 | } |
|
|
2346 | |
2300 | } |
2347 | 1 |
2301 | } |
2348 | } |
2302 | |
2349 | |
2303 | sub update { |
2350 | sub update { |
2304 | my ($self) = @_; |
2351 | my ($self) = @_; |
2305 | |
2352 | |
2306 | $CFClient::UI::ROOT->on_post_alloc ($self => sub { |
2353 | delete $self->{knob_w}; |
|
|
2354 | $self->SUPER::update; |
|
|
2355 | } |
|
|
2356 | |
|
|
2357 | sub _draw { |
|
|
2358 | my ($self) = @_; |
|
|
2359 | |
|
|
2360 | unless ($self->{knob_w}) { |
2307 | $self->set_value ($self->{range}[0]); |
2361 | $self->set_value ($self->{range}[0]); |
2308 | |
2362 | |
2309 | my ($value, $lo, $hi, $page) = @{$self->{range}}; |
2363 | my ($value, $lo, $hi, $page) = @{$self->{range}}; |
2310 | my $range = ($hi - $page - $lo) || 1e-100; |
2364 | my $range = ($hi - $page - $lo) || 1e-100; |
2311 | |
2365 | |
… | |
… | |
2317 | $value = ($value - $lo) / $range; |
2371 | $value = ($value - $lo) / $range; |
2318 | $value = $value * $self->{scale} + $self->{offset}; |
2372 | $value = $value * $self->{scale} + $self->{offset}; |
2319 | |
2373 | |
2320 | $self->{knob_x} = $value - $knob_w * 0.5; |
2374 | $self->{knob_x} = $value - $knob_w * 0.5; |
2321 | $self->{knob_w} = $knob_w; |
2375 | $self->{knob_w} = $knob_w; |
2322 | }); |
2376 | } |
2323 | |
|
|
2324 | $self->SUPER::update; |
|
|
2325 | } |
|
|
2326 | |
|
|
2327 | sub _draw { |
|
|
2328 | my ($self) = @_; |
|
|
2329 | |
2377 | |
2330 | $self->SUPER::_draw (); |
2378 | $self->SUPER::_draw (); |
2331 | |
2379 | |
2332 | glScale $self->{w}, $self->{h}; |
2380 | glScale $self->{w}, $self->{h}; |
2333 | |
2381 | |
… | |
… | |
2827 | $self->SUPER::DESTROY; |
2875 | $self->SUPER::DESTROY; |
2828 | } |
2876 | } |
2829 | |
2877 | |
2830 | ############################################################################# |
2878 | ############################################################################# |
2831 | |
2879 | |
|
|
2880 | package CFClient::UI::Buttonbar; |
|
|
2881 | |
|
|
2882 | our @ISA = CFClient::UI::HBox::; |
|
|
2883 | |
|
|
2884 | # TODO: should actualyl wrap buttons and other goodies. |
|
|
2885 | |
|
|
2886 | ############################################################################# |
|
|
2887 | |
2832 | package CFClient::UI::Menu; |
2888 | package CFClient::UI::Menu; |
2833 | |
2889 | |
2834 | our @ISA = CFClient::UI::FancyFrame::; |
2890 | our @ISA = CFClient::UI::FancyFrame::; |
2835 | |
2891 | |
2836 | use CFClient::OpenGL; |
2892 | use CFClient::OpenGL; |
… | |
… | |
2883 | my ($self, $ev, $x, $y) = @_; |
2939 | my ($self, $ev, $x, $y) = @_; |
2884 | |
2940 | |
2885 | # TODO: should use vbox->find_widget or so |
2941 | # TODO: should use vbox->find_widget or so |
2886 | $HOVER = $ROOT->find_widget ($ev->{x}, $ev->{y}); |
2942 | $HOVER = $ROOT->find_widget ($ev->{x}, $ev->{y}); |
2887 | $self->{hover} = $self->{item}{$HOVER}; |
2943 | $self->{hover} = $self->{item}{$HOVER}; |
|
|
2944 | |
|
|
2945 | 0 |
2888 | } |
2946 | } |
2889 | |
2947 | |
2890 | sub button_up { |
2948 | sub button_up { |
2891 | my ($self, $ev, $x, $y) = @_; |
2949 | my ($self, $ev, $x, $y) = @_; |
2892 | |
2950 | |
… | |
… | |
2894 | undef $GRAB; |
2952 | undef $GRAB; |
2895 | $self->hide; |
2953 | $self->hide; |
2896 | |
2954 | |
2897 | $self->_emit ("popdown"); |
2955 | $self->_emit ("popdown"); |
2898 | $self->{hover}[1]->() if $self->{hover}; |
2956 | $self->{hover}[1]->() if $self->{hover}; |
|
|
2957 | } else { |
|
|
2958 | return 0 |
|
|
2959 | } |
|
|
2960 | |
|
|
2961 | 1 |
|
|
2962 | } |
|
|
2963 | |
|
|
2964 | ############################################################################# |
|
|
2965 | |
|
|
2966 | package CFClient::UI::Multiplexer; |
|
|
2967 | |
|
|
2968 | our @ISA = CFClient::UI::Container::; |
|
|
2969 | |
|
|
2970 | sub new { |
|
|
2971 | my $class = shift; |
|
|
2972 | |
|
|
2973 | my $self = $class->SUPER::new ( |
|
|
2974 | @_, |
|
|
2975 | ); |
|
|
2976 | |
|
|
2977 | $self->{current} = $self->{children}[0] |
|
|
2978 | if @{ $self->{children} }; |
|
|
2979 | |
|
|
2980 | $self |
|
|
2981 | } |
|
|
2982 | |
|
|
2983 | sub add { |
|
|
2984 | my ($self, @widgets) = @_; |
|
|
2985 | |
|
|
2986 | $self->SUPER::add (@widgets); |
|
|
2987 | |
|
|
2988 | $self->{current} = $self->{children}[0] |
|
|
2989 | if @{ $self->{children} }; |
|
|
2990 | } |
|
|
2991 | |
|
|
2992 | sub set_current_page { |
|
|
2993 | my ($self, $page_or_widget) = @_; |
|
|
2994 | |
|
|
2995 | my $widget = ref $page_or_widget |
|
|
2996 | ? $page_or_widget |
|
|
2997 | : $self->{children}[$page_or_widget]; |
|
|
2998 | |
|
|
2999 | $self->{current} = $widget; |
|
|
3000 | $self->{current}->configure (0, 0, $self->{w}, $self->{h}); |
|
|
3001 | |
|
|
3002 | $self->_emit (page_changed => $self->{current}); |
|
|
3003 | |
|
|
3004 | $self->realloc; |
|
|
3005 | } |
|
|
3006 | |
|
|
3007 | sub visible_children { |
|
|
3008 | $_[0]{current} |
|
|
3009 | } |
|
|
3010 | |
|
|
3011 | sub size_request { |
|
|
3012 | my ($self) = @_; |
|
|
3013 | |
|
|
3014 | $self->{current}->size_request |
|
|
3015 | } |
|
|
3016 | |
|
|
3017 | sub size_allocate { |
|
|
3018 | my ($self, $w, $h) = @_; |
|
|
3019 | |
|
|
3020 | $self->{current}->configure (0, 0, $w, $h); |
|
|
3021 | } |
|
|
3022 | |
|
|
3023 | sub _draw { |
|
|
3024 | my ($self) = @_; |
|
|
3025 | |
|
|
3026 | $self->{current}->draw; |
|
|
3027 | } |
|
|
3028 | |
|
|
3029 | ############################################################################# |
|
|
3030 | |
|
|
3031 | package CFClient::UI::Notebook; |
|
|
3032 | |
|
|
3033 | our @ISA = CFClient::UI::VBox::; |
|
|
3034 | |
|
|
3035 | sub new { |
|
|
3036 | my $class = shift; |
|
|
3037 | |
|
|
3038 | my $self = $class->SUPER::new ( |
|
|
3039 | buttonbar => (new CFClient::UI::Buttonbar), |
|
|
3040 | multiplexer => (new CFClient::UI::Multiplexer expand => 1), |
|
|
3041 | # filter => # will be put between multiplexer and $self |
|
|
3042 | @_, |
|
|
3043 | ); |
2899 | } |
3044 | |
|
|
3045 | $self->{filter}->add ($self->{multiplexer}) if $self->{filter}; |
|
|
3046 | $self->SUPER::add ($self->{buttonbar}, $self->{filter} || $self->{multiplexer}); |
|
|
3047 | |
|
|
3048 | $self |
|
|
3049 | } |
|
|
3050 | |
|
|
3051 | sub add { |
|
|
3052 | my ($self, $title, $widget, $tooltip) = @_; |
|
|
3053 | |
|
|
3054 | Scalar::Util::weaken $self; |
|
|
3055 | |
|
|
3056 | $self->{buttonbar}->add (new CFClient::UI::Button |
|
|
3057 | markup => $title, |
|
|
3058 | tooltip => $tooltip, |
|
|
3059 | on_activate => sub { $self->set_current_page ($widget) }, |
|
|
3060 | ); |
|
|
3061 | |
|
|
3062 | $self->{multiplexer}->add ($widget); |
|
|
3063 | } |
|
|
3064 | |
|
|
3065 | sub set_current_page { |
|
|
3066 | my ($self, $page) = @_; |
|
|
3067 | |
|
|
3068 | $self->{multiplexer}->set_current_page ($page); |
|
|
3069 | $self->_emit (page_changed => $self->{multiplexer}{current}); |
2900 | } |
3070 | } |
2901 | |
3071 | |
2902 | ############################################################################# |
3072 | ############################################################################# |
2903 | |
3073 | |
2904 | package CFClient::UI::Statusbox; |
3074 | package CFClient::UI::Statusbox; |
… | |
… | |
3017 | |
3187 | |
3018 | sub new { |
3188 | sub new { |
3019 | my $class = shift; |
3189 | my $class = shift; |
3020 | |
3190 | |
3021 | my $self = $class->SUPER::new ( |
3191 | my $self = $class->SUPER::new ( |
3022 | scrolled => (new CFClient::UI::Table col_expand => [0, 1, 0]), |
3192 | child => (new CFClient::UI::Table col_expand => [0, 1, 0]), |
3023 | @_, |
3193 | @_, |
3024 | ); |
3194 | ); |
3025 | |
3195 | |
3026 | $self |
3196 | $self |
3027 | } |
3197 | } |
3028 | |
3198 | |
3029 | sub set_items { |
3199 | sub set_items { |
3030 | my ($self, $items) = @_; |
3200 | my ($self, $items) = @_; |
3031 | |
3201 | |
3032 | $self->{scrolled}->clear; |
3202 | $self->{child}->clear; |
3033 | return unless $items; |
3203 | return unless $items; |
3034 | |
3204 | |
3035 | my @items = sort { |
3205 | my @items = sort { |
3036 | ($a->{type} <=> $b->{type}) |
3206 | ($a->{type} <=> $b->{type}) |
3037 | or ($a->{name} cmp $b->{name}) |
3207 | or ($a->{name} cmp $b->{name}) |
… | |
… | |
3041 | |
3211 | |
3042 | my $row = 0; |
3212 | my $row = 0; |
3043 | for my $item (@items) { |
3213 | for my $item (@items) { |
3044 | CFClient::Item::update_widgets $item; |
3214 | CFClient::Item::update_widgets $item; |
3045 | |
3215 | |
3046 | $self->{scrolled}->add (0, $row, $item->{face_widget}); |
3216 | $self->{child}->add (0, $row, $item->{face_widget}); |
3047 | $self->{scrolled}->add (1, $row, $item->{desc_widget}); |
3217 | $self->{child}->add (1, $row, $item->{desc_widget}); |
3048 | $self->{scrolled}->add (2, $row, $item->{weight_widget}); |
3218 | $self->{child}->add (2, $row, $item->{weight_widget}); |
3049 | |
3219 | |
3050 | $row++; |
3220 | $row++; |
3051 | } |
3221 | } |
3052 | } |
3222 | } |
3053 | |
3223 | |
… | |
… | |
3151 | $rec = $::CONN->stop_record if $::CONN; |
3321 | $rec = $::CONN->stop_record if $::CONN; |
3152 | return unless ref $rec eq 'ARRAY'; |
3322 | return unless ref $rec eq 'ARRAY'; |
3153 | $self->set_command_list ($rec); |
3323 | $self->set_command_list ($rec); |
3154 | } |
3324 | } |
3155 | |
3325 | |
3156 | # if $commit is true, the binding will be set after the user entered a key combo |
3326 | |
|
|
3327 | sub ask_for_bind_and_commit { |
|
|
3328 | my ($self) = @_; |
|
|
3329 | $self->ask_for_bind (1); |
|
|
3330 | } |
|
|
3331 | |
3157 | sub ask_for_bind { |
3332 | sub ask_for_bind { |
3158 | my ($self, $commit) = @_; |
3333 | my ($self, $commit) = @_; |
3159 | |
3334 | |
3160 | CFClient::Binder::open_binding_dialog (sub { |
3335 | CFClient::Binder::open_binding_dialog (sub { |
3161 | my ($mod, $sym) = @_; |
3336 | my ($mod, $sym) = @_; |
… | |
… | |
3245 | |
3420 | |
3246 | ############################################################################# |
3421 | ############################################################################# |
3247 | |
3422 | |
3248 | package CFClient::UI::SpellList; |
3423 | package CFClient::UI::SpellList; |
3249 | |
3424 | |
3250 | our @ISA = CFClient::UI::FancyFrame::; |
3425 | our @ISA = CFClient::UI::Table::; |
3251 | |
3426 | |
3252 | sub new { |
3427 | sub new { |
3253 | my $class = shift; |
3428 | my $class = shift; |
3254 | |
3429 | |
3255 | my $self = $class->SUPER::new (binding => [], commands => [], @_); |
3430 | my $self = $class->SUPER::new ( |
3256 | |
3431 | binding => [], |
3257 | $self->add (new CFClient::UI::ScrolledWindow |
3432 | commands => [], |
3258 | scrolled => $self->{spellbox} = new CFClient::UI::Table); |
3433 | @_, |
3259 | |
3434 | ) |
3260 | $self; |
|
|
3261 | } |
3435 | } |
3262 | |
3436 | |
3263 | # XXX: Do sorting? Argl... |
3437 | # XXX: Do sorting? Argl... |
3264 | sub add_spell { |
3438 | sub add_spell { |
3265 | my ($self, $spell) = @_; |
3439 | my ($self, $spell) = @_; |
3266 | $self->{spells}->{$spell->{name}} = $spell; |
3440 | $self->{spells}->{$spell->{name}} = $spell; |
3267 | |
3441 | |
3268 | $self->{spellbox}->add (0, $self->{tbl_idx}, new CFClient::UI::Face |
3442 | $self->add (0, $self->{tbl_idx}, new CFClient::UI::Face |
3269 | face => $spell->{face}, |
3443 | face => $spell->{face}, |
3270 | can_hover => 1, |
3444 | can_hover => 1, |
3271 | can_events => 1, |
3445 | can_events => 1, |
3272 | tooltip => $spell->{message}); |
3446 | tooltip => $spell->{message}); |
3273 | |
3447 | |
3274 | $self->{spellbox}->add (1, $self->{tbl_idx}, new CFClient::UI::Label |
3448 | $self->add (1, $self->{tbl_idx}, new CFClient::UI::Label |
3275 | text => $spell->{name}, |
3449 | text => $spell->{name}, |
3276 | can_hover => 1, |
3450 | can_hover => 1, |
3277 | can_events => 1, |
3451 | can_events => 1, |
3278 | tooltip => $spell->{message}, |
3452 | tooltip => $spell->{message}, |
3279 | expand => 1); |
3453 | expand => 1); |
3280 | |
3454 | |
3281 | $self->{spellbox}->add (2, $self->{tbl_idx}, new CFClient::UI::Label |
3455 | $self->add (2, $self->{tbl_idx}, new CFClient::UI::Label |
3282 | text => (sprintf "lvl: %2d sp: %2d dmg: %2d", |
3456 | text => (sprintf "lvl: %2d sp: %2d dmg: %2d", |
3283 | $spell->{level}, ($spell->{mana} || $spell->{grace}), $spell->{damage}), |
3457 | $spell->{level}, ($spell->{mana} || $spell->{grace}), $spell->{damage}), |
3284 | expand => 1); |
3458 | expand => 1); |
3285 | |
3459 | |
3286 | $self->{spellbox}->add (3, $self->{tbl_idx}++, new CFClient::UI::Button |
3460 | $self->add (3, $self->{tbl_idx}++, new CFClient::UI::Button |
3287 | text => "bind to key", |
3461 | text => "bind to key", |
3288 | on_activate => sub { $::BIND_EDITOR->do_quick_binding (["cast $spell->{name}"]) }); |
3462 | on_activate => sub { $::BIND_EDITOR->do_quick_binding (["cast $spell->{name}"]) }); |
3289 | } |
3463 | } |
3290 | |
3464 | |
3291 | sub rebuild_spell_list { |
3465 | sub rebuild_spell_list { |