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); }
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 nand_gate_glyph(cairo_t *cr) { static cairo_pattern_t *pat = 0; cairo_save(cr); cairo_scale(cr,0.68,0.8); if(pat == 0) { pat = cairo_pattern_create_radial (0.27, 0.3, 0.08, 0.2, 0.35, 0.6); cairo_pattern_add_color_stop_rgb (pat, 0, 0.9, 0.9, 0.9); cairo_pattern_add_color_stop_rgb (pat, 1, 1.0, 1.0, 0.8); } cairo_new_path(cr); cairo_move_to(cr,0.0,0.0); cairo_line_to(cr,0.0,1.0); cairo_line_to(cr,0.5,1.0); cairo_arc_negative(cr,0.5,0.5,0.5,M_PI/2.0,0); cairo_arc(cr,1.1,0.5,0.1,M_PI,0); cairo_arc(cr,1.1,0.5,0.1,0,M_PI); cairo_arc_negative(cr,0.5,0.5,0.5,0,-M_PI/2.0); cairo_close_path(cr); cairo_set_source (cr, pat); cairo_fill_preserve (cr); cairo_set_source_rgb(cr,0.0,0.0,0.0); cairo_set_line_width(cr,0.07); cairo_set_line_join(cr,CAIRO_LINE_JOIN_ROUND); cairo_stroke(cr); cairo_restore(cr); }
void or_gate_glyph(cairo_t *cr) { static cairo_pattern_t *pat = 0; cairo_save(cr); cairo_scale(cr,0.8,0.8); if(pat == 0) { pat = cairo_pattern_create_radial (0.35, 0.3, 0.08, 0.2, 0.35, 0.6); cairo_pattern_add_color_stop_rgb (pat, 0, 0.9, 0.9, 0.9); cairo_pattern_add_color_stop_rgb (pat, 1, 0.68, 1.0, 0.68); } cairo_new_path(cr); cairo_move_to(cr,0,0); cairo_arc(cr,-0.5,0.5,sqrt(2.0)/2,-M_PI/4,M_PI/4); cairo_line_to(cr,0.5,1.0); cairo_save(cr); cairo_scale(cr,0.9,2.0); double angle = asin(3.0/4); cairo_arc_negative(cr,0.5,-0.5,1.0,M_PI/2,angle); cairo_arc_negative(cr,0.5,1.0,1.0,-angle,-M_PI/2); cairo_restore(cr); cairo_close_path(cr); cairo_set_source (cr, pat); cairo_fill_preserve (cr); cairo_set_source_rgb(cr,0.0,0.0,0.0); cairo_set_line_width(cr,0.07); cairo_set_line_join(cr,CAIRO_LINE_JOIN_ROUND); cairo_stroke(cr); cairo_restore(cr); }
static void aosd_deco_rfunc_concaverect ( Ghosd * osd , cairo_t * cr , aosd_deco_style_data_t * data ) { /* decoration information ---------------------- draws a rectangle with concave angles; uses 2 colors (user color 1 and 2) and 1 font (user font 1), with optional shadow */ PangoLayout *osd_layout = data->layout; aosd_color_t color0 = g_array_index( data->decoration->colors , aosd_color_t , 0 ); aosd_color_t color1 = g_array_index( data->decoration->colors , aosd_color_t , 1 ); aosd_color_t textcolor0 = data->text->fonts_color[0]; aosd_color_t shadowcolor0 = data->text->fonts_shadow_color[0]; gboolean draw_shadow = data->text->fonts_draw_shadow[0]; gint width = 0, height = 0, bearing = 0; aosd_layout_size( osd_layout , &width , &height , &bearing ); /* draw jigsaw-piece-like container */ cairo_set_source_rgba( cr , (gdouble)color0.red / 65535 , (gdouble)color0.green / 65535 , (gdouble)color0.blue / 65535 , (gdouble)color0.alpha / 65535 ); cairo_move_to( cr , aosd_deco_styles[AOSD_DECO_STYLE_CONCAVERECT].padding.left , 0 ); cairo_arc_negative( cr , width + aosd_deco_styles[AOSD_DECO_STYLE_CONCAVERECT].padding.left + 2 , aosd_deco_styles[AOSD_DECO_STYLE_CONCAVERECT].padding.top - 2 , 8. , -G_PI_2 , 0. ); cairo_arc_negative( cr , width + aosd_deco_styles[AOSD_DECO_STYLE_CONCAVERECT].padding.left + 2 , aosd_deco_styles[AOSD_DECO_STYLE_CONCAVERECT].padding.top + height + 2 , 8. , -4. * G_PI_2 , -3. * G_PI_2 ); cairo_arc_negative( cr , aosd_deco_styles[AOSD_DECO_STYLE_CONCAVERECT].padding.left - 2 , aosd_deco_styles[AOSD_DECO_STYLE_CONCAVERECT].padding.top + height + 2 , 8. , -3. * G_PI_2 , -2. * G_PI_2 ); cairo_arc_negative( cr , aosd_deco_styles[AOSD_DECO_STYLE_CONCAVERECT].padding.left - 2 , aosd_deco_styles[AOSD_DECO_STYLE_CONCAVERECT].padding.top - 2 , 8. , -2. * G_PI_2 , -G_PI_2 ); cairo_close_path( cr ); cairo_fill_preserve( cr ); cairo_set_source_rgba( cr , (gdouble)color1.red / 65535 , (gdouble)color1.green / 65535 , (gdouble)color1.blue / 65535 , (gdouble)color1.alpha / 65535 ); cairo_stroke( cr ); if ( draw_shadow == TRUE ) { /* draw text shadow */ cairo_set_source_rgba( cr , (gdouble)shadowcolor0.red / 65535 , (gdouble)shadowcolor0.green / 65535 , (gdouble)shadowcolor0.blue / 65535 , (gdouble)shadowcolor0.alpha / 65535 ); cairo_move_to( cr , aosd_deco_styles[AOSD_DECO_STYLE_CONCAVERECT].padding.left + bearing + 2 , aosd_deco_styles[AOSD_DECO_STYLE_CONCAVERECT].padding.top + 2 ); pango_cairo_show_layout( cr , osd_layout ); } /* draw text */ cairo_set_source_rgba( cr , (gdouble)textcolor0.red / 65535 , (gdouble)textcolor0.green / 65535 , (gdouble)textcolor0.blue / 65535 , (gdouble)textcolor0.alpha / 65535 ); cairo_move_to( cr , aosd_deco_styles[AOSD_DECO_STYLE_CONCAVERECT].padding.left + bearing , aosd_deco_styles[AOSD_DECO_STYLE_CONCAVERECT].padding.top ); pango_cairo_show_layout( cr , osd_layout ); }
void shot_animation(cairo_t* cr, double size, double direction, struct cannon* can) { UNUSED(size); UNUSED(direction); /* Reduce the reload time by half of it so it draws the explosion and * the flash for half the reload time. */ int time = can->timeToReload - RELOAD_RATIO / 2; if (time <= 0) { return; /* if the gun is loaded don't paint anything */ } cairo_save(cr); cairo_pattern_t* pat; cairo_translate(cr, can->x, can->y); #if 0 /* flash of the shot, should be translate to the robot's position. */ cairo_scale(cr, size, size); cairo_rotate(cr, direction); pat = cairo_pattern_create_linear(128, 64, 128, 128.0); cairo_pattern_add_color_stop_rgba(pat, 0, 1, 0, 0, time / (RELOAD_RATIO / 2.0)); cairo_pattern_add_color_stop_rgba(pat, 1, 1, 1, 0, time / (RELOAD_RATIO / 2.0)); cairo_set_source(cr, pat); cairo_move_to(cr, 32, 50); cairo_arc_negative(cr, 32, 32, 18, 90 * (M_PI / 180.0), 0); cairo_arc_negative(cr, 68, 32, 18, M_PI, 90 * (M_PI / 180.0)); cairo_arc_negative(cr, 50, 50, 18, M_PI, 0); cairo_fill(cr); cairo_pattern_destroy(pat); #endif /* explosion */ cairo_arc(cr, 0, 0, 40, 0, 2 * M_PI); pat = cairo_pattern_create_radial(0, 0, 10, 0, 0, 40); cairo_pattern_add_color_stop_rgba(pat, 0, 1, 0, 0, time / (RELOAD_RATIO / 2.0)); cairo_pattern_add_color_stop_rgba(pat, 0.3, 1, 0.5, 0, time / (RELOAD_RATIO / 2.0)); cairo_pattern_add_color_stop_rgba(pat, 0.6, 1, 0.2, 0, time / (RELOAD_RATIO / 2.0)); cairo_set_source(cr, pat); cairo_fill(cr); cairo_pattern_destroy(pat); cairo_restore(cr); }
void buttonDoButtonPathImpl(button *self, cairo_t *cr) { size ourSize = WIDGET(self)->size; // Do the rounded rectangle cairo_arc_negative(cr, borderRadius, borderRadius, borderRadius, -M_PI_2, -M_PI); cairo_line_to(cr, 0, ourSize.y-borderRadius); cairo_arc_negative(cr, borderRadius, ourSize.y-borderRadius, borderRadius, M_PI, M_PI_2); cairo_line_to(cr, ourSize.x-borderRadius, ourSize.y); cairo_arc_negative(cr, ourSize.x-borderRadius, ourSize.y-borderRadius, borderRadius, M_PI_2, 0); cairo_line_to(cr, ourSize.x, borderRadius); cairo_arc_negative(cr, ourSize.x-borderRadius, borderRadius, borderRadius, 0, -M_PI_2); cairo_close_path(cr); }
static void fill_arc(DiaRenderer *self, Point *center, real width, real height, real angle1, real angle2, Color *color) { DiaCairoRenderer *renderer = DIA_CAIRO_RENDERER (self); Point start; double a1, a2; DIAG_NOTE(g_message("draw_arc %fx%f <%f,<%f", width, height, angle1, angle2)); cairo_set_source_rgba (renderer->cr, color->red, color->green, color->blue, 1.0); cairo_new_path (renderer->cr); start.x = center->x + (width / 2.0) * cos((M_PI / 180.0) * angle1); start.y = center->y - (height / 2.0) * sin((M_PI / 180.0) * angle1); cairo_move_to (renderer->cr, center->x, center->y); cairo_line_to (renderer->cr, start.x, start.y); a1 = - (angle1 / 180.0) * G_PI; a2 = - (angle2 / 180.0) * G_PI; /* FIXME: to handle width != height some cairo_scale/cairo_translate would be needed */ cairo_arc_negative (renderer->cr, center->x, center->y, width > height ? height / 2.0 : width / 2.0, /* FIXME 2nd radius */ a1, a2); cairo_line_to (renderer->cr, center->x, center->y); cairo_close_path (renderer->cr); cairo_fill (renderer->cr); DIAG_STATE(renderer->cr) }
void RadialPlot::DrawItem(cairo_t* cr, RadialPlotTreeItem const &item, wxPoint c, int diameter) { double ro = ((double)diameter) * (item.level +1) / (2*(maxLevel + 1)); double ri = ((double)diameter) * (item.level+.1) / (2*(maxLevel + 1)); double sa = item.startAngle; double ea = item.endAngle; double da = .01; sa += da; ea -= da; if (ea < sa) ea = sa = (sa+ea) / 2; sa -= M_PI/2; ea -=M_PI/2; cairo_arc(cr, c.x, c.y, ro, sa, ea); cairo_arc_negative(cr, c.x, c.y, ri, ea, sa); cairo_close_path(cr); cairo_set_source_rgb(cr, item.color.Red()/255.0, item.color.Green()/255.0, item.color.Blue()/255.0); cairo_fill_preserve(cr); cairo_set_source_rgb(cr, 0, 0, 0); cairo_set_line_width(cr, 1); cairo_stroke(cr); }
// FIXME: This function needs to be adjusted to match the functionality on the Mac side. void GraphicsContext::strokeArc(const IntRect& rect, int startAngle, int angleSpan) { if (paintingDisabled()) return; if (strokeStyle() == NoStroke) return; int x = rect.x(); int y = rect.y(); float w = rect.width(); #if 0 // FIXME: unused so far float h = rect.height(); float scaleFactor = h / w; float reverseScaleFactor = w / h; #endif float r = w / 2; float fa = startAngle; float falen = fa + angleSpan; cairo_t* cr = m_data->cr; cairo_save(cr); cairo_arc_negative(cr, x + r, y + r, r, -fa * M_PI/180, -falen * M_PI/180); setColor(cr, strokeColor()); cairo_set_line_width(cr, strokeThickness()); cairo_stroke(cr); cairo_restore(cr); }
static void br_cairo_draw_section(duc_graph *g, double a1, double a2, double r1, double r2, double H, double S, double V, double line) { struct cairo_backend_data *bd = g->backend_data; cairo_t *cr = bd->cr; double R, G, B; hsv2rgb(H, S, V, &R, &G, &B); cairo_new_path(cr); cairo_arc(cr, g->cx, g->cy, r1, ang(a1), ang(a2)); cairo_arc_negative(cr, g->cx, g->cy, r2, ang(a2), ang(a1)); cairo_close_path(cr); if(R != 1.0 || G != 1.0 || B != 1.0) { cairo_pattern_t *pat; pat = cairo_pattern_create_radial(g->cx, g->cy, 0, g->cx, g->cy, g->cx-50); double off1 = r2 / g->cx; double off2 = r1 / g->cx; cairo_pattern_add_color_stop_rgb(pat, off1, R, G, B); cairo_pattern_add_color_stop_rgb(pat, off2, R * 0.6, G * 0.6, B * 0.6); cairo_set_source(cr, pat); cairo_fill_preserve(cr); cairo_pattern_destroy(pat); } if(line) { cairo_set_line_width(cr, 0.5); cairo_set_source_rgba(cr, 0, 0, 0, 0.9); cairo_stroke(cr); } }
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 int cr_arc_negative (lua_State *L) { cairo_t **obj = luaL_checkudata(L, 1, OOCAIRO_MT_NAME_CONTEXT); cairo_arc_negative(*obj, luaL_checknumber(L, 2), luaL_checknumber(L, 3), luaL_checknumber(L, 4), luaL_checknumber(L, 5), luaL_checknumber(L, 6)); return 0; }
static gboolean draw_1 (ClutterCanvas *canvas, cairo_t *cr, int width_raw, int height_raw) { /* rounded rectangle taken from: * * http://cairographics.org/samples/rounded_rectangle/ * * we leave 1 pixel around the edges to avoid jagged edges * when rotating the actor */ double x = 1.0, /* parameters like cairo_rectangle */ y = 1.0, width = width_raw - 2.0, height = height_raw - 2.0, corner_radius = 5.0, tab_radius = 20.0; double radius = corner_radius ; double degrees = M_PI / 180.0; cairo_save (cr); cairo_set_operator (cr, CAIRO_OPERATOR_CLEAR); cairo_paint (cr); cairo_restore (cr); 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); /*bottom-left*/cairo_arc (cr, x + radius + 30, y + height - radius, radius, 90 * degrees, 180 * degrees); cairo_arc_negative (cr, x + 30 - tab_radius, 225, tab_radius, 0 * degrees, -45 * degrees); cairo_arc (cr, x + tab_radius, 255 - 75, tab_radius, 135 * degrees, 180 * degrees); cairo_arc (cr, x + tab_radius, 255 - 75 - 85, tab_radius, 180 * degrees, 225 * degrees); cairo_arc_negative (cr, x + 30 - tab_radius, 255 - 75 - 85 - 45, tab_radius, 45 * degrees, 0 * degrees); /*top-left*/cairo_arc (cr, x + radius + 30, y + radius, radius, 180 * degrees, 270 * degrees); cairo_close_path (cr); cairo_set_source_rgba (cr, 0.14*.2, 0.14, 0.36*.5, 0.5); cairo_fill_preserve (cr); /* we're done drawing */ return TRUE; }
static VALUE cr_arc_negative (VALUE self, VALUE xc, VALUE yc, VALUE radius, VALUE angle1, VALUE angle2) { cairo_arc_negative (_SELF, NUM2DBL (xc), NUM2DBL (yc), NUM2DBL (radius), NUM2DBL (angle1), NUM2DBL (angle2)); cr_check_status (_SELF); return self; }
void GraphicsContext::strokeArc(const IntRect& rect, int startAngle, int angleSpan) { if (paintingDisabled() || strokeStyle() == NoStroke) return; int x = rect.x(); int y = rect.y(); float w = rect.width(); float h = rect.height(); float scaleFactor = h / w; float reverseScaleFactor = w / h; float hRadius = w / 2; float vRadius = h / 2; float fa = startAngle; float falen = fa + angleSpan; cairo_t* cr = platformContext()->cr(); cairo_save(cr); if (w != h) cairo_scale(cr, 1., scaleFactor); cairo_arc_negative(cr, x + hRadius, (y + vRadius) * reverseScaleFactor, hRadius, -fa * M_PI/180, -falen * M_PI/180); if (w != h) cairo_scale(cr, 1., reverseScaleFactor); int patternWidth = 0; switch (strokeStyle()) { case DottedStroke: patternWidth = floorf(strokeThickness() / 2.f); break; case DashedStroke: patternWidth = 3 * floorf(strokeThickness() / 2.f); break; default: break; } setSourceRGBAFromColor(cr, strokeColor()); if (patternWidth) { float distance = 0; if (hRadius == vRadius) distance = (piFloat * hRadius) / 2.f; else // We are elliptical and will have to estimate the distance distance = (piFloat * sqrtf((hRadius * hRadius + vRadius * vRadius) / 2.f)) / 2.f; double patternOffset = calculateStrokePatternOffset(floorf(distance), patternWidth); double patternWidthAsDouble = patternWidth; cairo_set_dash(cr, &patternWidthAsDouble, 1, patternOffset); } cairo_stroke(cr); cairo_restore(cr); }
void cairox_paint_curved_arrow(cairo_t *cr, ArrowHeadType head, CairoxPoint *coordinates, int points, double width, double zoom) { int i = 0; cairo_set_line_width(cr, width * zoom); cairo_move_to(cr, zoom * coordinates[i].x, zoom * coordinates[i].y); if (points <= 2) { /* Not enough line segments for true curves: */ cairox_paint_final_arrow_segment(cr, head, &coordinates[1], width, zoom); } else { while (++i < points-1) { double w1 = line_length(&coordinates[i-1], &coordinates[i]); double w2 = line_length(&coordinates[i+1], &coordinates[i]); double dw = MIN(w1, w2) / 2.0; CairoxPoint point_a; // CairoxPoint point_b; CairoxPoint centre; double slope_a, slope_b, radius; double angle1, angle2; /* Where does the arc start: */ point_a.x = coordinates[i-1].x + (coordinates[i].x-coordinates[i-1].x)*(w1-dw)/w1; point_a.y = coordinates[i-1].y + (coordinates[i].y-coordinates[i-1].y)*(w1-dw)/w1; /* Where does the arc end: */ // point_b.x = coordinates[i+1].x + (coordinates[i].x-coordinates[i+1].x)*(w2-dw)/w2; // point_b.y = coordinates[i+1].y + (coordinates[i].y-coordinates[i+1].y)*(w2-dw)/w2; slope_a = line_calculate_slope(&coordinates[i-1], &coordinates[i]); slope_b = line_calculate_slope(&coordinates[i+1], &coordinates[i]); radius = dw * tan((slope_b-slope_a)/2.0); /* arc is of size radius and goes from point_a to point_b */ centre.x = point_a.x - radius * sin(slope_a); centre.y = point_a.y + radius * cos(slope_a); /* Draw a line segment in the appropriate direction: */ cairo_line_to(cr, point_a.x, point_a.y); /* Now draw the arc: */ if (radius < 0) { angle1 = slope_a + M_PI / 2.0; angle2 = slope_b - M_PI / 2.0; cairo_arc(cr, centre.x, centre.y, -radius, angle1, angle2); } else { angle1 = slope_a - M_PI / 2.0; angle2 = slope_b + M_PI / 2.0; cairo_arc_negative(cr, centre.x, centre.y, radius, angle1, angle2); } } cairox_paint_final_arrow_segment(cr, head, &coordinates[i-1], width, zoom); } }
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; }
// cairo_public void // cairo_arc_negative (cairo_t *cr, // double xc, double yc, // double radius, // double angle1, double angle2); static int l_cairo_arc_negative(lua_State* L) { cairo_t *cr = get_cairo_t (L, 1); double xc = luaL_checknumber(L, 2); double yc = luaL_checknumber(L, 3); double radius = luaL_checknumber(L, 4); double angle1 = luaL_checknumber(L, 5); double angle2 = luaL_checknumber(L, 6); cairo_arc_negative(cr, xc, yc, radius, angle1, angle2); return 0; }
static void draw_pie(GtkWidget *pie, WindowData *windata, cairo_t *cr) { gdouble arc_angle = 1.0 - (gdouble)windata->remaining / (gdouble)windata->timeout; cairo_set_source_rgba (cr, 1.0, 0.4, 0.0, 0.3); cairo_move_to(cr, PIE_RADIUS, PIE_RADIUS); cairo_arc_negative(cr, PIE_RADIUS, PIE_RADIUS, PIE_RADIUS, -M_PI/2, (-0.25 + arc_angle)*2*M_PI); cairo_line_to(cr, PIE_RADIUS, PIE_RADIUS); cairo_fill (cr); }
static PyObject * pycairo_arc_negative (PycairoContext *o, PyObject *args) { double xc, yc, radius, angle1, angle2; if (!PyArg_ParseTuple (args, "ddddd:Context.arc_negative", &xc, &yc, &radius, &angle1, &angle2)) return NULL; cairo_arc_negative (o->ctx, xc, yc, radius, angle1, angle2); RETURN_NULL_IF_CAIRO_CONTEXT_ERROR(o->ctx); Py_RETURN_NONE; }
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 int cairo_arc_negative_l( lua_State* L ) { lua_cairo_t* lc = lua_cairo_check( L, 1 ); cairo_arc_negative( lc->cairo, luaL_checknumber( L, 2 ), /* xc */ luaL_checknumber( L, 3 ), /* yc */ luaL_checknumber( L, 4 ), /* radius */ luaL_checknumber( L, 5 ), /* angle1 */ luaL_checknumber( L, 6 ) ); /* angle2 */ return( 0 ); }
void dtgtk_cairo_paint_masks_exclusion(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_source_rgb(cr, 0.6, 0.6, 0.6); cairo_arc(cr, 0.0, 0.5, 0.45, 0, 6.2832); cairo_arc_negative(cr, 0.714, 0.5, 0.45, 0, 6.2832); cairo_fill(cr); cairo_identity_matrix(cr); }
void Path::addArc(const FloatPoint& p, float r, float sa, float ea, 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(sa) || !isfinite(ea)) return; cairo_t* cr = platformPath()->m_cr; if (anticlockwise) cairo_arc_negative(cr, p.x(), p.y(), r, sa, ea); else cairo_arc(cr, p.x(), p.y(), r, sa, ea); }
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 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 (); }
static gboolean on_countdown_draw(GtkWidget* pie, cairo_t* cr, WindowData* windata) { GtkAllocation allocation; GtkStyleContext* style; GdkRGBA color; GdkRGBA fg_color; cairo_t* context; cairo_surface_t* surface; double r, g, b; context = gdk_cairo_create(gtk_widget_get_window(GDK_WINDOW(windata->pie_countdown))); #if GTK_CHECK_VERSION(3, 0, 0) style = gtk_widget_get_style_context(windata->win); cairo_set_operator(context, CAIRO_OPERATOR_SOURCE); gtk_widget_get_allocation(pie, &allocation); surface = cairo_surface_create_similar(cairo_get_target(context), CAIRO_CONTENT_COLOR_ALPHA, allocation.width, allocation.height); cairo_set_source_surface (cr, surface, 0, 0); cairo_set_operator(cr, CAIRO_OPERATOR_OVER); #if GTK_CHECK_VERSION (3, 0, 0) gtk_style_context_get_color (context, GTK_STATE_FLAG_NORMAL, &color); gtk_style_context_get_background_color (context, GTK_STATE_FLAG_NORMAL, &fg_color); r = color.red; g = color.green; b = color.blue; cairo_set_source_rgba(cr, r, g, b, BACKGROUND_ALPHA); cairo_paint(cr); if (windata->timeout > 0) { gdouble pct = (gdouble) windata->remaining / (gdouble) windata->timeout; gdk_cairo_set_source_rgba(cr, &fg_color); cairo_move_to(cr, PIE_RADIUS, PIE_RADIUS); cairo_arc_negative(cr, PIE_RADIUS, PIE_RADIUS, PIE_RADIUS, -G_PI_2, -(pct * G_PI * 2) - G_PI_2); cairo_line_to(cr, PIE_RADIUS, PIE_RADIUS); cairo_fill(cr); } cairo_destroy(cr); cairo_set_source_surface(context, surface, 0, 0); cairo_paint(context); cairo_surface_destroy(surface); cairo_destroy(context); return TRUE; }