예제 #1
0
static void
render_image (UmUserImage *image)
{
        cairo_surface_t *surface;
        gint scale, pixel_size;

        if (image->priv->user == NULL)
                return;

        pixel_size = gtk_image_get_pixel_size (GTK_IMAGE (image));
        scale = gtk_widget_get_scale_factor (GTK_WIDGET (image));
        surface = render_user_icon (image->priv->user,
                                    UM_ICON_STYLE_NONE,
                                    pixel_size > 0 ? pixel_size : 48,
                                    scale);
        gtk_image_set_from_surface (GTK_IMAGE (image), surface);
        cairo_surface_destroy (surface);
}
예제 #2
0
파일: gbimage.c 프로젝트: jubalh/deadbeef
/*
 * Writes the source code needed to create this widget.
 * You have to output everything necessary to create the widget here, though
 * there are some convenience functions to help.
 */
static void
gb_image_write_source (GtkWidget * widget, GbWidgetWriteSourceData * data)
{
  /* For GNOME projects menuitem images are handled by the GnomeUIInfo
     structs, so we don't create source code here. */
  if (widget->parent && GTK_IS_IMAGE_MENU_ITEM (widget->parent)
      && glade_project_get_gnome_support (data->project))
    return;

  if (data->create_widget)
    {
      gchar *icon = gtk_object_get_data (GTK_OBJECT (widget), GladeIconKey);
      const gchar *icon_size = "GTK_ICON_SIZE_BUTTON";
      GtkImageType storage_type;
      gint i;

      for (i = 0; i < GladeIconSizeChoicesSize; i++)
	{
	  if (GladeIconSizeValues[i] == GTK_IMAGE (widget)->icon_size)
	    {
	      icon_size = GladeIconSizeSymbols[i];
	    }
	}

      storage_type = gtk_image_get_storage_type (GTK_IMAGE (widget));

      if (storage_type == GTK_IMAGE_ICON_NAME)
	{
	  gint pixel_size = gtk_image_get_pixel_size (GTK_IMAGE (widget));
	  gchar *icon_name;

	  g_object_get (widget,
			"icon_name", &icon_name,
			NULL);

	  source_add (data,
		      "  %s = gtk_image_new_from_icon_name (\"%s\", %s);\n",
		      data->wname, icon_name ? icon_name : "gtk-missing-image",
		      icon_size);

	  if (pixel_size > 0)
	    {
	      source_add (data,
			  "  gtk_image_set_pixel_size (%s, %i);\n",
			  data->wname, pixel_size);
	    }
	}
      else if (glade_util_check_is_stock_id (icon))
	{

	  source_add (data,
		      "  %s = gtk_image_new_from_stock (\"%s\", %s);\n",
		      data->wname, icon, icon_size);
	}
      else
	{
	  source_create_pixmap (data, data->wname, icon);
	}
    }

  gb_widget_write_standard_source (widget, data);

  if (fabs (GTK_MISC (widget)->xalign - 0.5) > 0.0001
      || fabs (GTK_MISC (widget)->yalign - 0.5) > 0.0001)
    source_add (data, "  gtk_misc_set_alignment (GTK_MISC (%s), %g, %g);\n",
	 data->wname, GTK_MISC (widget)->xalign, GTK_MISC (widget)->yalign);

  if (GTK_MISC (widget)->xpad != 0 || GTK_MISC (widget)->ypad != 0)
    source_add (data, "  gtk_misc_set_padding (GTK_MISC (%s), %i, %i);\n",
	     data->wname, GTK_MISC (widget)->xpad, GTK_MISC (widget)->ypad);
}
예제 #3
0
파일: gbimage.c 프로젝트: jubalh/deadbeef
/*
 * Gets the properties of the widget. This is used for both displaying the
 * properties in the property editor, and also for saving the properties.
 */
static void
gb_image_get_properties (GtkWidget * widget, GbWidgetGetArgData * data)
{
  gchar *icon = gtk_object_get_data (GTK_OBJECT (widget), GladeIconKey);
  gchar *icon_name = NULL;
  gboolean is_stock_icon, is_named_icon = FALSE;
  gint i, pixel_size;
  GtkImageType storage_type;

  storage_type = gtk_image_get_storage_type (GTK_IMAGE (widget));
  pixel_size = gtk_image_get_pixel_size (GTK_IMAGE (widget));

  is_stock_icon = glade_util_check_is_stock_id (icon);

  if (storage_type == GTK_IMAGE_ICON_NAME)
    {
      g_object_get (widget,
		    "icon_name", &icon_name,
		    NULL);
      if (icon_name && *icon_name)
	is_named_icon = TRUE;
    }

  if (data->action == GB_SAVING)
    {
      /* When saving we want to use "stock" or "pixbuf", depending on whether
	 it is a stock icon or an oridinary pixmap file. */
      if (is_stock_icon)
	gb_widget_output_icon (data, "stock", icon);
      else
	gb_widget_output_icon (data, "pixbuf", icon);
    }
  else
    {
      gb_widget_output_icon (data, Icon, icon);
    }

  if (is_stock_icon || is_named_icon)
    {
      if (data->action == GB_SHOWING)
	{
	  for (i = 0; i < GladeIconSizeChoicesSize; i++)
	    {
	      if (GladeIconSizeValues[i] == GTK_IMAGE (widget)->icon_size)
		gb_widget_output_choice (data, IconSize, i,
					 GladeIconSizeSymbols[i]);
	    }

	  check_visible_sizes (icon, is_named_icon);
	}
      else
	{
	  /* We have to save the size as an integer, which sucks a bit.
	     The integer is the GtkIconSize enum value, not the actual size.*/
	  if (is_stock_icon || pixel_size == -1)
	    gb_widget_output_int (data, IconSize,
				  GTK_IMAGE (widget)->icon_size);
	}
    }

  gb_widget_output_named_icon (data, IconName, icon_name);

  /* The icon size only applies to stock icons or named icons.
     The pixel size only applies to named icons. */
  if (data->action == GB_SHOWING)
    {
      property_set_sensitive (IconSize, is_stock_icon || is_named_icon);
      property_set_sensitive (PixelSize, is_named_icon);
    }

  /* We only want to save the pixel size for named icons, and only if it is
     not -1. */
  if (data->action == GB_SHOWING
      || (storage_type == GTK_IMAGE_ICON_NAME && pixel_size != -1))
    gb_widget_output_int (data, PixelSize, pixel_size);

  gb_widget_output_float (data, XAlign, GTK_MISC (widget)->xalign);
  gb_widget_output_float (data, YAlign, GTK_MISC (widget)->yalign);
  gb_widget_output_int (data, XPad, GTK_MISC (widget)->xpad);
  gb_widget_output_int (data, YPad, GTK_MISC (widget)->ypad);
}