Esempio n. 1
0
bool ScreenAreaCairo::on_draw(const Cairo::RefPtr<Cairo::Context> &poContext)
{
	DrawingArea::on_draw(poContext);

	Cairo::RefPtr< Cairo::ImageSurface >   poImage;
	Cairo::RefPtr< Cairo::SurfacePattern > poPattern;
	Cairo::Matrix oMatrix;
	const int iScaledPitch = m_iWidth * sizeof(u32);

	poContext->set_identity_matrix();
	poContext->scale(m_dScaleFactor, m_dScaleFactor);

	poImage = Cairo::ImageSurface::create((u8 *)m_puiPixels, Cairo::FORMAT_RGB24,
	                                      m_iWidth, m_iHeight, iScaledPitch);

	cairo_matrix_init_translate(&oMatrix, -m_iAreaLeft, -m_iAreaTop);
	poPattern = Cairo::SurfacePattern::create(poImage);
	poPattern->set_filter(Cairo::FILTER_NEAREST);
	poPattern->set_matrix (oMatrix);
	poContext->set_source_rgb(0.0, 0.0, 0.0);
	poContext->paint();

	poContext->set_source(poPattern);
	poContext->paint();

	return true;
}
Esempio n. 2
0
void cairo::draw_triangle( const Cairo::RefPtr<Cairo::Context>& cr, const Geodesics::edge_handle& e0 )
{
  const rgba_color_t color( .8, .8, .8, .3);

  // get edge-free pair
  const Geodesics::edge_handle e1 ( e0.next() );
  const Geodesics::edge_handle e2 ( e1.next() );

  const coord_t e0l= e0.length();
  const coord_t e1l= e1.length();
  const coord_t e2l= e2.length();

  // coordinates of C - using circle-circle intersection ( intersect circle (w.b0,w.d0) with (w.b1,w.d1) )

  cairo_coord_t A(0.,0.);
  cairo_coord_t B(e0l,0.);
  cairo_coord_t C;
  boost::tie(C[0],C[1]) = utk::triangulate( e0l, e2l, e1l );
  //C[1] = - C[1];

  const coord2_t centroid = ( ( coord2_t(e0l, 0) += C ) /= coord_t(3) );

  cr->save();

    //cr->set_operator( Cairo::OPERATOR_DEST_OVER );

    cr->set_source_rgba( color[0], color[1], color[2], color[3] );

    cr->save();
      // shrink slightly towards centroid
      cr->translate( centroid[0], centroid[1] );
      cr->scale( .95, .95 );
      cr->translate( -centroid[0], -centroid[1] );
      //draw triangle
      cr->set_line_width( 1. * user_unit_distance( cr ).length() );

      draw_half_arrow( cr, A, B );

      draw_half_arrow( cr, B, C );

      draw_half_arrow( cr, C, A );


    cr->restore();

    cr->stroke();

  cr->restore();

  // draw text
  cr->save();

    cr->user_to_device( A[0], A[1] );
    cr->user_to_device( B[0], B[1] );
    cr->user_to_device( C[0], C[1] );

    cr->set_identity_matrix();

    //cr->select_font_face( "Purisa", Cairo::FONT_SLANT_NORMAL, Cairo::FONT_WEIGHT_NORMAL );

    cr->set_source_rgba( 0., 0., 0.,.5 );

    cr->set_font_size( 8. /* user_unit_distance( cr ).length()*/ );

    std::ostringstream nrss;
    nrss << e0.source().descriptor();
    draw_centered_text( cr, nrss.str(), A );

    nrss.str("");
    nrss << e1.source().descriptor();
    draw_centered_text( cr, nrss.str(), B );

    nrss.str("");
    nrss << e2.source().descriptor();
    draw_centered_text( cr, nrss.str(), C );

  cr->restore();

}