コード例 #1
0
static GdkPixbuf *
impl_load_pixbuf_gicon (GIcon       *icon,
                        GtkIconInfo *info,
                        int          size,
                        GError     **error)
{
  int scaled_width, scaled_height;
  GdkPixbuf *pixbuf = gtk_icon_info_load_icon (info, error);
  int width, height;

  if (!pixbuf)
    return NULL;

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

  if (compute_pixbuf_scale (width,
                            height,
                            size, size,
                            &scaled_width, &scaled_height))
    {
      GdkPixbuf *scaled = gdk_pixbuf_scale_simple (pixbuf, width, height, GDK_INTERP_BILINEAR);
      g_object_unref (pixbuf);
      pixbuf = scaled;
    }
  return pixbuf;
}
コード例 #2
0
ファイル: st-texture-cache.c プロジェクト: joequant/Cinnamon
/**
 * on_image_size_prepared:
 * @pixbuf_loader: #GdkPixbufLoader loading the image
 * @width: the original width of the image
 * @height: the original height of the image
 * @data: pointer to the #Dimensions sructure containing available width and height for the image,
 *        available width or height can be -1 if the dimension is not limited
 *
 * Private function.
 *
 * Sets the size of the image being loaded to fit the available width and height dimensions,
 * but never scales up the image beyond its actual size.
 * Intended to be used as a callback for #GdkPixbufLoader "size-prepared" signal.
 */
static void
on_image_size_prepared (GdkPixbufLoader *pixbuf_loader,
                        gint             width,
                        gint             height,
                        gpointer         data)
{
  Dimensions *available_dimensions = data;
  int available_width = available_dimensions->width;
  int available_height = available_dimensions->height;
  int scaled_width;
  int scaled_height;
  int final_width = width;
  int final_height = height;


  if (compute_pixbuf_scale (width, height, available_width, available_height,
                            &scaled_width, &scaled_height)) {
    final_width = scaled_width;
    final_height = scaled_height;
  }

  final_width = (int)((double) final_width * active_scale);
  final_height = (int)((double) final_height * active_scale);
  gdk_pixbuf_loader_set_size (pixbuf_loader, final_width, final_height);
}
コード例 #3
0
static GdkPixbuf *
impl_load_pixbuf_gicon (GtkIconInfo  *info,
                        int           size,
                        StIconColors *colors,
                        GError      **error)
{
  int scaled_width, scaled_height;
  GdkPixbuf *pixbuf;
  int width, height;

  if (colors)
    {
      GdkRGBA foreground_color;
      GdkRGBA success_color;
      GdkRGBA warning_color;
      GdkRGBA error_color;

      rgba_from_clutter (&foreground_color, &colors->foreground);
      rgba_from_clutter (&success_color, &colors->success);
      rgba_from_clutter (&warning_color, &colors->warning);
      rgba_from_clutter (&error_color, &colors->error);

      pixbuf = gtk_icon_info_load_symbolic (info,
                                            &foreground_color, &success_color,
                                            &warning_color, &error_color,
                                            NULL, error);
    }
  else
    {
      pixbuf = gtk_icon_info_load_icon (info, error);
    }

  if (!pixbuf)
    return NULL;

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

  if (compute_pixbuf_scale (width,
                            height,
                            size, size,
                            &scaled_width, &scaled_height))
    {
      GdkPixbuf *scaled = gdk_pixbuf_scale_simple (pixbuf, width, height, GDK_INTERP_BILINEAR);
      g_object_unref (pixbuf);
      pixbuf = scaled;
    }
  return pixbuf;
}
コード例 #4
0
/**
 * on_image_size_prepared:
 * @pixbuf_loader: #GdkPixbufLoader loading the image
 * @width: the original width of the image
 * @height: the original height of the image
 * @data: pointer to the #Dimensions sructure containing available width and height for the image,
 *        available width or height can be -1 if the dimension is not limited
 *
 * Private function.
 *
 * Sets the size of the image being loaded to fit the available width and height dimensions,
 * but never scales up the image beyond its actual size.
 * Intended to be used as a callback for #GdkPixbufLoader "size-prepared" signal.
 */
static void
on_image_size_prepared (GdkPixbufLoader *pixbuf_loader,
                        gint             width,
                        gint             height,
                        gpointer         data)
{
  Dimensions *available_dimensions = data;
  int available_width = available_dimensions->width;
  int available_height = available_dimensions->height;
  int scaled_width;
  int scaled_height;

  if (compute_pixbuf_scale (width, height, available_width, available_height,
                            &scaled_width, &scaled_height))
    gdk_pixbuf_loader_set_size (pixbuf_loader, scaled_width, scaled_height);
}