… | |
… | |
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 | |
… | |
… | |
661 | our @ISA = CFClient::UI::Base::; |
668 | our @ISA = CFClient::UI::Base::; |
662 | |
669 | |
663 | sub new { |
670 | sub new { |
664 | my ($class, %arg) = @_; |
671 | my ($class, %arg) = @_; |
665 | |
672 | |
666 | my $children = delete $arg{children} || []; |
673 | my $children = delete $arg{children}; |
667 | |
674 | |
668 | my $self = $class->SUPER::new ( |
675 | my $self = $class->SUPER::new ( |
669 | children => [], |
676 | children => [], |
670 | can_events => 0, |
677 | can_events => 0, |
671 | %arg, |
678 | %arg, |
672 | ); |
679 | ); |
|
|
680 | |
673 | $self->add ($_) for @$children; |
681 | $self->add (@$children) |
|
|
682 | if $children; |
674 | |
683 | |
675 | $self |
684 | $self |
676 | } |
685 | } |
677 | |
686 | |
678 | sub add { |
687 | sub add { |
… | |
… | |
726 | $x -= $self->{x}; |
735 | $x -= $self->{x}; |
727 | $y -= $self->{y}; |
736 | $y -= $self->{y}; |
728 | |
737 | |
729 | my $res; |
738 | my $res; |
730 | |
739 | |
731 | for (reverse @{ $self->{children} }) { |
740 | for (reverse $self->visible_children) { |
732 | $res = $_->find_widget ($x, $y) |
741 | $res = $_->find_widget ($x, $y) |
733 | and return $res; |
742 | and return $res; |
734 | } |
743 | } |
735 | |
744 | |
736 | $self->SUPER::find_widget ($x + $self->{x}, $y + $self->{y}) |
745 | $self->SUPER::find_widget ($x + $self->{x}, $y + $self->{y}) |
… | |
… | |
784 | |
793 | |
785 | $self->{children}[0]->configure (0, 0, $w, $h); |
794 | $self->{children}[0]->configure (0, 0, $w, $h); |
786 | } |
795 | } |
787 | |
796 | |
788 | ############################################################################# |
797 | ############################################################################# |
|
|
798 | |
|
|
799 | # back-buffered drawing area |
789 | |
800 | |
790 | package CFClient::UI::Window; |
801 | package CFClient::UI::Window; |
791 | |
802 | |
792 | our @ISA = CFClient::UI::Bin::; |
803 | our @ISA = CFClient::UI::Bin::; |
793 | |
804 | |
… | |
… | |
946 | package CFClient::UI::ScrolledWindow; |
957 | package CFClient::UI::ScrolledWindow; |
947 | |
958 | |
948 | our @ISA = CFClient::UI::HBox::; |
959 | our @ISA = CFClient::UI::HBox::; |
949 | |
960 | |
950 | sub new { |
961 | sub new { |
951 | my $class = shift; |
962 | my ($class, %arg) = @_; |
|
|
963 | |
|
|
964 | my $child = delete $arg{child}; |
952 | |
965 | |
953 | my $self; |
966 | my $self; |
954 | |
967 | |
955 | my $slider = new CFClient::UI::Slider |
968 | my $slider = new CFClient::UI::Slider |
956 | vertical => 1, |
969 | vertical => 1, |
… | |
… | |
961 | ; |
974 | ; |
962 | |
975 | |
963 | $self = $class->SUPER::new ( |
976 | $self = $class->SUPER::new ( |
964 | vp => (new CFClient::UI::ViewPort expand => 1), |
977 | vp => (new CFClient::UI::ViewPort expand => 1), |
965 | slider => $slider, |
978 | slider => $slider, |
966 | @_, |
979 | %arg, |
967 | ); |
980 | ); |
968 | |
981 | |
969 | $self->{vp}->add ($self->{scrolled}); |
|
|
970 | $self->add ($self->{vp}); |
|
|
971 | $self->add ($self->{slider}); |
982 | $self->SUPER::add ($self->{vp}, $self->{slider}); |
|
|
983 | $self->add ($child) if $child; |
972 | |
984 | |
973 | $self |
985 | $self |
|
|
986 | } |
|
|
987 | |
|
|
988 | sub add { |
|
|
989 | my ($self, $widget) = @_; |
|
|
990 | |
|
|
991 | $self->{vp}->add ($self->{child} = $widget); |
974 | } |
992 | } |
975 | |
993 | |
976 | sub update { |
994 | sub update { |
977 | my ($self) = @_; |
995 | my ($self) = @_; |
978 | |
996 | |
… | |
… | |
1157 | |
1175 | |
1158 | ($x, $y) = ($ev->{x}, $ev->{y}); |
1176 | ($x, $y) = ($ev->{x}, $ev->{y}); |
1159 | |
1177 | |
1160 | $self->move_abs ($bx + $x - $ox, $by + $y - $oy); |
1178 | $self->move_abs ($bx + $x - $ox, $by + $y - $oy); |
1161 | }; |
1179 | }; |
|
|
1180 | } else { |
|
|
1181 | return 0; |
|
|
1182 | } |
|
|
1183 | |
1162 | } |
1184 | 1 |
1163 | } |
1185 | } |
1164 | |
1186 | |
1165 | sub button_up { |
1187 | sub button_up { |
1166 | my ($self, $ev, $x, $y) = @_; |
1188 | my ($self, $ev, $x, $y) = @_; |
1167 | |
1189 | |
1168 | delete $self->{motion}; |
1190 | !!delete $self->{motion} |
1169 | } |
1191 | } |
1170 | |
1192 | |
1171 | sub mouse_motion { |
1193 | sub mouse_motion { |
1172 | my ($self, $ev, $x, $y) = @_; |
1194 | my ($self, $ev, $x, $y) = @_; |
1173 | |
1195 | |
1174 | $self->{motion}->($ev, $x, $y) if $self->{motion}; |
1196 | $self->{motion}->($ev, $x, $y) if $self->{motion}; |
|
|
1197 | |
|
|
1198 | !!$self->{motion} |
1175 | } |
1199 | } |
1176 | |
1200 | |
1177 | sub _draw { |
1201 | sub _draw { |
1178 | my ($self) = @_; |
1202 | my ($self) = @_; |
1179 | |
1203 | |
… | |
… | |
1652 | |
1676 | |
1653 | delete $self->{cur_h}; |
1677 | delete $self->{cur_h}; |
1654 | |
1678 | |
1655 | return if $self->{text} eq $text; |
1679 | return if $self->{text} eq $text; |
1656 | |
1680 | |
1657 | delete $self->{texture}; |
|
|
1658 | |
|
|
1659 | $self->{last_activity} = $::NOW; |
1681 | $self->{last_activity} = $::NOW; |
1660 | $self->{text} = $text; |
1682 | $self->{text} = $text; |
1661 | |
1683 | |
1662 | $text =~ s/./*/g if $self->{hidden}; |
1684 | $text =~ s/./*/g if $self->{hidden}; |
1663 | $self->{layout}->set_text ("$text "); |
1685 | $self->{layout}->set_text ("$text "); |
1664 | |
1686 | |
1665 | $self->_emit (changed => $self->{text}); |
1687 | $self->_emit (changed => $self->{text}); |
|
|
1688 | $self->update; |
1666 | } |
1689 | } |
1667 | |
1690 | |
1668 | sub set_text { |
1691 | sub set_text { |
1669 | my ($self, $text) = @_; |
1692 | my ($self, $text) = @_; |
1670 | |
1693 | |
… | |
… | |
1709 | $self->{cursor} = length $text; |
1732 | $self->{cursor} = length $text; |
1710 | } elsif ($uni == 27) { |
1733 | } elsif ($uni == 27) { |
1711 | $self->_emit ('escape'); |
1734 | $self->_emit ('escape'); |
1712 | } elsif ($uni) { |
1735 | } elsif ($uni) { |
1713 | substr $text, $self->{cursor}++, 0, chr $uni; |
1736 | substr $text, $self->{cursor}++, 0, chr $uni; |
|
|
1737 | } else { |
|
|
1738 | return 0; |
1714 | } |
1739 | } |
1715 | |
1740 | |
1716 | $self->_set_text ($text); |
1741 | $self->_set_text ($text); |
1717 | |
1742 | |
1718 | $self->realloc; |
1743 | $self->realloc; |
|
|
1744 | |
|
|
1745 | 1 |
1719 | } |
1746 | } |
1720 | |
1747 | |
1721 | sub focus_in { |
1748 | sub focus_in { |
1722 | my ($self) = @_; |
1749 | my ($self) = @_; |
1723 | |
1750 | |
… | |
… | |
1738 | utf8::encode $text; |
1765 | utf8::encode $text; |
1739 | $self->{cursor} = length substr $text, 0, $idx; |
1766 | $self->{cursor} = length substr $text, 0, $idx; |
1740 | |
1767 | |
1741 | $self->_set_text ($self->{text}); |
1768 | $self->_set_text ($self->{text}); |
1742 | $self->update; |
1769 | $self->update; |
|
|
1770 | |
|
|
1771 | 1 |
1743 | } |
1772 | } |
1744 | |
1773 | |
1745 | sub mouse_motion { |
1774 | sub mouse_motion { |
1746 | my ($self, $ev, $x, $y) = @_; |
1775 | my ($self, $ev, $x, $y) = @_; |
1747 | # printf "M %d,%d %d,%d\n", $ev->motion_x, $ev->motion_y, $x, $y;#d# |
1776 | # printf "M %d,%d %d,%d\n", $ev->motion_x, $ev->motion_y, $x, $y;#d# |
|
|
1777 | |
|
|
1778 | 0 |
1748 | } |
1779 | } |
1749 | |
1780 | |
1750 | sub _draw { |
1781 | sub _draw { |
1751 | my ($self) = @_; |
1782 | my ($self) = @_; |
1752 | |
1783 | |
… | |
… | |
1829 | } else { |
1860 | } else { |
1830 | $self->set_text ($self->{history_saveback}); |
1861 | $self->set_text ($self->{history_saveback}); |
1831 | } |
1862 | } |
1832 | |
1863 | |
1833 | } else { |
1864 | } else { |
1834 | $self->SUPER::key_down ($ev); |
1865 | return $self->SUPER::key_down ($ev) |
|
|
1866 | } |
|
|
1867 | |
1835 | } |
1868 | 1 |
1836 | |
|
|
1837 | } |
1869 | } |
1838 | |
1870 | |
1839 | ############################################################################# |
1871 | ############################################################################# |
1840 | |
1872 | |
1841 | package CFClient::UI::Button; |
1873 | package CFClient::UI::Button; |
… | |
… | |
1870 | my ($self, $ev, $x, $y) = @_; |
1902 | my ($self, $ev, $x, $y) = @_; |
1871 | |
1903 | |
1872 | $self->emit ("activate") |
1904 | $self->emit ("activate") |
1873 | if $x >= 0 && $x < $self->{w} |
1905 | if $x >= 0 && $x < $self->{w} |
1874 | && $y >= 0 && $y < $self->{h}; |
1906 | && $y >= 0 && $y < $self->{h}; |
|
|
1907 | |
|
|
1908 | 1 |
1875 | } |
1909 | } |
1876 | |
1910 | |
1877 | sub _draw { |
1911 | sub _draw { |
1878 | my ($self) = @_; |
1912 | my ($self) = @_; |
1879 | |
1913 | |
… | |
… | |
1933 | |
1967 | |
1934 | if ($x >= $self->{padding_x} && $x < $self->{w} - $self->{padding_x} |
1968 | if ($x >= $self->{padding_x} && $x < $self->{w} - $self->{padding_x} |
1935 | && $y >= $self->{padding_y} && $y < $self->{h} - $self->{padding_y}) { |
1969 | && $y >= $self->{padding_y} && $y < $self->{h} - $self->{padding_y}) { |
1936 | $self->{state} = !$self->{state}; |
1970 | $self->{state} = !$self->{state}; |
1937 | $self->_emit (changed => $self->{state}); |
1971 | $self->_emit (changed => $self->{state}); |
|
|
1972 | } else { |
|
|
1973 | return 0 |
|
|
1974 | } |
|
|
1975 | |
1938 | } |
1976 | 1 |
1939 | } |
1977 | } |
1940 | |
1978 | |
1941 | sub _draw { |
1979 | sub _draw { |
1942 | my ($self) = @_; |
1980 | my ($self) = @_; |
1943 | |
1981 | |
… | |
… | |
2281 | |
2319 | |
2282 | $self->SUPER::button_down ($ev, $x, $y); |
2320 | $self->SUPER::button_down ($ev, $x, $y); |
2283 | |
2321 | |
2284 | $self->{click} = [$self->{range}[0], $self->{vertical} ? $y : $x]; |
2322 | $self->{click} = [$self->{range}[0], $self->{vertical} ? $y : $x]; |
2285 | |
2323 | |
2286 | $self->mouse_motion ($ev, $x, $y); |
2324 | $self->mouse_motion ($ev, $x, $y) |
2287 | } |
2325 | } |
2288 | |
2326 | |
2289 | sub mouse_motion { |
2327 | sub mouse_motion { |
2290 | my ($self, $ev, $x, $y) = @_; |
2328 | my ($self, $ev, $x, $y) = @_; |
2291 | |
2329 | |
… | |
… | |
2295 | my (undef, $lo, $hi, $page) = @{$self->{range}}; |
2333 | my (undef, $lo, $hi, $page) = @{$self->{range}}; |
2296 | |
2334 | |
2297 | $x = ($x - $self->{click}[1]) / ($w * $self->{scale}); |
2335 | $x = ($x - $self->{click}[1]) / ($w * $self->{scale}); |
2298 | |
2336 | |
2299 | $self->set_value ($self->{click}[0] + $x * ($hi - $page - $lo)); |
2337 | $self->set_value ($self->{click}[0] + $x * ($hi - $page - $lo)); |
|
|
2338 | } else { |
|
|
2339 | return 0; |
|
|
2340 | } |
|
|
2341 | |
2300 | } |
2342 | 1 |
2301 | } |
2343 | } |
2302 | |
2344 | |
2303 | sub update { |
2345 | sub update { |
2304 | my ($self) = @_; |
2346 | my ($self) = @_; |
2305 | |
2347 | |
2306 | $CFClient::UI::ROOT->on_post_alloc ($self => sub { |
2348 | delete $self->{knob_w}; |
|
|
2349 | $self->SUPER::update; |
|
|
2350 | } |
|
|
2351 | |
|
|
2352 | sub _draw { |
|
|
2353 | my ($self) = @_; |
|
|
2354 | |
|
|
2355 | unless ($self->{knob_w}) { |
2307 | $self->set_value ($self->{range}[0]); |
2356 | $self->set_value ($self->{range}[0]); |
2308 | |
2357 | |
2309 | my ($value, $lo, $hi, $page) = @{$self->{range}}; |
2358 | my ($value, $lo, $hi, $page) = @{$self->{range}}; |
2310 | my $range = ($hi - $page - $lo) || 1e-100; |
2359 | my $range = ($hi - $page - $lo) || 1e-100; |
2311 | |
2360 | |
… | |
… | |
2317 | $value = ($value - $lo) / $range; |
2366 | $value = ($value - $lo) / $range; |
2318 | $value = $value * $self->{scale} + $self->{offset}; |
2367 | $value = $value * $self->{scale} + $self->{offset}; |
2319 | |
2368 | |
2320 | $self->{knob_x} = $value - $knob_w * 0.5; |
2369 | $self->{knob_x} = $value - $knob_w * 0.5; |
2321 | $self->{knob_w} = $knob_w; |
2370 | $self->{knob_w} = $knob_w; |
2322 | }); |
2371 | } |
2323 | |
|
|
2324 | $self->SUPER::update; |
|
|
2325 | } |
|
|
2326 | |
|
|
2327 | sub _draw { |
|
|
2328 | my ($self) = @_; |
|
|
2329 | |
2372 | |
2330 | $self->SUPER::_draw (); |
2373 | $self->SUPER::_draw (); |
2331 | |
2374 | |
2332 | glScale $self->{w}, $self->{h}; |
2375 | glScale $self->{w}, $self->{h}; |
2333 | |
2376 | |
… | |
… | |
2827 | $self->SUPER::DESTROY; |
2870 | $self->SUPER::DESTROY; |
2828 | } |
2871 | } |
2829 | |
2872 | |
2830 | ############################################################################# |
2873 | ############################################################################# |
2831 | |
2874 | |
|
|
2875 | package CFClient::UI::Buttonbar; |
|
|
2876 | |
|
|
2877 | our @ISA = CFClient::UI::HBox::; |
|
|
2878 | |
|
|
2879 | # TODO: should actualyl wrap buttons and other goodies. |
|
|
2880 | |
|
|
2881 | ############################################################################# |
|
|
2882 | |
2832 | package CFClient::UI::Menu; |
2883 | package CFClient::UI::Menu; |
2833 | |
2884 | |
2834 | our @ISA = CFClient::UI::FancyFrame::; |
2885 | our @ISA = CFClient::UI::FancyFrame::; |
2835 | |
2886 | |
2836 | use CFClient::OpenGL; |
2887 | use CFClient::OpenGL; |
… | |
… | |
2883 | my ($self, $ev, $x, $y) = @_; |
2934 | my ($self, $ev, $x, $y) = @_; |
2884 | |
2935 | |
2885 | # TODO: should use vbox->find_widget or so |
2936 | # TODO: should use vbox->find_widget or so |
2886 | $HOVER = $ROOT->find_widget ($ev->{x}, $ev->{y}); |
2937 | $HOVER = $ROOT->find_widget ($ev->{x}, $ev->{y}); |
2887 | $self->{hover} = $self->{item}{$HOVER}; |
2938 | $self->{hover} = $self->{item}{$HOVER}; |
|
|
2939 | |
|
|
2940 | 0 |
2888 | } |
2941 | } |
2889 | |
2942 | |
2890 | sub button_up { |
2943 | sub button_up { |
2891 | my ($self, $ev, $x, $y) = @_; |
2944 | my ($self, $ev, $x, $y) = @_; |
2892 | |
2945 | |
… | |
… | |
2894 | undef $GRAB; |
2947 | undef $GRAB; |
2895 | $self->hide; |
2948 | $self->hide; |
2896 | |
2949 | |
2897 | $self->_emit ("popdown"); |
2950 | $self->_emit ("popdown"); |
2898 | $self->{hover}[1]->() if $self->{hover}; |
2951 | $self->{hover}[1]->() if $self->{hover}; |
|
|
2952 | } else { |
|
|
2953 | return 0 |
|
|
2954 | } |
|
|
2955 | |
|
|
2956 | 1 |
|
|
2957 | } |
|
|
2958 | |
|
|
2959 | ############################################################################# |
|
|
2960 | |
|
|
2961 | package CFClient::UI::Multiplexer; |
|
|
2962 | |
|
|
2963 | our @ISA = CFClient::UI::Container::; |
|
|
2964 | |
|
|
2965 | sub new { |
|
|
2966 | my $class = shift; |
|
|
2967 | |
|
|
2968 | my $self = $class->SUPER::new ( |
|
|
2969 | @_, |
|
|
2970 | ); |
|
|
2971 | |
|
|
2972 | $self->{current} = $self->{children}[0] |
|
|
2973 | if @{ $self->{children} }; |
|
|
2974 | |
|
|
2975 | $self |
|
|
2976 | } |
|
|
2977 | |
|
|
2978 | sub add { |
|
|
2979 | my ($self, @widgets) = @_; |
|
|
2980 | |
|
|
2981 | $self->SUPER::add (@widgets); |
|
|
2982 | |
|
|
2983 | $self->{current} = $self->{children}[0] |
|
|
2984 | if @{ $self->{children} }; |
|
|
2985 | } |
|
|
2986 | |
|
|
2987 | sub set_current_page { |
|
|
2988 | my ($self, $page_or_widget) = @_; |
|
|
2989 | |
|
|
2990 | my $widget = ref $page_or_widget |
|
|
2991 | ? $page_or_widget |
|
|
2992 | : $self->{children}[$page_or_widget]; |
|
|
2993 | |
|
|
2994 | $self->{current} = $widget; |
|
|
2995 | $self->{current}->configure (0, 0, $self->{w}, $self->{h}); |
|
|
2996 | |
|
|
2997 | $self->_emit (page_changed => $self->{current}); |
|
|
2998 | |
|
|
2999 | $self->realloc; |
|
|
3000 | } |
|
|
3001 | |
|
|
3002 | sub visible_children { |
|
|
3003 | $_[0]{current} |
|
|
3004 | } |
|
|
3005 | |
|
|
3006 | sub size_request { |
|
|
3007 | my ($self) = @_; |
|
|
3008 | |
|
|
3009 | $self->{current}->size_request |
|
|
3010 | } |
|
|
3011 | |
|
|
3012 | sub size_allocate { |
|
|
3013 | my ($self, $w, $h) = @_; |
|
|
3014 | |
|
|
3015 | $self->{current}->configure (0, 0, $w, $h); |
|
|
3016 | } |
|
|
3017 | |
|
|
3018 | sub _draw { |
|
|
3019 | my ($self) = @_; |
|
|
3020 | |
|
|
3021 | $self->{current}->draw; |
|
|
3022 | } |
|
|
3023 | |
|
|
3024 | ############################################################################# |
|
|
3025 | |
|
|
3026 | package CFClient::UI::Notebook; |
|
|
3027 | |
|
|
3028 | our @ISA = CFClient::UI::VBox::; |
|
|
3029 | |
|
|
3030 | sub new { |
|
|
3031 | my $class = shift; |
|
|
3032 | |
|
|
3033 | my $self = $class->SUPER::new ( |
|
|
3034 | buttonbar => (new CFClient::UI::Buttonbar), |
|
|
3035 | multiplexer => (new CFClient::UI::Multiplexer expand => 1), |
|
|
3036 | # filter => # will be put between multiplexer and $self |
|
|
3037 | @_, |
|
|
3038 | ); |
2899 | } |
3039 | |
|
|
3040 | $self->{filter}->add ($self->{multiplexer}) if $self->{filter}; |
|
|
3041 | $self->SUPER::add ($self->{buttonbar}, $self->{filter} || $self->{multiplexer}); |
|
|
3042 | |
|
|
3043 | $self |
|
|
3044 | } |
|
|
3045 | |
|
|
3046 | sub add { |
|
|
3047 | my ($self, $title, $widget, $tooltip) = @_; |
|
|
3048 | |
|
|
3049 | Scalar::Util::weaken $self; |
|
|
3050 | |
|
|
3051 | $self->{buttonbar}->add (new CFClient::UI::Button |
|
|
3052 | markup => $title, |
|
|
3053 | tooltip => $tooltip, |
|
|
3054 | on_activate => sub { $self->set_current_page ($widget) }, |
|
|
3055 | ); |
|
|
3056 | |
|
|
3057 | $self->{multiplexer}->add ($widget); |
|
|
3058 | } |
|
|
3059 | |
|
|
3060 | sub set_current_page { |
|
|
3061 | my ($self, $page) = @_; |
|
|
3062 | |
|
|
3063 | $self->{multiplexer}->set_current_page ($page); |
|
|
3064 | $self->_emit (page_changed => $self->{multiplexer}{current}); |
2900 | } |
3065 | } |
2901 | |
3066 | |
2902 | ############################################################################# |
3067 | ############################################################################# |
2903 | |
3068 | |
2904 | package CFClient::UI::Statusbox; |
3069 | package CFClient::UI::Statusbox; |
… | |
… | |
3017 | |
3182 | |
3018 | sub new { |
3183 | sub new { |
3019 | my $class = shift; |
3184 | my $class = shift; |
3020 | |
3185 | |
3021 | my $self = $class->SUPER::new ( |
3186 | my $self = $class->SUPER::new ( |
3022 | scrolled => (new CFClient::UI::Table col_expand => [0, 1, 0]), |
3187 | child => (new CFClient::UI::Table col_expand => [0, 1, 0]), |
3023 | @_, |
3188 | @_, |
3024 | ); |
3189 | ); |
3025 | |
3190 | |
3026 | $self |
3191 | $self |
3027 | } |
3192 | } |
3028 | |
3193 | |
3029 | sub set_items { |
3194 | sub set_items { |
3030 | my ($self, $items) = @_; |
3195 | my ($self, $items) = @_; |
3031 | |
3196 | |
3032 | $self->{scrolled}->clear; |
3197 | $self->{child}->clear; |
3033 | return unless $items; |
3198 | return unless $items; |
3034 | |
3199 | |
3035 | my @items = sort { |
3200 | my @items = sort { |
3036 | ($a->{type} <=> $b->{type}) |
3201 | ($a->{type} <=> $b->{type}) |
3037 | or ($a->{name} cmp $b->{name}) |
3202 | or ($a->{name} cmp $b->{name}) |
… | |
… | |
3041 | |
3206 | |
3042 | my $row = 0; |
3207 | my $row = 0; |
3043 | for my $item (@items) { |
3208 | for my $item (@items) { |
3044 | CFClient::Item::update_widgets $item; |
3209 | CFClient::Item::update_widgets $item; |
3045 | |
3210 | |
3046 | $self->{scrolled}->add (0, $row, $item->{face_widget}); |
3211 | $self->{child}->add (0, $row, $item->{face_widget}); |
3047 | $self->{scrolled}->add (1, $row, $item->{desc_widget}); |
3212 | $self->{child}->add (1, $row, $item->{desc_widget}); |
3048 | $self->{scrolled}->add (2, $row, $item->{weight_widget}); |
3213 | $self->{child}->add (2, $row, $item->{weight_widget}); |
3049 | |
3214 | |
3050 | $row++; |
3215 | $row++; |
3051 | } |
3216 | } |
3052 | } |
3217 | } |
3053 | |
3218 | |
… | |
… | |
3250 | |
3415 | |
3251 | ############################################################################# |
3416 | ############################################################################# |
3252 | |
3417 | |
3253 | package CFClient::UI::SpellList; |
3418 | package CFClient::UI::SpellList; |
3254 | |
3419 | |
3255 | our @ISA = CFClient::UI::FancyFrame::; |
3420 | our @ISA = CFClient::UI::Table::; |
3256 | |
3421 | |
3257 | sub new { |
3422 | sub new { |
3258 | my $class = shift; |
3423 | my $class = shift; |
3259 | |
3424 | |
3260 | my $self = $class->SUPER::new (binding => [], commands => [], @_); |
3425 | my $self = $class->SUPER::new ( |
3261 | |
3426 | binding => [], |
3262 | $self->add (new CFClient::UI::ScrolledWindow |
3427 | commands => [], |
3263 | scrolled => $self->{spellbox} = new CFClient::UI::Table); |
3428 | @_, |
3264 | |
3429 | ) |
3265 | $self; |
|
|
3266 | } |
3430 | } |
3267 | |
3431 | |
3268 | # XXX: Do sorting? Argl... |
3432 | # XXX: Do sorting? Argl... |
3269 | sub add_spell { |
3433 | sub add_spell { |
3270 | my ($self, $spell) = @_; |
3434 | my ($self, $spell) = @_; |
3271 | $self->{spells}->{$spell->{name}} = $spell; |
3435 | $self->{spells}->{$spell->{name}} = $spell; |
3272 | |
3436 | |
3273 | $self->{spellbox}->add (0, $self->{tbl_idx}, new CFClient::UI::Face |
3437 | $self->add (0, $self->{tbl_idx}, new CFClient::UI::Face |
3274 | face => $spell->{face}, |
3438 | face => $spell->{face}, |
3275 | can_hover => 1, |
3439 | can_hover => 1, |
3276 | can_events => 1, |
3440 | can_events => 1, |
3277 | tooltip => $spell->{message}); |
3441 | tooltip => $spell->{message}); |
3278 | |
3442 | |
3279 | $self->{spellbox}->add (1, $self->{tbl_idx}, new CFClient::UI::Label |
3443 | $self->add (1, $self->{tbl_idx}, new CFClient::UI::Label |
3280 | text => $spell->{name}, |
3444 | text => $spell->{name}, |
3281 | can_hover => 1, |
3445 | can_hover => 1, |
3282 | can_events => 1, |
3446 | can_events => 1, |
3283 | tooltip => $spell->{message}, |
3447 | tooltip => $spell->{message}, |
3284 | expand => 1); |
3448 | expand => 1); |
3285 | |
3449 | |
3286 | $self->{spellbox}->add (2, $self->{tbl_idx}, new CFClient::UI::Label |
3450 | $self->add (2, $self->{tbl_idx}, new CFClient::UI::Label |
3287 | text => (sprintf "lvl: %2d sp: %2d dmg: %2d", |
3451 | text => (sprintf "lvl: %2d sp: %2d dmg: %2d", |
3288 | $spell->{level}, ($spell->{mana} || $spell->{grace}), $spell->{damage}), |
3452 | $spell->{level}, ($spell->{mana} || $spell->{grace}), $spell->{damage}), |
3289 | expand => 1); |
3453 | expand => 1); |
3290 | |
3454 | |
3291 | $self->{spellbox}->add (3, $self->{tbl_idx}++, new CFClient::UI::Button |
3455 | $self->add (3, $self->{tbl_idx}++, new CFClient::UI::Button |
3292 | text => "bind to key", |
3456 | text => "bind to key", |
3293 | on_activate => sub { $::BIND_EDITOR->do_quick_binding (["cast $spell->{name}"]) }); |
3457 | on_activate => sub { $::BIND_EDITOR->do_quick_binding (["cast $spell->{name}"]) }); |
3294 | } |
3458 | } |
3295 | |
3459 | |
3296 | sub rebuild_spell_list { |
3460 | sub rebuild_spell_list { |