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.266 by root, Thu Jun 1 03:42:58 2006 UTC vs.
Revision 1.268 by root, Thu Jun 1 05:04:41 2006 UTC

171sub rescale_widgets { 171sub rescale_widgets {
172 my ($sx, $sy) = @_; 172 my ($sx, $sy) = @_;
173 173
174 for my $widget (values %WIDGET) { 174 for my $widget (values %WIDGET) {
175 if ($widget->{is_toplevel}) { 175 if ($widget->{is_toplevel}) {
176 $widget->{x} += $widget->{w} * 0.5 if $widget->{x} =~ /^[0-9.]+$/; 176 $widget->{x} += int $widget->{w} * 0.5 if $widget->{x} =~ /^[0-9.]+$/;
177 $widget->{y} += $widget->{h} * 0.5 if $widget->{y} =~ /^[0-9.]+$/; 177 $widget->{y} += int $widget->{h} * 0.5 if $widget->{y} =~ /^[0-9.]+$/;
178 178
179 $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.]+$/;
180 $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};
181 $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};
182 $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.]+$/;
183 $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};
184 $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};
185 185
186 $widget->{x} -= $widget->{w} * 0.5 if $widget->{x} =~ /^[0-9.]+$/; 186 $widget->{x} -= int $widget->{w} * 0.5 if $widget->{x} =~ /^[0-9.]+$/;
187 $widget->{y} -= $widget->{h} * 0.5 if $widget->{y} =~ /^[0-9.]+$/; 187 $widget->{y} -= int $widget->{h} * 0.5 if $widget->{y} =~ /^[0-9.]+$/;
188 188
189 } 189 }
190 } 190 }
191 191
192 reconfigure_widgets; 192 reconfigure_widgets;
450 my ($self, $ev, $x, $y) = @_; 450 my ($self, $ev, $x, $y) = @_;
451 451
452 $self->focus_in; 452 $self->focus_in;
453} 453}
454 454
455sub w { $_[0]{w} = $_[1] if @_ > 1; $_[0]{w} }
456sub h { $_[0]{h} = $_[1] if @_ > 1; $_[0]{h} }
457sub x { $_[0]{x} = $_[1] if @_ > 1; $_[0]{x} }
458sub y { $_[0]{y} = $_[1] if @_ > 1; $_[0]{y} }
459sub z { $_[0]{z} = $_[1] if @_ > 1; $_[0]{z} }
460
461sub find_widget { 455sub find_widget {
462 my ($self, $x, $y) = @_; 456 my ($self, $x, $y) = @_;
463 457
464 return () unless $self->{can_events}; 458 return () unless $self->{can_events};
465 459
526 520
527 $self->realloc; 521 $self->realloc;
528 $self->update; 522 $self->update;
529} 523}
530 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
531sub draw { 529sub draw {
532 my ($self) = @_; 530 my ($self) = @_;
533 531
534 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);
535 543
536 glPushMatrix; 544 glPushMatrix;
537 glTranslate $self->{x}, $self->{y}, 0; 545 glTranslate $self->{x}, $self->{y}, 0;
538 $self->_draw; 546 $self->_draw;
539 glPopMatrix; 547 glPopMatrix;
804 $self->SUPER::size_allocate ($w, $h); 812 $self->SUPER::size_allocate ($w, $h);
805 $self->update; 813 $self->update;
806} 814}
807 815
808sub _render { 816sub _render {
817 my ($self) = @_;
818
809 $_[0]{children}[0]->draw; 819 $self->{children}[0]->draw;
810} 820}
811 821
812sub render_child { 822sub render_child {
813 my ($self) = @_; 823 my ($self) = @_;
814 824
815 $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 {
816 glClearColor 0, 0, 0, 0; 826 glClearColor 0, 0, 0, 0;
817 glClear GL_COLOR_BUFFER_BIT; 827 glClear GL_COLOR_BUFFER_BIT;
818 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
819 $self->_render; 836 $self->_render;
820 }; 837 };
821} 838}
822 839
823sub _draw { 840sub _draw {
824 my ($self) = @_; 841 my ($self) = @_;
825 842
826 my ($w, $h) = ($self->w, $self->h); 843 my ($w, $h) = @$self{qw(w h)};
827 844
828 my $tex = $self->{texture} 845 my $tex = $self->{texture}
829 or return; 846 or return;
830 847
831 glEnable GL_TEXTURE_2D; 848 glEnable GL_TEXTURE_2D;
913 } 930 }
914} 931}
915 932
916sub _render { 933sub _render {
917 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};
918 938
919 CFClient::OpenGL::glTranslate -$self->{view_x}, -$self->{view_y}; 939 CFClient::OpenGL::glTranslate -$self->{view_x}, -$self->{view_y};
920 940
921 $self->SUPER::_render; 941 $self->SUPER::_render;
922} 942}
3471 glLoadIdentity; 3491 glLoadIdentity;
3472 glOrtho 0, $::WIDTH, $::HEIGHT, 0, -10000, 10000; 3492 glOrtho 0, $::WIDTH, $::HEIGHT, 0, -10000, 10000;
3473 glMatrixMode GL_MODELVIEW; 3493 glMatrixMode GL_MODELVIEW;
3474 glLoadIdentity; 3494 glLoadIdentity;
3475 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
3476 $self->_draw; 3503 $self->_draw;
3477} 3504}
3478 3505
3479############################################################################# 3506#############################################################################
3480 3507

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines