View on
MetaCPAN is shutting down
For details read Perl NOC. After June 25th this page will redirect to
Jeff Goff > Games-Shogi-0.03 > Window



Annotate this POD


New  2
Open  0
View/Report Bugs
Module Version: 0.01   Source  


Window - Create a virtual window into a MxN grid of data.


  use Window;
  my $vp = Window->new(
   viewport => [3,3], # Define a 3x3 window onto a chessboard
   grid     => [ [qw(R N B K Q B N R)], # Pieces represented as text
                 [qw(P P P P P P P P)],
                 [(undef) x 8], # And blank squares as undef
                 [(undef) x 8], 
                 [(undef) x 8],
                 [(undef) x 8],
                 [qw(p p p p p p p p)],
                 [qw(r n b q k b n r)] ] );
  print $vp->square(0,0); # 'R' is the TR square in the viewport
  print $vp->square(0,0); # 'P' is now the TR square after moving down and right
  $vp->set_square(0,0,' ');$vp->set_square(0,1,'P'); # Move the pawn


Given a two-D array of data, this module creates a smaller window onto the dataset that can be moved around with left(), down() &c methods. Use the square($x,$y) method to get the data in a square relative to the upper-left corner of the window, and view() to get the entire window's worth of data.

In addition, you can place a virtual cursor within the window, and use the curs_left(), curs_down() &c methods to move that cursor within the window. When the cursor reaches a boundary, the window moves, not the cursor.

The left(), right(), up() and down() routines return whether the window was moved or not. The only time the window can't be moved is when it's against a border.

curs_right() &c likewise signal if the window couldn't be moved. The data grid doesn't wrap around, as it doesn't really make sense to wrap around a chessboard.




Jeffrey Goff, <>


Copyright 2004 by Jeffrey Goff

This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.

syntax highlighting: