Re: One more Gnome2::Canvas question -- item->grab() $event_mask
- From: Mike Mayer <mikem circuitfarm com>
- To: gtk-perl-list gnome org
- Subject: Re: One more Gnome2::Canvas question -- item->grab() $event_mask
- Date: Mon, 02 Feb 2004 13:55:46 -0600
partly solved: I was using the gentoo ebuilds, which are older versions.
I installed gnome2-canvas 0.91 and glib 1.021 and it now accepts the
mask values.
However, when I ungrab an item the cursor and mask remain set to the
state the item->grab() put them in.
I'm trying to drag groups around a canvas. I'm following the examples as
closely as I can. Here is the event callback that I am using. Everything
works except that when I get the button-release event and ungrab, the
cursor stays a fleur and nothing can get a button-press event:
sub GroupEvent {
my $item = shift;
my $event = shift;
my $data = shift;
my ($x1, $y1, $x2, $y2) = $item->get_bounds();
my $type = $event->type();
my $itemY = $y1;
my $cursorY = $event->y();
print "Group event...type $type\n";
if (defined($layerRef{$item})) {
my $layer = $layerRef{$item};
my $layerName = $layer->getName();
my $layerType = $layer->getType();
}
if ($type eq "button-press") {
my $button = $event->button();
if ($button == 1) {
print("Button1 at $itemY\n");
$y = $cursorY;
$startY = $cursorY;
$item->grab([qw/pointer-motion-mask button-release-mask/],
Gtk2::Gdk::Cursor->new('fleur'),
$event->time());
$possibleDragging = 1;
$item->raise_to_top();
}
}
elsif ($type eq "2button-press") {
}
elsif ($type eq "button-release") {
print "startY: $startY, itemY: $itemY\n";
if ($dragging) {
my $layerLoc = round($itemY / $GRID_SPACING);
my $layerY = $layerLoc * $GRID_SPACING;
my $moveY = $layerY - $itemY;
print "dropped on layer $layerLoc ($layerY), moving
$moveY\n";
$item->move(0, $moveY);
$item->ungrab($event-time());
$dragging = 0;
}
else {
print "Clicked on group\n";
$possibleDragging = 0;
}
}
elsif ($type eq "motion-notify") {
if ($possibleDragging) {
if (abs($startY - $itemY) > $CLICK_MARGIN) {
$dragging = 1;
$possibleDragging = 0;
}
}
if ($dragging) {
my $newY = $cursorY;
# only move in y to keep column in alignment
$item->move(0, $newY - $y);
$y = $cursorY;
}
}
elsif ($type eq "enter-notify") {
}
elsif ($type eq "leave-notify") {
}
return FALSE;
}
--
=============================================================================
Mike Mayer Phone: (608) 523-1960
Circuitfarm, Inc. Cell: (608) 575-2732
mikem circuitfarm com
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]