Beispiel #1
0
static VALUE
cr_mesh_pattern_set_control_point (VALUE self, VALUE rb_nth_point,
                                   VALUE rb_x, VALUE rb_y)
{
  cairo_pattern_t *pattern;
  unsigned int nth_point;

  pattern = _SELF (self);
  nth_point = NUM2UINT (rb_nth_point);
  if (nth_point <= 3)
    {
      cairo_mesh_pattern_set_control_point (pattern, nth_point,
                                            NUM2DBL (rb_x), NUM2DBL (rb_y));
    }
  else
    {
      VALUE inspected;

      inspected = rb_funcall (rb_ary_new3 (3, rb_nth_point, rb_x, rb_y),
                              id_inspect, 0);
      rb_raise (rb_eArgError, "nth_point must be 0, 1, 2 or 3: <%u>: <%s>",
                nth_point, RVAL2CSTR (inspected));
    }
  cr_pattern_check_status (pattern);
  return self;
}
static cairo_test_status_t
draw (cairo_t *cr, int width, int height)
{
    cairo_pattern_t *pattern;
    unsigned int i, j;
    unsigned int num_patches;
    double x, y;

    cairo_set_source_rgb (cr, 1, 1, 1);
    cairo_paint (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_line_to (pattern, SIZE,    0);
    cairo_mesh_pattern_line_to (pattern, SIZE, SIZE);
    cairo_mesh_pattern_line_to (pattern,    0, SIZE);

    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_set_control_point (pattern, 0, SIZE * .7, SIZE * .7);
    cairo_mesh_pattern_set_control_point (pattern, 1, SIZE * .9, SIZE * .7);
    cairo_mesh_pattern_set_control_point (pattern, 2, SIZE * .9, SIZE * .9);
    cairo_mesh_pattern_set_control_point (pattern, 3, SIZE * .7, SIZE * .9);

    cairo_mesh_pattern_end_patch (pattern);

    cairo_mesh_pattern_begin_patch (pattern);

    cairo_mesh_pattern_move_to (pattern,   SIZE + PAD,    0);
    cairo_mesh_pattern_line_to (pattern, 2*SIZE + PAD,    0);
    cairo_mesh_pattern_line_to (pattern, 2*SIZE + PAD, SIZE);
    cairo_mesh_pattern_line_to (pattern,   SIZE + PAD, SIZE);

    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_set_source (cr, pattern);
    cairo_paint (cr);

    /* mark the location of the control points */
    cairo_set_source_rgb (cr, 0, 0, 0);
    cairo_mesh_pattern_get_patch_count (pattern, &num_patches);
    for (i = 0; i < num_patches; i++) {
	for (j = 0; j < 4; j++) {
	    cairo_mesh_pattern_get_control_point (pattern, i, j, &x, &y);
	    cairo_rectangle (cr, x - 5, y - 5, 10, 10);
	    cairo_fill (cr);
	}
    }

    cairo_pattern_destroy (pattern);

    return CAIRO_TEST_SUCCESS;
}