The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.

Finance::GeniusTrader::Graphics::Driver

A graphic driver is a well defined interface that let you actually generate a picture by using drawing primitives. Those primitives are used by "drawable" objects that implements the display($driver, $picture) method.

Drawing API

$picture = $driver->create_picture($rootzone)

This does create the empty picture on which you'll draw various things. The picture has the size corresponding to the given "zone".

$driver->line($picture, $x1, $y1, $x2, $y2, $color)

$driver->dashed_line($picture, $x1, $y1, $x2, $y2, $color)

$driver->antialiased_line($picture, $x1, $y1, $x2, $y2, $color)

$driver->rectangle($picture, $x1, $y1, $x2, $y2, $color)

$driver->filled_rectangle($picture, $x1, $y1, $x2, $y2, $color)

$driver->polygon($picture, $color, @points)

$driver->filled_polygon($picture, $color, @points)

$driver->circle($picture, $x, $y, $width, $height, $color)

The last 7 methods are simple drawing methods. The coordinates are absolute (ie as expressed in the $rootzone). Take care to convert them if needed.

For the rectangles, you give the lower left corner and the upper right corner.

The (0,0) coordinate is the lower left corner.

my $oldwidth = $driver->line_width($picture, $width)

This method changes the default width of displayed lines. It returns the previous width so that you can restore it to its previous value once you're finished with the operation needing a special line width.

If $width isn't given, it only returns the actual width.

$driver->string($p, $name, $size, $color, $x, $y, $text, $halign, $valign, $orientation)

This method is used to draw texts on the picture.

Horizontal/vertical align : $ALIGN_LEFT, $ALIGN_CENTER, $ALIGN_RIGHT

Orientation : $ORIENTATION_UP, $ORIENTATION_DOWN, $ORIENTATION_RIGHT, $ORIENTATION_LEFT

The text is displayed near (x,y) by follwing the required alignments.

Output API

$driver->save_to($p, $filename)

Save the picture in the given filename.

$driver->dump($p)

Dump the picture to the standard output.

Generic functions

Those functions don't need to be reimplemented, they are implemented with the other primitives.

$driver->cross($picture, $x1, $y1, $x2, $y2, $color)

Draw a cross.

DATA STRUCTURE

Colors

Colors are simple RGB triplet associated to an alpha channel : [ R, G, B, A ] They are only array references.

Some variables are available for the most common colors :

$COLOR_WHITE
$COLOR_BLACK
$COLOR_RED
$COLOR_GREEN
$COLOR_BLUE

Fonts

Font names are simple strings (true type font names). Font size are numbers.

Some variables are available for the most common values :

$FONT_SIZE_TINY
$FONT_SIZE_SMALL
$FONT_SIZE_MEDIUM
$FONT_SIZE_LARGE
$FONT_SIZE_GIANT
$FONT_ARIAL
$FONT_TIMES
$FONT_HELVETICA
$FONT_SERIF
$FONT_SANS_SERIF
$FONT_FIXED
$FONT_PROPORTIONNAL