/lib/SDLx/Surface/TiedMatrixRow.pm

http://github.com/PerlGameDev/SDL · Perl · 42 lines · 31 code · 11 blank · 0 comment · 0 complexity · cede8a0d1b7901418e421647560ff4f4 MD5 · raw file

  1. package SDLx::Surface::TiedMatrixRow;
  2. use strict;
  3. use warnings;
  4. use base 'Tie::Array';
  5. our $VERSION = 2.548;
  6. sub new {
  7. my $class = shift;
  8. my $matrix = shift;
  9. my $y = shift;
  10. my $self = {
  11. matrix => $matrix,
  12. y => $y,
  13. };
  14. return bless $self, $class;
  15. }
  16. sub TIEARRAY {
  17. return SDLx::Surface::TiedMatrixRow->new( $_[1], $_[2] );
  18. }
  19. sub FETCH {
  20. my ( $self, $x ) = @_;
  21. $self->{matrix}->get_pixel( $x, $self->{y} );
  22. }
  23. sub FETCHSIZE {
  24. my ( $self, $x ) = @_;
  25. return $self->{matrix}->surface->w;
  26. }
  27. sub STORE {
  28. my ( $self, $x, $new_value ) = @_;
  29. $self->{matrix}->set_pixel( $x, $self->{y}, $new_value );
  30. }
  31. 1;