… | |
… | |
439 | |
439 | |
440 | $::MAPWIDGET->focus_in #d# focus mapwidget if no other widget has focus |
440 | $::MAPWIDGET->focus_in #d# focus mapwidget if no other widget has focus |
441 | unless $FOCUS; |
441 | unless $FOCUS; |
442 | } |
442 | } |
443 | |
443 | |
444 | sub mouse_motion { } |
444 | sub mouse_motion { 0 } |
445 | sub button_up { } |
445 | sub button_up { 0 } |
446 | sub key_down { } |
446 | sub key_down { 0 } |
447 | sub key_up { } |
447 | sub key_up { 0 } |
448 | |
448 | |
449 | sub button_down { |
449 | sub button_down { |
450 | my ($self, $ev, $x, $y) = @_; |
450 | my ($self, $ev, $x, $y) = @_; |
451 | |
451 | |
452 | $self->focus_in; |
452 | $self->focus_in; |
|
|
453 | |
|
|
454 | 0 |
453 | } |
455 | } |
454 | |
456 | |
455 | sub find_widget { |
457 | sub find_widget { |
456 | my ($self, $x, $y) = @_; |
458 | my ($self, $x, $y) = @_; |
457 | |
459 | |
… | |
… | |
1157 | |
1159 | |
1158 | ($x, $y) = ($ev->{x}, $ev->{y}); |
1160 | ($x, $y) = ($ev->{x}, $ev->{y}); |
1159 | |
1161 | |
1160 | $self->move_abs ($bx + $x - $ox, $by + $y - $oy); |
1162 | $self->move_abs ($bx + $x - $ox, $by + $y - $oy); |
1161 | }; |
1163 | }; |
|
|
1164 | } else { |
|
|
1165 | return 0; |
|
|
1166 | } |
|
|
1167 | |
1162 | } |
1168 | 1 |
1163 | } |
1169 | } |
1164 | |
1170 | |
1165 | sub button_up { |
1171 | sub button_up { |
1166 | my ($self, $ev, $x, $y) = @_; |
1172 | my ($self, $ev, $x, $y) = @_; |
1167 | |
1173 | |
1168 | delete $self->{motion}; |
1174 | !!delete $self->{motion} |
1169 | } |
1175 | } |
1170 | |
1176 | |
1171 | sub mouse_motion { |
1177 | sub mouse_motion { |
1172 | my ($self, $ev, $x, $y) = @_; |
1178 | my ($self, $ev, $x, $y) = @_; |
1173 | |
1179 | |
1174 | $self->{motion}->($ev, $x, $y) if $self->{motion}; |
1180 | $self->{motion}->($ev, $x, $y) if $self->{motion}; |
|
|
1181 | |
|
|
1182 | !!$self->{motion} |
1175 | } |
1183 | } |
1176 | |
1184 | |
1177 | sub _draw { |
1185 | sub _draw { |
1178 | my ($self) = @_; |
1186 | my ($self) = @_; |
1179 | |
1187 | |
… | |
… | |
1709 | $self->{cursor} = length $text; |
1717 | $self->{cursor} = length $text; |
1710 | } elsif ($uni == 27) { |
1718 | } elsif ($uni == 27) { |
1711 | $self->_emit ('escape'); |
1719 | $self->_emit ('escape'); |
1712 | } elsif ($uni) { |
1720 | } elsif ($uni) { |
1713 | substr $text, $self->{cursor}++, 0, chr $uni; |
1721 | substr $text, $self->{cursor}++, 0, chr $uni; |
|
|
1722 | } else { |
|
|
1723 | return 0; |
1714 | } |
1724 | } |
1715 | |
1725 | |
1716 | $self->_set_text ($text); |
1726 | $self->_set_text ($text); |
1717 | |
1727 | |
1718 | $self->realloc; |
1728 | $self->realloc; |
|
|
1729 | |
|
|
1730 | 1 |
1719 | } |
1731 | } |
1720 | |
1732 | |
1721 | sub focus_in { |
1733 | sub focus_in { |
1722 | my ($self) = @_; |
1734 | my ($self) = @_; |
1723 | |
1735 | |
… | |
… | |
1738 | utf8::encode $text; |
1750 | utf8::encode $text; |
1739 | $self->{cursor} = length substr $text, 0, $idx; |
1751 | $self->{cursor} = length substr $text, 0, $idx; |
1740 | |
1752 | |
1741 | $self->_set_text ($self->{text}); |
1753 | $self->_set_text ($self->{text}); |
1742 | $self->update; |
1754 | $self->update; |
|
|
1755 | |
|
|
1756 | 1 |
1743 | } |
1757 | } |
1744 | |
1758 | |
1745 | sub mouse_motion { |
1759 | sub mouse_motion { |
1746 | my ($self, $ev, $x, $y) = @_; |
1760 | my ($self, $ev, $x, $y) = @_; |
1747 | # printf "M %d,%d %d,%d\n", $ev->motion_x, $ev->motion_y, $x, $y;#d# |
1761 | # printf "M %d,%d %d,%d\n", $ev->motion_x, $ev->motion_y, $x, $y;#d# |
|
|
1762 | |
|
|
1763 | 0 |
1748 | } |
1764 | } |
1749 | |
1765 | |
1750 | sub _draw { |
1766 | sub _draw { |
1751 | my ($self) = @_; |
1767 | my ($self) = @_; |
1752 | |
1768 | |
… | |
… | |
1829 | } else { |
1845 | } else { |
1830 | $self->set_text ($self->{history_saveback}); |
1846 | $self->set_text ($self->{history_saveback}); |
1831 | } |
1847 | } |
1832 | |
1848 | |
1833 | } else { |
1849 | } else { |
1834 | $self->SUPER::key_down ($ev); |
1850 | return $self->SUPER::key_down ($ev) |
|
|
1851 | } |
|
|
1852 | |
1835 | } |
1853 | 1 |
1836 | |
|
|
1837 | } |
1854 | } |
1838 | |
1855 | |
1839 | ############################################################################# |
1856 | ############################################################################# |
1840 | |
1857 | |
1841 | package CFClient::UI::Button; |
1858 | package CFClient::UI::Button; |
… | |
… | |
1870 | my ($self, $ev, $x, $y) = @_; |
1887 | my ($self, $ev, $x, $y) = @_; |
1871 | |
1888 | |
1872 | $self->emit ("activate") |
1889 | $self->emit ("activate") |
1873 | if $x >= 0 && $x < $self->{w} |
1890 | if $x >= 0 && $x < $self->{w} |
1874 | && $y >= 0 && $y < $self->{h}; |
1891 | && $y >= 0 && $y < $self->{h}; |
|
|
1892 | |
|
|
1893 | 1 |
1875 | } |
1894 | } |
1876 | |
1895 | |
1877 | sub _draw { |
1896 | sub _draw { |
1878 | my ($self) = @_; |
1897 | my ($self) = @_; |
1879 | |
1898 | |
… | |
… | |
1933 | |
1952 | |
1934 | if ($x >= $self->{padding_x} && $x < $self->{w} - $self->{padding_x} |
1953 | if ($x >= $self->{padding_x} && $x < $self->{w} - $self->{padding_x} |
1935 | && $y >= $self->{padding_y} && $y < $self->{h} - $self->{padding_y}) { |
1954 | && $y >= $self->{padding_y} && $y < $self->{h} - $self->{padding_y}) { |
1936 | $self->{state} = !$self->{state}; |
1955 | $self->{state} = !$self->{state}; |
1937 | $self->_emit (changed => $self->{state}); |
1956 | $self->_emit (changed => $self->{state}); |
|
|
1957 | } else { |
|
|
1958 | return 0 |
|
|
1959 | } |
|
|
1960 | |
1938 | } |
1961 | 1 |
1939 | } |
1962 | } |
1940 | |
1963 | |
1941 | sub _draw { |
1964 | sub _draw { |
1942 | my ($self) = @_; |
1965 | my ($self) = @_; |
1943 | |
1966 | |
… | |
… | |
2281 | |
2304 | |
2282 | $self->SUPER::button_down ($ev, $x, $y); |
2305 | $self->SUPER::button_down ($ev, $x, $y); |
2283 | |
2306 | |
2284 | $self->{click} = [$self->{range}[0], $self->{vertical} ? $y : $x]; |
2307 | $self->{click} = [$self->{range}[0], $self->{vertical} ? $y : $x]; |
2285 | |
2308 | |
2286 | $self->mouse_motion ($ev, $x, $y); |
2309 | $self->mouse_motion ($ev, $x, $y) |
2287 | } |
2310 | } |
2288 | |
2311 | |
2289 | sub mouse_motion { |
2312 | sub mouse_motion { |
2290 | my ($self, $ev, $x, $y) = @_; |
2313 | my ($self, $ev, $x, $y) = @_; |
2291 | |
2314 | |
… | |
… | |
2295 | my (undef, $lo, $hi, $page) = @{$self->{range}}; |
2318 | my (undef, $lo, $hi, $page) = @{$self->{range}}; |
2296 | |
2319 | |
2297 | $x = ($x - $self->{click}[1]) / ($w * $self->{scale}); |
2320 | $x = ($x - $self->{click}[1]) / ($w * $self->{scale}); |
2298 | |
2321 | |
2299 | $self->set_value ($self->{click}[0] + $x * ($hi - $page - $lo)); |
2322 | $self->set_value ($self->{click}[0] + $x * ($hi - $page - $lo)); |
|
|
2323 | } else { |
|
|
2324 | return 0; |
|
|
2325 | } |
|
|
2326 | |
2300 | } |
2327 | 1 |
2301 | } |
2328 | } |
2302 | |
2329 | |
2303 | sub update { |
2330 | sub update { |
2304 | my ($self) = @_; |
2331 | my ($self) = @_; |
2305 | |
2332 | |
… | |
… | |
2883 | my ($self, $ev, $x, $y) = @_; |
2910 | my ($self, $ev, $x, $y) = @_; |
2884 | |
2911 | |
2885 | # TODO: should use vbox->find_widget or so |
2912 | # TODO: should use vbox->find_widget or so |
2886 | $HOVER = $ROOT->find_widget ($ev->{x}, $ev->{y}); |
2913 | $HOVER = $ROOT->find_widget ($ev->{x}, $ev->{y}); |
2887 | $self->{hover} = $self->{item}{$HOVER}; |
2914 | $self->{hover} = $self->{item}{$HOVER}; |
|
|
2915 | |
|
|
2916 | 0 |
2888 | } |
2917 | } |
2889 | |
2918 | |
2890 | sub button_up { |
2919 | sub button_up { |
2891 | my ($self, $ev, $x, $y) = @_; |
2920 | my ($self, $ev, $x, $y) = @_; |
2892 | |
2921 | |
… | |
… | |
2894 | undef $GRAB; |
2923 | undef $GRAB; |
2895 | $self->hide; |
2924 | $self->hide; |
2896 | |
2925 | |
2897 | $self->_emit ("popdown"); |
2926 | $self->_emit ("popdown"); |
2898 | $self->{hover}[1]->() if $self->{hover}; |
2927 | $self->{hover}[1]->() if $self->{hover}; |
|
|
2928 | } else { |
|
|
2929 | return 0 |
|
|
2930 | } |
|
|
2931 | |
2899 | } |
2932 | 1 |
2900 | } |
2933 | } |
2901 | |
2934 | |
2902 | ############################################################################# |
2935 | ############################################################################# |
2903 | |
2936 | |
2904 | package CFClient::UI::Statusbox; |
2937 | package CFClient::UI::Statusbox; |