… | |
… | |
50 | delete $TOOLTIP->{owner}; |
50 | delete $TOOLTIP->{owner}; |
51 | } |
51 | } |
52 | |
52 | |
53 | # class methods for events |
53 | # class methods for events |
54 | sub feed_sdl_key_down_event { |
54 | sub feed_sdl_key_down_event { |
55 | $FOCUS->emit (key_down => $_[0]) || $FOCUS->key_down ($_[0]) |
55 | $FOCUS->emit (key_down => $_[0]) |
56 | if $FOCUS; |
56 | if $FOCUS; |
57 | } |
57 | } |
58 | |
58 | |
59 | sub feed_sdl_key_up_event { |
59 | sub feed_sdl_key_up_event { |
60 | $FOCUS->emit (key_up => $_[0]) || $FOCUS->key_up ($_[0]) |
60 | $FOCUS->emit (key_up => $_[0]) |
61 | if $FOCUS; |
61 | if $FOCUS; |
62 | } |
62 | } |
63 | |
63 | |
64 | sub feed_sdl_button_down_event { |
64 | sub feed_sdl_button_down_event { |
65 | my ($ev) = @_; |
65 | my ($ev) = @_; |
… | |
… | |
74 | check_tooltip; |
74 | check_tooltip; |
75 | } |
75 | } |
76 | |
76 | |
77 | $BUTTON_STATE |= 1 << ($ev->{button} - 1); |
77 | $BUTTON_STATE |= 1 << ($ev->{button} - 1); |
78 | |
78 | |
79 | if ($GRAB) { |
79 | $GRAB->emit (button_down => $ev, $GRAB->coord2local ($x, $y)) |
80 | ($x, $y) = $GRAB->coord2local ($x, $y); |
80 | if $GRAB; |
81 | $GRAB->emit (button_down => $ev, $x, $y) || $GRAB->button_down ($ev, $x, $y); |
|
|
82 | } |
|
|
83 | } |
81 | } |
84 | |
82 | |
85 | sub feed_sdl_button_up_event { |
83 | sub feed_sdl_button_up_event { |
86 | my ($ev) = @_; |
84 | my ($ev) = @_; |
87 | my ($x, $y) = ($ev->{x}, $ev->{y}); |
85 | my ($x, $y) = ($ev->{x}, $ev->{y}); |
88 | |
86 | |
89 | my $widget = $GRAB || $ROOT->find_widget ($x, $y); |
87 | my $widget = $GRAB || $ROOT->find_widget ($x, $y); |
90 | |
88 | |
91 | $BUTTON_STATE &= ~(1 << ($ev->{button} - 1)); |
89 | $BUTTON_STATE &= ~(1 << ($ev->{button} - 1)); |
92 | |
90 | |
93 | if ($GRAB) { |
91 | $GRAB->emit (button_up => $ev, $GRAB->coord2local ($x, $y)) |
94 | ($x, $y) = $GRAB->coord2local ($x, $y); |
92 | if $GRAB; |
95 | $GRAB->emit (button_up => $ev, $x, $y) || $GRAB->button_up ($ev, $x, $y); |
|
|
96 | } |
|
|
97 | |
93 | |
98 | if (!$BUTTON_STATE) { |
94 | if (!$BUTTON_STATE) { |
99 | my $grab = $GRAB; undef $GRAB; |
95 | my $grab = $GRAB; undef $GRAB; |
100 | $grab->update if $grab; |
96 | $grab->update if $grab; |
101 | $GRAB->update if $GRAB; |
97 | $GRAB->update if $GRAB; |
… | |
… | |
117 | $HOVER->update if $HOVER && $HOVER->{can_hover}; |
113 | $HOVER->update if $HOVER && $HOVER->{can_hover}; |
118 | |
114 | |
119 | check_tooltip; |
115 | check_tooltip; |
120 | } |
116 | } |
121 | |
117 | |
122 | if ($HOVER) { |
|
|
123 | ($x, $y) = $HOVER->coord2local ($x, $y); |
|
|
124 | $HOVER->emit (mouse_motion => $ev, $x, $y) || $HOVER->mouse_motion ($ev, $x, $y); |
118 | $HOVER->emit (mouse_motion => $ev, $HOVER->coord2local ($x, $y)) |
125 | } |
119 | if $HOVER; |
126 | } |
120 | } |
127 | |
121 | |
128 | # convert position array to integers |
122 | # convert position array to integers |
129 | sub harmonize { |
123 | sub harmonize { |
130 | my ($vals) = @_; |
124 | my ($vals) = @_; |
… | |
… | |
229 | $self->move (($::WIDTH - $self->{w}) * 0.5, ($::HEIGHT - $self->{h}) * 0.5); |
223 | $self->move (($::WIDTH - $self->{w}) * 0.5, ($::HEIGHT - $self->{h}) * 0.5); |
230 | }, |
224 | }, |
231 | ); |
225 | ); |
232 | } |
226 | } |
233 | |
227 | |
234 | sub hide { |
228 | sub set_invisible { |
235 | my ($self) = @_; |
229 | my ($self) = @_; |
|
|
230 | |
|
|
231 | # broken show/hide model |
|
|
232 | |
|
|
233 | delete $self->{visible}; |
236 | |
234 | |
237 | undef $GRAB if $GRAB == $self; |
235 | undef $GRAB if $GRAB == $self; |
238 | undef $HOVER if $HOVER == $self; |
236 | undef $HOVER if $HOVER == $self; |
|
|
237 | |
|
|
238 | CFClient::UI::check_tooltip |
|
|
239 | if $CFClient::UI::TOOLTIP->{owner} == $self; |
|
|
240 | |
|
|
241 | $self->focus_out; |
|
|
242 | } |
|
|
243 | |
|
|
244 | sub hide { |
|
|
245 | my ($self) = @_; |
|
|
246 | |
|
|
247 | $self->set_invisible; |
239 | |
248 | |
240 | $self->{parent}->remove ($self) |
249 | $self->{parent}->remove ($self) |
241 | if $self->{parent}; |
250 | if $self->{parent}; |
242 | } |
251 | } |
243 | |
252 | |
… | |
… | |
343 | return if $FOCUS == $self; |
352 | return if $FOCUS == $self; |
344 | return unless $self->{can_focus}; |
353 | return unless $self->{can_focus}; |
345 | |
354 | |
346 | my $focus = $FOCUS; $FOCUS = $self; |
355 | my $focus = $FOCUS; $FOCUS = $self; |
347 | |
356 | |
348 | $self->emit (focus_in => $focus); |
357 | $self->_emit (focus_in => $focus); |
349 | |
358 | |
350 | $focus->update if $focus; |
359 | $focus->update if $focus; |
351 | $FOCUS->update; |
360 | $FOCUS->update; |
352 | } |
361 | } |
353 | |
362 | |
… | |
… | |
356 | |
365 | |
357 | return unless $FOCUS == $self; |
366 | return unless $FOCUS == $self; |
358 | |
367 | |
359 | my $focus = $FOCUS; undef $FOCUS; |
368 | my $focus = $FOCUS; undef $FOCUS; |
360 | |
369 | |
361 | $self->emit (focus_out => $focus); |
370 | $self->_emit (focus_out => $focus); |
362 | |
371 | |
363 | $focus->update if $focus; #? |
372 | $focus->update if $focus; #? |
|
|
373 | |
|
|
374 | $::MAPWIDGET->focus_in #d# focus mapwidget if no other widget has focus |
|
|
375 | unless $FOCUS; |
364 | } |
376 | } |
365 | |
377 | |
366 | sub mouse_motion { } |
378 | sub mouse_motion { } |
367 | sub button_up { } |
379 | sub button_up { } |
368 | sub key_down { } |
380 | sub key_down { } |
369 | sub key_up { } |
381 | sub key_up { } |
370 | |
382 | |
371 | sub button_down { |
383 | sub button_down { |
372 | my ($self, $ev, $x, $y) = @_; |
384 | my ($self, $ev, $x, $y) = @_; |
373 | |
385 | |
374 | $self->focus_in; |
386 | $self->focus_in; |
… | |
… | |
468 | my ($self, $signal, $cb) = @_; |
480 | my ($self, $signal, $cb) = @_; |
469 | |
481 | |
470 | push @{ $self->{signal_cb}{$signal} }, $cb; |
482 | push @{ $self->{signal_cb}{$signal} }, $cb; |
471 | } |
483 | } |
472 | |
484 | |
|
|
485 | sub _emit { |
|
|
486 | my ($self, $signal, @args) = @_; |
|
|
487 | |
|
|
488 | List::Util::sum map $_->($self, @args), @{$self->{signal_cb}{$signal} || []} |
|
|
489 | } |
|
|
490 | |
473 | sub emit { |
491 | sub emit { |
474 | my ($self, $signal, @args) = @_; |
492 | my ($self, $signal, @args) = @_; |
475 | |
493 | |
476 | List::Util::sum map $_->($self, @args), @{$self->{signal_cb}{$signal} || []} |
494 | $self->_emit ($signal, @args) |
|
|
495 | || $self->$signal (@args); |
477 | } |
496 | } |
478 | |
497 | |
479 | sub DESTROY { |
498 | sub DESTROY { |
480 | my ($self) = @_; |
499 | my ($self) = @_; |
481 | |
500 | |
… | |
… | |
1524 | $self->{text} = $text; |
1543 | $self->{text} = $text; |
1525 | |
1544 | |
1526 | $text =~ s/./*/g if $self->{hidden}; |
1545 | $text =~ s/./*/g if $self->{hidden}; |
1527 | $self->{layout}->set_text ("$text "); |
1546 | $self->{layout}->set_text ("$text "); |
1528 | |
1547 | |
1529 | $self->emit (changed => $self->{text}); |
1548 | $self->_emit (changed => $self->{text}); |
1530 | } |
1549 | } |
1531 | |
1550 | |
1532 | sub set_text { |
1551 | sub set_text { |
1533 | my ($self, $text) = @_; |
1552 | my ($self, $text) = @_; |
1534 | |
1553 | |
… | |
… | |
1546 | my ($self) = @_; |
1565 | my ($self) = @_; |
1547 | |
1566 | |
1548 | my ($w, $h) = $self->SUPER::size_request; |
1567 | my ($w, $h) = $self->SUPER::size_request; |
1549 | |
1568 | |
1550 | ($w + 1, $h) # add 1 for cursor |
1569 | ($w + 1, $h) # add 1 for cursor |
1551 | } |
|
|
1552 | |
|
|
1553 | sub size_allocate { |
|
|
1554 | my ($self, $w, $h) = @_; |
|
|
1555 | |
|
|
1556 | $self->_set_text (delete $self->{text});#d# don't check for == inside _set_text |
|
|
1557 | } |
1570 | } |
1558 | |
1571 | |
1559 | sub key_down { |
1572 | sub key_down { |
1560 | my ($self, $ev) = @_; |
1573 | my ($self, $ev) = @_; |
1561 | |
1574 | |
… | |
… | |
1576 | } elsif ($sym == CFClient::SDLK_HOME) { |
1589 | } elsif ($sym == CFClient::SDLK_HOME) { |
1577 | $self->{cursor} = 0; |
1590 | $self->{cursor} = 0; |
1578 | } elsif ($sym == CFClient::SDLK_END) { |
1591 | } elsif ($sym == CFClient::SDLK_END) { |
1579 | $self->{cursor} = length $text; |
1592 | $self->{cursor} = length $text; |
1580 | } elsif ($uni == 27) { |
1593 | } elsif ($uni == 27) { |
1581 | $self->emit ('escape'); |
1594 | $self->_emit ('escape'); |
1582 | } elsif ($uni) { |
1595 | } elsif ($uni) { |
1583 | substr $text, $self->{cursor}++, 0, chr $uni; |
1596 | substr $text, $self->{cursor}++, 0, chr $uni; |
1584 | } |
1597 | } |
1585 | |
1598 | |
1586 | $self->_set_text ($text); |
1599 | $self->_set_text ($text); |
… | |
… | |
1673 | if ($sym == 13) { |
1686 | if ($sym == 13) { |
1674 | unshift @{$self->{history}}, |
1687 | unshift @{$self->{history}}, |
1675 | my $txt = $self->get_text; |
1688 | my $txt = $self->get_text; |
1676 | $self->{history_pointer} = -1; |
1689 | $self->{history_pointer} = -1; |
1677 | $self->{history_saveback} = ''; |
1690 | $self->{history_saveback} = ''; |
1678 | $self->emit (activate => $txt); |
1691 | $self->_emit (activate => $txt); |
1679 | $self->update; |
1692 | $self->update; |
1680 | |
1693 | |
1681 | } elsif ($sym == CFClient::SDLK_UP) { |
1694 | } elsif ($sym == CFClient::SDLK_UP) { |
1682 | if ($self->{history_pointer} < 0) { |
1695 | if ($self->{history_pointer} < 0) { |
1683 | $self->{history_saveback} = $self->get_text; |
1696 | $self->{history_saveback} = $self->get_text; |
… | |
… | |
1731 | can_events => 1, |
1744 | can_events => 1, |
1732 | @_ |
1745 | @_ |
1733 | ) |
1746 | ) |
1734 | } |
1747 | } |
1735 | |
1748 | |
|
|
1749 | sub activate { } |
|
|
1750 | |
1736 | sub button_up { |
1751 | sub button_up { |
1737 | my ($self, $ev, $x, $y) = @_; |
1752 | my ($self, $ev, $x, $y) = @_; |
1738 | |
1753 | |
|
|
1754 | $self->emit ("activate") |
1739 | if ($x >= 0 && $x < $self->{w} |
1755 | if $x >= 0 && $x < $self->{w} |
1740 | && $y >= 0 && $y < $self->{h}) { |
1756 | && $y >= 0 && $y < $self->{h}; |
1741 | $self->emit ("activate"); |
|
|
1742 | } |
|
|
1743 | } |
1757 | } |
1744 | |
1758 | |
1745 | sub _draw { |
1759 | sub _draw { |
1746 | my ($self) = @_; |
1760 | my ($self) = @_; |
1747 | |
1761 | |
… | |
… | |
1799 | my ($self, $ev, $x, $y) = @_; |
1813 | my ($self, $ev, $x, $y) = @_; |
1800 | |
1814 | |
1801 | if ($x >= $self->{padding} && $x < $self->{w} - $self->{padding} |
1815 | if ($x >= $self->{padding} && $x < $self->{w} - $self->{padding} |
1802 | && $y >= $self->{padding} && $y < $self->{h} - $self->{padding}) { |
1816 | && $y >= $self->{padding} && $y < $self->{h} - $self->{padding}) { |
1803 | $self->{state} = !$self->{state}; |
1817 | $self->{state} = !$self->{state}; |
1804 | $self->emit (changed => $self->{state}); |
1818 | $self->_emit (changed => $self->{state}); |
1805 | } |
1819 | } |
1806 | } |
1820 | } |
1807 | |
1821 | |
1808 | sub _draw { |
1822 | sub _draw { |
1809 | my ($self) = @_; |
1823 | my ($self) = @_; |
… | |
… | |
2125 | if $unit; |
2139 | if $unit; |
2126 | |
2140 | |
2127 | @{$self->{range}} = ($value, $lo, $hi, $page, $unit); |
2141 | @{$self->{range}} = ($value, $lo, $hi, $page, $unit); |
2128 | |
2142 | |
2129 | if ($value != $old_value) { |
2143 | if ($value != $old_value) { |
2130 | $self->emit (changed => $value); |
2144 | $self->_emit (changed => $value); |
2131 | $self->update; |
2145 | $self->update; |
2132 | } |
2146 | } |
2133 | } |
2147 | } |
2134 | |
2148 | |
2135 | sub size_request { |
2149 | sub size_request { |
… | |
… | |
2517 | |
2531 | |
2518 | # TODO: use animation |
2532 | # TODO: use animation |
2519 | if ($self->{state} = !$self->{state}) { |
2533 | if ($self->{state} = !$self->{state}) { |
2520 | $CFClient::UI::ROOT->add ($self->{other}); |
2534 | $CFClient::UI::ROOT->add ($self->{other}); |
2521 | $self->{other}->move ($self->coord2global (0, $self->{h})); |
2535 | $self->{other}->move ($self->coord2global (0, $self->{h})); |
2522 | $self->emit ("open"); |
2536 | $self->_emit ("open"); |
2523 | } else { |
2537 | } else { |
2524 | $CFClient::UI::ROOT->remove ($self->{other}); |
2538 | $CFClient::UI::ROOT->remove ($self->{other}); |
2525 | $self->emit ("close"); |
2539 | $self->_emit ("close"); |
2526 | } |
2540 | } |
2527 | |
2541 | |
2528 | $self->emit (changed => $self->{state}); |
2542 | $self->_emit (changed => $self->{state}); |
2529 | } |
2543 | } |
2530 | |
2544 | |
2531 | ############################################################################# |
2545 | ############################################################################# |
2532 | |
2546 | |
2533 | package CFClient::UI::Tooltip; |
2547 | package CFClient::UI::Tooltip; |
… | |
… | |
2881 | |
2895 | |
2882 | # popup given the event (must be a mouse button down event currently) |
2896 | # popup given the event (must be a mouse button down event currently) |
2883 | sub popup { |
2897 | sub popup { |
2884 | my ($self, $ev) = @_; |
2898 | my ($self, $ev) = @_; |
2885 | |
2899 | |
2886 | $self->emit ("popdown"); |
2900 | $self->_emit ("popdown"); |
2887 | |
2901 | |
2888 | # maybe save $GRAB? must be careful about events... |
2902 | # maybe save $GRAB? must be careful about events... |
2889 | $GRAB = $self; |
2903 | $GRAB = $self; |
2890 | $self->{button} = $ev->{button}; |
2904 | $self->{button} = $ev->{button}; |
2891 | |
2905 | |
… | |
… | |
2906 | |
2920 | |
2907 | if ($ev->{button} == $self->{button}) { |
2921 | if ($ev->{button} == $self->{button}) { |
2908 | undef $GRAB; |
2922 | undef $GRAB; |
2909 | $self->hide; |
2923 | $self->hide; |
2910 | |
2924 | |
2911 | $self->emit ("popdown"); |
2925 | $self->_emit ("popdown"); |
2912 | $self->{hover}[1]->() if $self->{hover}; |
2926 | $self->{hover}[1]->() if $self->{hover}; |
2913 | } |
2927 | } |
2914 | } |
2928 | } |
2915 | |
2929 | |
2916 | ############################################################################# |
2930 | ############################################################################# |
… | |
… | |
3121 | $self->SUPER::remove (@children); |
3135 | $self->SUPER::remove (@children); |
3122 | |
3136 | |
3123 | while (@children) { |
3137 | while (@children) { |
3124 | my $w = pop @children; |
3138 | my $w = pop @children; |
3125 | push @children, $w->children; |
3139 | push @children, $w->children; |
3126 | delete $w->{visible}; |
3140 | $w->set_invisible; |
3127 | } |
3141 | } |
3128 | } |
3142 | } |
3129 | |
3143 | |
3130 | sub on_refresh { |
3144 | sub on_refresh { |
3131 | my ($self, $id, $cb) = @_; |
3145 | my ($self, $id, $cb) = @_; |
… | |
… | |
3185 | $w = 0 if $w < 0; |
3199 | $w = 0 if $w < 0; |
3186 | $h = 0 if $h < 0; |
3200 | $h = 0 if $h < 0; |
3187 | |
3201 | |
3188 | $widget->{w} = $w; |
3202 | $widget->{w} = $w; |
3189 | $widget->{h} = $h; |
3203 | $widget->{h} = $h; |
3190 | $widget->size_allocate ($w, $h); |
|
|
3191 | $widget->emit (size_allocate => $w, $h); |
3204 | $widget->emit (size_allocate => $w, $h); |
3192 | } |
3205 | } |
3193 | } |
3206 | } |
3194 | |
3207 | |
3195 | while ($self->{post_alloc_hook}) { |
3208 | while ($self->{post_alloc_hook}) { |