Esempio n. 1
0
static cairo_surface_t *
ensure_surface_from_pixbuf (GtkIconHelper *self,
                            GtkCssStyle   *style,
                            gint           scale,
                            GdkPixbuf     *orig_pixbuf,
                            gint           orig_scale)
{
  gint width, height;
  cairo_surface_t *surface;
  GdkPixbuf *pixbuf;
  GtkCssIconEffect icon_effect;

  if (get_pixbuf_size (self,
                       scale,
                       orig_pixbuf,
                       orig_scale,
                       &width, &height, &scale))
    pixbuf = gdk_pixbuf_scale_simple (orig_pixbuf,
                                      width, height,
                                      GDK_INTERP_BILINEAR);
  else
    pixbuf = g_object_ref (orig_pixbuf);

  surface = gdk_cairo_surface_create_from_pixbuf (pixbuf, scale, gtk_widget_get_window (gtk_css_gadget_get_owner (GTK_CSS_GADGET (self))));
  icon_effect = _gtk_css_icon_effect_value_get (gtk_css_style_get_value (style, GTK_CSS_PROPERTY_ICON_EFFECT));
  gtk_css_icon_effect_apply (icon_effect, surface);
  g_object_unref (pixbuf);

  return surface;
}
Esempio n. 2
0
static void
ensure_surface_from_pixbuf (GtkIconHelper   *self,
			    GtkStyleContext *context)
{
  gint width, height;
  GdkPixbuf *pixbuf, *stated;
  int scale;

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

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

  if (get_pixbuf_size (self, context, &width, &height, &scale))
    pixbuf = gdk_pixbuf_scale_simple (self->priv->orig_pixbuf,
                                      width, height,
                                      GDK_INTERP_BILINEAR);
  else
    pixbuf = g_object_ref (self->priv->orig_pixbuf);

  stated = ensure_stated_pixbuf_from_pixbuf (self, context, pixbuf);
  g_object_unref (pixbuf);
  pixbuf = stated;

  self->priv->rendered_surface_width = (width + scale - 1) / scale;
  self->priv->rendered_surface_height = (height + scale - 1) / scale;

  self->priv->rendered_surface = gdk_cairo_surface_create_from_pixbuf (pixbuf, scale, self->priv->window);
  g_object_unref (pixbuf);
}
Esempio n. 3
0
void background_info_set_background_by_file(BackgroundInfo* info,
        const char* file)
{
    g_message("[%s] file, :%s", __func__, file);
    GError* error = NULL;

    GdkScreen *screen;
    screen = gtk_window_get_screen (GTK_WINDOW (info->container));
    gint w = gdk_screen_get_width(screen);
    gint h = gdk_screen_get_height(screen);
    g_message("[%s] gdk_screen_get_width:%d, height: %d\n", __func__, w, h);
    GdkPixbuf* pb = gdk_pixbuf_new_from_file_at_scale(file,w,h,FALSE, &error);
    if (error != NULL) {
        g_warning("[%s] failed: %s\n", __func__, error->message);
        g_error_free(error);
        return;
    }
    g_mutex_lock(&info->m);
    if (info->bg != NULL) {
        cairo_surface_destroy(info->bg);
        info->bg = NULL;
    }
    info->bg = gdk_cairo_surface_create_from_pixbuf(pb, 1,
               gtk_widget_get_window(info->container));
    g_mutex_unlock(&info->m);
    g_object_unref(pb);
    if (gtk_widget_get_realized(info->container)) {
        gdk_window_invalidate_rect(gtk_widget_get_window(info->container),
                                   NULL, TRUE);
    }
}
static void
gd_tagged_entry_tag_ensure_close_surface (GdTaggedEntryTag *tag,
        GtkStyleContext *context)
{
    GtkIconInfo *info;
    GdkPixbuf *pixbuf;
    gint icon_size;
    gint scale_factor;

    if (tag->close_surface != NULL)
        return;

    gtk_icon_size_lookup (GTK_ICON_SIZE_MENU,
                          &icon_size, NULL);
    scale_factor = gtk_widget_get_scale_factor (GTK_WIDGET (tag->entry));

    info = gtk_icon_theme_lookup_icon_for_scale (gtk_icon_theme_get_default (),
            "window-close-symbolic",
            icon_size, scale_factor,
            GTK_ICON_LOOKUP_GENERIC_FALLBACK);

    /* FIXME: we need a fallback icon in case the icon is not found */
    pixbuf = gtk_icon_info_load_symbolic_for_context (info, context, NULL, NULL);
    tag->close_surface = gdk_cairo_surface_create_from_pixbuf (pixbuf, scale_factor, tag->window);

    g_object_unref (info);
    g_object_unref (pixbuf);
}
Esempio n. 5
0
File: gtkrender.c Progetto: Vort/gtk
/**
 * gtk_render_icon:
 * @context: a #GtkStyleContext
 * @cr: a #cairo_t
 * @pixbuf: a #GdkPixbuf containing the icon to draw
 * @x: X position for the @pixbuf
 * @y: Y position for the @pixbuf
 *
 * Renders the icon in @pixbuf at the specified @x and @y coordinates.
 *
 * This function will render the icon in @pixbuf at exactly its size,
 * regardless of scaling factors, which may not be appropriate when
 * drawing on displays with high pixel densities.
 *
 * You probably want to use gtk_render_icon_surface() instead, if you
 * already have a Cairo surface.
 *
 * Since: 3.2
 **/
void
gtk_render_icon (GtkStyleContext *context,
                 cairo_t         *cr,
                 GdkPixbuf       *pixbuf,
                 gdouble          x,
                 gdouble          y)
{
  cairo_surface_t *surface;

  g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
  g_return_if_fail (cr != NULL);

  cairo_save (cr);
  cairo_new_path (cr);

  surface = gdk_cairo_surface_create_from_pixbuf (pixbuf, 1, NULL);

  gtk_css_style_render_icon_surface (gtk_style_context_lookup_style (context),
                                     cr,
                                     surface,
                                     x, y);

  cairo_surface_destroy (surface);

  cairo_restore (cr);
}
Esempio n. 6
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;
}
Esempio n. 7
0
/**
 * gs_image_set_from_pixbuf_with_scale:
 **/
void
gs_image_set_from_pixbuf_with_scale (GtkImage *image, const GdkPixbuf *pixbuf, gint scale)
{
	cairo_surface_t *surface;
	surface = gdk_cairo_surface_create_from_pixbuf (pixbuf, scale, NULL);
	gtk_image_set_from_surface (image, surface);
	cairo_surface_destroy (surface);
}
Esempio n. 8
0
static cairo_surface_t *
get_surface_from_pixbuf (GdkPixbuf         *pixbuf,
                         MetaImageFillType  fill_type,
                         gdouble            width,
                         gdouble            height,
                         gboolean           vertical_stripes,
                         gboolean           horizontal_stripes)
{
  gdouble pixbuf_width;
  gdouble pixbuf_height;
  cairo_surface_t *surface;
  cairo_content_t content;
  cairo_surface_t *copy;
  cairo_t *cr;

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

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

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

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

      cairo_surface_destroy (surface);
      surface = scaled;
    }

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

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

  cairo_set_source_surface (cr, surface, 0, 0);

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

  cairo_paint (cr);
  cairo_destroy (cr);

  cairo_surface_destroy (surface);

  return copy;
}
Esempio n. 9
0
static void
ensure_stated_surface_from_info (GtkIconHelper *self,
				 GtkStyleContext *context,
				 GtkIconInfo *info,
				 int scale)
{
  GdkPixbuf *destination = NULL;
  cairo_surface_t *surface;
  gboolean symbolic;

  symbolic = FALSE;

  if (info)
    destination =
      gtk_icon_info_load_symbolic_for_context (info,
					       context,
					       &symbolic,
					       NULL);

  if (destination == NULL)
    {
      GtkIconSet *icon_set;

      G_GNUC_BEGIN_IGNORE_DEPRECATIONS;

      icon_set = gtk_icon_factory_lookup_default (GTK_STOCK_MISSING_IMAGE);

      destination =
        gtk_icon_set_render_icon_pixbuf (icon_set, context, self->priv->icon_size);

      G_GNUC_END_IGNORE_DEPRECATIONS;
    }
  else if (!symbolic)
    {
      GdkPixbuf *rendered;

      rendered = ensure_stated_pixbuf_from_pixbuf (self, context, destination);
      g_object_unref (destination);
      destination = rendered;
    }

  surface = NULL;
  if (destination)
    {
      surface = gdk_cairo_surface_create_from_pixbuf (destination, scale, self->priv->window);

      self->priv->rendered_surface_width = 
	(gdk_pixbuf_get_width (destination) + scale - 1) / scale;
      self->priv->rendered_surface_height = 
	(gdk_pixbuf_get_height (destination) + scale - 1) / scale;
      g_object_unref (destination);
    }

  self->priv->rendered_surface = surface;
}
static cairo_surface_t *
get_content_loading_icon (BgSource *source)
{
  GtkIconTheme *theme;
  GtkIconInfo *icon_info;
  GdkPixbuf *pixbuf, *ret;
  GError *error = NULL;
  int scale_factor;
  cairo_surface_t *surface;
  int thumbnail_height;
  int thumbnail_width;

  theme = gtk_icon_theme_get_default ();
  icon_info = gtk_icon_theme_lookup_icon (theme,
                                          "content-loading-symbolic",
                                          16,
                                          GTK_ICON_LOOKUP_FORCE_SIZE | GTK_ICON_LOOKUP_GENERIC_FALLBACK);
  if (icon_info == NULL)
    {
      g_warning ("Failed to find placeholder icon");
      return NULL;
    }

  pixbuf = gtk_icon_info_load_icon (icon_info, &error);
  if (pixbuf == NULL)
    {
      g_warning ("Failed to load placeholder icon: %s", error->message);
      g_clear_error (&error);
      g_clear_object (&icon_info);
      return NULL;
    }

  thumbnail_height = bg_source_get_thumbnail_height (source);
  thumbnail_width = bg_source_get_thumbnail_width (source);
  ret = gdk_pixbuf_new (GDK_COLORSPACE_RGB,
                        TRUE,
                        8, thumbnail_width, thumbnail_height);
  gdk_pixbuf_fill (ret, 0x00000000);

  /* Put the icon in the middle */
  gdk_pixbuf_copy_area (pixbuf, 0, 0,
			gdk_pixbuf_get_width (pixbuf), gdk_pixbuf_get_height (pixbuf),
			ret,
			(thumbnail_width - gdk_pixbuf_get_width (pixbuf)) / 2,
			(thumbnail_height - gdk_pixbuf_get_height (pixbuf)) / 2);
  g_object_unref (pixbuf);

  scale_factor = bg_source_get_scale_factor (source);
  surface = gdk_cairo_surface_create_from_pixbuf (ret, scale_factor, NULL);
  g_object_unref (ret);
  g_clear_object (&icon_info);

  return surface;
}
Esempio n. 11
0
static void
ensure_surface_from_pixbuf (GtkIconHelper   *self,
			    GtkStyleContext *context)
{
  gint width, height;
  GdkPixbuf *pixbuf;
  int scale;

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

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

  scale = get_scale_factor (self, context);

  if (self->priv->force_scale_pixbuf &&
      (self->priv->pixel_size != -1 ||
       self->priv->icon_size != GTK_ICON_SIZE_INVALID))
    {
      ensure_icon_size (self, context, &width, &height);

      if (scale != self->priv->orig_pixbuf_scale ||
	  width < gdk_pixbuf_get_width (self->priv->orig_pixbuf) / self->priv->orig_pixbuf_scale ||
          height < gdk_pixbuf_get_height (self->priv->orig_pixbuf) / self->priv->orig_pixbuf_scale)
	{
	  width = MIN (width * scale, gdk_pixbuf_get_width (self->priv->orig_pixbuf) * scale / self->priv->orig_pixbuf_scale);
	  height = MIN (height * scale, gdk_pixbuf_get_height (self->priv->orig_pixbuf) * scale / self->priv->orig_pixbuf_scale);

	  pixbuf = gdk_pixbuf_scale_simple (self->priv->orig_pixbuf,
					    width, height,
					    GDK_INTERP_BILINEAR);
	}
      else
	{
	  pixbuf = g_object_ref (self->priv->orig_pixbuf); 
	  scale = self->priv->orig_pixbuf_scale;
	}
    }
  else
    {
      pixbuf = g_object_ref (self->priv->orig_pixbuf);
      scale = self->priv->orig_pixbuf_scale;
    }

  self->priv->rendered_surface_width = (gdk_pixbuf_get_width (pixbuf) + scale - 1) / scale;
  self->priv->rendered_surface_height = (gdk_pixbuf_get_height (pixbuf) + scale - 1) / scale;

  self->priv->rendered_surface = gdk_cairo_surface_create_from_pixbuf (pixbuf, scale, self->priv->window);
  g_object_unref (pixbuf);
}
Esempio n. 12
0
static gboolean 
pattern_value_parse (GtkCssParser *parser,
                     GValue       *value)
{
  if (_gtk_css_parser_try (parser, "none", TRUE))
    {
      /* nothing to do here */
    }
  else
    {
      GError *error = NULL;
      gchar *path;
      GdkPixbuf *pixbuf;
      GFile *file;
      cairo_surface_t *surface;
      cairo_pattern_t *pattern;
      cairo_matrix_t matrix;

      file = _gtk_css_parser_read_url (parser);
      if (file == NULL)
        return FALSE;

      path = g_file_get_path (file);
      g_object_unref (file);

      pixbuf = gdk_pixbuf_new_from_file (path, &error);
      g_free (path);
      if (pixbuf == NULL)
        {
          _gtk_css_parser_take_error (parser, error);
          return FALSE;
        }

      surface = gdk_cairo_surface_create_from_pixbuf (pixbuf, 1, NULL);
      pattern = cairo_pattern_create_for_surface (surface);
      cairo_surface_destroy (surface);

      cairo_matrix_init_scale (&matrix,
                               gdk_pixbuf_get_width (pixbuf),
                               gdk_pixbuf_get_height (pixbuf));
      cairo_pattern_set_matrix (pattern, &matrix);

      g_object_unref (pixbuf);

      g_value_take_boxed (value, pattern);
    }
  
  return TRUE;
}
Esempio n. 13
0
GtkCssImage *
_gtk_css_image_surface_new_for_pixbuf (GdkPixbuf *pixbuf)
{
  GtkCssImage *image;
  cairo_surface_t *surface;

  g_return_val_if_fail (GDK_IS_PIXBUF (pixbuf), NULL);

  surface = gdk_cairo_surface_create_from_pixbuf (pixbuf, 1, NULL);

  image = _gtk_css_image_surface_new (surface);
  cairo_surface_destroy (surface);

  return image;
}
Esempio n. 14
0
File: gtkrender.c Progetto: 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;
}
Esempio n. 15
0
File: gdkcursor.c Progetto: Vort/gtk
/**
 * gdk_cursor_new_from_pixbuf:
 * @display: the #GdkDisplay for which the cursor will be created
 * @pixbuf: the #GdkPixbuf containing the cursor image
 * @x: the horizontal offset of the “hotspot” of the cursor.
 * @y: the vertical offset of the “hotspot” of the cursor.
 *
 * Creates a new cursor from a pixbuf.
 *
 * Not all GDK backends support RGBA cursors. If they are not
 * supported, a monochrome approximation will be displayed.
 * The functions gdk_display_supports_cursor_alpha() and
 * gdk_display_supports_cursor_color() can be used to determine
 * whether RGBA cursors are supported;
 * gdk_display_get_default_cursor_size() and
 * gdk_display_get_maximal_cursor_size() give information about
 * cursor sizes.
 *
 * If @x or @y are `-1`, the pixbuf must have
 * options named “x_hot” and “y_hot”, resp., containing
 * integer values between `0` and the width resp. height of
 * the pixbuf. (Since: 3.0)
 *
 * On the X backend, support for RGBA cursors requires a
 * sufficently new version of the X Render extension.
 *
 * Returns: a new #GdkCursor.
 *
 * Since: 2.4
 */
GdkCursor *
gdk_cursor_new_from_pixbuf (GdkDisplay *display,
                            GdkPixbuf  *pixbuf,
                            gint        x,
                            gint        y)
{
  cairo_surface_t *surface;
  const char *option;
  char *end;
  gint64 value;
  GdkCursor *cursor;
 
  g_return_val_if_fail (GDK_IS_DISPLAY (display), NULL);
  g_return_val_if_fail (GDK_IS_PIXBUF (pixbuf), NULL);

  if (x == -1 && (option = gdk_pixbuf_get_option (pixbuf, "x_hot")))
    {
      errno = 0;
      end = NULL;
      value = g_ascii_strtoll (option, &end, 10);
      if (errno == 0 &&
          end != option &&
          value >= 0 && value < G_MAXINT)
        x = (gint) value;
    }
  
  if (y == -1 && (option = gdk_pixbuf_get_option (pixbuf, "y_hot")))
    {
      errno = 0;
      end = NULL;
      value = g_ascii_strtoll (option, &end, 10);
      if (errno == 0 &&
          end != option &&
          value >= 0 && value < G_MAXINT)
        y = (gint) value;
    }

  surface = gdk_cairo_surface_create_from_pixbuf (pixbuf, 1, NULL);
  
  cursor = GDK_DISPLAY_GET_CLASS (display)->get_cursor_for_surface (display, surface, x, y);

  cairo_surface_destroy (surface);

  return cursor;
}
Esempio n. 16
0
static int gtkDialogSetOpacityImageAttrib(Ihandle *ih, const char *value)
{
  GdkPixbuf* pixbuf = iupImageGetImage(value, ih, 0);
  if (pixbuf)
  {
#if GTK_CHECK_VERSION(3, 0, 0)
    GdkWindow* window = iupgtkGetWindow(ih->handle);
    if (window)
    {
      cairo_region_t *shape;

#if GTK_CHECK_VERSION(3, 10, 0)
      cairo_surface_t* surface = gdk_cairo_surface_create_from_pixbuf(pixbuf, 0, window);
#else
      int width = gdk_pixbuf_get_width(pixbuf);
      int height = gdk_pixbuf_get_height(pixbuf);
      cairo_surface_t* surface = gdk_window_create_similar_surface(window, CAIRO_CONTENT_COLOR_ALPHA, width, height);
      cairo_t* cr = cairo_create(surface);
      gdk_cairo_set_source_pixbuf(cr, pixbuf, 0, 0);
      cairo_set_operator(cr, CAIRO_OPERATOR_SOURCE);
      cairo_paint(cr);
      cairo_destroy(cr);
#endif

      shape = gdk_cairo_region_create_from_surface(surface);
      cairo_surface_destroy(surface);

      gtk_widget_shape_combine_region(ih->handle, shape);
      cairo_region_destroy(shape);
    }
#else
    GdkBitmap* mask = NULL;
    gdk_pixbuf_render_pixmap_and_mask(pixbuf, NULL, &mask, 255);
    if (mask) 
    {
      gtk_widget_shape_combine_mask(ih->handle, mask, 0, 0);
      g_object_unref(mask);
    }
#endif
    return 1;
  }
  return 0;
}
static void
create_surface (PhotosPrintPreview *preview)
{
  PhotosPrintPreviewPrivate *priv = preview->priv;
  GdkPixbuf *pixbuf;

  if (priv->surface != NULL)
    {
      cairo_surface_destroy (priv->surface);
      priv->surface = NULL;
    }

  pixbuf = create_preview_buffer (preview);
  if (pixbuf != NULL)
    {
      priv->surface = gdk_cairo_surface_create_from_pixbuf (pixbuf, 0,
                                                            gtk_widget_get_window (GTK_WIDGET (preview)));
      g_object_unref (pixbuf);
    }

  priv->flag_create_surface = FALSE;
}
Esempio n. 18
0
static cairo_surface_t *
ensure_surface_for_icon_set (GtkIconHelper    *self,
                             GtkCssStyle      *style,
                             GtkTextDirection  direction,
                             gint              scale,
			     GtkIconSet       *icon_set)
{
  cairo_surface_t *surface;
  GdkPixbuf *pixbuf;

  pixbuf = gtk_icon_set_render_icon_pixbuf_for_scale (icon_set,
                                                      style,
                                                      direction,
                                                      self->priv->icon_size,
                                                      scale);
  surface = gdk_cairo_surface_create_from_pixbuf (pixbuf,
                                                  scale,
                                                  gtk_widget_get_window (gtk_css_gadget_get_owner (GTK_CSS_GADGET (self))));
  g_object_unref (pixbuf);

  return surface;
}
static void
photos_tool_filter_button_constructed (GObject *object)
{
  PhotosToolFilterButton *self = PHOTOS_TOOL_FILTER_BUTTON (object);
  GApplication *app;
  g_autoptr (GdkPixbuf) preview_icon = NULL;
  GtkWidget *image;
  PhotosWidgetShader *shader;
  cairo_surface_t *preview_icon_surface = NULL; /* TODO: use g_autoptr */
  gint scale;

  G_OBJECT_CLASS (photos_tool_filter_button_parent_class)->constructed (object);

  app = g_application_get_default ();
  scale = photos_application_get_scale_factor (PHOTOS_APPLICATION (app));
  preview_icon = photos_utils_create_placeholder_icon_for_scale ("content-loading-symbolic", 96, scale);
  if (preview_icon != NULL)
    preview_icon_surface = gdk_cairo_surface_create_from_pixbuf (preview_icon, scale, NULL);

  image = gtk_image_new_from_surface (preview_icon_surface);
  gtk_container_add (GTK_CONTAINER (self->overlay), image);
  shader = photos_widget_shader_new (image);
  gtk_widget_show (image);

  self->button = gtk_radio_button_new_with_label_from_widget (self->group, self->label);
  gtk_button_set_always_show_image (GTK_BUTTON (self->button), TRUE);
  gtk_button_set_image (GTK_BUTTON (self->button), self->overlay);
  gtk_button_set_image_position (GTK_BUTTON (self->button), GTK_POS_TOP);
  gtk_button_set_relief (GTK_BUTTON (self->button), GTK_RELIEF_NONE);
  gtk_toggle_button_set_mode (GTK_TOGGLE_BUTTON (self->button), FALSE);
  gtk_container_add (GTK_CONTAINER (self), self->button);
  g_object_bind_property (self->button, "active", shader, "active", G_BINDING_SYNC_CREATE);
  g_signal_connect_swapped (self->button, "toggled", G_CALLBACK (photos_tool_filter_button_toggled), self);
  photos_tool_filter_button_toggled (self);

  g_clear_pointer (&preview_icon_surface, (GDestroyNotify) cairo_surface_destroy);
  self->group = NULL; /* We will not need it any more */
}
static void
picture_scaled (GObject *source_object,
                GAsyncResult *res,
                gpointer user_data)
{
  BgPicturesSource *bg_source;
  CcBackgroundItem *item;
  GError *error = NULL;
  GdkPixbuf *pixbuf = NULL;
  const char *software;
  const char *uri;
  GtkTreeIter iter;
  GtkTreePath *path;
  GtkTreeRowReference *row_ref;
  GtkListStore *store;
  cairo_surface_t *surface = NULL;
  int scale_factor;

  item = g_object_get_data (source_object, "item");
  pixbuf = gdk_pixbuf_new_from_stream_finish (res, &error);
  if (pixbuf == NULL)
    {
      if (!g_error_matches (error, G_IO_ERROR, G_IO_ERROR_CANCELLED))
        {
          g_warning ("Failed to load image: %s", error->message);
          remove_placeholder (BG_PICTURES_SOURCE (user_data), item);
        }

      g_error_free (error);
      goto out;
    }

  /* since we were not cancelled, we can now cast user_data
   * back to BgPicturesSource.
   */
  bg_source = BG_PICTURES_SOURCE (user_data);
  store = bg_source_get_liststore (BG_SOURCE (bg_source));
  uri = cc_background_item_get_uri (item);
  if (uri == NULL)
    uri = cc_background_item_get_source_url (item);

  /* Ignore screenshots */
  software = gdk_pixbuf_get_option (pixbuf, "tEXt::Software");
  if (software != NULL &&
      g_str_equal (software, "gnome-screenshot"))
    {
      g_debug ("Ignored URL '%s' as it's a screenshot from gnome-screenshot", uri);
      remove_placeholder (BG_PICTURES_SOURCE (user_data), item);
      goto out;
    }

  scale_factor = bg_source_get_scale_factor (BG_SOURCE (bg_source));
  surface = gdk_cairo_surface_create_from_pixbuf (pixbuf, scale_factor, NULL);
  cc_background_item_load (item, NULL);

  row_ref = g_object_get_data (G_OBJECT (item), "row-ref");
  if (row_ref == NULL)
    {
      /* insert the item into the liststore if it did not exist */
      gtk_list_store_insert_with_values (store, NULL, -1,
                                         0, surface,
                                         1, item,
                                         -1);
    }
  else
    {
      path = gtk_tree_row_reference_get_path (row_ref);
      if (gtk_tree_model_get_iter (GTK_TREE_MODEL (store), &iter, path))
        {
          /* otherwise update the thumbnail */
          gtk_list_store_set (store, &iter,
                              0, surface,
                              -1);
        }
    }

  g_hash_table_insert (bg_source->priv->known_items,
                       bg_pictures_source_get_unique_filename (uri),
                       GINT_TO_POINTER (TRUE));


 out:
  g_clear_pointer (&surface, (GDestroyNotify) cairo_surface_destroy);
  g_clear_object (&pixbuf);
}
Esempio n. 21
0
static void
nautilus_list_model_get_value (GtkTreeModel *tree_model, GtkTreeIter *iter, int column, GValue *value)
{
	NautilusListModel *model;
	FileEntry *file_entry;
	NautilusFile *file;
	char *str;
	GdkPixbuf *icon, *rendered_icon;
	GIcon *gicon, *emblemed_icon, *emblem_icon;
	NautilusIconInfo *icon_info;
	GEmblem *emblem;
	GList *emblem_icons, *l;
	int icon_size, icon_scale;
	NautilusZoomLevel zoom_level;
	NautilusFileIconFlags flags;
	cairo_surface_t *surface;
	
	model = (NautilusListModel *)tree_model;

	g_return_if_fail (model->details->stamp == iter->stamp);
	g_return_if_fail (!g_sequence_iter_is_end (iter->user_data));

	file_entry = g_sequence_get (iter->user_data);
	file = file_entry->file;
	
	switch (column) {
	case NAUTILUS_LIST_MODEL_FILE_COLUMN:
		g_value_init (value, NAUTILUS_TYPE_FILE);

		g_value_set_object (value, file);
		break;
	case NAUTILUS_LIST_MODEL_SUBDIRECTORY_COLUMN:
		g_value_init (value, NAUTILUS_TYPE_DIRECTORY);

		g_value_set_object (value, file_entry->subdirectory);
		break;
	case NAUTILUS_LIST_MODEL_SMALLEST_ICON_COLUMN:
	case NAUTILUS_LIST_MODEL_SMALLER_ICON_COLUMN:
	case NAUTILUS_LIST_MODEL_SMALL_ICON_COLUMN:
	case NAUTILUS_LIST_MODEL_STANDARD_ICON_COLUMN:
	case NAUTILUS_LIST_MODEL_LARGE_ICON_COLUMN:
	case NAUTILUS_LIST_MODEL_LARGER_ICON_COLUMN:
	case NAUTILUS_LIST_MODEL_LARGEST_ICON_COLUMN:
		g_value_init (value, CAIRO_GOBJECT_TYPE_SURFACE);

		if (file != NULL) {
			zoom_level = nautilus_list_model_get_zoom_level_from_column_id (column);
			icon_size = nautilus_get_icon_size_for_zoom_level (zoom_level);
			icon_scale = nautilus_list_model_get_icon_scale (model);

			flags = NAUTILUS_FILE_ICON_FLAGS_USE_THUMBNAILS |
				NAUTILUS_FILE_ICON_FLAGS_FORCE_THUMBNAIL_SIZE |
				NAUTILUS_FILE_ICON_FLAGS_USE_MOUNT_ICON_AS_EMBLEM;
			if (model->details->drag_view != NULL) {
				GtkTreePath *path_a, *path_b;
				
				gtk_tree_view_get_drag_dest_row (model->details->drag_view,
								 &path_a,
								 NULL);
				if (path_a != NULL) {
					path_b = gtk_tree_model_get_path (tree_model, iter);

					if (gtk_tree_path_compare (path_a, path_b) == 0) {
						flags |= NAUTILUS_FILE_ICON_FLAGS_FOR_DRAG_ACCEPT;
					}
						
					gtk_tree_path_free (path_a);
					gtk_tree_path_free (path_b);
				}
			}

			gicon = G_ICON (nautilus_file_get_icon_pixbuf (file, icon_size, TRUE, icon_scale, flags));
			emblem_icons = nautilus_file_get_emblem_icons (file);

			/* pick only the first emblem we can render for the list view */
			for (l = emblem_icons; l != NULL; l = l->next) {
				emblem_icon = l->data;
				if (nautilus_icon_theme_can_render (G_THEMED_ICON (emblem_icon))) {
					emblem = g_emblem_new (emblem_icon);
					emblemed_icon = g_emblemed_icon_new (gicon, emblem);

					g_object_unref (gicon);
					g_object_unref (emblem);
					gicon = emblemed_icon;

					break;
				}
			}

			g_list_free_full (emblem_icons, g_object_unref);

			icon_info = nautilus_icon_info_lookup (gicon, icon_size, icon_scale);
			icon = nautilus_icon_info_get_pixbuf_at_size (icon_info, icon_size);

			g_object_unref (icon_info);
			g_object_unref (gicon);

			if (model->details->highlight_files != NULL &&
			    g_list_find_custom (model->details->highlight_files,
			                        file, (GCompareFunc) nautilus_file_compare_location))
			{
				rendered_icon = eel_create_spotlight_pixbuf (icon);

				if (rendered_icon != NULL) {
					g_object_unref (icon);
					icon = rendered_icon;
				}
			}

			surface = gdk_cairo_surface_create_from_pixbuf (icon, icon_scale, NULL);
			g_value_take_boxed (value, surface);
			g_object_unref (icon);
		}
		break;
	case NAUTILUS_LIST_MODEL_FILE_NAME_IS_EDITABLE_COLUMN:
		g_value_init (value, G_TYPE_BOOLEAN);
		
                g_value_set_boolean (value, file != NULL && nautilus_file_can_rename (file));
                break;
 	default:
 		if (column >= NAUTILUS_LIST_MODEL_NUM_COLUMNS || column < NAUTILUS_LIST_MODEL_NUM_COLUMNS + model->details->columns->len) {
			NautilusColumn *nautilus_column;
			GQuark attribute;
			nautilus_column = model->details->columns->pdata[column - NAUTILUS_LIST_MODEL_NUM_COLUMNS];
			
			g_value_init (value, G_TYPE_STRING);
			g_object_get (nautilus_column, 
				      "attribute_q", &attribute, 
				      NULL);
			if (file != NULL) {
				str = nautilus_file_get_string_attribute_with_default_q (file, 
											 attribute);
				g_value_take_string (value, str);
			} else if (attribute == attribute_name_q) {
				if (file_entry->parent->loaded) {
					g_value_set_string (value, _("(Empty)"));
				} else {
					g_value_set_string (value, _("Loading…"));
				}
			}
		} else {
			g_assert_not_reached ();
		}
	}
}
Esempio n. 22
0
GIcon *
photos_utils_create_symbolic_icon_for_scale (const gchar *name, gint base_size, gint scale)
{
  g_autoptr (GIcon) icon = NULL;
  GIcon *ret_val = NULL;
  g_autoptr (GdkPixbuf) pixbuf = NULL;
  g_autoptr (GtkIconInfo) info = NULL;
  GtkIconTheme *theme;
  g_autoptr (GtkStyleContext) style = NULL;
  g_autoptr (GtkWidgetPath) path = NULL;
  cairo_surface_t *icon_surface = NULL; /* TODO: use g_autoptr */
  cairo_surface_t *surface; /* TODO: use g_autoptr */
  cairo_t *cr; /* TODO: use g_autoptr */
  g_autofree gchar *symbolic_name = NULL;
  const gint bg_size = 24;
  const gint emblem_margin = 4;
  gint emblem_pos;
  gint emblem_size;
  gint total_size;
  gint total_size_scaled;

  total_size = base_size / 2;
  total_size_scaled = total_size * scale;
  emblem_size = bg_size - emblem_margin * 2;

  surface = cairo_image_surface_create (CAIRO_FORMAT_ARGB32, total_size_scaled, total_size_scaled);
  cairo_surface_set_device_scale (surface, (gdouble) scale, (gdouble) scale);
  cr = cairo_create (surface);

  style = gtk_style_context_new ();

  path = gtk_widget_path_new ();
  gtk_widget_path_append_type (path, GTK_TYPE_ICON_VIEW);
  gtk_style_context_set_path (style, path);

  gtk_style_context_add_class (style, "photos-icon-bg");

  gtk_render_background (style, cr, total_size - bg_size, total_size - bg_size, bg_size, bg_size);

  symbolic_name = g_strconcat (name, "-symbolic", NULL);
  icon = g_themed_icon_new_with_default_fallbacks (symbolic_name);

  theme = gtk_icon_theme_get_default();
  info = gtk_icon_theme_lookup_by_gicon_for_scale (theme, icon, emblem_size, scale, GTK_ICON_LOOKUP_FORCE_SIZE);
  if (info == NULL)
    goto out;

  pixbuf = gtk_icon_info_load_symbolic_for_context (info, style, NULL, NULL);
  if (pixbuf == NULL)
    goto out;

  icon_surface = gdk_cairo_surface_create_from_pixbuf (pixbuf, scale, NULL);

  emblem_pos = total_size - emblem_size - emblem_margin;
  gtk_render_icon_surface (style, cr, icon_surface, emblem_pos, emblem_pos);

  ret_val = G_ICON (gdk_pixbuf_get_from_surface (surface, 0, 0, total_size_scaled, total_size_scaled));

 out:
  cairo_surface_destroy (icon_surface);
  cairo_surface_destroy (surface);
  cairo_destroy (cr);

  return ret_val;
}
Esempio n. 23
0
/**
 * gd_create_symbolic_icon_for_scale:
 * @name:
 * @base_size:
 * @scale:
 *
 * Returns: (transfer full):
 */
GIcon *
gd_create_symbolic_icon_for_scale (const gchar *name,
                                   gint base_size,
                                   gint scale)
{
  gchar *symbolic_name;
  GIcon *icon, *retval = NULL;
  cairo_surface_t *icon_surface;
  cairo_surface_t *surface;
  cairo_t *cr;
  GtkStyleContext *style;
  GtkWidgetPath *path;
  GdkPixbuf *pixbuf;
  GtkIconTheme *theme;
  GtkIconInfo *info;
  gint bg_size;
  gint emblem_size;
  gint total_size;
  gint total_size_scaled;

  total_size = base_size / 2;
  total_size_scaled = total_size * scale;

  bg_size = MAX (total_size / 2, _BG_MIN_SIZE);
  emblem_size = MAX (bg_size - 8, _EMBLEM_MIN_SIZE);

  surface = cairo_image_surface_create (CAIRO_FORMAT_ARGB32, total_size_scaled, total_size_scaled);
  cairo_surface_set_device_scale (surface, (gdouble) scale, (gdouble) scale);
  cr = cairo_create (surface);

  style = gtk_style_context_new ();

  path = gtk_widget_path_new ();
  gtk_widget_path_append_type (path, GTK_TYPE_ICON_VIEW);
  gtk_style_context_set_path (style, path);
  gtk_widget_path_unref (path);

  gtk_style_context_add_class (style, "documents-icon-bg");

  gtk_render_background (style, cr, (total_size - bg_size) / 2, (total_size - bg_size) / 2, bg_size, bg_size);

  symbolic_name = g_strconcat (name, "-symbolic", NULL);
  icon = g_themed_icon_new_with_default_fallbacks (symbolic_name);
  g_free (symbolic_name);

  theme = gtk_icon_theme_get_default();
  info = gtk_icon_theme_lookup_by_gicon_for_scale (theme, icon, emblem_size, scale,
                                                   GTK_ICON_LOOKUP_FORCE_SIZE);
  g_object_unref (icon);

  if (info == NULL)
    goto out;

  pixbuf = gtk_icon_info_load_symbolic_for_context (info, style, NULL, NULL);
  g_object_unref (info);

  if (pixbuf == NULL)
    goto out;

  icon_surface = gdk_cairo_surface_create_from_pixbuf (pixbuf, scale, NULL);
  g_object_unref (pixbuf);

  gtk_render_icon_surface (style, cr, icon_surface, (total_size - emblem_size) / 2,  (total_size - emblem_size) / 2);
  cairo_surface_destroy (icon_surface);

  retval = G_ICON (gdk_pixbuf_get_from_surface (surface, 0, 0, total_size_scaled, total_size_scaled));

 out:
  g_object_unref (style);
  cairo_surface_destroy (surface);
  cairo_destroy (cr);

  return retval;
}
Esempio n. 24
0
static gboolean
swatch_draw (GtkWidget *widget,
             cairo_t   *cr)
{
  GtkColorSwatch *swatch = (GtkColorSwatch*)widget;
  gdouble width, height;
  GtkStyleContext *context;
  GtkStateFlags state;
  GtkIconTheme *theme;
  GtkBorder border, padding;
  GdkRectangle rect;
  GtkIconInfo *icon_info = NULL;
  gint scale;

  theme = gtk_icon_theme_get_default ();
  context = gtk_widget_get_style_context (widget);
  state = gtk_style_context_get_state (context);
  width = gtk_widget_get_allocated_width (widget);
  height = gtk_widget_get_allocated_height (widget);

  gtk_render_background (context, cr, 0, 0, width, height);

  if (swatch->priv->has_color)
    {
      cairo_pattern_t *pattern;
      cairo_matrix_t matrix;

      gtk_render_content_path (context, cr, 0, 0, width, height);

      if (swatch->priv->use_alpha)
        {
          cairo_save (cr);

          cairo_clip_preserve (cr);

          cairo_set_source_rgb (cr, 0.33, 0.33, 0.33);
          cairo_fill_preserve (cr);

          pattern = _gtk_color_chooser_get_checkered_pattern ();
          cairo_matrix_init_scale (&matrix, 0.125, 0.125);
          cairo_pattern_set_matrix (pattern, &matrix);

          cairo_set_source_rgb (cr, 0.66, 0.66, 0.66);
          cairo_mask (cr, pattern);
          cairo_pattern_destroy (pattern);

          cairo_restore (cr);

          gdk_cairo_set_source_rgba (cr, &swatch->priv->color);
        }
      else
        {
          cairo_set_source_rgb (cr,
                                swatch->priv->color.red,
                                swatch->priv->color.green,
                                swatch->priv->color.blue);
        }

      cairo_fill (cr);
    }

  gtk_render_frame (context, cr, 0, 0, width, height);

  scale = gtk_widget_get_scale_factor (widget);
  if (swatch->priv->icon)
    {
      icon_info = gtk_icon_theme_lookup_icon_for_scale (theme, swatch->priv->icon, PIXBUF_SIZE,
                                                        scale,
                                                        GTK_ICON_LOOKUP_GENERIC_FALLBACK
                                                        | GTK_ICON_LOOKUP_USE_BUILTIN);
    }
  else if ((state & GTK_STATE_FLAG_SELECTED) != 0)
    {
      GIcon *gicon;

      gicon = g_themed_icon_new ("object-select-symbolic");
      /* fallback for themes that don't have object-select-symbolic */
      g_themed_icon_append_name (G_THEMED_ICON (gicon), "gtk-apply");

      icon_info = gtk_icon_theme_lookup_by_gicon_for_scale (theme, gicon, PIXBUF_SIZE,
                                                            scale,
                                                            GTK_ICON_LOOKUP_GENERIC_FALLBACK
                                                            | GTK_ICON_LOOKUP_USE_BUILTIN);
      g_object_unref (gicon);
    }

  /* now draw the overlay image */
  gtk_style_context_get_border (context, state, &border);
  gtk_style_context_get_padding (context, state, &padding);
  rect.width = width - (border.left + border.right + padding.left + padding.right);
  rect.height = height - (border.top + border.bottom + padding.top + padding.bottom);
  rect.x = border.left + padding.left;
  rect.y = border.top + padding.top;

  gtk_style_context_save_to_node (context, swatch->priv->overlay_node);

  gtk_render_background (context, cr, rect.x, rect.y, rect.width, rect.height);
  gtk_render_frame (context, cr, rect.x, rect.y, rect.width, rect.height);

  if (icon_info != NULL)
    {
      GdkPixbuf *pixbuf;

      pixbuf = gtk_icon_info_load_symbolic_for_context (icon_info, context, NULL, NULL);
      if (pixbuf != NULL)
        {
          cairo_surface_t *surface;

          surface = gdk_cairo_surface_create_from_pixbuf (pixbuf, scale, gtk_widget_get_window (widget));
          gtk_render_icon_surface (context, cr, surface,
                                   rect.x + (rect.width - (gdk_pixbuf_get_width (pixbuf) / scale)) / 2,
                                   rect.y + (rect.height - (gdk_pixbuf_get_height (pixbuf) / scale)) / 2);
          cairo_surface_destroy (surface);
          g_object_unref (pixbuf);
        }

      g_object_unref (icon_info);
    }

  if (gtk_widget_has_visible_focus (widget))
    gtk_render_focus (context, cr, 0, 0, width, height);

  gtk_style_context_restore (context);

  return FALSE;
}
Esempio n. 25
0
static gboolean
gtk_color_swatch_render_overlay (GtkCssGadget *gadget,
                                 cairo_t      *cr,
                                 int           x,
                                 int           y,
                                 int           width,
                                 int           height,
                                 gpointer      data)
{
    GtkWidget *widget;
    GtkColorSwatch *swatch;
    GtkStyleContext *context;
    GtkStateFlags state;
    GtkIconTheme *theme;
    GtkIconInfo *icon_info = NULL;
    gint scale;

    widget = gtk_css_gadget_get_owner (gadget);
    swatch = GTK_COLOR_SWATCH (widget);

    theme = gtk_icon_theme_get_default ();
    context = gtk_widget_get_style_context (widget);
    state = gtk_style_context_get_state (context);

    scale = gtk_widget_get_scale_factor (widget);
    if (swatch->priv->icon)
    {
        icon_info = gtk_icon_theme_lookup_icon_for_scale (theme, swatch->priv->icon, PIXBUF_SIZE,
                    scale,
                    GTK_ICON_LOOKUP_GENERIC_FALLBACK
                    | GTK_ICON_LOOKUP_USE_BUILTIN);
    }
    else if ((state & GTK_STATE_FLAG_SELECTED) != 0)
    {
        GIcon *gicon;

        gicon = g_themed_icon_new ("object-select-symbolic");
        /* fallback for themes that don't have object-select-symbolic */
        g_themed_icon_append_name (G_THEMED_ICON (gicon), "gtk-apply");

        icon_info = gtk_icon_theme_lookup_by_gicon_for_scale (theme, gicon, PIXBUF_SIZE,
                    scale,
                    GTK_ICON_LOOKUP_USE_BUILTIN);
        g_object_unref (gicon);
    }

    /* now draw the overlay image */
    if (icon_info != NULL)
    {
        GdkPixbuf *pixbuf;

        pixbuf = gtk_icon_info_load_symbolic_for_context (icon_info, context, NULL, NULL);
        if (pixbuf != NULL)
        {
            cairo_surface_t *surface;

            surface = gdk_cairo_surface_create_from_pixbuf (pixbuf, scale, gtk_widget_get_window (widget));
            gtk_render_icon_surface (context, cr, surface, x, y);
            cairo_surface_destroy (surface);
            g_object_unref (pixbuf);
        }

        g_object_unref (icon_info);
    }

    return FALSE;
}
Esempio n. 26
0
static void
photos_base_item_check_effects_and_update_info (PhotosBaseItem *self)
{
  PhotosBaseItemPrivate *priv = self->priv;
  GApplication *app;
  GIcon *pix;
  GList *emblem_icons = NULL;
  GList *windows;
  GdkPixbuf *emblemed_pixbuf = NULL;
  GdkPixbuf *thumbnailed_pixbuf = NULL;
  GdkWindow *window;
  gint scale;

  if (priv->original_icon == NULL)
    goto out;

  emblemed_pixbuf = g_object_ref (priv->original_icon);

  if (priv->favorite)
    {
      pix = photos_base_item_create_symbolic_emblem (PHOTOS_ICON_FAVORITE);
      emblem_icons = g_list_prepend (emblem_icons, pix);
    }

  if (g_list_length (emblem_icons) > 0)
    {
      GIcon *emblemed_icon;
      GList *l;
      GtkIconInfo *icon_info;
      GtkIconTheme *theme;
      gint height;
      gint size;
      gint width;

      emblem_icons = g_list_reverse (emblem_icons);
      emblemed_icon = g_emblemed_icon_new (G_ICON (priv->original_icon), NULL);
      for (l = emblem_icons; l != NULL; l = g_list_next (l))
        {
          GEmblem *emblem;
          GIcon *emblem_icon = G_ICON (l->data);

          emblem = g_emblem_new (emblem_icon);
          g_emblemed_icon_add_emblem (G_EMBLEMED_ICON (emblemed_icon), emblem);
          g_object_unref (emblem);
        }

      theme = gtk_icon_theme_get_default ();

      width = gdk_pixbuf_get_width (priv->original_icon);
      height = gdk_pixbuf_get_height (priv->original_icon);
      size = (width > height) ? width : height;

      icon_info = gtk_icon_theme_lookup_by_gicon (theme, emblemed_icon, size, GTK_ICON_LOOKUP_FORCE_SIZE);

      if (icon_info != NULL)
        {
          GError *error = NULL;
          GdkPixbuf *tmp;

          tmp = gtk_icon_info_load_icon (icon_info, &error);
          if (error != NULL)
            {
              g_warning ("Unable to render the emblem: %s", error->message);
              g_error_free (error);
            }
          else
            {
              g_object_unref (emblemed_pixbuf);
              emblemed_pixbuf = tmp;
            }

          g_object_unref (icon_info);
        }

      g_object_unref (emblemed_icon);
    }

  g_clear_pointer (&priv->surface, (GDestroyNotify) cairo_surface_destroy);

  if (priv->thumb_path != NULL)
    {
      GtkBorder *slice;

      slice = photos_utils_get_thumbnail_frame_border ();
      thumbnailed_pixbuf = gd_embed_image_in_frame (emblemed_pixbuf,
                                                    "resource:///org/gnome/photos/thumbnail-frame.png",
                                                    slice,
                                                    slice);
      gtk_border_free (slice);
    }
  else
    thumbnailed_pixbuf = g_object_ref (emblemed_pixbuf);

  app = g_application_get_default ();
  scale = photos_application_get_scale_factor (PHOTOS_APPLICATION (app));
  windows = gtk_application_get_windows (GTK_APPLICATION (app));
  window = gtk_widget_get_window (GTK_WIDGET (windows->data));
  priv->surface = gdk_cairo_surface_create_from_pixbuf (thumbnailed_pixbuf, scale, window);

  g_signal_emit (self, signals[INFO_UPDATED], 0);

 out:
  g_clear_object (&thumbnailed_pixbuf);
  g_clear_object (&emblemed_pixbuf);
  g_list_free_full (emblem_icons, g_object_unref);
}
static void
bg_colors_source_add_color (BgColorsSource               *self,
                            GnomeDesktopThumbnailFactory *thumb_factory,
                            GtkListStore                 *store,
                            const char                   *color,
                            GtkTreeRowReference         **ret_row_ref)
{
  CcBackgroundItemFlags flags;
  CcBackgroundItem *item;
  GdkPixbuf *pixbuf;
  cairo_surface_t *surface;
  int scale_factor;
  int thumbnail_height, thumbnail_width;
  GtkTreeIter iter;

  thumbnail_height = bg_source_get_thumbnail_height (BG_SOURCE (self));
  thumbnail_width = bg_source_get_thumbnail_width (BG_SOURCE (self));

  item = cc_background_item_new (NULL);
  flags = CC_BACKGROUND_ITEM_HAS_PCOLOR |
          CC_BACKGROUND_ITEM_HAS_SCOLOR |
          CC_BACKGROUND_ITEM_HAS_SHADING |
          CC_BACKGROUND_ITEM_HAS_PLACEMENT |
          CC_BACKGROUND_ITEM_HAS_URI;
  /* It does have a URI, it's "none" */

  g_object_set (G_OBJECT (item),
                "uri", "file:///" DATADIR "/gnome-control-center/pixmaps/noise-texture-light.png",
                "primary-color", color,
                "secondary-color", color,
                "shading", G_DESKTOP_BACKGROUND_SHADING_SOLID,
                "placement", G_DESKTOP_BACKGROUND_STYLE_WALLPAPER,
                "flags", flags,
                NULL);
  cc_background_item_load (item, NULL);

  /* insert the item into the liststore */
  scale_factor = bg_source_get_scale_factor (BG_SOURCE (self));
  pixbuf = cc_background_item_get_thumbnail (item,
                                             thumb_factory,
                                             thumbnail_width, thumbnail_height,
                                             scale_factor);
  surface = gdk_cairo_surface_create_from_pixbuf (pixbuf, scale_factor, NULL);
  gtk_list_store_insert_with_values (store, &iter, 0,
                                     0, surface,
                                     1, item,
                                     -1);

  if (ret_row_ref)
    {
      GtkTreePath *path;

      path = gtk_tree_model_get_path (GTK_TREE_MODEL (store), &iter);
      *ret_row_ref = gtk_tree_row_reference_new (GTK_TREE_MODEL (store), path);
      gtk_tree_path_free (path);
    }

  cairo_surface_destroy (surface);
  g_object_unref (pixbuf);
  g_object_unref (item);
}
Esempio n. 28
0
cairo_surface_t *
render_user_icon (ActUser     *user,
                  UmIconStyle  style,
                  gint         icon_size,
                  gint         scale)
{
        GdkPixbuf    *pixbuf;
        GdkPixbuf    *framed;
        gboolean      res;
        GError       *error;
        const gchar  *icon_file;
        cairo_surface_t *surface = NULL;

        g_return_val_if_fail (ACT_IS_USER (user), NULL);
        g_return_val_if_fail (icon_size > 12, NULL);

        icon_file = act_user_get_icon_file (user);
        pixbuf = NULL;
        if (icon_file) {
                res = check_user_file (icon_file, MAX_FILE_SIZE);
                if (res) {
                        pixbuf = gdk_pixbuf_new_from_file_at_size (icon_file,
                                                                   icon_size * scale,
                                                                   icon_size * scale,
                                                                   NULL);
                }
                else {
                        pixbuf = NULL;
                }
        }

        if (pixbuf != NULL) {
                goto out;
        }

        error = NULL;
        pixbuf = gtk_icon_theme_load_icon (gtk_icon_theme_get_default (),

                                           "avatar-default",
                                           icon_size * scale,
                                           GTK_ICON_LOOKUP_FORCE_SIZE,
                                           &error);
        if (error) {
                g_warning ("%s", error->message);
                g_error_free (error);
        }

 out:

        if (pixbuf != NULL && (style & UM_ICON_STYLE_FRAME)) {
                framed = frame_pixbuf (pixbuf, scale);
                if (framed != NULL) {
                        g_object_unref (pixbuf);
                        pixbuf = framed;
                }
        }

        if (pixbuf != NULL && (style & UM_ICON_STYLE_STATUS) && act_user_is_logged_in (user)) {
                framed = logged_in_pixbuf (pixbuf, scale);
                if (framed != NULL) {
                        g_object_unref (pixbuf);
                        pixbuf = framed;
                }
        }

        if (pixbuf != NULL) {
                surface = gdk_cairo_surface_create_from_pixbuf (pixbuf, scale, NULL);
                g_object_unref (pixbuf);
        }

        return surface;
}
Esempio n. 29
0
static cairo_surface_t *
ensure_surface_for_gicon (GtkIconHelper    *self,
                          GtkCssStyle      *style,
                          GtkTextDirection  dir,
                          gint              scale,
                          GIcon            *gicon)
{
  GtkIconHelperPrivate *priv = self->priv;
  GtkIconTheme *icon_theme;
  gint width, height;
  GtkIconInfo *info;
  GtkIconLookupFlags flags;
  cairo_surface_t *surface;
  GdkPixbuf *destination;
  gboolean symbolic;

  icon_theme = gtk_css_icon_theme_value_get_icon_theme
    (gtk_css_style_get_value (style, GTK_CSS_PROPERTY_ICON_THEME));
  flags = get_icon_lookup_flags (self, style, dir);

  ensure_icon_size (self, &width, &height);

  info = gtk_icon_theme_lookup_by_gicon_for_scale (icon_theme,
                                                   gicon,
                                                   MIN (width, height),
                                                   scale, flags);
  if (info)
    {
      symbolic = gtk_icon_info_is_symbolic (info);

      if (symbolic)
        {
          GdkRGBA fg, success_color, warning_color, error_color;

          gtk_icon_theme_lookup_symbolic_colors (style, &fg, &success_color, &warning_color, &error_color);

          destination = gtk_icon_info_load_symbolic (info,
                                                     &fg, &success_color,
                                                     &warning_color, &error_color,
                                                     NULL,
                                                     NULL);
        }
      else
        {
          destination = gtk_icon_info_load_icon (info, NULL);
        }

      g_object_unref (info);
    }
  else
    {
      destination = NULL;
    }

  if (destination == NULL)
    {
      destination = gtk_icon_theme_load_icon (icon_theme,
                                              "image-missing",
                                              width,
                                              flags | GTK_ICON_LOOKUP_USE_BUILTIN | GTK_ICON_LOOKUP_GENERIC_FALLBACK,
                                              NULL);
      /* We include this image as resource, so we always have it available or
       * the icontheme code is broken */
      g_assert (destination);
      symbolic = FALSE;
    }

  surface = gdk_cairo_surface_create_from_pixbuf (destination, scale, gtk_widget_get_window (gtk_css_gadget_get_owner (GTK_CSS_GADGET (self))));

  if (!symbolic)
    {
      GtkCssIconEffect icon_effect;

      icon_effect = _gtk_css_icon_effect_value_get (gtk_css_style_get_value (style, GTK_CSS_PROPERTY_ICON_EFFECT));
      gtk_css_icon_effect_apply (icon_effect, surface);
    }
  else
    {
      priv->rendered_surface_is_symbolic = TRUE;
    }

  g_object_unref (destination);

  return surface;
}