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 $vp->down; $vp->right; 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
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_down() &c methods to move that cursor within the window. When the cursor reaches a boundary, the window moves, not the cursor.
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, <email@example.com>
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.