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