sub items_done_drag {
my($c, $x, $y) = @_;
# $cardid is a tag that uniquely identifies the card I'm dragging
my $card = $Klondike->get_card_by_tag("current");
my $cardid = $card->Tk_truename;
# This is really just a bbox of the card
my ($x1, $y1) = $c->coords($cardid);
my $x2 = $x1 + $Klondike->card_width;
my $y2 = $y1 + $Klondike->card_height;
my @ids = $c->find("overlapping", $x1, $y1, $x2, $y2);
# each pile of cards has a "set:foo" tag
my @setids = grep {grep /^set:/, $c->gettags($_)} @ids;
return undef unless @setids;
warn "too many columns overlapping!\n" if @setids >1;
my $setid = $setids[0];
return $setid;
}
So the problem is, what happens if the card is overlapping with more than
one pile. If the piles are close toether (e.g. the columns in a solitaire
game) then very often when you drag to one pile, you'll be slightly
overlapping another. What's the best way to figure out which pile it's
"supposed" to be on top of?
While I'm at it, I find myself often using the find method, which gives me a
ton of answers, and I grep that array for other tags. Is there some kind of
superfind which will find objects with a number of tags?
-Amir Karger
-++**==--++**==--++**==--++**==--++**==--++**==--++**==
This message was posted through the Stanford campus mailing list
server. If you wish to unsubscribe from this mailing list, send the
message body of "unsubscribe ptk" to majo...@lists.stanford.edu
I was pondering this recently while playing pysol. I think you need to
assume an internal border (of some width, to taste) to each pile; if the
cursor is released within that boundary, it is definitely an attempt to
drop on that pile. If not, I think it is nice to check whether precisely
one of the overlapped piles is a legal target to drop the card, and if
so assume that is the target pile. If none are legal targets, you reject
the drop; if more than one are possible targets then either reject the
drop or pick the pile the cursor is closest to.
Treat the pile from which the card was originally dragged as a potential
target site just as any other - if the player changes her mind, the
obvious way to show it is by dropping the card back on its pile, and it
is frustrating if that always attempts to place the card elsewhere.
HTH,
Hugo
All excellent ideas. I'd also highlight which pile the card will "goto"
once you release it. So, as you drag a card, once *the cursor* is over a
legal drop site, highlight the drop site. If the card is dropped when it's
not over a drop site, warp it to its starting point as Hugo suggests.
bind buttonpress to:
$canvas->configure(-closeenough=>30); # or some other number bigger than one
bind buttonrelease to:
$canvas->configure(-closeenough=>1); #to reset it.
Just an idea.
Jack
PS. This saves you from searching through a list of canvas items to see if
you are close enough to a stack in order to be considered in/over the stack.
> -----Original Message-----
> From: Steve Lidie [mailto:so...@lehigh.edu]
> Sent: July 26, 2000 4:34 PM
> To: Hugo van der Sanden; Amir Karger; p...@lists.Stanford.EDU
> Subject: Re: More sophisticated overlapping
>
>
>
>
> Hugo van der Sanden wrote:
> >
> I think you need to
> > assume an internal border (of some width, to taste) to each
> pile;