GtkImage: Add new_from_surface() and set_from_surface()
This commit is contained in:
@ -26,6 +26,7 @@
|
|||||||
|
|
||||||
#include <math.h>
|
#include <math.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
#include <cairo-gobject.h>
|
||||||
|
|
||||||
#include "gtkcontainer.h"
|
#include "gtkcontainer.h"
|
||||||
#include "gtkiconhelperprivate.h"
|
#include "gtkiconhelperprivate.h"
|
||||||
@ -185,6 +186,7 @@ enum
|
|||||||
{
|
{
|
||||||
PROP_0,
|
PROP_0,
|
||||||
PROP_PIXBUF,
|
PROP_PIXBUF,
|
||||||
|
PROP_SURFACE,
|
||||||
PROP_FILE,
|
PROP_FILE,
|
||||||
PROP_STOCK,
|
PROP_STOCK,
|
||||||
PROP_ICON_SET,
|
PROP_ICON_SET,
|
||||||
@ -231,6 +233,14 @@ gtk_image_class_init (GtkImageClass *class)
|
|||||||
GDK_TYPE_PIXBUF,
|
GDK_TYPE_PIXBUF,
|
||||||
GTK_PARAM_READWRITE));
|
GTK_PARAM_READWRITE));
|
||||||
|
|
||||||
|
g_object_class_install_property (gobject_class,
|
||||||
|
PROP_SURFACE,
|
||||||
|
g_param_spec_boxed ("surface",
|
||||||
|
P_("Surface"),
|
||||||
|
P_("A cairo_surface_t to display"),
|
||||||
|
CAIRO_GOBJECT_TYPE_SURFACE,
|
||||||
|
GTK_PARAM_READWRITE));
|
||||||
|
|
||||||
g_object_class_install_property (gobject_class,
|
g_object_class_install_property (gobject_class,
|
||||||
PROP_FILE,
|
PROP_FILE,
|
||||||
g_param_spec_string ("file",
|
g_param_spec_string ("file",
|
||||||
@ -430,6 +440,10 @@ gtk_image_set_property (GObject *object,
|
|||||||
gtk_image_set_from_pixbuf (image,
|
gtk_image_set_from_pixbuf (image,
|
||||||
g_value_get_object (value));
|
g_value_get_object (value));
|
||||||
break;
|
break;
|
||||||
|
case PROP_SURFACE:
|
||||||
|
gtk_image_set_from_surface (image,
|
||||||
|
g_value_get_boxed (value));
|
||||||
|
break;
|
||||||
case PROP_FILE:
|
case PROP_FILE:
|
||||||
gtk_image_set_from_file (image, g_value_get_string (value));
|
gtk_image_set_from_file (image, g_value_get_string (value));
|
||||||
break;
|
break;
|
||||||
@ -491,6 +505,9 @@ gtk_image_get_property (GObject *object,
|
|||||||
case PROP_PIXBUF:
|
case PROP_PIXBUF:
|
||||||
g_value_set_object (value, _gtk_icon_helper_peek_pixbuf (priv->icon_helper));
|
g_value_set_object (value, _gtk_icon_helper_peek_pixbuf (priv->icon_helper));
|
||||||
break;
|
break;
|
||||||
|
case PROP_SURFACE:
|
||||||
|
g_value_set_boxed (value, _gtk_icon_helper_peek_surface (priv->icon_helper));
|
||||||
|
break;
|
||||||
case PROP_FILE:
|
case PROP_FILE:
|
||||||
g_value_set_string (value, priv->filename);
|
g_value_set_string (value, priv->filename);
|
||||||
break;
|
break;
|
||||||
@ -632,6 +649,29 @@ gtk_image_new_from_pixbuf (GdkPixbuf *pixbuf)
|
|||||||
return GTK_WIDGET (image);
|
return GTK_WIDGET (image);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* gtk_image_new_from_surface:
|
||||||
|
* @surface: (allow-none): a #cairo_surface_t, or %NULL
|
||||||
|
*
|
||||||
|
* Creates a new #GtkImage displaying @surface.
|
||||||
|
* The #GtkImage does not assume a reference to the
|
||||||
|
* surface; you still need to unref it if you own references.
|
||||||
|
* #GtkImage will add its own reference rather than adopting yours.
|
||||||
|
*
|
||||||
|
* Return value: a new #GtkImage
|
||||||
|
**/
|
||||||
|
GtkWidget*
|
||||||
|
gtk_image_new_from_surface (cairo_surface_t *surface)
|
||||||
|
{
|
||||||
|
GtkImage *image;
|
||||||
|
|
||||||
|
image = g_object_new (GTK_TYPE_IMAGE, NULL);
|
||||||
|
|
||||||
|
gtk_image_set_from_surface (image, surface);
|
||||||
|
|
||||||
|
return GTK_WIDGET (image);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* gtk_image_new_from_stock:
|
* gtk_image_new_from_stock:
|
||||||
* @stock_id: a stock icon name
|
* @stock_id: a stock icon name
|
||||||
@ -1128,6 +1168,43 @@ gtk_image_set_from_gicon (GtkImage *image,
|
|||||||
g_object_thaw_notify (G_OBJECT (image));
|
g_object_thaw_notify (G_OBJECT (image));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* gtk_image_set_from_surface:
|
||||||
|
* @image: a #GtkImage
|
||||||
|
* @surface: a cairo_surface_t
|
||||||
|
*
|
||||||
|
* See gtk_image_new_from_surface() for details.
|
||||||
|
*
|
||||||
|
* Since: 3.10
|
||||||
|
**/
|
||||||
|
void
|
||||||
|
gtk_image_set_from_surface (GtkImage *image,
|
||||||
|
cairo_surface_t *surface)
|
||||||
|
{
|
||||||
|
GtkImagePrivate *priv;
|
||||||
|
|
||||||
|
g_return_if_fail (GTK_IS_IMAGE (image));
|
||||||
|
|
||||||
|
priv = image->priv;
|
||||||
|
|
||||||
|
g_object_freeze_notify (G_OBJECT (image));
|
||||||
|
|
||||||
|
if (surface)
|
||||||
|
cairo_surface_reference (surface);
|
||||||
|
|
||||||
|
gtk_image_clear (image);
|
||||||
|
|
||||||
|
if (surface)
|
||||||
|
{
|
||||||
|
_gtk_icon_helper_set_surface (priv->icon_helper, surface);
|
||||||
|
cairo_surface_destroy (surface);
|
||||||
|
}
|
||||||
|
|
||||||
|
g_object_notify (G_OBJECT (image), "surface");
|
||||||
|
|
||||||
|
g_object_thaw_notify (G_OBJECT (image));
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* gtk_image_get_storage_type:
|
* gtk_image_get_storage_type:
|
||||||
* @image: a #GtkImage
|
* @image: a #GtkImage
|
||||||
|
|||||||
@ -133,6 +133,8 @@ GtkWidget* gtk_image_new_from_icon_name (const gchar *icon_name,
|
|||||||
GDK_AVAILABLE_IN_ALL
|
GDK_AVAILABLE_IN_ALL
|
||||||
GtkWidget* gtk_image_new_from_gicon (GIcon *icon,
|
GtkWidget* gtk_image_new_from_gicon (GIcon *icon,
|
||||||
GtkIconSize size);
|
GtkIconSize size);
|
||||||
|
GDK_AVAILABLE_IN_3_10
|
||||||
|
GtkWidget* gtk_image_new_from_surface (cairo_surface_t *surface);
|
||||||
|
|
||||||
GDK_AVAILABLE_IN_ALL
|
GDK_AVAILABLE_IN_ALL
|
||||||
void gtk_image_clear (GtkImage *image);
|
void gtk_image_clear (GtkImage *image);
|
||||||
@ -164,6 +166,9 @@ GDK_AVAILABLE_IN_ALL
|
|||||||
void gtk_image_set_from_gicon (GtkImage *image,
|
void gtk_image_set_from_gicon (GtkImage *image,
|
||||||
GIcon *icon,
|
GIcon *icon,
|
||||||
GtkIconSize size);
|
GtkIconSize size);
|
||||||
|
GDK_AVAILABLE_IN_3_10
|
||||||
|
void gtk_image_set_from_surface (GtkImage *image,
|
||||||
|
cairo_surface_t *surface);
|
||||||
GDK_AVAILABLE_IN_ALL
|
GDK_AVAILABLE_IN_ALL
|
||||||
void gtk_image_set_pixel_size (GtkImage *image,
|
void gtk_image_set_pixel_size (GtkImage *image,
|
||||||
gint pixel_size);
|
gint pixel_size);
|
||||||
|
|||||||
Reference in New Issue
Block a user