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.376 by root, Mon Jul 16 20:20:23 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
994 $self->emit (changed => $self->{view_x}, $self->{view_y});
992 $self->update; 995 $self->update;
993} 996}
994 997
995# hmm, this does not work for topleft of $self... but we should not ask for that 998# hmm, this does not work for topleft of $self... but we should not ask for that
996sub coord2local { 999sub coord2local {
1072 row_expand => [1, 0], 1075 row_expand => [1, 0],
1073 %arg, 1076 %arg,
1074 ); 1077 );
1075 1078
1076 $self->{vp} = new CFPlus::UI::ViewPort 1079 $self->{vp} = new CFPlus::UI::ViewPort
1077 expand => 1, 1080 expand => 1,
1078 scroll_x => $self->{scroll_x}, 1081 scroll_x => $self->{scroll_x},
1079 scroll_y => $self->{scroll_y}, 1082 scroll_y => $self->{scroll_y},
1083 on_changed => sub {
1084 my ($vp, $x, $y) = @_;
1085 $vp->{parent}{hslider}->set_value ($x);
1086 $vp->{parent}{vslider}->set_value ($y);
1087
1088 0
1089 },
1080 ; 1090 ;
1081 1091
1082 $self->SUPER::add (0, 0, $self->{vp}); 1092 $self->SUPER::add (0, 0, $self->{vp});
1083 1093
1084 $self->add ($child) if $child; 1094 $self->add ($child) if $child;
1090 1100
1091sub add { 1101sub add {
1092 my ($self, $widget) = @_; 1102 my ($self, $widget) = @_;
1093 1103
1094 $self->{vp}->add ($self->{child} = $widget); 1104 $self->{vp}->add ($self->{child} = $widget);
1095}
1096
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} 1105}
1106 1106
1107sub update_slider { 1107sub update_slider {
1108 my ($self) = @_; 1108 my ($self) = @_;
1109 1109
1131sub update { 1131sub update {
1132 my ($self) = @_; 1132 my ($self) = @_;
1133 1133
1134 $self->SUPER::update; 1134 $self->SUPER::update;
1135 $self->update_slider; 1135 $self->update_slider;
1136}
1137
1138sub invoke_mouse_wheel {
1139 my ($self, $ev) = @_;
1140
1141 return 0 unless $ev->{dy}; # only vertical movements for now
1142
1143 $self->{vslider}->emit (mouse_wheel => $ev);
1144
1145 1
1146}
1147
1148sub invoke_button_down {
1149 my ($self, $ev, $x, $y) = @_;
1150
1151 if ($ev->{button} == 2) {
1152 $self->grab_focus;
1153
1154 my $ox = $self->{vp}{view_x} + $ev->{x};
1155 my $oy = $self->{vp}{view_y} + $ev->{y};
1156
1157 $self->{motion} = sub {
1158 my ($ev, $x, $y) = @_;
1159
1160 $self->{vp}->set_offset ($ox - $ev->{x}, $oy - $ev->{y});
1161 $self->update;
1162 };
1163
1164 return 1;
1165 }
1166
1167 0
1168}
1169
1170sub invoke_button_up {
1171 my ($self, $ev, $x, $y) = @_;
1172
1173 if (delete $self->{motion}) {
1174 return 1;
1175 }
1176
1177 0
1178}
1179
1180sub invoke_mouse_motion {
1181 my ($self, $ev, $x, $y) = @_;
1182
1183 if ($self->{motion}) {
1184 $self->{motion}->($ev, $x, $y);
1185 return 1;
1186 }
1187
1188 0
1136} 1189}
1137 1190
1138sub invoke_size_allocate { 1191sub invoke_size_allocate {
1139 my ($self, $w, $h) = @_; 1192 my ($self, $w, $h) = @_;
1140 1193

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines