--- deliantra/Deliantra-Client/DC/UI.pm 2006/06/01 03:42:58 1.266 +++ deliantra/Deliantra-Client/DC/UI.pm 2006/06/01 04:10:29 1.267 @@ -452,12 +452,6 @@ $self->focus_in; } -sub w { $_[0]{w} = $_[1] if @_ > 1; $_[0]{w} } -sub h { $_[0]{h} = $_[1] if @_ > 1; $_[0]{h} } -sub x { $_[0]{x} = $_[1] if @_ > 1; $_[0]{x} } -sub y { $_[0]{y} = $_[1] if @_ > 1; $_[0]{y} } -sub z { $_[0]{z} = $_[1] if @_ > 1; $_[0]{z} } - sub find_widget { my ($self, $x, $y) = @_; @@ -528,11 +522,23 @@ $self->update; } +# using global variables seems a bit hacky, but passing through all drawing +# functions seems pointless. +our ($draw_x, $draw_y, $draw_w, $draw_h); # screen rectangle being drawn + sub draw { my ($self) = @_; return unless $self->{h} && $self->{w}; + local $draw_x = $draw_x + $self->{x}; + local $draw_y = $draw_y + $self->{y}; + + return if $draw_x + $self->{w} < 0; + return if $draw_x >= $draw_w; + return if $draw_y + $self->{h} < 0; + return if $draw_y >= $draw_h; + glPushMatrix; glTranslate $self->{x}, $self->{y}, 0; $self->_draw; @@ -806,7 +812,9 @@ } sub _render { - $_[0]{children}[0]->draw; + my ($self) = @_; + + $self->{children}[0]->draw; } sub render_child { @@ -816,6 +824,13 @@ glClearColor 0, 0, 0, 0; glClear GL_COLOR_BUFFER_BIT; + { + package CFClient::UI::Base; + + ($draw_x, $draw_y, $draw_w, $draw_h) = + (0, 0, $self->{w}, $self->{h}); + } + $self->_render; }; } @@ -823,7 +838,7 @@ sub _draw { my ($self) = @_; - my ($w, $h) = ($self->w, $self->h); + my ($w, $h) = @$self{qw(w h)}; my $tex = $self->{texture} or return; @@ -916,6 +931,9 @@ sub _render { my ($self) = @_; + local $CFClient::UI::Base::draw_x = $CFClient::UI::Base::draw_x - $self->{view_x}; + local $CFClient::UI::Base::draw_y = $CFClient::UI::Base::draw_y - $self->{view_y}; + CFClient::OpenGL::glTranslate -$self->{view_x}, -$self->{view_y}; $self->SUPER::_render; @@ -3473,6 +3491,13 @@ glMatrixMode GL_MODELVIEW; glLoadIdentity; + { + package CFClient::UI::Base; + + ($draw_x, $draw_y, $draw_w, $draw_h) = + (0, 0, $self->{w}, $self->{h}); + } + $self->_draw; }