App-Asciio
view release on metacpan or search on metacpan
lib/App/Asciio/Elements.pm view on Meta::CPAN
}
#-----------------------------------------------------------------------------
sub move_elements_to_front
{
my ($self, @elements) = @_ ;
my %elements_to_move = map {$_ => 1} @elements ;
my @new_element_list ;
for(@{$self->{ELEMENTS}})
{
push @new_element_list, $_ unless (exists $elements_to_move{$_}) ;
}
$self->{ELEMENTS} = [@new_element_list, @elements] ;
} ;
#----------------------------------------------------------------------------------------------
sub move_elements_to_back
{
my ($self, @elements) = @_ ;
my %elements_to_move = map {$_ => 1} @elements ;
my @new_element_list ;
for(@{$self->{ELEMENTS}})
{
push @new_element_list, $_ unless (exists $elements_to_move{$_}) ;
}
$self->{ELEMENTS} = [@elements, @new_element_list] ;
} ;
#-----------------------------------------------------------------------------
sub delete_elements
{
my($self, @elements) = @_ ;
my %elements_to_delete = map {$_, 1} @elements ;
for my $element (@{$self->{ELEMENTS}})
{
if(exists $elements_to_delete{$element})
{
$self->delete_connections_containing($element) ;
$element = undef ;
}
}
@{$self->{ELEMENTS}} = grep { defined $_} @{$self->{ELEMENTS}} ;
$self->{MODIFIED }++ ;
}
#-----------------------------------------------------------------------------
sub edit_element
{
my ($self, $selected_element) = @_ ;
$selected_element->edit($self) ;
# handle connections
if($self->is_connected($selected_element))
{
# disconnect current connections
$self->delete_connections_containing($selected_element) ;
}
#~ !!! TODO if not already connected to them (same connection)
$self->connect_elements($selected_element) ; # connect to new elements if any
for my $connection ($self->get_connected($selected_element))
{
# all connection where the selected element is the connectee
my ($new_connection) = # in characters relative to element origin
$selected_element->get_named_connection($connection->{CONNECTION}{NAME}) ;
if(defined $new_connection)
{
my ($x_offset, $y_offset, $width, $height, $new_connector) =
$connection->{CONNECTED}->move_connector
(
$connection->{CONNECTOR}{NAME},
$new_connection->{X} - $connection->{CONNECTION}{X},
$new_connection->{Y}- $connection->{CONNECTION}{Y}
) ;
$connection->{CONNECTED}{X} += $x_offset ;
$connection->{CONNECTED}{Y} += $y_offset;
# the connection point has also changed
$connection->{CONNECTOR} = $new_connector ;
$connection->{CONNECTION} = $new_connection ;
$connection->{FIXED}++ ;
#find the other connectors belonging to this connected
for my $other_connection (grep{ ! $_->{FIXED}} @{$self->{CONNECTIONS}})
{
# move them relatively to their previous position
if($connection->{CONNECTED} == $other_connection->{CONNECTED})
{
my ($new_connector) = # in characters relative to element origin
$other_connection->{CONNECTED}->get_named_connection($other_connection->{CONNECTOR}{NAME}) ;
$other_connection->{CONNECTOR} = $new_connector ;
$other_connection->{FIXED}++ ;
}
}
for my $connection (@{$self->{CONNECTIONS}})
{
delete $connection->{FIXED} ;
}
}
else
{
$self->delete_connections($connection) ;
( run in 0.887 second using v1.01-cache-2.11-cpan-8f98c5d2c55 )