/[VRac]/Screen.pm
This is repository of my old source code which isn't updated any more. Go to git.rot13.org for current projects!
ViewVC logotype

Diff of /Screen.pm

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 96 by dpavlin, Thu Aug 2 13:58:26 2007 UTC revision 99 by dpavlin, Thu Aug 2 16:21:17 2007 UTC
# Line 14  use Carp qw/confess/; Line 14  use Carp qw/confess/;
14  use Data::Dump qw/dump/;  use Data::Dump qw/dump/;
15    
16  use base qw(Class::Accessor Prefs);  use base qw(Class::Accessor Prefs);
17  __PACKAGE__->mk_accessors(qw(app));  __PACKAGE__->mk_accessors(qw(app event));
18    
19  =head1 NAME  =head1 NAME
20    
# Line 46  sub open_screen { Line 46  sub open_screen {
46          #$app->grab_input( SDL_GRAB_QUERY );          #$app->grab_input( SDL_GRAB_QUERY );
47          $app->grab_input( SDL_GRAB_OFF );          $app->grab_input( SDL_GRAB_OFF );
48    
         warn "# created SDL::App\n";  
49          $self->app( $app );          $self->app( $app );
50    
51            my $event = SDL::Event->new();
52            $self->event( $event );
53    
54            warn "# created SDL::App\n";
55  }  }
56    
57  my $white       = SDL::Color->new( -r => 0xff, -g => 0xff, -b => 0xff );  my $white       = SDL::Color->new( -r => 0xff, -g => 0xff, -b => 0xff );
# Line 235  sub render_mem { Line 239  sub render_mem {
239          $app->sync;          $app->sync;
240  }  }
241    
242    =head2 key_pressed
243    
244    Check SDL event loop if there are any pending keys
245    
246      my $key = $self->key_pressed;
247    
248      if ( $self->key_pressed( 1 ) ) {
249            # just to check other events, don't process
250            # key
251      }
252    
253    =cut
254    
255    my $pending_key;
256    my $run_for = 2000;
257    
258    sub key_pressed {
259            my $self = shift;
260    
261            # don't take key, just pull event
262            my $just_checking = shift;
263    
264            my $event = $self->event || confess "no event?";
265    
266            $event->poll || return $pending_key;
267    
268            my $type = $event->type();
269    
270            exit if ($type == SDL_QUIT);
271    
272            my $k = $pending_key;
273    
274            if ($type == SDL_KEYDOWN) {
275                    $k = $event->key_name();
276                    if ( $k eq 'escape' ) {
277                            $run_for = $self->cli;
278                            warn "will check event loop every $run_for cycles\n";
279                    } else {
280                            warn "SDL_KEYDOWN ($type) = '$k'\n";
281                            $pending_key = $k if $just_checking;
282                    }
283            } elsif ( $type == SDL_KEYUP ) {
284                    my $up = $event->key_name();
285                    warn "SDL_KEYUP ($type) = '$up'\n";
286                    undef $pending_key;
287            }
288    
289            warn "key_pressed = $pending_key\n" if $pending_key;
290    
291            return $pending_key;
292    }
293    
294  =head2 loop  =head2 loop
295    
296  Implement SDL event loop  Implement SDL event loop
# Line 245  sub loop { Line 301  sub loop {
301          my $self = shift;          my $self = shift;
302          my $event = SDL::Event->new();          my $event = SDL::Event->new();
303    
         my $run_for = 2000;  
304    
305          MAIN_LOOP:          MAIN_LOOP:
306          while ( 1 ) {          while ( 1 ) {
307                  while ($event->poll) {                  $self->key_pressed( 1 );
                         my $type = $event->type();  
   
                         last MAIN_LOOP if ($type == SDL_QUIT);  
                         last MAIN_LOOP if ($type == SDL_KEYDOWN && $event->key_name() eq 'escape');  
   
                         if ($type == SDL_KEYDOWN) {  
                                 $run_for = $self->cli;  
                         }  
                 }  
308                  M6502::exec($run_for);                  M6502::exec($run_for);
309          }          }
310  }  }

Legend:
Removed from v.96  
changed lines
  Added in v.99

  ViewVC Help
Powered by ViewVC 1.1.26