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.382 by root, Thu Jul 19 19:58:56 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
1296 1355
1297my @border = 1356my @border =
1298 map { new_from_file CFPlus::Texture CFPlus::find_rcfile $_, mipmap => 1 } 1357 map { new_from_file CFPlus::Texture CFPlus::find_rcfile $_, mipmap => 1 }
1299 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);
1300 1359
1360my @icon =
1361 map { new_from_file CFPlus::Texture CFPlus::find_rcfile $_, mipmap => 1 }
1362 qw(x1_move.png x1_resize.png);
1363
1301sub new { 1364sub new {
1302 my ($class, %arg) = @_; 1365 my ($class, %arg) = @_;
1303 1366
1304 my $self = $class->SUPER::new ( 1367 my $self = $class->SUPER::new (
1305 bg => [1, 1, 1, 1], 1368 bg => [1, 1, 1, 1],
1473 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE; 1536 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE;
1474 1537
1475 my $border = $self->border; 1538 my $border = $self->border;
1476 1539
1477 glColor @{ $self->{border_bg} }; 1540 glColor @{ $self->{border_bg} };
1478 $border[0]->draw_quad_alpha (0, 0, $w, $border); 1541 $border[0]->draw_quad_alpha ( 0, 0, $w, $border);
1479 $border[1]->draw_quad_alpha (0, $border, $border, $ch); 1542 $border[1]->draw_quad_alpha ( 0, $border, $border, $ch);
1480 $border[2]->draw_quad_alpha ($w - $border, $border, $border, $ch); 1543 $border[2]->draw_quad_alpha ($w - $border, $border, $border, $ch);
1481 $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);
1482 1559
1483 if (@{$self->{bg}} < 4 || $self->{bg}[3]) { 1560 if (@{$self->{bg}} < 4 || $self->{bg}[3]) {
1484 glColor @{ $self->{bg} }; 1561 glColor @{ $self->{bg} };
1485 1562
1486 # TODO: repeat texture not scale 1563 # TODO: repeat texture not scale
2322 2399
2323use CFPlus::OpenGL; 2400use CFPlus::OpenGL;
2324 2401
2325my @tex = 2402my @tex =
2326 map { new_from_file CFPlus::Texture CFPlus::find_rcfile $_, mipmap => 1 } 2403 map { new_from_file CFPlus::Texture CFPlus::find_rcfile $_, mipmap => 1 }
2327 qw(b1_button_active.png); 2404 qw(b1_button_inactive.png b1_button_active.png);
2328 2405
2329sub new { 2406sub new {
2330 my $class = shift; 2407 my $class = shift;
2331 2408
2332 $class->SUPER::new ( 2409 $class->SUPER::new (
2333 padding_x => 4, 2410 padding_x => 4,
2334 padding_y => 4, 2411 padding_y => 4,
2335 fg => [1, 1, 1], 2412 fg => [1.0, 1.0, 1.0],
2336 active_fg => [0, 0, 1], 2413 active_fg => [0.8, 0.8, 0.8],
2337 can_hover => 1, 2414 can_hover => 1,
2338 align => 0, 2415 align => 0,
2339 valign => 0, 2416 valign => 0,
2340 can_events => 1, 2417 can_events => 1,
2341 @_ 2418 @_
2359 2436
2360 glEnable GL_TEXTURE_2D; 2437 glEnable GL_TEXTURE_2D;
2361 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; 2438 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE;
2362 glColor 0, 0, 0, 1; 2439 glColor 0, 0, 0, 1;
2363 2440
2441 my $tex = $tex[$GRAB == $self];
2364 $tex[0]->draw_quad_alpha (0, 0, $self->{w}, $self->{h}); 2442 $tex->draw_quad_alpha (0, 0, $self->{w}, $self->{h});
2365 2443
2366 glDisable GL_TEXTURE_2D; 2444 glDisable GL_TEXTURE_2D;
2367 2445
2368 $self->SUPER::_draw; 2446 $self->SUPER::_draw;
2369} 2447}
3434 ); 3512 );
3435 3513
3436 if ($self->{anim} && $self->{animspeed}) { 3514 if ($self->{anim} && $self->{animspeed}) {
3437 CFPlus::weaken (my $widget = $self); 3515 CFPlus::weaken (my $widget = $self);
3438 3516
3517 $widget->{animspeed} = List::Util::max 0.05, $widget->{animspeed};
3518 $widget->{anim_start} = $self->{animspeed} * Event::time / $self->{animspeed};
3439 $self->{timer} = Event->timer ( 3519 $self->{timer} = Event->timer (
3440 at => $self->{animspeed} * int $::NOW / $self->{animspeed},
3441 hard => 1, 3520 parked => 1,
3442 interval => $self->{animspeed},
3443 cb => sub { 3521 cb => sub {
3444 return unless $::CONN; 3522 return unless $::CONN && $widget;
3445 3523
3446 ++$widget->{frame}; 3524 ++$widget->{frame};
3447 $self->update_face; 3525 $widget->update_face;
3448 $self->update; 3526 $widget->update;
3527
3528 $widget->update_timer;
3449 }, 3529 },
3450 ); 3530 );
3451 3531
3452 $self->update_face; 3532 $self->update_face;
3533 $self->update_timer;
3453 } 3534 }
3454 3535
3455 $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 }
3456} 3554}
3457 3555
3458sub update_face { 3556sub update_face {
3459 my ($self) = @_; 3557 my ($self) = @_;
3460 3558
3492 return unless $self->{visible}; 3590 return unless $self->{visible};
3493 3591
3494 $self->SUPER::update; 3592 $self->SUPER::update;
3495} 3593}
3496 3594
3595sub invoke_visibility_change {
3596 my ($self) = @_;
3597
3598 $self->update_timer;
3599
3600 0
3601}
3602
3497sub _draw { 3603sub _draw {
3498 my ($self) = @_; 3604 my ($self) = @_;
3499 3605
3500 return unless $::CONN; 3606 return unless $::CONN;
3501 3607
3516} 3622}
3517 3623
3518sub destroy { 3624sub destroy {
3519 my ($self) = @_; 3625 my ($self) = @_;
3520 3626
3521 $self->{timer}->cancel 3627 (delete $self->{timer})->cancel
3522 if $self->{timer}; 3628 if $self->{timer};
3523 3629
3524 $self->SUPER::destroy; 3630 $self->SUPER::destroy;
3525} 3631}
3526 3632
4170 while ($self->{post_alloc_hook}) { 4276 while ($self->{post_alloc_hook}) {
4171 $_->() 4277 $_->()
4172 for values %{delete $self->{post_alloc_hook}}; 4278 for values %{delete $self->{post_alloc_hook}};
4173 } 4279 }
4174 4280
4175
4176 glViewport 0, 0, $::WIDTH, $::HEIGHT; 4281 glViewport 0, 0, $::WIDTH, $::HEIGHT;
4177 glClearColor +($::CFG->{fow_intensity}) x 3, 1; 4282 glClearColor +($::CFG->{fow_intensity}) x 3, 1;
4178 glClear GL_COLOR_BUFFER_BIT; 4283 glClear GL_COLOR_BUFFER_BIT;
4179 4284
4180 glMatrixMode GL_PROJECTION; 4285 glMatrixMode GL_PROJECTION;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines