Esempio n. 1
0
static cairo_test_status_t
draw (cairo_t *cr, int width, int height)
{
    size_t i = 0;
    cairo_operator_t op;
    cairo_t *bgcr, *fgcr;
    cairo_surface_t *bg, *fg;

    bg = cairo_surface_create_similar (cairo_get_target (cr), 
	    CAIRO_CONTENT_COLOR_ALPHA, SIZE * STEPS, SIZE * STEPS);
    fg = cairo_surface_create_similar (cairo_get_target (cr), 
	    CAIRO_CONTENT_COLOR_ALPHA, SIZE * STEPS, SIZE * STEPS);
    bgcr = cairo_create (bg);
    fgcr = cairo_create (fg);
    cairo_scale (bgcr, SIZE, SIZE);
    cairo_scale (fgcr, SIZE, SIZE);
    create_patterns (bgcr, fgcr);
    cairo_destroy (bgcr);
    cairo_destroy (fgcr);

    for (op = START_OPERATOR; op <= STOP_OPERATOR; op++, i++) {
	cairo_save (cr);
	cairo_translate (cr, 
		SIZE * (STEPS + 1) * (i % COUNT),
		SIZE * (STEPS + 1) * (i / COUNT));
	do_blend (cr, op, bg, fg);
	cairo_restore (cr);
    }

    cairo_surface_destroy (fg);
    cairo_surface_destroy (bg);

    return CAIRO_TEST_SUCCESS;
}
Esempio n. 2
0
static void
subdraw (cairo_t *cr, int width, int height)
{
    size_t i = 0;
    cairo_operator_t op;
    cairo_t *bgcr, *fgcr;
    cairo_surface_t *bg, *fg;

    bg = cairo_surface_create_similar (cairo_get_target (cr),
	    CAIRO_CONTENT_COLOR_ALPHA, SIZE * STEPS, SIZE * STEPS);
    fg = cairo_surface_create_similar (cairo_get_target (cr),
	    CAIRO_CONTENT_COLOR_ALPHA, SIZE * STEPS, SIZE * STEPS);
    bgcr = cairo_create (bg);
    fgcr = cairo_create (fg);
    cairo_scale (bgcr, SIZE, SIZE);
    cairo_scale (fgcr, SIZE, SIZE);
    create_patterns (bgcr, fgcr);
    cairo_destroy (bgcr);
    cairo_destroy (fgcr);

    for (op = START_OPERATOR; op <= STOP_OPERATOR; op++, i++) {
	cairo_save (cr);
	cairo_translate (cr,
		SIZE * (STEPS + 1) * (i % COUNT),
		SIZE * (STEPS + 1) * (i / COUNT));
	cairo_rectangle (cr, 0, 0, SIZE * (STEPS + 1), SIZE * (STEPS+1));
	cairo_clip (cr);
	do_composite (cr, op, bg, fg);
	cairo_restore (cr);
    }

    cairo_surface_destroy (fg);
    cairo_surface_destroy (bg);
}
static void paint_window(GtkWidget* widget, WindowData* windata)
{
	cairo_t* context;
	cairo_surface_t* surface;
	cairo_t* cr;

	if (windata->width == 0 || windata->height == 0)
	{
		#if GTK_CHECK_VERSION(3, 0, 0)

			GtkAllocation allocation;

			gtk_widget_get_allocation(windata->win, &allocation);

			windata->width = MAX(allocation.width, 1);
			windata->height = MAX(allocation.height, 1);
		#else
			windata->width = MAX(windata->win->allocation.width, 1);
			windata->height = MAX(windata->win->allocation.height, 1);
		#endif
	}

	context = gdk_cairo_create(widget->window);

	cairo_set_operator(context, CAIRO_OPERATOR_SOURCE);


	#if GTK_CHECK_VERSION(3, 0, 0)

		GtkAllocation allocation;

		gtk_widget_get_allocation(widget, &allocation);

		surface = cairo_surface_create_similar(cairo_get_target(context), CAIRO_CONTENT_COLOR_ALPHA, allocation.width, allocation.height);
	#else

		surface = cairo_surface_create_similar(cairo_get_target(context), CAIRO_CONTENT_COLOR_ALPHA, widget->allocation.width, widget->allocation.height);
	#endif

    cr = cairo_create(surface);

	fill_background(widget, windata, cr);

	cairo_destroy(cr);
	cairo_set_source_surface(context, surface, 0, 0);
	cairo_paint(context);
	cairo_surface_destroy(surface);
	cairo_destroy(context);

	update_shape(windata);
}
Esempio n. 4
0
static cairo_surface_t *
_similar_surface_create (void		 *closure,
			 cairo_content_t  content,
			 double 	  width,
			 double 	  height,
			 long		  uid)
{
    cairo_surface_t *surface;
    struct scache skey, *s;

    if (uid == 0 || surface_cache == NULL)
	return cairo_surface_create_similar (closure, content, width, height);

    skey.entry.hash = uid;
    s = _cairo_hash_table_lookup (surface_cache, &skey.entry);
    if (s != NULL) {
	if (s->content == content &&
	    s->width   == width   &&
	    s->height  == height)
	{
	    return cairo_surface_reference (s->surface);
	}

	/* The surface has been resized, allow the original entry to expire
	 * as it becomes inactive.
	 */
    }

    surface = cairo_surface_create_similar (closure, content, width, height);
    s = malloc (sizeof (struct scache));
    if (s == NULL)
	return surface;

    s->entry.hash = uid;
    s->content = content;
    s->width = width;
    s->height = height;
    s->surface = surface;
    if (_cairo_hash_table_insert (surface_cache, &s->entry)) {
	free (s);
    } else if (cairo_surface_set_user_data
	       (surface,
		(const cairo_user_data_key_t *) &surface_cache,
		s, scache_remove))
    {
	scache_remove (s);
    }

    return surface;
}
Esempio n. 5
0
/* cache buttons as small surfaces */
static cairo_surface_t *cache_button(Gameboard *g,
				     void (*draw)(cairo_t *c, 
						  double x, 
						  double y),
				     double pR,double pG,double pB,double pA,
				     double fR,double fG,double fB,double fA){
  cairo_t *wc = gdk_cairo_create(g->w.window);
  cairo_surface_t *ret = 
    cairo_surface_create_similar (cairo_get_target (wc),
				  CAIRO_CONTENT_COLOR_ALPHA,
				  BUTTON_RADIUS*2+1,
				  BUTTON_RADIUS*2+1);
  cairo_t *c = cairo_create(ret);
  cairo_destroy (wc);

  cairo_save(c);
  cairo_set_operator(c,CAIRO_OPERATOR_CLEAR);
  cairo_set_source_rgba (c, 1,1,1,1);
  cairo_paint(c);
  cairo_restore(c);
     
  cairo_set_source_rgba(c,fR,fG,fB,fA);
  cairo_set_line_width(c,BUTTON_LINE_WIDTH);
  draw(c,BUTTON_RADIUS+.5,BUTTON_RADIUS+.5);

  cairo_set_source_rgba(c,pR,pG,pB,pA);
  cairo_stroke(c);
  
  cairo_destroy(c);
  return ret;
}
Esempio n. 6
0
/* Scale the surface with the width and height requested */
cairo_surface_t *
scale_surface      (cairo_surface_t  *surface,
                    gdouble           width,
                    gdouble           height)
{
  gdouble old_width = cairo_image_surface_get_width (surface);
  gdouble old_height = cairo_image_surface_get_height (surface);
	
  cairo_surface_t *new_surface = cairo_surface_create_similar(surface, CAIRO_CONTENT_COLOR_ALPHA, width, height);
  cairo_t *cr = cairo_create (new_surface);

  /* Scale *before* setting the source surface (1) */
  cairo_scale (cr, width / old_width, height / old_height);
  cairo_set_source_surface (cr, surface, 0, 0);

  /* To avoid getting the edge pixels blended with 0 alpha, which would 
   * occur with the default EXTEND_NONE. Use EXTEND_PAD for 1.2 or newer (2)
   */
  cairo_pattern_set_extend (cairo_get_source(cr), CAIRO_EXTEND_REFLECT); 

  /* Replace the destination with the source instead of overlaying */
  cairo_set_operator (cr, CAIRO_OPERATOR_SOURCE);

  /* Do the actual drawing */
  cairo_paint (cr);
   
  cairo_destroy (cr);

  return new_surface;
}
Esempio n. 7
0
/**
 * windows resize funtion
*/
static gboolean
resize_window (GtkWidget      *widget,
              GdkEventMotion *mev)
{
	int w,h;
	if(isFullSreen)
		gdk_window_get_size(widget->window,&w,&h);
	else {
		w = DEFAULT_WIDTH;	
		h = DEFAULT_HEIGHT;	
	}
		
	if(w!=window_w && h!=window_h){
		window_w = w;
		window_h = h;

		surface = cairo_surface_create_similar (
          surface, 
          CAIRO_CONTENT_COLOR_ALPHA,
          w, h);
		gtk_widget_set_size_request(widget,w,h);
		
		CleanPaint();
	}

  /* tell the canvas widget that it needs to redraw itself */
 	 gtk_widget_queue_draw (widget);
  return FALSE;
}
Esempio n. 8
0
static gboolean configure_cb (GtkWidget *widget,
        GdkEventConfigure *evt, gpointer user_data) {
    canvasbacken_data_t *data = user_data;
    assert (data);

    int w = gtk_widget_get_allocated_width (widget);
    int h = gtk_widget_get_allocated_height (widget);

    if (data->track) 
        cairo_surface_destroy (data->track);
    data->track = gdk_window_create_similar_surface (
            gtk_widget_get_window (widget),
            CAIRO_CONTENT_COLOR_ALPHA,
            w, h);
    clear_surface (data->track);

    if (data->surf)
        cairo_surface_destroy (data->surf);

    data->surf = cairo_surface_create_similar (
            data->track,
            CAIRO_CONTENT_COLOR_ALPHA,
            w, h);

    clear_surface (data->surf);

    canvas_draw (data);
    gtk_widget_queue_draw (widget);

    return TRUE;
}
Esempio n. 9
0
static void
draw_mask (cairo_t *cr, int x, int y)
{
    cairo_surface_t *mask_surface;
    cairo_t *cr2;

    double width = (int)(0.9 * WIDTH);
    double height = (int)(0.9 * HEIGHT);
    x += 0.05 * WIDTH;
    y += 0.05 * HEIGHT;

    mask_surface = cairo_surface_create_similar (cairo_get_group_target (cr),
						 CAIRO_CONTENT_ALPHA,
						 width, height);
    cr2 = cairo_create (mask_surface);
    cairo_surface_destroy (mask_surface);

    cairo_save (cr2);
    cairo_set_source_rgba (cr2, 0, 0, 0, 0); /* transparent */
    cairo_set_operator (cr2, CAIRO_OPERATOR_SOURCE);
    cairo_paint (cr2);
    cairo_restore (cr2);

    cairo_set_source_rgb (cr2, 1, 1, 1); /* white */

    cairo_arc (cr2, 0.5 * width, 0.5 * height, 0.45 * height, 0, 2 * M_PI);
    cairo_fill (cr2);

    cairo_mask_surface (cr, cairo_get_target (cr2), x, y);
    cairo_destroy (cr2);
}
Esempio n. 10
0
cairo_surface_t *
ink_cairo_surface_create_same_size(cairo_surface_t *s, cairo_content_t c)
{
    cairo_surface_t *ns = cairo_surface_create_similar(s, c,
        ink_cairo_surface_get_width(s), ink_cairo_surface_get_height(s));
    return ns;
}
Esempio n. 11
0
static SeedValue
seed_cairo_surface_create_similar (SeedContext ctx,
				   SeedObject function,
				   SeedObject this_object,
				   gsize argument_count,
				   const SeedValue arguments[],
				   SeedException *exception)
{
  gint width, height;
  cairo_surface_t *surface, *ret;
  cairo_content_t content;
  CHECK_THIS();
  if (argument_count != 3)
    {
      EXPECTED_EXCEPTION("create_similar", "3 arguments");
    }

  surface = seed_object_to_cairo_surface (ctx, this_object, exception);
  if (!surface)
    return seed_make_undefined (ctx);
  content = seed_value_to_long (ctx, arguments[0], exception);
  width = seed_value_to_int (ctx, arguments[1], exception);
  height = seed_value_to_int (ctx, arguments[2], exception);

  ret = cairo_surface_create_similar (surface, content, width, height);
  return seed_object_from_cairo_surface (ctx, ret);
}
Esempio n. 12
0
cairo_surface_t *
BitmapSource::GetSurface (cairo_t *cr)
{
	if (image_surface == NULL)
		return NULL;

	if (native_surface)
		return native_surface;
	
	if (cr == NULL)
		return image_surface;

	native_surface = cairo_surface_create_similar (cairo_get_group_target (cr), 
						       cairo_surface_get_content (image_surface), 
						       GetPixelWidth (), GetPixelHeight ());

	cairo_t *context = cairo_create (native_surface);

	cairo_set_source_surface (context, image_surface, 0, 0);
	cairo_pattern_set_filter (cairo_get_source (context), CAIRO_FILTER_FAST);

	cairo_paint (context);
	cairo_destroy (context);

	return native_surface;
}
static inline cairo_surface_t *
scale_icon (cairo_surface_t *icon,
            double           width,
            double           height)
{
  cairo_surface_t *scaled_icon;
  cairo_t *cr;

  scaled_icon = cairo_surface_create_similar (icon,
                                              cairo_surface_get_content (icon),
                                              THUMBNAIL_WIDTH,
                                              THUMBNAIL_HEIGHT);

  cr = cairo_create (scaled_icon);

  cairo_scale (cr,
               THUMBNAIL_WIDTH / width,
               THUMBNAIL_HEIGHT / height);

  cairo_set_operator (cr, CAIRO_OPERATOR_SOURCE);
  cairo_set_source_surface (cr,
                            icon,
                            0.0,
                            0.0);

  cairo_paint (cr);
  cairo_destroy (cr);

  return scaled_icon;
}
Esempio n. 14
0
mWindow::mWindow() {
	looping = false;

	if (!(display = XOpenDisplay(NULL)))
		exit(1);
	screenID = DefaultScreen(display);
	topWin = XCreateSimpleWindow(display, DefaultRootWindow(display), 0, 0,
			winWidth, winHeight, 0, 100, 0xfffacd);
	XSelectInput(display, topWin,
			ButtonPressMask | ButtonReleaseMask | KeyPressMask | KeyReleaseMask
					| PointerMotionMask | StructureNotifyMask | ExposureMask);

	frontSurface = cairo_xlib_surface_create(display, topWin,
			DefaultVisual(display, screenID), winWidth, winHeight);
	frontContext = cairo_create(frontSurface);

	GUI_surface = cairo_surface_create_similar(cairo_get_target(frontContext),
			CAIRO_CONTENT_COLOR_ALPHA, winWidth, winHeight);

	//    MAP_surface = cairo_surface_create_similar(cairo_get_target(frontContext),
	//            CAIRO_CONTENT_COLOR_ALPHA, winWidth, winHeight);

	GUI_context = cairo_create(GUI_surface);
	//MAP_context = cairo_create(MAP_surface);

	Gmanager = new GUIManager(GUI_context);
	eventDispatcher = new EventDispatcher(winWidth, winHeight);
	Gmanager->registerEventDispatcher(eventDispatcher,
			eventDispatcher->getGUImap());
	eventDispatcher->registerGUImanager(Gmanager);

	animator = new Animator();
	Animatable::animator = animator;
}
static void
set_surface_pattern (cairo_t *cr, int x, int y)
{
    cairo_surface_t *source_surface;
    cairo_t *cr2;

    double width = (int)(0.6 * WIDTH);
    double height = (int)(0.6 * HEIGHT);
    x += 0.2 * WIDTH;
    y += 0.2 * HEIGHT;

    source_surface = cairo_surface_create_similar (cairo_get_group_target (cr),
						   CAIRO_CONTENT_COLOR_ALPHA,
						   width, height);
    cr2 = cairo_create (source_surface);
    cairo_surface_destroy (source_surface);

    cairo_set_source_rgb (cr2, 1, 0, 0); /* red */
    cairo_paint (cr2);

    cairo_set_source_rgb (cr2, 1, 1, 1); /* white */

    cairo_arc (cr2, 0.5 * width, 0.5 * height, 0.5 * height, 0, 2 * M_PI);
    cairo_fill (cr2);

    cairo_set_source_surface (cr, cairo_get_target (cr2), x, y);
    cairo_destroy (cr2);
}
Esempio n. 16
0
cairo_surface_t *
_gtk_css_image_get_surface (GtkCssImage     *image,
                            cairo_surface_t *target,
                            int              surface_width,
                            int              surface_height)
{
  cairo_surface_t *result;
  cairo_t *cr;

  g_return_val_if_fail (GTK_IS_CSS_IMAGE (image), NULL);
  g_return_val_if_fail (surface_width > 0, NULL);
  g_return_val_if_fail (surface_height > 0, NULL);

  if (target)
    result = cairo_surface_create_similar (target,
                                           CAIRO_CONTENT_COLOR_ALPHA,
                                           surface_width,
                                           surface_height);
  else
    result = cairo_image_surface_create (CAIRO_FORMAT_ARGB32,
                                         surface_width,
                                         surface_height);

  cr = cairo_create (result);
  _gtk_css_image_draw (image, cr, surface_width, surface_height);
  cairo_destroy (cr);

  return result;
}
Esempio n. 17
0
static cairo_test_status_t
draw (cairo_t *cr, int width, int height)
{
    cairo_surface_t *surface, *target;
    cairo_t *cr2;

    /* First draw a shape in blue on the original destination. */
    cairo_set_source_rgb (cr, 0, 0, 1); /* blue */
    draw_square (cr);

    /* Then, create an offset surface and repeat the drawing in red. */
    target = cairo_get_group_target (cr);
    surface = cairo_surface_create_similar (target,
					    cairo_surface_get_content (target),
					    SIZE / 2, SIZE / 2);
    cr2 = cairo_create (surface);

    cairo_set_source_rgb (cr2, 1, 0, 0); /* red */
    draw_square (cr2);

    cairo_destroy (cr2);

    cairo_surface_set_device_offset (surface, + SIZE / 2, + SIZE / 2);

    /* Finally, copy the offset surface to the original destination.
    * The final result should be a blue square with the upper-left
    * quarter red. */
    cairo_set_source_surface (cr, surface, SIZE / 2, SIZE / 2);

    cairo_paint (cr);

    cairo_surface_destroy (surface);

    return CAIRO_TEST_SUCCESS;
}
	cairo_surface_t* Win32UIBinding::ScaleCairoSurface(
		cairo_surface_t* oldSurface, int newWidth, int newHeight)
	{
		cairo_matrix_t scaleMatrix;
		cairo_matrix_init_scale(&scaleMatrix,
			(double) cairo_image_surface_get_width(oldSurface) / (double) newWidth,
			(double) cairo_image_surface_get_height(oldSurface) / (double) newHeight);

		cairo_pattern_t* surfacePattern = cairo_pattern_create_for_surface(oldSurface);
		cairo_pattern_set_matrix(surfacePattern, &scaleMatrix);
		cairo_pattern_set_filter(surfacePattern, CAIRO_FILTER_BEST);

		cairo_surface_t* newSurface = cairo_surface_create_similar(
			oldSurface, CAIRO_CONTENT_COLOR_ALPHA, newWidth, newHeight);
		cairo_t* cr = cairo_create(newSurface);
		cairo_set_source(cr, surfacePattern);

		/* To avoid getting the edge pixels blended with 0 alpha, which would 
		 * occur with the default EXTEND_NONE. Use EXTEND_PAD for 1.2 or newer (2) */
		cairo_pattern_set_extend(cairo_get_source(cr), CAIRO_EXTEND_REFLECT);

		 /* Replace the destination with the source instead of overlaying */
		cairo_set_operator(cr, CAIRO_OPERATOR_SOURCE);

		/* Do the actual drawing */
		cairo_paint(cr);
		cairo_destroy(cr);

		return newSurface;
	 }
Esempio n. 19
0
void iupDrawUpdateSize(IdrawCanvas* dc)
{
  int w, h;

#if GTK_CHECK_VERSION(2, 24, 0)
  w = gdk_window_get_width(dc->window);
  h = gdk_window_get_height(dc->window);
#else
  gdk_drawable_get_size(dc->window, &w, &h);
#endif

  if (w != dc->w || h != dc->h)
  {
    cairo_surface_t* surface;

    dc->w = w;
    dc->h = h;

    cairo_destroy(dc->image_cr);

    surface = cairo_surface_create_similar(cairo_get_target(dc->cr), CAIRO_CONTENT_COLOR_ALPHA, dc->w, dc->h);
    dc->image_cr = cairo_create(surface);
    cairo_surface_destroy(surface);
  }
}
Esempio n. 20
0
static void
draw_mask (cairo_t *cr)
{
    cairo_surface_t *surface;
    cairo_t *cr2;

    surface = cairo_surface_create_similar (cairo_get_group_target (cr),
	                                    CAIRO_CONTENT_ALPHA,
					    50, 50);
    cr2 = cairo_create (surface);
    cairo_surface_destroy (surface);

    cairo_rectangle (cr2,
	             0, 0,
	             40, 40);
    cairo_rectangle (cr2,
	             10, 10,
	             40, 40);
    cairo_clip (cr2);

    cairo_move_to (cr2, 0, 25);
    cairo_line_to (cr2, 50, 25);
    cairo_move_to (cr2, 25, 0);
    cairo_line_to (cr2, 25, 50);
    cairo_set_source_rgb (cr2, 1, 1, 1);
    cairo_stroke (cr2);

    cairo_set_source_rgb (cr, 1, 0, 0);
    cairo_mask_surface (cr, cairo_get_target (cr2), 50, 50);
    cairo_destroy (cr2);
}
Esempio n. 21
0
static void zoom_rect(int x1, int y1, int x2, int y2) {
	cairo_t *ctx;
	cairo_surface_t *buf, *t;
	t = cairo_xlib_surface_create(dpy, wshow, vis, sw, sh);
	buf = cairo_surface_create_similar(t, CAIRO_CONTENT_COLOR, sw, sh);
	ctx = cairo_create(buf);
	cairo_surface_destroy(t);
	PopplerDocument *pdf;
	pdf = poppler_document_new_from_file(show->uri, NULL, NULL);
	PopplerPage *page = poppler_document_get_page(pdf, show->cur);
	double pdfw, pdfh;
	poppler_page_get_size(page, &pdfw, &pdfh);
	cairo_set_source_rgba(ctx, 1, 1, 1, 1);
	cairo_paint(ctx);
	double scx = show->w / pdfw, scy = show->h / pdfh;
	double dx = 0.0, dy = 0.0;
	if (conf.lock_aspect) {
		if (scx > scy) dx = (show->w - pdfw * (scx=scy)) / 2.0;
		else dy = (show->h - pdfh * (scy=scx)) / 2.0;
	}
	cairo_scale(ctx, scx * show->w /(double) (x2-x1),
			scy * show->h /(double) (y2-y1));
	cairo_translate(ctx, (dx - x1)/scx, (dy - y1)/scy);
	poppler_page_render(page, ctx);
	cairo_set_source_surface(show->target[0].ctx, buf, 0, 0);
	int i;
	for (i = conf.fade; i; i--) {
		cairo_paint_with_alpha(show->target[0].ctx, 1/(float)i);
		XFlush(dpy);
		usleep(5000);
	}
	cairo_destroy(ctx);
	cairo_surface_destroy(buf);
}
Esempio n. 22
0
static void
draw_mask (cairo_t *cr, int x, int y)
{
    cairo_surface_t *mask_surface;
    cairo_t *cr2;

    double width = (int)(0.9 * WIDTH);
    double height = (int)(0.9 * HEIGHT);
    x += 0.05 * WIDTH;
    y += 0.05 * HEIGHT;

    mask_surface = cairo_surface_create_similar (cairo_get_target (cr),
						 CAIRO_CONTENT_ALPHA,
						 width, height);
    cr2 = cairo_create (mask_surface);

    cairo_set_source_rgb (cr2, 1, 1, 1); /* white */

    cairo_arc (cr2, 0.5 * width, 0.5 * height, 0.45 * height, 0, 2 * M_PI);
    cairo_fill (cr2);

    cairo_destroy (cr2);

    cairo_mask_surface (cr, mask_surface, x, y);

    cairo_surface_destroy (mask_surface);
}
static gboolean
countdown_expose_cb(GtkWidget *pie, GdkEventExpose *event,
					WindowData *windata)
{
	cairo_t *context;
	cairo_surface_t *surface;
	cairo_t *cr;

	context = gdk_cairo_create(pie->window);

	cairo_set_operator(context, CAIRO_OPERATOR_SOURCE);
	surface = cairo_surface_create_similar(cairo_get_target(context),
										   CAIRO_CONTENT_COLOR_ALPHA,
										   pie->allocation.width,
										   pie->allocation.height);
	cr = cairo_create(surface);

	cairo_translate (cr, -pie->allocation.x, -pie->allocation.y);
	fill_background (pie, windata, cr);
	cairo_translate (cr, pie->allocation.x, pie->allocation.y);
	
	draw_pie (pie, windata, cr);

	cairo_destroy(cr);
	cairo_set_source_surface(context, surface, 0, 0);
	cairo_paint(context);
	cairo_surface_destroy(surface);
	cairo_destroy(context);
	return TRUE;
}
static cairo_surface_t *
fill_image_buffer_from_file (cairo_t *cr, const char *filePath)
{
  GError *error = NULL;
  RsvgHandle *handle;
  cairo_surface_t *tmp_surface;
  cairo_t *tmp_cr;

  handle = rsvg_handle_new_from_file (filePath, &error);

  if (handle == NULL) {
    g_warning("rsvg_handle_new_from_file(\"%s\") failed: %s",
	      filePath, (error ? error->message : "unknown error"));
    if (error)
      g_error_free(error);
    return NULL;
  }

  tmp_surface = cairo_surface_create_similar (cairo_get_target (cr),
					      CAIRO_CONTENT_COLOR_ALPHA,
					      32, 32);
  tmp_cr = cairo_create (tmp_surface);
  rsvg_handle_render_cairo (handle, tmp_cr);
  cairo_destroy (tmp_cr);
  rsvg_handle_free (handle);
  return tmp_surface;
}
Esempio n. 25
0
static cairo_surface_t *
create_surface (cairo_t *target, cairo_content_t content, surface_type_t type)
{
    cairo_surface_t *surface;
    cairo_t *cr;

    surface = cairo_surface_create_similar (cairo_get_target (target),
					    content,
					    SIZE, SIZE);

    if (type == CLEAR)
	return surface;

    cr = cairo_create (surface);
    cairo_surface_destroy (surface);

    cairo_set_source_rgb (cr, 0.75, 0, 0);
    cairo_paint (cr);

    if (type == PAINTED)
	goto DONE;

    cairo_set_operator (cr, CAIRO_OPERATOR_CLEAR);
    cairo_paint (cr);

DONE:
    surface = cairo_surface_reference (cairo_get_target (cr));
    cairo_destroy (cr);

    return surface;
}
Esempio n. 26
0
cairo_surface_t *
ev_document_misc_surface_rotate_and_scale (cairo_surface_t *surface,
        gint             dest_width,
        gint             dest_height,
        gint             dest_rotation)
{
    cairo_surface_t *new_surface;
    cairo_t         *cr;
    gint             width, height;
    gint             new_width = dest_width;
    gint             new_height = dest_height;

    width = cairo_image_surface_get_width (surface);
    height = cairo_image_surface_get_height (surface);

    if (dest_width == width &&
            dest_height == height &&
            dest_rotation == 0) {
        return cairo_surface_reference (surface);
    }

    if (dest_rotation == 90 || dest_rotation == 270) {
        new_width = dest_height;
        new_height = dest_width;
    }

    new_surface = cairo_surface_create_similar (surface,
                  cairo_surface_get_content (surface),
                  new_width, new_height);

    cr = cairo_create (new_surface);
    switch (dest_rotation) {
    case 90:
        cairo_translate (cr, new_width, 0);
        break;
    case 180:
        cairo_translate (cr, new_width, new_height);
        break;
    case 270:
        cairo_translate (cr, 0, new_height);
        break;
    default:
        cairo_translate (cr, 0, 0);
    }
    cairo_rotate (cr, dest_rotation * G_PI / 180.0);

    if (dest_width != width || dest_height != height) {
        cairo_pattern_set_filter (cairo_get_source (cr), CAIRO_FILTER_BILINEAR);
        cairo_scale (cr,
                     (gdouble)dest_width / width,
                     (gdouble)dest_height / height);
    }

    cairo_set_source_surface (cr, surface, 0, 0);
    cairo_paint (cr);
    cairo_destroy (cr);

    return new_surface;
}
Esempio n. 27
0
cairo_surface_t *compat_gdk_window_create_similar_surface (GdkWindow *window, cairo_content_t content, gint width, gint height)
{
	cairo_t *cr = gdk_cairo_create(window);
	cairo_surface_t *ws = cairo_get_target(cr);
	cairo_surface_t *ret = cairo_surface_create_similar(ws, content, width, height);
	cairo_destroy(cr);
	return ret;
}
Esempio n. 28
0
static cairo_surface_t *
_similar_surface_create (void *closure,
			 cairo_content_t content,
			 double width, double height,
			 long uid)
{
    return cairo_surface_create_similar (closure, content, width, height);
}
Esempio n. 29
0
static cairo_surface_t *
get_surface_from_pixbuf (GdkPixbuf         *pixbuf,
                         MetaImageFillType  fill_type,
                         gdouble            width,
                         gdouble            height,
                         gboolean           vertical_stripes,
                         gboolean           horizontal_stripes)
{
  gdouble pixbuf_width;
  gdouble pixbuf_height;
  cairo_surface_t *surface;
  cairo_content_t content;
  cairo_surface_t *copy;
  cairo_t *cr;

  pixbuf_width = gdk_pixbuf_get_width (pixbuf);
  pixbuf_height = gdk_pixbuf_get_height (pixbuf);
  surface = gdk_cairo_surface_create_from_pixbuf (pixbuf, 1, NULL);

  if (pixbuf_width == width && pixbuf_height == height)
    {
      return surface;
    }

  if (fill_type != META_IMAGE_FILL_TILE)
    {
      cairo_surface_t *scaled;

      scaled = scale_surface (surface, pixbuf_width, pixbuf_height,
                              width, height, vertical_stripes,
                              horizontal_stripes);

      cairo_surface_destroy (surface);
      surface = scaled;
    }

  content = CAIRO_CONTENT_COLOR_ALPHA;
  width = ceil (width);
  height = ceil (height);

  copy = cairo_surface_create_similar (surface, content, width, height);
  cr = cairo_create (copy);

  cairo_set_source_surface (cr, surface, 0, 0);

  if (fill_type == META_IMAGE_FILL_TILE ||
      vertical_stripes || horizontal_stripes)
    {
      cairo_pattern_set_extend (cairo_get_source (cr), CAIRO_EXTEND_REPEAT);
    }

  cairo_paint (cr);
  cairo_destroy (cr);

  cairo_surface_destroy (surface);

  return copy;
}
Esempio n. 30
0
/* This test is designed to test painting a recording surface pattern with
 * CAIRO_EXTEND_NONE and a non identity pattern matrix.
 */
static cairo_pattern_t *create_pattern (cairo_t *target)
{
    cairo_surface_t *surface;
    cairo_pattern_t *pattern;
    cairo_t *cr;

    surface = cairo_surface_create_similar (cairo_get_group_target (target),
					    CAIRO_CONTENT_COLOR_ALPHA,
					    PAT_WIDTH, PAT_HEIGHT);
    cr = cairo_create (surface);
    cairo_surface_destroy (surface);

    cairo_set_source_rgba (cr, 1, 0, 1, 0.5);
    cairo_rectangle (cr, PAT_WIDTH/6.0, PAT_HEIGHT/6.0, PAT_WIDTH/4.0, PAT_HEIGHT/4.0);
    cairo_fill (cr);

    cairo_set_source_rgba (cr, 0, 1, 1, 0.5);
    cairo_rectangle (cr, PAT_WIDTH/2.0, PAT_HEIGHT/2.0, PAT_WIDTH/4.0, PAT_HEIGHT/4.0);
    cairo_fill (cr);

    cairo_set_line_width (cr, 1);
    cairo_move_to (cr, PAT_WIDTH/6.0, 0);
    cairo_line_to (cr, 0, 0);
    cairo_line_to (cr, 0, PAT_HEIGHT/6.0);
    cairo_set_source_rgb (cr, 1, 0, 0);
    cairo_stroke (cr);
    cairo_move_to (cr, PAT_WIDTH/6.0, PAT_HEIGHT);
    cairo_line_to (cr, 0, PAT_HEIGHT);
    cairo_line_to (cr, 0, 5*PAT_HEIGHT/6.0);
    cairo_set_source_rgb (cr, 0, 1, 0);
    cairo_stroke (cr);
    cairo_move_to (cr, 5*PAT_WIDTH/6.0, 0);
    cairo_line_to (cr, PAT_WIDTH, 0);
    cairo_line_to (cr, PAT_WIDTH, PAT_HEIGHT/6.0);
    cairo_set_source_rgb (cr, 0, 0, 1);
    cairo_stroke (cr);
    cairo_move_to (cr, 5*PAT_WIDTH/6.0, PAT_HEIGHT);
    cairo_line_to (cr, PAT_WIDTH, PAT_HEIGHT);
    cairo_line_to (cr, PAT_WIDTH, 5*PAT_HEIGHT/6.0);
    cairo_set_source_rgb (cr, 1, 1, 0);
    cairo_stroke (cr);

    cairo_set_source_rgb (cr, 0.5, 0.5, 0.5);
    cairo_set_line_width (cr, PAT_WIDTH/10.0);

    cairo_move_to (cr, 0,         PAT_HEIGHT/4.0);
    cairo_line_to (cr, PAT_WIDTH, PAT_HEIGHT/4.0);
    cairo_stroke (cr);

    cairo_move_to (cr, PAT_WIDTH/4.0,         0);
    cairo_line_to (cr, PAT_WIDTH/4.0, PAT_WIDTH);
    cairo_stroke (cr);

    pattern = cairo_pattern_create_for_surface (cairo_get_target (cr));
    cairo_destroy (cr);

    return pattern;
}