Exemplo n.º 1
0
static cairo_status_t
twin_scaled_font_render_glyph (cairo_scaled_font_t  *scaled_font,
			       unsigned long         glyph,
			       cairo_t              *cr,
			       cairo_text_extents_t *metrics)
{
    double x1, y1, x2, y2, x3, y3;
    const int8_t *b = _cairo_twin_outlines +
		      _cairo_twin_charmap[glyph >= ARRAY_LENGTH (_cairo_twin_charmap) ? 0 : glyph];
    const int8_t *g = twin_glyph_draw(b);

    struct {
      cairo_bool_t snap;
      int snap_x;
      int snap_y;
      int n_snap_x;
      int n_snap_y;
    } info = {FALSE};

    cairo_set_line_width (cr, 0.06);
    cairo_set_line_join (cr, CAIRO_LINE_JOIN_ROUND);
    cairo_set_line_cap (cr, CAIRO_LINE_CAP_ROUND);

    for (;;) {
	switch (*g++) {
	case 'M':
	    cairo_close_path (cr);
	    /* fall through */
	case 'm':
	    x1 = FX(*g++);
	    y1 = FY(*g++);
	    if (info.snap)
	    {
		x1 = SNAPX (x1);
		y1 = SNAPY (y1);
	    }
	    cairo_move_to (cr, x1, y1);
	    continue;
	case 'L':
	    cairo_close_path (cr);
	    /* fall through */
	case 'l':
	    x1 = FX(*g++);
	    y1 = FY(*g++);
	    if (info.snap)
	    {
		x1 = SNAPX (x1);
		y1 = SNAPY (y1);
	    }
	    cairo_line_to (cr, x1, y1);
	    continue;
	case 'C':
	    cairo_close_path (cr);
	    /* fall through */
	case 'c':
	    x1 = FX(*g++);
	    y1 = FY(*g++);
	    x2 = FX(*g++);
	    y2 = FY(*g++);
	    x3 = FX(*g++);
	    y3 = FY(*g++);
	    if (info.snap)
	    {
		x1 = SNAPX (x1);
		y1 = SNAPY (y1);
		x2 = SNAPX (x2);
		y2 = SNAPY (y2);
		x3 = SNAPX (x3);
		y3 = SNAPY (y3);
	    }
	    cairo_curve_to (cr, x1, y1, x2, y2, x3, y3);
	    continue;
	case 'E':
	    cairo_close_path (cr);
	    /* fall through */
	case 'e':
	    cairo_stroke (cr);
	    break;
	case 'X':
	    /* filler */
	    continue;
	}
	break;
    }

    metrics->x_advance = FX(twin_glyph_right(b)) + cairo_get_line_width (cr);
    metrics->x_advance +=  cairo_get_line_width (cr)/* XXX 2*x.margin */;
    if (info.snap)
	metrics->x_advance = SNAPI (SNAPX (metrics->x_advance));


    return CAIRO_STATUS_SUCCESS;
}
Exemplo n.º 2
0
void Context::quadTo( double x1, double y1, double x2, double y2 )
{
	double x0, y0;
	cairo_get_current_point( mCairo, &x0, &y0 );
	cairo_curve_to( mCairo, x0 + (x1 - x0) / 3.0f * 2.0f, y0 + (y1 - y0) / 3.0f * 2.0f, x1 + (x2 - x1) / 3.0f, y1 + (y2 - y1) / 3.0f, x2, y2 );
}
Exemplo n.º 3
0
static ClutterActor *
make_background (const ClutterColor *color,
                 gfloat              width,
                 gfloat              height)
{
  ClutterActor *tex = clutter_cairo_texture_new (width, height);
  cairo_t *cr = clutter_cairo_texture_create (CLUTTER_CAIRO_TEXTURE (tex));
  cairo_pattern_t *pat;
  gfloat x, y;

#define BG_ROUND_RADIUS         12

  x = y = 0;

  cairo_move_to (cr, BG_ROUND_RADIUS, y);
  cairo_line_to (cr, width - BG_ROUND_RADIUS, y);
  cairo_curve_to (cr, width, y, width, y, width, BG_ROUND_RADIUS);
  cairo_line_to (cr, width, height - BG_ROUND_RADIUS);
  cairo_curve_to (cr, width, height, width, height, width - BG_ROUND_RADIUS, height);
  cairo_line_to (cr, BG_ROUND_RADIUS, height);
  cairo_curve_to (cr, x, height, x, height, x, height - BG_ROUND_RADIUS);
  cairo_line_to (cr, x, BG_ROUND_RADIUS);
  cairo_curve_to (cr, x, y, x, y, BG_ROUND_RADIUS, y);

  cairo_close_path (cr);

  clutter_cairo_set_source_color (cr, color);
  cairo_stroke (cr);

  x += 4;
  y += 4;
  width -= 4;
  height -= 4;

  cairo_move_to (cr, BG_ROUND_RADIUS, y);
  cairo_line_to (cr, width - BG_ROUND_RADIUS, y);
  cairo_curve_to (cr, width, y, width, y, width, BG_ROUND_RADIUS);
  cairo_line_to (cr, width, height - BG_ROUND_RADIUS);
  cairo_curve_to (cr, width, height, width, height, width - BG_ROUND_RADIUS, height);
  cairo_line_to (cr, BG_ROUND_RADIUS, height);
  cairo_curve_to (cr, x, height, x, height, x, height - BG_ROUND_RADIUS);
  cairo_line_to (cr, x, BG_ROUND_RADIUS);
  cairo_curve_to (cr, x, y, x, y, BG_ROUND_RADIUS, y);

  cairo_close_path (cr);

  pat = cairo_pattern_create_linear (0, 0, 0, height);
  cairo_pattern_add_color_stop_rgba (pat, 1, .85, .85, .85, 1);
  cairo_pattern_add_color_stop_rgba (pat, .95, 1, 1, 1, 1);
  cairo_pattern_add_color_stop_rgba (pat, .05, 1, 1, 1, 1);
  cairo_pattern_add_color_stop_rgba (pat, 0, .85, .85, .85, 1);

  cairo_set_source (cr, pat);
  cairo_fill (cr);

  cairo_pattern_destroy (pat);
  cairo_destroy (cr);

#undef BG_ROUND_RADIUS

  return tex;
}
Exemplo n.º 4
0
void Drawer::DrawCurveDebug(const Point& aPrevPoint, const Point& aStartPoint, const Point& aEndPoint, const Point& aNextPoint, double& aCoef)
{
    if (aCoef < 0.0)
        aCoef = 0.0;
    else if (aCoef > 1.0)
        aCoef = 1.0;

    Point PrevPointLocal = aPrevPoint;
    Point StartPointLocal = aStartPoint;
    Point EndPointLocal = aEndPoint;
    Point NextPointLocal = aNextPoint;

    Point TanStartPointLocalCas1(0.0,0.0);
    Point TanStartPointLocalCas1R1(0.0,0.0);
    Point TanEndPointLocalCas1(0.0,0.0);
    Point TanEndPointLocalCas1R2(0.0,0.0);

    Point TanStartPointLocalCas2(0.0,0.0);
    Point TanStartPointLocalCas2R1(0.0,0.0);
    Point TanEndPointLocalCas2(0.0,0.0);
    Point TanEndPointLocalCas2R2(0.0,0.0);

    Point TanStartPointLocalCas3(0.0,0.0);
    Point TanStartPointLocalCas3R1(0.0,0.0);
    Point TanEndPointLocalCas3(0.0,0.0);
    Point TanEndPointLocalCas3R2(0.0,0.0);

    Point TanStartPointLocalCas4(0.0,0.0);
    Point TanEndPointLocalCas4(0.0,0.0);
    /* DEBUG
    std::cout << "PrevPointLocal  = (" << PrevPointLocal.X << "," << PrevPointLocal.Y << ")" << std::endl;
    std::cout << "StartPointLocal = (" << StartPointLocal.X << "," << StartPointLocal.Y << ")" << std::endl;
    std::cout << "EndPointLocal   = (" << EndPointLocal.X << "," << EndPointLocal.Y << ")" << std::endl;
    std::cout << "NextPointLocal  = (" << NextPointLocal.X << "," << NextPointLocal.Y << ")" << std::endl << std::endl; */

    Point StartPointTan(0,0);
    Point EndPointTan(0,0);

    double DistTan12  = 0.0;
    double DistTan34  = 0.0;
    double MinDistTan = 0.0;

    double AngleRadianR1 = 0.0;
    cairo_matrix_t TranslateMatrixR0toR1;
    cairo_matrix_t RotateMatrixR0toR1;
    Point StartPointLocalR1 = StartPointLocal;
    Point EndPointR1(0,0);
    Point StartPointTanR1(0,0);

    double AngleRadianR2 = 0.0;
    cairo_matrix_t TranslateMatrixR0toR2;
    cairo_matrix_t RotateMatrixR0toR2;
    Point StartPointLocalR2(0,0);
    Point EndPointR2 = EndPointLocal;
    Point EndPointTanR2(0,0);

    // Il faut que 'aPrevPoint' et 'aStartPoint' soit non confondu et 'aEndPoint' et 'aNextPoint' aussi
    if ((PrevPointLocal != StartPointLocal) && (EndPointLocal != NextPointLocal))
    {
        // Calcul de l'angle de rotation du nouveau repère R1 (aPrevPoint/aStartPoint)
        AngleRadianR1 = atan2 (StartPointLocal.Y - PrevPointLocal.Y, StartPointLocal.X - PrevPointLocal.X);

        /* DEBUG
        std::cout << "AngleRadianR1 = " << AngleRadianR1 << std::endl << std::endl;*/
        SetColor(0,0,0);
        MoveTo(PrevPointLocal);
        DrawLine(StartPointLocal,1);
        //DrawArc (PrevPointLocal,30, AngleRadianR1,1);

        // Translation du repère au point 'aPrevPoint'
        cairo_matrix_init_translate(&TranslateMatrixR0toR1, PrevPointLocal.X, PrevPointLocal.Y);
//      cairo_transform(mCairoDC, &TranslateMatrixR1);

        // Rotation du repère d'angle 'AngleRadianR1'
        cairo_matrix_init_rotate(&RotateMatrixR0toR1, AngleRadianR1);
//      cairo_transform(mCairoDC, &RotateMatrixR1);

        // Calcul des coordonnées des points StartPointLocal, EndPointLocal, TanStartPointLocal dans le repère R1
        // Point B et C R0 => Point B et C R1
        cairo_matrix_invert(&TranslateMatrixR0toR1);
        cairo_matrix_transform_point(&TranslateMatrixR0toR1, &EndPointLocal.X, &EndPointLocal.Y);
        cairo_matrix_transform_point(&TranslateMatrixR0toR1, &StartPointLocalR1.X, &StartPointLocalR1.Y);
        cairo_matrix_invert(&RotateMatrixR0toR1);
        cairo_matrix_transform_point(&RotateMatrixR0toR1, &EndPointLocal.X, &EndPointLocal.Y);
        cairo_matrix_transform_point(&RotateMatrixR0toR1, &StartPointLocalR1.X, &StartPointLocalR1.Y);
        EndPointR1 = EndPointLocal;
        // Reset du EndPointLocal
        EndPointLocal = aEndPoint;

        /* DEBUG
        std::cout << "EndPointR1     = (" << EndPointR1.X << "," << EndPointR1.Y << ")" << std::endl;*/
//      DrawRepere(0.0,0.0,0.6);

        // Coordonnées de StartPointTan dans le repère R1
        StartPointTanR1.X = EndPointR1.X;
        StartPointTanR1.Y = 0.0;

        // Sauvegarde de la distance du point pour le tracer de la tangente
        DistTan12 = abs(StartPointTanR1.X - StartPointLocalR1.X);
        MinDistTan = DistTan12;

        /* DEBUG
        std::cout << "StartPointTanR1= (" << StartPointTanR1.X << "," << StartPointTanR1.Y << ")" << std::endl << std::endl;*/
//      MoveTo(StartPointTanR1);
//      DrawLine(EndPointR1,1);

        // Calcul des coordonnées de StartPointTan dans le repère R0 (Origine)
//      StartPointTan = StartPointTanR1;
//      cairo_matrix_invert(&RotateMatrixR1);
//      cairo_matrix_transform_point(&RotateMatrixR1, &StartPointTan.X, &StartPointTan.Y);
//      cairo_matrix_invert(&TranslateMatrixR1);
//      cairo_matrix_transform_point(&TranslateMatrixR1, &StartPointTan.X, &StartPointTan.Y);

//      cairo_identity_matrix(mCairoDC);

        /* DEBUG
        std::cout << "StartPointTan = (" << StartPointTan.X << "," << StartPointTan.Y << ")" << std::endl << std::endl << std::endl;*/
//      SetColor(0,0,0);
//      DrawPoint(StartPointTan,3);

        /////////////

        // Calcul de l'angle de rotation du nouveau repère R1 (aPrevPoint/aStartPoint)
        AngleRadianR2 = atan2 (EndPointLocal.Y - NextPointLocal.Y, EndPointLocal.X - NextPointLocal.X);

        /* DEBUG
        std::cout << "AngleRadianR1 = " << AngleRadianR1 << std::endl << std::endl;*/
//      SetColor(0,0,0);
//      MoveTo(NextPointLocal);
//      DrawLine(EndPointLocal,1);
        //DrawArc (NextPointLocal,30, AngleRadianR2,1);

        // Translation du repère au point 'aNextPoint'
        cairo_matrix_init_translate(&TranslateMatrixR0toR2, NextPointLocal.X, NextPointLocal.Y);
//      cairo_transform(mCairoDC, &TranslateMatrixR2);

        // Rotation du repère d'angle 'AngleRadianR2'
        cairo_matrix_init_rotate(&RotateMatrixR0toR2, AngleRadianR2);
//      cairo_transform(mCairoDC, &RotateMatrixR2);

        // Calcul des coordonnées du Point StartPointLocal dans le repère R2
        // Point B et C R0 => Point B et C R2
        cairo_matrix_invert(&TranslateMatrixR0toR2);
        cairo_matrix_transform_point(&TranslateMatrixR0toR2, &StartPointLocal.X, &StartPointLocal.Y);
        cairo_matrix_transform_point(&TranslateMatrixR0toR2, &EndPointR2.X, &EndPointR2.Y);
        cairo_matrix_invert(&RotateMatrixR0toR2);
        cairo_matrix_transform_point(&RotateMatrixR0toR2, &StartPointLocal.X, &StartPointLocal.Y);
        cairo_matrix_transform_point(&RotateMatrixR0toR2, &EndPointR2.X, &EndPointR2.Y);
        StartPointLocalR2 = StartPointLocal;
        // Reset du StartPointLocal
        StartPointLocal = aStartPoint;

        /* DEBUG
        std::cout << "StartPointLocalR2 = (" << StartPointLocalR2.X << "," << StartPointLocalR2.Y << ")" << std::endl;*/
//      DrawRepere(0.0,0.0,0.6);

        // Coordonnées de EndPointTan dans le repère R2
        EndPointTanR2.X = StartPointLocalR2.X;
        EndPointTanR2.Y = 0.0;

        // Sauvegarde de la distance du point pour le tracer de la tangente
        DistTan34 = abs(EndPointTanR2.X - EndPointR2.X);
        if(DistTan34 < MinDistTan)
            MinDistTan = DistTan34;

        /* DEBUG
        std::cout << "EndPointTanR2     = (" << EndPointTanR2.X << "," << EndPointTanR2.Y << ")" << std::endl << std::endl;*/
//      MoveTo(EndPointTanR2);
//      DrawLine(StartPointLocalR2,1);

        // Calcul des coordonnées de EndPointTan dans le repère R0 (Origine)
//      EndPointTan = EndPointTanR2;
//      cairo_matrix_invert(&RotateMatrixR2);
//      cairo_matrix_transform_point(&RotateMatrixR2, &EndPointTan.X, &EndPointTan.Y);
//      cairo_matrix_invert(&TranslateMatrixR2);
//      cairo_matrix_transform_point(&TranslateMatrixR2, &EndPointTan.X, &EndPointTan.Y);

//      cairo_identity_matrix(mCairoDC);

        /* DEBUG
        std::cout << "EndPointTan = (" << EndPointTan.X << "," << EndPointTan.Y << ")" << std::endl;
        std::cout << "MinDistTan = " << MinDistTan << std::endl << std::endl << std::endl;*/
//      DrawPoint(EndPointTan,3);

        /* DEBUG
        std::cout << "Valeurs : " << std::endl;
        std::cout << "DistTan (1->2) = " << DistTan12 << std::endl;
        std::cout << "DistTan (3->4) = " << DistTan34 << std::endl;
        std::cout << "MinDistTan     = " << MinDistTan << std::endl << std::endl;*/

        cairo_matrix_invert(&RotateMatrixR0toR1);
        cairo_matrix_invert(&TranslateMatrixR0toR1);
        cairo_matrix_invert(&RotateMatrixR0toR2);
        cairo_matrix_invert(&TranslateMatrixR0toR2);

// 1er cas : (12) <=> DistTan12 et (34) <=> DistTan34
        // Coordonnées de TanStartPointLocal dans le repère R1
        TanStartPointLocalCas1R1.X = StartPointLocalR1.X + DistTan12 * aCoef;
        TanStartPointLocalCas1R1.Y = 0.0;
        TanStartPointLocalCas1 = TanStartPointLocalCas1R1;
        cairo_matrix_transform_point(&RotateMatrixR0toR1, &TanStartPointLocalCas1.X, &TanStartPointLocalCas1.Y);
        cairo_matrix_transform_point(&TranslateMatrixR0toR1, &TanStartPointLocalCas1.X, &TanStartPointLocalCas1.Y);
        // Coordonnées de TanEndPointLocal dans le repère R1
        TanEndPointLocalCas1R2.X = EndPointR2.X + DistTan34 * aCoef;
        TanEndPointLocalCas1R2.Y = 0.0;
        TanEndPointLocalCas1 = TanEndPointLocalCas1R2;
        cairo_matrix_transform_point(&RotateMatrixR0toR2, &TanEndPointLocalCas1.X, &TanEndPointLocalCas1.Y);
        cairo_matrix_transform_point(&TranslateMatrixR0toR2, &TanEndPointLocalCas1.X, &TanEndPointLocalCas1.Y);

        SetColor(1,0,0);
        DrawPoint(TanStartPointLocalCas1,3);
        DrawPoint(TanEndPointLocalCas1,3);

        cairo_move_to(mCairoDC, aStartPoint.X, aStartPoint.Y);
        cairo_curve_to(mCairoDC, TanStartPointLocalCas1.X,TanStartPointLocalCas1.Y, TanEndPointLocalCas1.X, TanEndPointLocalCas1.Y, aEndPoint.X, aEndPoint.Y);
        cairo_set_line_width(mCairoDC, 3);
        cairo_stroke(mCairoDC);

// 2eme cas : (12) <=> DistTan12 / 2 et (34) <=> DistTan34 / 2
        // Coordonnées de TanStartPointLocal dans le repère R1
        TanStartPointLocalCas2R1.X = StartPointLocalR1.X + DistTan12 * 0.5 * aCoef;
        TanStartPointLocalCas2R1.Y = 0.0;
        TanStartPointLocalCas2 = TanStartPointLocalCas2R1;
        cairo_matrix_transform_point(&RotateMatrixR0toR1, &TanStartPointLocalCas2.X, &TanStartPointLocalCas2.Y);
        cairo_matrix_transform_point(&TranslateMatrixR0toR1, &TanStartPointLocalCas2.X, &TanStartPointLocalCas2.Y);
        // Coordonnées de TanEndPointLocal dans le repère R1
        TanEndPointLocalCas2R2.X = EndPointR2.X + DistTan34 * 0.5 * aCoef;
        TanEndPointLocalCas2R2.Y = 0.0;
        TanEndPointLocalCas2 = TanEndPointLocalCas2R2;
        cairo_matrix_transform_point(&RotateMatrixR0toR2, &TanEndPointLocalCas2.X, &TanEndPointLocalCas2.Y);
        cairo_matrix_transform_point(&TranslateMatrixR0toR2, &TanEndPointLocalCas2.X, &TanEndPointLocalCas2.Y);

        SetColor(0,1,0);
        DrawPoint(TanStartPointLocalCas2,3);
        DrawPoint(TanEndPointLocalCas2,3);

        cairo_move_to(mCairoDC, aStartPoint.X, aStartPoint.Y);
        cairo_curve_to(mCairoDC, TanStartPointLocalCas2.X,TanStartPointLocalCas2.Y, TanEndPointLocalCas2.X, TanEndPointLocalCas2.Y, aEndPoint.X, aEndPoint.Y);
        cairo_set_line_width(mCairoDC, 3);
        cairo_stroke(mCairoDC);



// 3ème cas : (12) <=> MinDistTan et (34) <=> MinDistTan
        // Coordonnées de TanStartPointLocal dans le repère R1
        TanStartPointLocalCas3.X = StartPointLocalR1.X + MinDistTan * aCoef;
        TanStartPointLocalCas3.Y = 0.0;
        cairo_matrix_transform_point(&RotateMatrixR0toR1, &TanStartPointLocalCas3.X, &TanStartPointLocalCas3.Y);
        cairo_matrix_transform_point(&TranslateMatrixR0toR1, &TanStartPointLocalCas3.X, &TanStartPointLocalCas3.Y);
        // Coordonnées de TanEndPointLocal dans le repère R1
        TanEndPointLocalCas3.X = EndPointR2.X + MinDistTan * aCoef;
        TanEndPointLocalCas3.Y = 0.0;
        cairo_matrix_transform_point(&RotateMatrixR0toR2, &TanEndPointLocalCas3.X, &TanEndPointLocalCas3.Y);
        cairo_matrix_transform_point(&TranslateMatrixR0toR2, &TanEndPointLocalCas3.X, &TanEndPointLocalCas3.Y);

        SetColor(0,0,1);
        DrawPoint(TanStartPointLocalCas3,3);
        DrawPoint(TanEndPointLocalCas3,3);

        cairo_move_to(mCairoDC, aStartPoint.X, aStartPoint.Y);
        cairo_curve_to(mCairoDC, TanStartPointLocalCas3.X,TanStartPointLocalCas3.Y, TanEndPointLocalCas3.X, TanEndPointLocalCas3.Y, aEndPoint.X, aEndPoint.Y);
        cairo_set_line_width(mCairoDC, 3);
        cairo_stroke(mCairoDC);

// 4ème cas : (12) <=> MinDistTan / 2 et (34) <=> MinDistTan / 2
        // Coordonnées de TanStartPointLocal dans le repère R1
        TanStartPointLocalCas4.X = StartPointLocalR1.X + MinDistTan * 0.5 * aCoef;
        TanStartPointLocalCas4.Y = 0.0;
        cairo_matrix_transform_point(&RotateMatrixR0toR1, &TanStartPointLocalCas4.X, &TanStartPointLocalCas4.Y);
        cairo_matrix_transform_point(&TranslateMatrixR0toR1, &TanStartPointLocalCas4.X, &TanStartPointLocalCas4.Y);
        // Coordonnées de TanEndPointLocal dans le repère R1
        TanEndPointLocalCas4.X = EndPointR2.X + MinDistTan * 0.5 * aCoef;
        TanEndPointLocalCas4.Y = 0.0;
        cairo_matrix_transform_point(&RotateMatrixR0toR2, &TanEndPointLocalCas4.X, &TanEndPointLocalCas4.Y);
        cairo_matrix_transform_point(&TranslateMatrixR0toR2, &TanEndPointLocalCas4.X, &TanEndPointLocalCas4.Y);

        SetColor(0,1,1);
        DrawPoint(TanStartPointLocalCas4,3);
        DrawPoint(TanEndPointLocalCas4,3);

        cairo_move_to(mCairoDC, aStartPoint.X, aStartPoint.Y);
        cairo_curve_to(mCairoDC, TanStartPointLocalCas4.X,TanStartPointLocalCas4.Y, TanEndPointLocalCas4.X, TanEndPointLocalCas4.Y, aEndPoint.X, aEndPoint.Y);
        cairo_set_line_width(mCairoDC, 3);
        cairo_stroke(mCairoDC);

    }
}
Exemplo n.º 5
0
/*
 Sets gadget's background
*/
gboolean
libgadget_sidegadget_on_expose_event (GtkWidget *widget, GdkEventExpose *event, sidegadget_core_s *sidegadget)
{
	cairo_t *cr;
	
	double x0 = 5.0;
	double y0 = sidegadget->y_shape;
	double rect_width  = sidegadget->width_sidebar - 10;
	double rect_height = sidegadget->height;
	double radius = 20;
	double x1, y1;
	
	cr = gdk_cairo_create (widget->window);

	x1 = x0 + rect_width;
	y1 = y0 + rect_height;
	
	if (!rect_width || !rect_height)
		return;

	if ((rect_width/2) < radius) {
		if ((rect_height / 2) < radius) {
			cairo_move_to  (cr, x0, (y0 + y1)/2);
			cairo_curve_to (cr, x0 ,y0, x0, y0, (x0 + x1)/2, y0);
			cairo_curve_to (cr, x1, y0, x1, y0, x1, (y0 + y1)/2);
			cairo_curve_to (cr, x1, y1, x1, y1, (x1 + x0)/2, y1);
			cairo_curve_to (cr, x0, y1, x0, y1, x0, (y0 + y1)/2);
		} else {
			cairo_move_to  (cr, x0, y0 + radius);
			cairo_curve_to (cr, x0 ,y0, x0, y0, (x0 + x1)/2, y0);
			cairo_curve_to (cr, x1, y0, x1, y0, x1, y0 + radius);
			cairo_line_to (cr, x1 , y1 - radius);
			cairo_curve_to (cr, x1, y1, x1, y1, (x1 + x0)/2, y1);
			cairo_curve_to (cr, x0, y1, x0, y1, x0, y1- radius);
		}
	}
	else {
		if (rect_height/2<radius) {
			cairo_move_to  (cr, x0, (y0 + y1)/2);
			cairo_curve_to (cr, x0 , y0, x0 , y0, x0 + radius, y0);
			cairo_line_to (cr, x1 - radius, y0);
			cairo_curve_to (cr, x1, y0, x1, y0, x1, (y0 + y1)/2);
			cairo_curve_to (cr, x1, y1, x1, y1, x1 - radius, y1);
			cairo_line_to (cr, x0 + radius, y1);
			cairo_curve_to (cr, x0, y1, x0, y1, x0, (y0 + y1)/2);
		}
		else {
			cairo_move_to  (cr, x0, y0 + radius);
			cairo_curve_to (cr, x0 , y0, x0 , y0, x0 + radius, y0);
			cairo_line_to (cr, x1 - radius, y0);
			cairo_curve_to (cr, x1, y0, x1, y0, x1, y0 + radius);
			cairo_line_to (cr, x1 , y1 - radius);
			cairo_curve_to (cr, x1, y1, x1, y1, x1 - radius, y1);
			cairo_line_to (cr, x0 + radius, y1);
			cairo_curve_to (cr, x0, y1, x0, y1, x0, y1- radius);
		}
	}

	cairo_close_path (cr);

	cairo_set_source_rgba (cr,
	    					(float) sidegadget->color_gadget.red / 65535,
	    					(float) sidegadget->color_gadget.green / 65535,
						    (float) sidegadget->color_gadget.blue / 65535,
	    					sidegadget->transparency_gadget);

	cairo_fill_preserve (cr);

	cairo_set_source_rgba (cr, 0.0, 0.0, 0.0, 0.5);
	cairo_set_line_width (cr, 0.0);
	cairo_stroke (cr);
	cairo_destroy(cr);

	return FALSE;
}
Exemplo n.º 6
0
static void _draw_mode_toggle(cairo_t *cr, float x, float y, float width, float height, int type)
{
  cairo_save(cr);
  cairo_translate(cr, x, y);

  // border
  float border = MIN(width * .1, height * .1);
  cairo_set_source_rgba(cr, 0.0, 0.0, 0.0, 0.4);
  cairo_rectangle(cr, border, border, width - 2.0 * border, height - 2.0 * border);
  cairo_fill_preserve(cr);
  cairo_set_source_rgba(cr, 0.0, 0.0, 0.0, 0.5);
  cairo_set_line_width(cr, border);
  cairo_stroke(cr);

  // icon
  cairo_set_source_rgba(cr, 1.0, 1.0, 1.0, 0.5);
  cairo_move_to(cr, 2.0 * border, height - 2.0 * border);
  switch(type)
  {
    case DT_DEV_HISTOGRAM_LINEAR:
      cairo_line_to(cr, width - 2.0 * border, 2.0 * border);
      cairo_stroke(cr);
      break;
    case DT_DEV_HISTOGRAM_LOGARITHMIC:
      cairo_curve_to(cr, 2.0 * border, 0.33 * height, 0.66 * width, 2.0 * border, width - 2.0 * border,
                     2.0 * border);
      cairo_stroke(cr);
      break;
    case DT_DEV_HISTOGRAM_WAVEFORM:
    {
      cairo_pattern_t *pattern;
      pattern = cairo_pattern_create_linear(0.0, 1.5 * border, 0.0, height - 3.0 * border);

      cairo_pattern_add_color_stop_rgba(pattern, 0.0, 0.0, 0.0, 0.0, 0.5);
      cairo_pattern_add_color_stop_rgba(pattern, 0.2, 0.2, 0.2, 0.2, 0.5);
      cairo_pattern_add_color_stop_rgba(pattern, 0.5, 1.0, 1.0, 1.0, 0.5);
      cairo_pattern_add_color_stop_rgba(pattern, 0.6, 1.0, 1.0, 1.0, 0.5);
      cairo_pattern_add_color_stop_rgba(pattern, 1.0, 0.2, 0.2, 0.2, 0.5);

      cairo_rectangle(cr, 1.5 * border, 1.5 * border, (width - 3.0 * border) * 0.3, height - 3.0 * border);
      cairo_set_source(cr, pattern);
      cairo_fill(cr);

      cairo_save(cr);
      cairo_scale(cr, 1, -1);
      cairo_translate(cr, 0, -height);
      cairo_rectangle(cr, 1.5 * border + (width - 3.0 * border) * 0.2, 1.5 * border,
                      (width - 3.0 * border) * 0.6, height - 3.0 * border);
      cairo_set_source(cr, pattern);
      cairo_fill(cr);
      cairo_restore(cr);

      cairo_rectangle(cr, 1.5 * border + (width - 3.0 * border) * 0.7, 1.5 * border,
                      (width - 3.0 * border) * 0.3, height - 3.0 * border);
      cairo_set_source(cr, pattern);
      cairo_fill(cr);

      cairo_pattern_destroy(pattern);
      break;
    }
  }
  cairo_restore(cr);
}
Exemplo n.º 7
0
static void
marlin_text_renderer_render (GtkCellRenderer    *cell,
                             cairo_t            *cr,
                             GtkWidget          *widget,
                             const GdkRectangle *background_area,
                             const GdkRectangle *cell_area,
                             GtkCellRendererState flags)
{
    MarlinTextRenderer *text_renderer = MARLIN_TEXT_RENDERER (cell);
    GtkStyleContext *context;
    GtkStateFlags state;
    gint x0, x1, y0, y1;
    gint text_width;
    gint text_height;
    gint x_offset;
    gint y_offset;
    gint xpad, ypad;
    gfloat xalign, yalign;
    gboolean selected;

    /* setup the new widget */
    marlin_text_renderer_set_widget (text_renderer, widget);

    state = gtk_widget_get_state_flags (widget);
    if ((flags & GTK_CELL_RENDERER_SELECTED) == GTK_CELL_RENDERER_SELECTED)
    {
        state |= GTK_STATE_FLAG_SELECTED;
    }
    else if ((flags & GTK_CELL_RENDERER_PRELIT) == GTK_CELL_RENDERER_PRELIT
             && gtk_widget_get_state (widget) == GTK_STATE_PRELIGHT)
    {
        state = GTK_STATE_PRELIGHT;
    }
    else
    {
        state = gtk_widget_get_sensitive (widget) ? GTK_STATE_FLAG_NORMAL : GTK_STATE_INSENSITIVE;
    }

    /* render small/normal text depending on the zoom_level */
    if (text_renderer->zoom_level < MARLIN_ZOOM_LEVEL_NORMAL)
    {
        if (text_renderer->follow_prelit && (flags & GTK_CELL_RENDERER_PRELIT) != 0)
            pango_layout_set_attributes (text_renderer->layout, eel_pango_attr_list_small_underline_single ());
        else
            pango_layout_set_attributes (text_renderer->layout, eel_pango_attr_list_small ());
    } else {
        if (text_renderer->follow_prelit && (flags & GTK_CELL_RENDERER_PRELIT) != 0)
            pango_layout_set_attributes (text_renderer->layout, eel_pango_attr_list_underline_single ());
        else
            pango_layout_set_attributes (text_renderer->layout, NULL);
    }

    /* setup the wrapping */
    if (text_renderer->wrap_width < 0)
    {
        pango_layout_set_width (text_renderer->layout, -1);
        pango_layout_set_wrap (text_renderer->layout, PANGO_WRAP_CHAR);
    }
    else
    {
        pango_layout_set_width (text_renderer->layout, text_renderer->wrap_width * PANGO_SCALE);
        pango_layout_set_wrap (text_renderer->layout, text_renderer->wrap_mode);
    }

    /* ellipsize to max lines except for selected or prelit items */
    pango_layout_set_ellipsize (text_renderer->layout, PANGO_ELLIPSIZE_END);
    pango_layout_set_height (text_renderer->layout, -3);
    if ((flags & GTK_CELL_RENDERER_SELECTED) == GTK_CELL_RENDERER_SELECTED ||
            (flags & GTK_CELL_RENDERER_PRELIT) == GTK_CELL_RENDERER_PRELIT) {
        pango_layout_set_ellipsize (text_renderer->layout, PANGO_ELLIPSIZE_NONE);
    }

    gtk_cell_renderer_get_alignment (cell, &xalign, &yalign);
    if (xalign == 0.5f)
        pango_layout_set_alignment (text_renderer->layout, PANGO_ALIGN_CENTER);

    pango_layout_set_text (text_renderer->layout, text_renderer->text, -1);

    /* calculate the real text dimension */
    pango_layout_get_pixel_size (text_renderer->layout, &text_width, &text_height);


    /* take into account the state indicator (required for calculation) */
    if (text_renderer->follow_state)
    {
        text_width += 2 * text_renderer->focus_width;
        text_height += 2 * text_renderer->focus_width;
    }

    gtk_cell_renderer_get_padding (cell, &xpad, &ypad);

    /* calculate the real x-offset */
    x_offset = ((gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL) ? (1.0 - xalign) : xalign)
               * (cell_area->width - text_width - (2 * xpad));
    x_offset = MAX (x_offset, 0);

    /* calculate the real y-offset */
    y_offset = yalign * (cell_area->height - text_height - (2 * ypad));
    y_offset = MAX (y_offset, 0);

    context = gtk_widget_get_style_context (gtk_widget_get_parent (widget));
    gtk_style_context_save (context);
    gtk_style_context_set_state (context, state);

    selected = ((flags & GTK_CELL_RENDERER_SELECTED) == GTK_CELL_RENDERER_SELECTED && text_renderer->follow_state);

    /* render the state indicator */
    if (selected || text_renderer->background != NULL)
    {
        /* calculate the text bounding box (including the focus padding/width) */
        x0 = cell_area->x + x_offset;
        y0 = cell_area->y + y_offset;
        x1 = x0 + text_width;
        y1 = y0 + text_height;

        cairo_move_to (cr, x0 + 5, y0);
        cairo_line_to (cr, x1 - 5, y0);
        cairo_curve_to (cr, x1 - 5, y0, x1, y0, x1, y0 + 5);
        cairo_line_to (cr, x1, y1 - 5);
        cairo_curve_to (cr, x1, y1 - 5, x1, y1, x1 - 5, y1);
        cairo_line_to (cr, x0 + 5, y1);
        cairo_curve_to (cr, x0 + 5, y1, x0, y1, x0, y1 - 5);
        cairo_line_to (cr, x0, y0 + 5);
        cairo_curve_to (cr, x0, y0 + 5, x0, y0, x0 + 5, y0);

        GdkRGBA color;

        if(text_renderer->background != NULL && !selected)
        {
            if(!gdk_rgba_parse(&color, text_renderer->background))
            {
                g_critical("Can't parse this color value: %s", text_renderer->background);
                gtk_style_context_get_background_color (context, state, &color);
            }

        }
        else
        {
            gtk_style_context_get_background_color (context, state, &color);
        }
        gdk_cairo_set_source_rgba (cr, &color);
        cairo_fill (cr);
    }

    /* draw the focus indicator */
    if (text_renderer->follow_state && (flags & GTK_CELL_RENDERER_FOCUSED) != 0)
    {
        gtk_render_focus (context, cr, cell_area->x + x_offset, cell_area->y + y_offset, text_width, text_height);
    }

    /* get proper sizing for the layout drawing */
    if (text_renderer->follow_state)
    {
        text_width -= 2 * text_renderer->focus_width;
        text_height -= 2 * text_renderer->focus_width;
        x_offset += text_renderer->focus_width;
        y_offset += text_renderer->focus_width;
    }

    /* draw the text */
    if (xalign == 0.5f)
        x_offset = (cell_area->width - text_renderer->wrap_width)/2;

    gtk_render_layout (context, cr,
                       cell_area->x + x_offset + xpad,
                       cell_area->y + y_offset + ypad,
                       text_renderer->layout);

    gtk_style_context_restore (context);
}
Exemplo n.º 8
0
/**
 * uber_line_graph_render:
 * @graph: A #UberGraph.
 * @cr: A #cairo_t context.
 * @area: Full area to render contents within.
 * @line: The line to render.
 *
 * Render a particular line to the graph.
 *
 * Returns: None.
 * Side effects: None.
 */
static void
uber_line_graph_render_line (UberLineGraph *graph, /* IN */
                             cairo_t       *cr,    /* IN */
                             GdkRectangle  *area,  /* IN */
                             LineInfo      *line,  /* IN */
                             guint          epoch, /* IN */
                             gfloat         each)  /* IN */
{
	UberLineGraphPrivate *priv;
	UberRange pixel_range;
	GdkRectangle vis;
	guint x;
	guint last_x;
	gdouble y;
	gdouble last_y;
	gdouble val;
	gint i;

	g_return_if_fail(UBER_IS_LINE_GRAPH(graph));

	priv = graph->priv;
	uber_graph_get_content_area(UBER_GRAPH(graph), &vis);
	pixel_range.begin = area->y + 1;
	pixel_range.end = area->y + area->height;
	pixel_range.range = pixel_range.end - pixel_range.begin;
	/*
	 * Prepare cairo settings.
	 */
	uber_line_graph_stylize_line(graph, line, cr);
	/*
	 * Force a new path.
	 */
	cairo_new_path(cr);
	/*
	 * Draw the line contents as bezier curves.
	 */
	for (i = 0; i < line->raw_data->len; i++) {
		/*
		 * Retrieve data point.
		 */
		val = g_ring_get_index(line->raw_data, gdouble, i);
		/*
		 * Once we get to -INFINITY, we must be at the end of the data
		 * sequence.  This may not always be true in the future.
		 */
		if (val == -INFINITY) {
			break;
		}
		/*
		 * Translate value to coordinate system.
		 */
		if (!priv->scale(&priv->range, &pixel_range, &val, priv->scale_data)) {
			break;
		}
		/*
		 * Calculate X/Y coordinate.
		 */
		y = (gint)(RECT_BOTTOM(*area) - val) - .5;
		x = epoch - (each * i);
		if (i == 0) {
			/*
			 * Just move to the right position on first entry.
			 */
			cairo_move_to(cr, x, y);
			goto next;
		} else {
			/*
			 * Draw curve to data point using the last X/Y positions as
			 * control points.
			 */
			cairo_curve_to(cr,
			               last_x - (each / 2.),
			               last_y,
			               last_x - (each / 2.),
			               y, x, y);
		}
	  next:
		last_y = y;
		last_x = x;
	}
	/*
	 * Stroke the line content.
	 */
	cairo_stroke(cr);
}
Exemplo n.º 9
0
/**
 * uber_line_graph_render_fast:
 * @graph: A #UberGraph.
 *
 * XXX
 *
 * Returns: None.
 * Side effects: None.
 */
static void
uber_line_graph_render_fast (UberGraph    *graph, /* IN */
                             cairo_t      *cr,    /* IN */
                             GdkRectangle *rect,  /* IN */
                             guint         epoch, /* IN */
                             gfloat        each)  /* IN */
{
	UberLineGraphPrivate *priv;
	UberRange pixel_range;
	LineInfo *line;
	gdouble last_y;
	gdouble y;
	gint i;

	g_return_if_fail(UBER_IS_LINE_GRAPH(graph));
	g_return_if_fail(cr != NULL);
	g_return_if_fail(rect != NULL);

	priv = UBER_LINE_GRAPH(graph)->priv;
	pixel_range.begin = rect->y + 1;
	pixel_range.end = rect->y + rect->height;
	pixel_range.range = pixel_range.end - pixel_range.begin;
	/*
	 * Render most recent data point for each line.
	 */
	for (i = 0; i < priv->lines->len; i++) {
		line = &g_array_index(priv->lines, LineInfo, i);
		uber_line_graph_stylize_line(UBER_LINE_GRAPH(graph), line, cr);
		/*
		 * Calculate positions.
		 */
		y = g_ring_get_index(line->raw_data, gdouble, 0);
		last_y = g_ring_get_index(line->raw_data, gdouble, 1);
		/*
		 * Don't try to draw before we have real values.
		 */
		if ((isnan(y) || isinf(y)) || (isnan(last_y) || isinf(last_y))) {
			continue;
		}
		/*
		 * Translate to coordinate scale.
		 */
		if (!priv->scale(&priv->range, &pixel_range, &y, priv->scale_data) ||
		    !priv->scale(&priv->range, &pixel_range, &last_y, priv->scale_data)) {
			continue;
		}
		/*
		 * Translate position from bottom right corner.
		 */
		y = (gint)(RECT_BOTTOM(*rect) - y) - .5;
		last_y = (gint)(RECT_BOTTOM(*rect) - last_y) - .5;
		/*
		 * Convert relative position to fixed from bottom pixel.
		 */
		cairo_new_path(cr);
		cairo_move_to(cr, epoch, y);
		cairo_curve_to(cr,
		               epoch - (each / 2.),
		               y,
		               epoch - (each / 2.),
		               last_y,
		               epoch - each,
		               last_y);
		cairo_stroke(cr);
	}
}
Exemplo n.º 10
0
static gboolean
screen_saver_floater_do_draw (ScreenSaver        *screen_saver,
                              ScreenSaverFloater *floater,
                              cairo_t            *context)
{
    gint size;
    CachedSource *source;

    size = CLAMP ((int) (FLOATER_MAX_SIZE * floater->scale),
                  FLOATER_MIN_SIZE, FLOATER_MAX_SIZE);

    source = g_hash_table_lookup (screen_saver->cached_sources, GINT_TO_POINTER (size));

    if (source == NULL)
    {
        GdkPixbuf *pixbuf;
        GError *error;

        pixbuf = NULL;
        error = NULL;

        pixbuf = gdk_pixbuf_new_from_file_at_size (screen_saver->filename, size, -1,
                 &error);
        if (pixbuf == NULL)
        {
            g_assert (error != NULL);
            g_printerr ("%s", _(error->message));
            g_error_free (error);
            return FALSE;
        }

        if (gdk_pixbuf_get_has_alpha (pixbuf))
            gamma_correct (pixbuf);

        gdk_cairo_set_source_pixbuf (context, pixbuf, 0.0, 0.0);

        source = cached_source_new (cairo_get_source (context),
                                    gdk_pixbuf_get_width (pixbuf),
                                    gdk_pixbuf_get_height (pixbuf));
        g_object_unref (pixbuf);
        g_hash_table_insert (screen_saver->cached_sources, GINT_TO_POINTER (size),
                             source);
    }

    cairo_save (context);

    if (screen_saver->should_do_rotations && (abs (floater->angle) > G_MINDOUBLE))
    {
        floater->bounds.width = G_SQRT2 * source->width + 2;
        floater->bounds.height = G_SQRT2 * source->height + 2;
        floater->bounds.x = (int) (floater->position.x - .5 * G_SQRT2 * source->width) - 1;
        floater->bounds.y = (int) (floater->position.y - .5 * G_SQRT2 * source->height) - 1;

        cairo_translate (context,
                         trunc (floater->position.x),
                         trunc (floater->position.y));
        cairo_rotate (context, floater->angle);
        cairo_translate (context,
                         -trunc (floater->position.x),
                         -trunc (floater->position.y));
    }
    else
    {
        floater->bounds.width = source->width + 2;
        floater->bounds.height = source->height + 2;
        floater->bounds.x = (int) (floater->position.x - .5 * source->width) - 1;
        floater->bounds.y = (int) (floater->position.y - .5 * source->height) - 1;
    }

    cairo_translate (context,
                     trunc (floater->position.x - .5 * source->width),
                     trunc (floater->position.y - .5 * source->height));

    cairo_set_source (context, source->pattern);

    cairo_rectangle (context,
                     trunc (.5 * (source->width - floater->bounds.width)),
                     trunc (.5 * (source->height - floater->bounds.height)),
                     floater->bounds.width, floater->bounds.height);

    cairo_clip (context);
    cairo_paint_with_alpha (context, floater->opacity);
    cairo_restore (context);

    if (screen_saver->should_show_paths && (floater->path != NULL))
    {
        gdouble dash_pattern[] = { 5.0 };
        gint size;

        size = CLAMP ((int) (FLOATER_MAX_SIZE * floater->path_start_scale),
                      FLOATER_MIN_SIZE, FLOATER_MAX_SIZE);

        cairo_save (context);
        cairo_set_source_rgba (context, 1.0, 1.0, 1.0, .2 * floater->opacity);
        cairo_move_to (context,
                       floater->path->start_point.x,
                       floater->path->start_point.y);
        cairo_curve_to (context,
                        floater->path->start_control_point.x,
                        floater->path->start_control_point.y,
                        floater->path->end_control_point.x,
                        floater->path->end_control_point.y,
                        floater->path->end_point.x,
                        floater->path->end_point.y);
        cairo_set_line_cap (context, CAIRO_LINE_CAP_ROUND);
        cairo_stroke (context);
        cairo_set_source_rgba (context, 1.0, 0.0, 0.0, .5 * floater->opacity);
        cairo_rectangle (context,
                         floater->path->start_point.x - 3,
                         floater->path->start_point.y - 3,
                         6, 6);
        cairo_fill (context);
        cairo_set_source_rgba (context, 0.0, 0.5, 0.0, .5 * floater->opacity);
        cairo_arc (context,
                   floater->path->start_control_point.x,
                   floater->path->start_control_point.y,
                   3, 0.0, 2.0 * G_PI);
        cairo_stroke (context);
        cairo_set_source_rgba (context, 0.5, 0.0, 0.5, .5 * floater->opacity);
        cairo_arc (context,
                   floater->path->end_control_point.x,
                   floater->path->end_control_point.y,
                   3, 0.0, 2.0 * G_PI);
        cairo_stroke (context);
        cairo_set_source_rgba (context, 0.0, 0.0, 1.0, .5 * floater->opacity);
        cairo_rectangle (context,
                         floater->path->end_point.x - 3,
                         floater->path->end_point.y - 3,
                         6, 6);
        cairo_fill (context);

        cairo_set_dash (context, dash_pattern, G_N_ELEMENTS (dash_pattern), 0);
        cairo_set_source_rgba (context, .5, .5, .5, .2 * floater->scale);
        cairo_move_to (context, floater->path->start_point.x,
                       floater->path->start_point.y);
        cairo_line_to (context, floater->path->start_control_point.x,
                       floater->path->start_control_point.y);
        cairo_stroke (context);

        cairo_move_to (context, floater->path->end_point.x,
                       floater->path->end_point.y);
        cairo_line_to (context, floater->path->end_control_point.x,
                       floater->path->end_control_point.y);
        cairo_stroke (context);

        cairo_restore (context);
    }

    return TRUE;
}
void ofCairoRenderer::drawPath(const ofShape & path,bool is_subpath){
	if(!surface || !cr) return;
	const vector<ofShape::Command> & commands = path.getCommands();
	if(is_subpath)
		cairo_new_sub_path(cr);
	else
		cairo_new_path(cr);
	for(int i=0; i<(int)commands.size(); i++){
		switch(commands[i].type){
		case ofShape::Command::lineTo:
			curvePoints.clear();
			cairo_line_to(cr,commands[i].to.x,commands[i].to.y);
			break;


		case ofShape::Command::curveTo:
			curvePoints.push_back(commands[i].to);

			//code adapted from ofxVectorGraphics to convert catmull rom to bezier
			if(curvePoints.size()==4){
				ofPoint p1=curvePoints[0];
				ofPoint p2=curvePoints[1];
				ofPoint p3=curvePoints[2];
				ofPoint p4=curvePoints[3];

				//SUPER WEIRD MAGIC CONSTANT = 1/6 (this works 100% can someone explain it?)
				ofPoint cp1 = p2 + ( p3 - p1 ) * (1.0/6);
				ofPoint cp2 = p3 + ( p2 - p4 ) * (1.0/6);

				cairo_curve_to( cr, cp1.x, cp1.y, cp2.x, cp2.y, p3.x, p3.y );
				curvePoints.pop_front();
			}
			break;


		case ofShape::Command::bezierTo:
			curvePoints.clear();
			cairo_curve_to(cr,commands[i].cp1.x,commands[i].cp1.y,commands[i].cp2.x,commands[i].cp2.y,commands[i].to.x,commands[i].to.y);
			break;

		case ofShape::Command::quadBezierTo:
			curvePoints.clear();
			cairo_curve_to(cr,commands[i].cp1.x,commands[i].cp1.y,commands[i].cp2.x,commands[i].cp2.y,commands[i].to.x,commands[i].to.y);
			break;


		case ofShape::Command::arc:
			curvePoints.clear();
			// elliptic arcs not directly supported in cairo, lets scale y
			if(commands[i].radiusX!=commands[i].radiusY){
				float ellipse_ratio = commands[i].radiusY/commands[i].radiusX;
				pushMatrix();
				translate(0,-commands[i].to.y*ellipse_ratio);
				scale(1,ellipse_ratio);
				translate(0,commands[i].to.y*1/ellipse_ratio);
				cairo_arc(cr,commands[i].to.x,commands[i].to.y,commands[i].radiusX,commands[i].angleBegin,commands[i].angleEnd);
				//cairo_set_matrix(cr,&stored_matrix);
				popMatrix();
			}else{
				cairo_arc(cr,commands[i].to.x,commands[i].to.y,commands[i].radiusX,commands[i].angleBegin,commands[i].angleEnd);
			}
			break;
		}
	}

	if(path.isClosed()){
		cairo_close_path(cr);
	}

	const vector<ofShape> &subpaths = path.getSubShapes();
	for(int i=0;i<(int)subpaths.size();i++){
		drawPath(subpaths[i],true);
	}

	cairo_fill_rule_t cairo_poly_mode;
	if(path.getWindingMode()==OF_POLY_WINDING_ODD) cairo_poly_mode=CAIRO_FILL_RULE_EVEN_ODD;
	else cairo_poly_mode=CAIRO_FILL_RULE_WINDING;

	cairo_set_fill_rule(cr,cairo_poly_mode);


	if(path.getStrokeWidth()>0){
		ofColor c = path.getStrokeColor() * ofGetStyle().color;
		c.a = path.getStrokeColor().a/255. * ofGetStyle().color.a;
		cairo_set_source_rgba(cr, (float)c.r/255.0, (float)c.g/255.0, (float)c.b/255.0, (float)c.a/255.0);
		cairo_set_line_width( cr, path.getStrokeWidth() );
		if(path.isFilled())
			cairo_stroke_preserve( cr );
		else
			cairo_stroke( cr );
	}
	if(path.isFilled()){
		ofColor c = path.getFillColor() * ofGetStyle().color;
		c.a = path.getFillColor().a/255. * ofGetStyle().color.a;
		cairo_set_source_rgba(cr, (float)c.r/255.0, (float)c.g/255.0, (float)c.b/255.0, (float)c.a/255.0);
		cairo_fill( cr );
	}
}
Exemplo n.º 12
0
static void
gtk_css_image_builtin_draw_check (GtkCssImage *image,
                                  cairo_t     *cr,
                                  double       width,
                                  double       height,
                                  gboolean     checked,
                                  gboolean     inconsistent)
{
  GtkCssImageBuiltin *builtin = GTK_CSS_IMAGE_BUILTIN (image);
  gint x, y, exterior_size, interior_size, thickness, pad;

  exterior_size = MIN (width, height);

  if (exterior_size % 2 == 0) /* Ensure odd */
    exterior_size -= 1;

  /* FIXME: thickness */
  thickness = 1;
  pad = thickness + MAX (1, (exterior_size - 2 * thickness) / 9);
  interior_size = MAX (1, exterior_size - 2 * pad);

  if (interior_size < 7)
    {
      interior_size = 7;
      pad = MAX (0, (exterior_size - interior_size) / 2);
    }

  x = - (1 + exterior_size - (gint) width) / 2;
  y = - (1 + exterior_size - (gint) height) / 2;

  if (builtin->border_width > 0)
    {
      cairo_set_line_width (cr, builtin->border_width);

      cairo_rectangle (cr, x + 0.5, y + 0.5, exterior_size - 1, exterior_size - 1);
      gdk_cairo_set_source_rgba (cr, &builtin->bg_color);
      cairo_fill_preserve (cr);

      gdk_cairo_set_source_rgba (cr, &builtin->border_color);
      cairo_stroke (cr);
    }

  gdk_cairo_set_source_rgba (cr, &builtin->fg_color);

  if (inconsistent)
    {
      int line_thickness = MAX (1, (3 + interior_size * 2) / 7);

      cairo_rectangle (cr,
		       x + pad,
		       y + pad + (1 + interior_size - line_thickness) / 2,
		       interior_size,
		       line_thickness);
      cairo_fill (cr);
    }
  else
    {
      if (checked)
        {
          cairo_translate (cr,
                           x + pad, y + pad);

          cairo_scale (cr, interior_size / 7., interior_size / 7.);

          cairo_rectangle (cr, 0, 0, 7, 7);
          cairo_clip (cr);

          cairo_move_to  (cr, 7.0, 0.0);
          cairo_line_to  (cr, 7.5, 1.0);
          cairo_curve_to (cr, 5.3, 2.0,
                          4.3, 4.0,
                          3.5, 7.0);
          cairo_curve_to (cr, 3.0, 5.7,
                          1.3, 4.7,
                          0.0, 4.7);
          cairo_line_to  (cr, 0.2, 3.5);
          cairo_curve_to (cr, 1.1, 3.5,
                          2.3, 4.3,
                          3.0, 5.0);
          cairo_curve_to (cr, 1.0, 3.9,
                          2.4, 4.1,
                          3.2, 4.9);
          cairo_curve_to (cr, 3.5, 3.1,
                          5.2, 2.0,
                          7.0, 0.0);

          cairo_fill (cr);
        }
    }
}
/*
  Set gadget's background
*/
gboolean
on_expose_event (GtkWidget *widget, GdkEventExpose *event, temp_notifier_gadget_s *core)
{	
  cairo_t *cr;

  double x0      = 5.0;
  double y0      = 15.0;
  double rect_width  = core->width - 10;
  double rect_height = core->height - 25;
  double radius = 40;
  double x1,y1;
	
  cr = gdk_cairo_create (widget->window);
	
  /* Set gadget background transparent */
  cairo_set_source_rgba (cr, 1.0, 1.0, 1.0, 0.0);
  cairo_set_operator (cr, CAIRO_OPERATOR_SOURCE);
  cairo_paint (cr);

  x1 = x0 + rect_width;
  y1 = y0 + rect_height;

  if (!rect_width || !rect_height)
    return;

  cairo_move_to  (cr, x0, (y0 + y1)/2);
  cairo_curve_to (cr, x0 ,y0, x0, y0, (x0 + x1)/2, y0);
  cairo_curve_to (cr, x1, y0, x1, y0, x1, (y0 + y1)/2);
  cairo_curve_to (cr, x1, y1, x1, y1, (x1 + x0)/2, y1);
  cairo_curve_to (cr, x0, y1, x0, y1, x0, (y0 + y1)/2);

  cairo_close_path (cr);

  cairo_set_source_rgba (cr,
                         (float) core->gadget.red / 65535.0,
                         (float) core->gadget.green / 65535.0,
                         (float) core->gadget.blue / 65535.0,
                         1);
	
  cairo_fill_preserve (cr);

  switch (core->border_value)
  {
    case 1:
      gdk_color_parse ("#CC4400", &core->border);
      break;
    case 2:
      gdk_color_parse ("#CC6600", &core->border);
      break;
    case 3:
      gdk_color_parse ("#CCBB00", &core->border);
      break;
    case 4:
      gdk_color_parse ("#CCDD00", &core->border);
      break;
    case 5:
      gdk_color_parse ("#99DD00", &core->border);
      break;
    case 6:
      gdk_color_parse ("#00EE44", &core->border);
      break;
    case 7: /* Super green */
      gdk_color_parse ("#00BB44", &core->border);
      break;
    case -1: /* Super red */
      gdk_color_parse ("#002200", &core->border);
      break;
    default:
      gdk_color_parse ("#CCCCCC", &core->border);
      break;
    }

  cairo_set_source_rgba (cr,
                         (float) core->border.red / 65535.0,
                         (float) core->border.green / 65535.0,
                         (float) core->border.blue / 65535.0,
                         core->border_transparency);

  cairo_set_line_width (cr, 3.0);
  cairo_stroke (cr);
  cairo_destroy(cr);

  return FALSE;
}
Exemplo n.º 14
0
static void
schgui_cairo_path_draw(SchGUICairoDrawItem *item, cairo_t *cairo)
{
    if (cairo != NULL)
    {
        SchGUICairoPathPrivate *privat = SCHGUI_CAIRO_PATH_GET_PRIVATE(item);

        if (privat != NULL)
        {
            GSList *node;
            SchPathCommand *command;

            cairo_set_source_rgba(cairo, privat->red, privat->green, privat->blue, privat->alpha);

            cairo_set_line_width(cairo, privat->line_width);

            node = privat->commands;

            while (node != NULL)
            {
                command = SCH_PATH_COMMAND(node->data);

                switch (command->type)
                {
                    case SCH_PATH_COMMAND_INVALID:
                        g_debug("SchGUICairoPath: invalid path command");
                        break;

                    case SCH_PATH_COMMAND_CLOSEPATH:
                        cairo_close_path(cairo);
                        break;

                    case SCH_PATH_COMMAND_CURVETO_ABS:
                        cairo_curve_to(
                            cairo,
                            command->curveto.x[0], command->curveto.y[0],
                            command->curveto.x[1], command->curveto.y[1],
                            command->curveto.x[2], command->curveto.y[2]
                            );
                        break;

                    case SCH_PATH_COMMAND_CURVETO_REL:
                        cairo_rel_curve_to(
                            cairo,
                            command->curveto.x[0], command->curveto.y[0],
                            command->curveto.x[1], command->curveto.y[1],
                            command->curveto.x[2], command->curveto.y[2]
                            );
                        break;

                    case SCH_PATH_COMMAND_LINETO_ABS:
                        cairo_line_to(cairo, command->lineto.x, command->lineto.y);
                        break;

                    case SCH_PATH_COMMAND_LINETO_REL:
                        cairo_rel_line_to(cairo, command->lineto.x, command->lineto.y);
                        break;

                    case SCH_PATH_COMMAND_MOVETO_ABS:
                        cairo_move_to(cairo, command->moveto.x, command->moveto.y);
                        break;

                    case SCH_PATH_COMMAND_MOVETO_REL:
                        cairo_rel_move_to(cairo, command->moveto.x, command->moveto.y);
                        break;

                    default:
                        g_debug("SchGUICairoPath: unknown path command");
                }

                node = g_slist_next(node);
            }

            if (privat->solid)
            {
                cairo_fill_preserve(cairo);
            }

            cairo_stroke(cairo);
        }
    }
}
Exemplo n.º 15
0
/*
 * Can be called recursively.
 * If optimize_stroke == false, the view Rect is not used.
 */
static void
feed_curve_to_cairo(cairo_t *cr, Geom::Curve const &c, Geom::Affine const & trans, Geom::Rect view, bool optimize_stroke)
{
    if( is_straight_curve(c) )
    {
        Geom::Point end_tr = c.finalPoint() * trans;
        if (!optimize_stroke) {
            cairo_line_to(cr, end_tr[0], end_tr[1]);
        } else {
            Geom::Rect swept(c.initialPoint()*trans, end_tr);
            if (swept.intersects(view)) {
                cairo_line_to(cr, end_tr[0], end_tr[1]);
            } else {
                cairo_move_to(cr, end_tr[0], end_tr[1]);
            }
        }
    }
    else if(Geom::QuadraticBezier const *quadratic_bezier = dynamic_cast<Geom::QuadraticBezier const*>(&c)) {
        std::vector<Geom::Point> points = quadratic_bezier->points();
        points[0] *= trans;
        points[1] *= trans;
        points[2] *= trans;
        Geom::Point b1 = points[0] + (2./3) * (points[1] - points[0]);
        Geom::Point b2 = b1 + (1./3) * (points[2] - points[0]);
        if (!optimize_stroke) {
            cairo_curve_to(cr, b1[0], b1[1], b2[0], b2[1], points[2][0], points[2][1]);
        } else {
            Geom::Rect swept(points[0], points[2]);
            swept.expandTo(points[1]);
            if (swept.intersects(view)) {
                cairo_curve_to(cr, b1[0], b1[1], b2[0], b2[1], points[2][0], points[2][1]);
            } else {
                cairo_move_to(cr, points[2][0], points[2][1]);
            }
        }
    }
    else if(Geom::CubicBezier const *cubic_bezier = dynamic_cast<Geom::CubicBezier const*>(&c)) {
        std::vector<Geom::Point> points = cubic_bezier->points();
        //points[0] *= trans; // don't do this one here for fun: it is only needed for optimized strokes
        points[1] *= trans;
        points[2] *= trans;
        points[3] *= trans;
        if (!optimize_stroke) {
            cairo_curve_to(cr, points[1][0], points[1][1], points[2][0], points[2][1], points[3][0], points[3][1]);
        } else {
            points[0] *= trans;  // didn't transform this point yet
            Geom::Rect swept(points[0], points[3]);
            swept.expandTo(points[1]);
            swept.expandTo(points[2]);
            if (swept.intersects(view)) {
                cairo_curve_to(cr, points[1][0], points[1][1], points[2][0], points[2][1], points[3][0], points[3][1]);
            } else {
                cairo_move_to(cr, points[3][0], points[3][1]);
            }
        }
    }
//    else if(Geom::SVGEllipticalArc const *svg_elliptical_arc = dynamic_cast<Geom::SVGEllipticalArc *>(c)) {
//        //TODO: get at the innards and spit them out to cairo
//    }
    else {
        //this case handles sbasis as well as all other curve types
        Geom::Path sbasis_path = Geom::cubicbezierpath_from_sbasis(c.toSBasis(), 0.1);

        //recurse to convert the new path resulting from the sbasis to svgd
        for(Geom::Path::iterator iter = sbasis_path.begin(); iter != sbasis_path.end(); ++iter) {
            feed_curve_to_cairo(cr, *iter, trans, view, optimize_stroke);
        }
    }
}
Exemplo n.º 16
0
void CanvasCairo::pathCubicTo(float x1, float y1, float x2, float y2, float x3, float y3) {
	cairo_curve_to(_context, x1, y1, x2, y2, x3, y3);
}
Exemplo n.º 17
0
void gfxContext::CurveTo(gfxPoint pt1, gfxPoint pt2, gfxPoint pt3)
{
    cairo_curve_to(mCairo, pt1.x, pt1.y, pt2.x, pt2.y, pt3.x, pt3.y);
}
static void
clearlooks_glossy_draw_checkbox (cairo_t *cr,
                          const ClearlooksColors  *colors,
                          const WidgetParameters  *widget,
                          const CheckboxParameters *checkbox,
                          int x, int y, int width, int height)
{
	const CairoColor *border;
	const CairoColor *dot; 
	gboolean inconsistent = FALSE;
	gboolean draw_bullet = (checkbox->shadow_type == GTK_SHADOW_IN);

	inconsistent = (checkbox->shadow_type == GTK_SHADOW_ETCHED_IN);
	draw_bullet |= inconsistent;
	
	if (widget->disabled)
	{
		border = &colors->shade[5];
		dot    = &colors->shade[6];
	}
	else
	{
		if (widget->prelight)
			border = &colors->spot[2];
		else		
			border = &colors->shade[6];
		dot    = &colors->text[GTK_STATE_NORMAL];
	}

	cairo_translate (cr, x, y);
	cairo_set_line_width (cr, 1);
	
	if (widget->xthickness > 2 && widget->ythickness > 2)
	{
		widget->style_functions->draw_inset (cr, &widget->parentbg, 0, 0, 
                                           width, height, (widget->radius > 0)? 1 : 0, CR_CORNER_ALL);
		
		/* Draw the rectangle for the checkbox itself */
		ge_cairo_rounded_rectangle (cr, 1.5, 1.5, 
                                  width-3, height-3, (widget->radius > 0)? 1 : 0, CR_CORNER_ALL);
	}
	else
	{
		/* Draw the rectangle for the checkbox itself */
		ge_cairo_rounded_rectangle (cr, 0.5, 0.5, 
                                  width-1, height-1, (widget->radius > 0)? 1 : 0, CR_CORNER_ALL);
	}
	
	if (!widget->disabled)
	{
		if (widget->prelight)
			clearlooks_set_mixed_color (cr, &colors->base[0], &colors->spot[1], 0.5);
		else
			ge_cairo_set_color (cr, &colors->base[0]);
		cairo_fill_preserve (cr);
	}
	
	ge_cairo_set_color (cr, border);
	cairo_stroke (cr);

	if (draw_bullet)
	{
		if (inconsistent) /* Inconsistent */
		{
			cairo_set_line_width (cr, 2.0);
			cairo_move_to (cr, 3, height*0.5);
			cairo_line_to (cr, width-3, height*0.5);
		}
		else
		{
			cairo_set_line_width (cr, 1.7);
			cairo_move_to (cr, 0.5 + (width*0.2), (height*0.5));
			cairo_line_to (cr, 0.5 + (width*0.4), (height*0.7));
		
			cairo_curve_to (cr, 0.5 + (width*0.4), (height*0.7),
			                    0.5 + (width*0.5), (height*0.4),
			                    0.5 + (width*0.70), (height*0.25));

		}
		
		ge_cairo_set_color (cr, dot);
		cairo_stroke (cr);
	}
}
Exemplo n.º 19
0
static cairo_status_t
twin_scaled_font_render_glyph (cairo_scaled_font_t  *scaled_font,
			       unsigned long         glyph,
			       cairo_t              *cr,
			       cairo_text_extents_t *metrics)
{
    double x1, y1, x2, y2, x3, y3;
    double marginl;
    twin_scaled_properties_t *props;
    twin_snap_info_t info;
    const int8_t *b;
    const int8_t *g;
    int8_t w;
    double gw;

    props = cairo_scaled_font_get_user_data (scaled_font, &twin_properties_key);

    /* Save glyph space, we need it when stroking */
    cairo_save (cr);

    /* center the pen */
    cairo_translate (cr, props->penx * .5, -props->peny * .5);

    /* small-caps */
    if (props->face_props->smallcaps && glyph >= 'a' && glyph <= 'z') {
	glyph += 'A' - 'a';
	/* 28 and 42 are small and capital letter heights of the glyph data */
	cairo_scale (cr, 1, 28. / 42);
    }

    /* slant */
    if (props->face_props->slant != CAIRO_FONT_SLANT_NORMAL) {
	cairo_matrix_t shear = { 1, 0, -.2, 1, 0, 0};
	cairo_transform (cr, &shear);
    }

    b = _cairo_twin_outlines +
	_cairo_twin_charmap[unlikely (glyph >= ARRAY_LENGTH (_cairo_twin_charmap)) ? 0 : glyph];
    g = twin_glyph_draw(b);
    w = twin_glyph_right(b);
    gw = F(w);

    marginl = props->marginl;

    /* monospace */
    if (props->face_props->monospace) {
	double monow = F(24);
	double extra =  props->penx + props->marginl + props->marginr;
	cairo_scale (cr, (monow + extra) / (gw + extra), 1);
	gw = monow;

	/* resnap margin for new transform */
	{
	    double x, y, x_scale, x_scale_inv;
	    x = 1; y = 0;
	    compute_hinting_scale (cr, x, y, &x_scale, &x_scale_inv);
	    marginl = SNAPXI (marginl);
	}
    }

    cairo_translate (cr, marginl, 0);

    /* stretch */
    cairo_scale (cr, props->stretch, 1);

    if (props->snap)
	twin_compute_snap (cr, &info, b);
    else
	info.n_snap_x = info.n_snap_y = 0;

    /* advance width */
    metrics->x_advance = gw * props->stretch + props->penx + props->marginl + props->marginr;

    /* glyph shape */
    for (;;) {
	switch (*g++) {
	case 'M':
	    cairo_close_path (cr);
	    /* fall through */
	case 'm':
	    x1 = SNAPX(*g++);
	    y1 = SNAPY(*g++);
	    cairo_move_to (cr, x1, y1);
	    continue;
	case 'L':
	    cairo_close_path (cr);
	    /* fall through */
	case 'l':
	    x1 = SNAPX(*g++);
	    y1 = SNAPY(*g++);
	    cairo_line_to (cr, x1, y1);
	    continue;
	case 'C':
	    cairo_close_path (cr);
	    /* fall through */
	case 'c':
	    x1 = SNAPX(*g++);
	    y1 = SNAPY(*g++);
	    x2 = SNAPX(*g++);
	    y2 = SNAPY(*g++);
	    x3 = SNAPX(*g++);
	    y3 = SNAPY(*g++);
	    cairo_curve_to (cr, x1, y1, x2, y2, x3, y3);
	    continue;
	case 'E':
	    cairo_close_path (cr);
	    /* fall through */
	case 'e':
	    cairo_restore (cr); /* restore glyph space */
	    cairo_set_tolerance (cr, 0.01);
	    cairo_set_line_join (cr, CAIRO_LINE_JOIN_ROUND);
	    cairo_set_line_cap (cr, CAIRO_LINE_CAP_ROUND);
	    cairo_set_line_width (cr, 1);
	    cairo_scale (cr, props->penx, props->peny);
	    cairo_stroke (cr);
	    break;
	case 'X':
	    /* filler */
	    continue;
	}
	break;
    }

    return CAIRO_STATUS_SUCCESS;
}
void wxSVGCanvasPathCairo::CurveToCubicImpl(double x1, double y1, double x2,
		double y2, double x, double y) {
	cairo_curve_to(m_cr, x1, y1, x2, y2, x, y);
}
Exemplo n.º 21
0
void Drawer::DrawCurve(const Point& aPrevPoint, const Point& aStartPoint, const Point& aEndPoint, const Point& aNextPoint, double& aCoef)
{
    if (aCoef < 0.0)
        aCoef = 0.0;
    else if (aCoef > 1.0)
        aCoef = 1.0;

    double AngleRadianR0toR1 = 0.0;
    cairo_matrix_t TranslateMatrixR0toR1;
    cairo_matrix_t RotateMatrixR0toR1;
    Point StartPointInR1 = aStartPoint;
    Point EndPointInR1 = aEndPoint;

    double AngleRadianR0toR2 = 0.0;
    cairo_matrix_t TranslateMatrixR0toR2;
    cairo_matrix_t RotateMatrixR0toR2;
    Point StartPointInR2 = aStartPoint;
    Point EndPointInR2 = aEndPoint;

    double DistTanStart  = 0.0;
    double DistTanEnd    = 0.0;

    Point StartTanPoint(0.0,0.0);
    Point StartTanPointInR1(0,0);
    Point EndTanPoint(0.0,0.0);
    Point EndTanPointInR2(0,0);

    // Il faut que 'aPrevPoint' et 'aStartPoint' soit non confondu et 'aEndPoint' et 'aNextPoint' aussi
    if ((aPrevPoint != aStartPoint) && (aEndPoint != aNextPoint))
    {
        // Calcul de l'angle de rotation du nouveau repère R1 (aPrevPoint/aStartPoint)
        AngleRadianR0toR1 = atan2 (aStartPoint.Y - aPrevPoint.Y, aStartPoint.X - aPrevPoint.X);

        // Translation du repère au point 'aPrevPoint'
        cairo_matrix_init_translate(&TranslateMatrixR0toR1, aPrevPoint.X, aPrevPoint.Y);
        // Rotation du repère d'angle 'AngleRadianR1'
        cairo_matrix_init_rotate(&RotateMatrixR0toR1, AngleRadianR0toR1);

        // Calcul des coordonnées des points aStartPoint, aEndPoint, TanStartPointLocal dans le repère R1
        // Point B et C R0 => Point B et C R1
        cairo_matrix_invert(&TranslateMatrixR0toR1);
        cairo_matrix_transform_point(&TranslateMatrixR0toR1, &EndPointInR1.X, &EndPointInR1.Y);
        cairo_matrix_transform_point(&TranslateMatrixR0toR1, &StartPointInR1.X, &StartPointInR1.Y);
        cairo_matrix_invert(&RotateMatrixR0toR1);
        cairo_matrix_transform_point(&RotateMatrixR0toR1, &EndPointInR1.X, &EndPointInR1.Y);
        cairo_matrix_transform_point(&RotateMatrixR0toR1, &StartPointInR1.X, &StartPointInR1.Y);

        // Coordonnées de StartPointTan dans le repère R1
        StartTanPointInR1.X = EndPointInR1.X;
        StartTanPointInR1.Y = 0.0;

        // Sauvegarde de la distance du point pour le tracer de la tangente
        DistTanStart = abs(StartTanPointInR1.X - StartPointInR1.X);

        /////////////

        // Calcul de l'angle de rotation du nouveau repère R1 (aPrevPoint/aStartPoint)
        AngleRadianR0toR2 = atan2 (aEndPoint.Y - aNextPoint.Y, aEndPoint.X - aNextPoint.X);

        // Translation du repère au point 'aNextPoint'
        cairo_matrix_init_translate(&TranslateMatrixR0toR2, aNextPoint.X, aNextPoint.Y);
        // Rotation du repère d'angle 'AngleRadianR0toR2'
        cairo_matrix_init_rotate(&RotateMatrixR0toR2, AngleRadianR0toR2);

        // Calcul des coordonnées du Point aStartPoint dans le repère R2
        // Point B et C R0 => Point B et C R2
        cairo_matrix_invert(&TranslateMatrixR0toR2);
        cairo_matrix_transform_point(&TranslateMatrixR0toR2, &StartPointInR2.X, &StartPointInR2.Y);
        cairo_matrix_transform_point(&TranslateMatrixR0toR2, &EndPointInR2.X, &EndPointInR2.Y);
        cairo_matrix_invert(&RotateMatrixR0toR2);
        cairo_matrix_transform_point(&RotateMatrixR0toR2, &StartPointInR2.X, &StartPointInR2.Y);
        cairo_matrix_transform_point(&RotateMatrixR0toR2, &EndPointInR2.X, &EndPointInR2.Y);

        // Coordonnées de EndPointTan dans le repère R2
        EndTanPointInR2.X = StartPointInR2.X;
        EndTanPointInR2.Y = 0.0;

        // Sauvegarde de la distance du point pour le tracer de la tangente
        DistTanEnd = abs(EndTanPointInR2.X - EndPointInR2.X);

        // Cas : (12) <=> DistTan12 / 2 et (34) <=> DistTan34 / 2
        // Coordonnées de TanStartPoint dans le repère R1
        StartTanPoint.X = StartPointInR1.X + DistTanStart * 0.5 * aCoef;
        StartTanPoint.Y = 0.0;
        cairo_matrix_invert(&RotateMatrixR0toR1);
        cairo_matrix_transform_point(&RotateMatrixR0toR1, &StartTanPoint.X, &StartTanPoint.Y);
        cairo_matrix_invert(&TranslateMatrixR0toR1);
        cairo_matrix_transform_point(&TranslateMatrixR0toR1, &StartTanPoint.X, &StartTanPoint.Y);
        // Coordonnées de TanEndPoint dans le repère R1
        EndTanPoint.X = EndPointInR2.X + DistTanEnd * 0.5 * aCoef;
        EndTanPoint.Y = 0.0;
        cairo_matrix_invert(&RotateMatrixR0toR2);
        cairo_matrix_transform_point(&RotateMatrixR0toR2, &EndTanPoint.X, &EndTanPoint.Y);
        cairo_matrix_invert(&TranslateMatrixR0toR2);
        cairo_matrix_transform_point(&TranslateMatrixR0toR2, &EndTanPoint.X, &EndTanPoint.Y);


        cairo_move_to(mCairoDC, aStartPoint.X, aStartPoint.Y);
        cairo_curve_to(mCairoDC, StartTanPoint.X,StartTanPoint.Y, EndTanPoint.X, EndTanPoint.Y, aEndPoint.X, aEndPoint.Y);
        cairo_set_line_width(mCairoDC, 3);
        cairo_stroke(mCairoDC);
    }
}
Exemplo n.º 22
0
/*
  Set gadget's background
*/
gboolean
on_expose_event (GtkWidget *widget, GdkEventExpose *event, block_notes_core_s *core)
{
  cairo_t *cr;	
  double x0      = 5.0;
  double y0      = 12.0;
  double rect_width  = core->width - 10;
  double rect_height = core->height - 15;
  double radius = 30;
  double x1,y1;
	
  cr = gdk_cairo_create (widget->window);
	
  /* settaggi per rendere trasparente lo sfondo */
  cairo_set_source_rgba (cr, 1.0f, 1.0f, 1.0f, 0.0f);
  cairo_set_operator (cr, CAIRO_OPERATOR_SOURCE);
  cairo_paint (cr);

  x1 = x0 + rect_width;
  y1 = y0 + rect_height;
	
  if (!rect_width || !rect_height)
    return;

  cairo_move_to  (cr, x0, y0 + radius);
  cairo_curve_to (cr, x0 , y0, x0 , y0, x0 + radius, y0);
  cairo_line_to (cr, x1 - radius, y0);
  cairo_curve_to (cr, x1, y0, x1, y0, x1, y0 + radius);
  cairo_line_to (cr, x1 , y1 - radius);
  cairo_curve_to (cr, x1, y1, x1, y1, x1 - radius, y1);
  cairo_line_to (cr, x0 + radius, y1);
  cairo_curve_to (cr, x0, y1, x0, y1, x0, y1- radius);

  cairo_close_path (cr);



  cairo_set_source_rgba (cr,
                         (float) core->gadget.red / 65535.0,
                         (float) core->gadget.green / 65535.0,
                         (float) core->gadget.blue / 65535.0,
                         1.0);

  cairo_fill_preserve (cr);

  cairo_set_source_rgba (cr,
                         1.0,
                         1.0,
                         1.0,
                         0.7);

	cairo_set_source_rgba (cr,
                         (float) core->border.red / 65535.0,
                         (float) core->border.green / 65535.0,
                         (float) core->border.blue / 65535.0,
                         core->border_transparency);

  cairo_set_line_width (cr, 3.0);
  cairo_stroke (cr);
  cairo_destroy (cr);

  return FALSE;
}
Exemplo n.º 23
0
void ofCairoRenderer::draw(ofSubPath & path){
	if(!surface || !cr) return;
	const vector<ofSubPath::Command> & commands = path.getCommands();
	cairo_new_sub_path(cr);
	for(int i=0; i<(int)commands.size(); i++){
		switch(commands[i].type){
		case ofSubPath::Command::lineTo:
			curvePoints.clear();
			cairo_line_to(cr,commands[i].to.x,commands[i].to.y);
			break;


		case ofSubPath::Command::curveTo:
			curvePoints.push_back(commands[i].to);

			//code adapted from ofxVectorGraphics to convert catmull rom to bezier
			if(curvePoints.size()==4){
				ofPoint p1=curvePoints[0];
				ofPoint p2=curvePoints[1];
				ofPoint p3=curvePoints[2];
				ofPoint p4=curvePoints[3];

				//SUPER WEIRD MAGIC CONSTANT = 1/6 (this works 100% can someone explain it?)
				ofPoint cp1 = p2 + ( p3 - p1 ) * (1.0/6);
				ofPoint cp2 = p3 + ( p2 - p4 ) * (1.0/6);

				cairo_curve_to( cr, cp1.x, cp1.y, cp2.x, cp2.y, p3.x, p3.y );
				curvePoints.pop_front();
			}
			break;


		case ofSubPath::Command::bezierTo:
			curvePoints.clear();
			cairo_curve_to(cr,commands[i].cp1.x,commands[i].cp1.y,commands[i].cp2.x,commands[i].cp2.y,commands[i].to.x,commands[i].to.y);
			break;

		case ofSubPath::Command::quadBezierTo:
			curvePoints.clear();
			cairo_curve_to(cr,commands[i].cp1.x,commands[i].cp1.y,commands[i].cp2.x,commands[i].cp2.y,commands[i].to.x,commands[i].to.y);
			break;


		case ofSubPath::Command::arc:
			curvePoints.clear();
			// elliptic arcs not directly supported in cairo, lets scale y
			if(commands[i].radiusX!=commands[i].radiusY){
				float ellipse_ratio = commands[i].radiusY/commands[i].radiusX;
				pushMatrix();
				translate(0,-commands[i].to.y*ellipse_ratio);
				scale(1,ellipse_ratio);
				translate(0,commands[i].to.y/ellipse_ratio);
				cairo_arc(cr,commands[i].to.x,commands[i].to.y,commands[i].radiusX,commands[i].angleBegin,commands[i].angleEnd);
				//cairo_set_matrix(cr,&stored_matrix);
				popMatrix();
			}else{
				cairo_arc(cr,commands[i].to.x,commands[i].to.y,commands[i].radiusX,commands[i].angleBegin,commands[i].angleEnd);
			}
			break;
		}
	}

	if(path.isClosed()){
		cairo_close_path(cr);
	}


}
Exemplo n.º 24
0
/*
  Refresh gadget's background if needed
*/
gboolean
refresh_background (block_notes_core_s *core)
{	
  GdkColor color;
  cairo_t *cr;
  double x0      = 5.0;
  double y0      = 12.0;
  double rect_width  = core->width - 10;
  double rect_height = core->height - 12;
  double radius = 40;
  double x1,y1;

  cr = gdk_cairo_create (core->window->window);

  /* Set gadget's background transparent */
  cairo_set_source_rgba (cr, 1.0, 1.0, 1.0, 0.0);
  cairo_set_operator (cr, CAIRO_OPERATOR_SOURCE);
  cairo_paint (cr);

  x1 = x0 + rect_width;
  y1 = y0 + rect_height;

  if (!rect_width || !rect_height)
    return;

  cairo_move_to  (cr, x0, (y0 + y1)/2);
  cairo_curve_to (cr, x0 ,y0, x0, y0, (x0 + x1)/2, y0);
  cairo_curve_to (cr, x1, y0, x1, y0, x1, (y0 + y1)/2);
  cairo_curve_to (cr, x1, y1, x1, y1, (x1 + x0)/2, y1);
  cairo_curve_to (cr, x0, y1, x0, y1, x0, (y0 + y1)/2);

  cairo_close_path (cr);

  cairo_set_source_rgba (cr,
                         (float) core->gadget.red / 65535.0,
                         (float) core->gadget.green / 65535.0,
                         (float) core->gadget.blue / 65535.0,
                         1.0);
	
  cairo_fill_preserve (cr);
	
  cairo_set_source_rgba (cr,
                         (float) core->border.red / 65535.0,
                         (float) core->border.green / 65535.0,
                         (float) core->border.blue / 65535.0,
                         core->border_transparency);

  cairo_set_line_width (cr, 3.0);
  cairo_stroke (cr);
  cairo_destroy (cr);


  gtk_widget_modify_base (core->view, GTK_STATE_NORMAL, &core->gadget);

  /* Reset textview font */
  gtk_widget_modify_font (core->view, core->font_pango);

  /* Reset font color */
  gtk_widget_modify_text (core->view, GTK_STATE_NORMAL, &core->text);

  /* Resize window */
  gtk_window_resize (GTK_WINDOW(core->window), core->width, core->height);

  /* Reset buttons */
  gtk_fixed_move (GTK_FIXED(core->fixed), core->button_setting, core->width - 40, 0);
  gtk_fixed_move (GTK_FIXED(core->fixed), core->button_move, core->width - 30, 0);
  gtk_fixed_move (GTK_FIXED(core->fixed), core->button_close, core->width - 20, 0);
  gtk_widget_set_size_request (core->view, core->width - 27, core->height - 30);

  return FALSE;
}
Exemplo n.º 25
0
void cairo_context::curve_to(double ct1_x, double ct1_y, double ct2_x, double ct2_y, double end_x, double end_y)
{
    cairo_curve_to(cairo_.get(), ct1_x,ct1_y,ct2_x,ct2_y,end_x,end_y);
    check_object_status_and_throw_exception(*this);
}
Exemplo n.º 26
0
void
dt_view_image_expose(
    dt_view_image_over_t *image_over,
    uint32_t imgid,
    cairo_t *cr,
    int32_t width,
    int32_t height,
    int32_t zoom,
    int32_t px,
    int32_t py)
{
  cairo_save (cr);
  float bgcol = 0.4, fontcol = 0.425, bordercol = 0.1, outlinecol = 0.2;
  int selected = 0, altered = 0, imgsel;
  DT_CTL_GET_GLOBAL(imgsel, lib_image_mouse_over_id);
  // if(img->flags & DT_IMAGE_SELECTED) selected = 1;

  /* clear and reset statements */
  DT_DEBUG_SQLITE3_CLEAR_BINDINGS(darktable.view_manager->statements.is_selected);
  DT_DEBUG_SQLITE3_CLEAR_BINDINGS(darktable.view_manager->statements.have_history);
  DT_DEBUG_SQLITE3_RESET(darktable.view_manager->statements.is_selected);
  DT_DEBUG_SQLITE3_RESET(darktable.view_manager->statements.have_history);

  /* bind imgid to prepared statments */
  DT_DEBUG_SQLITE3_BIND_INT(darktable.view_manager->statements.is_selected, 1, imgid);
  DT_DEBUG_SQLITE3_BIND_INT(darktable.view_manager->statements.have_history, 1, imgid); 

  /* lets check if imgid is selected */
  if(sqlite3_step(darktable.view_manager->statements.is_selected) == SQLITE_ROW) 
    selected = 1;

  /* lets check if imgid has history */
  if(sqlite3_step(darktable.view_manager->statements.have_history) == SQLITE_ROW) 
    altered = 1;
  
  const dt_image_t *img = dt_image_cache_read_testget(darktable.image_cache, imgid);
  if(selected == 1)
  {
    outlinecol = 0.4;
    bgcol = 0.6;
    fontcol = 0.5;
  }
  if(imgsel == imgid)
  {
    bgcol = 0.8;  // mouse over
    fontcol = 0.7;
    outlinecol = 0.6;
    // if the user points at this image, we really want it:
    if(!img)
      img = dt_image_cache_read_get(darktable.image_cache, imgid);
  }
  float imgwd = 0.90f;
  if(zoom == 1)
  {
    imgwd = .97f;
    // cairo_set_antialias(cr, CAIRO_ANTIALIAS_NONE);
  }
  else
  {
    double x0 = 1, y0 = 1, rect_width = width-2, rect_height = height-2, radius = 5;
    double x1, y1, off, off1;

    x1=x0+rect_width;
    y1=y0+rect_height;
    off=radius*0.666;
    off1 = radius-off;
    cairo_move_to  (cr, x0, y0 + radius);
    cairo_curve_to (cr, x0, y0+off1, x0+off1 , y0, x0 + radius, y0);
    cairo_line_to (cr, x1 - radius, y0);
    cairo_curve_to (cr, x1-off1, y0, x1, y0+off1, x1, y0 + radius);
    cairo_line_to (cr, x1 , y1 - radius);
    cairo_curve_to (cr, x1, y1-off1, x1-off1, y1, x1 - radius, y1);
    cairo_line_to (cr, x0 + radius, y1);
    cairo_curve_to (cr, x0+off1, y1, x0, y1-off1, x0, y1- radius);
    cairo_close_path (cr);
    cairo_set_source_rgb(cr, bgcol, bgcol, bgcol);
    cairo_fill_preserve(cr);
    cairo_set_line_width(cr, 0.005*width);
    cairo_set_source_rgb(cr, outlinecol, outlinecol, outlinecol);
    cairo_stroke(cr);

    if(img)
    {
      const char *ext = img->filename + strlen(img->filename);
      while(ext > img->filename && *ext != '.') ext--;
      ext++;
      cairo_set_source_rgb(cr, fontcol, fontcol, fontcol);
      cairo_select_font_face (cr, "sans-serif", CAIRO_FONT_SLANT_NORMAL, CAIRO_FONT_WEIGHT_BOLD);
      cairo_set_font_size (cr, .25*width);

      cairo_move_to (cr, .01*width, .24*height);
      cairo_show_text (cr, ext);
    }
  }

  float scale = 1.0;
  dt_mipmap_buffer_t buf;
  dt_mipmap_size_t mip = 
    dt_mipmap_cache_get_matching_size(
      darktable.mipmap_cache,
      imgwd*width, imgwd*height);
  dt_mipmap_cache_read_get(
      darktable.mipmap_cache,
      &buf,
      imgid,
      mip,
      0);
  cairo_surface_t *surface = NULL;
  if(buf.buf)
  {
    const int32_t stride = cairo_format_stride_for_width (CAIRO_FORMAT_RGB24, buf.width);
    surface = cairo_image_surface_create_for_data (buf.buf, CAIRO_FORMAT_RGB24, buf.width, buf.height, stride);
    if(zoom == 1)
    {
      scale = fminf(
			 fminf(darktable.thumbnail_width, width) / (float)buf.width, 
			 fminf(darktable.thumbnail_height, height) / (float)buf.height
			 );
    }
    else scale = fminf(width*imgwd/(float)buf.width, height*imgwd/(float)buf.height);
  }

  // draw centered and fitted:
  cairo_save(cr);
  cairo_translate(cr, width/2.0, height/2.0f);
  cairo_scale(cr, scale, scale);

  if(buf.buf)
  {
    cairo_translate(cr, -.5f*buf.width, -.5f*buf.height);
    cairo_set_source_surface (cr, surface, 0, 0);
    if(buf.width <= 8 && buf.height <= 8)
      cairo_pattern_set_filter(cairo_get_source(cr), CAIRO_FILTER_NEAREST);
    cairo_rectangle(cr, 0, 0, buf.width, buf.height);
    cairo_fill(cr);
    cairo_surface_destroy (surface);

    if(zoom == 1) cairo_pattern_set_filter(cairo_get_source(cr), CAIRO_FILTER_BEST);
    cairo_rectangle(cr, 0, 0, buf.width, buf.height);
  }

  // border around image
  const float border = zoom == 1 ? 16/scale : 2/scale;
  cairo_set_source_rgb(cr, bordercol, bordercol, bordercol);
  if(buf.buf && selected)
  {
    cairo_set_line_width(cr, 1./scale);
    if(zoom == 1)
    {
      // draw shadow around border
      cairo_set_source_rgb(cr, 0.2, 0.2, 0.2);
      cairo_stroke(cr);
      // cairo_new_path(cr);
      cairo_set_fill_rule (cr, CAIRO_FILL_RULE_EVEN_ODD);
      float alpha = 1.0f;
      for(int k=0; k<16; k++)
      {
        cairo_rectangle(cr, 0, 0, buf.width, buf.height);
        cairo_new_sub_path(cr);
        cairo_rectangle(cr, -k/scale, -k/scale, buf.width+2.*k/scale, buf.height+2.*k/scale);
        cairo_set_source_rgba(cr, 0, 0, 0, alpha);
        alpha *= 0.6f;
        cairo_fill(cr);
      }
    }
    else
    {
      cairo_set_fill_rule (cr, CAIRO_FILL_RULE_EVEN_ODD);
      cairo_new_sub_path(cr);
      cairo_rectangle(cr, -border, -border, buf.width+2.*border, buf.height+2.*border);
      cairo_stroke_preserve(cr);
      cairo_set_source_rgb(cr, 1.0-bordercol, 1.0-bordercol, 1.0-bordercol);
      cairo_fill(cr);
    }
  }
  else if(buf.buf)
  {
    cairo_set_line_width(cr, 1);
    cairo_stroke(cr);
  }
  cairo_restore(cr);
  if(buf.buf)
    dt_mipmap_cache_read_release(darktable.mipmap_cache, &buf);

  const float fscale = fminf(width, height);
  if(imgsel == imgid)
  {
    // draw mouseover hover effects, set event hook for mouse button down!
    *image_over = DT_VIEW_DESERT;
    cairo_set_line_width(cr, 1.5);
    cairo_set_source_rgb(cr, outlinecol, outlinecol, outlinecol);
    cairo_set_line_join (cr, CAIRO_LINE_JOIN_ROUND);
    float r1, r2;
    if(zoom != 1)
    {
      r1 = 0.05*width;
      r2 = 0.022*width;
    }
    else
    {
      r1 = 0.015*fscale;
      r2 = 0.007*fscale;
    }

    float x, y;
    if(zoom != 1) y = 0.90*height;
    else y = .12*fscale;

    if(img) for(int k=0; k<5; k++)
      {
        if(zoom != 1) x = (0.41+k*0.12)*width;
        else x = (.08+k*0.04)*fscale;

        if((img->flags & 0x7) != 6) //if rejected: draw no stars
        {
          dt_view_star(cr, x, y, r1, r2);
          if((px - x)*(px - x) + (py - y)*(py - y) < r1*r1)
          {
            *image_over = DT_VIEW_STAR_1 + k;
            cairo_fill(cr);
          }
          else if((img->flags & 0x7) > k)
          {
            cairo_fill_preserve(cr);
            cairo_set_source_rgb(cr, 1.0-bordercol, 1.0-bordercol, 1.0-bordercol);
            cairo_stroke(cr);
            cairo_set_source_rgb(cr, outlinecol, outlinecol, outlinecol);
          }
          else cairo_stroke(cr);
        }
      }

    //Image rejected?
    if(zoom !=1) x = 0.11*width;
    else x = .04*fscale;

    if((px - x)*(px - x) + (py - y)*(py - y) < r1*r1)
    {
      *image_over = DT_VIEW_REJECT; //mouse sensitive
      cairo_new_sub_path(cr);
      cairo_arc(cr, x, y, (r1+r2)*.5, 0, 2.0f*M_PI);
      cairo_stroke(cr);
    }
    else if (img && ((img->flags & 0x7) == 6))
    {
      cairo_set_source_rgb(cr, 1., 0., 0.);
      cairo_new_sub_path(cr);
      cairo_arc(cr, x, y, (r1+r2)*.5, 0, 2.0f*M_PI);
      cairo_stroke(cr);
      cairo_set_line_width(cr, 2.5);
    }

    //reject cross:
    cairo_move_to(cr, x-r2, y-r2);
    cairo_line_to(cr, x+r2, y+r2);
    cairo_move_to(cr, x+r2, y-r2);
    cairo_line_to(cr, x-r2, y+r2);
    cairo_close_path(cr);
    cairo_stroke(cr);
    cairo_set_source_rgb(cr, outlinecol, outlinecol, outlinecol);
    cairo_set_line_width(cr, 1.5);

    // image altered?
    if(altered)
    {
      // align to right
      float s = (r1+r2)*.5;
      if(zoom != 1)
      {
        x = width*0.9;
        y = height*0.1;
      }
      else x = (.04+7*0.04)*fscale;
      dt_view_draw_altered(cr, x, y, s);
      //g_print("px = %d, x = %.4f, py = %d, y = %.4f\n", px, x, py, y);
      if(img && abs(px-x) <= 1.2*s && abs(py-y) <= 1.2*s) // mouse hovers over the altered-icon -> history tooltip!
      {
        darktable.gui->center_tooltip = 1;
      }
    }
  }

  // kill all paths, in case img was not loaded yet, or is blocked:
  cairo_new_path(cr);

  // TODO: make mouse sensitive, just as stars!
  // TODO: cache in image struct!
  {
    // color labels:
    const float x = zoom == 1 ? (0.07)*fscale : .21*width;
    const float y = zoom == 1 ? 0.17*fscale: 0.1*height;
    const float r = zoom == 1 ? 0.01*fscale : 0.03*width;

    /* clear and reset prepared statement */
    DT_DEBUG_SQLITE3_CLEAR_BINDINGS(darktable.view_manager->statements.get_color);
    DT_DEBUG_SQLITE3_RESET(darktable.view_manager->statements.get_color); 

    /* setup statement and iterate rows */
    DT_DEBUG_SQLITE3_BIND_INT(darktable.view_manager->statements.get_color, 1, imgid);
    while(sqlite3_step(darktable.view_manager->statements.get_color) == SQLITE_ROW)
    {
      cairo_save(cr);
      int col = sqlite3_column_int(darktable.view_manager->statements.get_color, 0);
      // see src/dtgtk/paint.c
      dtgtk_cairo_paint_label(cr, x+(3*r*col)-5*r, y-r, r*2, r*2, col);
      cairo_restore(cr);
    }
  }

  if(img && (zoom == 1))
  {
    // some exif data
    cairo_set_source_rgb(cr, .7, .7, .7);
    cairo_select_font_face (cr, "sans-serif", CAIRO_FONT_SLANT_NORMAL, CAIRO_FONT_WEIGHT_BOLD);
    cairo_set_font_size (cr, .025*fscale);

    cairo_move_to (cr, .02*fscale, .04*fscale);
    // cairo_show_text(cr, img->filename);
    cairo_text_path(cr, img->filename);
    char exifline[50];
    cairo_move_to (cr, .02*fscale, .08*fscale);
    dt_image_print_exif(img, exifline, 50);
    cairo_text_path(cr, exifline);
    cairo_fill_preserve(cr);
    cairo_set_line_width(cr, 1.0);
    cairo_set_source_rgb(cr, 0.3, 0.3, 0.3);
    cairo_stroke(cr);
  }

  if(img) dt_image_cache_read_release(darktable.image_cache, img);
  cairo_restore(cr);
  // if(zoom == 1) cairo_set_antialias(cr, CAIRO_ANTIALIAS_DEFAULT);
}
Exemplo n.º 27
0
void Context::curveTo( double x1, double y1, double x2, double y2, double x3, double y3 )
{
	cairo_curve_to( mCairo, x1, y1, x2, y2, x3, y3 );
}
Exemplo n.º 28
0
void ofCairoRenderer::draw(const ofPath::Command & command) const{
	if(!surface || !cr) return;
	ofCairoRenderer * mut_this = const_cast<ofCairoRenderer*>(this);
	switch(command.type){
	case ofPath::Command::moveTo:
		curvePoints.clear();
		cairo_move_to(cr,command.to.x,command.to.y);
		break;

	case ofPath::Command::lineTo:
		curvePoints.clear();
		cairo_line_to(cr,command.to.x,command.to.y);
		break;


	case ofPath::Command::curveTo:
		curvePoints.push_back(command.to);

		//code adapted from ofxVectorGraphics to convert catmull rom to bezier
		if(curvePoints.size()==4){
			ofPoint p1=curvePoints[0];
			ofPoint p2=curvePoints[1];
			ofPoint p3=curvePoints[2];
			ofPoint p4=curvePoints[3];

			//SUPER WEIRD MAGIC CONSTANT = 1/6 (this works 100% can someone explain it?)
			ofPoint cp1 = p2 + ( p3 - p1 ) * (1.0f/6.f);
			ofPoint cp2 = p3 + ( p2 - p4 ) * (1.0f/6.f);

			cairo_curve_to( cr, cp1.x, cp1.y, cp2.x, cp2.y, p3.x, p3.y );
			curvePoints.pop_front();
		}
		break;


	case ofPath::Command::bezierTo:
		curvePoints.clear();
		cairo_curve_to(cr,command.cp1.x,command.cp1.y,command.cp2.x,command.cp2.y,command.to.x,command.to.y);
		break;

	case ofPath::Command::quadBezierTo:
		curvePoints.clear();
		cairo_curve_to(cr,command.cp1.x,command.cp1.y,command.cp2.x,command.cp2.y,command.to.x,command.to.y);
		break;


	case ofPath::Command::arc:
		curvePoints.clear();
		// elliptic arcs not directly supported in cairo, lets scale y
		if(command.radiusX!=command.radiusY){
			float ellipse_ratio = command.radiusY/command.radiusX;
			mut_this->pushMatrix();
			mut_this->translate(0,-command.to.y*ellipse_ratio);
			mut_this->scale(1,ellipse_ratio);
			mut_this->translate(0,command.to.y/ellipse_ratio);
			cairo_arc(cr,command.to.x,command.to.y,command.radiusX,command.angleBegin*DEG_TO_RAD,command.angleEnd*DEG_TO_RAD);
			//cairo_set_matrix(cr,&stored_matrix);
			mut_this->popMatrix();
		}else{
			cairo_arc(cr,command.to.x,command.to.y,command.radiusX,command.angleBegin*DEG_TO_RAD,command.angleEnd*DEG_TO_RAD);
		}
		break;

	case ofPath::Command::arcNegative:
		curvePoints.clear();
		// elliptic arcs not directly supported in cairo, lets scale y
		if(command.radiusX!=command.radiusY){
			float ellipse_ratio = command.radiusY/command.radiusX;
			mut_this->pushMatrix();
			mut_this->translate(0,-command.to.y*ellipse_ratio);
			mut_this->scale(1,ellipse_ratio);
			mut_this->translate(0,command.to.y/ellipse_ratio);
			cairo_arc_negative(cr,command.to.x,command.to.y,command.radiusX,command.angleBegin*DEG_TO_RAD,command.angleEnd*DEG_TO_RAD);
			//cairo_set_matrix(cr,&stored_matrix);
			mut_this->popMatrix();
		}else{
			cairo_arc_negative(cr,command.to.x,command.to.y,command.radiusX,command.angleBegin*DEG_TO_RAD,command.angleEnd*DEG_TO_RAD);
		}
	break;

	case ofPath::Command::close:
		cairo_close_path(cr);
		break;

	}


}
Exemplo n.º 29
0
void
terranova_draw_button_effect(cairo_t *cr, const WidgetParameters *params,
				const terranovaColors *colors, int width, int height)
{

	const CairoColor *stripe_fill = &colors->bg[GTK_STATE_SELECTED];
	CairoColor hilight, middle, shadow;
	cairo_pattern_t *pattern;

	if (params->button_effect == 1)
	{

		tn_shade_color (stripe_fill, 1.10, &middle);
		tn_shade_color (stripe_fill, 0.90, &shadow);
		tn_shade_color (stripe_fill, 1.35, &hilight);

		pattern = cairo_pattern_create_linear (0, 0, 0, height);
		cairo_pattern_add_color_stop_rgb (pattern, 0.25, hilight.r, hilight.g, hilight.b);
		cairo_pattern_add_color_stop_rgb (pattern, 0.05, middle.r, middle.g, middle.b);
		cairo_pattern_add_color_stop_rgb (pattern, 0.75, shadow.r, shadow.g, shadow.b);
		cairo_set_source (cr, pattern);
		cairo_pattern_destroy (pattern);

		cairo_move_to  (cr, 1, 1);
		cairo_line_to  (cr, width, 1);
		cairo_curve_to (cr, width, 1, 1, 1, 1, height);
		cairo_close_path(cr);
		cairo_fill(cr);

	}
	else if (params->button_effect == 2)
	{

		tn_shade_color (stripe_fill, 1.10, &middle);
		tn_shade_color (stripe_fill, 0.90, &shadow);
		tn_shade_color (stripe_fill, 1.35, &hilight);

		pattern = cairo_pattern_create_linear (0, 0, 0, height);
		cairo_pattern_add_color_stop_rgb (pattern, 0.25, hilight.r, hilight.g, hilight.b);
		cairo_pattern_add_color_stop_rgb (pattern, 0.05, middle.r, middle.g, middle.b);
		cairo_pattern_add_color_stop_rgb (pattern, 0.75, shadow.r, shadow.g, shadow.b);
		cairo_set_source (cr, pattern);
		cairo_pattern_destroy (pattern);

		cairo_move_to  (cr, 3, height-20);
		cairo_line_to  (cr, 3, height-3);
		cairo_line_to  (cr, 20, height-3);
		cairo_line_to  (cr, 8, height-9);
		cairo_line_to  (cr, 3, height-20);
		cairo_close_path(cr);
		cairo_fill(cr);

		cairo_move_to (cr, width-20, 3);
		cairo_line_to (cr, width-3, 3);
		cairo_line_to (cr, width-3, 20);
		cairo_line_to (cr, width-8, 9);
		cairo_line_to (cr, width-20, 3);
		cairo_close_path(cr);
		cairo_fill(cr);
	}

}
Exemplo n.º 30
0
static void
snippet(cairo_t *cr, int i)
{
  if (1)
    {
      cairo_save(cr);
      cairo_rotate (cr, i * 0.002);
      /* a custom shape that could be wrapped in a function */
      double x0      = 25.6,   /* parameters like cairo_rectangle */
	y0      = 25.6,
	rect_width  = 204.8,
	rect_height = 204.8,
	radius = 102.4;   /* and an approximate curvature radius */

      double x1,y1;

      x1=x0+rect_width;
      y1=y0+rect_height;
      if (rect_width/2<radius) {
	if (rect_height/2<radius) {
	  cairo_move_to  (cr, x0, (y0 + y1)/2);
	  cairo_curve_to (cr, x0 ,y0, x0, y0, (x0 + x1)/2, y0);
	  cairo_curve_to (cr, x1, y0, x1, y0, x1, (y0 + y1)/2);
	  cairo_curve_to (cr, x1, y1, x1, y1, (x1 + x0)/2, y1);
	  cairo_curve_to (cr, x0, y1, x0, y1, x0, (y0 + y1)/2);
	} else {
	  cairo_move_to  (cr, x0, y0 + radius);
	  cairo_curve_to (cr, x0 ,y0, x0, y0, (x0 + x1)/2, y0);
	  cairo_curve_to (cr, x1, y0, x1, y0, x1, y0 + radius);
	  cairo_line_to (cr, x1 , y1 - radius);
	  cairo_curve_to (cr, x1, y1, x1, y1, (x1 + x0)/2, y1);
	  cairo_curve_to (cr, x0, y1, x0, y1, x0, y1- radius);
	}
      } else {
	if (rect_height/2<radius) {
	  cairo_move_to  (cr, x0, (y0 + y1)/2);
	  cairo_curve_to (cr, x0 , y0, x0 , y0, x0 + radius, y0);
	  cairo_line_to (cr, x1 - radius, y0);
	  cairo_curve_to (cr, x1, y0, x1, y0, x1, (y0 + y1)/2);
	  cairo_curve_to (cr, x1, y1, x1, y1, x1 - radius, y1);
	  cairo_line_to (cr, x0 + radius, y1);
	  cairo_curve_to (cr, x0, y1, x0, y1, x0, (y0 + y1)/2);
	} else {
	  cairo_move_to  (cr, x0, y0 + radius);
	  cairo_curve_to (cr, x0 , y0, x0 , y0, x0 + radius, y0);
	  cairo_line_to (cr, x1 - radius, y0);
	  cairo_curve_to (cr, x1, y0, x1, y0, x1, y0 + radius);
	  cairo_line_to (cr, x1 , y1 - radius);
	  cairo_curve_to (cr, x1, y1, x1, y1, x1 - radius, y1);
	  cairo_line_to (cr, x0 + radius, y1);
	  cairo_curve_to (cr, x0, y1, x0, y1, x0, y1- radius);
	}
      }
      cairo_close_path (cr);

      cairo_set_source_rgb (cr, 0.5, 0.5, 1);
      cairo_fill_preserve (cr);
      cairo_set_source_rgba (cr, 0.5, 0, 0, 0.5);
      cairo_set_line_width (cr, 10.0);
      cairo_stroke (cr);
      cairo_restore(cr);
    }
  if (1)
    {
      double xc = 128.0;
      double yc = 128.0;
      double radius = 100.0;
      double angle1 = (45.0 + i * 5)  * (M_PI/180.0);  /* angles are specified */
      double angle2 = (180.0 + i * 5) * (M_PI/180.0);  /* in radians           */

      cairo_set_source_rgb (cr, 0.0, 0.0, 0.0);

      cairo_set_line_width (cr, 10.0);
      cairo_arc (cr, xc, yc, radius, angle1, angle2);
      cairo_stroke (cr);

      /* draw helping lines */
      cairo_set_source_rgba (cr, 1, 0.2, 0.2, 0.6);
      cairo_set_line_width (cr, 6.0);

      cairo_arc (cr, xc, yc, 10.0, 0, 2*M_PI);
      cairo_fill (cr);

      cairo_arc (cr, xc, yc, radius, angle1, angle1);
      cairo_line_to (cr, xc, yc);
      cairo_arc (cr, xc, yc, radius, angle2, angle2);
      cairo_line_to (cr, xc, yc);
      cairo_stroke (cr);
    }
}