package ONO::Lib::PDF::Elements::CheckBox;
################################################################################
# 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;
#: This module generates specific PDF content.
sub checkbox {
my (
$self,
$canvas,
$x,
$y,
$width,
$weight,
$checked,
) = @_;
#: This generates a checkbox.
my $off = $width/6;
ONO::Lib::PDF::Draw->rect($canvas,$x+$off, $y+$off, $x+$width+$off,$y+$width+$off,$weight,"","0:127:127:127");
ONO::Lib::PDF::Draw->rect($canvas,$x, $y, $x+$width, $y+$width, $weight,"","0:255:255:255");
ONO::Lib::PDF::Draw->rect($canvas,$x, $y, $x+$width, $y+$width, $weight);
if ($checked) {
ONO::Lib::PDF::Draw->line($canvas,$x+$off,$y+$off,$x+$width-$off,$y+$width-$off,1);
ONO::Lib::PDF::Draw->line($canvas,$x+$width-$off,$y+$off,$x+$off,$y+$width-$off,1);
}
}
sub cross {
my (
$self,
$canvas,
$x,
$y,
$size,
$switches,
$color, # not implemented yet, red = default
) = @_;
#: This generates a cross.
#:
#: Switches:
#:
#: -W wide background
eval "use PDF::Reuse";
if (!$@) {
my @rand;
for (my $r = 0; $r < 8; $r++) {
$rand[$r] = 0.3-rand(0.6);
}
my ($c1,$c2,$c3) = (200+int(rand(50)),int(rand(30)),int(rand(40)));
if ($switches =~ /W/) {
ONO::Lib::PDF::Draw->line($canvas,$x+$size+$rand[0],$y-$size+$rand[1],$x-$size+$rand[2],$y+$size+$rand[3],$size*1.75,"0:255:255:255");
ONO::Lib::PDF::Draw->line($canvas,$x+$size+$rand[4],$y+$size+$rand[5],$x-$size+$rand[6],$y-$size+$rand[7],$size*1.75,"0:255:255:255");
}
ONO::Lib::PDF::Draw->line($canvas,$x+$size+$rand[0],$y-$size+$rand[1],$x-$size+$rand[2],$y+$size+$rand[3],$size,"0:$c1:$c2:$c3");
ONO::Lib::PDF::Draw->line($canvas,$x+$size+$rand[4],$y+$size+$rand[5],$x-$size+$rand[6],$y-$size+$rand[7],$size,"0:$c1:$c2:$c3");
}
}
###############################################################################
# end of script
###############################################################################
1;
__END__