Thread Canvas find: closest und withtag (6 answers)
Opened by michael25 at 2005-09-07 02:12

renee
 2005-09-07 23:26
#44542 #44542
User since
2003-08-04
14371 Artikel
ModeratorIn
[Homepage] [default_avatar]
Das hier sollte funktionieren:

Code: (dl )
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
sub _findClosestWithTag{
my ($zinc,$x,$y,$tag) = @_;
my @ids_base = $zinc->find('withtag','*');
my @ids = map{$_->[-1]}
grep{$_->[0] =~ $tag}
map{[$zinc->itemcget($_,-tags),$_]}@ids_base;
my $close = $zinc->find('closest',$x,$y);
my %hash;
if($close && grep{$_ == $close}@ids){
$hash{0} = $close;
}
else{
for my $id(@ids){
my @coords = $zinc->bbox($id);
if($x > $coords[0] && $x < $coords[2]){
# maus in oder ueber oder unter widget
if($y > $coords[1] && $y < $coords[3]){
# maus in widget
$hash{0} = $id;
}
elsif($y < $coords[1]){
# maus ueber widget
$hash{abs($coords[1] - $y)} = $id;
}
elsif($y > $coords[3]){
# maus unter widget
$hash{abs($coords[1] - $y)} = $id;
}
}
elsif($x < $coords[0]){
# maus links von widget
if($y > $coords[1] && $y < $coords[3]){
# maus links neben widget
$hash{abs($coords[0] - $x)} = $id;
}
elsif($y < $coords[1]){
# maus links ueber widget
my $loc_distance = sqrt(((abs($x - $coords[0]))**2 + (abs($y - $coords[1]))**2));
$hash{$loc_distance} = $id;
}
elsif($y > $coords[3]){
# maus links unter widget
my $loc_distance = sqrt(((abs($x - $coords[0]))**2 + (abs($y - $coords[3]))**2));
$hash{$loc_distance} = $id;
}
}
elsif($x > $coords[2]){
# maus rechts von widget
if($y > $coords[1] && $y < $coords[3]){
# maus rechts neben widget
$hash{abs($coords[2] - $x)} = $id;
}
elsif($y < $coords[1]){
# maus rechts ueber widget
my $loc_distance = sqrt(((abs($x - $coords[2]))**2 + (abs($y - $coords[1]))**2));
$hash{$loc_distance} = $id;
}
elsif($y > $coords[3]){
# maus rechts unter widget
my $loc_distance = sqrt(((abs($x - $coords[2]))**2 + (abs($y - $coords[3]))**2));
$hash{$loc_distance} = $id;
}
}
}
}
my ($min) = sort{$a <=> $b}keys(%hash) if(keys(%hash) > 0);
return $min && $hash{$min} ? $hash{$min} : '';
}# _findClosestWidget


Aufruf erfolgt über _findClosestWithTag($canvas,$x,$y,$gewuenschterTag)...
OTRS-Erweiterungen (http://feature-addons.de/)
Frankfurt Perlmongers (http://frankfurt.pm/)
--

Unterlagen OTRS-Workshop 2012: http://otrs.perl-services.de/workshop.html
Perl-Entwicklung: http://perl-services.de/

View full thread Canvas find: closest und withtag