Re: Motion events in a DrawingArea



On Thu, Aug 17, 2017 at 06:01:38PM +1000, Kevin Ryde via gtk-perl-list wrote:
Daniel Kasak <d j kasak dk gmail com> writes:

$self->{drawing_area}->set_events(

Gtk 2 is ->add_events() usually from INIT_INSTANCE to have extra events
selected when realized, if that's still so.

I also use add_events() rather than set_events() with Gtk3. A MWE showing a responsive DrawingArea is below.

Jeremy

--
All generalizations are false, including this one.
                -- Mark Twain

#!/usr/bin/perl

use strict;
use warnings;
use 5.012;

use Glib qw/TRUE FALSE/;
use Gtk3 qw/-init/;

my $da = Gtk3::DrawingArea->new();
#$da->signal_connect( 'draw'          => \&draw_canvas );
#$da->signal_connect( 'size-allocate' => \&resize      );

$da->add_events(0x004|0x100|0x200);
$da->signal_connect( 'motion-notify-event'  => \&_on_motion );
$da->signal_connect( 'button-release-event' => \&_on_click  );

my $mw = Gtk3::Window->new('toplevel');
$mw->set_size_request(100, 100);
$mw->signal_connect( destroy => sub { Gtk3->main_quit } );

$mw->add($da);
$mw->show_all;

Gtk3->main;


sub _on_motion {
   my ($da, $ev) = @_;
   say join ' ', 'MOTION at', $ev->x, $ev->y;
}

sub _on_click {
   my ($da, $ev) = @_;
   say join ' ', 'CLICK at', $ev->x, $ev->y;
}


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]