blib/lib/App/Asciio/Actions/Arrow.pm untested

filter: Statementstmt 0.0% 0 / 109 Branchbran 0.0% 0 / 24 Conditioncond 0.0% 0 / 6 MC/DCmcdc 0.0% 0 / 3 Subroutinesub 0.0% 0 / 10 Podpod 0.0% 0 / 6 totaltotal 0.0% 0 / 158 CC 13 SCAR 25.6
CC
13
Cov
0%
interactive_change_arrow_direction
20.0
change_arrow_direction
20.0
flip_arrow_ends
20.0
CRAP 12.9
1  
2 package App::Asciio::Actions::Arrow ;
3  
4 use strict;
5 use warnings;
6  
7 #----------------------------------------------------------------------------------------------
8  
9 use List::Util qw(min max) ;
10  
11 use App::Asciio::Actions::Multiwirl ;
12  
13 #----------------------------------------------------------------------------------------------
14  
15 sub interactive_change_arrow_direction
16 {
17 my ($self) = @_ ;
18 my $changes_made = 0 ;
19  
20 for (grep {ref $_ eq 'App::Asciio::stripes::section_wirl_arrow'} $self->get_selected_elements(1))
21 {
22 $self->create_undo_snapshot() unless $changes_made++ ;
23 $_->change_last_section_direction() ;
24 }
25  
26 for (grep {ref $_ eq 'App::Asciio::stripes::angled_arrow'} $self->get_selected_elements(1))
27 {
28 $self->create_undo_snapshot() unless $changes_made++ ;
29 $_->change_direction() ;
30 }
31  
32 $self->update_display() if $changes_made ;
33 }
34  
35 #----------------------------------------------------------------------------------------------
36  
37 sub change_arrow_direction
38 {
39 my ($self) = @_ ;
40 my $changes_made = 0 ;
41  
42 for (grep {ref $_ eq 'App::Asciio::stripes::section_wirl_arrow'} $self->get_selected_elements(1))
43 {
44 $self->create_undo_snapshot() unless $changes_made++ ;
45 $_->change_section_direction($self->{MOUSE_X} - $_->{X}, $self->{MOUSE_Y} - $_->{Y}) ;
46 }
47  
48 for (grep {ref $_ eq 'App::Asciio::stripes::angled_arrow'} $self->get_selected_elements(1))
49 {
50 $self->create_undo_snapshot() unless $changes_made++ ;
51 $_->change_direction() ;
52 }
53  
54 $self->update_display() if $changes_made ;
55 }
56  
57 #----------------------------------------------------------------------------------------------
58  
59 sub flip_arrow_ends
60 {
61 my ($self) = @_ ;
62 my $changes_made = 0 ;
63  
64 my %reverse_direction =
65 (
66 'up', => 'down',
67 'right' => 'left',
68 'down' => 'up',
69 'left' => 'right'
70 ) ;
71  
72 for
73 (
74 grep
75 {
76 my @connectors = $_->get_connector_points() ;
77
78 ref $_ eq 'App::Asciio::stripes::section_wirl_arrow'
79 && $_->get_number_of_sections() == 1
80 && @connectors > 0 ;
81 } $self->get_selected_elements(1)
82 )
83 {
84 $self->create_undo_snapshot() unless $changes_made++ ;
85
86 my $new_direction = $_->get_section_direction(0) ;
87
88 if($new_direction =~ /(.*)-(.*)/)
89 {
90 my ($start_direction, $end_direction) = ($1, $2) ;
91 $new_direction = $reverse_direction{$end_direction} . '-' . $reverse_direction{$start_direction} ;
92 }
93 else
94 {
95 $new_direction = $reverse_direction{$new_direction} ;
96 }
97
98 my ($start_connector, $end_connector) = $_->get_connector_points() ;
99 my $arrow = new App::Asciio::stripes::section_wirl_arrow
100 ({
101 %{$_},
102 POINTS => [ [ - $end_connector->{X}, - $end_connector->{Y}, $new_direction, ] ],
103 DIRECTION => $new_direction,
104 }) ;
105
106 $self->add_element_at($arrow, $_->{X} + $end_connector->{X}, $_->{Y} + $end_connector->{Y}) ;
107 $self->delete_elements($_) ;
108 $self->select_elements(1, $arrow) ;
109 }
110  
111 $self->update_display() if $changes_made ;
112 }
113  
114 #----------------------------------------------------------------------------------------------
115  
116 sub move_arrow_start
117 {
118 my ($self, $direction) = @_ ;
119  
120 $self->create_undo_snapshot() ;
121  
122 for (grep {ref $_ eq 'App::Asciio::stripes::section_wirl_arrow'} $self->get_selected_elements(1))
123 {
124 $_->{X} += $direction->[0] ;
125 $_->{Y} += $direction->[1] ;
126
127 if($self->is_connected($_))
128 {
129 # disconnect current connections
130 $self->delete_connections_containing($_) ;
131 }
132
133 for my $section (1 .. $_->get_number_of_sections())
134 {
135 my $last_section = $section - 1 ;
136 $_->move_connector("endsection_$last_section", -$direction->[0], -$direction->[1]) ;
137 }
138
139 $self->connect_elements($_, @{$self->{ELEMENTS}}) ;
140 # $self->call_hook('CANONIZE_CONNECTIONS', $self->{CONNECTIONS}, $self->get_character_size()) ;
141 }
142  
143 for (grep {ref $_ eq 'App::Asciio::stripes::angled_arrow'} $self->get_selected_elements(1))
144 {
145 $_->{X} += $direction->[0] ;
146 $_->{Y} += $direction->[1] ;
147
148 $_->setup($_->{ARROW_TYPE}, $_->{END_X} - $direction->[0], $_->{END_Y} - $direction->[1], $_->{DIRECTION}, $_->{EDITABLE}) ;
149
150 $self->connect_elements($_, @{$self->{ELEMENTS}}) ;
151 $self->call_hook('CANONIZE_CONNECTIONS', $self->{CONNECTIONS}, $self->get_character_size()) ;
152 }
153  
154 $self->update_display() ;
155 }
156  
157 #----------------------------------------------------------------------------------------------
158  
159 sub move_arrow_end
160 {
161 my ($self, $direction) = @_ ;
162  
163 $self->create_undo_snapshot() ;
164  
165 for (grep {ref $_ eq 'App::Asciio::stripes::section_wirl_arrow'} $self->get_selected_elements(1))
166 {
167 if($self->is_connected($_))
168 {
169 # disconnect current connections
170 $self->delete_connections_containing($_) ;
171 }
172
173 my $last_section = $_->get_number_of_sections() - 1 ;
174 $_->move_connector("endsection_$last_section", $direction->[0], $direction->[1]) ;
175
176 $self->connect_elements($_, @{$self->{ELEMENTS}}) ;
177 # $self->call_hook('CANONIZE_CONNECTIONS', $self->{CONNECTIONS}, $self->get_character_size()) ;
178 }
179  
180 for (grep {ref $_ eq 'App::Asciio::stripes::angled_arrow'} $self->get_selected_elements(1))
181 {
182 $_->setup($_->{ARROW_TYPE}, $_->{END_X} + $direction->[0], $_->{END_Y} + $direction->[1], $_->{DIRECTION}, $_->{EDITABLE}) ;
183
184 $self->connect_elements($_) ;
185 $self->call_hook('CANONIZE_CONNECTIONS', $self->{CONNECTIONS}, $self->get_character_size()) ;
186 }
187  
188 $self->update_display() ;
189 }
190  
191 #----------------------------------------------------------------------------------------------
192  
193 sub interactive_to_mouse
194 {
195 my ($self, $event) = @_ ;
196  
197 App::Asciio::Actions::Mouse::mouse_motion($self, $event) ;
198  
199 my @selected_elements = $self->get_selected_elements(1) ;
200  
201 if(1 == @selected_elements)
202 {
203 for (grep {ref $_ eq 'App::Asciio::stripes::section_wirl_arrow'} @selected_elements)
204 {
205 App::Asciio::Actions::Multiwirl::move_last_section_to($self, $_, $self->{MOUSE_X}, $self->{MOUSE_Y}) ;
206 $self->update_display() ;
207 }
208
209 for (grep {ref $_ eq 'App::Asciio::stripes::angled_arrow'} @selected_elements)
210 {
211 $_->setup($_->{ARROW_TYPE}, $self->{MOUSE_X} - $_->{X}, $self->{MOUSE_Y} - $_->{Y}, $_->{DIRECTION}, $_->{EDITABLE}) ;
212
213 $self->connect_elements($_) ;
214 $self->call_hook('CANONIZE_CONNECTIONS', $self->{CONNECTIONS}, $self->get_character_size()) ;
215
216 $self->update_display() ;
217 }
218 }
219 }
220  
221 #----------------------------------------------------------------------------------------------
222  
223 1 ;
224