package ONO::Lib::UI::Range;
################################################################################
# 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;
###############################################################################
# radio buttons
###############################################################################
sub range {
my (
$self,
$id,
$value,
$min,
$max,
$step,
$label,
$switches,
$JS_ADD,
) = @_;
#: Range number input.
#:
#: -B Blue color slider
#: -G Green color slider
#: -R Red color slider
#: -J use additional $JS code
if (!$min) {
$min = 0;
}
if (!$max) {
$max = 100;
}
if (!$step) {
$step = 1;
}
my $id_add;
if ($id =~ /^(.*?):(.*?)$/) {
$id = $1;
$id_add = $2;
}
my $numwidth = 30;
if ($max > 9) {
$numwidth = 40;
}
if ($max > 99) {
$numwidth = 50;
}
if ($max > 999) {
$numwidth = 60;
}
if ($step =~ /\./) {
$numwidth = $numwidth+10;
}
my ($TD,$JS);
if ($switches =~ /(R|G|B)/) {
my ($r,$g,$b) = (0,0,0);
if ($switches =~ /R/) {
$r = $value;
$JS .= qq~onojs_setbgcolorrgb('ono_range_${id}_color',onojs_getvalue('ono_range_${id}_id'),0,0);~;
}
if ($switches =~ /G/) {
$g = $value;
$JS .= qq~onojs_setbgcolorrgb('ono_range_${id}_color',0,onojs_getvalue('ono_range_${id}_id'),0);~;
}
if ($switches =~ /B/) {
$b = $value;
$JS .= qq~onojs_setbgcolorrgb('ono_range_${id}_color',0,0,onojs_getvalue('ono_range_${id}_id'));~;
}
$TD = qq~<td style="padding:2px 5px 4px 2px">
<div id="ono_range_${id}_color" class="bg_white bo block radius5"
style="width:22px;height:22px;background-color:rgb($r,$g,$b);border-color:#666666"></div>
</td>
~;
}
if ($switches =~ /J/) {
$JS .= $JS_ADD;
}
return qq~<div class="rel">
<table class="wide_table">
<tr class="vbot">
<td class="w100">$label:</td>
$TD
<td class="">
<input type="number" id="ono_range_${id}_number" name="sCopiesText" min="$min" max="$max" step="$step" value="$value" style="width:${numwidth}px;padding:2px 2px 2px 4px">
</td>
</tr>
</table>
<div class="rel" style="padding:0px 5px 0px 0px;top:-5px">
<input type="range" id="ono_range_${id}_id" name="ono_range_${id}" min="$min" max="$max" step="$step" value="$value"
oninput="onojs_setvalue('ono_range_${id}_number',onojs_getvalue('ono_range_${id}_id'));$JS"
onchange="onojs_setvalue('ono_range_${id}_number',onojs_getvalue('ono_range_${id}_id'));$JS">
</div>
</div>
~;
}
###############################################################################
# end of script
###############################################################################
1;
__END__