The London Perl and Raku Workshop takes place on 26th Oct 2024. If your company depends on Perl, please consider sponsoring and/or attending.


Image::Base::Prima::Drawable -- draw into Prima window, image, etc


 use Image::Base::Prima::Drawable;
 my $image = Image::Base::Prima::Drawable->new
               (-drawable => $d);
 $image->line (0,0, 99,99, '#FF00FF');
 $image->rectangle (10,10, 20,15, 'white');


Image::Base::Prima::Drawable is a subclass of Image::Base,



Image::Base::Prima::Drawable extends Image::Base to draw into a Prima::Drawable drawable, meaning a widget window, off-screen image, printer, postscript accumulator, etc.

The native Prima drawing has many more features, but this module can point some Image::Base style code at a Prima image etc.

X,Y coordinates are the usual Image::Base style 0,0 at the top-left corner. Prima works from 0,0 as the bottom-left but Image::Base::Prima::Drawable converts. No attention is paid to the Prima translate() origin change, which ends up meaning the top-left shifts up etc with the translate. That seems reasonably logical, is it the best way though?

None of the drawing functions here do a $drawable->begin_paint() or a $drawable->begin_doc() (for Prima::PS::Drawable). That's left to the application. A begin_paint() of course happens automatically in an onPaint handler call. The symptom of forgetting a begin_paint() is generally that lines, rectangles and ellipses don't draw anything, though xy() might come out because it uses $drawable->pixel() (but don't rely on that). Forgetting a begin_doc() for PS output may cause various warnings about undef.


Colour names for drawing are

    Blue             Prima colour constants cl::Blue etc
    #RRGGBB          hex
    #RRRRGGGGBBBB    hex

Internally Prima works in 8-bit RGB components and drawables with less than 24-bits per pixel then reduce further. See "Color space" in Prima::Drawable for details and the cl:: colour constant names.


See "FUNCTIONS" in Image::Base for the behaviour common to all Image-Base classes.

$image = Image::Base::Prima::Drawable->new (key=>value,...)

Create and return a new image object. A Prima::Drawable object must be given.

    $image = Image::Base::Prima::Drawable->new
               (-drawable => $d);
$colour = $image->xy ($x, $y)
$image->xy ($x, $y, $colour)

Get or set the pixel at $x,$y.

Currently colours returned by a get are always 2-digit hex #RRGGBB. Would names "Blue" for cl::Blue etc be better for those particular colours?


-drawable (Prima::Drawable object)

The target drawable.

-width (integer)
-height (integer)

The width and height of the underlying drawable. Setting these resizes the drawable (as per $drawable->size, see "Other properties" in Prima::Drawable).


Image::Base, Prima::Drawable, Image::Base::Prima::Image

Image::Base::Gtk2::Gdk::Drawable, Image::Base::X11::Protocol::Drawable



Image-Base-Prima is Copyright 2010, 2011, 2012, 2015 Kevin Ryde

Image-Base-Prima is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 3, or (at your option) any later version.

Image-Base-Prima is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with Image-Base-Prima. If not, see <>.