PageRenderTime 35ms CodeModel.GetById 28ms app.highlight 5ms RepoModel.GetById 1ms app.codeStats 0ms

/t_backcompat/core_event_filter.pl

http://github.com/PerlGameDev/SDL
Perl | 47 lines | 39 code | 6 blank | 2 comment | 17 complexity | a774a246d62dbc4aa911215e3ea52618 MD5 | raw file
 1#!/usr/bin/perl -w
 2use strict;
 3use warnings;
 4use lib '.';
 5use SDL;
 6use SDL::Event;
 7use SDL::Events;
 8use SDL::Video;
 9
10SDL::init(SDL_INIT_VIDEO);
11my $display = SDL::Video::set_video_mode( 640, 480, 32, SDL_SWSURFACE );
12my $event = SDL::Event->new();
13
14#This filters out all ActiveEvents
15my $filter = sub {
16	if   ( $_[0]->type == SDL_ACTIVEEVENT ) { return 0 }
17	else                                    { return 1; }
18};
19my $filtered = 1;
20
21SDL::Events::set_event_filter($filter);
22
23while (1) {
24
25	SDL::Events::pump_events();
26	if ( SDL::Events::poll_event($event) ) {
27		if ( $event->type == SDL_ACTIVEEVENT ) {
28			$filtered = 0; #we got a problem!
29			print "Hello Mouse!!!\n"
30				if ( $event->active_gain
31				&& ( $event->active_state == SDL_APPMOUSEFOCUS ) );
32			print "Bye Mouse!!!\n"
33				if ( !$event->active_gain
34				&& ( $event->active_state == SDL_APPMOUSEFOCUS ) );
35		}
36		if ( $event->type == SDL_MOUSEBUTTONDOWN ) {
37			my ( $x, $y, $but, $wh ) = (
38				$event->button_x,      $event->button_y,
39				$event->button_button, $event->button_which
40			);
41			warn "$but $wh  CLICK!!! at $x and $y \n";
42		}
43		exit if ( $event->type == SDL_QUIT );
44	}
45}
46SDL::quit();
47