static void patch_line (cairo_pattern_t *pattern, double x0, double y0, double x1, double y1, double radius, double r, double g, double b, double a) { double dx = y1 - y0; double dy = x0 - x1; double len = radius / hypot (dx, dy); dx *= len; dy *= len; cairo_mesh_pattern_begin_patch (pattern); cairo_mesh_pattern_move_to (pattern, x0, y0); cairo_mesh_pattern_line_to (pattern, x0 + dx, y0 + dy); cairo_mesh_pattern_line_to (pattern, x1 + dx, y1 + dy); cairo_mesh_pattern_line_to (pattern, x1, y1); cairo_mesh_pattern_set_corner_color_rgba (pattern, 0, r, g, b, a); cairo_mesh_pattern_set_corner_color_rgba (pattern, 1, r, g, b, 0); cairo_mesh_pattern_set_corner_color_rgba (pattern, 2, r, g, b, 0); cairo_mesh_pattern_set_corner_color_rgba (pattern, 3, r, g, b, a); cairo_mesh_pattern_end_patch (pattern); }
static cairo_test_status_t draw (cairo_t *cr, int width, int height) { cairo_pattern_t *pattern; cairo_test_paint_checkered (cr); cairo_translate (cr, PAD, PAD); pattern = cairo_pattern_create_mesh (); cairo_mesh_pattern_begin_patch (pattern); cairo_mesh_pattern_move_to (pattern, 0, 0); cairo_mesh_pattern_curve_to (pattern, 30, -30, 60, 30, 100, 0); cairo_mesh_pattern_curve_to (pattern, 60, 30, 130, 60, 100, 100); cairo_mesh_pattern_curve_to (pattern, 60, 70, 30, 130, 0, 100); cairo_mesh_pattern_curve_to (pattern, 30, 70, -30, 30, 0, 0); cairo_mesh_pattern_set_corner_color_rgb (pattern, 0, 1, 0, 0); cairo_mesh_pattern_set_corner_color_rgb (pattern, 1, 0, 1, 0); cairo_mesh_pattern_set_corner_color_rgb (pattern, 2, 0, 0, 1); cairo_mesh_pattern_set_corner_color_rgb (pattern, 3, 1, 1, 0); cairo_mesh_pattern_end_patch (pattern); cairo_mesh_pattern_begin_patch (pattern); cairo_mesh_pattern_move_to (pattern, 50, 50); cairo_mesh_pattern_curve_to (pattern, 80, 20, 110, 80, 150, 50); cairo_mesh_pattern_curve_to (pattern, 110, 80, 180, 110, 150, 150); cairo_mesh_pattern_curve_to (pattern, 110, 120, 80, 180, 50, 150); cairo_mesh_pattern_curve_to (pattern, 80, 120, 20, 80, 50, 50); cairo_mesh_pattern_set_corner_color_rgba (pattern, 0, 1, 0, 0, 0.3); cairo_mesh_pattern_set_corner_color_rgb (pattern, 1, 0, 1, 0); cairo_mesh_pattern_set_corner_color_rgba (pattern, 2, 0, 0, 1, 0.3); cairo_mesh_pattern_set_corner_color_rgb (pattern, 3, 1, 1, 0); cairo_mesh_pattern_end_patch (pattern); cairo_scale (cr, .5, .5); cairo_set_source (cr, pattern); cairo_paint (cr); cairo_translate (cr, PAT_WIDTH, PAT_HEIGHT); cairo_translate (cr, PAT_WIDTH/2, PAT_HEIGHT/2); cairo_rotate (cr, M_PI/4); cairo_translate (cr, -PAT_WIDTH, -PAT_HEIGHT); cairo_set_source (cr, pattern); cairo_paint (cr); cairo_pattern_destroy (pattern); return CAIRO_TEST_SUCCESS; }
static void patch_arc (cairo_pattern_t *pattern, double x, double y, double start, double end, double radius, double r, double g, double b, double a) { double r_sin_A, r_cos_A; double r_sin_B, r_cos_B; double h; r_sin_A = radius * sin (start); r_cos_A = radius * cos (start); r_sin_B = radius * sin (end); r_cos_B = radius * cos (end); h = 4.0/3.0 * tan ((end - start) / 4.0); cairo_mesh_pattern_begin_patch (pattern); cairo_mesh_pattern_move_to (pattern, x, y); cairo_mesh_pattern_line_to (pattern, x + r_cos_A, y + r_sin_A); cairo_mesh_pattern_curve_to (pattern, x + r_cos_A - h * r_sin_A, y + r_sin_A + h * r_cos_A, x + r_cos_B + h * r_sin_B, y + r_sin_B - h * r_cos_B, x + r_cos_B, y + r_sin_B); cairo_mesh_pattern_line_to (pattern, x, y); cairo_mesh_pattern_set_corner_color_rgba (pattern, 0, r, g, b, a); cairo_mesh_pattern_set_corner_color_rgba (pattern, 1, r, g, b, 0); cairo_mesh_pattern_set_corner_color_rgba (pattern, 2, r, g, b, 0); cairo_mesh_pattern_set_corner_color_rgba (pattern, 3, r, g, b, a); cairo_mesh_pattern_end_patch (pattern); }
static cairo_pattern_t * mesh (void) { cairo_pattern_t *pattern; pattern = cairo_pattern_create_mesh (); cairo_mesh_pattern_begin_patch (pattern); cairo_mesh_pattern_move_to (pattern, 0, 0); cairo_mesh_pattern_curve_to (pattern, 30, -30, 60, 30, 100, 0); cairo_mesh_pattern_curve_to (pattern, 60, 30, 130, 60, 100, 100); cairo_mesh_pattern_curve_to (pattern, 60, 70, 30, 130, 0, 100); cairo_mesh_pattern_curve_to (pattern, 30, 70, -30, 30, 0, 0); cairo_mesh_pattern_set_corner_color_rgb (pattern, 0, 1, 0, 0); cairo_mesh_pattern_set_corner_color_rgb (pattern, 1, 0, 1, 0); cairo_mesh_pattern_set_corner_color_rgb (pattern, 2, 0, 0, 1); cairo_mesh_pattern_set_corner_color_rgb (pattern, 3, 1, 1, 0); cairo_mesh_pattern_end_patch (pattern); cairo_mesh_pattern_begin_patch (pattern); cairo_mesh_pattern_move_to (pattern, 50, 50); cairo_mesh_pattern_curve_to (pattern, 80, 20, 110, 80, 150, 50); cairo_mesh_pattern_curve_to (pattern, 110, 80, 180, 110, 150, 150); cairo_mesh_pattern_curve_to (pattern, 110, 120, 80, 180, 50, 150); cairo_mesh_pattern_curve_to (pattern, 80, 120, 20, 80, 50, 50); cairo_mesh_pattern_set_corner_color_rgba (pattern, 0, 1, 0, 0, 0.3); cairo_mesh_pattern_set_corner_color_rgb (pattern, 1, 0, 1, 0); cairo_mesh_pattern_set_corner_color_rgba (pattern, 2, 0, 0, 1, 0.3); cairo_mesh_pattern_set_corner_color_rgb (pattern, 3, 1, 1, 0); cairo_mesh_pattern_end_patch (pattern); return pattern; }
static VALUE cr_mesh_pattern_set_corner_color_generic (int argc, VALUE *argv, VALUE self) { cairo_pattern_t *pattern; VALUE rb_nth_corner, rb_red, rb_green, rb_blue, rb_alpha; unsigned int nth_corner; double red, green, blue, alpha; rb_scan_args (argc, argv, "41", &rb_nth_corner, &rb_red, &rb_green, &rb_blue, &rb_alpha); nth_corner = NUM2UINT (rb_nth_corner); if (nth_corner > 3) { VALUE inspected; inspected = rb_funcall (rb_ary_new4 (argc, argv), id_inspect, 0); rb_raise (rb_eArgError, "nth_corner must be 0, 1, 2 or 3: <%u>: <%s>", nth_corner, RVAL2CSTR (inspected)); } pattern = _SELF (self); red = NUM2DBL (rb_red); green = NUM2DBL (rb_green); blue = NUM2DBL (rb_blue); if (NIL_P (rb_alpha)) { cairo_mesh_pattern_set_corner_color_rgb (pattern, nth_corner, red, green, blue); } else { alpha = NUM2DBL (rb_alpha); cairo_mesh_pattern_set_corner_color_rgba (pattern, nth_corner, red, green, blue, alpha); } cr_pattern_check_status (pattern); return self; }