X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?p=sdlgit%2FSDL-Site.git;a=blobdiff_plain;f=pages%2Fblog-0024.html-inc;h=84a740ff4f425ede40b97567d59b2b37c0970fbf;hp=0de3c832cedb93b3d65e9876f3ff91874c42d50a;hb=a05e5d4499fb58198e463162d0385e8a156e1f03;hpb=e1ec9f6e00ef090d063bc417e9683d40fc49b26f diff --git a/pages/blog-0024.html-inc b/pages/blog-0024.html-inc index 0de3c83..84a740f 100644 --- a/pages/blog-0024.html-inc +++ b/pages/blog-0024.html-inc @@ -1,59 +1,35 @@

-Once in a while .... (set_event_filter) +Migrating Sol's Tutorial of SDL to SDL_Perl

-

-Once in a while
-Things just work!
-

+
If I have seen further it is only by standing on the shoulders of giants. --Newton

+

+

+

Sol's Tutorials


+

When I was struggling with SDL C a while ago, someone recommended Sol's Tutorial to me. It had not only help me understand video in SDL, but I believe my code has improved using Sol's code style. I would like to pass these along to fellow SDL_Perl users too. So here is the Ch 02 code of Sol's Tutorial in SDL_Perl. It will be getting more and more Perly as our team hacks on it. There is more to come!
+


+

To use this code you need the new Redesigned SDL_Perl Library


+

Getting SDL Dependencies


+Only If you are on Linux (debian/ubuntu) you need the following dependencies:
+
+
$ sudo apt-get install libsdl-net1.2-dev libsdl-mixer1.2-dev libsmpeg-dev libsdl1.2-dev libsdl-image1.2-dev libsdl-ttf2.0-dev 

+On Windows we recommend using Strawberry Perl. It comes with SDL-1.2.13 header files and libs included.
+
+Both Windows and Linux needs to install Alien::SDL
+
+
$ cpan Alien::SDL
** Add sudo to this for Linux
+
+

Getting Bleeding SDL


+The bleeding SDL is on github. Click download on this site .
+
+Extract it and cd into the folder run
+
$ cpan . 
** The dot is needed
+** in Linux you may need to do sudo

-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
+Then you can run this script by doing

-
 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 +
$ perl examples/sols/ch02.pl 
+


+

\ No newline at end of file