… | |
… | |
452 | |
452 | |
453 | $FOCUS->emit ("focus_out") if $FOCUS; |
453 | $FOCUS->emit ("focus_out") if $FOCUS; |
454 | $self->emit ("focus_in"); |
454 | $self->emit ("focus_in"); |
455 | } |
455 | } |
456 | |
456 | |
457 | sub invoke_mouse_motion { 1 } |
457 | sub invoke_mouse_motion { 0 } |
458 | sub invoke_button_up { 1 } |
458 | sub invoke_button_up { 0 } |
459 | sub invoke_key_down { 1 } |
459 | sub invoke_key_down { 0 } |
460 | sub invoke_key_up { 1 } |
460 | sub invoke_key_up { 0 } |
461 | |
461 | |
462 | sub invoke_button_down { |
462 | sub invoke_button_down { |
463 | my ($self, $ev, $x, $y) = @_; |
463 | my ($self, $ev, $x, $y) = @_; |
464 | |
464 | |
465 | $self->grab_focus; |
465 | $self->grab_focus; |
466 | |
466 | |
467 | 1 |
467 | 0 |
468 | } |
468 | } |
469 | |
469 | |
470 | sub connect { |
470 | sub connect { |
471 | my ($self, $signal, $cb) = @_; |
471 | my ($self, $signal, $cb) = @_; |
472 | |
472 | |
473 | push @{ $self->{signal_cb}{$signal} }, $cb; |
473 | push @{ $self->{signal_cb}{$signal} }, $cb; |
474 | } |
474 | } |
475 | |
475 | |
476 | sub emit { |
476 | sub emit { |
477 | my ($self, $signal, @args) = @_; |
477 | my ($self, $signal, @args) = @_; |
|
|
478 | |
|
|
479 | #warn +(caller(1))[3] . "emit $signal on $self (parent $self->{parent})\n";#d# |
478 | |
480 | |
479 | #d##TODO# stop propagating at first true, do not use sum |
481 | #d##TODO# stop propagating at first true, do not use sum |
480 | (List::Util::sum map $_->($self, @args), @{$self->{signal_cb}{$signal} || []}) # before |
482 | (List::Util::sum map $_->($self, @args), @{$self->{signal_cb}{$signal} || []}) # before |
481 | || ($self->can ("invoke_$signal") || sub { 1 })->($self, @args) # closure |
483 | || ($self->can ("invoke_$signal") || sub { 1 })->($self, @args) # closure |
482 | || ($self->{parent} && $self->{parent}->emit ($signal, @args)) # parent |
484 | || ($self->{parent} && $self->{parent}->emit ($signal, @args)) # parent |
… | |
… | |
587 | } |
589 | } |
588 | |
590 | |
589 | sub DESTROY { |
591 | sub DESTROY { |
590 | my ($self) = @_; |
592 | my ($self) = @_; |
591 | |
593 | |
|
|
594 | return if CFClient::in_destruct; |
|
|
595 | |
592 | delete $WIDGET{$self+0}; |
596 | delete $WIDGET{$self+0}; |
593 | |
597 | |
594 | eval { $self->destroy }; |
598 | eval { $self->destroy }; |
595 | warn "exception during widget destruction: $@" if $@ & $@ != /during global destruction/; |
599 | warn "exception during widget destruction: $@" if $@ & $@ != /during global destruction/; |
596 | } |
600 | } |
… | |
… | |
994 | my ($self, $widget) = @_; |
998 | my ($self, $widget) = @_; |
995 | |
999 | |
996 | $self->{vp}->add ($self->{child} = $widget); |
1000 | $self->{vp}->add ($self->{child} = $widget); |
997 | } |
1001 | } |
998 | |
1002 | |
|
|
1003 | sub invoke_button_up { |
|
|
1004 | my ($self, $ev) = @_; |
|
|
1005 | |
|
|
1006 | warn "button up $ev->{button}\n";#d# |
|
|
1007 | |
|
|
1008 | 0 |
|
|
1009 | } |
|
|
1010 | |
999 | sub update_slider { |
1011 | sub update_slider { |
1000 | my ($self) = @_; |
1012 | my ($self) = @_; |
1001 | |
1013 | |
1002 | $self->{slider}->set_range ([$self->{slider}{range}[0], 0, $self->{vp}->child->{h}, $self->{vp}{h}, 1]); |
1014 | $self->{slider}->set_range ([$self->{slider}{range}[0], 0, $self->{vp}->child->{h}, $self->{vp}{h}, 1]); |
1003 | } |
1015 | } |
… | |
… | |
1080 | my $self = $class->SUPER::new ( |
1092 | my $self = $class->SUPER::new ( |
1081 | bg => [1, 1, 1, 1], |
1093 | bg => [1, 1, 1, 1], |
1082 | border_bg => [1, 1, 1, 1], |
1094 | border_bg => [1, 1, 1, 1], |
1083 | border => 0.6, |
1095 | border => 0.6, |
1084 | can_events => 1, |
1096 | can_events => 1, |
1085 | min_w => 16, |
1097 | min_w => 64, |
1086 | min_h => 16, |
1098 | min_h => 32, |
1087 | %arg, |
1099 | %arg, |
1088 | ); |
1100 | ); |
1089 | |
1101 | |
1090 | $self->{title_widget} = new CFClient::UI::Label |
1102 | $self->{title_widget} = new CFClient::UI::Label |
1091 | align => 0, |
1103 | align => 0, |
… | |
… | |
1826 | |
1838 | |
1827 | my $idx = $self->{layout}->xy_to_index ($x, $y); |
1839 | my $idx = $self->{layout}->xy_to_index ($x, $y); |
1828 | |
1840 | |
1829 | # byte-index to char-index |
1841 | # byte-index to char-index |
1830 | my $text = $self->{text}; |
1842 | my $text = $self->{text}; |
1831 | utf8::encode $text; |
1843 | utf8::encode $text; $text = substr $text, 0, $idx; utf8::decode $text; |
1832 | $self->{cursor} = length substr $text, 0, $idx; |
1844 | $self->{cursor} = length $text; |
1833 | |
1845 | |
1834 | $self->_set_text ($self->{text}); |
1846 | $self->_set_text ($self->{text}); |
1835 | $self->update; |
1847 | $self->update; |
1836 | |
1848 | |
1837 | 1 |
1849 | 1 |
… | |
… | |
2116 | my $self = $class->SUPER::new ( |
2128 | my $self = $class->SUPER::new ( |
2117 | can_events => 0, |
2129 | can_events => 0, |
2118 | @_, |
2130 | @_, |
2119 | ); |
2131 | ); |
2120 | |
2132 | |
2121 | $self->{path} |
2133 | $self->{path} || $self->{tex} |
2122 | or Carp::croak "required attribute 'path' not set"; |
2134 | or Carp::croak "'path' or 'tex' attributes required"; |
2123 | |
2135 | |
2124 | $self->{tex} = $texture_cache{$self->{path}} ||= |
2136 | $self->{tex} ||= $texture_cache{$self->{path}} ||= |
2125 | new_from_file CFClient::Texture CFClient::find_rcfile $self->{path}, mipmap => 1; |
2137 | new_from_file CFClient::Texture CFClient::find_rcfile $self->{path}, mipmap => 1; |
2126 | |
2138 | |
2127 | Scalar::Util::weaken $texture_cache{$self->{path}}; |
2139 | Scalar::Util::weaken $texture_cache{$self->{path}}; |
2128 | |
2140 | |
2129 | $self->{aspect} ||= $self->{tex}{w} / $self->{tex}{h}; |
2141 | $self->{aspect} ||= $self->{tex}{w} / $self->{tex}{h}; |
… | |
… | |
3814 | my ($w, $h) = @$widget{qw(alloc_w alloc_h)}; |
3826 | my ($w, $h) = @$widget{qw(alloc_w alloc_h)}; |
3815 | |
3827 | |
3816 | $w = 0 if $w < 0; |
3828 | $w = 0 if $w < 0; |
3817 | $h = 0 if $h < 0; |
3829 | $h = 0 if $h < 0; |
3818 | |
3830 | |
|
|
3831 | $w = max $widget->{min_w}, $w; |
|
|
3832 | $h = max $widget->{min_h}, $h; |
|
|
3833 | |
|
|
3834 | $w = min $widget->{max_w}, $w if exists $widget->{max_w}; |
|
|
3835 | $h = min $widget->{max_h}, $h if exists $widget->{max_h}; |
|
|
3836 | |
3819 | $w = int $w + 0.5; |
3837 | $w = int $w + 0.5; |
3820 | $h = int $h + 0.5; |
3838 | $h = int $h + 0.5; |
3821 | |
3839 | |
3822 | if ($widget->{w} != $w || $widget->{h} != $h || delete $widget->{force_size_alloc}) { |
3840 | if ($widget->{w} != $w || $widget->{h} != $h || delete $widget->{force_size_alloc}) { |
3823 | $widget->{old_w} = $widget->{w}; |
3841 | $widget->{old_w} = $widget->{w}; |