blib/lib/Gtk2/Ex/MindMapView/HotSpot/Grip/Lentil.pm untested

filter: Statementstmt 0.0% 0 / 59 Branchbran 0.0% 0 / 2 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 0.0% 0 / 11 Podpod 0.0% 0 / 4 totaltotal 0.0% 0 / 76 CC 2 SCAR 9.8
CC
2
Cov
0%
_get_path_def
6.0
new
2.0
hotspot_adjust_event_handler
2.0
CRAP 2.7
1 package Gtk2::Ex::MindMapView::HotSpot::Grip::Lentil;
2  
3 our $VERSION = '0.000001';
4  
5 use warnings;
6 use strict;
7 use Carp;
8  
9 use Gtk2::Ex::MindMapView::ArgUtils;
10  
11 use Glib ':constants';
12  
13 use Gnome2::Canvas;
14  
15 use base 'Gtk2::Ex::MindMapView::HotSpot::Grip';
16  
17 sub new
18 {
19 my ($class, @attributes) = @_;
20  
21 my $self = $class->SUPER::new(@attributes);
22  
23 my %attributes = @attributes;
24  
25 args_valid(\%attributes, qw(item side enabled radius
26 fill_color_gdk outline_color_gdk hotspot_color_gdk));
27  
28 arg_default($self, 'radius', 10);
29  
30 arg_default($self, 'enabled', FALSE);
31  
32 arg_default($self, 'fill_color_gdk', Gtk2::Gdk::Color->parse('white'));
33  
34 arg_default($self, 'outline_color_gdk', Gtk2::Gdk::Color->parse('gray'));
35  
36 arg_default($self, 'hotspot_color_gdk', Gtk2::Gdk::Color->parse('orange'));
37  
38 $self->{image} = $self->hotspot_get_image();
39  
40 return $self;
41 }
42  
43  
44 # $self->hotspot_adjust_event_handler($item);
45  
46 sub hotspot_adjust_event_handler
47 {
48 my ($self, $item) = @_;
49  
50 # FIXME: Item is not defined...
51  
52 $self->{image}->set_path_def(_get_path_def($self));
53  
54 $self->{image}->request_update();
55 }
56  
57  
58 # my $image = $self->hotspot_get_image();
59  
60 sub hotspot_get_image
61 {
62 my $self = shift(@_);
63  
64 my $image = Gnome2::Canvas::Item->new($self->{item}, 'Gnome2::Canvas::Shape',
65 fill_color_gdk=>$self->{fill_color_gdk},
66 outline_color_gdk=>$self->{outline_color_gdk});
67  
68 $image->set_path_def(_get_path_def($self));
69  
70 return $image;
71 }
72  
73  
74 sub _get_path_def
75 {
76 my $self = shift(@_);
77  
78 my $o = 1;
79  
80 my $offset = 1;
81  
82 my $r = $self->{radius};
83  
84 # my ($top, $left, $bottom, $right) = $self->{item}->get_insets();
85  
86 my @p = ();
87  
88 if ($self->{side} eq 'left')
89 {
90 my $x = $self->{item}->get('x') + $offset;
91  
92 my $y = $self->{item}->get('y') + $self->{item}->get('height') - $offset;
93  
94 @p = ($x+$r-$o,$y-$o, $x+($r/2),$y, $x,$y-($r/2), $x+$o,$y-$r+$o, $x+($r/2),$y-$r, $x+$r,$y-($r/2));
95 }
96 else # $self->{side} eq 'right'
97 {
98 my $x = $self->{item}->get('x') + $self->{item}->get('width') - $offset;
99  
100 my $y = $self->{item}->get('y') + $self->{item}->get('height') - $offset;
101  
102 @p = ($x-$o,$y-$r+$o, $x,$y-($r/2), $x-($r/2),$y, $x-$r+$o,$y-$o, $x-$r,$y-($r/2), $x-($r/2),$y-$r);
103 }
104  
105 my $pathdef = Gnome2::Canvas::PathDef->new();
106  
107 $pathdef->moveto ($p[0], $p[1]);
108  
109 $pathdef->curveto ($p[2], $p[3], $p[4], $p[5], $p[6], $p[7]);
110  
111 $pathdef->curveto ($p[8], $p[9], $p[10], $p[11], $p[0], $p[1]);
112  
113 $pathdef->closepath_current;
114  
115 return $pathdef;
116 }
117  
118  
119  
120 1; # Magic true value required at end of module
121 __END__