当前位置: 首页>>代码示例>>C++>>正文


C++ cairo_destroy函数代码示例

本文整理汇总了C++中cairo_destroy函数的典型用法代码示例。如果您正苦于以下问题:C++ cairo_destroy函数的具体用法?C++ cairo_destroy怎么用?C++ cairo_destroy使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了cairo_destroy函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: cairo_destroy

bool
TextPainter::prepareBuffer() {

	if (_cairoWidth <= 0 || _cairoHeight <= 0)
		return false;

	if (_context)
		cairo_destroy(_context);

	if (_surface)
		cairo_surface_destroy(_surface);

	// ensure a valid opengl context
	OpenGl::Guard guard;

	// bind buffer for writing
	glCheck(glBindBufferARB(GL_PIXEL_UNPACK_BUFFER_ARB, _buf));

	// discard previous buffer (so we don't have to wait for GPU until we can
	// map) and create new buffer
	glCheck(glBufferDataARB(GL_PIXEL_UNPACK_BUFFER_ARB, _cairoWidth*_cairoHeight*sizeof(cairo_pixel_t), 0, GL_DYNAMIC_DRAW));

	// bind buffer for reading
	glCheck(glBindBufferARB(GL_PIXEL_PACK_BUFFER_ARB, _buf));

	LOG_ALL(textpainterlog) << "determine raster position of "
	                        << _glRoi.minX + 1.0/_lastResolution.x << ", "
	                        << _glRoi.maxY - 1.0/_lastResolution.y << " [gl]" << std::endl;

	// get the window coordinates of the lower-left corner of the rectangle we
	// want to draw to
	int r[4];
	glCheck(glRasterPos2f(_glRoi.minX + 1.0/_lastResolution.x, _glRoi.maxY - 1.0/_lastResolution.y));
	glCheck(glGetIntegerv(GL_CURRENT_RASTER_POSITION, r));
	_rasterPos.x = r[0];
	_rasterPos.y = r[1];

	LOG_ALL(textpainterlog) << "read content from raster position " << _rasterPos << std::endl;

	// load current content to buffer
	glCheck(glReadPixels(
			_rasterPos.x,
			_rasterPos.y,
			_cairoWidth,
			_cairoHeight,
			detail::pixel_format_traits<cairo_pixel_t>::gl_format,
			detail::pixel_format_traits<cairo_pixel_t>::gl_type,
			0));

	// map the pixel buffer object
	unsigned char* p = (unsigned char*)glMapBufferARB(GL_PIXEL_UNPACK_BUFFER_ARB, GL_WRITE_ONLY_ARB);

	// wrap the buffer in a cairo surface
	_surface =
			cairo_image_surface_create_for_data(
					p,
					CAIRO_FORMAT_ARGB32,
					_cairoWidth,
					_cairoHeight,
					cairo_format_stride_for_width(CAIRO_FORMAT_ARGB32, _cairoWidth));

	// create a context for the surface
	_context = cairo_create(_surface);

	// set antialiasing options
	cairo_set_font_options(_context, _fontOptions);

	return true;
}
开发者ID:ongbe,项目名称:gui-1,代码行数:69,代码来源:TextPainter.cpp

示例2: on_expose_event

 static gboolean
  on_expose_event (GtkWidget * widget, GdkEventExpose * event, gpointer *project)
  {
  cairo_t *cr;
  GdkWindow *gdkw;
  gint i;
  gdkw = gtk_layout_get_bin_window (GTK_LAYOUT(widget));
  cr = gdk_cairo_create (gdkw);
  cairo_set_source_rgb (cr, 0, 0, 0);
  cairo_set_line_width (cr, 1);


  if(!layoutexp)
  {
  for(i=0;i<=MAXLEN12;i++)
    {
  	  if(pertchart[i].name != NULL)
        {
  		  drawbutton(widget,pertchart[i].name,pertchart[i].x,pertchart[i].y,pertchart[i].type,project);
         }
     }
  for(i=0;i<Lin;i++)
   {
 		   cr = gdk_cairo_create (gdkw);
 		   cairo_set_source_rgb (cr, 0, 0, 0);
           cairo_set_line_width (cr, 1);
           cairo_move_to (cr, arrow[i].x1,arrow[i].y1);
           cairo_line_to (cr, arrow[i].x2,arrow[i].y2);
           cairo_move_to (cr, arrow[i].x2,arrow[i].y2);
           cairo_line_to (cr, arrow[i].x3,arrow[i].y3);
           cairo_move_to (cr, arrow[i].x3,arrow[i].y3);
           cairo_line_to (cr, arrow[i].x4,arrow[i].y4);

           cairo_stroke_preserve (cr);
           cairo_set_source_rgb (cr, 1, 1, 1);
           cairo_fill (cr);
           cairo_destroy (cr);
    }
  }
  else
  {
	  for(i=0;i<Lin;i++)
	     {
	   		   cr = gdk_cairo_create (gdkw);
	   		   cairo_set_source_rgb (cr, 0, 0, 0);
	             cairo_set_line_width (cr, 1);
	             cairo_move_to (cr, arrow[i].x1,arrow[i].y1);
	             cairo_line_to (cr, arrow[i].x2,arrow[i].y2);
	             cairo_move_to (cr, arrow[i].x2,arrow[i].y2);
	             cairo_line_to (cr, arrow[i].x3,arrow[i].y3);
	             cairo_move_to (cr, arrow[i].x3,arrow[i].y3);
	             cairo_line_to (cr, arrow[i].x4,arrow[i].y4);

	             cairo_stroke_preserve (cr);
	             cairo_set_source_rgb (cr, 1, 1, 1);
	             cairo_fill (cr);
	             cairo_destroy (cr);}
  }
  layoutexp++;
  return FALSE;
  }
开发者ID:zsyyr,项目名称:Planner,代码行数:61,代码来源:planner-pert-chart.c

示例3: dt_iop_levels_expose


//.........这里部分代码省略.........
    }
  }

  // clear bg
  cairo_set_source_rgb (cr, .2, .2, .2);
  cairo_paint(cr);

  cairo_translate(cr, inset, inset);
  width -= 2*inset;
  height -= 2*inset;

  cairo_set_line_width(cr, 1.0);
  cairo_set_source_rgb (cr, .1, .1, .1);
  cairo_rectangle(cr, 0, 0, width, height);
  cairo_stroke(cr);

  cairo_set_source_rgb (cr, .3, .3, .3);
  cairo_rectangle(cr, 0, 0, width, height);
  cairo_fill(cr);

  // draw grid
  cairo_set_line_width(cr, .4);
  cairo_set_source_rgb (cr, .1, .1, .1);
  dt_draw_vertical_lines(cr, 4, 0, 0, width, height);

  // Drawing the vertical line indicators
  cairo_set_line_width(cr, 2.);

  for(int k = 0; k < 3; k++)
  {
    if(k == c->handle_move && c->mouse_x > 0)
      cairo_set_source_rgb(cr, 1, 1, 1);
    else
      cairo_set_source_rgb(cr, .7, .7, .7);

    cairo_move_to(cr, width*p->levels[k], height);
    cairo_rel_line_to(cr, 0, -height);
    cairo_stroke(cr);
  }

  // draw x positions
  cairo_set_line_width(cr, 1.);
  const float arrw = 7.0f;
  for(int k=0; k<3; k++)
  {
    switch(k)
    {
      case 0:
        cairo_set_source_rgb(cr, 0, 0, 0);
        break;

      case 1:
        cairo_set_source_rgb(cr, 0.5, 0.5, 0.5);
        break;

      default:
        cairo_set_source_rgb(cr, 1, 1, 1);
        break;
    }

    cairo_move_to(cr, width*p->levels[k], height+inset-1);
    cairo_rel_line_to(cr, -arrw*.5f, 0);
    cairo_rel_line_to(cr, arrw*.5f, -arrw);
    cairo_rel_line_to(cr, arrw*.5f, arrw);
    cairo_close_path(cr);
    if(c->handle_move == k && c->mouse_x > 0)
      cairo_fill(cr);
    else
      cairo_stroke(cr);
  }

  cairo_translate(cr, 0, height);

  // draw lum histogram in background
  // only if the module is enabled
  if (self->enabled)
  {
    dt_develop_t *dev = darktable.develop;
    float *hist, hist_max;
    hist = self->histogram;
    hist_max = dev->histogram_linear?self->histogram_max[0]:logf(1.0 + self->histogram_max[0]);
    if(hist && hist_max > 0)
    {
      cairo_save(cr);
      cairo_scale(cr, width/63.0, -(height-5)/(float)hist_max);
      cairo_set_source_rgba(cr, .2, .2, .2, 0.5);
      dt_draw_histogram_8(cr, hist, 0);
      cairo_restore(cr);
    }
  }

  // Cleaning up
  cairo_destroy(cr);
  cairo_t *cr_pixmap = gdk_cairo_create(gtk_widget_get_window(widget));
  cairo_set_source_surface (cr_pixmap, cst, 0, 0);
  cairo_paint(cr_pixmap);
  cairo_destroy(cr_pixmap);
  cairo_surface_destroy(cst);
  return TRUE;
}
开发者ID:jonleighton,项目名称:darktable,代码行数:101,代码来源:levels.c

示例4: SetIconText

SetIconText(GtkStatusIcon *tray_icon, const char *text, const char *color) {

  // build background from image
  GdkPixbuf* special_icon = gdk_pixbuf_new_from_file("message-mail-new.png", NULL); // GError **error);
  GdkPixbuf *dest = gdk_pixbuf_copy(special_icon);
  int w=gdk_pixbuf_get_width(special_icon);
  int h=gdk_pixbuf_get_height(special_icon);

  // prepare colors/alpha
  GdkColormap* cmap=gdk_screen_get_system_colormap(gdk_screen_get_default());
  int screen_depth=24;
  GdkVisual* visual = gdk_colormap_get_visual(cmap);
  screen_depth = visual->depth;
  GdkColor fore = { 0, 0, 0, 0 };
  GdkColor alpha  = { 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF};
  gdk_color_parse(color, &fore);
  if(fore.red==alpha.red && fore.green==alpha.green && fore.blue==alpha.blue) {
    alpha.red=0; // make sure alpha is different from fore
  }
  gdk_colormap_alloc_color (cmap, &fore, TRUE, TRUE);
  gdk_colormap_alloc_color (cmap, &alpha, TRUE, TRUE);

  // build pixmap with rectangle
  GdkPixmap *pm = gdk_pixmap_new (NULL, w, h, screen_depth);
  cairo_t *cr = gdk_cairo_create(pm);
  gdk_cairo_set_source_color(cr, &alpha);
/* void                gdk_cairo_set_source_color          (cairo_t *cr, */
/*                                                          const GdkColor *color); */
  cairo_rectangle(cr, 0, 0, w, h);
  /* void                cairo_rectangle                     (cairo_t *cr, */
  /*                                                          double x, */
  /*                                                          double y, */
  /*                                                          double width, */
  /*                                                          double height); */
  cairo_set_source_rgb(cr, 1, 1, 1);
  cairo_fill(cr);

  // build text
  GtkWidget *scratch = gtk_window_new(GTK_WINDOW_TOPLEVEL);
  PangoLayout *layout = gtk_widget_create_pango_layout(scratch, NULL);
  gtk_widget_destroy(scratch);
  PangoFontDescription *fnt = pango_font_description_from_string("Sans 18");
  pango_font_description_set_weight (fnt,PANGO_WEIGHT_SEMIBOLD);
  pango_layout_set_spacing            (layout,0);
  pango_layout_set_font_description   (layout, fnt);
  pango_layout_set_text (layout, (gchar *)text,-1);
  int tw=0;
  int th=0;
  int sz;
  int border=4;
  pango_layout_get_pixel_size(layout, &tw, &th);
  while( (tw>w - border || th > h - border)) //fit text to the icon by decreasing font size
  {
    sz=pango_font_description_get_size (fnt);
    if(sz<MIN_FONT_SIZE) {
      sz=MIN_FONT_SIZE;
      break;
    }
    sz-=PANGO_SCALE;
    pango_font_description_set_size (fnt,sz);
    pango_layout_set_font_description   (layout, fnt);
    pango_layout_get_pixel_size(layout, &tw, &th);
  }
  pango_font_description_free (fnt);
  // center text
  int px, py;
  px=(w-tw)/2;
  py=(h-th)/2;

  // draw text on pixmap
  gdk_cairo_set_source_color(cr, &fore);
  cairo_move_to (cr, px, py);
  pango_cairo_show_layout (cr, layout);
  cairo_destroy(cr);
  g_object_unref (layout);

  GdkPixbuf *buf = gdk_pixbuf_get_from_drawable (NULL, pm, NULL, 0, 0, 0, 0, w, h);
  g_object_unref (pm);
  GdkPixbuf *alpha_buf = gdk_pixbuf_add_alpha(buf, TRUE, (guchar)alpha.red, (guchar)alpha.green, (guchar)alpha.blue);
  g_object_unref (buf);

  //merge the rendered text on top
  gdk_pixbuf_composite(alpha_buf,dest,0,0,w,h,0,0,1,1,GDK_INTERP_NEAREST,255);
  g_object_unref(alpha_buf);
  /* gdk_pixbuf_composite(buf,dest,0,0,w,h,0,0,1,1,GDK_INTERP_NEAREST,255); */
  /* g_object_unref(buf); */

  gtk_status_icon_set_from_pixbuf(GTK_STATUS_ICON(tray_icon), GDK_PIXBUF(dest));
}
开发者ID:DavidPrevot,项目名称:FireTray,代码行数:89,代码来源:gtk_icon_example.c

示例5: render


//.........这里部分代码省略.........
      cairo_fill_preserve (cr);
      cairo_set_source_rgba (cr, 0, 0, 0, 0.7);
      cairo_stroke (cr);

      // Draw internal highlight
      cairo_set_source_rgba (cr, 1, 1, 1, 0.45);
      cairo_set_line_width (cr, 1);

      if (color_button->priv->fraction < 0.03) {
        cairo_arc (cr, (width / 2) + .5, (height / 2) + .5, 3.25,
			    0, 2 * G_PI);
      } else if (color_button->priv->fraction > 0.99) {
        cairo_arc (cr, (width / 2) + .5, (height / 2) + .5, radius - 3.5,
			    0, 2 * G_PI);
      } else {
        cairo_arc_negative (cr, (width / 2) + .5, (height / 2) + .5, radius - 3.5,
		 arc_start + (1 / (radius - 3.75)),
		 arc_end - (1 / (radius - 3.75)));
        cairo_arc_negative (cr, (width / 2) + .5, (height / 2) + .5, 3.25,
		   arc_end - (1 / (radius - 3.75)),
                   arc_start + (1 / (radius - 3.75)));
        cairo_arc_negative (cr, (width / 2) + .5, (height / 2) + .5, radius - 3.5,
		 arc_start + (1 / (radius - 3.75)),
		 arc_start + (1 / (radius - 3.75)));
      }
      cairo_stroke (cr);

      // Draw external shape
      cairo_set_line_width (cr, 1);
      cairo_set_source_rgba (cr, 0, 0, 0, 0.2);
      cairo_arc (cr, (width / 2) + .5, (height / 2) + .5, radius - 1.25, 0,
		 G_PI * 2);
      cairo_stroke (cr);

      break;
    case GSMCP_TYPE_NETWORK_IN:
      if (color_button->priv->image_buffer == NULL)
	color_button->priv->image_buffer =
	  fill_image_buffer_from_file (cr, DATADIR "/pixmaps/mate-system-monitor/download.svg");
      gtk_widget_set_size_request (widget, 32, 32);
      cairo_move_to (cr, 8.5, 1.5);
      cairo_line_to (cr, 23.5, 1.5);
      cairo_line_to (cr, 23.5, 11.5);
      cairo_line_to (cr, 29.5, 11.5);
      cairo_line_to (cr, 16.5, 27.5);
      cairo_line_to (cr, 15.5, 27.5);
      cairo_line_to (cr, 2.5, 11.5);
      cairo_line_to (cr, 8.5, 11.5);
      cairo_line_to (cr, 8.5, 1.5);
      cairo_close_path (cr);
      path = cairo_copy_path (cr);
      cairo_set_line_cap (cr, CAIRO_LINE_CAP_SQUARE);
      cairo_set_line_join (cr, CAIRO_LINE_JOIN_MITER);
      cairo_set_line_width (cr, 1);
      cairo_fill_preserve (cr);
      cairo_set_miter_limit (cr, 5.0);
      cairo_stroke (cr);
      cairo_set_source_rgba (cr, 0, 0, 0, 0.5);
      cairo_append_path (cr, path);
      cairo_path_destroy(path);
      cairo_stroke (cr);
      cairo_set_source_surface (cr, color_button->priv->image_buffer, 0.0,
				0.0);
      cairo_paint (cr);

      break;
    case GSMCP_TYPE_NETWORK_OUT:
      if (color_button->priv->image_buffer == NULL)
	color_button->priv->image_buffer =
	  fill_image_buffer_from_file (cr, DATADIR "/pixmaps/mate-system-monitor/upload.svg");
      gtk_widget_set_size_request (widget, 32, 32);
      cairo_move_to (cr, 16.5, 1.5);
      cairo_line_to (cr, 29.5, 17.5);
      cairo_line_to (cr, 23.5, 17.5);
      cairo_line_to (cr, 23.5, 27.5);
      cairo_line_to (cr, 8.5, 27.5);
      cairo_line_to (cr, 8.5, 17.5);
      cairo_line_to (cr, 2.5, 17.5);
      cairo_line_to (cr, 15.5, 1.5);
      cairo_line_to (cr, 16.5, 1.5);
      cairo_close_path (cr);
      path = cairo_copy_path (cr);
      cairo_set_line_cap (cr, CAIRO_LINE_CAP_SQUARE);
      cairo_set_line_join (cr, CAIRO_LINE_JOIN_MITER);
      cairo_set_line_width (cr, 1);
      cairo_fill_preserve (cr);
      cairo_set_miter_limit (cr, 5.0);
      cairo_stroke (cr);
      cairo_set_source_rgba (cr, 0, 0, 0, 0.5);
      cairo_append_path (cr, path);
      cairo_path_destroy(path);
      cairo_stroke (cr);
      cairo_set_source_surface (cr, color_button->priv->image_buffer, 0.0,
				0.0);
      cairo_paint (cr);

      break;
    }
  cairo_destroy (cr);
}
开发者ID:matiasdelellis,项目名称:mate-system-monitor,代码行数:101,代码来源:gsm_color_button.c

示例6: setup_tile


//.........这里部分代码省略.........
	raico_blur_t*    blur        = NULL;

	cr_surf = cairo_image_surface_create (CAIRO_FORMAT_ARGB32,
					      3 * BUBBLE_SHADOW_SIZE,
					      3 * BUBBLE_SHADOW_SIZE);
	status = cairo_surface_status (cr_surf);
	if (status != CAIRO_STATUS_SUCCESS)
		g_print ("Error: \"%s\"\n", cairo_status_to_string (status));

	cr = cairo_create (cr_surf);
	status = cairo_status (cr);
	if (status != CAIRO_STATUS_SUCCESS)
	{
		cairo_surface_destroy (cr_surf);
		g_print ("Error: \"%s\"\n", cairo_status_to_string (status));
	}

	// clear and render drop-shadow and bubble-background
	cairo_scale (cr, 1.0f, 1.0f);
	cairo_set_operator (cr, CAIRO_OPERATOR_CLEAR);
	cairo_paint (cr);
	cairo_set_operator (cr, CAIRO_OPERATOR_OVER);

	if (g_composited)
	{
		draw_shadow (cr,
			     width,
			     height,
			     BUBBLE_SHADOW_SIZE,
			     CORNER_RADIUS);
		cairo_set_operator (cr, CAIRO_OPERATOR_CLEAR);
		draw_round_rect (cr,
				 1.0f,
				 (gdouble) BUBBLE_SHADOW_SIZE,
				 (gdouble) BUBBLE_SHADOW_SIZE,
				 (gdouble) CORNER_RADIUS,
				 (gdouble) (width - 2.0f * BUBBLE_SHADOW_SIZE),
				 (gdouble) (height - 2.0f* BUBBLE_SHADOW_SIZE));
		cairo_fill (cr);
		cairo_set_operator (cr, CAIRO_OPERATOR_OVER);
		cairo_set_source_rgba (cr,
				       BUBBLE_BG_COLOR_R,
				       BUBBLE_BG_COLOR_G,
				       BUBBLE_BG_COLOR_B,
				       0.95f);
	}
	else
		cairo_set_source_rgb (cr,
				      BUBBLE_BG_COLOR_R,
				      BUBBLE_BG_COLOR_G,
				      BUBBLE_BG_COLOR_B);
	draw_round_rect (cr,
			 1.0f,
			 BUBBLE_SHADOW_SIZE,
			 BUBBLE_SHADOW_SIZE,
			 CORNER_RADIUS,
			 (gdouble) (width - 2.0f * BUBBLE_SHADOW_SIZE),
			 (gdouble) (height - 2.0f * BUBBLE_SHADOW_SIZE));
	cairo_fill (cr);

	tmp = cairo_image_surface_create_for_data (
			cairo_image_surface_get_data (cr_surf),
			cairo_image_surface_get_format (cr_surf),
			3 * BUBBLE_SHADOW_SIZE,
			3 * BUBBLE_SHADOW_SIZE,
			cairo_image_surface_get_stride (cr_surf));
	dummy_surf = copy_surface (tmp);
	cairo_surface_destroy (tmp);

	tmp = cairo_image_surface_create_for_data (
			cairo_image_surface_get_data (dummy_surf),
			cairo_image_surface_get_format (dummy_surf),
			2 * BUBBLE_SHADOW_SIZE,
			2 * BUBBLE_SHADOW_SIZE,
			cairo_image_surface_get_stride (dummy_surf));
	norm_surf = copy_surface (tmp);
	cairo_surface_destroy (tmp);

	blur = raico_blur_create (RAICO_BLUR_QUALITY_LOW);
	raico_blur_set_radius (blur, 6);
	raico_blur_apply (blur, dummy_surf);
	raico_blur_destroy (blur);

	tmp = cairo_image_surface_create_for_data (
			cairo_image_surface_get_data (dummy_surf),
			cairo_image_surface_get_format (dummy_surf),
			2 * BUBBLE_SHADOW_SIZE,
			2 * BUBBLE_SHADOW_SIZE,
			cairo_image_surface_get_stride (dummy_surf));
	blur_surf = copy_surface (tmp);
	cairo_surface_destroy (tmp);
	cairo_surface_destroy (dummy_surf);

	g_tile = tile_new_for_padding (norm_surf, blur_surf);
	cairo_surface_destroy (norm_surf);
	cairo_surface_destroy (blur_surf);

	cairo_surface_destroy (cr_surf);
	cairo_destroy (cr);
}
开发者ID:chappyhome,项目名称:notify-osd-customizable,代码行数:101,代码来源:test-grow-bubble.c

示例7: conting_cs_draw

static void
conting_cs_draw(ContingDrawing *self, cairo_t *cr)
{
    ContingSymbol *symb;
    ContingComponent *comp;
	GdkColor *color;

    ArtPoint pw0, pw1;
    GdkRectangle rect;
	gdouble affine[6];

    g_return_if_fail(self != NULL && CONTING_IS_CS(self));

    symb = CONTING_SYMBOL(self);
    comp = CONTING_COMPONENT(self);

	g_object_get(self, "color", &color, NULL);

    pw0 = comp->p0;
    pw1 = comp->p1;

    rect.x = (pw0.x < pw1.x ? pw0.x : pw1.x);
    rect.y = (pw0.y < pw1.y ? pw0.y : pw1.y);
    rect.width = fabs(pw1.x - pw0.x);
    rect.height = fabs(pw1.y - pw0.y);

	cairo_set_antialias(cr, CAIRO_ANTIALIAS_DEFAULT);

	cairo_arc(cr,
			rect.x + ((gdouble) rect.width / 2.0),
			rect.y + ((gdouble) rect.height / 2.0),
			(gdouble) rect.width / 2.0, 0, 2 * M_PI);
	cairo_set_source_rgb(cr,
			(gdouble) color->red / (gdouble) G_MAXUINT16,
			(gdouble) color->green / (gdouble) G_MAXUINT16,
			(gdouble) color->blue / (gdouble) G_MAXUINT16);
	cairo_stroke(cr);

	cr = conting_drawing_get_cairo_absolute(self);
	conting_drawing_get_i2w_affine_absolute(self, affine);
	cairo_transform(cr, (cairo_matrix_t *) affine);
	cairo_set_antialias(cr, CAIRO_ANTIALIAS_DEFAULT);
	
	cairo_set_source_rgb(cr,
			(gdouble) color->red / (gdouble) G_MAXUINT16,
			(gdouble) color->green / (gdouble) G_MAXUINT16,
			(gdouble) color->blue / (gdouble) G_MAXUINT16);
    {
        PangoLayout *layout;
        PangoFontDescription *font;

        layout = pango_cairo_create_layout(cr);

        font = pango_font_description_new();
        pango_font_description_set_size(font, 4 * PANGO_SCALE);
    /*  g_print("size = %d\n", pango_font_description_get_size(font)); */
        pango_font_description_set_family_static(font, "Arial");
        pango_font_description_set_style(font, PANGO_STYLE_NORMAL);

        pango_layout_set_font_description(layout, font);
        pango_layout_set_text(layout, "CS", 2);
		
		cairo_move_to(cr, pw0.x + 1, pw0.y + 2);
		pango_cairo_update_layout(cr, layout);
		pango_cairo_show_layout(cr, layout);

		g_object_unref(layout);
	}


	cairo_stroke(cr);

	cairo_destroy(cr);

	CONTING_DRAWING_CLASS(parent_class)->draw(self, cr);
}
开发者ID:gcms,项目名称:gustavo,代码行数:76,代码来源:contingcs.c

示例8: render_text_to_surface

cairo_surface_t*
render_text_to_surface (gchar*                      text,
			gint                        width,
			gint                        height,
			const cairo_font_options_t* font_opts,
			gdouble                     dpi)
{
	cairo_surface_t*      surface;
	cairo_t*              cr;
	PangoFontDescription* desc;
	PangoLayout*          layout;

	// sanity check
	if (!text      ||
	    width <= 0 ||
	    height <= 0)
		return NULL;

	// create surface
	surface = cairo_image_surface_create (CAIRO_FORMAT_ARGB32,
					      width,
					      height);
	if (cairo_surface_status (surface) != CAIRO_STATUS_SUCCESS)
		return NULL;

	// create context
	cr = cairo_create (surface);
	if (cairo_status (cr) != CAIRO_STATUS_SUCCESS)
	{
		cairo_surface_destroy (surface);
		return NULL;
	}

	// clear context
	cairo_scale (cr, 1.0f, 1.0f);
	cairo_set_operator (cr, CAIRO_OPERATOR_CLEAR);
	cairo_paint (cr);

	//
	layout = pango_cairo_create_layout (cr);
	desc = pango_font_description_new ();

	pango_font_description_set_size (desc, 12 * PANGO_SCALE);
	pango_font_description_set_family_static (desc, "Candara");
	pango_font_description_set_weight (desc, PANGO_WEIGHT_NORMAL);
	pango_font_description_set_style (desc, PANGO_STYLE_NORMAL);

	pango_layout_set_wrap (layout, PANGO_WRAP_WORD);
	pango_layout_set_font_description (layout, desc);
	pango_font_description_free (desc);
	pango_layout_set_width (layout, width * PANGO_SCALE);
	pango_layout_set_height (layout, height * PANGO_SCALE);
	pango_layout_set_alignment (layout, PANGO_ALIGN_CENTER);
	pango_layout_set_ellipsize (layout, PANGO_ELLIPSIZE_END);

	// print and layout string (pango-wise)
	pango_layout_set_text (layout, text, -1);

	// make sure system-wide font-options like hinting, antialiasing etc.
	// are taken into account
	pango_cairo_context_set_font_options (pango_layout_get_context (layout),
					      font_opts);
	pango_cairo_context_set_resolution  (pango_layout_get_context (layout),
					     dpi);
	pango_layout_context_changed (layout);

	// draw pango-text to our cairo-context
	cairo_move_to (cr, 0.0f, 0.0f);
	cairo_set_operator (cr, CAIRO_OPERATOR_OVER);
	cairo_set_source_rgba (cr, 1.0f, 1.0f, 1.0f, 1.0f);

	// this call leaks 3803 bytes, I've no idea how to fix that
	pango_cairo_show_layout (cr, layout);

	// clean up
	g_object_unref (layout);
	cairo_destroy (cr);

	return surface;	
}
开发者ID:chappyhome,项目名称:notify-osd-customizable,代码行数:80,代码来源:test-scroll-text.c

示例9: setup_text_tile

tile_t*
setup_text_tile (const cairo_font_options_t* font_opts,
		 gdouble                     dpi,
		 gint                        w,
		 gint                        h)
{
	tile_t*          tile    = NULL;
	cairo_status_t   status;
	cairo_surface_t* surface = NULL;
	cairo_surface_t* text    = NULL;
	cairo_surface_t* shadow  = NULL;
	cairo_t*         cr;
	gdouble          width   = (gdouble) w;
	gdouble          height  = (gdouble) h;
	raico_blur_t*    blur    = NULL;
	cairo_pattern_t* pattern = NULL;

	surface = cairo_image_surface_create (CAIRO_FORMAT_ARGB32, width, height);
	status = cairo_surface_status (surface);
	if (status != CAIRO_STATUS_SUCCESS)
		g_print ("Error: \"%s\"\n", cairo_status_to_string (status));

	cr = cairo_create (surface);
	status = cairo_status (cr);
	if (status != CAIRO_STATUS_SUCCESS)
	{
		cairo_surface_destroy (surface);
		g_print ("Error: \"%s\"\n", cairo_status_to_string (status));
	}

        // clear and render drop-shadow and bubble-background
	cairo_scale (cr, 1.0f, 1.0f);
	cairo_set_operator (cr, CAIRO_OPERATOR_CLEAR);
	cairo_paint (cr);
	cairo_set_operator (cr, CAIRO_OPERATOR_OVER);

	text = render_text_to_surface (
			"After an evening of hacking at the"
			" Fataga hotel here at GUADEC I   "
			"can present you even text-scroll "
			"with blur-cache and fade-out mask"
			" and I dedicate this to Behdad who"
			" sadly burst his upper lip during "
			"the evening and had to go to the "
			"hospital. Some spanish KDE-folks "
			"kindly accompanied him to help out"
			" with translation. True collaboration!\0",
			width,
			height,
			font_opts,
			dpi);

	shadow = render_text_to_surface (
			"After an evening of hacking at the"
			" Fataga hotel here at GUADEC I   "
			"can present you even text-scroll "
			"with blur-cache and fade-out mask"
			" and I dedicate this to Behdad who"
			" sadly burst his upper lip during "
			"the evening and had to go to the "
			"hospital. Some spanish KDE-folks "
			"kindly accompanied him to help out"
			" with translation. True collaboration!\0",
			width,
			height,
			font_opts,
			dpi);

	// create and setup blur
	blur = raico_blur_create (RAICO_BLUR_QUALITY_LOW);
	raico_blur_set_radius (blur, 4);

	// now blur it
	raico_blur_apply (blur, shadow);

	// blur no longer needed
	raico_blur_destroy (blur);

	cairo_push_group (cr);
	cairo_set_source_surface (cr,
				  shadow,
				  0.0f,
				  0.0f);

	cairo_paint (cr);
	pattern = cairo_pop_group (cr);
	cairo_set_source_rgba (cr, 0.0f, 0.0f, 0.0f, 1.0f);
	cairo_mask (cr, pattern);
	cairo_surface_destroy (shadow);
	cairo_pattern_destroy (pattern);
	cairo_set_source_surface (cr, text, 0.0f, 0.0f);
	cairo_paint (cr);

	cairo_destroy (cr);
	cairo_surface_destroy (text);
	tile = tile_new (surface, 6);
	cairo_surface_destroy (surface);

	return tile;
}
开发者ID:chappyhome,项目名称:notify-osd-customizable,代码行数:100,代码来源:test-scroll-text.c

示例10: sctp_graph_draw

static void sctp_graph_draw(struct sctp_udata *u_data)
{
	int length, lwidth;
	guint32 distance=5, i, e, sec, w, start, a, j, b;
	gint label_width, label_height;
	char label_string[15];
	gfloat dis;
	gboolean write_label = FALSE;
	PangoLayout  *layout;
	GtkAllocation widget_alloc;
	cairo_t *cr;

	if (u_data->io->x1_tmp_sec == 0 && u_data->io->x1_tmp_usec == 0)
		u_data->io->offset = 0;
	else
		u_data->io->offset = 5;

	if (u_data->io->x2_tmp_sec - u_data->io->x1_tmp_sec > 1500)
	{
		u_data->io->min_x=u_data->io->x1_tmp_sec;
		u_data->io->max_x=u_data->io->x2_tmp_sec;
		u_data->io->uoff = TRUE;
	}
	else
	{
		u_data->io->min_x=((guint32) (u_data->io->x1_tmp_sec*1000000.0))+u_data->io->x1_tmp_usec;
		u_data->io->max_x=((guint32) (u_data->io->x2_tmp_sec*1000000.0))+u_data->io->x2_tmp_usec;
		u_data->io->uoff = FALSE;
	}

	u_data->io->tmp_width = u_data->io->max_x - u_data->io->min_x;

	if (u_data->dir == 1)
	{
		if (u_data->io->tmp == FALSE)
		{
			if (u_data->assoc->sort_tsn1 != NULL)
				u_data->io->max_y = u_data->io->tmp_max_tsn1 - u_data->io->tmp_min_tsn1;
			else
				u_data->io->max_y = 0;
			u_data->io->min_y = 0;
		}
		else
		{
			u_data->io->max_y = u_data->io->tmp_max_tsn1;
			u_data->io->min_y = u_data->io->tmp_min_tsn1;
		}
	}
	else if (u_data->dir == 2)
	{
		if (u_data->io->tmp == FALSE)
		{
			if (u_data->assoc->tsn2 != NULL)
				u_data->io->max_y = u_data->io->tmp_max_tsn2 - u_data->io->tmp_min_tsn2;
			else
				u_data->io->max_y = 0;
			u_data->io->min_y = 0;
		}
		else
		{
			u_data->io->max_y = u_data->io->tmp_max_tsn2;
			u_data->io->min_y = u_data->io->tmp_min_tsn2;
		}
	}

#if GTK_CHECK_VERSION(2,22,0)
	cr = cairo_create (u_data->io->surface);
#else
	cr = gdk_cairo_create (u_data->io->pixmap);
#endif
	cairo_set_source_rgb (cr, 1, 1, 1);
	gtk_widget_get_allocation(u_data->io->draw_area, &widget_alloc);
	cairo_rectangle (cr,
		0,
		0,
		widget_alloc.width,
		widget_alloc.height);
	cairo_fill (cr);
	cairo_destroy (cr);

	/* x_axis */
#if GTK_CHECK_VERSION(2,22,0)
	cr = cairo_create (u_data->io->surface);
#else
	cr = gdk_cairo_create (u_data->io->pixmap);
#endif
	cairo_set_line_width (cr, 1.0);
	cairo_move_to(cr, LEFT_BORDER+u_data->io->offset+0.5, u_data->io->surface_height - BOTTOM_BORDER+0.5);
	cairo_line_to(cr, u_data->io->surface_width - RIGHT_BORDER + u_data->io->offset+0.5, u_data->io->surface_height - BOTTOM_BORDER+0.5);

	cairo_move_to(cr, u_data->io->surface_width - RIGHT_BORDER + u_data->io->offset+0.5, u_data->io->surface_height - BOTTOM_BORDER+0.5);
	cairo_line_to(cr, u_data->io->surface_width - RIGHT_BORDER + u_data->io->offset - 5+0.5, u_data->io->surface_height - BOTTOM_BORDER - 5+0.5);

	cairo_move_to(cr, u_data->io->surface_width - RIGHT_BORDER + u_data->io->offset + 0.5, u_data->io->surface_height - BOTTOM_BORDER + 0.5);
	cairo_line_to(cr, u_data->io->surface_width - RIGHT_BORDER + u_data->io->offset - 5.5, u_data->io->surface_height - BOTTOM_BORDER + 5.5);
	cairo_stroke(cr);
	cairo_destroy(cr);

	u_data->io->axis_width = u_data->io->surface_width - LEFT_BORDER - RIGHT_BORDER - u_data->io->offset;

//.........这里部分代码省略.........
开发者ID:DuLerWeil,项目名称:wireshark,代码行数:101,代码来源:sctp_byte_graph_dlg.c

示例11: paint_background

static void paint_background() {
    cr = cairo_create(surface);
    cairo_set_source_rgb(cr, 0.0, 0.8, 0.0);
    cairo_paint(cr);
    cairo_destroy(cr);
}
开发者ID:wyongfei,项目名称:LinuxSound-HTMLSource,代码行数:6,代码来源:x_code.c

示例12: draw_tsn_graph

static void draw_tsn_graph(struct sctp_udata *u_data)
{
GPtrArray *array = NULL;
guint32 i, size = 0, start, end;
gint diff, width;
cairo_t *cr;

	if (u_data->dir == 1)
	{
		array = u_data->assoc->sort_tsn1;
		size = u_data->assoc->n_data_chunks_ep1;
		if (u_data->io->tmp == FALSE)
		{
			min_tsn = 0;
			max_tsn = u_data->assoc->max_bytes1;
		}
		else
		{
			min_tsn = u_data->io->tmp_min_tsn1;
			max_tsn = u_data->io->tmp_max_tsn1;
		}
	}
	else if (u_data->dir == 2)
	{
		array = u_data->assoc->sort_tsn2;
		size  = u_data->assoc->n_data_chunks_ep2;
		if (u_data->io->tmp == FALSE)
		{
			min_tsn = 0;
			max_tsn = u_data->assoc->max_bytes2;
		}
		else
		{
			min_tsn = u_data->io->tmp_min_tsn2;
			max_tsn = u_data->io->tmp_max_tsn2;
		}
	}
	width = u_data->io->max_x - u_data->io->min_x;

	for (i=0; i<size; i++)
	{
		if (u_data->io->uoff)
			diff = (gint)((struct tsn_sort*)(g_ptr_array_index(array, i)))->secs -u_data->io->min_x;
		else
			diff = (gint)((struct tsn_sort*)(g_ptr_array_index(array, i)))->secs*1000000 + ((struct tsn_sort*)(g_ptr_array_index(array, i)))->usecs-u_data->io->min_x;
		start = ((struct tsn_sort*)(g_ptr_array_index(array, i)))->offset;
		end = start + ((struct tsn_sort*)(g_ptr_array_index(array, i)))->length;
		if (start >= min_tsn && diff > 0 && diff <= width){
#if GTK_CHECK_VERSION(2,22,0)
			cr = cairo_create (u_data->io->surface);
#else
			cr = gdk_cairo_create (u_data->io->pixmap);
#endif
			cairo_set_line_width (cr, 1.0);
			cairo_move_to(cr,
				(LEFT_BORDER+u_data->io->offset+u_data->io->x_interval*diff)+0.5,
				(u_data->io->surface_height-BOTTOM_BORDER-u_data->io->offset-((SUB_32(start,min_tsn))*u_data->io->y_interval))+0.5);
			cairo_line_to(cr,
				(LEFT_BORDER+u_data->io->offset+u_data->io->x_interval*diff)+0.5,
				(u_data->io->surface_height-BOTTOM_BORDER-u_data->io->offset-((SUB_32(end,min_tsn))*u_data->io->y_interval))+0.5);
			cairo_stroke(cr);
			cairo_destroy(cr);
		}
	}

}
开发者ID:DuLerWeil,项目名称:wireshark,代码行数:66,代码来源:sctp_byte_graph_dlg.c

示例13: draw_sack_graph

static void draw_sack_graph(struct sctp_udata *u_data)
{
	GdkRGBA red_color =    {1.0, 0.0, 0.0, 1.0};
	GdkRGBA green_color =  {0.0, 1.0, 0.0, 1.0};
	gint diff;
	GPtrArray *array = NULL;
	guint32 i, size = 0, start=0, end;
	gboolean more = FALSE;
	gint width;
	cairo_t *cr;

	if (u_data->dir == 1)
	{
		array = u_data->assoc->sort_sack1;
		size=u_data->assoc->n_sack_chunks_ep1;
		if (u_data->io->tmp == FALSE)
		{
			min_tsn = 0;
			max_tsn = u_data->assoc->max_bytes1;
		}
		else
		{
			min_tsn = u_data->io->tmp_min_tsn1;
			max_tsn = u_data->io->tmp_max_tsn1;
		}
	}
	else if (u_data->dir == 2)
	{
		array = u_data->assoc->sort_sack2;
		size = u_data->assoc->n_sack_chunks_ep2;
		if (u_data->io->tmp == FALSE)
		{
			min_tsn = 0;
			max_tsn = u_data->assoc->max_bytes2;
		}
		else
		{
			min_tsn = u_data->io->tmp_min_tsn2;
			max_tsn = u_data->io->tmp_max_tsn2;
		}
	}

	width = u_data->io->max_x - u_data->io->min_x;

	for (i=0; i<size; i++)
	{
		if (u_data->io->uoff)
			diff = (gint)((struct tsn_sort*)(g_ptr_array_index(array,  i)))->secs - u_data->io->min_x;
		else
			diff = (gint)((struct tsn_sort*)(g_ptr_array_index(array,  i)))->secs * 1000000 + ((struct tsn_sort*)(g_ptr_array_index(array,  i)))->usecs - u_data->io->min_x;
		end = start + ((struct tsn_sort*)(g_ptr_array_index(array,  i)))->length;
		if (end>max_tsn)
		{
			end = max_tsn;
			more = TRUE;
		}

		if (start >= min_tsn && diff > 0 && diff <= width)
		{
#if GTK_CHECK_VERSION(2,22,0)
			cr = cairo_create (u_data->io->surface);
#else
			cr = gdk_cairo_create (u_data->io->pixmap);
#endif
			gdk_cairo_set_source_rgba (cr, &red_color);
			cairo_set_line_width (cr, 1.0);
			cairo_move_to(cr,
				LEFT_BORDER+u_data->io->offset+u_data->io->x_interval*diff+0.5,
				u_data->io->surface_height-BOTTOM_BORDER-u_data->io->offset-((SUB_32(start,min_tsn))*u_data->io->y_interval)+0.5);
			cairo_line_to(cr,
				LEFT_BORDER+u_data->io->offset+u_data->io->x_interval*diff+0.5,
				u_data->io->surface_height-BOTTOM_BORDER-u_data->io->offset-((SUB_32(end,min_tsn))*u_data->io->y_interval)+0.5);
				cairo_stroke(cr);
				cairo_destroy(cr);
			if (more == TRUE)
			{
#if GTK_CHECK_VERSION(2,22,0)
				cr = cairo_create (u_data->io->surface);
#else
				cr = gdk_cairo_create (u_data->io->pixmap);
#endif
				gdk_cairo_set_source_rgba (cr, &green_color);
				cairo_set_line_width (cr, 1.0);
				cairo_move_to(cr,
					LEFT_BORDER+u_data->io->offset+u_data->io->x_interval*diff+0.5,
					u_data->io->surface_height-BOTTOM_BORDER-u_data->io->offset-((SUB_32(end,min_tsn))*u_data->io->y_interval)+0.5);
				cairo_line_to(cr,
					LEFT_BORDER+u_data->io->offset+u_data->io->x_interval*diff,
					u_data->io->surface_height-BOTTOM_BORDER-u_data->io->offset-((SUB_32(end+10,min_tsn))*u_data->io->y_interval)+0.5);
				cairo_stroke(cr);
				cairo_destroy(cr);
				more = FALSE;
			}
		}

	}
}
开发者ID:DuLerWeil,项目名称:wireshark,代码行数:97,代码来源:sctp_byte_graph_dlg.c

示例14: Close_Graphics

void Close_Graphics(cairo_t *cr)
{
  cairo_destroy(cr);
}
开发者ID:LucasvBerkel,项目名称:TweedejaarsProject,代码行数:4,代码来源:DE_Minimal.c

示例15: setup_tile


//.........这里部分代码省略.........
		cairo_set_operator (cr, CAIRO_OPERATOR_CLEAR);
		draw_round_rect (cr,
				 1.0f,
				 (gdouble) BUBBLE_SHADOW_SIZE,
				 (gdouble) BUBBLE_SHADOW_SIZE,
				 (gdouble) CORNER_RADIUS,
				 (gdouble) (width - 2.0f * BUBBLE_SHADOW_SIZE),
				 (gdouble) (height - 2.0f* BUBBLE_SHADOW_SIZE));
		cairo_fill (cr);
		cairo_set_operator (cr, CAIRO_OPERATOR_OVER);
		cairo_set_source_rgba (cr,
				       BUBBLE_BG_COLOR_R,
				       BUBBLE_BG_COLOR_G,
				       BUBBLE_BG_COLOR_B,
				       0.95f);
	}
	else
		cairo_set_source_rgb (cr,
				      BUBBLE_BG_COLOR_R,
				      BUBBLE_BG_COLOR_G,
				      BUBBLE_BG_COLOR_B);
	draw_round_rect (cr,
			 1.0f,
			 BUBBLE_SHADOW_SIZE,
			 BUBBLE_SHADOW_SIZE,
			 CORNER_RADIUS,
			 (gdouble) (width - 2.0f * BUBBLE_SHADOW_SIZE),
			 (gdouble) (height - 2.0f * BUBBLE_SHADOW_SIZE));
	cairo_fill (cr);

	// create tmp. copy of scratch-surface
	tmp = cairo_image_surface_create_for_data (
			cairo_image_surface_get_data (cr_surf),
			cairo_image_surface_get_format (cr_surf),
			3 * BUBBLE_SHADOW_SIZE,
			3 * BUBBLE_SHADOW_SIZE,
			cairo_image_surface_get_stride (cr_surf));
	dummy_surf = copy_surface (tmp);
	cairo_surface_destroy (tmp);

	// create normal-state surface for tile from copy of scratch-surface
	tmp = cairo_image_surface_create_for_data (
			cairo_image_surface_get_data (dummy_surf),
			cairo_image_surface_get_format (dummy_surf),
			2 * BUBBLE_SHADOW_SIZE,
			2 * BUBBLE_SHADOW_SIZE,
			cairo_image_surface_get_stride (dummy_surf));
	norm_surf = copy_surface (tmp);
	cairo_surface_destroy (tmp);

	// blur tmp. copy of scratch-surface 
	blur = raico_blur_create (RAICO_BLUR_QUALITY_LOW);
	raico_blur_set_radius (blur, 6);
	raico_blur_apply (blur, dummy_surf);
	raico_blur_destroy (blur);

	// create blurred-state surface for tile
	tmp = cairo_image_surface_create_for_data (
			cairo_image_surface_get_data (dummy_surf),
			cairo_image_surface_get_format (dummy_surf),
			2 * BUBBLE_SHADOW_SIZE,
			2 * BUBBLE_SHADOW_SIZE,
			cairo_image_surface_get_stride (dummy_surf));
	blur_surf = copy_surface (tmp);
	cairo_surface_destroy (tmp);

	// actually create the tile with padding in mind
	tile = tile_new_for_padding (norm_surf, blur_surf);
	destroy_cloned_surface (norm_surf);
	destroy_cloned_surface (blur_surf);
	destroy_cloned_surface (dummy_surf);

	cairo_destroy (cr);
	cairo_surface_destroy (cr_surf);

	norm_surf = cairo_image_surface_create (CAIRO_FORMAT_ARGB32, w, h);
	cr = cairo_create (norm_surf);
	cairo_scale (cr, 1.0f, 1.0f);
	cairo_set_operator (cr, CAIRO_OPERATOR_CLEAR);
	cairo_paint (cr);
	cairo_set_operator (cr, CAIRO_OPERATOR_OVER);
	tile_paint_with_padding (tile, cr, 0.0f, 0.0f, w, h, 1.0f, 0.0f);
	cairo_destroy (cr);

	blur_surf = cairo_image_surface_create (CAIRO_FORMAT_ARGB32, w, h);
	cr = cairo_create (blur_surf);
	cairo_scale (cr, 1.0f, 1.0f);
	cairo_set_operator (cr, CAIRO_OPERATOR_CLEAR);
	cairo_paint (cr);
	cairo_set_operator (cr, CAIRO_OPERATOR_OVER);
	tile_paint_with_padding (tile, cr, 0.0f, 0.0f, w, h, 0.0f, 1.0f);
	cairo_destroy (cr);

	g_tile = tile_new_for_padding (norm_surf, blur_surf);

	// clean up
	tile_destroy (tile);
	cairo_surface_destroy (norm_surf);
	cairo_surface_destroy (blur_surf);
}
开发者ID:chappyhome,项目名称:notify-osd-customizable,代码行数:101,代码来源:test-scroll-text.c


注:本文中的cairo_destroy函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。