Polylines

A polyline is drawn as a set of ordered vertices relative to the shape's x,y coordinate.

Polylines may be filled or unfilled. An unfilled polyline is more conceptually familiar with what is implied by a polyline. A filled polyline is essentially an unclosed polygon.

The following contains an example that will add an unfilled polygon to a canvas. The blue lines represent the x and y axes, and show through since an alpha value of 0.9 is used.

polyline.png

Unfilled Polyline drawn by example code below

Note that set_outline() is used to set the line color.

void add_polyline_unfilled( Papyrus::Canvas& canvas ) {
  // Create a polyline that will form a Z
  Papyrus::Polyline::pointer polyline = Papyrus::Polyline::create();

  // Add the polyline to the canvas
  canvas.add( polyline );

  // Set a line width
  polyline->line_style().set_width(10);

  // Add the four points of the Z (upper left, upper right, lower left, lower right)
  polyline->add_vertex( -50, -50 );
  polyline->add_vertex(  50, -50 );
  polyline->add_vertex( -50,  50 );
  polyline->add_vertex(  50,  50 );

  // To color the lines of a polyline shape, set the outline pattern
  polyline->line_style().set_pattern( Cairo::SolidPattern::create_rgba(1.0, 0.0, 1.0, 0.9) );
}

The following illustrates the effects of filling a polyline.

polyline_filled.png

Filled Polyline drawn by example code below

void add_polyline_filled( Papyrus::Canvas& canvas ) {
  // Create a filled polyline that will form a U
  Papyrus::Polyline::pointer polyline = Papyrus::Polyline::create();

  // Add the polyline to the canvas
  canvas.add( polyline );

  // Set a line width
  polyline->line_style().set_width(10);

  // Add the four points of the U (upper left, lower left, lower right, upper right)
  polyline->add_vertex( -50, -50 );
  polyline->add_vertex( -50,  50 );
  polyline->add_vertex(  50,  50 );
  polyline->add_vertex(  50, -50 );

  // Set the fill color to red, with an alpha value of 0.9
  polyline->set_fill( Cairo::SolidPattern::create_rgba(0.0, 1.0, 1.0, 0.9) );

  // To color the lines of a polyline shape, set the outline pattern
  polyline->set_outline( Cairo::SolidPattern::create_rgba(0.0, 0.0, 0.0, 0.9) );
}

Generated on Sun Mar 11 10:01:28 2007 by  doxygen 1.5.1