Re: GtkFixed doesn't receive button_release_event ?!
| From: | Christophe VG | Date: | Fri, 28 Sep 2001 12:40:57 +0000 |
| Subject: | Re: GtkFixed doesn't receive button_release_event ?! | ||
| References: | 1 2 | Groups: | php.gtk.general |
| Request: | Send a blank email to php-gtk-general+get-165@lists.php.net to get a copy of this message | ||
Thanks, ... it confirms the stuff I found in the test/scribble.php
example a few minutes ago (which after reading your mail entirely you
mention also :) ).
My resulting code reflects the info you gave me and for my problem I
didn't even needed button_press or button_release events ... Working
with the motion_notify_event was enough ...
The goal was to be able to move object around on a fixed layout, and
eventually, these objects had to be fixed grids themselves to be able to
add other objects to them.
Again thanks, and this is maybe yet another code snippet someone else
can use.
C
<?
dl( 'php_gtk.' . (strstr(PHP_OS, 'WIN') ? 'dll' : 'so'));
$window = &new GtkWindow;
$window->set_default_size( 200, 200 );
$fixed = &new GtkFixed;
$window->add( $fixed );
$xx = 50;
$yy = 50;
$moving = false;
// button
$button = &new GtkButton( 'Move me' );
$fixed->put( $button, $xx, $yy );
// two step motion detection
$button->connect( 'motion_notify_event', 'on_motion_notify' );
$button->set_events( GDK_POINTER_MOTION_MASK );
$hx = 0;
$hy = 0;
function on_motion_notify( $widget, $event ) {
global $button;
global $fixed;
global $xx, $yy;
global $moving;
global $hx, $hy;
// new mouse position ...
$x = (int)$event->x;
$y = (int)$event->y;
$state = $event->state;
if( $state & GDK_BUTTON1_MASK ) {
if( !$moving ) {
$hx = $x; // keep mouse position inside the button
$hy = $y; // so that the mouse pointer stays on initial click
$moving = true;
}
$xx += $x - $hx; // new position on fixed layout += moved distance
$yy += $y - $hy;
$fixed->move( $button, $xx, $yy );
} else {
// not pressed == not moving
$moving = false;
}
return true;
}
$window->show_all();
Gtk::main();
?>
On Fri, 2001-09-28 at 10:35, Markus Fischer wrote:
> On Fri, Sep 28, 2001 at 11:32:03AM +0000, Christophe VG wrote :
> > // fixed2
> > $fixed2 = &new GtkFixed;
> > $fixed->put( $fixed2, 0, 0 );
> >
> > $button = &new GtkButton( 'Nothing' );
> > $fixed2->put( $button, 25, 25 );
> >
> > $fixed2->connect( 'button_press_event', 'on_mouse_down' );
> > $fixed2->connect( 'button_release_event', 'on_mouse_up' );
>
> Why do you connect the signals to the GtkFixed widget and not to
> the $button ?
>
> > This builds a window with a fixed layout with a button and another fixed
> > layout also with a button (just to stretch the second fixed layout).
> > Both the first button and the second layout are connected to the same
> > signal handlers.
> >
> > Pressing and releasing the mouse button on the first button gives the
> > expected result. Doing the same in the area where we can access the
> > fixed layout only returns down events.
>
> GtkFixed widget (like e.g GtkLabel) does not receive such kind of
> events. If you want to catch them there you will have to use another
> widget, GtkEventBox (put the GtkFixed into the GtkEventBox first
> and connect the signals to the GtkEventBox). But I think you
> really want to connect your handlers directly to the button, no?
>
> > Anyhow, I hope someone can point me to a solution or a reason for this
> > behaviour.
> >
> > While you're at it, a fewe related things ...
> >
> > 1) is there a way to get the current mouse position ?
>
> Events like 'button_press_event' pass GdkEvent object to the
> callback handler. GdkEvent contains this information (just use
> var_dump($event); to find it)
>
> > 2) are the x,y coordinates passed to the signal handler of the
> > button_press and release ?
>
> Yes.
>
> > 3) is there a mouse_move event ? ...
>
> The signal in question is 'motion_notify_event'; again your
> callback gets an GdkEvent object with the information you need.
>
> You might want to take a look at the GTK+ Tutorial [1]; most of tis
> information can be reused for PHP-GTK. PHP-GTK also comes with a
> test application called scribble.php in the test/ directory.
>
> - Markus
>
> [1] http://www.gtk.org/tutorial/
>
> --
> Markus Fischer, http://guru.josefine.at/~mfischer/
> EMail: mfischer@guru.josefine.at
> PGP Public Key: http://guru.josefine.at/~mfischer/C2272BD0.asc
> PGP Fingerprint: D3B0 DD4F E12B F911 3CE1 C2B5 D674 B445 C227 2BD0
> -All your scripts are belong to Zend-