PageRenderTime 19ms CodeModel.GetById 15ms app.highlight 1ms RepoModel.GetById 1ms app.codeStats 0ms

/lib/pods/SDLx/App.pod

http://github.com/PerlGameDev/SDL
Unknown | 192 lines | 119 code | 73 blank | 0 comment | 0 complexity | 56dc7c9938629955324bbe8f66abdb97 MD5 | raw file
  1
  2=pod
  3
  4=head1 NAME
  5
  6SDLx::App - a SDL perl extension
  7
  8=head1 CATEGORY
  9
 10Extension
 11
 12=head1 SYNOPSIS
 13
 14    use SDL;
 15    use SDLx::App; 
 16    use SDL::Event;
 17    use SDL::Events; 
 18    
 19    my $app = SDLx::App->new( 
 20        title  => 'Application Title',
 21        width  => 640,
 22        height => 480,
 23        depth  => 32
 24    ); 
 25
 26This is the manual way of doing things
 27
 28    my $event = SDL::Event->new; # create a new event 
 29    
 30    SDL::Events::pump_events();
 31       
 32    while ( SDL::Events::poll_event($event) ) { 
 33        my $type = $event->type(); # get event type 
 34        print $type; 
 35        exit if $type == SDL_QUIT; 
 36    }
 37
 38An alternative to the manual Event processing is through the L<SDLx::Controller> module. L<SDLx::App> is a Controller so see the CALLBACKS section below.
 39
 40=head1 DESCRIPTION
 41
 42L<SDLx::App> controls the root window of the of your SDL based application.
 43It extends the L<SDL::Surface> class, and provides an interface to the window
 44manager oriented functions.
 45
 46=head1 METHODS
 47
 48=head2 new
 49
 50C<SDLx::App::new> initializes the SDL, creates a new screen,
 51and initializes some of the window manager properties.
 52C<SDLx::App::new> takes a series of named parameters:
 53
 54=over 4
 55
 56=item * title
 57the window title. Defaults to the file name. Shorter alias: 't'
 58
 59=item * icon_title
 60the icon title. Defaults to file name. Shortcut: 'it'
 61
 62=item * icon
 63the icon itself. Defaults to none. Shortcut: 'i'
 64
 65=item * width
 66Window width, in pixels. Defaults to 800. Shortcut: 'w'
 67
 68=item * height
 69Window height, in pixels. Defaults to 600. Shortcut: 'h'
 70
 71=item * depth
 72Screen depth. Defaults to 16. Shortcut: 'd'.
 73
 74=item * flags
 75Any flags you want to pass to L<SDL::Video> upon initialization. Defaults to SDL_ANYFORMAT. Flags should be I<or'ed> together if you're passing more than one (flags => FOO|BAR). Shortcut: 'f'.
 76
 77=item * resizeable
 78Set this to a true value to make the window resizeable by the user. Default is off.
 79
 80=item * exit_on_quit
 81Set this to a true value to make the app exit if a SDL_QUIT event is triggered. Shortcut: 'eoq'.
 82
 83=back
 84
 85=head1 METHODS
 86
 87=head2 title()
 88
 89=head2 title( $new_title )
 90
 91=head2 title( $window_title, $icon_title )
 92
 93C<SDLx::App::title> takes 0, 1, or 2 arguments. If no parameter is given,
 94it returns the current application window title. If one parameter is
 95passed, both the window title and icon title will be set to its value.
 96If two parameters are passed the window title will be set to the first,
 97and the icon title to the second.
 98
 99=head2 delay( $ms )
100
101C<SDLx::App::delay> takes 1 argument, and will sleep the application for
102that many ms.
103
104=head2 ticks
105
106C<SDLx::App::ticks> returns the number of ms since the application began.
107
108=head2 error
109
110C<SDLx::App::error> returns the last error message set by the SDL.
111
112=head2 resize( $width, $height )
113
114C<SDLx::App::resize> takes a new width and height of the application. Only
115works if the application was originally created with the resizable option.
116
117=head2 fullscreen
118
119C<SDLx::App::fullscreen> toggles the application in and out of fullscreen mode.
120
121=head2 iconify
122
123C<SDLx::App::iconify> iconifies the application window.
124
125=head2 grab_input( $CONSTANT )
126
127C<SDLx::App::grab_input> can be used to change the input focus behavior of
128the application. It takes one argument, which should be one of the following:
129
130=over 4
131
132=item * SDL_GRAB_QUERY
133
134=item * SDL_GRAB_ON
135
136=item * SDL_GRAB_OFF
137
138=back
139
140=head2 sync
141
142C<SDLx::App::sync> encapsulates the various methods of synchronizing the screen with the
143current video buffer. C<SDLx::App::sync> will do a fullscreen update, using the double buffer
144or OpenGL buffer if applicable. This is preferred to calling flip on the application window.
145
146=head2 attribute( $attr )
147
148=head2 attribute( $attr, $value )
149
150C<SDLx::App::attribute> allows one to get and set GL attributes. By passing a value
151in addition to the attribute selector, the value will be set. C<SDL:::App::attribute>
152always returns the current value of the given attribute, or Carp::confess on failure.
153
154=head1 CALLBACKS
155
156C<SDLx::App> is a C<SDLx::Controller>. Use the event, show and handlers to run the app.
157
158  use SDL;
159  use SDLx::App;
160 
161  use SDL::Event; #Where ever the event call back is processed
162
163  my $app = SDLx::App->new( width => 200, height => 200);
164
165  $app->add_event_handler( sub{
166      my ($event, $app) = @_;
167      return $_[0]->type == SDL_QUIT ? 0 : 1;
168  });
169
170  $app->add_show_handler( sub{
171      my ($delta, $app) = @_;
172      $app->update;
173  } );
174
175  $app->add_move_handler( sub{ 
176      my ($step, $app, $t) = @_;
177      #calc your physics here 
178  } );
179
180  $app->run();
181
182see L<SDLx::Controller> for more details.
183
184=head1 AUTHORS
185
186See L<SDL/AUTHORS>.
187
188=head1 SEE ALSO
189
190L<perl> L<SDL::Surface> L<SDL::Event>  L<SDL::OpenGL>
191
192=cut