… | |
… | |
944 | |
944 | |
945 | ############################################################################# |
945 | ############################################################################# |
946 | |
946 | |
947 | package CFPlus::UI::ViewPort; |
947 | package CFPlus::UI::ViewPort; |
948 | |
948 | |
|
|
949 | use List::Util qw(min max); |
|
|
950 | |
949 | our @ISA = CFPlus::UI::Window::; |
951 | our @ISA = CFPlus::UI::Window::; |
950 | |
952 | |
951 | sub new { |
953 | sub new { |
952 | my $class = shift; |
954 | my $class = shift; |
953 | |
955 | |
… | |
… | |
984 | } |
986 | } |
985 | |
987 | |
986 | sub set_offset { |
988 | sub set_offset { |
987 | my ($self, $x, $y) = @_; |
989 | my ($self, $x, $y) = @_; |
988 | |
990 | |
989 | $self->{view_x} = int $x; |
991 | $self->{view_x} = max 0, min $self->child->{w} - $self->{w}, int $x; |
990 | $self->{view_y} = int $y; |
992 | $self->{view_y} = max 0, min $self->child->{h} - $self->{h}, int $y; |
991 | |
993 | |
992 | $self->update; |
994 | $self->update; |
993 | } |
995 | } |
994 | |
996 | |
995 | # hmm, this does not work for topleft of $self... but we should not ask for that |
997 | # hmm, this does not work for topleft of $self... but we should not ask for that |
… | |
… | |
1092 | my ($self, $widget) = @_; |
1094 | my ($self, $widget) = @_; |
1093 | |
1095 | |
1094 | $self->{vp}->add ($self->{child} = $widget); |
1096 | $self->{vp}->add ($self->{child} = $widget); |
1095 | } |
1097 | } |
1096 | |
1098 | |
1097 | sub invoke_mouse_wheel { |
|
|
1098 | my ($self, $ev) = @_; |
|
|
1099 | |
|
|
1100 | return 0 unless $ev->{dy}; # only vertical movements for now |
|
|
1101 | |
|
|
1102 | $self->{vslider}->emit (mouse_wheel => $ev); |
|
|
1103 | |
|
|
1104 | 1 |
|
|
1105 | } |
|
|
1106 | |
|
|
1107 | sub update_slider { |
1099 | sub update_slider { |
1108 | my ($self) = @_; |
1100 | my ($self) = @_; |
1109 | |
1101 | |
1110 | my $child = ($self->{vp} or return)->child; |
1102 | my $child = ($self->{vp} or return)->child; |
1111 | |
1103 | |
… | |
… | |
1131 | sub update { |
1123 | sub update { |
1132 | my ($self) = @_; |
1124 | my ($self) = @_; |
1133 | |
1125 | |
1134 | $self->SUPER::update; |
1126 | $self->SUPER::update; |
1135 | $self->update_slider; |
1127 | $self->update_slider; |
|
|
1128 | } |
|
|
1129 | |
|
|
1130 | sub invoke_mouse_wheel { |
|
|
1131 | my ($self, $ev) = @_; |
|
|
1132 | |
|
|
1133 | return 0 unless $ev->{dy}; # only vertical movements for now |
|
|
1134 | |
|
|
1135 | $self->{vslider}->emit (mouse_wheel => $ev); |
|
|
1136 | |
|
|
1137 | 1 |
|
|
1138 | } |
|
|
1139 | |
|
|
1140 | sub invoke_button_down { |
|
|
1141 | my ($self, $ev, $x, $y) = @_; |
|
|
1142 | |
|
|
1143 | if ($ev->{button} == 2) { |
|
|
1144 | $self->grab_focus; |
|
|
1145 | |
|
|
1146 | $self->{motion} = sub { |
|
|
1147 | my ($ev, $x, $y) = @_; |
|
|
1148 | |
|
|
1149 | $self->{vp}->set_offset ( |
|
|
1150 | $self->{vp}{view_x} - $ev->{xrel}, |
|
|
1151 | $self->{vp}{view_y} - $ev->{yrel}, |
|
|
1152 | ); |
|
|
1153 | }; |
|
|
1154 | |
|
|
1155 | return 1; |
|
|
1156 | } |
|
|
1157 | |
|
|
1158 | 0 |
|
|
1159 | } |
|
|
1160 | |
|
|
1161 | sub invoke_button_up { |
|
|
1162 | my ($self, $ev, $x, $y) = @_; |
|
|
1163 | |
|
|
1164 | if (delete $self->{motion}) { |
|
|
1165 | return 1; |
|
|
1166 | } |
|
|
1167 | |
|
|
1168 | 0 |
|
|
1169 | } |
|
|
1170 | |
|
|
1171 | sub invoke_mouse_motion { |
|
|
1172 | my ($self, $ev, $x, $y) = @_; |
|
|
1173 | |
|
|
1174 | if ($self->{motion}) { |
|
|
1175 | $self->{motion}->($ev, $x, $y); |
|
|
1176 | return 1; |
|
|
1177 | } |
|
|
1178 | |
|
|
1179 | 0 |
1136 | } |
1180 | } |
1137 | |
1181 | |
1138 | sub invoke_size_allocate { |
1182 | sub invoke_size_allocate { |
1139 | my ($self, $w, $h) = @_; |
1183 | my ($self, $w, $h) = @_; |
1140 | |
1184 | |