SDL::GetError to SDL::geterror in lib/SDL/App.pm
[sdlgit/SDL_perl.git] / lib / SDL / App.pm
index b35d41e..542b79f 100644 (file)
@@ -38,12 +38,11 @@ use SDL::Event;
 use SDL::Surface;
 use SDL::Rect;
 
+our @ISA = qw(SDL::Surface);
 sub DESTROY {
 
 }
 
-our @ISA = qw(SDL::Surface);
-
 sub new {
        my $proto = shift;
        my $class = ref($proto) || $proto;
@@ -56,10 +55,16 @@ sub new {
                                -red_accum_size -ras -blue_accum_size -bas 
                                -green_accum_sizee -gas -alpha_accum_size -aas
                                -double_buffer -db -buffer_size -bs -stencil_size -st
-                               -asyncblit
+                               -asyncblit -init
                / ) if ($SDL::DEBUG);
 
-       SDL::Init(SDL::SDL_INIT_EVERYTHING());
+        # SDL_INIT_VIDEO() is 0, so check defined instead of truth.
+        my $init = defined $options{-init} ? $options{-init} :
+       SDL_INIT_EVERYTHING();
+       
+        SDL::init($init);
+
+       #SDL::Init(SDL::SDL_INIT_EVERYTHING());
        
        my $t = $options{-title}        || $options{-t}         || $0;
        my $it = $options{-icon_title}  || $options{-it}        || $t;
@@ -107,8 +112,8 @@ sub new {
                $SDL::App::USING_OPENGL = 0;
        }
 
-       my $self = \SDL::SetVideoMode($w,$h,$d,$f)
-               or croak SDL::GetError();
+       my $self = SDL::SetVideoMode($w,$h,$d,$f)
+               or croak SDL::geterror();
        
        if ($ic and -e $ic) {
           my $icon = new SDL::Surface -name => $ic;
@@ -152,7 +157,7 @@ sub ticks {
 }
 
 sub error {
-       return SDL::GetError();
+       return SDL::geterror();
 }
 
 sub warp ($$$) {
@@ -180,8 +185,7 @@ sub loop ($$) {
        my $event = new SDL::Event;
        while ( $event->wait() ) {
                if ( ref($$href{$event->type()}) eq "CODE" ) {
-                       &{$$href{$event->type()}}($event);
-                       $self->sync();
+                       &{$$href{$event->type()}}($event);                      
                }
        }
 }
@@ -191,7 +195,7 @@ sub sync ($) {
        if ($SDL::App::USING_OPENGL) {
                SDL::GLSwapBuffers()
        } else {
-               $self->flip();
+               SDL::Flip($self);
        }
 }
 
@@ -217,17 +221,35 @@ __END__;
 SDL::App - a SDL perl extension
 
 =head1 SYNOPSIS
-
-       my $app = new SDL::App (
-               -title => 'Application Title',
-               -width => 640, 
-               -height => 480,
-               -depth => 32 );
+               
+       use SDL;
+       use SDL::Event; 
+       use SDL::App; 
+        
+       my $app = new SDL::App ( 
+       -title => 'Application Title', 
+       -width => 640, 
+       -height => 480, 
+       -depth => 32 ); 
+
+This is the manual way of doing things 
+
+       my $event = new SDL::Event;             # create a new event 
+
+       $event->pump();
+       $event->poll();
+
+       while ($event->wait()) { 
+         my $type = $event->type();      # get event type 
+         print $type; 
+         exit if $type == SDL_QUIT; 
+         }
+An alternative to the manual Event processing is the L<SDL::App::loop> .
 
 =head1 DESCRIPTION
 
 L<SDL::App> controls the root window of the of your SDL based application.
-It extends the L<SDL_Surface> class, and provides an interface to the window
+It extends the L<SDL::Surface> class, and provides an interface to the window
 manager oriented functions.
 
 =head1 METHODS