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.380 by root, Tue Jul 17 17:39:07 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
991 my $x = max 0, min $self->child->{w} - $self->{w}, int $x;
992 my $y = max 0, min $self->child->{h} - $self->{h}, int $y;
993
994 if ($x != $self->{view_x} or $y != $self->{view_y}) {
989 $self->{view_x} = int $x; 995 $self->{view_x} = $x;
990 $self->{view_y} = int $y; 996 $self->{view_y} = $y;
991 997
998 $self->emit (changed => $x, $y);
992 $self->update; 999 $self->update;
1000 }
993} 1001}
994 1002
995# hmm, this does not work for topleft of $self... but we should not ask for that 1003# hmm, this does not work for topleft of $self... but we should not ask for that
996sub coord2local { 1004sub coord2local {
997 my ($self, $x, $y) = @_; 1005 my ($self, $x, $y) = @_;
1072 row_expand => [1, 0], 1080 row_expand => [1, 0],
1073 %arg, 1081 %arg,
1074 ); 1082 );
1075 1083
1076 $self->{vp} = new CFPlus::UI::ViewPort 1084 $self->{vp} = new CFPlus::UI::ViewPort
1077 expand => 1, 1085 expand => 1,
1078 scroll_x => $self->{scroll_x}, 1086 scroll_x => $self->{scroll_x},
1079 scroll_y => $self->{scroll_y}, 1087 scroll_y => $self->{scroll_y},
1088 on_changed => sub {
1089 my ($vp, $x, $y) = @_;
1090
1091 $vp->{parent}{hslider}->set_value ($x);
1092 $vp->{parent}{vslider}->set_value ($y);
1093
1094 0
1095 },
1080 ; 1096 ;
1081 1097
1082 $self->SUPER::add (0, 0, $self->{vp}); 1098 $self->SUPER::add (0, 0, $self->{vp});
1083 1099
1084 $self->add ($child) if $child; 1100 $self->add ($child) if $child;
1090 1106
1091sub add { 1107sub add {
1092 my ($self, $widget) = @_; 1108 my ($self, $widget) = @_;
1093 1109
1094 $self->{vp}->add ($self->{child} = $widget); 1110 $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} 1111}
1106 1112
1107sub update_slider { 1113sub update_slider {
1108 my ($self) = @_; 1114 my ($self) = @_;
1109 1115
1131sub update { 1137sub update {
1132 my ($self) = @_; 1138 my ($self) = @_;
1133 1139
1134 $self->SUPER::update; 1140 $self->SUPER::update;
1135 $self->update_slider; 1141 $self->update_slider;
1142}
1143
1144sub invoke_mouse_wheel {
1145 my ($self, $ev) = @_;
1146
1147 return 0 unless $ev->{dy}; # only vertical movements for now
1148
1149 $self->{vslider}->emit (mouse_wheel => $ev);
1150
1151 1
1152}
1153
1154sub invoke_button_down {
1155 my ($self, $ev, $x, $y) = @_;
1156
1157 if ($ev->{button} == 2) {
1158 $self->grab_focus;
1159
1160 my $ox = $self->{vp}{view_x} + $ev->{x};
1161 my $oy = $self->{vp}{view_y} + $ev->{y};
1162
1163 $self->{motion} = sub {
1164 my ($ev, $x, $y) = @_;
1165
1166 $self->{vp}->set_offset ($ox - $ev->{x}, $oy - $ev->{y});
1167 $self->update;
1168 };
1169
1170 return 1;
1171 }
1172
1173 0
1174}
1175
1176sub invoke_button_up {
1177 my ($self, $ev, $x, $y) = @_;
1178
1179 if (delete $self->{motion}) {
1180 return 1;
1181 }
1182
1183 0
1184}
1185
1186sub invoke_mouse_motion {
1187 my ($self, $ev, $x, $y) = @_;
1188
1189 if ($self->{motion}) {
1190 $self->{motion}->($ev, $x, $y);
1191 return 1;
1192 }
1193
1194 0
1136} 1195}
1137 1196
1138sub invoke_size_allocate { 1197sub invoke_size_allocate {
1139 my ($self, $w, $h) = @_; 1198 my ($self, $w, $h) = @_;
1140 1199
3434 ); 3493 );
3435 3494
3436 if ($self->{anim} && $self->{animspeed}) { 3495 if ($self->{anim} && $self->{animspeed}) {
3437 CFPlus::weaken (my $widget = $self); 3496 CFPlus::weaken (my $widget = $self);
3438 3497
3498 $widget->{animspeed} = List::Util::max 0.05, $widget->{animspeed};
3499 $widget->{anim_start} = $self->{animspeed} * Event::time / $self->{animspeed};
3439 $self->{timer} = Event->timer ( 3500 $self->{timer} = Event->timer (
3440 at => $self->{animspeed} * int $::NOW / $self->{animspeed},
3441 hard => 1, 3501 parked => 1,
3442 interval => $self->{animspeed},
3443 cb => sub { 3502 cb => sub {
3444 return unless $::CONN; 3503 return unless $::CONN && $widget;
3445 3504
3446 ++$widget->{frame}; 3505 ++$widget->{frame};
3447 $self->update_face; 3506 $widget->update_face;
3448 $self->update; 3507 $widget->update;
3508
3509 $widget->update_timer;
3449 }, 3510 },
3450 ); 3511 );
3451 3512
3452 $self->update_face; 3513 $self->update_face;
3514 $self->update_timer;
3453 } 3515 }
3454 3516
3455 $self 3517 $self
3518}
3519
3520sub update_timer {
3521 my ($self) = @_;
3522
3523 return unless $self->{timer};
3524
3525 if ($self->{visible}) {
3526 $self->{timer}->at (
3527 $self->{anim_start}
3528 + $self->{animspeed}
3529 * int 1.5 + (Event::time - $self->{anim_start}) / $self->{animspeed}
3530 );
3531 $self->{timer}->start;
3532 } else {
3533 $self->{timer}->stop;
3534 }
3456} 3535}
3457 3536
3458sub update_face { 3537sub update_face {
3459 my ($self) = @_; 3538 my ($self) = @_;
3460 3539
3492 return unless $self->{visible}; 3571 return unless $self->{visible};
3493 3572
3494 $self->SUPER::update; 3573 $self->SUPER::update;
3495} 3574}
3496 3575
3576sub invoke_visibility_change {
3577 my ($self) = @_;
3578
3579 $self->update_timer;
3580
3581 0
3582}
3583
3497sub _draw { 3584sub _draw {
3498 my ($self) = @_; 3585 my ($self) = @_;
3499 3586
3500 return unless $::CONN; 3587 return unless $::CONN;
3501 3588
3516} 3603}
3517 3604
3518sub destroy { 3605sub destroy {
3519 my ($self) = @_; 3606 my ($self) = @_;
3520 3607
3521 $self->{timer}->cancel 3608 (delete $self->{timer})->cancel
3522 if $self->{timer}; 3609 if $self->{timer};
3523 3610
3524 $self->SUPER::destroy; 3611 $self->SUPER::destroy;
3525} 3612}
3526 3613

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines