void photos_utils_draw_rectangle_handles (cairo_t *cr, gdouble x, gdouble y, gdouble width, gdouble height, gdouble offset, gdouble radius) { cairo_save (cr); cairo_new_sub_path (cr); cairo_arc (cr, x - offset, y - offset, radius, 0.0, 2.0 * M_PI); cairo_fill (cr); cairo_new_sub_path (cr); cairo_arc (cr, x + width + offset, y - offset, radius, 0.0, 2.0 * M_PI); cairo_fill (cr); cairo_new_sub_path (cr); cairo_arc (cr, x + width + offset, y + height + offset, radius, 0.0, 2.0 * M_PI); cairo_fill (cr); cairo_new_sub_path (cr); cairo_arc (cr, x - offset, y + height + offset, radius, 0.0, 2.0 * M_PI); cairo_fill (cr); cairo_restore (cr); }
void render() { draw_fill(ctx, rgba(0,0,0,127)); int stride = cairo_format_stride_for_width(CAIRO_FORMAT_ARGB32, window->width); cairo_surface_t * surface = cairo_image_surface_create_for_data(ctx->buffer, CAIRO_FORMAT_ARGB32, window->width, window->height, stride); cairo_t * cr = cairo_create(surface); cairo_set_line_width (cr, 6); cairo_rectangle (cr, 12, 12, 232, 70); cairo_new_sub_path (cr); cairo_arc (cr, 64, 64, 40, 0, 2*M_PI); cairo_new_sub_path (cr); cairo_arc_negative (cr, 192, 64, 40, 0, -2*M_PI); cairo_set_fill_rule (cr, CAIRO_FILL_RULE_EVEN_ODD); cairo_set_source_rgb (cr, 0, 0.7, 0); cairo_fill_preserve (cr); cairo_set_source_rgb (cr, 0, 0, 0); cairo_stroke (cr); cairo_translate (cr, 0, 128); cairo_rectangle (cr, 12, 12, 232, 70); cairo_new_sub_path (cr); cairo_arc (cr, 64, 64, 40, 0, 2*M_PI); cairo_new_sub_path (cr); cairo_arc_negative (cr, 192, 64, 40, 0, -2*M_PI); cairo_set_fill_rule (cr, CAIRO_FILL_RULE_WINDING); cairo_set_source_rgb (cr, 0, 0, 0.9); cairo_fill_preserve (cr); cairo_set_source_rgb (cr, 0, 0, 0); cairo_stroke (cr); cairo_surface_flush(surface); cairo_destroy(cr); cairo_surface_flush(surface); cairo_surface_destroy(surface); }
static cairo_test_status_t draw (cairo_t *cr, int width, int height) { /* We draw in the default black, so paint white first. */ cairo_save (cr); cairo_set_source_rgb (cr, 1.0, 1.0, 1.0); /* white */ cairo_paint (cr); cairo_restore (cr); /* subpath starts with cairo_move_to */ cairo_new_sub_path (cr); cairo_move_to (cr, SIZE, SIZE); cairo_rel_line_to (cr, SIZE, 0); cairo_rel_line_to (cr, 0, SIZE); cairo_close_path (cr); cairo_rel_line_to (cr, 0.5 * SIZE, SIZE); /* subpath starts with cairo_line_to */ cairo_new_sub_path (cr); cairo_line_to (cr, SIZE, 3 * SIZE); cairo_rel_line_to (cr, SIZE, 0); cairo_rel_line_to (cr, 0, SIZE); cairo_close_path (cr); cairo_rel_line_to (cr, 0, SIZE); /* subpath starts with cairo_curve_to */ cairo_new_sub_path (cr); cairo_curve_to (cr, SIZE, 5 * SIZE, 1.5 * SIZE, 6 * SIZE, 2 * SIZE, 5 * SIZE); cairo_rel_line_to (cr, 0, SIZE); cairo_close_path (cr); cairo_rel_line_to (cr, -0.5 * SIZE, SIZE); /* subpath starts with cairo_arc */ cairo_new_sub_path (cr); cairo_arc (cr, 1.5 * SIZE, 7 * SIZE, 0.5 * SIZE, M_PI, 2 * M_PI); cairo_rel_line_to (cr, 0, SIZE); cairo_close_path (cr); cairo_rel_line_to (cr, -0.7 * SIZE, 0.7 * SIZE); /* subpath starts with cairo_arc_negative */ cairo_new_sub_path (cr); cairo_arc_negative (cr, 1.5 * SIZE, 9 * SIZE, 0.5 * SIZE, M_PI, 2 * M_PI); cairo_rel_line_to (cr, 0, SIZE); cairo_close_path (cr); cairo_rel_line_to (cr, -0.8 * SIZE, 0.3 * SIZE); cairo_stroke (cr); return CAIRO_TEST_SUCCESS; }
static cairo_test_status_t draw (cairo_t *cr, int width, int height) { const cairo_test_context_t *ctx = cairo_test_get_context (cr); cairo_surface_t *image; cairo_set_source_rgb (cr, 1, 1, 1); cairo_paint (cr); image = cairo_test_create_surface_from_png (ctx, png_filename); cairo_set_source_surface (cr, image, 0, 0); /* simple clip */ cairo_save (cr); cairo_rectangle (cr, 2, 2, 16, 16); cairo_clip (cr); cairo_paint (cr); cairo_restore (cr); cairo_translate (cr, WIDTH, 0); /* unaligned clip */ cairo_save (cr); cairo_rectangle (cr, 2.5, 2.5, 15, 15); cairo_clip (cr); cairo_paint (cr); cairo_restore (cr); cairo_translate (cr, -WIDTH, HEIGHT); /* aligned-clip */ cairo_save (cr); cairo_set_fill_rule (cr, CAIRO_FILL_RULE_EVEN_ODD); cairo_rectangle (cr, 0, 0, 20, 20); cairo_rectangle (cr, 3, 3, 10, 10); cairo_rectangle (cr, 7, 7, 10, 10); cairo_clip (cr); cairo_paint (cr); cairo_restore (cr); cairo_translate (cr, WIDTH, 0); /* force a clip-mask */ cairo_save (cr); cairo_arc (cr, 10, 10, 10, 0, 2 * M_PI); cairo_new_sub_path (cr); cairo_arc_negative (cr, 10, 10, 5, 2 * M_PI, 0); cairo_new_sub_path (cr); cairo_arc (cr, 10, 10, 2, 0, 2 * M_PI); cairo_clip (cr); cairo_paint (cr); cairo_restore (cr); return CAIRO_TEST_SUCCESS; }
static cairo_test_status_t draw (cairo_t *cr, int width, int height) { const char *cairo = "Cairo"; cairo_text_extents_t extents; double x0, y0; cairo_text_extents (cr, cairo, &extents); x0 = WIDTH/2. - (extents.width/2. + extents.x_bearing); y0 = HEIGHT/2. - (extents.height/2. + extents.y_bearing); cairo_set_source_rgb (cr, 1, 1, 1); cairo_paint (cr); /* aligned-clip */ cairo_save (cr); cairo_set_fill_rule (cr, CAIRO_FILL_RULE_EVEN_ODD); cairo_rectangle (cr, 0, 0, 20, 20); cairo_rectangle (cr, 3, 3, 10, 10); cairo_rectangle (cr, 7, 7, 10, 10); cairo_clip (cr); cairo_set_source_rgb (cr, 0.7, 0, 0); cairo_paint (cr); cairo_set_source_rgb (cr, 0, 0, 0); cairo_move_to (cr, x0, y0); cairo_show_text (cr, cairo); cairo_restore (cr); cairo_translate (cr, WIDTH, 0); /* force a clip-mask */ cairo_save (cr); cairo_arc (cr, 10, 10, 10, 0, 2 * M_PI); cairo_new_sub_path (cr); cairo_arc_negative (cr, 10, 10, 5, 2 * M_PI, 0); cairo_new_sub_path (cr); cairo_arc (cr, 10, 10, 2, 0, 2 * M_PI); cairo_clip (cr); cairo_set_source_rgb (cr, 0, 0, 0.7); cairo_paint (cr); cairo_set_source_rgb (cr, 0, 0, 0); cairo_move_to (cr, x0, y0); cairo_show_text (cr, cairo); cairo_restore (cr); return CAIRO_TEST_SUCCESS; }
static cairo_test_status_t draw (cairo_t *cr, int width, int height) { cairo_set_source_rgb (cr, 1, 1, 1); cairo_paint (cr); cairo_translate (cr, 10, 10); /* simple clip */ cairo_save (cr); cairo_rectangle (cr, 0, 0, 20, 20); cairo_clip (cr); shapes (cr); cairo_restore (cr); cairo_translate (cr, WIDTH, 0); /* unaligned clip */ cairo_save (cr); cairo_rectangle (cr, 0.5, 0.5, 20, 20); cairo_clip (cr); shapes (cr); cairo_restore (cr); cairo_translate (cr, -WIDTH, HEIGHT); /* aligned-clip */ cairo_save (cr); cairo_set_fill_rule (cr, CAIRO_FILL_RULE_EVEN_ODD); cairo_rectangle (cr, 0, 0, 20, 20); cairo_rectangle (cr, 3, 3, 10, 10); cairo_rectangle (cr, 7, 7, 10, 10); cairo_clip (cr); shapes (cr); cairo_restore (cr); cairo_translate (cr, WIDTH, 0); /* force a clip-mask */ cairo_save (cr); cairo_arc (cr, 10, 10, 10, 0, 2 * M_PI); cairo_new_sub_path (cr); cairo_arc_negative (cr, 10, 10, 5, 2 * M_PI, 0); cairo_new_sub_path (cr); cairo_arc (cr, 10, 10, 2, 0, 2 * M_PI); cairo_clip (cr); shapes (cr); cairo_restore (cr); return CAIRO_TEST_SUCCESS; }
static void pen(cairo_t *ctx, cairo_surface_t *buf, cairo_surface_t *cbuf, Theme *q) { XEvent ev; Bool on = False; XDefineCursor(dpy, wshow, crosshair_cursor); while (!XNextEvent(dpy, &ev)) { if (ev.type == KeyPress) { XPutBackEvent(dpy, &ev); break; } else if (ev.type == ButtonPress) { if (ev.xbutton.button == 1 && (on = !on) ) { cairo_new_sub_path(ctx); cairo_move_to(ctx, ev.xbutton.x, ev.xbutton.y); } else if (ev.xbutton.button == 2) { break; } else if (ev.xbutton.button == 3) { // TODO save changes to slide break; } } else if (ev.type == MotionNotify && on) { cairo_set_source_surface(ctx, cbuf, 0, 0); cairo_paint(ctx); cairo_set_source_rgba(ctx, q->R, q->G, q->B, q->A); cairo_line_to(ctx, ev.xbutton.x, ev.xbutton.y); cairo_stroke_preserve(ctx); cairo_set_source_surface(show->target[0].ctx, buf, 0, 0); cairo_paint(show->target[0].ctx); } } }
static VALUE cr_new_sub_path (VALUE self) { cairo_new_sub_path (_SELF); cr_check_status (_SELF); return self; }
void Path::addArc(const FloatPoint& p, float r, float startAngle, float endAngle, bool anticlockwise) { // http://bugs.webkit.org/show_bug.cgi?id=16449 // cairo_arc() functions hang or crash when passed inf as radius or start/end angle if (!isfinite(r) || !isfinite(startAngle) || !isfinite(endAngle)) return; cairo_t* cr = platformPath()->context(); float sweep = endAngle - startAngle; const float twoPI = 2 * piFloat; if ((sweep <= -twoPI || sweep >= twoPI) && ((anticlockwise && (endAngle < startAngle)) || (!anticlockwise && (startAngle < endAngle)))) { if (anticlockwise) cairo_arc_negative(cr, p.x(), p.y(), r, startAngle, startAngle - twoPI); else cairo_arc(cr, p.x(), p.y(), r, startAngle, startAngle + twoPI); cairo_new_sub_path(cr); cairo_arc(cr, p.x(), p.y(), r, endAngle, endAngle); } else { if (anticlockwise) cairo_arc_negative(cr, p.x(), p.y(), r, startAngle, endAngle); else cairo_arc(cr, p.x(), p.y(), r, startAngle, endAngle); } }
void draw_cairo_round_box (cairo_t *cr, GdkRectangle rect, gint tl_radius, gint tr_radius, gint bl_radius, gint br_radius) { gdouble right = rect.x + rect.width; gdouble bottom = rect.y + rect.height; cairo_new_sub_path (cr); cairo_move_to (cr, rect.x, rect.y + tl_radius); if (tl_radius > 0) draw_corner (cr, rect.x, rect.y, tl_radius, CORNER_TOP_LEFT); cairo_line_to (cr, right - tr_radius, rect.y); if (tr_radius > 0) draw_corner (cr, right, rect.y, tr_radius, CORNER_TOP_RIGHT); cairo_line_to (cr, right, bottom - br_radius); if (br_radius > 0) draw_corner (cr, right, bottom, br_radius, CORNER_BOTTOM_RIGHT); cairo_line_to (cr, rect.x + bl_radius, bottom); if (br_radius > 0) draw_corner (cr, rect.x, bottom, bl_radius, CORNER_BOTTOM_LEFT); cairo_close_path (cr); }
void ui_draw_rectangle(double x, double y, double w, double h, double radius, double line_width, int fill, double *rgba) { x += line_width / 2; y += line_width / 2; w -= line_width; h -= line_width; cairo_set_line_width(ui->w[ui->cur].c, 0.0); if (radius > 0) { double deg = 0.017453292519943295; /* 2 x 3.1415927 / 360.0 */ cairo_new_sub_path(ui->w[ui->cur].c); cairo_arc(ui->w[ui->cur].c, x + w - radius, y + radius, radius, -90 * deg, 0 * deg); cairo_arc(ui->w[ui->cur].c, x + w - radius, y + h - radius, radius, 0 * deg, 90 * deg); cairo_arc(ui->w[ui->cur].c, x + radius, y + h - radius, radius, 90 * deg, 180 * deg); cairo_arc(ui->w[ui->cur].c, x + radius, y + radius, radius, 180 * deg, 270 * deg); cairo_close_path(ui->w[ui->cur].c); cairo_set_source_rgba(ui->w[ui->cur].c, rgba[0], rgba[1], rgba[2], rgba[3]); if (fill) { cairo_set_line_width(ui->w[ui->cur].c, 0.0); cairo_fill_preserve(ui->w[ui->cur].c); } else { cairo_set_line_width(ui->w[ui->cur].c, line_width); } cairo_stroke(ui->w[ui->cur].c); } else { cairo_set_source_rgba(ui->w[ui->cur].c, rgba[0], rgba[1], rgba[2], rgba[3]); cairo_set_line_width(ui->w[ui->cur].c, line_width); cairo_rectangle(ui->w[ui->cur].c, x, y, w, h); if (fill) cairo_fill(ui->w[ui->cur].c); /* FIXME Should line width be 0 here? */ else cairo_stroke(ui->w[ui->cur].c); } }
void _gtk_rounded_box_path (const GtkRoundedBox *box, cairo_t *cr) { cairo_new_sub_path (cr); _cairo_ellipsis (cr, box->box.x + box->corner[GTK_CSS_TOP_LEFT].horizontal, box->box.y + box->corner[GTK_CSS_TOP_LEFT].vertical, box->corner[GTK_CSS_TOP_LEFT].horizontal, box->corner[GTK_CSS_TOP_LEFT].vertical, G_PI, 3 * G_PI_2); _cairo_ellipsis (cr, box->box.x + box->box.width - box->corner[GTK_CSS_TOP_RIGHT].horizontal, box->box.y + box->corner[GTK_CSS_TOP_RIGHT].vertical, box->corner[GTK_CSS_TOP_RIGHT].horizontal, box->corner[GTK_CSS_TOP_RIGHT].vertical, - G_PI_2, 0); _cairo_ellipsis (cr, box->box.x + box->box.width - box->corner[GTK_CSS_BOTTOM_RIGHT].horizontal, box->box.y + box->box.height - box->corner[GTK_CSS_BOTTOM_RIGHT].vertical, box->corner[GTK_CSS_BOTTOM_RIGHT].horizontal, box->corner[GTK_CSS_BOTTOM_RIGHT].vertical, 0, G_PI_2); _cairo_ellipsis (cr, box->box.x + box->corner[GTK_CSS_BOTTOM_LEFT].horizontal, box->box.y + box->box.height - box->corner[GTK_CSS_BOTTOM_LEFT].vertical, box->corner[GTK_CSS_BOTTOM_LEFT].horizontal, box->corner[GTK_CSS_BOTTOM_LEFT].vertical, G_PI_2, G_PI); cairo_close_path (cr); }
static void krad_vector_render_rrect(cairo_t *cr, int x, int y, int w, int h, float r, float g, float b, float op) { double aspect; double corner_radius; double radius; double degrees; if (w > h) { aspect = w/h; } else { aspect = h/w; } corner_radius = h / 15.0; radius = corner_radius / aspect; degrees = M_PI / 180.0; cairo_new_sub_path(cr); cairo_arc(cr, x + w - radius, y + radius, radius, -90 * degrees, 0); cairo_arc(cr, x + w - radius, y + h - radius, radius, 0, 90 * degrees); cairo_arc(cr, x + radius, y + h - radius, radius, 90 * degrees, 180 * degrees); cairo_arc(cr, x + radius, y + radius, radius, 180 * degrees, 270 * degrees); cairo_close_path(cr); cairo_set_source_rgba(cr, r, g, b, op); cairo_fill_preserve(cr); cairo_set_source_rgba(cr, r, g, b, op); cairo_set_line_width(cr, 5.0); cairo_stroke(cr); return; }
static void paint_marker(cairo_t *cr, int x, int y) { enum igt_text_align align; int xoff, yoff; cairo_move_to(cr, x, y - 20); cairo_line_to(cr, x, y + 20); cairo_move_to(cr, x - 20, y); cairo_line_to(cr, x + 20, y); cairo_new_sub_path(cr); cairo_arc(cr, x, y, 10, 0, M_PI * 2); cairo_set_line_width(cr, 4); cairo_set_source_rgb(cr, 0, 0, 0); cairo_stroke_preserve(cr); cairo_set_source_rgb(cr, 1, 1, 1); cairo_set_line_width(cr, 2); cairo_stroke(cr); xoff = x ? -20 : 20; align = x ? align_right : align_left; yoff = y ? -20 : 20; align |= y ? align_bottom : align_top; cairo_move_to(cr, x + xoff, y + yoff); cairo_set_font_size(cr, 18); igt_cairo_printf_line(cr, align, 0, "(%d, %d)", x, y); }
static int cairo_new_sub_path_l( lua_State* L ) { lua_cairo_t* lc = lua_cairo_check( L, 1 ); cairo_new_sub_path( lc->cairo ); return( 0 ); }
static int _new_sub_path(lua_State *L) { cairo_t *cr; luaA_to(L, dt_lua_cairo_t, &cr, 1); cairo_new_sub_path(cr); return 0; }
void cairo_rounded_rectangle(cairo_t * cr, double x, double y, double width, double height, double radius) { double degrees = M_PI / 180.0; cairo_new_sub_path(cr); cairo_arc (cr, x + width - radius, y + radius, radius, -90 * degrees, 0 * degrees); cairo_arc (cr, x + width - radius, y + height - radius, radius, 0 * degrees, 90 * degrees); cairo_arc (cr, x + radius, y + height - radius, radius, 90 * degrees, 180 * degrees); cairo_arc (cr, x + radius, y + radius, radius, 180 * degrees, 270 * degrees); cairo_close_path(cr); }
static void rounded_rectangle (cairo_t *cr, int x, int y, int w, int h, int r) { cairo_new_sub_path (cr); cairo_arc (cr, x + r, y + r, r, M_PI, 3 * M_PI / 2); cairo_arc (cr, x + w - r, y + r, r, 3 *M_PI / 2, 2 * M_PI); cairo_arc (cr, x + w - r, y + h - r, r, 0, M_PI / 2); cairo_arc (cr, x + r, y + h - r, r, M_PI / 2, M_PI); cairo_close_path (cr); }
void dv_draw_path_circle(cairo_t * cr, double x, double y, double w) { cairo_save(cr); double r = w / 2.0; cairo_new_sub_path(cr); cairo_arc(cr, x + r, y + r, r, 0.0, 2 * M_PI); cairo_close_path(cr); cairo_restore(cr); }
void TaskbarButton::Draw(cairo_t *cr) { // We only draw the button if it's pressed if (m_pressed) { double start_colour; double end_colour; double bound_colour; double percent; start_colour = START_COLOUR * 0.90; end_colour = END_COLOUR * 0.90; bound_colour = end_colour * 0.5; percent = 0.3; cairo_pattern_t *pattern; double x, y, w, h, r; x = 1.5; y = 1.5; w = m_draw_size.m_width - 3.0; h = m_draw_size.m_height - 1.5; r = 3.0; /* Create the path around the button */ cairo_new_sub_path (cr); cairo_arc (cr, x + r, y + r, r, M_PI, 3*M_PI/2); cairo_arc (cr, x + w - r, y + r, r, 3*M_PI/2, 0 ); cairo_arc (cr, x + w - r, y + h - r, r, 0, M_PI/2 ); cairo_arc (cr, x + r, y + h - r, r, M_PI/2, M_PI ); cairo_close_path (cr); /* Create the fill pattern - varying vertically */ pattern = cairo_pattern_create_linear(x, y, x, y + h); cairo_pattern_add_color_stop_rgb(pattern, 0.0, start_colour*m_colour.redf(), start_colour*m_colour.greenf(), start_colour*m_colour.bluef()); cairo_pattern_add_color_stop_rgb(pattern, 1.0, end_colour*m_colour.redf(), end_colour*m_colour.greenf(), end_colour*m_colour.bluef()); /* Fill with our pattern */ cairo_set_source(cr, pattern); cairo_fill_preserve (cr); /* Destroy the pattern */ cairo_pattern_destroy(pattern); /* Draw the outline */ cairo_set_source_rgb (cr, bound_colour, bound_colour, bound_colour); cairo_set_line_width (cr, 1.0); cairo_stroke (cr); } drawChild(cr); }
void dtgtk_cairo_paint_masks_intersection(cairo_t *cr, gint x, gint y, gint w, gint h, gint flags) { gint s = w < h ? w : h; cairo_translate(cr, x + (w / 2.0) - (s / 2.0), y + (h / 2.0) - (s / 2.0)); cairo_scale(cr, s * 1.4, s); cairo_set_line_cap(cr, CAIRO_LINE_CAP_ROUND); cairo_set_line_width(cr, 0.1); cairo_set_source_rgb(cr, 0.4, 0.4, 0.4); cairo_arc(cr, 0.05, 0.5, 0.45, 0, 6.3); cairo_new_sub_path(cr); cairo_arc(cr, 0.65, 0.5, 0.45, 0, 6.3); cairo_stroke(cr); cairo_set_source_rgb(cr, 0.7, 0.7, 0.7); cairo_new_sub_path(cr); cairo_arc(cr, 0.05, 0.5, 0.45, -1.0416, 1.0416); cairo_arc(cr, 0.65, 0.5, 0.45, 2.1, 4.1832); cairo_close_path(cr); cairo_fill(cr); cairo_identity_matrix(cr); }
static inline void do_arc (cairo_t *cr, double x, double y, double radius, int start_angle, int end_angle) { cairo_new_sub_path (cr); if (start_angle > start_angle + end_angle) { cairo_arc (cr, x, y, radius, -start_angle * (M_PI / 180.), (-start_angle - end_angle) * (M_PI / 180.)); } else { cairo_arc_negative (cr, x, y, radius, -start_angle * (M_PI / 180.), (-start_angle - end_angle) * (M_PI / 180.)); } }
static inline void do_arc (cairo_t *cr, double x, double y, double radius, double start_angle, double sweep_angle) { cairo_new_sub_path (cr); if (sweep_angle > 0) { cairo_arc (cr, x, y, radius, start_angle * (M_PI / 180.), (start_angle + sweep_angle) * (M_PI / 180.)); } else { cairo_arc_negative (cr, x, y, radius, start_angle * (M_PI / 180.), (start_angle + sweep_angle) * (M_PI / 180.)); } }
static cairo_perf_ticks_t do_fill_annuli (cairo_t *cr, int width, int height, int loops) { cairo_new_sub_path (cr); cairo_arc (cr, width/2.0, height/2.0, width/3.0, 0, 2 * M_PI); cairo_new_sub_path (cr); cairo_arc_negative (cr, width/2.0, height/2.0, width/4.0, 2 * M_PI, 0); cairo_new_sub_path (cr); cairo_arc (cr, width/2.0, height/2.0, width/6.0, 0, 2 * M_PI); cairo_new_sub_path (cr); cairo_arc_negative (cr, width/2.0, height/2.0, width/8.0, 2 * M_PI, 0); cairo_perf_timer_start (); while (loops--) cairo_fill_preserve (cr); cairo_perf_timer_stop (); cairo_new_path (cr); return cairo_perf_timer_elapsed (); }
void clock_render(rclk *clock) { cairo_t *cr; int width, height, i; double offset, angle1, angle2; double elapsed = (double) (((int32_t) time(NULL)) - clock->started); gtk_window_get_size(GTK_WINDOW(clock->widget), &width, &height); clock->cr = gdk_cairo_create(clock->widget->window); cr = clock->cr; offset = M_PI / -2.0; for(i = 0; i < 5; ++i) { angle2 = fmod(clock->rings[i].angle + (clock->rings[i].d_angle * elapsed), 2 * M_PI) + offset; angle1 = angle2 + offset; cairo_set_source_rgb(cr, 1, 1, 1); cairo_new_sub_path(cr); cairo_set_line_width(cr, 4.0); cairo_arc(cr, width/2, height/2, clock->rings[i].radius, 0, 2 * M_PI); cairo_stroke(cr); cairo_set_source_rgba(cr, 0.3, 0.3, 0.3, 0.4); cairo_new_sub_path(cr); cairo_set_line_width(cr, 2.0); cairo_arc(cr, width/2, height/2, clock->rings[i].radius, offset, angle2); cairo_stroke(cr); } cairo_destroy(clock->cr); }
static gboolean draw_cb (ClutterCairoTexture *canvas, cairo_t *cr) { EmpathyRoundedRectangle *self = EMPATHY_ROUNDED_RECTANGLE (canvas); guint width, height; guint border_width; gdouble tmp_alpha; gdouble radius; width = self->priv->width; height = self->priv->height; radius = self->priv->height / self->priv->round_factor; border_width = self->priv->border_width; /* compute the composited opacity of the actor taking into * account the opacity of the color set by the user */ tmp_alpha = (clutter_actor_get_paint_opacity (CLUTTER_ACTOR (self)) * self->priv->border_color.alpha) / 255.; cairo_set_source_rgba (cr, self->priv->border_color.red / 255., self->priv->border_color.green / 255., self->priv->border_color.blue / 255., tmp_alpha); cairo_set_line_width (cr, border_width); cairo_set_operator (cr, CAIRO_OPERATOR_CLEAR); cairo_paint (cr); cairo_set_operator (cr, CAIRO_OPERATOR_OVER); /* make room for the portion of the border drawn on the outside */ cairo_translate (cr, border_width/2.0, border_width/2.0); cairo_new_sub_path (cr); cairo_arc (cr, width - radius, radius, radius, -M_PI/2.0, 0); cairo_arc (cr, width - radius, height - radius, radius, 0, M_PI/2.0); cairo_arc (cr, radius, height - radius, radius, M_PI/2.0, M_PI); cairo_arc (cr, radius, radius, radius, M_PI, -M_PI/2.0); cairo_close_path (cr); cairo_stroke (cr); return TRUE; }
static void make_path (cairo_t *cr) { int i; cairo_save (cr); for (i = 0; i <= 3; i++) { cairo_new_sub_path (cr); cairo_move_to (cr, -SIZE / 2, 0.); cairo_line_to (cr, SIZE / 2, 0.); cairo_rotate (cr, M_PI / 4.); } cairo_restore (cr); }
void _gtk_rounded_box_path_left (const GtkRoundedBox *outer, const GtkRoundedBox *inner, cairo_t *cr) { double start_angle, middle_angle, end_angle; if (outer->box.x == inner->box.x) return; if (outer->box.y + outer->box.height == inner->box.y + inner->box.height) start_angle = G_PI_2; else start_angle = 3 * G_PI_4; middle_angle = G_PI; if (outer->box.y == inner->box.y) end_angle = 3 * G_PI_2; else end_angle = 5 * G_PI_4; cairo_new_sub_path (cr); _cairo_ellipsis (cr, outer->box.x + outer->corner[GTK_CSS_BOTTOM_LEFT].horizontal, outer->box.y + outer->box.height - outer->corner[GTK_CSS_BOTTOM_LEFT].vertical, outer->corner[GTK_CSS_BOTTOM_LEFT].horizontal, outer->corner[GTK_CSS_BOTTOM_LEFT].vertical, start_angle, middle_angle); _cairo_ellipsis (cr, outer->box.x + outer->corner[GTK_CSS_TOP_LEFT].horizontal, outer->box.y + outer->corner[GTK_CSS_TOP_LEFT].vertical, outer->corner[GTK_CSS_TOP_LEFT].horizontal, outer->corner[GTK_CSS_TOP_LEFT].vertical, middle_angle, end_angle); _cairo_ellipsis_negative (cr, inner->box.x + inner->corner[GTK_CSS_TOP_LEFT].horizontal, inner->box.y + inner->corner[GTK_CSS_TOP_LEFT].vertical, inner->corner[GTK_CSS_TOP_LEFT].horizontal, inner->corner[GTK_CSS_TOP_LEFT].vertical, end_angle, middle_angle); _cairo_ellipsis_negative (cr, inner->box.x + inner->corner[GTK_CSS_BOTTOM_LEFT].horizontal, inner->box.y + inner->box.height - inner->corner[GTK_CSS_BOTTOM_LEFT].vertical, inner->corner[GTK_CSS_BOTTOM_LEFT].horizontal, inner->corner[GTK_CSS_BOTTOM_LEFT].vertical, middle_angle, start_angle); cairo_close_path (cr); }
static cairo_test_status_t draw (cairo_t *cr, int width, int height) { cairo_set_source_rgb (cr, 0.0, 0.0, 1.0); /* blue */ /* Test cairo_new_sub_path followed by several different * path-modification functions in turn... */ /* ... cairo_move_to */ cairo_new_sub_path (cr); cairo_move_to (cr, SIZE, SIZE); cairo_line_to (cr, SIZE, 2 * SIZE); /* ... cairo_line_to */ cairo_new_sub_path (cr); cairo_line_to (cr, 2 * SIZE, 1.5 * SIZE); cairo_line_to (cr, 3 * SIZE, 1.5 * SIZE); /* ... cairo_curve_to */ cairo_new_sub_path (cr); cairo_curve_to (cr, 4.0 * SIZE, 1.5 * SIZE, 4.5 * SIZE, 1.0 * SIZE, 5.0 * SIZE, 1.5 * SIZE); /* ... cairo_arc */ cairo_new_sub_path (cr); cairo_arc (cr, 6.5 * SIZE, 1.5 * SIZE, 0.5 * SIZE, 0.0, 2.0 * M_PI); cairo_stroke (cr); return CAIRO_TEST_SUCCESS; }
void Drawer::DrawEllipse (double aWidth, double aHeight) { double X = 0.0; double Y = 0.0; cairo_get_current_point(mCairoDC, &X, &Y); cairo_save (mCairoDC); cairo_translate (mCairoDC, X, Y); cairo_scale (mCairoDC, aWidth / 2., aHeight / 2.); cairo_new_sub_path(mCairoDC); cairo_arc (mCairoDC, 0.0, 0.0, 1., 0., 2 * M_PI); cairo_scale (mCairoDC, 1.0/ (aWidth / 2.0), 1.0 / ( aHeight / 2.0)); cairo_restore (mCairoDC); cairo_stroke (mCairoDC); }