示例#1
0
GdkPixbuf*
get_circle_pixbuf_from_color (GdkRGBA *color,
                              gint     size)
{
  cairo_surface_t *surface;
  cairo_t *cr;
  GdkPixbuf *pix;

  /* TODO: review size here, maybe not hardcoded */
  surface = cairo_image_surface_create (CAIRO_FORMAT_ARGB32, size, size);
  cr = cairo_create (surface);

  cairo_set_source_rgba (cr,
                         color->red,
                         color->green,
                         color->blue,
                         color->alpha);
  cairo_arc (cr, size / 2.0, size / 2.0, size / 2.0, 0., 2 * M_PI);
  cairo_fill (cr);
  cairo_destroy (cr);
  pix = gdk_pixbuf_get_from_surface (surface,
                                     0, 0,
                                     size, size);
  cairo_surface_destroy (surface);
  return pix;
}
示例#2
0
static GdkPixbuf *
biji_note_obj_get_pristine (BijiItem *item)
{
  GdkRGBA                note_color;
  cairo_t               *cr;
  cairo_surface_t       *surface = NULL;
  BijiNoteObj           *note = BIJI_NOTE_OBJ (item);

  if (note->priv->pristine)
    return note->priv->pristine;

  /* Create & Draw surface */
  surface = cairo_image_surface_create (CAIRO_FORMAT_ARGB32,
                                        BIJI_EMBLEM_WIDTH,
                                        BIJI_EMBLEM_HEIGHT) ;
  cr = cairo_create (surface);

  /* Background */
  cairo_rectangle (cr, 0, 0, BIJI_EMBLEM_WIDTH, BIJI_EMBLEM_HEIGHT);
  if (biji_note_obj_get_rgba (note, &note_color))
    gdk_cairo_set_source_rgba (cr, &note_color);

  cairo_fill (cr);
  cairo_destroy (cr);

  note->priv->pristine = gdk_pixbuf_get_from_surface (surface,
                                                      0, 0,
                                                      BIJI_EMBLEM_WIDTH,
                                                      BIJI_EMBLEM_HEIGHT);

  cairo_surface_destroy (surface);

  return note->priv->pristine;
}
示例#3
0
bool wxGTKCairoDCImpl::DoGetPixel(int x, int y, wxColour* col) const
{
    if (col)
    {
        cairo_t* cr = NULL;
        if (m_graphicContext)
            cr = static_cast<cairo_t*>(m_graphicContext->GetNativeContext());
        if (cr)
        {
            cairo_surface_t* surface = cairo_get_target(cr);
            x = LogicalToDeviceX(x);
            y = LogicalToDeviceY(y);
            GdkPixbuf* pixbuf = gdk_pixbuf_get_from_surface(surface, x, y, 1, 1);
            if (pixbuf)
            {
                const guchar* src = gdk_pixbuf_get_pixels(pixbuf);
                col->Set(src[0], src[1], src[2]);
                g_object_unref(pixbuf);
                return true;
            }
            *col = wxColour();
        }
    }
    return false;
}
示例#4
0
GdkPixbuf*
gcal_get_pixbuf_from_color (GdkColor *color)
{
    cairo_surface_t *surface;
    cairo_t *cr;
    gint width, height;
    GdkPixbuf *pix;

    /* TODO: review size here, maybe not hardcoded */
    width = height = 10;
    surface = cairo_image_surface_create (CAIRO_FORMAT_ARGB32, width, height);
    cr = cairo_create (surface);

    cairo_set_source_rgb (cr,
                          color->red / 65535.0,
                          color->green / 65535.0,
                          color->blue / 65535.0);
    cairo_rectangle (cr, 0, 0, width, height);
    cairo_fill (cr);
    cairo_destroy (cr);
    pix = gdk_pixbuf_get_from_surface (surface,
                                       0, 0,
                                       width, height);
    cairo_surface_destroy (surface);
    return pix;
}
示例#5
0
static void
export_png (GtkButton     *button,
    ChamplainView *view)
{
  cairo_surface_t *surface;
  GdkPixbuf *pixbuf;
  GFileOutputStream *os;
  GFile *file;
  gint width, height;

  if (champlain_view_get_state (view) != CHAMPLAIN_STATE_DONE)
    return;

  surface = champlain_view_to_surface (view, TRUE);
  if (!surface)
    return;

  width = cairo_image_surface_get_width (surface);
  height = cairo_image_surface_get_height (surface);
  pixbuf = gdk_pixbuf_get_from_surface (surface, 0, 0, width, height);
  if (!pixbuf)
    return;

  file = g_file_new_for_path ("champlain-map.png");
  os = g_file_replace (file, NULL, FALSE, G_FILE_CREATE_NONE, NULL, NULL);
  if (!os)
    {
      g_object_unref (pixbuf);
      return;
    }

  gdk_pixbuf_save_to_stream (pixbuf, G_OUTPUT_STREAM (os), "png", NULL, NULL, NULL);
  g_output_stream_close (G_OUTPUT_STREAM (os), NULL, NULL);
}
示例#6
0
static GdkPixbuf* accessx_status_applet_get_glyph_pixbuf(AccessxStatusApplet* sapplet, GtkWidget* widget, GdkPixbuf* base, GdkColor* fg, GdkColor* bg, gchar* glyphstring)
{
	GdkPixbuf* glyph_pixbuf;
	cairo_surface_t *surface;
	PangoLayout* layout;
	PangoRectangle ink, logic;
	PangoContext* pango_context;
	gint w = gdk_pixbuf_get_width(base);
	gint h = gdk_pixbuf_get_height(base);
	cairo_t *cr;

	surface = gdk_window_create_similar_surface (gdk_get_default_root_window (), CAIRO_CONTENT_COLOR_ALPHA, w, h);
	pango_context = gtk_widget_get_pango_context(widget);
	layout = pango_layout_new(pango_context);
	pango_layout_set_alignment(layout, PANGO_ALIGN_CENTER);
	pango_layout_set_text(layout, glyphstring, -1);

	cr = cairo_create (surface);
	gdk_cairo_set_source_color (cr, bg);
	cairo_paint (cr);
	gdk_cairo_set_source_color (cr, fg);

	pango_layout_get_pixel_extents(layout, &ink, &logic);

	cairo_move_to (cr, (w - ink.x - ink.width)/2, (h - ink.y - ink.height)/2);
	pango_cairo_show_layout (cr, layout);
	cairo_destroy (cr);

	g_object_unref(layout);
	glyph_pixbuf = gdk_pixbuf_get_from_surface (surface, 0, 0, w, h);
	cairo_surface_destroy (surface);

	return glyph_pixbuf;
}
static bool decodeImage(ArgumentDecoder* decoder, GRefPtr<GdkPixbuf>& pixbuf)
{
    ShareableBitmap::Handle handle;
    if (!decoder->decode(handle))
        return false;

    RefPtr<ShareableBitmap> bitmap = ShareableBitmap::create(handle);
    if (!bitmap)
        return false;

    RefPtr<Image> image = bitmap->createImage();
    if (!image)
        return false;

    cairo_surface_t* surface = image->nativeImageForCurrentFrame();
    if (!surface)
        return false;

    pixbuf = adoptGRef(gdk_pixbuf_get_from_surface(surface, 0, 0,
                                                   cairo_image_surface_get_width(surface),
                                                   cairo_image_surface_get_height(surface)));
    if (!pixbuf)
        return false;

    return true;
}
示例#8
0
/**
 * gd_embed_image_in_frame:
 * @source_image:
 * @frame_image_url:
 * @slice_width:
 * @border_width:
 *
 * Returns: (transfer full):
 */
GdkPixbuf *
gd_embed_image_in_frame (GdkPixbuf *source_image,
                         const gchar *frame_image_url,
                         GtkBorder *slice_width,
                         GtkBorder *border_width)
{
  cairo_surface_t *surface, *embedded_surface;
  GdkPixbuf *retval;

  surface = gdk_cairo_surface_create_from_pixbuf (source_image,
                                                  0, NULL);

  /* Force the device scale to 1.0, since pixbufs are always in unscaled
   * dimensions.
   */
  cairo_surface_set_device_scale (surface, 1.0, 1.0);
  embedded_surface = gd_embed_surface_in_frame (surface, frame_image_url,
                                                slice_width, border_width);
  retval = gdk_pixbuf_get_from_surface (embedded_surface,
                                        0, 0,
                                        cairo_image_surface_get_width (embedded_surface),
                                        cairo_image_surface_get_height (embedded_surface));

  cairo_surface_destroy (embedded_surface);
  cairo_surface_destroy (surface);

  return retval;
}
示例#9
0
static void
ensure_pixbuf_from_surface (GtkIconHelper   *self,
			    GtkStyleContext *context)
{
  cairo_surface_t *surface;
  gint width, height;
  cairo_t *cr;


  if (!check_invalidate_pixbuf (self, context))
    return;

  if (self->priv->rendered_pixbuf)
    return;

  get_surface_size (self, context, self->priv->orig_surface, &width, &height);

  surface = cairo_image_surface_create (CAIRO_FORMAT_ARGB32,
					width, height);

  cr = cairo_create (surface);
  cairo_set_source_surface (cr, self->priv->orig_surface, 0, 0);
  cairo_paint (cr);
  cairo_destroy (cr);

  self->priv->rendered_pixbuf =
    gdk_pixbuf_get_from_surface (surface, 0, 0, width, height);

  cairo_surface_destroy (surface);
}
示例#10
0
static GtkWidget *get_color_icon(int c, GtkStyle *style)
{
        GtkWidget *icon;
        GdkPixbuf *pixbuf;
        cairo_surface_t *canvas;
        cairo_t *cr;

        canvas = cairo_image_surface_create(CAIRO_FORMAT_ARGB32, 16, 16);
        cr = cairo_create(canvas);

        gdk_cairo_set_source_color(cr, &style->dark[GTK_STATE_NORMAL]);
        cairo_rectangle(cr, 0, 0, 16, 16);
        cairo_fill(cr);

        gdk_cairo_set_source_color(cr, &colors[c]);
        cairo_rectangle(cr, 1, 1, 14, 14);
        cairo_fill(cr);

        cairo_destroy(cr);

        pixbuf = gdk_pixbuf_get_from_surface(canvas, 0, 0, 16, 16);
        icon = gtk_image_new_from_pixbuf(pixbuf);

        cairo_surface_destroy(canvas);
        g_object_unref(pixbuf);

        return icon;
}
示例#11
0
static GdkPixbuf* accessx_status_applet_get_glyph_pixbuf(AccessxStatusApplet* sapplet, GtkWidget* widget, GdkPixbuf* base, GdkColor* fg, GdkColor* bg, gchar* glyphstring)
{
    GdkPixbuf* glyph_pixbuf;
#if GTK_CHECK_VERSION (3, 0, 0)
    cairo_surface_t *surface;
#else
    GdkPixbuf *alpha_pixbuf;
    GdkPixmap* pixmap;
#endif
    PangoLayout* layout;
    PangoRectangle ink, logic;
    PangoContext* pango_context;
    gint w = gdk_pixbuf_get_width(base);
    gint h = gdk_pixbuf_get_height(base);
    cairo_t *cr;

#if GTK_CHECK_VERSION (3, 0, 0)
    surface = gdk_window_create_similar_surface (gdk_get_default_root_window (), CAIRO_CONTENT_COLOR_ALPHA, w, h);
#else
    pixmap = gdk_pixmap_new(gdk_get_default_root_window (),w, h, -1);
#endif
    pango_context = gtk_widget_get_pango_context(widget);
    layout = pango_layout_new(pango_context);
    pango_layout_set_alignment(layout, PANGO_ALIGN_CENTER);
    pango_layout_set_text(layout, glyphstring, -1);

#if GTK_CHECK_VERSION (3, 0, 0)
    cr = cairo_create (surface);
#else
    cr = gdk_cairo_create (pixmap);
#endif
    gdk_cairo_set_source_color (cr, bg);
    cairo_paint (cr);
    gdk_cairo_set_source_color (cr, fg);

    pango_layout_get_pixel_extents(layout, &ink, &logic);

    cairo_move_to (cr, (w - ink.x - ink.width)/2, (h - ink.y - ink.height)/2);
    pango_cairo_show_layout (cr, layout);
    cairo_destroy (cr);

    g_object_unref(layout);
#if GTK_CHECK_VERSION (3, 0, 0)
    glyph_pixbuf = gdk_pixbuf_get_from_surface (surface, 0, 0, w, h);
    cairo_surface_destroy (surface);

    return glyph_pixbuf;
#else
    glyph_pixbuf = gdk_pixbuf_get_from_drawable(NULL, pixmap, NULL, 0, 0, 0, 0, w, h);
    g_object_unref(pixmap);
    alpha_pixbuf = gdk_pixbuf_add_alpha(glyph_pixbuf, TRUE, bg->red >> 8, bg->green >> 8, bg->blue >> 8);
    g_object_unref(G_OBJECT(glyph_pixbuf));

    return alpha_pixbuf;
#endif
}
示例#12
0
/**
 * ev_document_misc_pixbuf_from_surface:
 * @surface: a #cairo_surface_t
 *
 * Returns: (transfer full): a #GdkPixbuf
 */
GdkPixbuf *
ev_document_misc_pixbuf_from_surface (cairo_surface_t *surface)
{
    g_return_val_if_fail (surface, NULL);

    return gdk_pixbuf_get_from_surface (surface,
                                        0, 0,
                                        cairo_image_surface_get_width (surface),
                                        cairo_image_surface_get_height (surface));
}
示例#13
0
static void
icon_cb (GObject *obj, GParamSpec *spec, GtkWindow *dlg)
{
  GdkPixbuf *pb = gdk_pixbuf_get_from_surface (webkit_web_view_get_favicon (view), 0, 0, -1, -1);
  if (pb)
    {
      gtk_window_set_icon (dlg, pb);
      g_object_unref (pb);
    }
}
示例#14
0
static GdkPixbuf *
ev_document_misc_render_thumbnail_frame (GtkWidget *widget,
                                         int        width,
                                         int        height,
                                         gboolean   inverted_colors,
                                         GdkPixbuf *source_pixbuf)
{
        GtkStyleContext *context = gtk_widget_get_style_context (widget);
        GtkStateFlags    state = gtk_widget_get_state_flags (widget);
        int              width_r, height_r;
        int              width_f, height_f;
        cairo_surface_t *surface;
        cairo_t         *cr;
        GtkBorder        border = {0, };
        GdkPixbuf       *retval;

        if (source_pixbuf) {
                g_return_val_if_fail (GDK_IS_PIXBUF (source_pixbuf), NULL);

                width_r = gdk_pixbuf_get_width (source_pixbuf);
                height_r = gdk_pixbuf_get_height (source_pixbuf);
        } else {
                width_r = width;
                height_r = height;
        }

        gtk_style_context_save (context);

        gtk_style_context_add_class (context, "page-thumbnail");
        if (inverted_colors)
                gtk_style_context_add_class (context, "inverted");

        gtk_style_context_get_border (context, state, &border);
        width_f = width_r + border.left + border.right;
        height_f = height_r + border.top + border.bottom;

        surface = cairo_image_surface_create (CAIRO_FORMAT_ARGB32,
                                              width_f, height_f);
        cr = cairo_create (surface);
        if (source_pixbuf) {
                gdk_cairo_set_source_pixbuf (cr, source_pixbuf, border.left, border.top);
                cairo_paint (cr);
        } else {
                gtk_render_background (context, cr, 0, 0, width_f, height_f);
        }
        gtk_render_frame (context, cr, 0, 0, width_f, height_f);
        cairo_destroy (cr);

        gtk_style_context_restore (context);

        retval = gdk_pixbuf_get_from_surface (surface, 0, 0, width_f, height_f);
        cairo_surface_destroy (surface);

        return retval;
}
示例#15
0
文件: tray.c 项目: Explorer09/hime
static void draw_icon()
{
  gboolean tsin_pho_mode();

  if (!tray_icon)
    return;

  GdkPixbuf *pix =  ((! current_CS) ||
                     (current_CS->im_state != HIME_STATE_CHINESE)) ?
                    pixbuf : pixbuf_ch;

  int w = 0, h = 0;
  iw = gtk_status_icon_get_size(tray_icon), ih = gtk_status_icon_get_size(tray_icon);

  cairo_surface_t *cst = cairo_image_surface_create(CAIRO_FORMAT_ARGB32, iw, ih);
  cr = cairo_create (cst);
  gdk_cairo_set_source_color (cr, &red_color_fg);

  if (pix) {
    gdk_cairo_set_source_pixbuf (cr, pix, 0, 0);
    cairo_paint (cr);
  } else {
    get_text_w_h(inmd[current_CS->in_method].cname, &w, &h);
    cairo_move_to (cr, 0, 0);
    pango_cairo_show_layout (cr, pango);
  }

  if (current_CS) {
    gdk_cairo_set_source_color (cr, &red_color_fg);
    if (current_shape_mode()) {
      get_text_w_h(full,  &w, &h);
      cairo_move_to (cr, iw - w, ih - h);
      pango_cairo_show_layout (cr, pango);
    }
    if (current_CS->im_state == HIME_STATE_CHINESE && !tsin_pho_mode()) {
      gdk_cairo_set_source_color (cr, &blue_color_fg);
      get_text_w_h(engst,  &w, &h);
      cairo_move_to (cr, 0, 0);
      pango_cairo_show_layout (cr, pango);
    }
  }

  if (gb_output) {
    gdk_cairo_set_source_color (cr, &red_color_fg);
    get_text_w_h(sim,  &w, &h);
    cairo_move_to (cr, 0, ih - h);
    pango_cairo_show_layout (cr, pango);
  }
  cairo_destroy(cr); cr = NULL;
  GdkPixbuf *icon_pixbuf_output = gdk_pixbuf_get_from_surface(cst, 0, 0, iw, ih);
  cairo_surface_destroy(cst); cst = NULL;
  gtk_status_icon_set_from_pixbuf(tray_icon, icon_pixbuf_output);
  g_object_unref(icon_pixbuf_output); icon_pixbuf_output = NULL;
  pix = NULL;
}
示例#16
0
文件: ui.c 项目: fatman2021/marco
GdkPixbuf*
meta_gdk_pixbuf_get_from_pixmap (GdkPixbuf   *dest,
                                 Pixmap       xpixmap,
                                 int          src_x,
                                 int          src_y,
                                 int          dest_x,
                                 int          dest_y,
                                 int          width,
                                 int          height)
{
  cairo_surface_t *surface;
  Display *display;
  Window root_return;
  int x_ret, y_ret;
  unsigned int w_ret, h_ret, bw_ret, depth_ret;
  XWindowAttributes attrs;
  GdkPixbuf *retval;

  display = GDK_DISPLAY_XDISPLAY (gdk_display_get_default ());

  if (!XGetGeometry (display, xpixmap, &root_return,
                     &x_ret, &y_ret, &w_ret, &h_ret, &bw_ret, &depth_ret))
    return NULL;

  if (depth_ret == 1)
    {
      surface = cairo_xlib_surface_create_for_bitmap (display,
                                                      xpixmap,
                                                      GDK_SCREEN_XSCREEN (gdk_screen_get_default ()),
                                                      w_ret,
                                                      h_ret);
    }
  else
    {
      if (!XGetWindowAttributes (display, root_return, &attrs))
        return NULL;

      surface = cairo_xlib_surface_create (display,
                                           xpixmap,
                                           attrs.visual,
                                           w_ret, h_ret);
    }

  retval = gdk_pixbuf_get_from_surface (surface,
                                        src_x,
                                        src_y,
                                        width,
                                        height);
  cairo_surface_destroy (surface);

  return retval;
}
示例#17
0
文件: callbacks.c 项目: pwmt/zathura
void
cb_window_update_icon(ZathuraRenderRequest* GIRARA_UNUSED(request), cairo_surface_t* surface, void* data)
{
  zathura_t* zathura = data;

  girara_debug("updating window icon");
  GdkPixbuf* pixbuf = gdk_pixbuf_get_from_surface(surface, 0, 0, cairo_image_surface_get_width(surface), cairo_image_surface_get_height(surface));
  if (pixbuf == NULL) {
    girara_error("Unable to convert cairo surface to Gdk Pixbuf.");
  }

  gtk_window_set_icon(GTK_WINDOW(zathura->ui.session->gtk.window), pixbuf);
  g_object_unref(pixbuf);
}
int
#if GTK_MAJOR_VERSION >= 3
cairo_surface_dump(cairo_surface_t* srf, std::string filename) {
	if (srf == NULL) return -1;
	guint W = cairo_image_surface_get_width (srf);
	guint H = cairo_image_surface_get_height (srf);
	if (W == 0 || H == 0) {
		return -1;
	}
	GdkPixbuf* pixbuf = gdk_pixbuf_get_from_surface (srf, 0, 0, W, H);
	int i = gdk_pixbuf_dump(pixbuf, filename);
	g_object_unref(G_OBJECT(pixbuf));
	return i;
}
示例#19
0
/**
 * ev_document_misc_render_thumbnail_with_frame:
 * @widget: a #GtkWidget to use for style information
 * @source_pixbuf: a #GdkPixbuf
 *
 * Returns: (transfer full): a #GdkPixbuf
 *
 * Since: 3.8
 */
GdkPixbuf *
ev_document_misc_render_thumbnail_with_frame (GtkWidget *widget,
        GdkPixbuf *source_pixbuf)
{
    GdkPixbuf *retval;
    cairo_surface_t *surface;

    surface = ev_document_misc_render_thumbnail_frame (widget, -1, -1, FALSE, source_pixbuf, NULL);
    retval = gdk_pixbuf_get_from_surface (surface, 0, 0,
                                          cairo_image_surface_get_width (surface),
                                          cairo_image_surface_get_height (surface));
    cairo_surface_destroy (surface);

    return retval;
}
示例#20
0
/**
 * ev_document_misc_render_loading_thumbnail:
 * @widget: a #GtkWidget to use for style information
 * @width: the desired width
 * @height: the desired height
 * @inverted_colors: whether to invert colors
 *
 * Returns: (transfer full): a #GdkPixbuf
 *
 * Since: 3.8
 */
GdkPixbuf *
ev_document_misc_render_loading_thumbnail (GtkWidget *widget,
        int        width,
        int        height,
        gboolean   inverted_colors)
{
    GdkPixbuf *retval;
    cairo_surface_t *surface;

    surface = ev_document_misc_render_thumbnail_frame (widget, width, height, inverted_colors, NULL, NULL);
    retval = gdk_pixbuf_get_from_surface (surface, 0, 0, width, height);
    cairo_surface_destroy (surface);

    return retval;
}
示例#21
0
文件: gtkrender.c 项目: Vort/gtk
GdkPixbuf *
gtk_render_icon_pixbuf_unpacked (GdkPixbuf           *base_pixbuf,
                                 GtkIconSize          size,
                                 GtkCssIconEffect     icon_effect)
{
  GdkPixbuf *scaled;
  GdkPixbuf *stated;
  cairo_surface_t *surface;

  g_return_val_if_fail (base_pixbuf != NULL, NULL);

  /* If the size was wildcarded, and we're allowed to scale, then scale; otherwise,
   * leave it alone.
   */
  if (size != (GtkIconSize) -1)
    {
      int width = 1;
      int height = 1;

      if (!gtk_icon_size_lookup (size, &width, &height))
        {
          g_warning (G_STRLOC ": invalid icon size '%d'", size);
          return NULL;
        }

      scaled = scale_or_ref (base_pixbuf, width, height);
    }
  else
    {
      scaled = g_object_ref (base_pixbuf);
    }

  if (icon_effect != GTK_CSS_ICON_EFFECT_NONE)
    {
      surface = gdk_cairo_surface_create_from_pixbuf (scaled, 1, NULL);
      gtk_css_icon_effect_apply (icon_effect, surface);
      stated = gdk_pixbuf_get_from_surface (surface, 0, 0,
					    cairo_image_surface_get_width (surface),
					    cairo_image_surface_get_height (surface));
      cairo_surface_destroy (surface);
    }
  else
    {
      stated = scaled;
    }

  return stated;
}
示例#22
0
static gboolean
gtk_selection_data_set_surface (GtkSelectionData *selection_data,
			        cairo_surface_t  *surface)
{
  GdkPixbuf *pixbuf;
  gboolean retval;

  pixbuf = gdk_pixbuf_get_from_surface (surface,
                                        0, 0,
                                        cairo_image_surface_get_width (surface),
                                        cairo_image_surface_get_height (surface));
  retval = gtk_selection_data_set_pixbuf (selection_data, pixbuf);
  g_object_unref (pixbuf);

  return retval;
}
示例#23
0
static GdkPixbuf *
logged_in_pixbuf (GdkPixbuf *pixbuf, gint scale)
{
        cairo_format_t format;
        cairo_surface_t *surface;
        cairo_pattern_t *pattern;
        cairo_t *cr;
        gint width, height;
        GdkRGBA color;

        width = gdk_pixbuf_get_width (pixbuf);
        height = gdk_pixbuf_get_height (pixbuf);

        g_return_val_if_fail (width > 15 && height > 15, pixbuf);

        format = gdk_pixbuf_get_has_alpha (pixbuf) ? CAIRO_FORMAT_ARGB32 : CAIRO_FORMAT_RGB24;
        surface = cairo_image_surface_create (format, width, height);
        cr = cairo_create (surface);

        gdk_cairo_set_source_pixbuf (cr, pixbuf, 0, 0);
        cairo_paint (cr);

        /* Draw pattern */
        cairo_rectangle (cr, 0, 0, width, height);
        pattern = cairo_pattern_create_radial (width - 9.5 * scale, height - 10 * scale, 0,
                                               width - 8.5 * scale, height - 7.5 * scale, 7.7 * scale);
        cairo_pattern_add_color_stop_rgb (pattern, 0, 0.4, 0.9, 0);
        cairo_pattern_add_color_stop_rgb (pattern, 0.7, 0.3, 0.6, 0);
        cairo_pattern_add_color_stop_rgb (pattern, 0.8, 0.4, 0.4, 0.4);
        cairo_pattern_add_color_stop_rgba (pattern, 1.0, 0, 0, 0, 0);
        cairo_set_source (cr, pattern);
        cairo_fill (cr);

        /* Draw border */
        cairo_set_line_width (cr, 0.9 * scale);
        cairo_arc (cr, width - 8.5 * scale, height - 8.5 * scale, 6 * scale, 0, 2 * G_PI);
        gdk_rgba_parse (&color, "#ffffff");
        gdk_cairo_set_source_rgba (cr, &color);
        cairo_stroke (cr);

        pixbuf = gdk_pixbuf_get_from_surface (surface, 0, 0, width, height);

        cairo_surface_finish (surface);
        cairo_destroy (cr);

        return pixbuf;
}
示例#24
0
/**
 * gdk_cursor_get_image:
 * @cursor: a #GdkCursor
 *
 * Returns a #GdkPixbuf with the image used to display the cursor.
 *
 * Note that depending on the capabilities of the windowing system and 
 * on the cursor, GDK may not be able to obtain the image data. In this 
 * case, %NULL is returned.
 *
 * Returns: (transfer full): a #GdkPixbuf representing @cursor, or %NULL
 *
 * Since: 2.8
 */
GdkPixbuf*  
gdk_cursor_get_image (GdkCursor *cursor)
{
  int w, h;
  cairo_surface_t *surface;
  GdkPixbuf *pixbuf;
  gchar buf[32];
  double x_hot, y_hot;
  double x_scale, y_scale;

  g_return_val_if_fail (GDK_IS_CURSOR (cursor), NULL);

  surface = gdk_cursor_get_surface (cursor, &x_hot, &y_hot);
  if (surface == NULL)
    return NULL;

  w = cairo_image_surface_get_width (surface);
  h = cairo_image_surface_get_height (surface);

  x_scale = y_scale = 1;
#ifdef HAVE_CAIRO_SURFACE_SET_DEVICE_SCALE
  cairo_surface_get_device_scale (surface, &x_scale, &y_scale);
#endif

  pixbuf = gdk_pixbuf_get_from_surface (surface, 0, 0, w, h);
  cairo_surface_destroy (surface);

  if (x_scale != 1)
    {
      GdkPixbuf *old;

      old = pixbuf;
      pixbuf = gdk_pixbuf_scale_simple (old,
					w / x_scale, h / y_scale,
					GDK_INTERP_HYPER);
      g_object_unref (old);
    }

  
  g_snprintf (buf, 32, "%d", (int)x_hot);
  gdk_pixbuf_set_option (pixbuf, "x_hot", buf);

  g_snprintf (buf, 32, "%d", (int)y_hot);
  gdk_pixbuf_set_option (pixbuf, "y_hot", buf);

  return pixbuf;
}
示例#25
0
static void faviconChanged(GObject *object, GParamSpec *paramSpec, BrowserWindow *window)
{
    GdkPixbuf *favicon = NULL;
    cairo_surface_t *surface = webkit_web_view_get_favicon(window->webView);

    if (surface) {
        int width = cairo_image_surface_get_width(surface);
        int height = cairo_image_surface_get_height(surface);
        favicon = gdk_pixbuf_get_from_surface(surface, 0, 0, width, height);
    }

    if (window->favicon)
        g_object_unref(window->favicon);
    window->favicon = favicon;

    updateUriEntryIcon(window);
    HS_favicon_changed(surface, window->webView); //add by zlf
}
示例#26
0
static GRefPtr<GdkCursor> createNamedCursor(CustomCursorType cursorType)
{
    CustomCursor cursor = CustomCursors[cursorType];
    GRefPtr<GdkCursor> c = adoptGRef(gdk_cursor_new_from_name(gdk_display_get_default(), cursor.name));
    if (c)
        return c;

    RefPtr<cairo_surface_t> source = adoptRef(cairo_image_surface_create_for_data(const_cast<unsigned char*>(cursor.bits), CAIRO_FORMAT_A1, 32, 32, 4));
    RefPtr<cairo_surface_t> mask = adoptRef(cairo_image_surface_create_for_data(const_cast<unsigned char*>(cursor.mask_bits), CAIRO_FORMAT_A1, 32, 32, 4));
    RefPtr<cairo_surface_t> surface = adoptRef(cairo_image_surface_create(CAIRO_FORMAT_A1, 32, 32));
    RefPtr<cairo_t> cr = adoptRef(cairo_create(surface.get()));

    cairo_set_source_surface(cr.get(), source.get(), 0, 0);
    cairo_mask_surface(cr.get(), mask.get(), 0, 0);

    GRefPtr<GdkPixbuf> pixbuf = adoptGRef(gdk_pixbuf_get_from_surface(surface.get(), 0, 0, 32, 32));
    return adoptGRef(gdk_cursor_new_from_pixbuf(gdk_display_get_default(), pixbuf.get(), cursor.hot_x, cursor.hot_y));
}
示例#27
0
/**
  * workrave_timerbox_update: 
  *
  * @self: a @WorkraveTimerbox 
  * @image: a @GtkImage where the timerbox will be drawn into
  *
  */
void
workrave_timerbox_update(WorkraveTimerbox *self, GtkImage *image)
{
  int width = 24;
  int height = 24;

  workrave_timerbox_compute_dimensions(self, &width, &height);
  
  cairo_surface_t *surface = cairo_image_surface_create(CAIRO_FORMAT_ARGB32, width, height);
  cairo_t *cr = cairo_create(surface);

  workrave_timerbox_draw(self, cr);

  GdkPixbuf *pixbuf = gdk_pixbuf_get_from_surface(surface, 0, 0, width, height);
  gtk_image_set_from_pixbuf(image, pixbuf);

  gdk_pixbuf_unref(pixbuf);
  cairo_surface_destroy(surface);
  cairo_destroy(cr);
}
示例#28
0
static GdkPixbuf *
frame_pixbuf (GdkPixbuf *source, gint scale)
{
        GdkPixbuf       *dest;
        cairo_t         *cr;
        cairo_surface_t *surface;
        guint            w;
        guint            h;
        int              frame_width;
        double           radius;

        frame_width = 2 * scale;

        w = gdk_pixbuf_get_width (source) + frame_width * 2;
        h = gdk_pixbuf_get_height (source) + frame_width * 2;
        radius = w / 10;

        surface = cairo_image_surface_create (CAIRO_FORMAT_ARGB32,
                                              w, h);
        cr = cairo_create (surface);
        cairo_surface_destroy (surface);

        /* set up image */
        cairo_rectangle (cr, 0, 0, w, h);
        cairo_set_source_rgba (cr, 1.0, 1.0, 1.0, 0.0);
        cairo_fill (cr);

        rounded_rectangle (cr, 1.0, 0.5, 0.5, radius, w - 1, h - 1);
        cairo_set_source_rgba (cr, 0.5, 0.5, 0.5, 0.3);
        cairo_fill_preserve (cr);

        gdk_cairo_set_source_pixbuf (cr, source, frame_width, frame_width);
        cairo_fill (cr);

        dest = gdk_pixbuf_get_from_surface (surface, 0, 0, w, h);

        cairo_destroy (cr);

        return dest;
}
示例#29
0
void
add_mark_combo_item_to_cbox(GtkTreeStore *list, GtkTreeIter *iter, GtkTreeIter *parent, int column_id, struct objlist *obj, const char *field, int id)
{
  int j, type;
  GtkTreeIter locl_iter;

  if (iter == NULL) {
    iter = &locl_iter;
  }

  type = -1;
  getobj(obj, field, id, 0, NULL, &type);


  for (j = 0; j < MARK_TYPE_NUM; j++) {
    GdkPixbuf *pixbuf;
#if GTK_CHECK_VERSION(3, 0, 0)
    pixbuf = gdk_pixbuf_get_from_surface(NgraphApp.markpix[j],
					 0, 0, MARK_PIX_SIZE, MARK_PIX_SIZE);
#else
    pixbuf = gdk_pixbuf_get_from_drawable(NULL, NgraphApp.markpix[j], NULL, 0, 0, 0, 0, -1, -1);
#endif
    if (pixbuf) {
      char buf[64];

      gtk_tree_store_append(list, iter, parent);
      snprintf(buf, sizeof(buf), "%02d ", j);
      gtk_tree_store_set(list, iter,
			 OBJECT_COLUMN_TYPE_STRING, buf,
			 OBJECT_COLUMN_TYPE_PIXBUF, pixbuf,
			 OBJECT_COLUMN_TYPE_INT, column_id,
			 OBJECT_COLUMN_TYPE_TOGGLE_VISIBLE, TRUE,
			 OBJECT_COLUMN_TYPE_TOGGLE_IS_RADIO, TRUE,
			 OBJECT_COLUMN_TYPE_TOGGLE, j == type,
			 OBJECT_COLUMN_TYPE_ENUM, j,
			 -1);
      g_object_unref(pixbuf);
    }
  }
}
/* create a menu-sized pixbuf filled with specified color */
static GdkPixbuf *
create_color_icon_pixbuf (const char * color_spec)
{
  static int width = -1;
  static int height = -1;
  GdkPixbuf * pixbuf = NULL;

  if (width == -1)
    {
      gtk_icon_size_lookup (GTK_ICON_SIZE_MENU, &width, &height);
      width = CLAMP (width, 10, 30);
      height = CLAMP (height, 10, 30);
    }

  if (color_spec && *color_spec)
    {
      cairo_surface_t * surface;
      cairo_t * cr;
      GdkRGBA rgba;

      surface = cairo_image_surface_create (CAIRO_FORMAT_ARGB32, width, height);
      cr = cairo_create (surface);

      if (gdk_rgba_parse (&rgba, color_spec))
        gdk_cairo_set_source_rgba (cr, &rgba);

      cairo_paint (cr);
      cairo_set_source_rgba (cr, 0, 0, 0, 0.5);
      cairo_set_line_width (cr, 1);
      cairo_rectangle (cr, 0.5, 0.5, width-1, height-1);
      cairo_stroke (cr);

      pixbuf = gdk_pixbuf_get_from_surface (surface, 0, 0, width, height);

      cairo_destroy (cr);
      cairo_surface_destroy (surface);
    }

  return pixbuf;
}