Progress Bar enabled \!
This commit is contained in:
parent
242837e1ff
commit
7ef776a887
@ -2,7 +2,7 @@ package MyWrapper;
|
||||
use GD;
|
||||
use strict;
|
||||
use warnings;
|
||||
use 5.14.2;
|
||||
use v5.14;
|
||||
use Moo;
|
||||
use MooX::Options;
|
||||
|
||||
@ -13,6 +13,22 @@ option distance_entre_mots => ( is => 'rw',
|
||||
short => 'dem',
|
||||
format => 'i', default => sub { 5 }
|
||||
);
|
||||
option extends => ( is => 'rw',
|
||||
doc => 'si la taille du message est importante, on peut agrandir le cadre à volonté',
|
||||
short => 'ext'
|
||||
);
|
||||
option progress_bar => ( is => 'rw',
|
||||
doc => 'si vous souhaitez utiliser le script pour gérer une barre de progression, il faut indiquer un pourcentage',
|
||||
format => 'i', short => 'pb'
|
||||
);
|
||||
option debug => ( is => 'rw',
|
||||
doc => 'si vous souhaitez utiliser le script pour gérer une barre de progression',
|
||||
short => 'd'
|
||||
);
|
||||
option couleurs_dispo => ( is => 'rw',
|
||||
doc => 'affiche les couleurs disponibles',
|
||||
short => 'cd'
|
||||
);
|
||||
option output => ( is => 'rw',
|
||||
doc => 'fichier généré : fichier image (ex: image.png)',
|
||||
short => 'o',
|
||||
@ -36,7 +52,7 @@ option couleur_contour => ( is => 'rw',
|
||||
option couleur_interne => ( is => 'rw',
|
||||
doc => 'couleur interne',
|
||||
short => 'ci',
|
||||
format => 's', default => sub { 'blanc' }
|
||||
format => 's', default => sub { 'rouge' }
|
||||
);
|
||||
option couleur_background => ( is => 'rw' ,
|
||||
doc => 'couleur du fond (écriture)',
|
||||
@ -51,7 +67,7 @@ option taille_x => ( is => 'rw',
|
||||
option taille_y => ( is => 'rw',
|
||||
doc => 'taille Y', format => 'i',
|
||||
short => 'y',
|
||||
default => sub { 50 }
|
||||
default => sub { 30 }
|
||||
);
|
||||
sub _build_colors {
|
||||
{
|
||||
@ -75,31 +91,47 @@ sub afficher_couleurs {
|
||||
sub afficher_valeurs_actuelles {
|
||||
my ($self) = @_;
|
||||
say "Message : " . $self->message;
|
||||
say "Peut être étendu" if $self->extends;
|
||||
say "Output file : " . $self->output;
|
||||
say "Distance entre mots : " . $self->distance_entre_mots;
|
||||
say "couleur_interne : " . $self->couleur_interne;
|
||||
say "couleur_externe : " . $self->couleur_externe;
|
||||
say "couleur_background : " . $self->couleur_background;
|
||||
say "taille_x : " . $self->taille_x;
|
||||
say "taille_y : " . $self->taille_y;
|
||||
say "taille_x calculée: " . $self->calcul_taille_x;
|
||||
}
|
||||
sub tests {
|
||||
sub calcul_taille_x {
|
||||
my ($self) = @_;
|
||||
my %couleurs = %{$self->couleurs};
|
||||
|
||||
say "couleur_externe : " . $self->couleur_externe;
|
||||
say "Cette couleur n'existe pas !" unless exists $couleurs{$self->couleur_externe};
|
||||
my $taille_x = $self->taille_x;
|
||||
my @mots = split / /, $self->message;
|
||||
if( $self->extends ) {
|
||||
$taille_x += length $_ for( @mots ) ;
|
||||
}
|
||||
return $taille_x;
|
||||
}
|
||||
sub run {
|
||||
my $self = shift;
|
||||
#$self->afficher_couleurs ;
|
||||
#$self->afficher_valeurs_actuelles;
|
||||
sub calcul_taille_y {
|
||||
my ($self) = @_;
|
||||
return $self->taille_y;
|
||||
}
|
||||
sub enregistrement_image {
|
||||
my ($self, $im) = @_;
|
||||
# We record the image file
|
||||
open (DISPLAY,"> " . $self->output ) || die;
|
||||
binmode DISPLAY;
|
||||
print DISPLAY $im->png;
|
||||
close DISPLAY;
|
||||
}
|
||||
sub do_img {
|
||||
my ($self) = @_;
|
||||
my %couleurs = %{$self->couleurs};
|
||||
my %couleurs_allouee;
|
||||
|
||||
my @mots = split / /, $self->message;
|
||||
my $x = $self->taille_x;
|
||||
my $y = $self->taille_y;
|
||||
my $intersection = $x - 30;
|
||||
my $x = $self->calcul_taille_x;
|
||||
my $y = $self->calcul_taille_y;
|
||||
my $intersection = $x -30;
|
||||
my $taille_progress_bar = $self->progress_bar * ($x - 1) / 100;
|
||||
|
||||
# create a new image
|
||||
my $im = new GD::Image($x,$y);
|
||||
@ -113,20 +145,23 @@ sub run {
|
||||
# make the background transparent and interlaced
|
||||
#$im->transparent($couleurs_allouee{'blanc'});
|
||||
$im->interlaced('true');
|
||||
|
||||
# Put a frame around the picture
|
||||
$im->rectangle(0, 0, $x -1, $y -1, $couleurs_allouee{$self->couleur_contour});
|
||||
# Put the background color
|
||||
$im->filledRectangle(1, 1, $x -2, $y -2, $couleurs_allouee{$self->couleur_background});
|
||||
|
||||
# We add the word cases
|
||||
$im->filledRectangle(2, 2, $intersection - $self->distance_entre_mots, $y -3, $couleurs_allouee{$self->couleur_interne});
|
||||
$im->filledRectangle(2, 2, $taille_progress_bar, $y -3, $couleurs_allouee{$self->couleur_interne});
|
||||
|
||||
# make sure we are writing to a binary stream
|
||||
binmode STDOUT;
|
||||
|
||||
# Convert the image to PNG and print it on standard output
|
||||
print $im->png;
|
||||
$self->enregistrement_image( $im );
|
||||
}
|
||||
sub mode_debug {
|
||||
my ($self) = @_;
|
||||
say "ENTER DEBUG MODE";
|
||||
$self->afficher_valeurs_actuelles unless $self->couleurs_dispo;
|
||||
$self->afficher_couleurs if $self->couleurs_dispo;
|
||||
}
|
||||
sub run {
|
||||
my ($self) = @_;
|
||||
$self->mode_debug if $self->debug;
|
||||
$self->do_img unless $self->debug;
|
||||
}
|
||||
|
||||
1;
|
||||
|
Loading…
Reference in New Issue
Block a user