package ONO::Lib::Image::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::IO;
###############################################################################
#
###############################################################################
sub brick {
my (
$self,
$size_x,
$size_y,
$color,
$switches,
) = @_;
#: Generate brick element HTML code.
#:
#: -B disable border color = #333333
#: -f flat (side view 1/3)
#: -F flat double (side view 2/3)
#: -i info (show below the brick)
#: -m display mm in -i mode
#: -s side view
#: -t top view (default)
my @resp = (32,20,10,5);
if (ONO::IO->device("phone")) {
@resp = (16,10,5,2);
}
my $width = $size_x*$resp[0];
my $height = $size_y*$resp[0];
my $total_height = $size_y*$resp[0];
if ($color =~ /:/) {
my @cp = split(/:/,$color);
$color = "rgb($cp[1],$cp[2],$cp[3])";
} else {
$color = "#$color";
}
if ($switches =~ /s/) {
$height = $resp[0];
if ($switches =~ /f/) {
$height = $height/3;
}
if ($switches =~ /F/) {
$height = $height/3*2;
}
if ($switches =~ /(f|F)/) {
$total_height = $height;
}
$height = int($height*1.2);
$total_height = int($total_height*1.21);
}
my $BULLET = "box_fabric p0 block$resp[1] radius$resp[2] auto trans70";
my ($BRICK,$STYLE);
if ($switches !~ /B/) {
$STYLE .= "border-color:#333333;";
}
$BRICK .= qq~<div class="rel block$resp[0] bo" style="width:${width}px;height:${total_height}px;$STYLE">
<div style="background-color:$color">
<table class="default_table">
~;
for (my $y = 0; $y < $size_y; $y++) {
$BRICK .= qq~ <tr>~;
for (my $x = 0; $x < $size_x; $x++) {
if ($switches =~ /s/) {
if ($y > 0) {
$BRICK .= qq~ <td class="p0 bt" style="border-color:#333333">
<div class="block$resp[0]" style="height:${height}px">
</div>
</td>
~;
} else {
$BRICK .= qq~ <td class="p0">
<div class="block$resp[0]" style="height:${height}px">
<div class="rel" style="left:5px;top:-10px">
<div class="bo block8" style="width:20px;background-color:$color;$STYLE"></div>
</div>
</div>
</td>
~;
}
} else {
$BRICK .= qq~ <td class="p0">
<div class="block$resp[0]">
<div class="rel" style="top:$resp[3]px">
<div class="$BULLET"></div>
</div>
</div>
</td>
~;
}
}
$BRICK .= qq~ </tr>~;
}
$BRICK .= qq~ </table>
</div>
~;
if ($switches =~ /i/) {
if (!ONO::IO->device("phone")) {
my $INFO = "$size_x * $size_y";
if ($switches =~ /i/) {
$INFO = qq~ $size_x<span class="col9">u</span>~;
}
if ($switches =~ /m/) {
my $mm = 8 * $size_x;
$INFO .= qq~ • $mm<span class="col9">mm</span>~;
}
$BRICK .= qq~ <div class="p5 bl bb br mt5"></div><div class="center large col3 bold">$INFO</div>~;
}
}
$BRICK .= qq~</div>~;
return $BRICK;
}
sub rail {
my (
$self,
$size_w,
$size_h,
) = @_;
#: Generate brick element rail HTML code.
my @s = (
int($size_w/2), int($size_h/3.5),
int($size_w/4), int($size_h/2.5),
$size_w, int($size_h/4.5),
);
return qq~<table class="default_table">
<tr>
<td class="p0"><div class="p2 auto" style="width:$s[0]px;height:$s[1]px;background-color:#eeaa00"></div></td>
</tr>
<tr>
<td class="p0"><div class="p2 auto" style="width:$s[2]px;height:$s[3]px;background-color:#eeaa00"></div></td>
</tr>
<tr>
<td class="p0"><div class="p2 auto" style="width:$s[4]px;height:$s[5]px;background-color:#eeaa00"></div></td>
</tr>
</table>
~;
}
sub rail_track {
my (
$self,
$scale,
) = @_;
#: Generate brick element rail track HTML code.
my @data;
# units gauge adj / tr_w tr_h adjust / tie
if ($scale eq "g") {
@data = (11, 45, 50, 32, 32, 22, 56, "663300","ims");
}
if ($scale eq "l") {
@data = (8, 38, 55, 28, 24, 16.66,66.66,"666666","fims");
}
if ($scale eq "lm") {
@data = (6, 32, 40, 28, 24, 25, 50, "666666","fims");
}
if ($scale eq "h0") {
@data = (4, 16.5, 50, 12, 12, 20, 60, "663300","fims");
}
my $width_total = ($data[0] * 32) + 2;
my $TRACK;
$TRACK .= qq~<div class="auto" style="width:$data[2]%">
<div class="bold large center">$data[1]<span class="col9">mm</span></div>
<div class="p5 bt bl br mb5"></div>
</div>
~;
$TRACK .= qq~<div class="rel" style="z-index:999">
<table class="wide_table">
<tr>
<td style="width:$data[5]%"></td>
<td class="p0">
~;
$TRACK .= &rail("",$data[3],$data[4]);
$TRACK .= qq~ </td>
<td style="width:$data[6]%"></td>
<td class="p0">
~;
$TRACK .= &rail("",$data[3],$data[4]);
$TRACK .= qq~ </td>
<td style="width:$data[6]%"></td>
</tr>
</table>
</div>
<div class="rel" style="z-index:0">
~;
$TRACK .= &brick("",$data[0],1,$data[7],$data[8]);
$TRACK .= qq~</div>~;
return qq~<div class="rel" style="width:${width_total}px">$TRACK</div>~;
}
###############################################################################
# end of script
###############################################################################
1;
__END__