Example #1
0
void arrow_1_glyph(cairo_t *cr) {
	static cairo_pattern_t *pat_in, *pat_out = 0;

	if(pat_in == 0) {
		pat_in = cairo_pattern_create_radial (ARROW_HEAD_START-0.1, 0.25, 0.01, ARROW_HEAD_START-0.1, 0.25, 1.0);
		cairo_pattern_add_color_stop_rgb (pat_in, 0, 1.0, 0.9, 0.88);
		cairo_pattern_add_color_stop_rgb (pat_in, ARROW_BODY_RADIUS*(0.7), 1.0, 0.35, 0.35);
		cairo_pattern_add_color_stop_rgb (pat_in, 1, 0.7, 0.0, 0.0);
	}

	if(pat_out == 0) {
		pat_out = cairo_pattern_create_radial (0, 0, ARROW_BODY_RADIUS, 0.03, 0, 0.3);
		cairo_pattern_add_color_stop_rgba(pat_out, 0, 1.0, 0.3, 0.3, 0.6);
		cairo_pattern_add_color_stop_rgba(pat_out, 1, 1.0, 0.1, 0.1, 0.0);
	}

	cairo_save(cr);
	cairo_translate(cr,ARROW_POS_X,ARROW_POS_Y);

	cairo_new_path(cr);
	cairo_move_to(cr,0.0,0.0);
	cairo_line_to(cr,0.0,0.5);
	cairo_line_to(cr,1.0,0.5);
	cairo_line_to(cr,1.0,0.0);
	cairo_close_path(cr);

	cairo_save(cr);
	cairo_translate(cr,ARROW_HEAD_START-0.1, 0.25);
	cairo_scale(cr,1.7,0.9);
	cairo_set_source(cr,pat_out);
	cairo_fill(cr);
	cairo_restore(cr);

	cairo_new_path(cr);
	cairo_move_to(cr,ARROW_BODY_START,0.25-ARROW_BODY_RADIUS);
	cairo_line_to(cr,ARROW_BODY_START,0.25+ARROW_BODY_RADIUS);
	cairo_line_to(cr,ARROW_HEAD_START,0.25+ARROW_BODY_RADIUS);
	cairo_line_to(cr,ARROW_HEAD_START,0.25+ARROW_HEAD_RADIUS);
	cairo_line_to(cr,ARROW_HEAD_END,0.25);
	cairo_line_to(cr,ARROW_HEAD_START,0.25-ARROW_HEAD_RADIUS);
	cairo_line_to(cr,ARROW_HEAD_START,0.25-ARROW_BODY_RADIUS);
	cairo_close_path(cr);
	
	cairo_set_source(cr,pat_in);
	cairo_fill_preserve(cr);

	cairo_set_source_rgb(cr,0,0,0);
	cairo_set_line_width(cr,0.03);
	cairo_clip_preserve(cr);
	cairo_stroke(cr);

	cairo_restore(cr);
}
Example #2
0
void and_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.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, 0.68, 0.68);
	}

	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,-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);
}
Example #3
0
static cairo_pattern_t *
fade_pattern (cairo_pattern_t *pattern,
              double           opacity)
{
  double x0, y0, x1, y1, r0, r1;
  cairo_pattern_t *result;
  int i, n;

  switch (cairo_pattern_get_type (pattern))
    {
    case CAIRO_PATTERN_TYPE_LINEAR:
      cairo_pattern_get_linear_points (pattern, &x0, &y0, &x1, &y1);
      result = cairo_pattern_create_linear (x0, y0, x1, y1);
      break;
    case CAIRO_PATTERN_TYPE_RADIAL:
      cairo_pattern_get_radial_circles (pattern, &x0, &y0, &r0, &x1, &y1, &r1);
      result = cairo_pattern_create_radial (x0, y0, r0, x1, y1, r1);
      break;
    default:
      g_return_val_if_reached (NULL);
    }

  cairo_pattern_get_color_stop_count (pattern, &n);
  for (i = 0; i < n; i++)
    {
      double o, r, g, b, a;

      cairo_pattern_get_color_stop_rgba (pattern, i, &o, &r, &g, &b, &a);
      cairo_pattern_add_color_stop_rgba (result, o, r, g, b, a * opacity);
    }

  return result;
}
Example #4
0
static gboolean
ghid_trackball_expose (GtkWidget * widget, GdkEventExpose * ev)
{
  cairo_t *cr;
  cairo_pattern_t *pattern;
  GtkAllocation allocation;
  GdkColor color;
  double radius;

  cr = gdk_cairo_create (gtk_widget_get_window (widget));

          /* set a clip region for the expose event */
  cairo_rectangle (cr,
                   ev->area.x, ev->area.y,
                   ev->area.width, ev->area.height);
  cairo_clip (cr);

  gtk_widget_get_allocation (widget, &allocation);

  radius = (MIN (allocation.width, allocation.height) - 5) / 2.;
  pattern = cairo_pattern_create_radial (2 * radius * 0.8,
                                         2 * radius * 0.3,
                                         0.,
                                         2 * radius * 0.50,
                                         2 * radius * 0.50,
                                         2 * radius * 0.71);

  color = widget->style->fg[GTK_WIDGET_STATE (widget)];

  cairo_pattern_add_color_stop_rgb (pattern, 0.0,
                                    (color.red   / 65535. * 0.5 + 4.5) / 5.,
                                    (color.green / 65535. * 0.5 + 4.5) / 5.,
                                    (color.blue  / 65535. * 0.5 + 4.5) / 5.);
  cairo_pattern_add_color_stop_rgb (pattern, 0.2,
                                    (color.red   / 65535. * 1.5 + 3.7) / 5.,
                                    (color.green / 65535. * 1.5 + 3.7) / 5.,
                                    (color.blue  / 65535. * 1.5 + 3.7) / 5.);
  cairo_pattern_add_color_stop_rgb (pattern, 1.0,
                                    (color.red   / 65535. * 5. + 0.) / 5.,
                                    (color.green / 65535. * 5. + 0.) / 5.,
                                    (color.blue  / 65535. * 5. + 0.) / 5.);
  cairo_set_source (cr, pattern);
  cairo_pattern_destroy (pattern);

  cairo_save (cr);
  cairo_translate (cr, allocation.width / 2., allocation.height / 2.);
  cairo_scale (cr, radius, radius);
  cairo_arc (cr, 0., 0., 1., 0., 2 * M_PI);
  cairo_restore (cr);

  cairo_fill_preserve (cr);

  gdk_cairo_set_source_color (cr, &widget->style->bg[GTK_WIDGET_STATE (widget)]);
  cairo_set_line_width (cr, 0.4);
  cairo_stroke (cr);

  cairo_destroy (cr);

  return FALSE;
}
Example #5
0
void copy_cell_glyph(cairo_t *cr, int rotation) {
	static cairo_pattern_t *pat = 0;

	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, 0.2, 0.9, 0.3);
	}

	cairo_save(cr);
	cairo_scale(cr,0.8,0.8);

	cairo_new_path(cr);
	cairo_arc(cr,0.5,0.5,0.5,(rotation*2-5)*M_PI/4,(rotation*2+5)*M_PI/4);
	cairo_line_to(cr,0.5,0.5);
	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);
}
Example #6
0
static cairo_time_t
do_pattern_create_radial (cairo_t *cr, int width, int height, int loops)
{
    cairo_perf_timer_start ();
    cairo_perf_set_thread_aware (cr, FALSE);

    while (loops--) {
	cairo_pattern_t *pattern;
	int i;

	if (loops == 0)
		cairo_perf_set_thread_aware (cr, TRUE);

	for (i = 0; i < RADIALS_COUNT; i++) {
	    pattern =
		cairo_pattern_create_radial (radials[i].cx0, radials[i].cy0,
					     radials[i].radius0,
					     radials[i].cx1, radials[i].cy1,
					     radials[i].radius1);
	    cairo_pattern_destroy (pattern);
	}
    }

    cairo_perf_timer_stop ();

    return cairo_perf_timer_elapsed ();
}
Example #7
0
cairo_pattern_t* Gradient::platformGradient()
{
    if (m_gradient)
        return m_gradient;

    if (m_radial)
        m_gradient = cairo_pattern_create_radial(m_p0.x(), m_p0.y(), m_r0, m_p1.x(), m_p1.y(), m_r1);
    else
        m_gradient = cairo_pattern_create_linear(m_p0.x(), m_p0.y(), m_p1.x(), m_p1.y());

    Vector<ColorStop>::iterator stopIterator = m_stops.begin();
    while (stopIterator != m_stops.end()) {
        cairo_pattern_add_color_stop_rgba(m_gradient, stopIterator->stop, stopIterator->red, stopIterator->green, stopIterator->blue, stopIterator->alpha);
        ++stopIterator;
    }

    switch (m_spreadMethod) {
    case SpreadMethodPad:
        cairo_pattern_set_extend(m_gradient, CAIRO_EXTEND_PAD);
        break;
    case SpreadMethodReflect:
        cairo_pattern_set_extend(m_gradient, CAIRO_EXTEND_REFLECT);
        break;
    case SpreadMethodRepeat:
        cairo_pattern_set_extend(m_gradient, CAIRO_EXTEND_REPEAT);
        break;
    }

    cairo_matrix_t matrix = m_gradientSpaceTransformation;
    cairo_matrix_invert(&matrix);
    cairo_pattern_set_matrix(m_gradient, &matrix);

    return m_gradient;
}
Example #8
0
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);
	}
}
Example #9
0
static cairo_test_status_t
draw (cairo_t *cr, int width, int height)
{
    cairo_pattern_t *pattern;
    cairo_matrix_t mat = {
	0, -4.5254285714285709 * FACTOR,
	-2.6398333333333333 * FACTOR, 0,
	0, 0
    };

    pattern = cairo_pattern_create_radial (0, 0, 0,
					   0, 0, 16384 * FACTOR);
    cairo_pattern_add_color_stop_rgba (pattern,
				       0, 0.376471, 0.533333, 0.27451, 1);
    cairo_pattern_add_color_stop_rgba (pattern, 1, 1, 1, 1, 1);
    cairo_pattern_set_matrix (pattern, &mat);

    cairo_scale (cr, 0.05, 0.05);
    cairo_translate (cr, 6000, 3500);

    cairo_set_source (cr, pattern);
    cairo_rectangle (cr, -6000, -3500, 12000, 7000);
    cairo_pattern_destroy (pattern);
    cairo_fill (cr);

    return CAIRO_TEST_SUCCESS;
}
Example #10
0
static cairo_pattern_t*
radial_gradient_create_pattern(CcGradient const* gradient,
                               CcView const    * view,
                               CcItem const    * item)
{
    CcDRect const* bounds = cc_hash_map_lookup(item->bounds, view);
    CcDRect nul = {0.0, 0.0, 0.0, 0.0};

    if(G_LIKELY(bounds)) {
        nul = *bounds;
    }

    cc_view_world_to_window(view, &nul.x1, &nul.y1);
    cc_view_world_to_window(view, &nul.x2, &nul.y2);

    nul.x2 -= nul.x1 + 1.0;
    nul.y2 -= nul.y1 + 1.0;

    return cairo_pattern_create_radial(nul.x1 + P(gradient)->x * nul.x2,
                                       nul.y1 + P(gradient)->y * nul.y2,
                                       0.0,
                                       nul.x1 + P(gradient)->x * nul.x2,
                                       nul.y1 + P(gradient)->y * nul.y2,
                                       P(gradient)->radius * MAX(nul.x2, nul.y2));
}
static void
draw_gradient (cairo_t		*cr,
	       int		x,
	       int		y,
	       int		size,
	       double		r1_offset,
	       double		r1_radius,
	       double		r2_offset,
	       double		r2_radius,
	       cairo_extend_t	extend)
{
    cairo_pattern_t *pattern;

    cairo_save (cr);

    pattern = cairo_pattern_create_radial (x + size/2.0 + r1_offset,
					   y + size/2.0 + r1_offset,
					   r1_radius,
					   x + size/2.0 + r2_offset,
					   y + size/2.0 + r2_offset,
					   r2_radius);
    cairo_pattern_add_color_stop_rgb (pattern, 0.25, 1, 0, 0);
    cairo_pattern_set_extend (pattern, extend);

    cairo_rectangle (cr, x, y, size, size);
    cairo_clip (cr);

    cairo_set_source (cr, pattern);
    cairo_paint (cr);

    cairo_pattern_destroy (pattern);

    cairo_restore (cr);
}
Example #12
0
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);
}
Example #13
0
cairo_pattern_t *
_gtk_gradient_resolve_full (GtkGradient             *gradient,
                            GtkStyleProviderPrivate *provider,
                            GtkCssComputedValues    *values,
                            GtkCssComputedValues    *parent_values,
                            GtkCssDependencies      *dependencies)
{
  cairo_pattern_t *pattern;
  guint i;

  g_return_val_if_fail (gradient != NULL, NULL);
  g_return_val_if_fail (GTK_IS_STYLE_PROVIDER (provider), NULL);
  g_return_val_if_fail (GTK_IS_CSS_COMPUTED_VALUES (values), NULL);
  g_return_val_if_fail (parent_values == NULL || GTK_IS_CSS_COMPUTED_VALUES (parent_values), NULL);
  g_return_val_if_fail (*dependencies == 0, NULL);

  if (gradient->radius0 == 0 && gradient->radius1 == 0)
    pattern = cairo_pattern_create_linear (gradient->x0, gradient->y0,
                                           gradient->x1, gradient->y1);
  else
    pattern = cairo_pattern_create_radial (gradient->x0, gradient->y0,
                                           gradient->radius0,
                                           gradient->x1, gradient->y1,
                                           gradient->radius1);

  for (i = 0; i < gradient->stops->len; i++)
    {
      ColorStop *stop;
      GtkCssValue *val;
      GdkRGBA rgba;
      GtkCssDependencies stop_deps;

      stop = &g_array_index (gradient->stops, ColorStop, i);

      /* if color resolving fails, assume transparency */
      val = _gtk_css_color_value_resolve (_gtk_symbolic_color_get_css_value (stop->color),
                                          provider,
                                          _gtk_css_computed_values_get_value (values, GTK_CSS_PROPERTY_COLOR),
                                          GTK_CSS_DEPENDS_ON_COLOR,
                                          &stop_deps,
                                          NULL);
      if (val)
        {
          rgba = *_gtk_css_rgba_value_get_rgba (val);
          *dependencies = _gtk_css_dependencies_union (*dependencies, stop_deps);
          _gtk_css_value_unref (val);
        }
      else
        {
          rgba.red = rgba.green = rgba.blue = rgba.alpha = 0.0;
        }

      cairo_pattern_add_color_stop_rgba (pattern, stop->offset,
                                         rgba.red, rgba.green,
                                         rgba.blue, rgba.alpha);
    }

  return pattern;
}
Example #14
0
void displayDiliriumUIMicroKnob(deliriumUI* deliriumUI_window, cairo_t* cr, int widgetNumber)
{
	deliriumUIWidget* deliriumUIWidgets = deliriumUI_window->deliriumUIWidgets;

	int x = deliriumUIWidgets[widgetNumber].x * deliriumUI_window->widgetWidth;
	int y = deliriumUIWidgets[widgetNumber].y * deliriumUI_window->widgetHeight;
	int w = deliriumUIWidgets[widgetNumber].w * deliriumUI_window->widgetWidth;
	int h = deliriumUIWidgets[widgetNumber].h * deliriumUI_window->widgetHeight;

	float value = deliriumUIWidgets[widgetNumber].value; // deliriumUIWidgets[widgetNumber].value;

	cairo_set_source_rgb(cr, 0.0, 0.0, 0.0);
	cairo_rectangle(cr, x, y, w, h);
	cairo_clip(cr);

	// Draw label
	cairo_text_extents_t extents;
	cairo_set_font_size(cr, h / 5);
	cairo_text_extents(cr, deliriumUIWidgets[widgetNumber].label, &extents);

	cairo_move_to(cr,
	              (x + w / 2) - extents.width / 2,
	              (y + h) - extents.height / 4);

	if (deliriumUIWidgets[widgetNumber].hover) {
		cairo_set_source_rgba(cr, 1, 1, 1, 1);;
	} else {
		cairo_set_source_rgba(cr, 1, 1, 1, 0.6);;
	}

	cairo_show_text(cr, deliriumUIWidgets[widgetNumber].label);

	y -= (h/8);

	// ------------------------------------------------------------------

	float cos_x =  (w/5) * (cos(((((1-value)*0.75)-0.3)*2) * M_PI));
	float sin_y =  (w/5) * (sin(((((1-value)*0.75)-0.3)*2) * M_PI));

	cairo_pattern_t* pat;

	pat = cairo_pattern_create_radial (x+(w/2) + sin_y, y+(h/2)+cos_x, 0, x+(w/2), y+(h/2) ,(w/2.5));

	cairo_pattern_add_color_stop_rgba (pat, 0,0.4,0.4,0.4,1);
	cairo_pattern_add_color_stop_rgba (pat, 0.5,0.2,0.2,0.2,1);
	cairo_pattern_add_color_stop_rgba (pat, 0.8,0.17,0.17,0.17,1);
	cairo_pattern_add_color_stop_rgba (pat, 1.0,0.0,0.0,0.0,1);

	cairo_set_source(cr, pat);
	cairo_arc(cr, x+(w/2), y+(h/2), (w/2.5), 0.0, 2 * M_PI);
	cairo_fill(cr);
	cairo_set_source_rgb(cr, 0.0, 0.0, 0.0);
	cairo_arc(cr, x+(w/2) +cos_x, y+(h/2)+sin_y, (w/16), 0.0, 2 * M_PI);
	cairo_fill(cr);

	cairo_reset_clip(cr);	
	cairo_pattern_destroy (pat);
}
Example #15
0
void wxCairoSVGRadialGradient::Op(cairo_t* cairo_image, bool preserve, wxCairoSVGPaintServerOp op) {

	cairo_pattern_t *pat;
	bool saved = false;

	if (m_gradientUnits == _T("objectBoundingBox")) {
		cairo_save(cairo_image);
		saved = true;
		double minx;
		double miny;
		double maxx;
		double maxy;

		cairo_path_extents(cairo_image, &minx, &miny, &maxx, &maxy);
		cairo_matrix_t mat;
		cairo_matrix_init(&mat, maxx-minx, 0, 0, maxy-miny, minx, miny);
		cairo_transform(cairo_image, &mat);
		wxLogTrace(_T("svg"), _T("wxCairoSVGRadialGradient::Op transformed to objectBoundingBox minx %f miny %f maxx %f maxy %f"),
				minx, miny, maxx, maxy);
	} else if (m_gradientTransform.Contains(_T("matrix"))) {
		double m[6];
		wxArrayString params = wxStringTokenize(m_gradientTransform.Mid(m_gradientTransform.Find(_T("matrix(")) + 7), _T(" "));
		if (params.Count() == 6) {
			for (int i = 0; i < 6; i++) {
				params[i].Strip().ToDouble(&m[i]);
			}
			cairo_save(cairo_image);
			saved = true;
			cairo_matrix_t mat;
			cairo_matrix_init(&mat, m[0], m[1], m[2], m[3], m[4], m[5]);
			cairo_transform(cairo_image, &mat);
			wxLogTrace(_T("svg"), _T("wxCairoSVGRadialGradient::Op matrix transform %f %f %f %f %f %f"),
					m[0], m[1], m[2], m[3], m[4], m[5]);
		}
	}

	pat = cairo_pattern_create_radial(m_cx, m_cy, 0, m_cx, m_cy, m_r);
	wxLogTrace(_T("svg"), _T("wxCairoSVGRadialGradient::Op cairo_pattern_create_radial cx %f cy %f r %f"),
			m_cx, m_cy, m_r);

	for (wxCairoSVGGradientStopList::iterator i = m_stopList.begin(); i != m_stopList.end(); ++i) {
		wxCairoSVGGradientStop* stop = *i;
		if (stop->m_opacity == 1) {
			cairo_pattern_add_color_stop_rgb(pat, stop->m_offset, (double) stop->m_r / 255.0, (double) stop->m_g / 255.0, (double) stop->m_b / 255.0);
		} else {
			cairo_pattern_add_color_stop_rgba(pat, stop->m_offset, (double) stop->m_r / 255.0, (double) stop->m_g / 255.0, (double) stop->m_b / 255.0, stop->m_opacity);
		}
	}

	cairo_set_source(cairo_image, pat);
	wxCairoSVGPaintServer::Op(cairo_image, preserve, op);

	if (saved) cairo_restore(cairo_image);

	cairo_pattern_destroy(pat);

	wxLogTrace(_T("svg"), _T("wxCairoSVGRadialGradient::Op done"));
}
Example #16
0
static cairo_pattern_t *
transition_pattern (cairo_pattern_t *start,
                    cairo_pattern_t *end,
                    double           progress)
{
  double sx0, sy0, sx1, sy1, sr0, sr1, ex0, ey0, ex1, ey1, er0, er1;
  cairo_pattern_t *result;
  int i, n;

  progress = CLAMP (progress, 0.0, 1.0);

  if (end == NULL)
    return fade_pattern (start, 1.0 - progress);

  g_assert (cairo_pattern_get_type (start) == cairo_pattern_get_type (end));

  switch (cairo_pattern_get_type (start))
    {
    case CAIRO_PATTERN_TYPE_LINEAR:
      cairo_pattern_get_linear_points (start, &sx0, &sy0, &sx1, &sy1);
      cairo_pattern_get_linear_points (end, &ex0, &ey0, &ex1, &ey1);
      result = cairo_pattern_create_linear ((1 - progress) * sx0 + progress * ex0,
                                            (1 - progress) * sx1 + progress * ex1,
                                            (1 - progress) * sy0 + progress * ey0,
                                            (1 - progress) * sy1 + progress * ey1);
      break;
    case CAIRO_PATTERN_TYPE_RADIAL:
      cairo_pattern_get_radial_circles (start, &sx0, &sy0, &sr0, &sx1, &sy1, &sr1);
      cairo_pattern_get_radial_circles (end, &ex0, &ey0, &er0, &ex1, &ey1, &er1);
      result = cairo_pattern_create_radial ((1 - progress) * sx0 + progress * ex0,
                                            (1 - progress) * sy0 + progress * ey0,
                                            (1 - progress) * sr0 + progress * er0,
                                            (1 - progress) * sx1 + progress * ex1,
                                            (1 - progress) * sy1 + progress * ey1,
                                            (1 - progress) * sr1 + progress * er1);
      break;
    default:
      g_return_val_if_reached (NULL);
    }

  cairo_pattern_get_color_stop_count (start, &n);
  for (i = 0; i < n; i++)
    {
      double so, sr, sg, sb, sa, eo, er, eg, eb, ea;

      cairo_pattern_get_color_stop_rgba (start, i, &so, &sr, &sg, &sb, &sa);
      cairo_pattern_get_color_stop_rgba (end, i, &eo, &er, &eg, &eb, &ea);

      cairo_pattern_add_color_stop_rgba (result,
                                         (1 - progress) * so + progress * eo,
                                         (1 - progress) * sr + progress * er,
                                         (1 - progress) * sg + progress * eg,
                                         (1 - progress) * sb + progress * eb,
                                         (1 - progress) * sa + progress * ea);
    }

  return result;
}
static gboolean
button_drawing_area_draw_event (GtkWidget  *widget,
				cairo_t    *cr,
				GtkBuilder *dialog)
{
	gdouble center_x, center_y, size;
	GdkRGBA inner_color, outer_color;
	cairo_pattern_t *pattern;

	size = MAX (MIN (gtk_widget_get_allocated_width (widget), gtk_widget_get_allocated_height (widget)), 1);
	center_x = gtk_widget_get_allocated_width (widget) / 2.0;
	center_y = gtk_widget_get_allocated_height (widget) / 2.0;

	switch (double_click_state) {
	case DOUBLE_CLICK_TEST_ON:
	case DOUBLE_CLICK_TEST_STILL_ON:
	case DOUBLE_CLICK_TEST_ALMOST_THERE:
	case DOUBLE_CLICK_TEST_GEGL:
		gdk_rgba_parse (&outer_color, "#729fcf");
		gdk_rgba_parse (&inner_color, "#729fcf");
		break;
	case DOUBLE_CLICK_TEST_MAYBE:
		gdk_rgba_parse (&outer_color, "#729fcf");
		gdk_rgba_parse (&inner_color, "#ffffff");
		break;
	case DOUBLE_CLICK_TEST_OFF:
		gdk_rgba_parse (&outer_color, "#ffffff");
		gdk_rgba_parse (&inner_color, "#ffffff");
		break;
	}

	/* Draw shadow. */
	cairo_rectangle (cr, center_x - size / 2,  center_y - size / 2, size, size);
	pattern = cairo_pattern_create_radial (center_x, center_y, 0, center_x, center_y, size);
	cairo_pattern_add_color_stop_rgba (pattern, 0.5 - SHADOW_SIZE / size, 0, 0, 0, SHADOW_OPACITY);
	cairo_pattern_add_color_stop_rgba (pattern, 0.5, 0, 0, 0, 0);
	cairo_set_source (cr, pattern);
	cairo_fill (cr);

	/* Draw outer circle. */
	cairo_set_line_width (cr, OUTER_CIRCLE_SIZE);
	cairo_arc (cr, center_x, center_y + SHADOW_SHIFT_Y,
		   INNER_CIRCLE_SIZE + ANNULUS_SIZE + OUTER_CIRCLE_SIZE / 2,
		   0, 2 * G_PI);
	gdk_cairo_set_source_rgba (cr, &outer_color);
	cairo_stroke (cr);

	/* Draw inner circle. */
	cairo_set_line_width (cr, 0);
	cairo_arc (cr, center_x, center_y + SHADOW_SHIFT_Y,
		   INNER_CIRCLE_SIZE,
		   0, 2 * G_PI);
	gdk_cairo_set_source_rgba (cr, &inner_color);
	cairo_fill (cr);

	return FALSE;
}
Example #18
0
static cairo_pattern_t *
create_node_pattern(double r, double g, double b)
{
	cairo_pattern_t *retval = cairo_pattern_create_radial(0.0, -0.33, 0.0, 0.0, 0.0, 1.0);
	cairo_pattern_add_color_stop_rgb(retval, 0.0, MAX(1.0, r * 1.5), MAX(1.0, g * 1.5), MAX(1.0, b * 1.5));
	cairo_pattern_add_color_stop_rgb(retval, 0.5, r, g, b);
	cairo_pattern_add_color_stop_rgb(retval, 0.75, r * 0.5, g * 0.5, b * 0.5);
	cairo_pattern_add_color_stop_rgb(retval, 1.0, r, g, b);
	return retval;
}
Example #19
0
static PyObject *
radial_gradient_new (PyTypeObject *type, PyObject *args, PyObject *kwds) {
  double cx0, cy0, radius0, cx1, cy1, radius1;
  if (!PyArg_ParseTuple(args, "dddddd:RadialGradient.__new__",
			&cx0, &cy0, &radius0, &cx1, &cy1, &radius1))
    return NULL;
  return PycairoPattern_FromPattern (
	    cairo_pattern_create_radial (cx0, cy0, radius0, cx1, cy1, radius1),
	    NULL);
}
Example #20
0
static void
render(cairo_t *cr)
{
cairo_pattern_t *pat;

pat = cairo_pattern_create_linear (0.0, 0.0,  0.0, 256.0);
cairo_pattern_add_color_stop_rgba (pat, 1, 0, 0, 0, 1);
cairo_pattern_add_color_stop_rgba (pat, 0, 1, 1, 1, 1);
cairo_rectangle (cr, 0, 0, 256, 256);
cairo_set_source (cr, pat);
cairo_fill (cr);
cairo_pattern_destroy (pat);

pat = cairo_pattern_create_radial (115.2, 102.4, 25.6,
                                   102.4,  102.4, 128.0);
cairo_pattern_add_color_stop_rgba (pat, 0, 1, 1, 1, 1);
cairo_pattern_add_color_stop_rgba (pat, 1, 0, 0, 0, 1);
cairo_set_source (cr, pat);
cairo_arc (cr, 128.0, 128.0, 76.8, 0, 2 * M_PI);
cairo_fill (cr);
cairo_pattern_destroy (pat);


cairo_set_source_rgba(cr, 1.0, 0.5, 0.5, 0.3);
cairo_set_line_width(cr, 40.96);
cairo_move_to(cr, 76.8, 84.48);
cairo_rel_line_to(cr, 51.2, -51.2);
cairo_rel_line_to(cr, 51.2, 51.2);
cairo_set_line_join(cr, CAIRO_LINE_JOIN_MITER);
cairo_stroke(cr);

cairo_set_source_rgba(cr, 0.0, 0.5, 0.5, 0.3);
cairo_set_line_width(cr, 40.96);
cairo_move_to(cr, 76.8, 161.28);
cairo_rel_line_to(cr, 51.2, -51.2);
cairo_rel_line_to(cr, 51.2, 51.2);
cairo_set_line_join(cr, CAIRO_LINE_JOIN_MITER);
cairo_stroke(cr);

cairo_set_source_rgba(cr, 1.0, 0.5, 0.5, 0.3);
cairo_set_line_width(cr, 40.96);
cairo_move_to(cr, 76.8, 84.48);
cairo_rel_line_to(cr, 51.2, -51.2);
cairo_rel_line_to(cr, 51.2, 51.2);
cairo_set_line_join(cr, CAIRO_LINE_JOIN_MITER);
cairo_stroke(cr);

cairo_set_source_rgba(cr, 0.5, 0.5, 1.0, 0.3);
cairo_set_line_width(cr, 40.96);
cairo_move_to(cr, 76.8, 238.08);
cairo_rel_line_to(cr, 51.2, -51.2);
cairo_rel_line_to(cr, 51.2, 51.2);
cairo_set_line_join(cr, CAIRO_LINE_JOIN_MITER);
cairo_stroke(cr);
}
Example #21
0
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);
}
Example #22
0
void draw_radial_round(cairo_t *cr, gint x, gint y, gint r)
{
    cairo_pattern_t *radial = cairo_pattern_create_radial(x, y, r, x, y, 0);
    cairo_pattern_add_color_stop_rgba(radial, 0, 0, 0, 0, 0);
    cairo_pattern_add_color_stop_rgba(radial, 0.66, 0, 0, 0, 0.2);
    cairo_pattern_add_color_stop_rgba(radial, 1, 0, 0, 0, 0.33);
    cairo_arc(cr, x, y, r, 0, 2 * G_PI);
    cairo_set_source(cr, radial);
    cairo_fill(cr);

    cairo_pattern_destroy(radial);
}
Example #23
0
static int l_pattern_create_radial(lua_State * L)
{
	double cx0 = luaL_checknumber(L, 1);
	double cy0 = luaL_checknumber(L, 2);
	double radius0 = luaL_checknumber(L, 3);
	double cx1 = luaL_checknumber(L, 4);
	double cy1 = luaL_checknumber(L, 5);
	double radius1 = luaL_checknumber(L, 6);
	struct lpattern_t * pattern = lua_newuserdata(L, sizeof(struct lpattern_t));
	pattern->pattern = cairo_pattern_create_radial(cx0, cy0, radius0, cx1, cy1, radius1);
	luaL_setmetatable(L, MT_PATTERN);
	return 1;
}
int l_cairo_pattern_create_radial(lua_State * L)
{
	double cx0 = luaL_checknumber(L, 1);
	double cy0 = luaL_checknumber(L, 2);
	double radius0 = luaL_checknumber(L, 3);
	double cx1 = luaL_checknumber(L, 4);
	double cy1 = luaL_checknumber(L, 5);
	double radius1 = luaL_checknumber(L, 6);
	cairo_pattern_t ** pattern = lua_newuserdata(L, sizeof(cairo_pattern_t *));
	*pattern = cairo_pattern_create_radial(cx0, cy0, radius0, cx1, cy1, radius1);
	luaL_setmetatable(L, MT_NAME_CAIRO_PATTERN);
	return 1;
}
Example #25
0
static void draw_gradient(cairo_t *cr, double step, int width, int height)
{
	cairo_pattern_t *pat;
	double r, g, b;
	double x, y, tx, ty;
	char buf[128];
	double fontsize = 20.0;

	r = 0.1 + fabs(sin(5 * step));
	g = 0.0;
	b = 0.1 + fabs(sin(3 * step));

	x = width * (sin(10 * step) + 1)/2;
	y = height * (1 - fabs(sin(30 * step)));

	tx = width/2 * (sin(5 * step) + 1)/2;
	ty = fontsize + (height - fontsize) * (1 - fabs(sin(20 * step)));


	pat = cairo_pattern_create_linear (0.0, 0.0,  0.0, height);
	cairo_pattern_add_color_stop_rgba (pat, 1, r, g, b, 1);
	cairo_pattern_add_color_stop_rgba (pat, 0, 0, 0, 0, 1);
	cairo_rectangle (cr, 0, 0, width, height);
	cairo_set_source (cr, pat);
	cairo_fill (cr);
	cairo_pattern_destroy (pat);

	pat = cairo_pattern_create_radial (x-128, y-128, 25.6,
					   x+128, y+128, 128.0);
	cairo_pattern_add_color_stop_rgba (pat, 0, 0, 1, 0, 1);
	cairo_pattern_add_color_stop_rgba (pat, 1, 0, 0, 0, 1);
	cairo_set_source (cr, pat);
	cairo_arc (cr, x, y, 76.8, 0, 2 * M_PI);
	cairo_fill (cr);
	cairo_pattern_destroy (pat);

	/* Draw text */
	cairo_select_font_face (cr, "Sans", CAIRO_FONT_SLANT_NORMAL,
				CAIRO_FONT_WEIGHT_NORMAL);
	cairo_set_font_size (cr, fontsize);

	re_snprintf(buf, sizeof(buf), "%H", fmt_gmtime, NULL);

	cairo_move_to (cr, tx, ty);
	cairo_text_path (cr, buf);
	cairo_set_source_rgb (cr, 1, 1, 1);
	cairo_fill_preserve (cr);
	cairo_set_source_rgb (cr, 0, 0, 0);
	cairo_set_line_width (cr, 0.1);
	cairo_stroke (cr);
}
Example #26
0
File: draw.c Project: zanton/dagviz
cairo_pattern_t *
dv_get_color_radial_pattern(double radius, double alpha) {
  char ** stops = (char **) DV_RADIAL_PATTERN_STOPS;
  int n = DV_RADIAL_PATTERN_STOPS_NUM;
  cairo_pattern_t * pat = cairo_pattern_create_radial(0.0, 0.0, 0.0, 0.0, 0.0, radius);
  double step = 1.0 / (n - 1);
  int i;
  for (i = 0; i < n; i++) {
    GdkRGBA color;
    gdk_rgba_parse(&color, stops[i]);
    cairo_pattern_add_color_stop_rgba(pat, i * step, color.red, color.green, color.blue, color.alpha * alpha);
  }
  return pat;
}
Example #27
0
int
main (void)
{
    cairo_test_context_t ctx;
    cairo_surface_t *surface;
    cairo_pattern_t *solid_rgb, *solid_rgba, *surface_pattern, *linear, *radial;
    cairo_test_status_t result = CAIRO_TEST_SUCCESS;

    cairo_test_init (&ctx, "pattern-get-type");
    cairo_test_log (&ctx, "Creating patterns of all types\n");

    solid_rgb = cairo_pattern_create_rgb (0.0, 0.1, 0.2);
    solid_rgba = cairo_pattern_create_rgba (0.3, 0.4, 0.5, 0.6);
    surface = cairo_image_surface_create (CAIRO_FORMAT_ARGB32,
					  1, 1);
    surface_pattern = cairo_pattern_create_for_surface (surface);
    linear = cairo_pattern_create_linear (0.0, 0.0, 10.0, 10.0);
    radial = cairo_pattern_create_radial (10.0, 10.0, 0.1,
					  10.0, 10.0, 1.0);

    cairo_test_log (&ctx, "Verifying return values of cairo_pattern_get_type\n");

    if (cairo_pattern_get_type (solid_rgb) != CAIRO_PATTERN_TYPE_SOLID)
	result = CAIRO_TEST_FAILURE;

    if (cairo_pattern_get_type (solid_rgba) != CAIRO_PATTERN_TYPE_SOLID)
	result = CAIRO_TEST_FAILURE;

    if (cairo_pattern_get_type (surface_pattern) != CAIRO_PATTERN_TYPE_SURFACE)
	result = CAIRO_TEST_FAILURE;

    if (cairo_pattern_get_type (linear) != CAIRO_PATTERN_TYPE_LINEAR)
	result = CAIRO_TEST_FAILURE;

    if (cairo_pattern_get_type (radial) != CAIRO_PATTERN_TYPE_RADIAL)
	result = CAIRO_TEST_FAILURE;

    cairo_test_log (&ctx, "Cleaning up\n");

    cairo_pattern_destroy (solid_rgb);
    cairo_pattern_destroy (solid_rgba);
    cairo_pattern_destroy (surface_pattern);
    cairo_surface_destroy (surface);
    cairo_pattern_destroy (linear);
    cairo_pattern_destroy (radial);

    cairo_test_fini (&ctx);

    return result;
}
Example #28
0
static VALUE
cr_radial_pattern_initialize (VALUE self, VALUE cx0, VALUE cy0, VALUE radius0,
                              VALUE cx1, VALUE cy1, VALUE radius1)
{
  cairo_pattern_t *pattern;

  pattern = cairo_pattern_create_radial (NUM2DBL (cx0), NUM2DBL (cy0),
                                         NUM2DBL (radius0),
                                         NUM2DBL (cx1), NUM2DBL (cy1),
                                         NUM2DBL (radius1));
  cr_pattern_check_status (pattern);
  DATA_PTR (self) = pattern;
  return Qnil;
}
Example #29
0
void  draw_mask(cairo_t *cr)
{
	cairo_pattern_t *linpat, *radpat;
	linpat = cairo_pattern_create_linear (0, 1, 1, 1);
	cairo_pattern_add_color_stop_rgb (linpat, 1, 0, 0, 0); //offset ,r,g,b
	cairo_pattern_add_color_stop_rgb (linpat, 1, 0, 0, 0);
	
	radpat = cairo_pattern_create_radial (300,200, 100, 300,200, 400);
	cairo_pattern_add_color_stop_rgba (radpat, 1, 0, 0, 0, 0.5);
	cairo_pattern_add_color_stop_rgba (radpat, 1, 0, 0, 0, 0.5);
	
	cairo_set_source (cr, linpat);
	cairo_mask (cr, radpat);
}
Example #30
0
cairo_pattern_t* Gradient::platformGradient(float globalAlpha)
{
    if (m_gradient && m_platformGradientAlpha == globalAlpha)
        return m_gradient;

    platformDestroy();
    m_platformGradientAlpha = globalAlpha;

    if (m_radial)
        m_gradient = cairo_pattern_create_radial(m_p0.x(), m_p0.y(), m_r0, m_p1.x(), m_p1.y(), m_r1);
    else
        m_gradient = cairo_pattern_create_linear(m_p0.x(), m_p0.y(), m_p1.x(), m_p1.y());

    Vector<ColorStop>::iterator stopIterator = m_stops.begin();
    while (stopIterator != m_stops.end()) {
#if !PLATFORM(JS) || USE(ACCELERATED_COMPOSITING)
        cairo_pattern_add_color_stop_rgba(m_gradient, stopIterator->stop,
                                          stopIterator->red, stopIterator->green, stopIterator->blue,
                                          stopIterator->alpha * globalAlpha);
#else
				// Swap the RGBA channels, canvas painting needs to be ARGB
				// but since the channels come out backwards as ABGR we just
				// swap the red and blue to get the same channel format without
				// haveing to go through all of the pixels and swap them post-blit.
				cairo_pattern_add_color_stop_rgba(m_gradient, stopIterator->stop,
																					stopIterator->blue, stopIterator->green, stopIterator->red,
																					stopIterator->alpha * globalAlpha);
#endif
        ++stopIterator;
    }

    switch (m_spreadMethod) {
    case SpreadMethodPad:
        cairo_pattern_set_extend(m_gradient, CAIRO_EXTEND_PAD);
        break;
    case SpreadMethodReflect:
        cairo_pattern_set_extend(m_gradient, CAIRO_EXTEND_REFLECT);
        break;
    case SpreadMethodRepeat:
        cairo_pattern_set_extend(m_gradient, CAIRO_EXTEND_REPEAT);
        break;
    }

    cairo_matrix_t matrix = m_gradientSpaceTransformation;
    cairo_matrix_invert(&matrix);
    cairo_pattern_set_matrix(m_gradient, &matrix);

    return m_gradient;
}