Ah, thanks! Now it works fine. Here is the code, maybe someone knows a better or more efficient way to do it:
[code] #!perl use strict; use warnings; use SDL; use SDLx::App; use SDL::Event; # for the event object itself use SDL::Events; # functions for event queue handling my $app = SDLx::App->new( title => 'text wrap', exit_on_quit => 1, init => SDL_INIT_VIDEO ); $app->add_show_handler( \&render ); $app->add_event_handler( \&handle_events ); $app->run(); exit(0); sub handle_events { my $event = shift; my $controller = shift; my ($mask, undef, undef) = @{ SDL::Events::get_mouse_state( ) }; if( $event->type == SDL_MOUSEMOTION && !($mask & SDL_BUTTON_LMASK) ) { print "mousemotion and no left key pressed\n"; }elsif( $event->type == SDL_MOUSEMOTION && ($mask & SDL_BUTTON_LMASK) ) { print "mousemotion with left key pressed\n"; } return; } # /handle_events sub render { my ($delta, $app) = @_; $app->update(); return; } # /render [/code] -----Ursprüngliche Nachricht----- Von: Tobias Leich [mailto:em...@froggs.de] Gesendet: Dienstag, 31. Januar 2012 09:13 An: Alex Cc: sdl-devel@perl.org Betreff: Re: SDL::Event - invalid button_state on SDL_MOUSEMOTION ? Documentation tells that you have to use ->motion_state instead of ->button_state. See: http://sdl.perl.org/SDL-Event.html#Mouse_motion_events -- Cheers, Tobias Am 30.01.2012 23:23, schrieb Alex: > Dear all! > > I'm still working on this kind of button-like widget and I want to > implement the behaviour when hovering over the button. > Unfortunately, the button_state does not work as I expected (maybe I > expected it wrong). > > When I click somewhere, continue to hold down the mouse button (so > there is no SDL_MOUSEBUTTONUP event) and move the mouse, shouldn't > $event->button_state return SDL_PRESSED (which is 1)? > Because, using the script attached, I always get SDL_RELEASED (0). > The single case where I get SDL_PRESSED is when I check it on > SDL_MOUSEBUTTONDOWN. > > So, is this behaviour intended? > Or, to ask it in another way: do I have to keep track of the > SDL_MOUSEBUTTONUP event myself in order to determine if the user still > holds down the mouse button? > > Kind regards, > Alex > > #!perl > > use strict; > use warnings; > use SDL; > use SDLx::App; > use SDL::Event; # for the event object itself use SDL::Events; # > functions for event queue handling > > my $app = SDLx::App->new( > title => 'text wrap', > exit_on_quit => 1, > init => SDL_INIT_VIDEO > ); > > $app->add_show_handler( \&render ); > $app->add_event_handler( \&handle_events ); > > $app->run(); > > exit(0); > > sub handle_events { > my $event = shift; > my $controller = shift; > > if( $event->type == SDL_MOUSEMOTION ) { > printf "Button state: [%s]\n",$event->button_state; > } > > return; > } > > > sub render { > my ($delta, $app) = @_; > > $app->update(); > return; > } # /render > ----- eMail ist virenfrei. Von AVG überprüft - www.avg.de Version: 2012.0.1901 / Virendatenbank: 2109/4776 - Ausgabedatum: 30.01.2012