From: Tobias Leich Date: Fri, 13 Nov 2009 19:15:29 +0000 (+0100) Subject: articles X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=5697e3219c147941ec37b557b1852c61787146a2;p=sdlgit%2FSDL-Site.git articles --- diff --git a/pages/blog-0000.html-inc b/pages/blog-0000.html-inc index 8db63a9..f0a8ce6 100644 --- a/pages/blog-0000.html-inc +++ b/pages/blog-0000.html-inc @@ -1,6 +1,2 @@
-

-Once in a while .... (set_event_filter) -

-
-

Once in a while
Things just work!



So I have been hacking for a while on SDL::Events::set_event_filter. The code below is an example usage. The magic behind this is here

 1 #!/usr/bin/perl -w
2
use strict;
3 use warnings;
4 use SDL v2.3; #Require the redesign branch
5
use SDL::Video;
6 use SDL::Event;
7 use SDL::Events;
8
9 SDL::init(SDL_INIT_VIDEO);
10 my $display = SDL::Video::set_video_mode(640,480,32, SDL_SWSURFACE );
11 my $event = SDL::Event->new();
12
13 #This filters out all ActiveEvents
14
my $filter = sub {
15 my ($e, $type) = ($_[0], $_[0]->type);
16 if($type == SDL_ACTIVEEVENT){ return 0 }
17 elsif($type == SDL_MOUSEBUTTONDOWN && $e->button_button == 1){ return 0 }
18 else { return 1; }
19 };
20
21 SDL::Events::set_event_filter($filter);
22
23 while(1)
24 {
25
26 SDL::Events::pump_events();
27 if(SDL::Events::poll_event($event))
28 {
29
30 if( $event->type == SDL_ACTIVEEVENT)
31 {
32 print "Hello Mouse!!!\n" if ($event->active_gain && ($event->active_state == SDL_APPMOUSEFOCUS) );
33 print "Bye Mouse!!!\n" if (!$event->active_gain && ($event->active_state == SDL_APPMOUSEFOCUS) );
34 }
35 if( $event->type == SDL_MOUSEBUTTONDOWN)
36 {
37 my ($x, $y, $but ) = ($event->button_x, $event->button_y, $event->button_button);
38 warn "$but CLICK!!! at $x and $y \n";
39 }
40
41 last if($event->type == SDL_QUIT);
42 }
43 }
44 SDL::quit()
 
 
Tinker with $filter and look at perldoc lib/SDL/pods/Event.pod. 
 
Have fun,
--yapgh
\ No newline at end of file +Once in a while .... (set_event_filter)

Hello Mouse? An Example of the New Event Code

Development Update

Development Update

The Future and Beyond!

The beginnings of modular design for SDL Perl

Why and How Frozen Bubble is going to CPAN

HackFest: Results

Updates, Falling Block Game, and Hack Fest

Thanks nothingmuch, and updates

Design of SDL::Rect

Updates and Design Decisions

Why I will be sticking to CPAN

Frozen Bubble coming to CPAN

Newbie Friendly Perl Projects

Can someone please point me to good XS documentation!

More Games + Update

Updates on Plan for v2.4

Code is not the only thing

SDL Perl v2.2.2 out and Plans for v2.4

Catching memory leaks in XS

Alien::SDL 0.01 released!!!

SDL perl is coming to Strawberry!!

My milestones (itches) for gaming in Perl

SDL Perl Windows Status