--- deliantra/Deliantra-Client/DC.pm 2006/04/07 18:20:13 1.3 +++ deliantra/Deliantra-Client/DC.pm 2006/04/07 18:49:52 1.4 @@ -29,6 +29,25 @@ my @textures; +sub _new { + my ($class, %data) = @_; + + my $self = bless \%data, $class; + + push @textures, $self; + Scalar::Util::weaken $textures[-1]; + + $self->upload; + + $self +} + +sub new_from_image { + my ($class, $image) = @_; + + $class->_new (image => $image) +} + sub new_from_file { my ($class, $path) = @_; @@ -36,22 +55,19 @@ or die "$path: $!"; local $/; - $class->new_from_data (<$fh>) + $class->new_from_image (<$fh>) } -sub new_from_image { - my ($class, $image) = @_; +sub new_from_surface { + my ($class, $surface) = @_; - my $self = bless { - image => $data, - }; + $surface->rgba; - push @textures, $self; - Scalar::Util::weaken $textures[-1]; - - $self->upload; - - $self + $class->_new ( + data => $surface->pixels, + width => $surface->width, + height => $surface->height, + ) } sub upload { @@ -65,7 +81,7 @@ ($data, $width, $height) = ($self->{data}, $self->{width}, $self->{height}); } else { my $pb = new Gtk2::Gdk::PixbufLoader; - $pb->write ($self->{data}); + $pb->write ($self->{image}); $pb->close; $pb = $pb->get_pixbuf;