package ONO::Lib::UI::Icon;
################################################################################
# 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;
###############################################################################
# get the size of an image
###############################################################################
sub button {
my (
$self,
$icon,
$size,
$class,
$link,
$target_onclick,
$label,
$switches,
$threshold,
) = @_;
# -B web = button, mobile = icon, using $threshold as responsive trigger (default = 800)
# -C custom icon (instead of ONO icon set), this also supports double icons (the latter is incompatible with -D and -S options and works best with 24px icons!)
# -d disabled
# -D disable onclick
# -i inline mode (required to make background DIVs visible in some cases)
# -P parent -> blank
# -S submit ($link = action)
my $IMG = "/ono/osr/images/icons/ono/32x32/$icon.png";
my $ICON = qq~<img class="block$size $class" src="$IMG" alt="$icon">~;
if ($switches =~ /S/) {
$ICON = qq~<input class="block$size $class" type="image" src="$IMG" name="" value="">~;
}
if ($switches =~ /C/) {
$IMG = $icon;
$ICON = qq~<img class="block$size $class" src="$IMG" alt="$icon">~;
if ($icon =~ /^(.*?):(.*?)$/) {
$ICON = qq~<div class="block$size rel mr15">
<img class="block$size abs $class" src="$1" style="top:0px;left:0px" alt="">
<img class="block$size abs $class" src="$2" style="top:0px;left:20px" alt="">
</div>
~;
}
if ($switches =~ /S/) {
$ICON = qq~<input class="block$size $class" type="image" src="$IMG" name="" value="" style="width:${size}px;height:${size}px">~;
}
}
if (!$size) {
$size = 32;
}
my $rand = 1000000+int(rand(999999));
if ($label) {
$ICON = qq~<div class="rel fl">
<div class="fl" onmouseover="onojs_block('onolib_icolab_$rand');" onmouseout="onojs_hide('onolib_icolab_$rand');">$ICON</div>
<div id="onolib_icolab_$rand" class="abs hide" style="top:-28px;left:-16px">
<div class="box_paper bo pad10_0 nowrap small">$label</div>
</div>
</div>
~;
}
if ($link) {
$ICON = qq~<a href="$link" $target_onclick>$ICON</a>~;
}
if ($switches) {
if ($switches =~ /d/) {
$ICON = qq~<div class="trans30">$ICON</div>~;
}
if ($switches =~ /D/) {
$ICON = qq~<div id="onolib_icodis1_$rand" onclick="onojs_hide('onolib_icodis1_$rand');onojs_block('onolib_icodis2_$rand');">$ICON</div>
<div id="onolib_icodis2_$rand" class="fl hide"><img class="block$size $class trans30" src="$IMG" alt="$icon"></div>
~;
}
if ($switches =~ /B/) {
if ($threshold < 600) {
$threshold = 800;
}
my $label_add;
if ($label =~ s~: (.*)$~~) {
$label_add = $1;
$ICON = qq~<div class="fl rel hide$threshold" onmouseover="onojs_block('onolib_icolab_but_$rand');" onmouseout="onojs_hide('onolib_icolab_but_$rand');">
<a href="$link" $target_onclick class="button_green $class">$label</a>
<div id="onolib_icolab_but_$rand" class="abs hide" style="top:-28px;left:-16px">
<div class="box_paper bo pad10_0 nowrap small">$label_add</div>
</div>
</div>
<div class="fl hide block$threshold ">$ICON</div>
~;
} else {
$ICON = qq~<div class="fl rel hide$threshold"><a href="$link" $target_onclick class="button_green $class">$label</a>$label_add</div>
<div class="fl hide block$threshold ">$ICON</div>
~;
}
}
if ($switches =~ /i/) {
$ICON = qq~<div class="inline">$ICON</div>~;
}
}
return $ICON;
}
###############################################################################
# app icon
###############################################################################
sub icon {
#: Displays an app icon. Image URL and size need to be indicated, link and
#: name are optional.
my (
$self,
$ICON,
$SIZE,
$LINK,
$NAME,
) = @_;
my $APP;
$APP = qq~<img class="block$SIZE app$SIZE" src="$ICON" alt="app icon">~;
if ($LINK) {
$APP = qq~<a href="$LINK" class="col3">$APP</a>~;
}
if ($NAME) {
if ($LINK) {
$NAME = qq~<a href="$LINK" class="col3">$NAME</a>~;
}
$APP = qq~<div>
<div class="inline auto">$APP</div>
<div class="center mt5">$NAME</div>
</div>
~;
}
return $APP;
}
###############################################################################
# end of script
###############################################################################
1;
__END__