You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
64 lines
1.7 KiB
64 lines
1.7 KiB
package HexGrid::Dynamic;
|
|
|
|
use v5.30;
|
|
|
|
use Carp;
|
|
use Data::Dumper;
|
|
|
|
use feature "signatures";
|
|
no warnings "experimental::signatures";
|
|
|
|
$HexGrid::Dynamic::click_pin = <<EOS;
|
|
function clickPin(pinId, containerId) {
|
|
let popup = document.getElementById(pinId + '-popup');
|
|
popup.style.visibility = popup.style.visibility == 'visible' ? 'hidden' : 'visible';
|
|
}
|
|
EOS
|
|
$HexGrid::Dynamic::click_region = <<EOS;
|
|
function clickRegion(regionName, x, y) {
|
|
// let popup = document.getElementById(pinId + '-popup');
|
|
// popup.style.visibility = popup.style.visibility == 'visible' ? 'hidden' : 'visible';
|
|
alert("" + x + "," + y);
|
|
}
|
|
EOS
|
|
$HexGrid::Dynamic::toggle_coords = <<EOS;
|
|
function toggleCoords(show) {
|
|
for (var elem of document.getElementsByClassName('coords')) {
|
|
elem.style.visibility = show ? 'visible' : 'hidden';
|
|
}
|
|
}
|
|
EOS
|
|
|
|
$HexGrid::Dynamic::coords_toggler = <<EOS;
|
|
<label for="show-coords-checkbox">Show coordinates</label>
|
|
<input type="checkbox" checked id="show-coords-checkbox" onclick="toggleCoords(event.srcElement.checked)" />
|
|
EOS
|
|
|
|
sub render_html($svg, $options = undef)
|
|
{
|
|
my $document = "<!DOCTYPE html>";
|
|
$document .= "\n<html>\n<body>";
|
|
|
|
if($options)
|
|
{
|
|
if (ref $options eq 'HASH')
|
|
{
|
|
$document .= "\n<script>\n";
|
|
$document .= $HexGrid::Dynamic::click_pin if $options->{pin_popups};
|
|
$document .= $HexGrid::Dynamic::click_region if $options->{region_popups};
|
|
$document .= $HexGrid::Dynamic::toggle_coords if $options->{toggle_coords};
|
|
$document .= "\n</script>\n";
|
|
$document .= $HexGrid::Dynamic::coords_toggler if $options->{toggle_coords};
|
|
}
|
|
else
|
|
{
|
|
carp("Options passed to HexGrid::Dynamic::render_html must be a hash ref");
|
|
return;
|
|
}
|
|
}
|
|
|
|
$document .= "\n" . $svg;
|
|
$document .= "\n</body>\n</html>";
|
|
return $document;
|
|
}
|
|
1;
|
|
|