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.
51 lines
1.4 KiB
51 lines
1.4 KiB
1 year ago
|
package HexGrid::Pin;
|
||
|
|
||
|
use Moo;
|
||
|
use MooX::Aliases;
|
||
|
|
||
|
use feature "signatures";
|
||
|
no warnings "experimental::signatures";
|
||
|
|
||
|
has name => (is => 'rw');
|
||
|
has id => (is => 'ro', required => 1);
|
||
|
has icon => (is => 'rw', alias => [qw(img source src)], required => 1);
|
||
|
has link => (is => 'rw', alias => 'href');
|
||
|
has description => (is => 'rw', alias => 'desc');
|
||
|
|
||
|
has popup_class => (is => 'rw', default => 'pin-popup');
|
||
|
|
||
|
sub render($this, $pin_container, $x, $y, $w, $h, $laters = undef)
|
||
|
{
|
||
|
my $element = $pin_container->image(href => $this->{icon},
|
||
|
x => $x, y => $y, width => $w, height => $h);
|
||
|
$element->{id} = "$this->{id}-img";
|
||
|
$element->{onclick} = "clickPin('$this->{id}', '$pin_container->{id}');";
|
||
|
my $center_x = $x + $w/2;
|
||
|
my $center_y = $y + $h/2;
|
||
|
|
||
|
if(defined $laters)
|
||
|
{
|
||
|
push @$laters, sub ($popup_container) { $this->render_popup($popup_container,
|
||
|
$pin_container->{transform}, $center_x, $center_y); };
|
||
|
}
|
||
|
return $element;
|
||
|
}
|
||
|
|
||
|
sub render_popup($this, $popup_container, $transform, $x_shift, $y_shift)
|
||
|
{
|
||
|
my $popup_scaler = $popup_container->
|
||
|
g(id => "$this->{id}-popup",transform => $transform, class => $this->{popup_class})->
|
||
|
svg(id => "$this->{id}-scaler");
|
||
|
my $popup = new HexGrid::PopUp
|
||
|
(
|
||
|
name => $this->{name},
|
||
|
description => $this->{description},
|
||
|
link => $this->{link}
|
||
|
);
|
||
|
my $popup_element = $popup->render($popup_scaler);
|
||
|
$popup_element->{x} = $x_shift - $popup->{origin_x};
|
||
|
$popup_element->{y} = $y_shift - $popup_element->{height};
|
||
|
}
|
||
|
|
||
|
1;
|