Acme-Monkey
view release on metacpan or search on metacpan
lib/Acme/Monkey.pm view on Meta::CPAN
# TODO: put all OO boilerplate...
sub new {
my $class = shift;
my %params = @_;
my $self = {};
$self->{WIDTH} = $params{'width'} || $params{'W'} || undef;
$self->{HEIGHT} = $params{'height'} || $params{'H'} || undef;
# TODO: Should we just default X,Y instead?
croak "Width required\n" if !defined($self->{WIDTH});
croak "Height required\n" if !defined($self->{HEIGHT});
$self->{BUF_SIZE} = $self->{WIDTH} * $self->{HEIGHT};
$self->{BUFFER} = '';
bless($self, $class);
}
sub width {
lib/Acme/Monkey/Frame.pm view on Meta::CPAN
use Acme::Monkey::ClearScreen;
use Term::Screen;
use Term::ANSIColor qw(:constants);
extends 'Acme::Monkey::ClearScreen';
has 'width' => (is=>'rw', isa=>'Int', required=>1);
has 'height' => (is=>'rw', isa=>'Int', required=>1);
has 'layers' => (is=>'rw', isa=>'HashRef', default=>sub{ {} });
sub draw {
my ($self) = @_;
my @layers = map { $self->layers->{$_} } sort keys( %{ $self->layers() } );
my $content = '';
foreach my $y (1..$self->height()) {
foreach my $x (1..$self->width()) {
my $char;
lib/Acme/Monkey/Frame/Layer.pm view on Meta::CPAN
package Acme::Monkey::Frame::Layer;
use Moose;
use Term::ANSIColor qw(:constants);
has 'x' => (is=>'rw', isa=>'Int', default=>1);
has 'y' => (is=>'rw', isa=>'Int', default=>1);
has 'width' => (is=>'rw', isa=>'Int', required=>1);
has 'height' => (is=>'rw', isa=>'Int', required=>1);
has 'hidden' => (is=>'rw', isa=>'Int', default=>0);
has 'constrain' => (is=>'rw', isa=>'Int', default=>0);
has 'color' => (is=>'rw', isa=>'Str', default=>WHITE);
has '_canvas' => (is=>'rw', isa=>'ArrayRef', default=>\&clear, lazy=>1);
sub clear {
my ($self) = @_;
my $canvas = [];
foreach my $x (1..$self->width()) {
foreach my $y (1..$self->height()) {
$canvas->[$x]->[$y] = '';
}
( run in 0.397 second using v1.01-cache-2.11-cpan-0a6323c29d9 )