X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=pages%2Fblog-0014.html-inc;fp=pages%2Fblog-0014.html-inc;h=e65be37dd7211e92b433042690e9c72fb1ba4899;hb=56d4907c407e8564b4a8a9d09e252573131fad3e;hp=f5d4032823b6c03d8dddcead7217e725791e5374;hpb=a8a21960f071bf93e73815cd9fe25b96d5c98cd0;p=sdlgit%2FSDL-Site.git diff --git a/pages/blog-0014.html-inc b/pages/blog-0014.html-inc index f5d4032..e65be37 100644 --- a/pages/blog-0014.html-inc +++ b/pages/blog-0014.html-inc @@ -1,26 +1,36 @@

-The beginnings of modular design for SDL Perl +Hello Mouse? An Example of the New Event Code

-
“Do or do not... there is no try.”
-
--yoda
+
Any code that is not marketed is dead code
+--mst

+

+You need the new code from the redesign branch to use this .

-

The design before


-The bindings before were all in one huge XS file. This was then exported into the SDL module. This means that the XS file has to handle with macros if any component (e.x SDL_Mixer) is not compiled. Moreover having ever binding in one XS file prevents use to treat C structs as object with only one point of free and malloc. This would be BEGIN and DESTROY in Perl. Also the monolithic design introduces a lot of bugs because we have to use free and malloc all over the place. Lastly SDL monolithic design has the constructor for all structs in both Perl and in XS.
-
-

The design we are aiming for

Simple one XS per Module. This would also simplify the Build code.
-
-

First Step


-We have began with SDL Rect. It is in github master branch now. We are in the progress of making it back compatible. Originally SDL::Rect took named variables as parameters for new(). Now since the constructor is in XS we have only unnamed parameters.
-
-
-

Before


-SDL::Rect->new( -x => 0, -y => 0, -width => 0, -height => 0);
-
-

After


-SDL::Rect->new(0, 0, 0, 0);
-
-Ideally we would like both ways of constructing Rect. -


-

\ No newline at end of file +
#!/usr/bin/env perl
+
+use SDL;
+use SDL::Events;
+use SDL::Event;
+use SDL::Video; 
+
+SDL::init(SDL_INIT_VIDEO);
+
+my $display = SDL::Video::set_video_mode(640,480,32, SDL_SWSURFACE );
+my $event   = SDL::Event->new(); 
+
+while(1)
+{   
+ SDL::Events::pump_events();  
+
+ if(SDL::Events::poll_event($event) && $event->type == SDL_ACTIVEEVENT)
+ {
+  print "Hello Mouse!!!\n" if ($event->active_gain  && ($event->active_state == SDL_APPMOUSEFOCUS) );
+  print "Bye Mouse!!!\n"   if (!$event->active_gain && ($event->active_state == SDL_APPMOUSEFOCUS) );
+ }   
+ 
+ exit if($event->type == SDL_QUIT);
+}
+


+

\ No newline at end of file