ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/Deliantra-Client/DC/UI.pm
(Generate patch)

Comparing deliantra/Deliantra-Client/DC/UI.pm (file contents):
Revision 1.374 by root, Mon Jul 16 12:36:48 2007 UTC vs.
Revision 1.375 by root, Mon Jul 16 20:12:19 2007 UTC

944 944
945############################################################################# 945#############################################################################
946 946
947package CFPlus::UI::ViewPort; 947package CFPlus::UI::ViewPort;
948 948
949use List::Util qw(min max);
950
949our @ISA = CFPlus::UI::Window::; 951our @ISA = CFPlus::UI::Window::;
950 952
951sub new { 953sub new {
952 my $class = shift; 954 my $class = shift;
953 955
984} 986}
985 987
986sub set_offset { 988sub 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
1097sub 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
1107sub update_slider { 1099sub 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
1131sub update { 1123sub 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
1130sub 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
1140sub 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
1161sub invoke_button_up {
1162 my ($self, $ev, $x, $y) = @_;
1163
1164 if (delete $self->{motion}) {
1165 return 1;
1166 }
1167
1168 0
1169}
1170
1171sub 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
1138sub invoke_size_allocate { 1182sub invoke_size_allocate {
1139 my ($self, $w, $h) = @_; 1183 my ($self, $w, $h) = @_;
1140 1184

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines