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


C++ cairo_set_source函数代码示例

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


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

示例1: _draw_mode_toggle

static void _draw_mode_toggle(cairo_t *cr, float x, float y, float width, float height, int type)
{
  cairo_save(cr);
  cairo_translate(cr, x, y);

  // border
  float border = MIN(width * .1, height * .1);
  cairo_set_source_rgba(cr, 0.0, 0.0, 0.0, 0.4);
  cairo_rectangle(cr, border, border, width - 2.0 * border, height - 2.0 * border);
  cairo_fill_preserve(cr);
  cairo_set_source_rgba(cr, 0.0, 0.0, 0.0, 0.5);
  cairo_set_line_width(cr, border);
  cairo_stroke(cr);

  // icon
  cairo_set_source_rgba(cr, 1.0, 1.0, 1.0, 0.5);
  cairo_move_to(cr, 2.0 * border, height - 2.0 * border);
  switch(type)
  {
    case DT_DEV_HISTOGRAM_LINEAR:
      cairo_line_to(cr, width - 2.0 * border, 2.0 * border);
      cairo_stroke(cr);
      break;
    case DT_DEV_HISTOGRAM_LOGARITHMIC:
      cairo_curve_to(cr, 2.0 * border, 0.33 * height, 0.66 * width, 2.0 * border, width - 2.0 * border,
                     2.0 * border);
      cairo_stroke(cr);
      break;
    case DT_DEV_HISTOGRAM_WAVEFORM:
    {
      cairo_pattern_t *pattern;
      pattern = cairo_pattern_create_linear(0.0, 1.5 * border, 0.0, height - 3.0 * border);

      cairo_pattern_add_color_stop_rgba(pattern, 0.0, 0.0, 0.0, 0.0, 0.5);
      cairo_pattern_add_color_stop_rgba(pattern, 0.2, 0.2, 0.2, 0.2, 0.5);
      cairo_pattern_add_color_stop_rgba(pattern, 0.5, 1.0, 1.0, 1.0, 0.5);
      cairo_pattern_add_color_stop_rgba(pattern, 0.6, 1.0, 1.0, 1.0, 0.5);
      cairo_pattern_add_color_stop_rgba(pattern, 1.0, 0.2, 0.2, 0.2, 0.5);

      cairo_rectangle(cr, 1.5 * border, 1.5 * border, (width - 3.0 * border) * 0.3, height - 3.0 * border);
      cairo_set_source(cr, pattern);
      cairo_fill(cr);

      cairo_save(cr);
      cairo_scale(cr, 1, -1);
      cairo_translate(cr, 0, -height);
      cairo_rectangle(cr, 1.5 * border + (width - 3.0 * border) * 0.2, 1.5 * border,
                      (width - 3.0 * border) * 0.6, height - 3.0 * border);
      cairo_set_source(cr, pattern);
      cairo_fill(cr);
      cairo_restore(cr);

      cairo_rectangle(cr, 1.5 * border + (width - 3.0 * border) * 0.7, 1.5 * border,
                      (width - 3.0 * border) * 0.3, height - 3.0 * border);
      cairo_set_source(cr, pattern);
      cairo_fill(cr);

      cairo_pattern_destroy(pattern);
      break;
    }
  }
  cairo_restore(cr);
}
开发者ID:WhiteSymmetry,项目名称:darktable,代码行数:63,代码来源:histogram.c

示例2: snapshot_widget

static cairo_surface_t *
snapshot_widget (GtkWidget *widget, SnapshotMode mode)
{
    cairo_surface_t *surface;
    cairo_pattern_t *bg;
    GMainLoop *loop;
    cairo_t *cr;

    g_assert (gtk_widget_get_realized (widget));

    surface = gdk_window_create_similar_surface (gtk_widget_get_window (widget),
              CAIRO_CONTENT_COLOR,
              gtk_widget_get_allocated_width (widget),
              gtk_widget_get_allocated_height (widget));

    loop = g_main_loop_new (NULL, FALSE);
    /* We wait until the widget is drawn for the first time.
     * We can not wait for a GtkWidget::draw event, because that might not
     * happen if the window is fully obscured by windowed child widgets.
     * Alternatively, we could wait for an expose event on widget's window.
     * Both of these are rather hairy, not sure what's best. */
    gdk_event_handler_set (check_for_draw, loop, NULL);
    g_main_loop_run (loop);

    cr = cairo_create (surface);

    switch (mode)
    {
    case SNAPSHOT_WINDOW:
    {
        GdkWindow *window = gtk_widget_get_window (widget);
        if (gdk_window_get_window_type (window) == GDK_WINDOW_TOPLEVEL ||
                gdk_window_get_window_type (window) == GDK_WINDOW_FOREIGN)
        {
            /* give the WM/server some time to sync. They need it.
             * Also, do use popups instead of toplevls in your tests
             * whenever you can. */
            gdk_display_sync (gdk_window_get_display (window));
            g_timeout_add (500, quit_when_idle, loop);
            g_main_loop_run (loop);
        }
        gdk_cairo_set_source_window (cr, window, 0, 0);
        cairo_paint (cr);
    }
    break;
    case SNAPSHOT_DRAW:
        bg = gdk_window_get_background_pattern (gtk_widget_get_window (widget));
        if (bg)
        {
            cairo_set_source (cr, bg);
            cairo_paint (cr);
        }
        gtk_widget_draw (widget, cr);
        break;
    default:
        g_assert_not_reached();
        break;
    }

    cairo_destroy (cr);
    g_main_loop_unref (loop);
    gtk_widget_destroy (widget);

    return surface;
}
开发者ID:RavikumarTulugu,项目名称:antkorp,代码行数:65,代码来源:gtk-reftest.c

示例3: gtk_clock_draw

static gboolean
gtk_clock_draw (GtkWidget *clock, cairo_t *cr)
{
	gint width = gtk_widget_get_allocated_width (clock);
	gint height = gtk_widget_get_allocated_height (clock);
	gdouble cx = width / 2.0;
	gdouble cy = height / 2.0;
	gdouble radius = MIN (width/2, height/2) - 5;
	gint inset;
	gint i;
	GtkClockPrivate *priv = GTK_CLOCK_GET_PRIVATE (clock);
	struct tm *time = &priv->time;
	cairo_pattern_t *pat;

	cairo_arc (cr, cx, cy, radius, 0, 2 * M_PI);
	cairo_set_source_rgba (cr, 1, 1, 1, 0.5);
	cairo_fill_preserve (cr);
	cairo_set_source_rgb (cr, 0, 0, 0);
	cairo_stroke (cr);

	for (i = 0; i < 12; i++)
	{
		cairo_save (cr);

		if (i % 3 == 0)
			inset = 0.2 * radius;
		else {
			inset = 0.1 * radius;
			cairo_set_line_width (cr,
				0.5 * cairo_get_line_width (cr));
		}

		cairo_move_to (cr,
				cx + (radius - inset) * cos (i * M_PI / 6),
				cy + (radius - inset) * sin (i * M_PI / 6));
		cairo_line_to (cr,
				cx + radius * cos (i * M_PI / 6),
				cy + radius * sin (i * M_PI / 6));
		cairo_stroke (cr);

		cairo_restore (cr);
	}

	cairo_set_line_width (cr, 2.0 * cairo_get_line_width (cr));
	cairo_set_line_cap (cr, CAIRO_LINE_CAP_ROUND);

	cairo_move_to (cr, cx, cy);
	cairo_line_to (cr, cx + radius / 2 * sin (M_PI / 6 * time->tm_hour +
						M_PI / 360 * time->tm_min),
			cy + radius / 2 * -cos (M_PI / 6 * time->tm_hour +
						M_PI / 360 * time->tm_min));
	cairo_stroke (cr);

	cairo_move_to (cr, cx, cy);
	cairo_line_to (cr, cx + radius * 0.75 * sin (M_PI / 30 * time->tm_min),
			cy + radius * 0.75 * -cos (M_PI / 30 * time->tm_min));
	cairo_stroke (cr);

	cairo_set_line_width (cr, 0.2 * cairo_get_line_width (cr));
	cairo_set_source_rgb (cr, 1, 0, 0);
	cairo_move_to (cr, cx, cy);
	cairo_line_to (cr, cx + radius * 0.75 * sin (M_PI / 30 * time->tm_sec),
			cy + radius * 0.75 * -cos (M_PI / 30 * time->tm_sec));
	cairo_stroke (cr);

	cairo_arc (cr, cx, cy, radius, 0.0, 2.0 * M_PI);

	pat = cairo_pattern_create_radial (cx, cy, radius,
                                   cx,  0, radius);
	cairo_pattern_add_color_stop_rgba (pat, 0, 0, 0, 0, 0.4);
	cairo_pattern_add_color_stop_rgba (pat, 1, 1, 1, 1, 0.0);
	cairo_set_source (cr, pat);
	cairo_fill (cr);
	cairo_pattern_destroy (pat); 

	return TRUE;
}
开发者ID:echoline,项目名称:planner-desktop,代码行数:77,代码来源:clock.c

示例4: draw

static gboolean
draw (ClutterCanvas *canvas,
            cairo_t       *cr,
            int            width_raw,
            int            height_raw)
{
  /* rounded rectangle taken from:
   *
   *   http://cairographics.org/samples/rounded_rectangle/
   *
   * we leave 1 pixel around the edges to avoid jagged edges
   * when rotating the actor
   */
  double x             = 1.0,        /* parameters like cairo_rectangle */
         y             = 1.0,
         width         = width_raw - 2.0,
         height        = height_raw - 2.0,
         corner_radius = 5.0,
         tab_radius    = 20.0;

  double radius = corner_radius ;
  double degrees = M_PI / 180.0;
  cairo_pattern_t *gradient;
  cairo_surface_t *image;
  cairo_pattern_t *imagelol;
  cairo_surface_t *image2;
  cairo_pattern_t *imagelol2;

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

  cairo_new_sub_path (cr);
  cairo_arc (cr, x + width - radius, y + radius, radius, -90 * degrees, 0 * degrees);
  cairo_arc (cr, x + width - radius, y + height - radius, radius, 0 * degrees, 90 * degrees);
  /*bottom-left*/cairo_arc (cr, x + radius + 30, y + height - radius, radius, 90 * degrees, 180 * degrees);
  cairo_arc_negative (cr, x + 30 - tab_radius, 225, tab_radius, 0 * degrees, -45 * degrees);
  cairo_arc (cr, x + tab_radius, 255 - 75, tab_radius, 135 * degrees, 180 * degrees);
  cairo_arc (cr, x + tab_radius, 255 - 75 - 85, tab_radius, 180 * degrees, 225 * degrees);
  cairo_arc_negative (cr, x + 30 - tab_radius, 255 - 75 - 85 - 45, tab_radius, 45 * degrees, 0 * degrees);
  /*top-left*/cairo_arc (cr, x + radius + 30, y + radius, radius, 180 * degrees, 270 * degrees);
  cairo_close_path (cr);

  cairo_set_source_rgba (cr, 0.145098*1.7, 0.317647*1.6, 0.380392*1.5, 0.6);
  cairo_fill_preserve (cr);

  gradient = cairo_pattern_create_linear(0.0, 0.0, 0.0, 60);
  cairo_pattern_add_color_stop_rgba(gradient, 1, 0, 0, 0, 0);
  cairo_pattern_add_color_stop_rgba(gradient, 0, 1*.7, 1*.9, 1, .15);
  cairo_set_source(cr, gradient);
  cairo_fill_preserve(cr);

  gradient = cairo_pattern_create_linear(0.0, 0.0, 50.0, 0.0);
  cairo_pattern_add_color_stop_rgba(gradient, 1, 0, 0, 0, 0);
  cairo_pattern_add_color_stop_rgba(gradient, 0, 1*.7, 1*.9, 1, .08);
  cairo_set_source(cr, gradient);
  cairo_fill_preserve(cr);

  /*image = cairo_image_surface_create_from_png("/home/jason/workspace/lol/src/noise.png");
  imagelol = cairo_pattern_create_for_surface(image);
  cairo_set_source(cr, imagelol);
  cairo_pattern_set_extend(cairo_get_source(cr), CAIRO_EXTEND_REPEAT);
  cairo_set_operator(cr, CAIRO_OPERATOR_ADD);
  cairo_clip(cr);
  cairo_paint_with_alpha(cr, .1);*/
/*
  image2 = cairo_image_surface_create_from_png("/home/jason/Desktop/lol.png");
  imagelol2 = cairo_pattern_create_for_surface(image2);
  cairo_set_source(cr, imagelol2);
  cairo_pattern_set_extend(cairo_get_source(cr), CAIRO_EXTEND_REPEAT);
  cairo_set_operator(cr, CAIRO_OPERATOR_OVER);
  cairo_paint_with_alpha(cr, .25);
  *//* we're done drawing */
  return TRUE;
}
开发者ID:jsdir,项目名称:_,代码行数:76,代码来源:ipLocationWidget.old.c

示例5: render

static void
render (GtkCellRenderer      *cell,
        GdkDrawable          *window,
        GtkWidget            *widget,
        GdkRectangle         *background_area,
        GdkRectangle         *cell_area,
        GdkRectangle         *expose_area,
        GtkCellRendererState  flags)
{
  GtkCellRendererBubblePrivate *priv;
  cairo_t *cr;
  cairo_pattern_t *pattern;
  GdkColor *start;
  GdkColor *stop;
  
  g_return_if_fail (GTK_IS_CELL_RENDERER_BUBBLE (cell));
  
  priv = GTK_CELL_RENDERER_BUBBLE (cell)->priv;
  
  if (priv->show_bubble)
    {
      cr = gdk_cairo_create (GDK_DRAWABLE (window));
      g_assert (cr);
      
      start = &widget->style->light [GTK_STATE_SELECTED];
      stop = &widget->style->mid [GTK_STATE_SELECTED];
      
      pattern = cairo_pattern_create_linear (cell_area->x,
                                             cell_area->y,
                                             cell_area->x,
                                             cell_area->y + cell_area->height);
      
      cairo_pattern_add_color_stop_rgb (pattern, 0.3,
                                        start->red / (gdouble)G_MAXUINT16,
                                        start->green / (gdouble)G_MAXUINT16,
                                        start->blue / (gdouble)G_MAXUINT16);
      cairo_pattern_add_color_stop_rgb (pattern, 0.9,
                                        stop->red / (gdouble)G_MAXUINT16,
                                        stop->green / (gdouble)G_MAXUINT16,
                                        stop->blue / (gdouble)G_MAXUINT16);
      
      rounded_rectangle (cr,
                         cell_area->x, cell_area->y + 1,
                         cell_area->width, cell_area->height - 2,
                         cell_area->height / 2.5, cell_area->height / 2.5);
      
      cairo_set_source (cr, pattern);
      cairo_fill_preserve (cr);
      
      gdk_cairo_set_source_color (cr, &widget->style->dark [GTK_STATE_SELECTED]);
      cairo_set_line_width (cr, 1.0);
      cairo_stroke (cr);
      
      rounded_rectangle (cr,
                         cell_area->x + 1.0, cell_area->y + 2.0,
                         cell_area->width - 2.0, cell_area->height - 4.0,
                         cell_area->height / 2.5, cell_area->height / 2.5);
      gdk_cairo_set_source_color (cr, &widget->style->light [GTK_STATE_SELECTED]);
      cairo_stroke (cr);
      
      cairo_destroy (cr);
    }
  
  GTK_CELL_RENDERER_CLASS (gtk_cell_renderer_bubble_parent_class)->
    render (cell, window, widget, background_area, cell_area, expose_area, flags);
}
开发者ID:chergert,项目名称:custom-gtk-widgets,代码行数:66,代码来源:gtkcellrendererbubble.c

示例6: gtk_css_image_radial_draw


//.........这里部分代码省略.........
        double hradius, vradius;

        switch (radial->size)
        {
        case GTK_CSS_EXPLICIT_SIZE:
            hradius = _gtk_css_number_value_get (radial->sizes[0], width);
            vradius = _gtk_css_number_value_get (radial->sizes[1], height);
            break;
        case GTK_CSS_CLOSEST_SIDE:
            hradius = MIN (x, width - x);
            vradius = MIN (y, height - y);
            break;
        case GTK_CSS_FARTHEST_SIDE:
            hradius = MAX (x, width - x);
            vradius = MAX (y, height - y);
            break;
        case GTK_CSS_CLOSEST_CORNER:
            hradius = M_SQRT2 * MIN (x, width - x);
            vradius = M_SQRT2 * MIN (y, height - y);
            break;
        case GTK_CSS_FARTHEST_CORNER:
            hradius = M_SQRT2 * MAX (x, width - x);
            vradius = M_SQRT2 * MAX (y, height - y);
            break;
        default:
            g_assert_not_reached ();
        }

        hradius = MAX (1.0, hradius);
        vradius = MAX (1.0, vradius);

        radius = hradius;
        yscale = vradius / hradius;
    }

    gtk_css_image_radial_get_start_end (radial, radius, &start, &end);

    pattern = cairo_pattern_create_radial (0, 0, 0, 0, 0, radius);
    if (yscale != 1.0)
    {
        cairo_matrix_init_scale (&matrix, 1.0, 1.0 / yscale);
        cairo_pattern_set_matrix (pattern, &matrix);
    }

    if (radial->repeating)
        cairo_pattern_set_extend (pattern, CAIRO_EXTEND_REPEAT);
    else
        cairo_pattern_set_extend (pattern, CAIRO_EXTEND_PAD);

    offset = start;
    last = -1;
    for (i = 0; i < radial->stops->len; i++)
    {
        GtkCssImageRadialColorStop *stop;
        double pos, step;

        stop = &g_array_index (radial->stops, GtkCssImageRadialColorStop, i);

        if (stop->offset == NULL)
        {
            if (i == 0)
                pos = 0.0;
            else if (i + 1 == radial->stops->len)
                pos = 1.0;
            else
                continue;
        }
        else
            pos = _gtk_css_number_value_get (stop->offset, radius) / radius;

        pos = MAX (pos, 0);
        step = pos / (i - last);
        for (last = last + 1; last <= i; last++)
        {
            const GdkRGBA *rgba;

            stop = &g_array_index (radial->stops, GtkCssImageRadialColorStop, last);

            rgba = _gtk_css_rgba_value_get_rgba (stop->color);
            offset += step;

            cairo_pattern_add_color_stop_rgba (pattern,
                                               (offset - start) / (end - start),
                                               rgba->red,
                                               rgba->green,
                                               rgba->blue,
                                               rgba->alpha);
        }

        offset = pos;
        last = i;
    }

    cairo_rectangle (cr, 0, 0, width, height);
    cairo_translate (cr, x, y);
    cairo_set_source (cr, pattern);
    cairo_fill (cr);

    cairo_pattern_destroy (pattern);
}
开发者ID:Premangshu2010,项目名称:gtk,代码行数:101,代码来源:gtkcssimageradial.c

示例7: main


//.........这里部分代码省略.........
	  yoff=temp;
	  havey=1;
	  break;
	}
      }
      break;
    case 'r':
      if(strstr(optarg,"dpcm")){
	dpp=atof(optarg)*.03527777777778;
      }else if (strstr(optarg,"dpmm")){
	dpp=atof(optarg)*.35277777777778;
      }else if (strstr(optarg,"dpp")){
	dpp=atof(optarg);
      }else{
	dpp=atof(optarg)*.01388888888889;
      }
      break;
    case 'f':
      fontsize=atof(optarg);
      break;
    case 't':
      text=strdup(optarg);
      break;
    case 'h':
      usage(stdout);
      exit(0);
    case 'v':
      fprintf(stderr,"pngxpdf "VERSION"\n");
    default:
      usage(stderr);
    }
  }

  /* set up our surface */
  cs = cairo_pdf_surface_create_for_stream (pdf_write, NULL, width, height);
  if(!cs || cairo_surface_status(cs)!=CAIRO_STATUS_SUCCESS){
    fprintf(stderr,"CAIRO ERROR: Unable to create PDF surface.\n\n");
    exit(1);
  }
  ct = cairo_create(cs);
  if(fontsize<=0){
    fontsize=height*15./792.;
    if(fontsize<5)fontsize=5;
  }
  cairo_set_font_size(ct, fontsize);
  if(text){
    cairo_text_extents(ct, text, &extents);
    if(!havey)
      yoff = -extents.height-fontsize*4;
  }
  
  /* Iterate through PNG files inline */
  while(optind<argc){
    int ww, hh;
    char *filename = argv[optind];
    cairo_pattern_t *pattern;
    cairo_surface_t *ps=cairo_image_surface_create_from_png(filename);
    cairo_status_t status = cairo_surface_status(ps);
    if(!ps || status!=CAIRO_STATUS_SUCCESS){
      fprintf(stderr,"CAIRO ERROR: Unable to load PNG file %s: %s\n\n",filename,cairo_status_to_string(status));
      exit(1);
    }
    ww = cairo_image_surface_get_width(ps);
    hh = cairo_image_surface_get_height(ps);

    cairo_save(ct);
    cairo_scale(ct, 1./dpp, 1./dpp);
    pattern = cairo_pattern_create_for_surface(ps);
    cairo_translate(ct,(width*dpp - (ww-1))*.5,((height+yoff)*dpp - (hh-1))*.5);
    cairo_pattern_set_filter(pattern, CAIRO_FILTER_BEST);
    cairo_set_source(ct,pattern);
    cairo_paint(ct);
    cairo_restore(ct);

    /* draw comment text */
    if(text){
      cairo_set_source_rgba(ct, 1,1,1,.75);
      cairo_move_to(ct, width-extents.width-fontsize*1.5, height-fontsize*1.5);
      cairo_text_path (ct, text);  
      cairo_set_line_width(ct,3.);
      cairo_set_line_join(ct,CAIRO_LINE_JOIN_ROUND);
      cairo_stroke(ct);

      cairo_set_source_rgb(ct, 0,0,0);
      cairo_move_to(ct, width-extents.width-fontsize*1.5, height-fontsize*1.5);
      cairo_show_text(ct, text);  

    }


    cairo_surface_show_page(cs);


    cairo_surface_destroy(ps);
    optind++;
  }

  cairo_destroy(ct);
  cairo_surface_destroy(cs);
}
开发者ID:kazutomi,项目名称:xiphqt,代码行数:101,代码来源:main.c

示例8: render_image

void render_image(struct window *window, cairo_surface_t *image, enum scaling_mode scaling_mode) {
	double width = cairo_image_surface_get_width(image);
	double height = cairo_image_surface_get_height(image);

	switch (scaling_mode) {
	case SCALING_MODE_STRETCH:
		cairo_scale(window->cairo,
				(double) window->width / width,
				(double) window->height / height);
		cairo_set_source_surface(window->cairo, image, 0, 0);
		break;
	case SCALING_MODE_FILL:
	{
		double window_ratio = (double) window->width / window->height;
		double bg_ratio = width / height;

		if (window_ratio > bg_ratio) {
			double scale = (double) window->width / width;
			cairo_scale(window->cairo, scale, scale);
			cairo_set_source_surface(window->cairo, image,
					0,
					(double) window->height/2 / scale - height/2);
		} else {
			double scale = (double) window->height / height;
			cairo_scale(window->cairo, scale, scale);
			cairo_set_source_surface(window->cairo, image,
					(double) window->width/2 / scale - width/2,
					0);
		}
		break;
	}
	case SCALING_MODE_FIT:
	{
		double window_ratio = (double) window->width / window->height;
		double bg_ratio = width / height;

		if (window_ratio > bg_ratio) {
			double scale = (double) window->height / height;
			cairo_scale(window->cairo, scale, scale);
			cairo_set_source_surface(window->cairo, image,
					(double) window->width/2 / scale - width/2,
					0);
		} else {
			double scale = (double) window->width / width;
			cairo_scale(window->cairo, scale, scale);
			cairo_set_source_surface(window->cairo, image,
					0,
					(double) window->height/2 / scale - height/2);
		}
		break;
	}
	case SCALING_MODE_CENTER:
		cairo_set_source_surface(window->cairo, image,
				(double) window->width/2 - width/2,
				(double) window->height/2 - height/2);
		break;
	case SCALING_MODE_TILE:
	{
		cairo_pattern_t *pattern = cairo_pattern_create_for_surface(image);
		cairo_pattern_set_extend(pattern, CAIRO_EXTEND_REPEAT);
		cairo_set_source(window->cairo, pattern);
		break;
	}
	}

	cairo_paint(window->cairo);
}
开发者ID:Zeirison,项目名称:sway,代码行数:67,代码来源:main.c

示例9: destroyCairoContext

void
WallScreen::drawSwitcherBackground ()
{
    cairo_t         *cr;
    cairo_pattern_t *pattern;
    float           outline = 2.0f;
    int             width, height, radius;
    float           r, g, b, a;

    destroyCairoContext (switcherContext);
    setupCairoContext (switcherContext);

    cr = switcherContext.cr;
    clearCairoLayer (cr);

    width = switcherContext.width - outline;
    height = switcherContext.height - outline;

    cairo_save (cr);
    cairo_translate (cr, outline / 2.0f, outline / 2.0f);

    /* set the pattern for the switcher's background */
    pattern = cairo_pattern_create_linear (0, 0, width, height);
    getColorRGBA (BackgroundGradientBaseColor);
    cairo_pattern_add_color_stop_rgba (pattern, 0.00f, r, g, b, a);
    getColorRGBA (BackgroundGradientHighlightColor);
    cairo_pattern_add_color_stop_rgba (pattern, 0.65f, r, g, b, a);
    getColorRGBA (BackgroundGradientShadowColor);
    cairo_pattern_add_color_stop_rgba (pattern, 0.85f, r, g, b, a);
    cairo_set_source (cr, pattern);

    /* draw the border's shape */
    radius = optionGetEdgeRadius ();
    if (radius)
    {
	cairo_arc (cr, radius, radius, radius, PI, 1.5f * PI);
	cairo_arc (cr, radius + width - 2 * radius,
		   radius, radius, 1.5f * PI, 2.0 * PI);
	cairo_arc (cr, width - radius, height - radius, radius, 0,  PI / 2.0f);
	cairo_arc (cr, radius, height - radius, radius,  PI / 2.0f, PI);
    }
    else
    {
	cairo_rectangle (cr, 0, 0, width, height);
    }

    cairo_close_path (cr);

    /* apply pattern to background... */
    cairo_fill_preserve (cr);

    /* ... and draw an outline */
    cairo_set_line_width (cr, outline);
    getColorRGBA (OutlineColor);
    cairo_set_source_rgba (cr, r, g, b, a);
    cairo_stroke (cr);

    cairo_pattern_destroy (pattern);
    cairo_restore (cr);

    cairo_save (cr);
    for (unsigned int i = 0; i < (unsigned int) screen->vpSize ().height (); i++)
    {
	cairo_translate (cr, 0.0, viewportBorder);
	cairo_save (cr);
	for (unsigned int j = 0; j < (unsigned int) screen->vpSize ().width (); j++)
	{
	    cairo_translate (cr, viewportBorder, 0.0);

	    /* this cuts a hole into our background */
	    cairo_set_operator (cr, CAIRO_OPERATOR_OVER);
	    cairo_set_source_rgba (cr, 0.0, 0.0, 0.0, 1.0);
	    cairo_rectangle (cr, 0, 0, viewportWidth, viewportHeight);

	    cairo_fill_preserve (cr);
	    cairo_set_operator (cr, CAIRO_OPERATOR_XOR);
	    cairo_fill (cr);

	    cairo_translate (cr, viewportWidth, 0.0);
	}
	cairo_restore(cr);

	cairo_translate (cr, 0.0, viewportHeight);
    }
    cairo_restore (cr);
}
开发者ID:adrianobalani,项目名称:compiz-2,代码行数:86,代码来源:wall.cpp

示例10: cairo_set_source

void cairo_context::set_pattern(cairo_pattern const& pattern)
{
    cairo_set_source(cairo_.get(), pattern.pattern());
    check_object_status_and_throw_exception(*this);
}
开发者ID:Andrey-VI,项目名称:mapnik,代码行数:5,代码来源:cairo_context.cpp

示例11: ge_cairo_pattern_fill

/***********************************************
 * ge_cairo_pattern_fill -
 *  
 *   Fill an area with some pattern
 *   Scaling or tiling if needed
 ***********************************************/
void 
ge_cairo_pattern_fill(cairo_t *canvas,
			CairoPattern *pattern,
			gint x,
			gint y,
			gint width,
			gint height)
{
	cairo_matrix_t original_matrix, current_matrix;

	if (pattern->operator == CAIRO_OPERATOR_DEST)
	{
		return;
	}

	cairo_pattern_get_matrix(pattern->handle, &original_matrix);
	current_matrix = original_matrix;

	if (pattern->scale != GE_DIRECTION_NONE)
	{
		gdouble scale_x = 1.0;
		gdouble scale_y = 1.0;

		if ((pattern->scale == GE_DIRECTION_VERTICAL) || (pattern->scale == GE_DIRECTION_BOTH))
		{
			scale_x = 1.0/width;
		}

		if ((pattern->scale == GE_DIRECTION_HORIZONTAL) || (pattern->scale == GE_DIRECTION_BOTH))
		{
			scale_y = 1.0/height;
		}

		cairo_matrix_scale(&current_matrix, scale_x, scale_y);
	}

	if (pattern->translate != GE_DIRECTION_NONE)
	{
		gdouble translate_x = 0;
		gdouble translate_y = 0;

		if ((pattern->translate == GE_DIRECTION_VERTICAL) || (pattern->translate == GE_DIRECTION_BOTH))
		{
			translate_x = 0.0-x;
		}

		if ((pattern->translate == GE_DIRECTION_HORIZONTAL) || (pattern->translate == GE_DIRECTION_BOTH))
		{
			translate_y = 0.0-y;
		}

		cairo_matrix_translate(&current_matrix, translate_x, translate_y);
	}

	cairo_pattern_set_matrix(pattern->handle, &current_matrix);

	cairo_save(canvas);

	cairo_set_source(canvas, pattern->handle);
        cairo_set_operator(canvas, pattern->operator);
	cairo_rectangle(canvas, x, y, width, height);

	cairo_fill (canvas);

	cairo_restore(canvas);

	cairo_pattern_set_matrix(pattern->handle, &original_matrix);
}
开发者ID:davidhalter-archive,项目名称:ardour,代码行数:74,代码来源:cairo-support.c

示例12: ly_3lrc_widget_on_expose_cb

gboolean ly_3lrc_widget_on_expose_cb(GtkWidget * widget, cairo_t *cr, gpointer data)
{
	
	gint width;
	gint height;
	width = gtk_widget_get_allocated_width (widget);
	height = gtk_widget_get_allocated_height (widget);

	gchar title_font[1024]="Sans Regular 18";
	ly_reg_get("3lrc_title_font", "%1024[^\n]", title_font);
	gchar normal_font[1024]="Sans Regular 10";
	ly_reg_get("3lrc_normal_font", "%1024[^\n]", normal_font);

	/*
	 * draw bg
	 */
	if(ly_3lrc_pixbuf_bg)
	{
		if(ly_3lrc_pixbuf_bg_copy)
		{
			int h=gdk_pixbuf_get_height(ly_3lrc_pixbuf_bg_copy);
			int w=gdk_pixbuf_get_width(ly_3lrc_pixbuf_bg_copy);
			if(h<height||h-height>2||w<width||w-width>2)
			{
				g_object_unref(ly_3lrc_pixbuf_bg_copy);
				ly_3lrc_pixbuf_bg_copy=gdk_pixbuf_scale_simple(ly_3lrc_pixbuf_bg, width, height, GDK_INTERP_BILINEAR);
			}
		}
		else
		{
			ly_3lrc_pixbuf_bg_copy=gdk_pixbuf_scale_simple(ly_3lrc_pixbuf_bg, width, height, GDK_INTERP_BILINEAR);
		}
		gdk_cairo_set_source_pixbuf(cr, ly_3lrc_pixbuf_bg_copy, 0, 0);	
		cairo_paint(cr);
	}
	cairo_rectangle (cr, 0, 0, width, height);
	cairo_set_source_rgba (cr, 0, 0, 0, 0.5);
	cairo_fill(cr);

	//画标题
	cairo_pattern_t *pat;
	pat = cairo_pattern_create_linear (0, 0, 0, 45);
	cairo_pattern_add_color_stop_rgba (pat, 0, 1, 1, 1, 0.5);
	cairo_pattern_add_color_stop_rgba (pat, 0.18, 1, 1, 1, 0.3);
	cairo_pattern_add_color_stop_rgba (pat, 0.25, 1, 1, 1, 0.1);
	cairo_pattern_add_color_stop_rgba (pat, 1, 1, 1, 1, 0.1);
	cairo_rectangle (cr, 0, 0, width, 45);
	cairo_set_source (cr, pat);
	cairo_fill(cr);
	cairo_pattern_destroy (pat);

	cairo_set_line_width(cr, 0.5);
	cairo_set_source_rgba (cr, 0.9, 0.9, 0.9, 0.6);
	cairo_move_to(cr, 0, 44);
	cairo_line_to(cr, width, 44);
	cairo_stroke(cr);
	cairo_set_source_rgba (cr, 0, 0, 0, 0.9);
	cairo_move_to(cr, 0, 44.5);
	cairo_line_to(cr, width, 44.5);
	cairo_stroke(cr);

	LyMdhMetadata *md=ly_pqm_get_current_md();
	int length=ly_lrc_get_length();

	if(md)
	{
		gchar title[1024]="";
		g_snprintf(title, sizeof(title), "%s - %s", md->title,md->artist);
		cairo_set_source_rgb ( cr, 0.1, 0.1, 0.1);
		ly_3lrc_widget_draw_text_midx(cr, title, title_font, width ,6);
		cairo_set_source_rgb ( cr, 0.9, 0.9, 0.9);
		ly_3lrc_widget_draw_text_midx(cr, title, title_font, width ,7);
	}
	
	
	//没有找到歌词
	if(length<=0||!md)
	{
		//画边框
		cairo_set_source_rgba ( cr, 0.3 , 0.3 , 0.3 ,0.8) ;
		cairo_set_line_width ( cr,1);
		cairo_translate ( cr, width/2 , height/2);
		cairo_move_to(cr, -70, -30);
		cairo_line_to(cr, 70, -30);
		cairo_arc(cr, 70, 0.0, 30.0 ,-M_PI/2 ,-M_PI*3/2);
		cairo_line_to(cr, 70, 30);
		cairo_arc(cr, -70, 0.0, 30.0 ,M_PI/2 ,M_PI*3/2);
		cairo_fill (cr);
		
		//画闪烁的原点
		cairo_translate ( cr, -60 , 0 );
		static  gdouble const  trs[ 8 ] [ 8 ]  = {
			{ 0.0 , 0.15 , 0.30 , 0.5 , 0.65 , 0.80 , 0.9 , 1.0 } ,
			{ 1.0 , 0.0 , 0.15 , 0.30 , 0.5 , 0.65 , 0.8 , 0.9 } ,
			{ 0.9 , 1.0 , 0.0 , 0.15 , 0.3 , 0.5 , 0.65 , 0.8 } ,
			{ 0.8 , 0.9 , 1.0 , 0.0 , 0.15 , 0.3 , 0.5 , 0.65 } ,
			{ 0.65 , 0.8 , 0.9 , 1.0 , 0.0 , 0.15 , 0.3 , 0.5 } ,
			{ 0.5 , 0.65 , 0.8 , 0.9 , 1.0 , 0.0 , 0.15 , 0.3 } ,
			{ 0.3 , 0.5 , 0.65 , 0.8 , 0.9 , 1.0 , 0.0 , 0.15 } ,
			{ 0.15 , 0.3 , 0.5 , 0.65 , 0.8 , 0.9 , 1.0 , 0.0 ,}
//.........这里部分代码省略.........
开发者ID:lovesnow,项目名称:linnya,代码行数:101,代码来源:lrc_widget.c

示例13: cd_drop_indicator_render

gboolean cd_drop_indicator_render (gpointer pUserData, CairoDock *pDock, cairo_t *pCairoContext)
{
	CDDropIndicatorData *pData = CD_APPLET_GET_MY_DOCK_DATA (pDock);
	if (pData == NULL)
		return GLDI_NOTIFICATION_LET_PASS;
	
	if (pCairoContext != NULL)
	{
		if (pData->fAlpha > 0)
		{
			cairo_save (pCairoContext);
			double fX = pDock->container.iMouseX - myData.dropIndicator.iWidth / 2;
			if (pDock->container.bIsHorizontal)
				cairo_rectangle (pCairoContext,
					(int) pDock->container.iMouseX - myData.dropIndicator.iWidth/2,
					(int) (pDock->container.bDirectionUp ? 0 : pDock->iActiveHeight - 2*myData.dropIndicator.iHeight),
					(int) myData.dropIndicator.iWidth,
					(int) (pDock->container.bDirectionUp ? 2*myData.dropIndicator.iHeight : pDock->iActiveHeight));
			else
				cairo_rectangle (pCairoContext,
					(int) (pDock->container.bDirectionUp ? pDock->container.iHeight - pDock->iActiveHeight : pDock->iActiveHeight - 2*myData.dropIndicator.iHeight),
					(int) pDock->container.iMouseX - myData.dropIndicator.iWidth/2,
					(int) (pDock->container.bDirectionUp ? 2*myData.dropIndicator.iHeight : pDock->iActiveHeight),
					(int) myData.dropIndicator.iWidth);
			cairo_clip (pCairoContext);
			
			if (pDock->container.bIsHorizontal)
				cairo_translate (pCairoContext, fX, (pDock->container.bDirectionUp ? 0 : pDock->iActiveHeight));
			else
				cairo_translate (pCairoContext, (pDock->container.bDirectionUp ? 0 : pDock->iActiveHeight), fX);
			double fRotationAngle = (pDock->container.bIsHorizontal ? (pDock->container.bDirectionUp ? 0 : G_PI) : (pDock->container.bDirectionUp ? -G_PI/2 : G_PI/2));
			cairo_rotate (pCairoContext, fRotationAngle);
			
			cairo_translate (pCairoContext, 0, pData->iDropIndicatorOffset);
			cairo_pattern_t* pPattern = cairo_pattern_create_for_surface (myData.dropIndicator.pSurface);
			g_return_val_if_fail (cairo_pattern_status (pPattern) == CAIRO_STATUS_SUCCESS, GLDI_NOTIFICATION_LET_PASS);
			cairo_pattern_set_extend (pPattern, CAIRO_EXTEND_REPEAT);
			cairo_set_source (pCairoContext, pPattern);
			
			cairo_translate (pCairoContext, 0, - pData->iDropIndicatorOffset);
			cairo_pattern_t *pGradationPattern = cairo_pattern_create_linear (0.,
				0.,
				0.,
				2*myData.dropIndicator.iHeight);  // de haut en bas.
			g_return_val_if_fail (cairo_pattern_status (pGradationPattern) == CAIRO_STATUS_SUCCESS, GLDI_NOTIFICATION_LET_PASS);
		
			cairo_pattern_set_extend (pGradationPattern, CAIRO_EXTEND_NONE);
			cairo_pattern_add_color_stop_rgba (pGradationPattern,
				0.,
				0.,
				0.,
				0.,
				0.);
			cairo_pattern_add_color_stop_rgba (pGradationPattern,
				0.4,
				0.,
				0.,
				0.,
				pData->fAlpha);
			cairo_pattern_add_color_stop_rgba (pGradationPattern,
				0.5,
				0.,
				0.,
				0.,
				pData->fAlpha);
			cairo_pattern_add_color_stop_rgba (pGradationPattern,
				1.,
				0.,
				0.,
				0.,
				0.);
		
			cairo_mask (pCairoContext, pGradationPattern);
			
			cairo_pattern_destroy (pPattern);
			cairo_pattern_destroy (pGradationPattern);
			cairo_restore (pCairoContext);
		}
		
		if (pData->fAlphaHover > 0 && myData.hoverIndicator.pSurface != NULL)
		{
			Icon *pIcon = cairo_dock_get_pointed_icon (pDock->icons);
			if (pIcon != NULL && ! CAIRO_DOCK_ICON_TYPE_IS_SEPARATOR (pIcon))
			{
				cairo_save (pCairoContext);
				if (pDock->container.bIsHorizontal)
				{
					cairo_translate (pCairoContext,
						pIcon->fDrawX + 2./3*pIcon->fWidth*pIcon->fScale,
						pIcon->fDrawY);  // top right corner
					cairo_scale (pCairoContext,
						pIcon->fWidth*pIcon->fScale/3 / myData.hoverIndicator.iWidth,
						pIcon->fHeight*pIcon->fScale/3 / myData.hoverIndicator.iHeight);
				}
				else
				{
					cairo_translate (pCairoContext,
						pIcon->fDrawY + 2./3*pIcon->fWidth*pIcon->fScale,
						pIcon->fDrawX);
					cairo_scale (pCairoContext,
//.........这里部分代码省略.........
开发者ID:Cairo-Dock,项目名称:cairo-dock-plug-ins,代码行数:101,代码来源:applet-notifications.c

示例14: egg_panel_ebox_expose

static gboolean
egg_panel_ebox_expose (GtkWidget      *ebox,
                       GdkEventExpose *event,
                       EggPanel       *panel)
{
	EggPanelPrivate *priv = panel->priv;
	GdkRectangle alloc;
	cairo_pattern_t *pt;
	cairo_t *cr;
	double r1, r2, g1, g2, b1, b2;
	GtkStyle *style;
	GtkStateType state;

	/*
	 * Determine state from button press.
	 */
	state = (priv->state == STATE_DRAGGING) ? GTK_STATE_SELECTED : GTK_STATE_NORMAL;

	/*
	 * Create cairo context and clip drawing area to event region.
	 */
	cr = gdk_cairo_create(event->window);
	gdk_cairo_rectangle(cr, &event->area);
	cairo_clip(cr);

	/*
	 * Get gradient colors.
	 */
	style = gtk_widget_get_style(ebox);
	r1 = style->bg[state].red / 65535.;
	g1 = style->bg[state].green / 65535.;
	b1 = style->bg[state].blue / 65535.;
	r2 = style->dark[state].red / 65535.;
	g2 = style->dark[state].green / 65535.;
	b2 = style->dark[state].blue / 65535.;

	/*
	 * Draw the background gradient.
	 */
	gtk_widget_get_allocation(ebox, &alloc);
	pt = cairo_pattern_create_linear(0., 0., 0., alloc.height);
	cairo_pattern_add_color_stop_rgb(pt, 0., r1, g1, b1);
	cairo_pattern_add_color_stop_rgb(pt, 1., r2, g2, b2);
	cairo_rectangle(cr, 0., 0., alloc.width, alloc.height);
	cairo_set_source(cr, pt);
	cairo_fill(cr);

	/*
	 * Cleanup resources.
	 */
	cairo_pattern_destroy(pt);
	cairo_destroy(cr);

	/*
	 * Expose the child.
	 */
	gtk_container_propagate_expose(GTK_CONTAINER(ebox),
	                               panel->priv->header,
	                               event);

	return FALSE;
}
开发者ID:chergert,项目名称:custom-gtk-widgets,代码行数:62,代码来源:egg-panel.c

示例15: gtk_border_image_render_slice


//.........这里部分代码省略.........
  xstep = width;
  ystep = height;

  switch (hrepeat)
    {
    case GTK_CSS_REPEAT_STYLE_REPEAT:
      extend = CAIRO_EXTEND_REPEAT;
      hscale = vscale;
      break;
    case GTK_CSS_REPEAT_STYLE_SPACE:
      {
        double space, n;

        extend = CAIRO_EXTEND_NONE;
        hscale = vscale;

        xstep = hscale * slice_width;
        n = floor (width / xstep);
        space = (width - n * xstep) / (n + 1);
        xstep += space;
        x += space;
        width -= 2 * space;
      }
      break;
    case GTK_CSS_REPEAT_STYLE_STRETCH:
      break;
    case GTK_CSS_REPEAT_STYLE_ROUND:
      extend = CAIRO_EXTEND_REPEAT;
      hscale = width / (slice_width * MAX (round (width / (slice_width * vscale)), 1));
      break;
    default:
      g_assert_not_reached ();
      break;
    }

  switch (vrepeat)
    {
    case GTK_CSS_REPEAT_STYLE_REPEAT:
      extend = CAIRO_EXTEND_REPEAT;
      vscale = hscale;
      break;
    case GTK_CSS_REPEAT_STYLE_SPACE:
      {
        double space, n;

        extend = CAIRO_EXTEND_NONE;
        vscale = hscale;

        ystep = vscale * slice_height;
        n = floor (height / ystep);
        space = (height - n * ystep) / (n + 1);
        ystep += space;
        y += space;
        height -= 2 * space;
      }
      break;
    case GTK_CSS_REPEAT_STYLE_STRETCH:
      break;
    case GTK_CSS_REPEAT_STYLE_ROUND:
      extend = CAIRO_EXTEND_REPEAT;
      vscale = height / (slice_height * MAX (round (height / (slice_height * hscale)), 1));
      break;
    default:
      g_assert_not_reached ();
      break;
    }

  pattern = cairo_pattern_create_for_surface (slice);

  cairo_matrix_init_translate (&matrix,
                               hrepeat == GTK_CSS_REPEAT_STYLE_REPEAT ? slice_width / 2 : 0,
                               vrepeat == GTK_CSS_REPEAT_STYLE_REPEAT ? slice_height / 2 : 0);
  cairo_matrix_scale (&matrix, 1 / hscale, 1 / vscale);
  cairo_matrix_translate (&matrix,
                          hrepeat == GTK_CSS_REPEAT_STYLE_REPEAT ? - width / 2 : 0,
                          vrepeat == GTK_CSS_REPEAT_STYLE_REPEAT ? - height / 2 : 0);

  cairo_pattern_set_matrix (pattern, &matrix);
  cairo_pattern_set_extend (pattern, extend);

  cairo_save (cr);
  cairo_translate (cr, x, y);

  for (y = 0; y < height; y += ystep)
    {
      for (x = 0; x < width; x += xstep)
        {
          cairo_save (cr);
          cairo_translate (cr, x, y);
          cairo_set_source (cr, pattern);
          cairo_rectangle (cr, 0, 0, xstep, ystep);
          cairo_fill (cr);
          cairo_restore (cr);
        }
    }

  cairo_restore (cr);

  cairo_pattern_destroy (pattern);
}
开发者ID:Therzok,项目名称:gtk,代码行数:101,代码来源:gtkrenderborder.c


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