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.265 by root, Thu Jun 1 02:59:46 2006 UTC vs.
Revision 1.268 by root, Thu Jun 1 05:04:41 2006 UTC

40 40
41 $LAYOUT = $layout; 41 $LAYOUT = $layout;
42} 42}
43 43
44sub check_tooltip { 44sub check_tooltip {
45 return if $ENV{CFPLUS_DEBUG} & 8;
46
45 if (!$GRAB) { 47 if (!$GRAB) {
46 for (my $widget = $HOVER; $widget; $widget = $widget->{parent}) { 48 for (my $widget = $HOVER; $widget; $widget = $widget->{parent}) {
47 if (length $widget->{tooltip}) { 49 if (length $widget->{tooltip}) {
48
49 if ($TOOLTIP->{owner} != $widget) { 50 if ($TOOLTIP->{owner} != $widget) {
50 $TOOLTIP->hide; 51 $TOOLTIP->hide;
51 52
52 $TOOLTIP->{owner} = $widget; 53 $TOOLTIP->{owner} = $widget;
53 54
170sub rescale_widgets { 171sub rescale_widgets {
171 my ($sx, $sy) = @_; 172 my ($sx, $sy) = @_;
172 173
173 for my $widget (values %WIDGET) { 174 for my $widget (values %WIDGET) {
174 if ($widget->{is_toplevel}) { 175 if ($widget->{is_toplevel}) {
175 $widget->{x} += $widget->{w} * 0.5 if $widget->{x} =~ /^[0-9.]+$/; 176 $widget->{x} += int $widget->{w} * 0.5 if $widget->{x} =~ /^[0-9.]+$/;
176 $widget->{y} += $widget->{h} * 0.5 if $widget->{y} =~ /^[0-9.]+$/; 177 $widget->{y} += int $widget->{h} * 0.5 if $widget->{y} =~ /^[0-9.]+$/;
177 178
178 $widget->{x} = int 0.5 + $widget->{x} * $sx if $widget->{x} =~ /^[0-9.]+$/; 179 $widget->{x} = int 0.5 + $widget->{x} * $sx if $widget->{x} =~ /^[0-9.]+$/;
179 $widget->{w} = int 0.5 + $widget->{w} * $sx if exists $widget->{w}; 180 $widget->{w} = int 0.5 + $widget->{w} * $sx if exists $widget->{w};
180 $widget->{force_w} = int 0.5 + $widget->{force_w} * $sx if exists $widget->{force_w}; 181 $widget->{force_w} = int 0.5 + $widget->{force_w} * $sx if exists $widget->{force_w};
181 $widget->{y} = int 0.5 + $widget->{y} * $sy if $widget->{y} =~ /^[0-9.]+$/; 182 $widget->{y} = int 0.5 + $widget->{y} * $sy if $widget->{y} =~ /^[0-9.]+$/;
182 $widget->{h} = int 0.5 + $widget->{h} * $sy if exists $widget->{h}; 183 $widget->{h} = int 0.5 + $widget->{h} * $sy if exists $widget->{h};
183 $widget->{force_h} = int 0.5 + $widget->{force_h} * $sy if exists $widget->{force_h}; 184 $widget->{force_h} = int 0.5 + $widget->{force_h} * $sy if exists $widget->{force_h};
184 185
185 $widget->{x} -= $widget->{w} * 0.5 if $widget->{x} =~ /^[0-9.]+$/; 186 $widget->{x} -= int $widget->{w} * 0.5 if $widget->{x} =~ /^[0-9.]+$/;
186 $widget->{y} -= $widget->{h} * 0.5 if $widget->{y} =~ /^[0-9.]+$/; 187 $widget->{y} -= int $widget->{h} * 0.5 if $widget->{y} =~ /^[0-9.]+$/;
187 188
188 } 189 }
189 } 190 }
190 191
191 reconfigure_widgets; 192 reconfigure_widgets;
449 my ($self, $ev, $x, $y) = @_; 450 my ($self, $ev, $x, $y) = @_;
450 451
451 $self->focus_in; 452 $self->focus_in;
452} 453}
453 454
454sub w { $_[0]{w} = $_[1] if @_ > 1; $_[0]{w} }
455sub h { $_[0]{h} = $_[1] if @_ > 1; $_[0]{h} }
456sub x { $_[0]{x} = $_[1] if @_ > 1; $_[0]{x} }
457sub y { $_[0]{y} = $_[1] if @_ > 1; $_[0]{y} }
458sub z { $_[0]{z} = $_[1] if @_ > 1; $_[0]{z} }
459
460sub find_widget { 455sub find_widget {
461 my ($self, $x, $y) = @_; 456 my ($self, $x, $y) = @_;
462 457
463 return () unless $self->{can_events}; 458 return () unless $self->{can_events};
464 459
525 520
526 $self->realloc; 521 $self->realloc;
527 $self->update; 522 $self->update;
528} 523}
529 524
525# using global variables seems a bit hacky, but passing through all drawing
526# functions seems pointless.
527our ($draw_x, $draw_y, $draw_w, $draw_h); # screen rectangle being drawn
528
530sub draw { 529sub draw {
531 my ($self) = @_; 530 my ($self) = @_;
532 531
533 return unless $self->{h} && $self->{w}; 532 return unless $self->{h} && $self->{w};
533
534 # update screen rectangle
535 local $draw_x = $draw_x + $self->{x};
536 local $draw_y = $draw_y + $self->{y};
537 local $draw_w = $draw_x + $self->{w};
538 local $draw_h = $draw_y + $self->{h};
539
540 # skip widgets that are entirely outside the drawing area
541 return if ($draw_x + $self->{w} < 0) || ($draw_x >= $draw_w)
542 || ($draw_y + $self->{h} < 0) || ($draw_y >= $draw_h);
534 543
535 glPushMatrix; 544 glPushMatrix;
536 glTranslate $self->{x}, $self->{y}, 0; 545 glTranslate $self->{x}, $self->{y}, 0;
537 $self->_draw; 546 $self->_draw;
538 glPopMatrix; 547 glPopMatrix;
803 $self->SUPER::size_allocate ($w, $h); 812 $self->SUPER::size_allocate ($w, $h);
804 $self->update; 813 $self->update;
805} 814}
806 815
807sub _render { 816sub _render {
817 my ($self) = @_;
818
808 $_[0]{children}[0]->draw; 819 $self->{children}[0]->draw;
809} 820}
810 821
811sub render_child { 822sub render_child {
812 my ($self) = @_; 823 my ($self) = @_;
813 824
814 $self->{texture} = new_from_opengl CFClient::Texture $self->{w}, $self->{h}, sub { 825 $self->{texture} = new_from_opengl CFClient::Texture $self->{w}, $self->{h}, sub {
815 glClearColor 0, 0, 0, 0; 826 glClearColor 0, 0, 0, 0;
816 glClear GL_COLOR_BUFFER_BIT; 827 glClear GL_COLOR_BUFFER_BIT;
817 828
829 {
830 package CFClient::UI::Base;
831
832 ($draw_x, $draw_y, $draw_w, $draw_h) =
833 (0, 0, $self->{w}, $self->{h});
834 }
835
818 $self->_render; 836 $self->_render;
819 }; 837 };
820} 838}
821 839
822sub _draw { 840sub _draw {
823 my ($self) = @_; 841 my ($self) = @_;
824 842
825 my ($w, $h) = ($self->w, $self->h); 843 my ($w, $h) = @$self{qw(w h)};
826 844
827 my $tex = $self->{texture} 845 my $tex = $self->{texture}
828 or return; 846 or return;
829 847
830 glEnable GL_TEXTURE_2D; 848 glEnable GL_TEXTURE_2D;
912 } 930 }
913} 931}
914 932
915sub _render { 933sub _render {
916 my ($self) = @_; 934 my ($self) = @_;
935
936 local $CFClient::UI::Base::draw_x = $CFClient::UI::Base::draw_x - $self->{view_x};
937 local $CFClient::UI::Base::draw_y = $CFClient::UI::Base::draw_y - $self->{view_y};
917 938
918 CFClient::OpenGL::glTranslate -$self->{view_x}, -$self->{view_y}; 939 CFClient::OpenGL::glTranslate -$self->{view_x}, -$self->{view_y};
919 940
920 $self->SUPER::_render; 941 $self->SUPER::_render;
921} 942}
1523 1544
1524sub size_allocate { 1545sub size_allocate {
1525 my ($self, $w, $h) = @_; 1546 my ($self, $w, $h) = @_;
1526 1547
1527 delete $self->{texture} 1548 delete $self->{texture}
1528 ;#d# 1549 unless $w >= $self->{req_w} && $self->{old_w} >= $self->{req_w};
1529} 1550}
1530 1551
1531sub set_fontsize { 1552sub set_fontsize {
1532 my ($self, $fontsize) = @_; 1553 my ($self, $fontsize) = @_;
1533 1554
3372 $_->() 3393 $_->()
3373 for values %{delete $self->{refresh_hook}}; 3394 for values %{delete $self->{refresh_hook}};
3374 } 3395 }
3375 3396
3376 if ($self->{realloc}) { 3397 if ($self->{realloc}) {
3398 my %queue;
3377 my @queue; 3399 my @queue;
3400 my $widget;
3378 3401
3402 outer:
3379 while () { 3403 while () {
3380 if ($self->{realloc}) { 3404 if (my $realloc = delete $self->{realloc}) {
3381 #TODO use array-of-depth approach 3405 for $widget (values %$realloc) {
3406 $widget->{visible} or next; # do not resize invisible widgets
3382 3407
3383 use sort 'stable'; 3408 $queue{$widget+0}++ and next; # duplicates are common
3384 3409
3385 @queue = sort { $a->{visible} <=> $b->{visible} } 3410 push @{ $queue[$widget->{visible}] }, $widget;
3386 @queue, values %{delete $self->{realloc}}; 3411 }
3387 } 3412 }
3388 3413
3414 while () {
3415 @queue or last outer;
3416
3389 my $widget = pop @queue || last; 3417 $widget = pop @{ $queue[-1] || [] }
3418 and last;
3419
3420 pop @queue;
3421 }
3390 3422
3391 $widget->{visible} or last; # do not resize invisible widgets 3423 delete $queue{$widget+0};
3392 3424
3393 my ($w, $h) = $widget->size_request; 3425 my ($w, $h) = $widget->size_request;
3394 3426
3395 $w = List::Util::max $widget->{min_w}, $w + $widget->{padding_x} * 2; 3427 $w = List::Util::max $widget->{min_w}, $w + $widget->{padding_x} * 2;
3396 $h = List::Util::max $widget->{min_h}, $h + $widget->{padding_y} * 2; 3428 $h = List::Util::max $widget->{min_h}, $h + $widget->{padding_y} * 2;
3404 $widget->{req_h} = $h; 3436 $widget->{req_h} = $h;
3405 3437
3406 $self->{size_alloc}{$widget+0} = $widget; 3438 $self->{size_alloc}{$widget+0} = $widget;
3407 3439
3408 if (my $parent = $widget->{parent}) { 3440 if (my $parent = $widget->{parent}) {
3409 $self->{realloc}{$parent+0} = $parent; 3441 $self->{realloc}{$parent+0} = $parent
3410 #unshift @queue, $parent; 3442 unless $queue{$parent+0};
3443
3411 $parent->{force_size_alloc} = 1; 3444 $parent->{force_size_alloc} = 1;
3412 $self->{size_alloc}{$parent+0} = $parent; 3445 $self->{size_alloc}{$parent+0} = $parent;
3413 } 3446 }
3414 } 3447 }
3415 3448
3431 3464
3432 $w = int $w + 0.5; 3465 $w = int $w + 0.5;
3433 $h = int $h + 0.5; 3466 $h = int $h + 0.5;
3434 3467
3435 if ($widget->{w} != $w || $widget->{h} != $h || delete $widget->{force_size_alloc}) { 3468 if ($widget->{w} != $w || $widget->{h} != $h || delete $widget->{force_size_alloc}) {
3469 $widget->{old_w} = $widget->{w};
3470 $widget->{old_h} = $widget->{h};
3471
3436 $widget->{w} = $w; 3472 $widget->{w} = $w;
3437 $widget->{h} = $h; 3473 $widget->{h} = $h;
3438 3474
3439 $widget->emit (size_allocate => $w, $h); 3475 $widget->emit (size_allocate => $w, $h);
3440 } 3476 }
3455 glLoadIdentity; 3491 glLoadIdentity;
3456 glOrtho 0, $::WIDTH, $::HEIGHT, 0, -10000, 10000; 3492 glOrtho 0, $::WIDTH, $::HEIGHT, 0, -10000, 10000;
3457 glMatrixMode GL_MODELVIEW; 3493 glMatrixMode GL_MODELVIEW;
3458 glLoadIdentity; 3494 glLoadIdentity;
3459 3495
3496 {
3497 package CFClient::UI::Base;
3498
3499 ($draw_x, $draw_y, $draw_w, $draw_h) =
3500 (0, 0, $self->{w}, $self->{h});
3501 }
3502
3460 $self->_draw; 3503 $self->_draw;
3461} 3504}
3462 3505
3463############################################################################# 3506#############################################################################
3464 3507

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines