--- deliantra/Deliantra-Client/DC/UI.pm 2006/04/09 02:44:51 1.34 +++ deliantra/Deliantra-Client/DC/UI.pm 2006/04/09 17:34:15 1.35 @@ -130,23 +130,29 @@ #$self->deactivate; } -package Crossfire::Client::Widget::Container; +package Crossfire::Client::Widget::Bin; our @ISA = Crossfire::Client::Widget::; -use SDL::OpenGL; - sub add { $_[0]->{child} = $_[1]; $_[1]->set_parent ($_[0]); $_[1]->update } + sub get { $_[0]->{child} } + sub remove { my ($self, $chld) = @_; delete $self->{child} if $self->{child} == $chld; } -sub size_request { $_[0]->{child}->size_request if $_[0]->{child} } +sub size_request { + $_[0]->{child}->size_request if $_[0]->{child} +} -sub _draw { die "Containers can't be drawn!" } +sub _draw { + my ($self) = @_; + + $self->{child}->draw; +} package Crossfire::Client::Widget::Toplevel; @@ -186,7 +192,7 @@ package Crossfire::Client::Widget::Window; -our @ISA = Crossfire::Client::Widget::Container::; +our @ISA = Crossfire::Client::Widget::Bin::; use SDL::OpenGL; @@ -237,11 +243,9 @@ glEnable GL_BLEND; glEnable GL_TEXTURE_2D; - glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE; + glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; glBindTexture GL_TEXTURE_2D, $tex->{name}; - glColor 1, 0, 1; - glBegin GL_QUADS; glTexCoord 0, 0; glVertex 0, 0; glTexCoord 0, 1; glVertex 0, $h; @@ -255,7 +259,7 @@ package Crossfire::Client::Widget::Frame; -our @ISA = Crossfire::Client::Widget::Container::; +our @ISA = Crossfire::Client::Widget::Bin::; use SDL::OpenGL; @@ -404,7 +408,7 @@ package Crossfire::Client::Widget::Table; -our @ISA = Crossfire::Client::Widget::Container::; +our @ISA = Crossfire::Client::Widget::Bin::; use SDL::OpenGL; @@ -489,7 +493,7 @@ package Crossfire::Client::Widget::VBox; -our @ISA = Crossfire::Client::Widget::Container::; +our @ISA = Crossfire::Client::Widget::Bin::; use SDL::OpenGL; @@ -752,7 +756,10 @@ glEnable GL_TEXTURE_2D; glEnable GL_BLEND; - glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE; + glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; + + my $sw4 = ($sw + 3) & ~3; + my $lighting = "\x00" x ($sw4 * $sh); for my $x (0 .. $sw - 1) { for my $y (0 .. $sh - 1) { @@ -762,10 +769,9 @@ my $darkness = $cell->[0] * (1 / 255); if ($darkness < 0) { - glColor 0.3, 0.3, 0.3; - } else { - glColor $darkness, $darkness, $darkness; + $darkness = 0.15; } + substr $lighting, $y * $sw4 + $x, 1, chr 255 - $darkness * 255; for my $num (grep $_, @$cell[1,2,3]) { my $tex = $::CONN->{face}[$num]{texture} || next; @@ -788,6 +794,35 @@ } } +# if (1) { # higher quality darkness +# $lighting =~ s/(.)/$1$1$1/gs; +# my $pb = new_from_data Gtk2::Gdk::Pixbuf $lighting, "rgb", 0, 8, $sw4, $sh, $sw4 * 3; +# +# $pb = $pb->scale_simple ($sw4 * 0.5, $sh * 0.5, "bilinear"); +# +# $lighting = $pb->get_pixels; +# $lighting =~ s/(.)../$1/gs; +# } + + $lighting = new Crossfire::Client::Texture + width => $sw4, + height => $sh, + data => $lighting, + internalformat => GL_ALPHA4, + format => GL_ALPHA; + + glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA; + glColor 0, 0, 0, 0.75; + glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE; + glBindTexture GL_TEXTURE_2D, $lighting->{name}; + glTexParameter GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR; + glBegin GL_QUADS; + glTexCoord 0, 0; glVertex 0 , 0; + glTexCoord 0, 1; glVertex 0 , $sh * 32; + glTexCoord 1, 1; glVertex $sw4 * 32, $sh * 32; + glTexCoord 1, 0; glVertex $sw4 * 32, 0; + glEnd; + glDisable GL_TEXTURE_2D; glDisable GL_BLEND; } @@ -843,5 +878,45 @@ } } +package Crossfire::Client::Widget::Animator; + +use SDL::OpenGL; + +our @ISA = Crossfire::Client::Widget::Bin::; + +sub moveto { + my ($self, $x, $y) = @_; + + $self->{moveto} = [$self->{x}, $self->{y}, $x, $y]; + $self->{speed} = 0.01; + $self->{time} = 1; + + ::animation_start $self; +} + +sub animate { + my ($self, $interval) = @_; + + $self->{time} -= $interval * $self->{speed}; + if ($self->{time} <= 0) { + $self->{time} = 0; + ::animation_stop $self; + } + + my ($x0, $y0, $x1, $y1) = @{$self->{moveto}}; + + $self->{x} = $x0 * $self->{time} + $x1 * (1 - $self->{time}); + $self->{y} = $y0 * $self->{time} + $y1 * (1 - $self->{time}); +} + +sub _draw { + my ($self) = @_; + + glPushMatrix; + glRotate $self->{time} * 10000, 0, 1, 0; + $self->{child}->draw; + glPopMatrix; +} + 1;