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.381 by root, Thu Jul 19 13:45:18 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
2322 2381
2323use CFPlus::OpenGL; 2382use CFPlus::OpenGL;
2324 2383
2325my @tex = 2384my @tex =
2326 map { new_from_file CFPlus::Texture CFPlus::find_rcfile $_, mipmap => 1 } 2385 map { new_from_file CFPlus::Texture CFPlus::find_rcfile $_, mipmap => 1 }
2327 qw(b1_button_active.png); 2386 qw(b1_button_inactive.png b1_button_active.png);
2328 2387
2329sub new { 2388sub new {
2330 my $class = shift; 2389 my $class = shift;
2331 2390
2332 $class->SUPER::new ( 2391 $class->SUPER::new (
2333 padding_x => 4, 2392 padding_x => 4,
2334 padding_y => 4, 2393 padding_y => 4,
2335 fg => [1, 1, 1], 2394 fg => [1.0, 1.0, 1.0],
2336 active_fg => [0, 0, 1], 2395 active_fg => [0.8, 0.8, 0.8],
2337 can_hover => 1, 2396 can_hover => 1,
2338 align => 0, 2397 align => 0,
2339 valign => 0, 2398 valign => 0,
2340 can_events => 1, 2399 can_events => 1,
2341 @_ 2400 @_
2359 2418
2360 glEnable GL_TEXTURE_2D; 2419 glEnable GL_TEXTURE_2D;
2361 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; 2420 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE;
2362 glColor 0, 0, 0, 1; 2421 glColor 0, 0, 0, 1;
2363 2422
2423 my $tex = $tex[$GRAB == $self];
2364 $tex[0]->draw_quad_alpha (0, 0, $self->{w}, $self->{h}); 2424 $tex->draw_quad_alpha (0, 0, $self->{w}, $self->{h});
2365 2425
2366 glDisable GL_TEXTURE_2D; 2426 glDisable GL_TEXTURE_2D;
2367 2427
2368 $self->SUPER::_draw; 2428 $self->SUPER::_draw;
2369} 2429}
3434 ); 3494 );
3435 3495
3436 if ($self->{anim} && $self->{animspeed}) { 3496 if ($self->{anim} && $self->{animspeed}) {
3437 CFPlus::weaken (my $widget = $self); 3497 CFPlus::weaken (my $widget = $self);
3438 3498
3499 $widget->{animspeed} = List::Util::max 0.05, $widget->{animspeed};
3500 $widget->{anim_start} = $self->{animspeed} * Event::time / $self->{animspeed};
3439 $self->{timer} = Event->timer ( 3501 $self->{timer} = Event->timer (
3440 at => $self->{animspeed} * int $::NOW / $self->{animspeed},
3441 hard => 1, 3502 parked => 1,
3442 interval => $self->{animspeed},
3443 cb => sub { 3503 cb => sub {
3444 return unless $::CONN; 3504 return unless $::CONN && $widget;
3445 3505
3446 ++$widget->{frame}; 3506 ++$widget->{frame};
3447 $self->update_face; 3507 $widget->update_face;
3448 $self->update; 3508 $widget->update;
3509
3510 $widget->update_timer;
3449 }, 3511 },
3450 ); 3512 );
3451 3513
3452 $self->update_face; 3514 $self->update_face;
3515 $self->update_timer;
3453 } 3516 }
3454 3517
3455 $self 3518 $self
3519}
3520
3521sub update_timer {
3522 my ($self) = @_;
3523
3524 return unless $self->{timer};
3525
3526 if ($self->{visible}) {
3527 $self->{timer}->at (
3528 $self->{anim_start}
3529 + $self->{animspeed}
3530 * int 1.5 + (Event::time - $self->{anim_start}) / $self->{animspeed}
3531 );
3532 $self->{timer}->start;
3533 } else {
3534 $self->{timer}->stop;
3535 }
3456} 3536}
3457 3537
3458sub update_face { 3538sub update_face {
3459 my ($self) = @_; 3539 my ($self) = @_;
3460 3540
3492 return unless $self->{visible}; 3572 return unless $self->{visible};
3493 3573
3494 $self->SUPER::update; 3574 $self->SUPER::update;
3495} 3575}
3496 3576
3577sub invoke_visibility_change {
3578 my ($self) = @_;
3579
3580 $self->update_timer;
3581
3582 0
3583}
3584
3497sub _draw { 3585sub _draw {
3498 my ($self) = @_; 3586 my ($self) = @_;
3499 3587
3500 return unless $::CONN; 3588 return unless $::CONN;
3501 3589
3516} 3604}
3517 3605
3518sub destroy { 3606sub destroy {
3519 my ($self) = @_; 3607 my ($self) = @_;
3520 3608
3521 $self->{timer}->cancel 3609 (delete $self->{timer})->cancel
3522 if $self->{timer}; 3610 if $self->{timer};
3523 3611
3524 $self->SUPER::destroy; 3612 $self->SUPER::destroy;
3525} 3613}
3526 3614
4170 while ($self->{post_alloc_hook}) { 4258 while ($self->{post_alloc_hook}) {
4171 $_->() 4259 $_->()
4172 for values %{delete $self->{post_alloc_hook}}; 4260 for values %{delete $self->{post_alloc_hook}};
4173 } 4261 }
4174 4262
4175
4176 glViewport 0, 0, $::WIDTH, $::HEIGHT; 4263 glViewport 0, 0, $::WIDTH, $::HEIGHT;
4177 glClearColor +($::CFG->{fow_intensity}) x 3, 1; 4264 glClearColor +($::CFG->{fow_intensity}) x 3, 1;
4178 glClear GL_COLOR_BUFFER_BIT; 4265 glClear GL_COLOR_BUFFER_BIT;
4179 4266
4180 glMatrixMode GL_PROJECTION; 4267 glMatrixMode GL_PROJECTION;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines