… | |
… | |
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}) |
… | |
… | |
1157 | |
1166 | |
1158 | ($x, $y) = ($ev->{x}, $ev->{y}); |
1167 | ($x, $y) = ($ev->{x}, $ev->{y}); |
1159 | |
1168 | |
1160 | $self->move_abs ($bx + $x - $ox, $by + $y - $oy); |
1169 | $self->move_abs ($bx + $x - $ox, $by + $y - $oy); |
1161 | }; |
1170 | }; |
|
|
1171 | } else { |
|
|
1172 | return 0; |
|
|
1173 | } |
|
|
1174 | |
1162 | } |
1175 | 1 |
1163 | } |
1176 | } |
1164 | |
1177 | |
1165 | sub button_up { |
1178 | sub button_up { |
1166 | my ($self, $ev, $x, $y) = @_; |
1179 | my ($self, $ev, $x, $y) = @_; |
1167 | |
1180 | |
1168 | delete $self->{motion}; |
1181 | !!delete $self->{motion} |
1169 | } |
1182 | } |
1170 | |
1183 | |
1171 | sub mouse_motion { |
1184 | sub mouse_motion { |
1172 | my ($self, $ev, $x, $y) = @_; |
1185 | my ($self, $ev, $x, $y) = @_; |
1173 | |
1186 | |
1174 | $self->{motion}->($ev, $x, $y) if $self->{motion}; |
1187 | $self->{motion}->($ev, $x, $y) if $self->{motion}; |
|
|
1188 | |
|
|
1189 | !!$self->{motion} |
1175 | } |
1190 | } |
1176 | |
1191 | |
1177 | sub _draw { |
1192 | sub _draw { |
1178 | my ($self) = @_; |
1193 | my ($self) = @_; |
1179 | |
1194 | |
… | |
… | |
1709 | $self->{cursor} = length $text; |
1724 | $self->{cursor} = length $text; |
1710 | } elsif ($uni == 27) { |
1725 | } elsif ($uni == 27) { |
1711 | $self->_emit ('escape'); |
1726 | $self->_emit ('escape'); |
1712 | } elsif ($uni) { |
1727 | } elsif ($uni) { |
1713 | substr $text, $self->{cursor}++, 0, chr $uni; |
1728 | substr $text, $self->{cursor}++, 0, chr $uni; |
|
|
1729 | } else { |
|
|
1730 | return 0; |
1714 | } |
1731 | } |
1715 | |
1732 | |
1716 | $self->_set_text ($text); |
1733 | $self->_set_text ($text); |
1717 | |
1734 | |
1718 | $self->realloc; |
1735 | $self->realloc; |
|
|
1736 | |
|
|
1737 | 1 |
1719 | } |
1738 | } |
1720 | |
1739 | |
1721 | sub focus_in { |
1740 | sub focus_in { |
1722 | my ($self) = @_; |
1741 | my ($self) = @_; |
1723 | |
1742 | |
… | |
… | |
1738 | utf8::encode $text; |
1757 | utf8::encode $text; |
1739 | $self->{cursor} = length substr $text, 0, $idx; |
1758 | $self->{cursor} = length substr $text, 0, $idx; |
1740 | |
1759 | |
1741 | $self->_set_text ($self->{text}); |
1760 | $self->_set_text ($self->{text}); |
1742 | $self->update; |
1761 | $self->update; |
|
|
1762 | |
|
|
1763 | 1 |
1743 | } |
1764 | } |
1744 | |
1765 | |
1745 | sub mouse_motion { |
1766 | sub mouse_motion { |
1746 | my ($self, $ev, $x, $y) = @_; |
1767 | my ($self, $ev, $x, $y) = @_; |
1747 | # printf "M %d,%d %d,%d\n", $ev->motion_x, $ev->motion_y, $x, $y;#d# |
1768 | # printf "M %d,%d %d,%d\n", $ev->motion_x, $ev->motion_y, $x, $y;#d# |
|
|
1769 | |
|
|
1770 | 0 |
1748 | } |
1771 | } |
1749 | |
1772 | |
1750 | sub _draw { |
1773 | sub _draw { |
1751 | my ($self) = @_; |
1774 | my ($self) = @_; |
1752 | |
1775 | |
… | |
… | |
1829 | } else { |
1852 | } else { |
1830 | $self->set_text ($self->{history_saveback}); |
1853 | $self->set_text ($self->{history_saveback}); |
1831 | } |
1854 | } |
1832 | |
1855 | |
1833 | } else { |
1856 | } else { |
1834 | $self->SUPER::key_down ($ev); |
1857 | return $self->SUPER::key_down ($ev) |
|
|
1858 | } |
|
|
1859 | |
1835 | } |
1860 | 1 |
1836 | |
|
|
1837 | } |
1861 | } |
1838 | |
1862 | |
1839 | ############################################################################# |
1863 | ############################################################################# |
1840 | |
1864 | |
1841 | package CFClient::UI::Button; |
1865 | package CFClient::UI::Button; |
… | |
… | |
1870 | my ($self, $ev, $x, $y) = @_; |
1894 | my ($self, $ev, $x, $y) = @_; |
1871 | |
1895 | |
1872 | $self->emit ("activate") |
1896 | $self->emit ("activate") |
1873 | if $x >= 0 && $x < $self->{w} |
1897 | if $x >= 0 && $x < $self->{w} |
1874 | && $y >= 0 && $y < $self->{h}; |
1898 | && $y >= 0 && $y < $self->{h}; |
|
|
1899 | |
|
|
1900 | 1 |
1875 | } |
1901 | } |
1876 | |
1902 | |
1877 | sub _draw { |
1903 | sub _draw { |
1878 | my ($self) = @_; |
1904 | my ($self) = @_; |
1879 | |
1905 | |
… | |
… | |
1933 | |
1959 | |
1934 | if ($x >= $self->{padding_x} && $x < $self->{w} - $self->{padding_x} |
1960 | if ($x >= $self->{padding_x} && $x < $self->{w} - $self->{padding_x} |
1935 | && $y >= $self->{padding_y} && $y < $self->{h} - $self->{padding_y}) { |
1961 | && $y >= $self->{padding_y} && $y < $self->{h} - $self->{padding_y}) { |
1936 | $self->{state} = !$self->{state}; |
1962 | $self->{state} = !$self->{state}; |
1937 | $self->_emit (changed => $self->{state}); |
1963 | $self->_emit (changed => $self->{state}); |
|
|
1964 | } else { |
|
|
1965 | return 0 |
|
|
1966 | } |
|
|
1967 | |
1938 | } |
1968 | 1 |
1939 | } |
1969 | } |
1940 | |
1970 | |
1941 | sub _draw { |
1971 | sub _draw { |
1942 | my ($self) = @_; |
1972 | my ($self) = @_; |
1943 | |
1973 | |
… | |
… | |
2281 | |
2311 | |
2282 | $self->SUPER::button_down ($ev, $x, $y); |
2312 | $self->SUPER::button_down ($ev, $x, $y); |
2283 | |
2313 | |
2284 | $self->{click} = [$self->{range}[0], $self->{vertical} ? $y : $x]; |
2314 | $self->{click} = [$self->{range}[0], $self->{vertical} ? $y : $x]; |
2285 | |
2315 | |
2286 | $self->mouse_motion ($ev, $x, $y); |
2316 | $self->mouse_motion ($ev, $x, $y) |
2287 | } |
2317 | } |
2288 | |
2318 | |
2289 | sub mouse_motion { |
2319 | sub mouse_motion { |
2290 | my ($self, $ev, $x, $y) = @_; |
2320 | my ($self, $ev, $x, $y) = @_; |
2291 | |
2321 | |
… | |
… | |
2295 | my (undef, $lo, $hi, $page) = @{$self->{range}}; |
2325 | my (undef, $lo, $hi, $page) = @{$self->{range}}; |
2296 | |
2326 | |
2297 | $x = ($x - $self->{click}[1]) / ($w * $self->{scale}); |
2327 | $x = ($x - $self->{click}[1]) / ($w * $self->{scale}); |
2298 | |
2328 | |
2299 | $self->set_value ($self->{click}[0] + $x * ($hi - $page - $lo)); |
2329 | $self->set_value ($self->{click}[0] + $x * ($hi - $page - $lo)); |
|
|
2330 | } else { |
|
|
2331 | return 0; |
|
|
2332 | } |
|
|
2333 | |
2300 | } |
2334 | 1 |
2301 | } |
2335 | } |
2302 | |
2336 | |
2303 | sub update { |
2337 | sub update { |
2304 | my ($self) = @_; |
2338 | my ($self) = @_; |
2305 | |
2339 | |
… | |
… | |
2827 | $self->SUPER::DESTROY; |
2861 | $self->SUPER::DESTROY; |
2828 | } |
2862 | } |
2829 | |
2863 | |
2830 | ############################################################################# |
2864 | ############################################################################# |
2831 | |
2865 | |
|
|
2866 | package CFClient::UI::Buttonbar; |
|
|
2867 | |
|
|
2868 | our @ISA = CFClient::UI::HBox::; |
|
|
2869 | |
|
|
2870 | # TODO: should actualyl wrap buttons and other goodies. |
|
|
2871 | |
|
|
2872 | ############################################################################# |
|
|
2873 | |
2832 | package CFClient::UI::Menu; |
2874 | package CFClient::UI::Menu; |
2833 | |
2875 | |
2834 | our @ISA = CFClient::UI::FancyFrame::; |
2876 | our @ISA = CFClient::UI::FancyFrame::; |
2835 | |
2877 | |
2836 | use CFClient::OpenGL; |
2878 | use CFClient::OpenGL; |
… | |
… | |
2883 | my ($self, $ev, $x, $y) = @_; |
2925 | my ($self, $ev, $x, $y) = @_; |
2884 | |
2926 | |
2885 | # TODO: should use vbox->find_widget or so |
2927 | # TODO: should use vbox->find_widget or so |
2886 | $HOVER = $ROOT->find_widget ($ev->{x}, $ev->{y}); |
2928 | $HOVER = $ROOT->find_widget ($ev->{x}, $ev->{y}); |
2887 | $self->{hover} = $self->{item}{$HOVER}; |
2929 | $self->{hover} = $self->{item}{$HOVER}; |
|
|
2930 | |
|
|
2931 | 0 |
2888 | } |
2932 | } |
2889 | |
2933 | |
2890 | sub button_up { |
2934 | sub button_up { |
2891 | my ($self, $ev, $x, $y) = @_; |
2935 | my ($self, $ev, $x, $y) = @_; |
2892 | |
2936 | |
… | |
… | |
2894 | undef $GRAB; |
2938 | undef $GRAB; |
2895 | $self->hide; |
2939 | $self->hide; |
2896 | |
2940 | |
2897 | $self->_emit ("popdown"); |
2941 | $self->_emit ("popdown"); |
2898 | $self->{hover}[1]->() if $self->{hover}; |
2942 | $self->{hover}[1]->() if $self->{hover}; |
|
|
2943 | } else { |
|
|
2944 | return 0 |
|
|
2945 | } |
|
|
2946 | |
2899 | } |
2947 | 1 |
|
|
2948 | } |
|
|
2949 | |
|
|
2950 | ############################################################################# |
|
|
2951 | |
|
|
2952 | package CFClient::UI::Multiplexer; |
|
|
2953 | |
|
|
2954 | our @ISA = CFClient::UI::Container::; |
|
|
2955 | |
|
|
2956 | sub new { |
|
|
2957 | my $class = shift; |
|
|
2958 | |
|
|
2959 | my $self = $class->SUPER::new ( |
|
|
2960 | @_, |
|
|
2961 | ); |
|
|
2962 | |
|
|
2963 | $self->{current} = $self->{children}[0] |
|
|
2964 | if @{ $self->{children} }; |
|
|
2965 | |
|
|
2966 | $self |
|
|
2967 | } |
|
|
2968 | |
|
|
2969 | sub add { |
|
|
2970 | my ($self, @widgets) = @_; |
|
|
2971 | |
|
|
2972 | $self->SUPER::add (@widgets); |
|
|
2973 | |
|
|
2974 | $self->{current} = $self->{children}[0] |
|
|
2975 | if @{ $self->{children} }; |
|
|
2976 | } |
|
|
2977 | |
|
|
2978 | sub set_current_page { |
|
|
2979 | my ($self, $page_or_widget) = @_; |
|
|
2980 | |
|
|
2981 | my $widget = ref $page_or_widget |
|
|
2982 | ? $page_or_widget |
|
|
2983 | : $self->{children}[$page_or_widget]; |
|
|
2984 | |
|
|
2985 | $self->{current} = $widget; |
|
|
2986 | $self->{current}->configure (0, 0, $self->{w}, $self->{h}); |
|
|
2987 | |
|
|
2988 | $self->_emit (page_changed => $self->{current}); |
|
|
2989 | |
|
|
2990 | $self->realloc; |
|
|
2991 | } |
|
|
2992 | |
|
|
2993 | sub visible_children { |
|
|
2994 | $_[0]{current} |
|
|
2995 | } |
|
|
2996 | |
|
|
2997 | sub size_request { |
|
|
2998 | my ($self) = @_; |
|
|
2999 | |
|
|
3000 | $self->{current}->size_request |
|
|
3001 | } |
|
|
3002 | |
|
|
3003 | sub size_allocate { |
|
|
3004 | my ($self, $w, $h) = @_; |
|
|
3005 | |
|
|
3006 | $self->{current}->configure (0, 0, $w, $h); |
|
|
3007 | } |
|
|
3008 | |
|
|
3009 | sub _draw { |
|
|
3010 | my ($self) = @_; |
|
|
3011 | |
|
|
3012 | $self->{current}->draw; |
|
|
3013 | } |
|
|
3014 | |
|
|
3015 | ############################################################################# |
|
|
3016 | |
|
|
3017 | package CFClient::UI::Notebook; |
|
|
3018 | |
|
|
3019 | our @ISA = CFClient::UI::VBox::; |
|
|
3020 | |
|
|
3021 | sub new { |
|
|
3022 | my $class = shift; |
|
|
3023 | |
|
|
3024 | my $self = $class->SUPER::new ( |
|
|
3025 | buttonbar => (new CFClient::UI::Buttonbar), |
|
|
3026 | multiplexer => (new CFClient::UI::Multiplexer expand => 1), |
|
|
3027 | @_, |
|
|
3028 | ); |
|
|
3029 | |
|
|
3030 | $self->SUPER::add ($self->{buttonbar}, $self->{multiplexer}); |
|
|
3031 | |
|
|
3032 | $self |
|
|
3033 | } |
|
|
3034 | |
|
|
3035 | sub add { |
|
|
3036 | my ($self, $title, $widget, $tooltip) = @_; |
|
|
3037 | |
|
|
3038 | Scalar::Util::weaken $self; |
|
|
3039 | |
|
|
3040 | $self->{buttonbar}->add (new CFClient::UI::Button |
|
|
3041 | markup => $title, |
|
|
3042 | tooltip => $tooltip, |
|
|
3043 | on_activate => sub { $self->set_current_page ($widget) }, |
|
|
3044 | ); |
|
|
3045 | |
|
|
3046 | $self->{multiplexer}->add ($widget); |
|
|
3047 | } |
|
|
3048 | |
|
|
3049 | sub set_current_page { |
|
|
3050 | my ($self, $page) = @_; |
|
|
3051 | |
|
|
3052 | $self->{multiplexer}->set_current_page ($page); |
|
|
3053 | $self->_emit (page_changed => $self->{multiplexer}{current}); |
2900 | } |
3054 | } |
2901 | |
3055 | |
2902 | ############################################################################# |
3056 | ############################################################################# |
2903 | |
3057 | |
2904 | package CFClient::UI::Statusbox; |
3058 | package CFClient::UI::Statusbox; |
… | |
… | |
3151 | $rec = $::CONN->stop_record if $::CONN; |
3305 | $rec = $::CONN->stop_record if $::CONN; |
3152 | return unless ref $rec eq 'ARRAY'; |
3306 | return unless ref $rec eq 'ARRAY'; |
3153 | $self->set_command_list ($rec); |
3307 | $self->set_command_list ($rec); |
3154 | } |
3308 | } |
3155 | |
3309 | |
3156 | # if $commit is true, the binding will be set after the user entered a key combo |
3310 | |
|
|
3311 | sub ask_for_bind_and_commit { |
|
|
3312 | my ($self) = @_; |
|
|
3313 | $self->ask_for_bind (1); |
|
|
3314 | } |
|
|
3315 | |
3157 | sub ask_for_bind { |
3316 | sub ask_for_bind { |
3158 | my ($self, $commit) = @_; |
3317 | my ($self, $commit) = @_; |
3159 | |
3318 | |
3160 | CFClient::Binder::open_binding_dialog (sub { |
3319 | CFClient::Binder::open_binding_dialog (sub { |
3161 | my ($mod, $sym) = @_; |
3320 | my ($mod, $sym) = @_; |
… | |
… | |
3245 | |
3404 | |
3246 | ############################################################################# |
3405 | ############################################################################# |
3247 | |
3406 | |
3248 | package CFClient::UI::SpellList; |
3407 | package CFClient::UI::SpellList; |
3249 | |
3408 | |
3250 | our @ISA = CFClient::UI::FancyFrame::; |
3409 | our @ISA = CFClient::UI::ScrolledWindow::; |
3251 | |
3410 | |
3252 | sub new { |
3411 | sub new { |
3253 | my $class = shift; |
3412 | my $class = shift; |
3254 | |
3413 | |
3255 | my $self = $class->SUPER::new (binding => [], commands => [], @_); |
3414 | my $self = $class->SUPER::new ( |
3256 | |
3415 | binding => [], |
3257 | $self->add (new CFClient::UI::ScrolledWindow |
3416 | commands => [], |
3258 | scrolled => $self->{spellbox} = new CFClient::UI::Table); |
3417 | scrolled => (new CFClient::UI::Table), |
3259 | |
3418 | @_, |
3260 | $self; |
3419 | ) |
3261 | } |
3420 | } |
3262 | |
3421 | |
3263 | # XXX: Do sorting? Argl... |
3422 | # XXX: Do sorting? Argl... |
3264 | sub add_spell { |
3423 | sub add_spell { |
3265 | my ($self, $spell) = @_; |
3424 | my ($self, $spell) = @_; |
3266 | $self->{spells}->{$spell->{name}} = $spell; |
3425 | $self->{spells}->{$spell->{name}} = $spell; |
3267 | |
3426 | |
3268 | $self->{spellbox}->add (0, $self->{tbl_idx}, new CFClient::UI::Face |
3427 | $self->{scrolled}->add (0, $self->{tbl_idx}, new CFClient::UI::Face |
3269 | face => $spell->{face}, |
3428 | face => $spell->{face}, |
3270 | can_hover => 1, |
3429 | can_hover => 1, |
3271 | can_events => 1, |
3430 | can_events => 1, |
3272 | tooltip => $spell->{message}); |
3431 | tooltip => $spell->{message}); |
3273 | |
3432 | |
3274 | $self->{spellbox}->add (1, $self->{tbl_idx}, new CFClient::UI::Label |
3433 | $self->{scrolled}->add (1, $self->{tbl_idx}, new CFClient::UI::Label |
3275 | text => $spell->{name}, |
3434 | text => $spell->{name}, |
3276 | can_hover => 1, |
3435 | can_hover => 1, |
3277 | can_events => 1, |
3436 | can_events => 1, |
3278 | tooltip => $spell->{message}, |
3437 | tooltip => $spell->{message}, |
3279 | expand => 1); |
3438 | expand => 1); |
3280 | |
3439 | |
3281 | $self->{spellbox}->add (2, $self->{tbl_idx}, new CFClient::UI::Label |
3440 | $self->{scrolled}->add (2, $self->{tbl_idx}, new CFClient::UI::Label |
3282 | text => (sprintf "lvl: %2d sp: %2d dmg: %2d", |
3441 | text => (sprintf "lvl: %2d sp: %2d dmg: %2d", |
3283 | $spell->{level}, ($spell->{mana} || $spell->{grace}), $spell->{damage}), |
3442 | $spell->{level}, ($spell->{mana} || $spell->{grace}), $spell->{damage}), |
3284 | expand => 1); |
3443 | expand => 1); |
3285 | |
3444 | |
3286 | $self->{spellbox}->add (3, $self->{tbl_idx}++, new CFClient::UI::Button |
3445 | $self->{scrolled}->add (3, $self->{tbl_idx}++, new CFClient::UI::Button |
3287 | text => "bind to key", |
3446 | text => "bind to key", |
3288 | on_activate => sub { $::BIND_EDITOR->do_quick_binding (["cast $spell->{name}"]) }); |
3447 | on_activate => sub { $::BIND_EDITOR->do_quick_binding (["cast $spell->{name}"]) }); |
3289 | } |
3448 | } |
3290 | |
3449 | |
3291 | sub rebuild_spell_list { |
3450 | sub rebuild_spell_list { |