Exemplo n.º 1
0
/* This function creates a background pattern from a named icon
 * if renderer->bg_icon_name is set.
 */
static cairo_pattern_t *
gimp_view_renderer_create_background (GimpViewRenderer *renderer,
                                      GtkWidget        *widget)
{
  cairo_pattern_t *pattern = NULL;

  if (renderer->bg_icon_name)
    {
      GdkPixbuf *pixbuf = gimp_widget_load_icon (widget,
                                                 renderer->bg_icon_name, 64);

      if (pixbuf)
        {
          cairo_surface_t *surface;

          surface = gimp_cairo_surface_create_from_pixbuf (pixbuf);

          g_object_unref (pixbuf);

          pattern = cairo_pattern_create_for_surface (surface);
          cairo_pattern_set_extend (pattern, CAIRO_EXTEND_REPEAT);

          cairo_surface_destroy (surface);
        }
    }

  return pattern;
}
Exemplo n.º 2
0
void
gimp_view_renderer_render_icon (GimpViewRenderer *renderer,
                                GtkWidget        *widget,
                                const gchar      *icon_name)
{
  GdkPixbuf *pixbuf;

  g_return_if_fail (GIMP_IS_VIEW_RENDERER (renderer));
  g_return_if_fail (GTK_IS_WIDGET (widget));
  g_return_if_fail (icon_name != NULL);

  if (renderer->pixbuf)
    {
      g_object_unref (renderer->pixbuf);
      renderer->pixbuf = NULL;
    }

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

  pixbuf = gimp_widget_load_icon (widget, icon_name,
                                  MIN (renderer->width, renderer->height));

  if (pixbuf)
    {
      gint  width  = gdk_pixbuf_get_width (pixbuf);
      gint  height = gdk_pixbuf_get_height (pixbuf);

      if (width > renderer->width || height > renderer->height)
        {
          GdkPixbuf *scaled_pixbuf;

          gimp_viewable_calc_preview_size (width, height,
                                           renderer->width, renderer->height,
                                           TRUE, 1.0, 1.0,
                                           &width, &height,
                                           NULL);

          scaled_pixbuf = gdk_pixbuf_scale_simple (pixbuf,
                                                   width, height,
                                                   GDK_INTERP_BILINEAR);

          g_object_unref (pixbuf);
          pixbuf = scaled_pixbuf;
        }

      renderer->pixbuf = pixbuf;
    }

  renderer->needs_render = FALSE;
}
Exemplo n.º 3
0
static gboolean
gimp_display_shell_icon_update_idle (gpointer data)
{
  GimpDisplayShell *shell = GIMP_DISPLAY_SHELL (data);
  GimpImage        *image = gimp_display_get_image (shell->display);
  GdkPixbuf        *icon  = NULL;

  shell->icon_idle_id = 0;

  if (image)
    {
      Gimp      *gimp = gimp_display_get_gimp (shell->display);
      GdkPixbuf *pixbuf;
      gint       width;
      gint       height;
      gint       scale_factor;
      gdouble    factor = ((gdouble) gimp_image_get_height (image) /
                           (gdouble) gimp_image_get_width  (image));

      if (factor >= 1)
        {
          height = MAX (shell->icon_size, 1);
          width  = MAX (((gdouble) shell->icon_size) / factor, 1);
        }
      else
        {
          height = MAX (((gdouble) shell->icon_size) * factor, 1);
          width  = MAX (shell->icon_size, 1);
        }

      scale_factor = gtk_widget_get_scale_factor (GTK_WIDGET (shell));
      width  *= scale_factor;
      height *= scale_factor;
      pixbuf = gimp_viewable_get_pixbuf (GIMP_VIEWABLE (image),
                                         gimp_get_user_context (gimp),
                                         width, height);

      icon = gdk_pixbuf_new (GDK_COLORSPACE_RGB, TRUE, 8,
                             shell->icon_size * scale_factor,
                             shell->icon_size * scale_factor);

      memset (gdk_pixbuf_get_pixels (icon), 0,
              gdk_pixbuf_get_height (icon) *
              gdk_pixbuf_get_rowstride (icon));

      gdk_pixbuf_copy_area (pixbuf, 0, 0, width, height,
                            icon,
                            0, shell->icon_size * scale_factor - height);

      pixbuf = gimp_widget_load_icon (GTK_WIDGET (shell), "gimp-wilber-outline",
                                      shell->icon_size_small);

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

      gdk_pixbuf_composite (pixbuf, icon,
                            shell->icon_size * scale_factor - width,
                            0, width, height,
                            shell->icon_size * scale_factor - width,
                            0.0, 1.0, 1.0,
                            GDK_INTERP_NEAREST, 255);
      g_object_unref (pixbuf);
    }

  g_object_set (shell, "icon", icon, NULL);

  if (icon)
    g_object_unref (icon);

  return FALSE;
}