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.376 by root, Mon Jul 16 20:20:23 2007 UTC vs.
Revision 1.382 by root, Thu Jul 19 19:58:56 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 $self->emit (changed => $self->{view_x}, $self->{view_y}); 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);
995 $self->update; 999 $self->update;
1000 }
996} 1001}
997 1002
998# 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
999sub coord2local { 1004sub coord2local {
1000 my ($self, $x, $y) = @_; 1005 my ($self, $x, $y) = @_;
1080 expand => 1, 1085 expand => 1,
1081 scroll_x => $self->{scroll_x}, 1086 scroll_x => $self->{scroll_x},
1082 scroll_y => $self->{scroll_y}, 1087 scroll_y => $self->{scroll_y},
1083 on_changed => sub { 1088 on_changed => sub {
1084 my ($vp, $x, $y) = @_; 1089 my ($vp, $x, $y) = @_;
1090
1085 $vp->{parent}{hslider}->set_value ($x); 1091 $vp->{parent}{hslider}->set_value ($x);
1086 $vp->{parent}{vslider}->set_value ($y); 1092 $vp->{parent}{vslider}->set_value ($y);
1087 1093
1088 0 1094 0
1089 }, 1095 },
1349 1355
1350my @border = 1356my @border =
1351 map { new_from_file CFPlus::Texture CFPlus::find_rcfile $_, mipmap => 1 } 1357 map { new_from_file CFPlus::Texture CFPlus::find_rcfile $_, mipmap => 1 }
1352 qw(d1_border_top.png d1_border_right.png d1_border_left.png d1_border_bottom.png); 1358 qw(d1_border_top.png d1_border_right.png d1_border_left.png d1_border_bottom.png);
1353 1359
1360my @icon =
1361 map { new_from_file CFPlus::Texture CFPlus::find_rcfile $_, mipmap => 1 }
1362 qw(x1_move.png x1_resize.png);
1363
1354sub new { 1364sub new {
1355 my ($class, %arg) = @_; 1365 my ($class, %arg) = @_;
1356 1366
1357 my $self = $class->SUPER::new ( 1367 my $self = $class->SUPER::new (
1358 bg => [1, 1, 1, 1], 1368 bg => [1, 1, 1, 1],
1526 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE; 1536 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE;
1527 1537
1528 my $border = $self->border; 1538 my $border = $self->border;
1529 1539
1530 glColor @{ $self->{border_bg} }; 1540 glColor @{ $self->{border_bg} };
1531 $border[0]->draw_quad_alpha (0, 0, $w, $border); 1541 $border[0]->draw_quad_alpha ( 0, 0, $w, $border);
1532 $border[1]->draw_quad_alpha (0, $border, $border, $ch); 1542 $border[1]->draw_quad_alpha ( 0, $border, $border, $ch);
1533 $border[2]->draw_quad_alpha ($w - $border, $border, $border, $ch); 1543 $border[2]->draw_quad_alpha ($w - $border, $border, $border, $ch);
1534 $border[3]->draw_quad_alpha (0, $h - $border, $w, $border); 1544 $border[3]->draw_quad_alpha ( 0, $h - $border, $w, $border);
1545
1546 # move
1547 my $w2 = ($w - $border) * .5;
1548 my $h2 = ($h - $border) * .5;
1549 $icon[0]->draw_quad_alpha ( 0, $h2, $border, $border);
1550 $icon[0]->draw_quad_alpha ($w - $border, $h2, $border, $border);
1551 $icon[0]->draw_quad_alpha ($w2 , $h - $border, $border, $border);
1552
1553 # resize
1554 $icon[1]->draw_quad_alpha ( 0, 0, $border, $border);
1555 $icon[1]->draw_quad_alpha ($w - $border, 0, $border, $border)
1556 unless $self->{has_close_button};
1557 $icon[1]->draw_quad_alpha ( 0, $h - $border, $border, $border);
1558 $icon[1]->draw_quad_alpha ($w - $border, $h - $border, $border, $border);
1535 1559
1536 if (@{$self->{bg}} < 4 || $self->{bg}[3]) { 1560 if (@{$self->{bg}} < 4 || $self->{bg}[3]) {
1537 glColor @{ $self->{bg} }; 1561 glColor @{ $self->{bg} };
1538 1562
1539 # TODO: repeat texture not scale 1563 # TODO: repeat texture not scale
2375 2399
2376use CFPlus::OpenGL; 2400use CFPlus::OpenGL;
2377 2401
2378my @tex = 2402my @tex =
2379 map { new_from_file CFPlus::Texture CFPlus::find_rcfile $_, mipmap => 1 } 2403 map { new_from_file CFPlus::Texture CFPlus::find_rcfile $_, mipmap => 1 }
2380 qw(b1_button_active.png); 2404 qw(b1_button_inactive.png b1_button_active.png);
2381 2405
2382sub new { 2406sub new {
2383 my $class = shift; 2407 my $class = shift;
2384 2408
2385 $class->SUPER::new ( 2409 $class->SUPER::new (
2386 padding_x => 4, 2410 padding_x => 4,
2387 padding_y => 4, 2411 padding_y => 4,
2388 fg => [1, 1, 1], 2412 fg => [1.0, 1.0, 1.0],
2389 active_fg => [0, 0, 1], 2413 active_fg => [0.8, 0.8, 0.8],
2390 can_hover => 1, 2414 can_hover => 1,
2391 align => 0, 2415 align => 0,
2392 valign => 0, 2416 valign => 0,
2393 can_events => 1, 2417 can_events => 1,
2394 @_ 2418 @_
2412 2436
2413 glEnable GL_TEXTURE_2D; 2437 glEnable GL_TEXTURE_2D;
2414 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; 2438 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE;
2415 glColor 0, 0, 0, 1; 2439 glColor 0, 0, 0, 1;
2416 2440
2441 my $tex = $tex[$GRAB == $self];
2417 $tex[0]->draw_quad_alpha (0, 0, $self->{w}, $self->{h}); 2442 $tex->draw_quad_alpha (0, 0, $self->{w}, $self->{h});
2418 2443
2419 glDisable GL_TEXTURE_2D; 2444 glDisable GL_TEXTURE_2D;
2420 2445
2421 $self->SUPER::_draw; 2446 $self->SUPER::_draw;
2422} 2447}
3487 ); 3512 );
3488 3513
3489 if ($self->{anim} && $self->{animspeed}) { 3514 if ($self->{anim} && $self->{animspeed}) {
3490 CFPlus::weaken (my $widget = $self); 3515 CFPlus::weaken (my $widget = $self);
3491 3516
3517 $widget->{animspeed} = List::Util::max 0.05, $widget->{animspeed};
3518 $widget->{anim_start} = $self->{animspeed} * Event::time / $self->{animspeed};
3492 $self->{timer} = Event->timer ( 3519 $self->{timer} = Event->timer (
3493 at => $self->{animspeed} * int $::NOW / $self->{animspeed},
3494 hard => 1, 3520 parked => 1,
3495 interval => $self->{animspeed},
3496 cb => sub { 3521 cb => sub {
3497 return unless $::CONN; 3522 return unless $::CONN && $widget;
3498 3523
3499 ++$widget->{frame}; 3524 ++$widget->{frame};
3500 $self->update_face; 3525 $widget->update_face;
3501 $self->update; 3526 $widget->update;
3527
3528 $widget->update_timer;
3502 }, 3529 },
3503 ); 3530 );
3504 3531
3505 $self->update_face; 3532 $self->update_face;
3533 $self->update_timer;
3506 } 3534 }
3507 3535
3508 $self 3536 $self
3537}
3538
3539sub update_timer {
3540 my ($self) = @_;
3541
3542 return unless $self->{timer};
3543
3544 if ($self->{visible}) {
3545 $self->{timer}->at (
3546 $self->{anim_start}
3547 + $self->{animspeed}
3548 * int 1.5 + (Event::time - $self->{anim_start}) / $self->{animspeed}
3549 );
3550 $self->{timer}->start;
3551 } else {
3552 $self->{timer}->stop;
3553 }
3509} 3554}
3510 3555
3511sub update_face { 3556sub update_face {
3512 my ($self) = @_; 3557 my ($self) = @_;
3513 3558
3545 return unless $self->{visible}; 3590 return unless $self->{visible};
3546 3591
3547 $self->SUPER::update; 3592 $self->SUPER::update;
3548} 3593}
3549 3594
3595sub invoke_visibility_change {
3596 my ($self) = @_;
3597
3598 $self->update_timer;
3599
3600 0
3601}
3602
3550sub _draw { 3603sub _draw {
3551 my ($self) = @_; 3604 my ($self) = @_;
3552 3605
3553 return unless $::CONN; 3606 return unless $::CONN;
3554 3607
3569} 3622}
3570 3623
3571sub destroy { 3624sub destroy {
3572 my ($self) = @_; 3625 my ($self) = @_;
3573 3626
3574 $self->{timer}->cancel 3627 (delete $self->{timer})->cancel
3575 if $self->{timer}; 3628 if $self->{timer};
3576 3629
3577 $self->SUPER::destroy; 3630 $self->SUPER::destroy;
3578} 3631}
3579 3632
4223 while ($self->{post_alloc_hook}) { 4276 while ($self->{post_alloc_hook}) {
4224 $_->() 4277 $_->()
4225 for values %{delete $self->{post_alloc_hook}}; 4278 for values %{delete $self->{post_alloc_hook}};
4226 } 4279 }
4227 4280
4228
4229 glViewport 0, 0, $::WIDTH, $::HEIGHT; 4281 glViewport 0, 0, $::WIDTH, $::HEIGHT;
4230 glClearColor +($::CFG->{fow_intensity}) x 3, 1; 4282 glClearColor +($::CFG->{fow_intensity}) x 3, 1;
4231 glClear GL_COLOR_BUFFER_BIT; 4283 glClear GL_COLOR_BUFFER_BIT;
4232 4284
4233 glMatrixMode GL_PROJECTION; 4285 glMatrixMode GL_PROJECTION;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines