X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=pages%2Fblog-0005.html-inc;h=706ea537074945bb91e1162b2494c72640b80ed3;hb=c8ad4fe9f211e727310a1ce6d23ffb1d7822d71f;hp=51a18a506ef1d304b1a7b3b2c674dde9b22b3783;hpb=d502f71f4cb7e6073e2629cdba69f20e7001b721;p=sdlgit%2FSDL-Site.git diff --git a/pages/blog-0005.html-inc b/pages/blog-0005.html-inc index 51a18a5..706ea53 100644 --- a/pages/blog-0005.html-inc +++ b/pages/blog-0005.html-inc @@ -1,6 +1,77 @@
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
use PDL; + use SDL::Rect; + use SDL::Video; + use SDL::Surface; + use SDL::PixelFormat; +
my ( $bytes_per_pixel, $width, $height ) = ( 4, 200, 400 ); +
my $piddle = zeros( byte, $bytes_per_pixel, $width, $height ); +
my $pointer = $piddle->get_dataref(); +
my $surface = SDL::Surface->new_from( $pointer, $width, $height, 32, + $width * $bytes_per_pixel ); +
warn "Made surface of $width, $height and ". $surface->format->BytesPerPixel; + return ( $piddle, $surface ); +
SDL::Video::lock_surface($surface); + + $piddle ( :, 0 : rand(400), 0 : rand(200) ) .= pdl( rand(225), rand(225), rand(255), 255 ); +
SDL::Video::unlock_surface($surface); +
my $b = SDL::Video::blit_surface( + $surface, SDL::Rect->new( 0, 0, $surface->w, $surface->h ), + $app, SDL::Rect->new( ( $app->w - $surface->w ) / 2, ( $app->h - $surface->h ) / 2, $app->w, $app->h ) + ); + + die "Could not blit: " . SDL::get_error() if ( $b == -1 ); +