line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Tk::GraphItems::Node; |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
|
4
|
|
|
|
|
|
|
# Copyright (C) 2007 by Christoph Lamprecht |
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
# This library is free software; you can redistribute it and/or modify |
7
|
|
|
|
|
|
|
# it under the same terms as Perl itself, either Perl version 5.8.7 or, |
8
|
|
|
|
|
|
|
# at your option, any later version of Perl 5 you may have available. |
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
|
12
|
4
|
|
|
4
|
|
156
|
use 5.008; |
|
4
|
|
|
|
|
13
|
|
|
4
|
|
|
|
|
221
|
|
13
|
|
|
|
|
|
|
our $VERSION = '0.11'; |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
#use Data::Dumper; |
16
|
4
|
|
|
4
|
|
21
|
use Carp; |
|
4
|
|
|
|
|
7
|
|
|
4
|
|
|
|
|
262
|
|
17
|
4
|
|
|
4
|
|
29
|
use warnings; |
|
4
|
|
|
|
|
6
|
|
|
4
|
|
|
|
|
116
|
|
18
|
4
|
|
|
4
|
|
22
|
use strict; |
|
4
|
|
|
|
|
6
|
|
|
4
|
|
|
|
|
153
|
|
19
|
4
|
|
|
4
|
|
36
|
use Scalar::Util (qw/looks_like_number/); |
|
4
|
|
|
|
|
8
|
|
|
4
|
|
|
|
|
4475
|
|
20
|
|
|
|
|
|
|
require Tk::GraphItems::GraphItem; |
21
|
|
|
|
|
|
|
require Tk::GraphItems::TiedCoord; |
22
|
|
|
|
|
|
|
our @ISA = qw/ Tk::GraphItems::GraphItem /; |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
{ |
26
|
|
|
|
|
|
|
my %iinfo = (-text=>1); # item information hash |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
sub _set_canvas_bindings_for_tag{ |
29
|
0
|
|
|
0
|
|
|
my ($self,$tag) = @_; |
30
|
0
|
|
|
|
|
|
my $can = $self->{canvas}; |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
$can->bind($tag,'<1>' => sub { |
33
|
0
|
|
|
0
|
|
|
my($can) = @_; |
34
|
0
|
|
|
|
|
|
my $e = $can->XEvent; |
35
|
0
|
|
|
|
|
|
_items_start_drag ($can, $e->x, $e->y, \%iinfo); |
36
|
|
|
|
|
|
|
} |
37
|
0
|
|
|
|
|
|
); |
38
|
|
|
|
|
|
|
$can->bind($tag,'' =>sub { |
39
|
0
|
|
|
0
|
|
|
_items_drag ($can, |
40
|
|
|
|
|
|
|
$Tk::event->x, |
41
|
|
|
|
|
|
|
$Tk::event->y, |
42
|
|
|
|
|
|
|
\%iinfo); |
43
|
|
|
|
|
|
|
} |
44
|
0
|
|
|
|
|
|
); |
45
|
|
|
|
|
|
|
} |
46
|
|
|
|
|
|
|
} #end scope of iinfo |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
sub _items_drag { |
49
|
0
|
|
|
0
|
|
|
my($can, $x, $y, $iinfo) = @_; |
50
|
|
|
|
|
|
|
|
51
|
0
|
|
|
|
|
|
my $id= ($can->find(withtag => 'current'))[0]; |
52
|
0
|
|
|
|
|
|
my $self = _get_inst_by_id($can,$id); |
53
|
0
|
|
|
|
|
|
my ($d_x,$d_y) = ($x-$iinfo->{lastX},$y-$iinfo->{lastY}); |
54
|
0
|
|
|
|
|
|
$self->_move($d_x ,$d_y); |
55
|
0
|
|
|
|
|
|
$self->{was_dragged}=1; |
56
|
|
|
|
|
|
|
|
57
|
0
|
|
|
|
|
|
$iinfo->{lastX} = $x; |
58
|
0
|
|
|
|
|
|
$iinfo->{lastY} = $y; |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
} # end items_drag |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
sub _items_start_drag { |
63
|
|
|
|
|
|
|
|
64
|
0
|
|
|
0
|
|
|
my($can, $x, $y, $iinfo) = @_; |
65
|
0
|
|
|
|
|
|
$iinfo->{lastX} = $x; |
66
|
0
|
|
|
|
|
|
$iinfo->{lastY} = $y; |
67
|
0
|
|
|
|
|
|
my $id= ($can->find(withtag => 'current'))[0]; |
68
|
0
|
|
|
|
|
|
my $self = _get_inst_by_id($can,$id); |
69
|
0
|
|
|
|
|
|
$self->{was_dragged}=0; |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
} # end items_start_drag |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
sub move{ |
76
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
77
|
|
|
|
|
|
|
looks_like_number($_)|| |
78
|
|
|
|
|
|
|
croak "method 'move' failed: args <$_[0]>,<$_[1]> have to be numbers!" |
79
|
0
|
|
0
|
|
|
|
for (@_[0,1]); |
80
|
0
|
|
|
|
|
|
$self->_move(@_); |
81
|
|
|
|
|
|
|
} |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
sub _move{ |
84
|
0
|
|
|
0
|
|
|
my ($self,$d_x,$d_y) = @_; |
85
|
0
|
|
|
|
|
|
my ($x,$y) = $self->get_coords; |
86
|
0
|
|
|
|
|
|
$self->_set_coords($x+$d_x,$y+$d_y); |
87
|
|
|
|
|
|
|
} |
88
|
|
|
|
|
|
|
sub set_coords{ |
89
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
90
|
0
|
0
|
0
|
|
|
|
if (ref $_[0]&& ref$_[1]) { |
91
|
0
|
|
|
|
|
|
$self->_tie_coords(@_); |
92
|
0
|
|
|
|
|
|
return; |
93
|
|
|
|
|
|
|
} |
94
|
0
|
|
|
|
|
|
for ( @_[0,1] ) { |
95
|
0
|
0
|
|
|
|
|
looks_like_number($_)|| |
96
|
|
|
|
|
|
|
croak "method 'set_coords' failed:\n" |
97
|
|
|
|
|
|
|
."args <$_[0]>,<$_[1]> have to be numbers!"; |
98
|
|
|
|
|
|
|
} |
99
|
0
|
|
|
|
|
|
$self->_set_coords(@_); |
100
|
|
|
|
|
|
|
} |
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
sub _tie_coords{ |
103
|
0
|
|
|
0
|
|
|
my $self = shift; |
104
|
0
|
|
|
|
|
|
$self ->_untie_coords; |
105
|
0
|
0
|
|
|
|
|
tie ${$_[0]}, 'Tk::GraphItems::TiedCoord',$self,0 if ref $_[0]; |
|
0
|
|
|
|
|
|
|
106
|
0
|
0
|
|
|
|
|
tie ${$_[1]}, 'Tk::GraphItems::TiedCoord',$self,1 if ref $_[1]; |
|
0
|
|
|
|
|
|
|
107
|
0
|
|
|
|
|
|
@$self{qw/tiedx tiedy/}= @_[0,1]; |
108
|
|
|
|
|
|
|
} |
109
|
|
|
|
|
|
|
sub _untie_coords{ |
110
|
0
|
|
|
0
|
|
|
my $self = shift; |
111
|
0
|
|
|
|
|
|
for (@$self{qw/tiedx tiedy/}) { |
112
|
0
|
|
|
|
|
|
untie ${$_} ; #if tied $$_ |
|
0
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
} |
114
|
|
|
|
|
|
|
} |
115
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
sub was_dragged{ |
117
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
118
|
0
|
|
0
|
|
|
|
return $self->{was_dragged} ||0; |
119
|
|
|
|
|
|
|
} |
120
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
sub _get_inst_by_id{ |
122
|
0
|
|
|
0
|
|
|
my ($can,$id) = @_; |
123
|
0
|
|
|
|
|
|
my $obj_map = $can->{GraphItemsMap}; |
124
|
0
|
|
0
|
|
|
|
return $obj_map->{$id}||undef; |
125
|
|
|
|
|
|
|
} |
126
|
|
|
|
|
|
|
|
127
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
|
130
|
|
|
|
|
|
|
1; |
131
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
__END__ |