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.375 by root, Mon Jul 16 20:12:19 2007 UTC vs.
Revision 1.381 by root, Thu Jul 19 13:45:18 2007 UTC

986} 986}
987 987
988sub set_offset { 988sub set_offset {
989 my ($self, $x, $y) = @_; 989 my ($self, $x, $y) = @_;
990 990
991 $self->{view_x} = max 0, min $self->child->{w} - $self->{w}, int $x; 991 my $x = max 0, min $self->child->{w} - $self->{w}, int $x;
992 $self->{view_y} = max 0, min $self->child->{h} - $self->{h}, int $y; 992 my $y = max 0, min $self->child->{h} - $self->{h}, int $y;
993 993
994 if ($x != $self->{view_x} or $y != $self->{view_y}) {
995 $self->{view_x} = $x;
996 $self->{view_y} = $y;
997
998 $self->emit (changed => $x, $y);
994 $self->update; 999 $self->update;
1000 }
995} 1001}
996 1002
997# 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
998sub coord2local { 1004sub coord2local {
999 my ($self, $x, $y) = @_; 1005 my ($self, $x, $y) = @_;
1074 row_expand => [1, 0], 1080 row_expand => [1, 0],
1075 %arg, 1081 %arg,
1076 ); 1082 );
1077 1083
1078 $self->{vp} = new CFPlus::UI::ViewPort 1084 $self->{vp} = new CFPlus::UI::ViewPort
1079 expand => 1, 1085 expand => 1,
1080 scroll_x => $self->{scroll_x}, 1086 scroll_x => $self->{scroll_x},
1081 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 },
1082 ; 1096 ;
1083 1097
1084 $self->SUPER::add (0, 0, $self->{vp}); 1098 $self->SUPER::add (0, 0, $self->{vp});
1085 1099
1086 $self->add ($child) if $child; 1100 $self->add ($child) if $child;
1140sub invoke_button_down { 1154sub invoke_button_down {
1141 my ($self, $ev, $x, $y) = @_; 1155 my ($self, $ev, $x, $y) = @_;
1142 1156
1143 if ($ev->{button} == 2) { 1157 if ($ev->{button} == 2) {
1144 $self->grab_focus; 1158 $self->grab_focus;
1159
1160 my $ox = $self->{vp}{view_x} + $ev->{x};
1161 my $oy = $self->{vp}{view_y} + $ev->{y};
1145 1162
1146 $self->{motion} = sub { 1163 $self->{motion} = sub {
1147 my ($ev, $x, $y) = @_; 1164 my ($ev, $x, $y) = @_;
1148 1165
1149 $self->{vp}->set_offset ( 1166 $self->{vp}->set_offset ($ox - $ev->{x}, $oy - $ev->{y});
1150 $self->{vp}{view_x} - $ev->{xrel}, 1167 $self->update;
1151 $self->{vp}{view_y} - $ev->{yrel},
1152 );
1153 }; 1168 };
1154 1169
1155 return 1; 1170 return 1;
1156 } 1171 }
1157 1172
2366 2381
2367use CFPlus::OpenGL; 2382use CFPlus::OpenGL;
2368 2383
2369my @tex = 2384my @tex =
2370 map { new_from_file CFPlus::Texture CFPlus::find_rcfile $_, mipmap => 1 } 2385 map { new_from_file CFPlus::Texture CFPlus::find_rcfile $_, mipmap => 1 }
2371 qw(b1_button_active.png); 2386 qw(b1_button_inactive.png b1_button_active.png);
2372 2387
2373sub new { 2388sub new {
2374 my $class = shift; 2389 my $class = shift;
2375 2390
2376 $class->SUPER::new ( 2391 $class->SUPER::new (
2377 padding_x => 4, 2392 padding_x => 4,
2378 padding_y => 4, 2393 padding_y => 4,
2379 fg => [1, 1, 1], 2394 fg => [1.0, 1.0, 1.0],
2380 active_fg => [0, 0, 1], 2395 active_fg => [0.8, 0.8, 0.8],
2381 can_hover => 1, 2396 can_hover => 1,
2382 align => 0, 2397 align => 0,
2383 valign => 0, 2398 valign => 0,
2384 can_events => 1, 2399 can_events => 1,
2385 @_ 2400 @_
2403 2418
2404 glEnable GL_TEXTURE_2D; 2419 glEnable GL_TEXTURE_2D;
2405 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; 2420 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE;
2406 glColor 0, 0, 0, 1; 2421 glColor 0, 0, 0, 1;
2407 2422
2423 my $tex = $tex[$GRAB == $self];
2408 $tex[0]->draw_quad_alpha (0, 0, $self->{w}, $self->{h}); 2424 $tex->draw_quad_alpha (0, 0, $self->{w}, $self->{h});
2409 2425
2410 glDisable GL_TEXTURE_2D; 2426 glDisable GL_TEXTURE_2D;
2411 2427
2412 $self->SUPER::_draw; 2428 $self->SUPER::_draw;
2413} 2429}
3478 ); 3494 );
3479 3495
3480 if ($self->{anim} && $self->{animspeed}) { 3496 if ($self->{anim} && $self->{animspeed}) {
3481 CFPlus::weaken (my $widget = $self); 3497 CFPlus::weaken (my $widget = $self);
3482 3498
3499 $widget->{animspeed} = List::Util::max 0.05, $widget->{animspeed};
3500 $widget->{anim_start} = $self->{animspeed} * Event::time / $self->{animspeed};
3483 $self->{timer} = Event->timer ( 3501 $self->{timer} = Event->timer (
3484 at => $self->{animspeed} * int $::NOW / $self->{animspeed},
3485 hard => 1, 3502 parked => 1,
3486 interval => $self->{animspeed},
3487 cb => sub { 3503 cb => sub {
3488 return unless $::CONN; 3504 return unless $::CONN && $widget;
3489 3505
3490 ++$widget->{frame}; 3506 ++$widget->{frame};
3491 $self->update_face; 3507 $widget->update_face;
3492 $self->update; 3508 $widget->update;
3509
3510 $widget->update_timer;
3493 }, 3511 },
3494 ); 3512 );
3495 3513
3496 $self->update_face; 3514 $self->update_face;
3515 $self->update_timer;
3497 } 3516 }
3498 3517
3499 $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 }
3500} 3536}
3501 3537
3502sub update_face { 3538sub update_face {
3503 my ($self) = @_; 3539 my ($self) = @_;
3504 3540
3536 return unless $self->{visible}; 3572 return unless $self->{visible};
3537 3573
3538 $self->SUPER::update; 3574 $self->SUPER::update;
3539} 3575}
3540 3576
3577sub invoke_visibility_change {
3578 my ($self) = @_;
3579
3580 $self->update_timer;
3581
3582 0
3583}
3584
3541sub _draw { 3585sub _draw {
3542 my ($self) = @_; 3586 my ($self) = @_;
3543 3587
3544 return unless $::CONN; 3588 return unless $::CONN;
3545 3589
3560} 3604}
3561 3605
3562sub destroy { 3606sub destroy {
3563 my ($self) = @_; 3607 my ($self) = @_;
3564 3608
3565 $self->{timer}->cancel 3609 (delete $self->{timer})->cancel
3566 if $self->{timer}; 3610 if $self->{timer};
3567 3611
3568 $self->SUPER::destroy; 3612 $self->SUPER::destroy;
3569} 3613}
3570 3614
4214 while ($self->{post_alloc_hook}) { 4258 while ($self->{post_alloc_hook}) {
4215 $_->() 4259 $_->()
4216 for values %{delete $self->{post_alloc_hook}}; 4260 for values %{delete $self->{post_alloc_hook}};
4217 } 4261 }
4218 4262
4219
4220 glViewport 0, 0, $::WIDTH, $::HEIGHT; 4263 glViewport 0, 0, $::WIDTH, $::HEIGHT;
4221 glClearColor +($::CFG->{fow_intensity}) x 3, 1; 4264 glClearColor +($::CFG->{fow_intensity}) x 3, 1;
4222 glClear GL_COLOR_BUFFER_BIT; 4265 glClear GL_COLOR_BUFFER_BIT;
4223 4266
4224 glMatrixMode GL_PROJECTION; 4267 glMatrixMode GL_PROJECTION;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines