Ejemplo n.º 1
0
VALUE
shoes_canvas_shape(int argc, VALUE *argv, VALUE self)
{
  int x;
  double x1, y1, x2, y2;
  cairo_t *shape = NULL;
  cairo_path_t *line = NULL;
  SETUP_SHAPE();

  shape = canvas->shape;
  VALUE attr = shoes_shape_attr(argc, argv, 2, s_left, s_top);
  canvas->shape = cairo_create(cairo_image_surface_create(CAIRO_FORMAT_ARGB32, 1, 1));
  cairo_move_to(canvas->shape, 0, 0);
  if (rb_block_given_p()) rb_funcall(rb_block_proc(), s_call, 0);

#if CAIRO_VERSION_MAJOR == 1 && CAIRO_VERSION_MINOR <= 4
  cairo_fill_extents(canvas->shape, &x1, &y1, &x2, &y2);
#else
  cairo_path_extents(canvas->shape, &x1, &y1, &x2, &y2);
#endif
  x = x2 - x1;
  ATTRSET(attr, width, INT2NUM(x));
  x = y2 - y1;
  ATTRSET(attr, height, INT2NUM(x));
  line = cairo_copy_path(canvas->shape);
  canvas->shape = shape;
  return shoes_add_shape(self, s_shape, attr, line);
}
Ejemplo n.º 2
0
VALUE shoes_canvas_line_to(VALUE self, VALUE _x, VALUE _y) {
    double x, y;
    SETUP_SHAPE();

    x = NUM2DBL(_x);
    y = NUM2DBL(_y);

    if (canvas->shape != NULL) cairo_line_to(canvas->shape, x, y);
    return self;
}
Ejemplo n.º 3
0
VALUE shoes_canvas_curve_to(VALUE self, VALUE _x1, VALUE _y1, VALUE _x2, VALUE _y2, VALUE _x3, VALUE _y3) {
    double x1, y1, x2, y2, x3, y3;
    SETUP_SHAPE();

    x1 = NUM2DBL(_x1);
    y1 = NUM2DBL(_y1);
    x2 = NUM2DBL(_x2);
    y2 = NUM2DBL(_y2);
    x3 = NUM2DBL(_x3);
    y3 = NUM2DBL(_y3);

    if (canvas->shape != NULL) cairo_curve_to(canvas->shape, x1, y1, x2, y2, x3, y3);
    return self;
}
Ejemplo n.º 4
0
VALUE shoes_canvas_arc_to(VALUE self, VALUE _x, VALUE _y, VALUE _w, VALUE _h, VALUE _a1, VALUE _a2) {
    double x, y, w, h, a1, a2;
    SETUP_SHAPE();

    x = NUM2DBL(_x);
    y = NUM2DBL(_y);
    w = NUM2DBL(_w);
    h = NUM2DBL(_h);
    a1 = NUM2DBL(_a1);
    a2 = NUM2DBL(_a2);

    if (canvas->shape != NULL) {
        cairo_save(canvas->shape);
        shoes_cairo_arc(canvas->shape, x, y, w, h, a1, a2);
        cairo_restore(canvas->shape);
    }
    return self;
}
Ejemplo n.º 5
0
VALUE
shoes_canvas_shape(int argc, VALUE *argv, VALUE self)
{
  int x;
  double x1, y1, x2, y2;
  cairo_t *shape = NULL;
  cairo_path_t *line = NULL;
  SETUP_SHAPE();

  shape = canvas->shape;
  attr = shoes_shape_attr(argc, argv, 2, s_left, s_top);
  canvas->shape = cairo_create(cairo_image_surface_create(CAIRO_FORMAT_ARGB32, 1, 1));
  cairo_move_to(canvas->shape, 0, 0);
  if (rb_block_given_p()) rb_yield(Qnil);

  cairo_path_extents(canvas->shape, &x1, &y1, &x2, &y2);
  x = x2 - x1;
  ATTRSET(attr, width, INT2NUM(x));
  x = y2 - y1;
  ATTRSET(attr, height, INT2NUM(x));
  line = cairo_copy_path(canvas->shape);
  canvas->shape = shape;
  return shoes_add_shape(self, s_shape, attr, line);
}