Device-Chip-SSD1306
view release on metacpan or search on metacpan
lib/Device/Chip/SSD1306.pm view on Meta::CPAN
{
$val //= 1;
$_framebuffer or
_framebuffer_new( $_framebuffer, $_rows, $_columns );
_framebuffer_draw_vline( $_framebuffer, $x, $y1, $y2, $val );
}
=head2 draw_rect
$chip->draw_rect( $x1, $y1, $x2, $y2, $val = 1 );
I<Since version 0.15.>
Draw a solid rectangle in between the given I<$x1> to I<$2> columns and rows
I<$y1> to I<$y2> (all inclusive). If the final argument is false, the pixels
will be cleared instead of set.
=cut
method draw_rect ( $x1, $y1, $x2, $y2, $val = 1 )
{
$_framebuffer or
_framebuffer_new( $_framebuffer, $_rows, $_columns );
_framebuffer_draw_rect( $_framebuffer, $x1, $y1, $x2, $y2, $val );
}
=head2 draw_blit
$chip->draw_blit( $x, $y, @lines );
Draws a bitmap pattern by copying the data given in lines, starting at the
given position.
Each value in C<@lines> should be a string giving a horizontal line of bitmap
data, each character corresponding to a single pixel of the display. Pixels
corresponding to a spaces will be left alone, a hyphen will be cleared, and
any other character (for example a C<#>) will be set.
For example, to draw an rightward-pointing arrow:
$chip->draw_blit( 20, 40,
" # ",
" ## ",
"######",
"######",
" ## ",
" # " );
=cut
method draw_blit ( $x0, $y, @lines )
{
$_framebuffer or
_framebuffer_new( $_framebuffer, $_rows, $_columns );
# TODO: more efficient in XS, somehow...?
for( ; @lines; $y++ ) {
my @pixels = split m//, shift @lines;
@pixels or next;
my $x = $x0;
for( ; @pixels; $x++ ) {
my $p = shift @pixels;
$p eq " " ? next :
$p eq "-" ? _framebuffer_draw_pixel( $_framebuffer, $x, $y, 0 ) :
_framebuffer_draw_pixel( $_framebuffer, $x, $y, 1 );
}
}
}
=head2 draw_glyph
$chip->draw_glyph( $x, $y, $glyph, $val = 1, $bg = undef );
I<Since version 0.15.>
Draws a glyph by copying the bitmap data out of the C<$glyph> argument, as if
it were a single glyph structure obtained from L<Font::PCF>. The bitmap is
copied starting at the given position, and extends rightward and downward for
whatever is the defined size of the glyph given by its data. For each pixel
set in the glyph's bitmap, the corresponding pixel of the display is set to
C<$val>; the other pixels are set to C<$bg>. Either of these last two values
may be set to C<undef> to not modify those corresponding pixels.
Note that neither this module nor its tests actually depend on C<Font::PCF>
itself; it merely invokes methods on the object consistent with that API.
Specifically, it expects the following methods:
=over 4
=item width
$cols = $glyph->width;
Returns the number of columns wide that contain pixels of glyph data.
=item bitmap
[ $row0, $row1, ... ] = $glyph->bitmap;
Returns an C<ARRAY> reference of rows of pixel data. Each row is represented
by a big-endian 32bit integer. The topmost bit corresponds to the leftmost
pixel.
=back
=cut
method draw_glyph ( $x0, $y0, $glyph, $val = 1, $bg = undef )
{
my $bitmap = $glyph->bitmap;
my $width_1 = $glyph->width - 1;
$_framebuffer or
_framebuffer_new( $_framebuffer, $_rows, $_columns );
# TODO: more efficient in XS, somehow...?
( run in 1.437 second using v1.01-cache-2.11-cpan-71847e10f99 )