File Coverage

lib/App/Asciio/stripes/wirl_arrow.pm
Criterion Covered Total %
statement 183 247 74.0
branch 32 60 53.3
condition 13 45 28.8
subroutine 31 38 81.5
pod 0 27 0.0
total 259 417 62.1


line stmt bran cond sub pod time code
1              
2             package App::Asciio::stripes::wirl_arrow ;
3              
4 2     2   18 use base App::Asciio::stripes::stripes ;
  2         4  
  2         236  
5              
6 2     2   17 use strict;
  2         4  
  2         55  
7 2     2   9 use warnings;
  2         4  
  2         114  
8              
9 2     2   12 use List::Util qw(min max) ;
  2         20  
  2         198  
10 2     2   14 use Readonly ;
  2         4  
  2         124  
11 2     2   32 use Clone ;
  2         5  
  2         1490  
12              
13             #-----------------------------------------------------------------------------
14              
15             Readonly my $DEFAULT_ARROW_TYPE =>
16             [
17             #name: $start, $body, $connection, $body_2, $end
18            
19             ['origin', '', '*', '', '', '', 1],
20             ['up', '|', '|', '', '', '^', 1],
21             ['down', '|', '|', '', '', 'v', 1],
22             ['left', '-', '-', '', '', '<', 1],
23             ['up-left', '|', '|', '.', '-', '<', 1],
24             ['left-up', '-', '-', '\'', '|', '^', 1],
25             ['down-left', '|', '|', '\'', '-', '<', 1],
26             ['left-down', '-', '-', '.', '|', 'v', 1],
27             ['right', '-', '-', '', '', '>', 1],
28             ['up-right', '|', '|', '.', '-', '>', 1],
29             ['right-up', '-', '-', '\'', '|', '^', 1],
30             ['down-right', '|', '|', '\'', '-', '>', 1],
31             ['right-down', '-', '-', '.', '|', 'v', 1],
32             ['45', '/', '/', '', '', '^', 1],
33             ['135', '\\', '\\', '', '', 'v', 1],
34             ['225', ' /', '/', '', '', 'v', 1],
35             ['315', '\\', '\\', '', '', '^', 1],
36             ] ;
37              
38             sub new
39             {
40 192     192 0 394 my ($class, $element_definition) = @_ ;
41              
42 192         430 my $self = bless {}, __PACKAGE__ ;
43              
44             $self->setup
45             (
46             $element_definition->{ARROW_TYPE} || Clone::clone($DEFAULT_ARROW_TYPE),
47             $element_definition->{END_X}, $element_definition->{END_Y},
48             $element_definition->{DIRECTION},
49             $element_definition->{ALLOW_DIAGONAL_LINES},
50             $element_definition->{EDITABLE},
51 192   33     746 ) ;
52              
53 192         466 return $self ;
54             }
55              
56             #-----------------------------------------------------------------------------
57              
58             sub setup
59             {
60 192     192 0 434 my ($self, $arrow_type, $end_x, $end_y, $direction, $allow_diagonal_lines, $editable) = @_ ;
61              
62 192         271 my ($stripes, $width, $height) ;
63              
64 192         439 ($stripes, $width, $height, $direction) = get_arrow($arrow_type, $end_x, $end_y, $direction, $allow_diagonal_lines) ;
65              
66 192         786 $self->set
67             (
68             STRIPES => $stripes,
69             WIDTH => $width,
70             HEIGHT => $height,
71             DIRECTION => $direction,
72             ARROW_TYPE => $arrow_type,
73             END_X => $end_x,
74             END_Y => $end_y,
75             ALLOW_DIAGONAL_LINES => $allow_diagonal_lines,
76             ) ;
77             }
78              
79             #-----------------------------------------------------------------------------
80              
81             my %direction_to_arrow =
82             (
83             'origin' => \&draw_origin,
84             'up' => \&draw_up,
85             'down' => \&draw_down,
86             'left' => \&draw_left,
87             'up-left' => \&draw_upleft,
88             'left-up' => \&draw_leftup,
89             'down-left' => \&draw_downleft,
90             'left-down' => \&draw_leftdown,
91             'right' => \&draw_right,
92             'up-right' => \&draw_upright,
93             'right-up' => \&draw_rightup,
94             'down-right' => \&draw_downright,
95             'right-down' => \&draw_rightdown,
96             ) ;
97              
98             sub get_arrow
99             {
100 192     192 0 385 my ($arrow_type, $end_x, $end_y, $direction, $allow_diagonal_lines) = @_ ;
101              
102 2     2   18 use constant CENTER => 1 ;
  2         4  
  2         217  
103 2     2   17 use constant LEFT => 0 ;
  2         4  
  2         123  
104 2     2   13 use constant RIGHT => 2 ;
  2         4  
  2         158  
105 2     2   21 use constant UP => 0 ;
  2         14  
  2         116  
106 2     2   11 use constant DOWN => 2 ;
  2         4  
  2         10802  
107              
108 192 100       1595 my @position_to_direction =
    100          
    100          
    100          
109             (
110             [$direction =~ /^up/ ? 'up-left' : 'left-up', 'left', $direction =~ /^down/ ? 'down-left' : 'left-down'] ,
111             ['up', 'origin', 'down'],
112             [$direction =~ /^up/ ? 'up-right' : 'right-up', 'right', $direction =~ /^down/ ? 'down-right' : 'right-down'],
113             ) ;
114              
115 192 100       721 $direction = $position_to_direction
    100          
    100          
    100          
116             [$end_x == 0 ? CENTER : $end_x < 0 ? LEFT : RIGHT]
117             [$end_y == 0 ? CENTER : $end_y < 0 ? UP : DOWN] ;
118              
119 192         621 return($direction_to_arrow{$direction}->($arrow_type, $end_x, $end_y, $allow_diagonal_lines), $direction) ;
120             }
121              
122             #-----------------------------------------------------------------------------
123              
124             sub draw_down
125             {
126 21     21 0 41 my ($arrow_type, $end_x, $end_y) = @_ ;
127              
128 21         44 my ($stripes, $width, $height) = ([], 1, $end_y + 1) ;
129 21         34 my ($start, $body, $connection, $body_2, $end) = @{$arrow_type->[2]}[1 .. 5] ;
  21         58  
130              
131 21 50       26 push @{$stripes},
  21         228  
132             {
133             'HEIGHT' => $height,
134             'TEXT' => $height == 2 ? "$start\n$end" : $start . "\n" . ("$body\n" x ($height -2)) . $end,
135             'WIDTH' => 1,
136             'X_OFFSET' => 0,
137             'Y_OFFSET' => 0,
138             } ;
139              
140 21         122 return($stripes, $width, $height) ;
141             }
142              
143             #-----------------------------------------------------------------------------
144              
145             sub draw_origin
146             {
147 0     0 0 0 my ($arrow_type, $end_x, $end_y) = @_ ;
148              
149 0         0 my ($stripes, $width, $height) = ([], 1, 1) ;
150 0         0 my ($start, $body, $connection, $body_2, $end) = @{$arrow_type->[0]}[1 .. 5] ;
  0         0  
151              
152 0         0 push @{$stripes},
  0         0  
153             {
154             'HEIGHT' => 1,
155             'TEXT' => $body,
156             'WIDTH' => 1,
157             'X_OFFSET' => 0,
158             'Y_OFFSET' => 0,
159             } ;
160              
161 0         0 return($stripes, $width, $height) ;
162             }
163              
164             #-----------------------------------------------------------------------------
165              
166             sub draw_up
167             {
168 21     21 0 50 my ($arrow_type, $end_x, $end_y) = @_ ;
169              
170 21         52 my ($stripes, $width, $height) = ([], 1, -$end_y + 1) ;
171 21         39 my ($start, $body, $connection, $body_2, $end) = @{$arrow_type->[1]}[1 .. 5] ;
  21         65  
172              
173 21 50       30 push @{$stripes},
  21         144  
174             {
175             'HEIGHT' => $height,
176             'TEXT' => $height == 2 ? "$end\n$start" : $end . "\n" . ("$body\n" x ($height -2)) . $start,
177             'WIDTH' => 1,
178             'X_OFFSET' => 0,
179             'Y_OFFSET' => $end_y,
180             } ;
181              
182 21         107 return($stripes, $width, $height) ;
183             }
184              
185             #-----------------------------------------------------------------------------
186              
187             sub draw_left
188             {
189 21     21 0 52 my ($arrow_type, $end_x, $end_y) = @_ ;
190              
191 21         65 my ($stripes, $width, $height) = ([], -$end_x + 1, 1) ;
192 21         45 my ($start, $body, $connection, $body_2, $end) = @{$arrow_type->[3]}[1 .. 5] ;
  21         72  
193              
194 21 50       35 push @{$stripes},
  21         199  
195             {
196             'HEIGHT' => 1,
197             'TEXT' => $width == 2 ? "$end$start" : $end . $body x ($width -2) . $start,
198             'WIDTH' => $width,
199             'X_OFFSET' => $end_x,
200             'Y_OFFSET' => 0,
201             } ;
202              
203 21         115 return($stripes, $width, $height) ;
204             }
205              
206             #-----------------------------------------------------------------------------
207              
208             sub draw_upleft # or 315
209             {
210 6     6 0 13 my ($arrow_type, $end_x, $end_y, $allow_diagonal_lines) = @_ ;
211              
212 6         19 my ($stripes, $width, $height) = ([], -$end_x + 1, -$end_y + 1) ;
213              
214 6 50 33     20 if($allow_diagonal_lines && $end_x == $end_y)
215             {
216 0         0 my ($start, $body, $connection, $body_2, $end) = @{$arrow_type->[16]}[1 .. 5] ;
  0         0  
217 0         0 push @{$stripes}, get_315_stripes($end_x, $start, $body, $end) ;
  0         0  
218             }
219             else
220             {
221 6         12 my ($start, $body, $connection, $body_2, $end) = @{$arrow_type->[4]}[1 .. 5] ;
  6         39  
222 6         11 push @{$stripes},
  6         68  
223             {
224             'HEIGHT' => $height ,
225             'TEXT' => "$connection\n" . "$body\n" x ($height - 2) . $start,
226             'WIDTH' => 1,
227             'X_OFFSET' => 0,
228             'Y_OFFSET' => $end_y,
229             },
230             {
231             'HEIGHT' => 1,
232             'TEXT' => $end . $body_2 x ($width - 2),
233             'WIDTH' => $width - 1,
234             'X_OFFSET' => $end_x,
235             'Y_OFFSET' => $end_y ,
236             } ;
237             }
238              
239 6         32 return($stripes, $width, $height) ;
240             }
241              
242             #-----------------------------------------------------------------------------
243              
244             sub draw_leftup # or 315
245             {
246 22     22 0 74 my ($arrow_type, $end_x, $end_y, $allow_diagonal_lines) = @_ ;
247              
248 22         67 my ($stripes, $width, $height) = ([], -$end_x + 1, -$end_y + 1) ;
249 22         42 my ($start, $body, $connection, $body_2, $end) = @{$arrow_type->[5]}[1 .. 5] ;
  22         81  
250              
251 22 100 66     94 if($allow_diagonal_lines && $end_x == $end_y)
252             {
253 16         31 my ($start, $body, $connection, $body_2, $end) = @{$arrow_type->[16]}[1 .. 5] ;
  16         52  
254 16         25 push @{$stripes}, get_315_stripes($end_x, $start, $body, $end) ;
  16         48  
255             }
256             else
257             {
258 6         7 push @{$stripes},
  6         64  
259             {
260             'HEIGHT' => 1 ,
261             'TEXT' => $connection . $body x ($width - 2) . $start,
262             'WIDTH' => $width,
263             'X_OFFSET' => $end_x,
264             'Y_OFFSET' => 0,
265             },
266             {
267             'HEIGHT' => $height - 1,
268             'TEXT' => "$end\n" . "$body_2\n" x ($height - 2),
269             'WIDTH' => 1,
270             'X_OFFSET' => $end_x,
271             'Y_OFFSET' => $end_y ,
272             } ;
273             }
274              
275 22         151 return($stripes, $width, $height) ;
276             }
277              
278             #-----------------------------------------------------------------------------
279              
280             sub get_315_stripes
281             {
282 16     16 0 39 my ($position, $start, $body, $end) = @_ ;
283              
284 16         30 my @stripes ;
285              
286 16         88 push @stripes,
287             {
288             'HEIGHT' => 1,
289             'TEXT' => $start,
290             'WIDTH' => 1,
291             'X_OFFSET' => 0,
292             'Y_OFFSET' => 0,
293             } ;
294            
295 16         53 for(my $xy = -$position - 1 ; $xy> 0 ; $xy--)
296             {
297 40         187 push @stripes,
298             {
299             'HEIGHT' => 1,
300             'TEXT' => $body,
301             'WIDTH' => 1,
302             'X_OFFSET' => -$xy,
303             'Y_OFFSET' => -$xy,
304             } ;
305             }
306              
307 16         108 push @stripes,
308             {
309             'HEIGHT' => 1,
310             'TEXT' => $end,
311             'WIDTH' => 1,
312             'X_OFFSET' => $position ,
313             'Y_OFFSET' => $position ,
314             } ;
315              
316 16         64 return(@stripes) ;
317             }
318              
319             #-----------------------------------------------------------------------------
320              
321             sub draw_downleft # or 225
322             {
323 5     5 0 12 my ($arrow_type, $end_x, $end_y, $allow_diagonal_lines) = @_ ;
324              
325 5         16 my ($stripes, $width, $height) = ([], -$end_x + 1, $end_y + 1) ;
326 5         9 my ($start, $body, $connection, $body_2, $end) = @{$arrow_type->[6]}[1 .. 5] ;
  5         16  
327              
328 5 50 33     17 if($allow_diagonal_lines && -$end_x == $end_y)
329             {
330 0         0 my ($start, $body, $connection, $body_2, $end) = @{$arrow_type->[15]}[1 .. 5] ;
  0         0  
331 0         0 push @{$stripes}, get_225_stripes($end_x, $start, $body, $end) ;
  0         0  
332             }
333             else
334             {
335 5         8 push @{$stripes},
  5         53  
336             {
337             'HEIGHT' => $height ,
338             'TEXT' => "$start\n" . "$body\n" x ($height - 2) . $connection,
339             'WIDTH' => 1,
340             'X_OFFSET' => 0,
341             'Y_OFFSET' => 0,
342             },
343             {
344             'HEIGHT' => 1,
345             'TEXT' => $end . $body_2 x ($width - 2),
346             'WIDTH' => $width - 1,
347             'X_OFFSET' => $end_x,
348             'Y_OFFSET' => $end_y ,
349             } ;
350             }
351              
352 5         25 return($stripes, $width, $height) ;
353             }
354              
355             #-----------------------------------------------------------------------------
356              
357             sub draw_leftdown # or 225
358             {
359 20     20 0 48 my ($arrow_type, $end_x, $end_y, $allow_diagonal_lines) = @_ ;
360              
361 20         63 my ($stripes, $width, $height) = ([], -$end_x + 1, $end_y + 1) ;
362 20         41 my ($start, $body, $connection, $body_2, $end) = @{$arrow_type->[7]}[1 .. 5] ;
  20         73  
363              
364 20 100 66     89 if($allow_diagonal_lines && -$end_x == $end_y)
365             {
366 16         33 my ($start, $body, $connection, $body_2, $end) = @{$arrow_type->[15]}[1 .. 5] ;
  16         47  
367 16         30 push @{$stripes}, get_225_stripes($end_x, $start, $body, $end) ;
  16         43  
368             }
369             else
370             {
371 4         6 push @{$stripes},
  4         65  
372             {
373             'HEIGHT' => 1 ,
374             'TEXT' => $connection . $body x ($width - 2) . $start,
375             'WIDTH' => $width,
376             'X_OFFSET' => $end_x,
377             'Y_OFFSET' => 0,
378             },
379             {
380             'HEIGHT' => $height - 1,
381             'TEXT' => "$body_2\n" x ($height - 2) . $end,
382             'WIDTH' => 1,
383             'X_OFFSET' => $end_x,
384             'Y_OFFSET' => 1 ,
385             } ;
386             }
387              
388 20         122 return($stripes, $width, $height) ;
389             }
390              
391             #-----------------------------------------------------------------------------
392              
393             sub get_225_stripes
394             {
395 16     16 0 39 my ($position, $start, $body, $end) = @_ ;
396              
397 16         28 my @stripes ;
398              
399 16         73 push @stripes,
400             {
401             'HEIGHT' => 1,
402             'TEXT' => $start,
403             'WIDTH' => 1,
404             'X_OFFSET' => 0,
405             'Y_OFFSET' => 0,
406             } ;
407              
408 16         91 for(my $xy = -$position - 1 ; $xy> 0 ; $xy--)
409             {
410 40         160 push @stripes,
411             {
412             'HEIGHT' => 1,
413             'TEXT' => $body,
414             'WIDTH' => 1,
415             'X_OFFSET' => -$xy,
416             'Y_OFFSET' => $xy,
417             } ;
418             }
419              
420 16         111 push @stripes,
421             {
422             'HEIGHT' => 1,
423             'TEXT' => $end,
424             'WIDTH' => 1,
425             'X_OFFSET' => $position ,
426             'Y_OFFSET' => -$position ,
427             } ;
428              
429 16         70 return(@stripes) ;
430             }
431              
432             #-----------------------------------------------------------------------------
433              
434             sub draw_right
435             {
436 20     20 0 39 my ($arrow_type, $end_x, $end_y) = @_ ;
437              
438 20         45 my ($stripes, $width, $height) = ([], $end_x + 1, 1) ;
439 20         31 my ($start, $body, $connection, $body_2, $end) = @{$arrow_type->[8]}[1 .. 5] ;
  20         57  
440              
441 20 50       26 push @{$stripes},
  20         187  
442             {
443             'HEIGHT' => 1,
444             'TEXT' => $width == 2 ? "$start$end" : $start . $body x ($width -2) . $end,
445             'WIDTH' => $width,
446             'X_OFFSET' => 0,
447             'Y_OFFSET' => 0,
448             } ;
449              
450 20         115 return($stripes, $width, $height) ;
451             }
452              
453             #-----------------------------------------------------------------------------
454              
455             sub draw_upright # or 45
456             {
457 6     6 0 14 my ($arrow_type, $end_x, $end_y, $allow_diagonal_lines) = @_ ;
458              
459 6         17 my ($stripes, $width, $height) = ([], $end_x + 1, -$end_y + 1) ;
460 6         10 my ($start, $body, $connection, $body_2, $end) = @{$arrow_type->[9]}[1 .. 5] ;
  6         18  
461              
462 6 50 33     20 if($allow_diagonal_lines && -$end_x == $end_y)
463             {
464 0         0 my ($start, $body, $connection, $body_2, $end) = @{$arrow_type->[13]}[1 .. 5] ;
  0         0  
465 0         0 push @{$stripes}, get_45_stripes($end_x, $start, $body, $end) ;
  0         0  
466             }
467             else
468             {
469 6         10 push @{$stripes},
  6         62  
470             {
471             'HEIGHT' => $height ,
472             'TEXT' => "$connection\n". "$body\n" x ($height -2) . $start,
473             'WIDTH' => 1,
474             'X_OFFSET' => 0,
475             'Y_OFFSET' => $end_y,
476             },
477             {
478             'HEIGHT' => 1,
479             'TEXT' => $body_2 x ($width -2) . $end,
480             'WIDTH' => $end_x,
481             'X_OFFSET' => 1,
482             'Y_OFFSET' => $end_y,
483             } ;
484             }
485              
486 6         29 return($stripes, $width, $height) ;
487             }
488              
489             #-----------------------------------------------------------------------------
490              
491             sub draw_rightup # or 45
492             {
493 22     22 0 54 my ($arrow_type, $end_x, $end_y, $allow_diagonal_lines) = @_ ;
494              
495 22         60 my ($stripes, $width, $height) = ([], $end_x + 1, -$end_y + 1) ;
496 22         52 my ($start, $body, $connection, $body_2, $end) = @{$arrow_type->[10]}[1 .. 5] ;
  22         106  
497              
498 22 100 66     93 if($allow_diagonal_lines && -$end_x == $end_y)
499             {
500 16         31 my ($start, $body, $connection, $body_2, $end) = @{$arrow_type->[13]}[1 .. 5] ;
  16         46  
501 16         27 push @{$stripes}, get_45_stripes($end_x, $start, $body, $end) ;
  16         48  
502             }
503             else
504             {
505 6         8 push @{$stripes},
  6         92  
506             {
507             'HEIGHT' => 1,
508             'TEXT' => $start . $body x ($width -2) . $connection,
509             'WIDTH' => $width,
510             'X_OFFSET' => 0,
511             'Y_OFFSET' => 0,
512             },
513             {
514             'HEIGHT' => $height - 1,
515             'TEXT' => "$end\n" . "$body_2\n" x ($height -2),
516             'WIDTH' => 1,
517             'X_OFFSET' => $end_x,
518             'Y_OFFSET' => $end_y,
519             } ;
520             }
521              
522 22         122 return($stripes, $width, $height) ;
523             }
524              
525             #-----------------------------------------------------------------------------
526              
527             sub get_45_stripes
528             {
529 16     16 0 40 my ($position, $start, $body, $end) = @_ ;
530              
531 16         31 my @stripes ;
532              
533 16         102 push @stripes,
534             {
535             'HEIGHT' => 1,
536             'TEXT' => $start,
537             'WIDTH' => 1,
538             'X_OFFSET' => 0,
539             'Y_OFFSET' => 0,
540             } ;
541              
542 16         54 for(my $xy = $position - 1 ; $xy > 0 ; $xy--)
543             {
544 40         168 push @stripes,
545             {
546             'HEIGHT' => 1,
547             'TEXT' => $body,
548             'WIDTH' => 1,
549             'X_OFFSET' => $xy,
550             'Y_OFFSET' => -$xy,
551             } ;
552             }
553              
554 16         62 push @stripes,
555             {
556             'HEIGHT' => 1,
557             'TEXT' => $end,
558             'WIDTH' => 1,
559             'X_OFFSET' => $position ,
560             'Y_OFFSET' => -$position ,
561             } ;
562              
563 16         84 return(@stripes) ;
564             }
565              
566             #-----------------------------------------------------------------------------
567              
568             sub draw_downright # or 135
569             {
570 5     5 0 11 my ($arrow_type, $end_x, $end_y, $allow_diagonal_lines) = @_ ;
571              
572 5         12 my ($stripes, $width, $height) = ([], $end_x + 1, $end_y + 1) ;
573 5         10 my ($start, $body, $connection, $body_2, $end) = @{$arrow_type->[11]}[1 .. 5] ;
  5         12  
574              
575 5 50 33     20 if($allow_diagonal_lines && $end_x == $end_y)
576             {
577 0         0 my ($start, $body, $connection, $body_2, $end) = @{$arrow_type->[14]}[1 .. 5] ;
  0         0  
578 0         0 push @{$stripes}, get_135_stripes($end_x, $start, $body, $end) ;
  0         0  
579             }
580             else
581             {
582 5         7 push @{$stripes},
  5         43  
583             {
584             'HEIGHT' => $height ,
585             'TEXT' => "$start\n" ."$body\n" x ($height -2) . $connection,
586             'WIDTH' => 1,
587             'X_OFFSET' => 0,
588             'Y_OFFSET' => 0,
589             },
590             {
591             'HEIGHT' => 1,
592             'TEXT' => $body_2 x ($width -2) . $end,
593             'WIDTH' => $width - 1,
594             'X_OFFSET' => 1,
595             'Y_OFFSET' => $end_y,
596             } ;
597             }
598              
599 5         22 return($stripes, $width, $height) ;
600             }
601              
602             #-----------------------------------------------------------------------------
603              
604             sub draw_rightdown # or 135
605             {
606 23     23 0 51 my ($arrow_type, $end_x, $end_y, $allow_diagonal_lines) = @_ ;
607              
608 23         63 my ($stripes, $width, $height) = ([], $end_x + 1, $end_y + 1) ;
609 23         48 my ($start, $body, $connection, $body_2, $end) = @{$arrow_type->[12]}[1 .. 5] ;
  23         90  
610              
611 23 100 66     131 if($allow_diagonal_lines && $end_x == $end_y)
612             {
613 16         36 my ($start, $body, $connection, $body_2, $end) = @{$arrow_type->[14]}[1 .. 5] ;
  16         49  
614 16         24 push @{$stripes}, get_135_stripes($end_x, $start, $body, $end) ;
  16         45  
615             }
616             else
617             {
618 7         8 push @{$stripes},
  7         58  
619             {
620             'HEIGHT' => 1,
621             'TEXT' => $start . $body x ($width -2) . $connection,
622             'WIDTH' => $width,
623             'X_OFFSET' => 0,
624             'Y_OFFSET' => 0,
625             },
626             {
627             'HEIGHT' => $height - 1 ,
628             'TEXT' => "$body_2\n" x ($height -2) . $end,
629             'WIDTH' => 1,
630             'X_OFFSET' => $end_x,
631             'Y_OFFSET' => 1,
632             } ;
633             }
634              
635 23         179 return($stripes, $width, $height) ;
636             }
637              
638             #-----------------------------------------------------------------------------
639              
640             sub get_135_stripes
641             {
642 16     16 0 33 my ($position, $start, $body, $end) = @_ ;
643              
644 16         29 my @stripes ;
645              
646 16         108 push @stripes,
647             {
648             'HEIGHT' => 1,
649             'TEXT' => $start,
650             'WIDTH' => 1,
651             'X_OFFSET' => 0 ,
652             'Y_OFFSET' => 0 ,
653             } ;
654              
655 16         61 for(my $xy = 1 ; $xy < $position ; $xy++)
656             {
657 40         196 push @stripes,
658             {
659             'HEIGHT' => 1,
660             'TEXT' => $body,
661             'WIDTH' => 1,
662             'X_OFFSET' => $xy,
663             'Y_OFFSET' => $xy,
664             } ;
665             }
666              
667 16         56 push @stripes,
668             {
669             'HEIGHT' => 1,
670             'TEXT' => $end,
671             'WIDTH' => 1,
672             'X_OFFSET' => $position,
673             'Y_OFFSET' => $position,
674             } ;
675              
676 16         66 return(@stripes) ;
677             }
678              
679             #-----------------------------------------------------------------------------
680              
681             sub get_selection_action
682             {
683 0     0 0 0 my ($self, $x, $y) = @_ ;
684              
685 0 0 0     0 if (
      0        
      0        
686             ($x == 0 && $y == 0)
687             || ($x == $self->{END_X} && $y == $self->{END_Y})
688             )
689             {
690 0         0 'resize' ;
691             }
692             else
693             {
694 0         0 'move' ;
695             }
696             }
697              
698             #-----------------------------------------------------------------------------
699              
700             sub get_connector_points
701             {
702 384     384 0 703 my ($self) = @_ ;
703              
704             return
705             (
706             {X => 0, Y => 0, NAME => 'start'},
707 384         1869 {X => $self->{END_X}, Y => $self->{END_Y}, NAME => 'end'},
708             ) ;
709             }
710             #-----------------------------------------------------------------------------
711              
712             sub get_named_connection
713             {
714 0     0 0   my ($self, $name) = @_ ;
715              
716 0 0         if($name eq 'start')
    0          
717             {
718 0           return( {X => 0, Y => 0, NAME => 'start', CHAR => 'X'} ) ;
719             }
720             elsif($name eq 'end')
721             {
722 0           return( {X => $self->{END_X}, Y => $self->{END_Y}, NAME => 'end', CHAR => 'Y'} ) ;
723             }
724             else
725             {
726 0           return ;
727             }
728             }
729              
730             #-----------------------------------------------------------------------------
731              
732             sub get_direction
733             {
734 0     0 0   my ($self) = @_ ;
735              
736 0           return $self->{DIRECTION} ;
737             }
738              
739             #-----------------------------------------------------------------------------
740              
741             sub move_connector
742             {
743 0     0 0   my ($self, $connector_name, $x_offset, $y_offset, $hint) = @_ ;
744              
745 0 0         if($connector_name eq 'start')
    0          
746             {
747 0           my ($x_offset, $y_offset, $width, $height, undef) =
748             $self->resize(0, 0, $x_offset, $y_offset, $hint) ;
749            
750             return
751             $x_offset, $y_offset, $width, $height,
752 0           {X => $self->{END_X}, Y => $self->{END_Y}, NAME => 'start'} ;
753             }
754             elsif($connector_name eq 'end')
755             {
756             my ($x_offset, $y_offset, $width, $height, undef) =
757 0           $self->resize(-1, -1, $self->{END_X} + $x_offset, $self->{END_Y} + $y_offset, $hint) ;
758            
759             return
760             $x_offset, $y_offset, $width, $height,
761 0           {X => $self->{END_X}, Y => $self->{END_Y}, NAME => 'end'} ;
762             }
763             else
764             {
765 0           die "unknown connector '$connector_name'!\n" ;
766             }
767             }
768              
769             #-----------------------------------------------------------------------------
770              
771             sub resize
772             {
773 0     0 0   my ($self, $reference_x, $reference_y, $new_x, $new_y, $hint, $connector_name) = @_ ;
774              
775 0           my $is_start ;
776              
777 0 0         if(defined $connector_name)
778             {
779 0 0         if($connector_name eq 'start')
780             {
781 0           $is_start++ ;
782             }
783             }
784             else
785             {
786 0 0 0       if($reference_x == 0 && $reference_y == 0)
787             {
788 0           $is_start++ ;
789             }
790             }
791              
792 0 0         if($is_start)
793             {
794 0           my $x_offset = $new_x ;
795 0           my $y_offset = $new_y ;
796            
797 0           my $new_end_x = $self->{END_X} - $x_offset ;
798 0           my $new_end_y = $self->{END_Y} - $y_offset ;
799            
800 0   0       $self->setup($self->{ARROW_TYPE}, $new_end_x, $new_end_y, $hint || $self->{DIRECTION},$self ->{ALLOW_DIAGONAL_LINES}, $self->{EDITABLE}) ;
801            
802 0           return($x_offset, $y_offset, $self->{WIDTH}, $self->{HEIGHT}, 'start') ;
803             }
804             else
805             {
806 0           my $new_end_x = $new_x ;
807 0           my $new_end_y = $new_y ;
808            
809 0   0       $self->setup($self->{ARROW_TYPE}, $new_end_x, $new_end_y, $hint || $self->{DIRECTION}, $self ->{ALLOW_DIAGONAL_LINES}, $self->{EDITABLE}) ;
810            
811 0           return(0, 0, $self->{WIDTH}, $self->{HEIGHT}, 'end') ;
812             }
813             }
814              
815             #-----------------------------------------------------------------------------
816              
817             sub edit
818             {
819 0     0 0   my ($self, $asciio) = @_ ;
820              
821 0 0         return unless $self->{EDITABLE} ;
822              
823 0           $self->display_arrow_edit_dialog() ;
824              
825             my ($stripes, $width, $height, $x_offset, $y_offset) =
826 0           $direction_to_arrow{$self->{DIRECTION}}->($self->{ARROW_TYPE}, $self->{END_X}, $self->{END_Y}) ;
827              
828 0           $self->set(STRIPES => $stripes,) ;
829             }
830              
831             #-----------------------------------------------------------------------------
832              
833             1 ;
834              
835              
836              
837              
838              
839              
840              
841              
842