ONO::Lib::PDF::Elements::Brick

package ONO::Lib::PDF::Elements::Brick;
################################################################################
# COPYRIGHT / LICENSE #
################################################################################
#
# This file is part of the ONO Software Project.
#
# Copyright (C) 2000-2025 Jos KIRPS [ www.kirps.com | jos_AT_kirps_DOT_com ]
# and The Joopita Project [ www.joopita.org | contact_AT_joopita_DOT_com ]
#
# This file, as well as other parts of the ONO Software Project or related
# elements, are FREE SOFTWARE available under the ARTISTIC LICENSE 2.0.
#
# This program is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
#
# For the full license, see /ono/osr/license/LICENSE.txt, or write to
# jos_AT_kirps_DOT_com or contact_AT_joopita_DOT_com.
#
################################################################################
# END OF COPYRIGHT / LICENSE, HERE COMES THE CODE ... #
################################################################################

use strict;

use ONO::Lib::PDF::Draw;
use ONO::Lib::Image::Canvas::Draw;
use ONO::Lib::PDF::Elements::CheckBox;

#: This module generates specific PDF content.

sub brick {

my (
$self,
$canvas,
$x1,
$y1,
$width,
$height,
$mm_per_unit,
$weight,
$color,
$circle_color,
$circle_max,
$circle_split,
$circle_minus,
) = @_;

#: This generates a builing block brick.

eval "use PDF::Reuse";
if (!$@) {

if ($mm_per_unit < 1 || $mm_per_unit > 20) {
$mm_per_unit = 10;
}

my $x2 = $x1 + ($width * $mm_per_unit);
my $y2 = $y1 + ($height * $mm_per_unit);
my $counter;

ONO::Lib::PDF::Draw->rect($canvas,$x1,$y1,$x2,$y2,$weight,"",$color);

my $delta = 100;
my $delta_color = ONO::Lib::PDF::Draw->color_calc($color,$delta);
my $circle_color2;
if ($circle_max) {
if ($circle_color =~ m~^(.*?)/(.*?)$~) {
$circle_color = $1;
$circle_color2 = $2;
}
if ($circle_color) {
$delta_color = $circle_color;
}
}

for (my $x = 0; $x < $width; $x++) {
for (my $y = 0; $y < $height; $y++) {

my ($circ_x,$circ_y) = ($x1+($x*$mm_per_unit)+($mm_per_unit/2),$y1+($y*$mm_per_unit)+($mm_per_unit/2));
my $circ_size = $mm_per_unit/3;
my $minus_bar;

if ($circle_max) {
# add mode: switch color
if ($circle_split && $counter+1 > $circle_split) {
$delta_color = $circle_color2;
}
# limit colored dots
if ($counter+1 > $circle_max) {
$delta_color = "";
}
# minus mode: bars
if ($circle_minus) {
if ($counter < $circle_max && $counter+1 > $circle_max-$circle_minus) {
$minus_bar = 1;
}
}
}

ONO::Lib::PDF::Draw->circle(
$canvas,
$circ_x,$circ_y,
$circ_size,
$weight,
ONO::Lib::PDF::Draw->color_calc($delta_color,15-int(rand(30))+$minus_bar*30),
);

if ($minus_bar) {

ONO::Lib::PDF::Elements::CheckBox->cross($canvas,$circ_x,$circ_y,$circ_size);

}

$counter++;

}
}

}

}

###############################################################################
# end of script
###############################################################################

1;

__END__