|
Packit |
1069cd |
/* gtk-clutter-texture.h
|
|
Packit |
1069cd |
*
|
|
Packit |
1069cd |
* Copyright (C) 2010 Intel Corp.
|
|
Packit |
1069cd |
*
|
|
Packit |
1069cd |
* This library is free software; you can redistribute it and/or
|
|
Packit |
1069cd |
* modify it under the terms of the GNU Lesser General Public
|
|
Packit |
1069cd |
* License as published by the Free Software Foundation; either
|
|
Packit |
1069cd |
* version 2 of the License, or (at your option) any later version.
|
|
Packit |
1069cd |
*
|
|
Packit |
1069cd |
* This library is distributed in the hope that it will be useful,
|
|
Packit |
1069cd |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
Packit |
1069cd |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
Packit |
1069cd |
* Lesser General Public License for more details.
|
|
Packit |
1069cd |
*
|
|
Packit |
1069cd |
* You should have received a copy of the GNU Lesser General Public
|
|
Packit |
1069cd |
* License along with this library. If not see <http://www.fsf.org/licensing>.
|
|
Packit |
1069cd |
*
|
|
Packit |
1069cd |
* Authors:
|
|
Packit |
1069cd |
* Emmanuele Bassi <ebassi@linux.intel.com>
|
|
Packit |
1069cd |
*/
|
|
Packit |
1069cd |
|
|
Packit |
1069cd |
/**
|
|
Packit |
1069cd |
* SECTION:gtk-clutter-texture
|
|
Packit |
1069cd |
* @Title: GtkClutterTexture
|
|
Packit |
1069cd |
* @Short_Description: A texture class using GTK+ image data types
|
|
Packit |
1069cd |
*
|
|
Packit |
1069cd |
* #GtkClutterTexture is a simple sub-class of #ClutterTexture that
|
|
Packit |
1069cd |
* integrates nicely with #GdkPixbuf, #GtkIconTheme and stock icons.
|
|
Packit |
1069cd |
*/
|
|
Packit |
1069cd |
|
|
Packit |
1069cd |
#include "config.h"
|
|
Packit |
1069cd |
|
|
Packit |
1069cd |
#include "gtk-clutter-texture.h"
|
|
Packit |
1069cd |
|
|
Packit |
1069cd |
#include <glib/gi18n-lib.h>
|
|
Packit |
1069cd |
|
|
Packit |
1069cd |
G_DEFINE_TYPE (GtkClutterTexture, gtk_clutter_texture, CLUTTER_TYPE_TEXTURE);
|
|
Packit |
1069cd |
|
|
Packit |
1069cd |
static void
|
|
Packit |
1069cd |
gtk_clutter_texture_class_init (GtkClutterTextureClass *klass)
|
|
Packit |
1069cd |
{
|
|
Packit |
1069cd |
}
|
|
Packit |
1069cd |
|
|
Packit |
1069cd |
static void
|
|
Packit |
1069cd |
gtk_clutter_texture_init (GtkClutterTexture *texture)
|
|
Packit |
1069cd |
{
|
|
Packit |
1069cd |
}
|
|
Packit |
1069cd |
|
|
Packit |
1069cd |
GQuark
|
|
Packit |
1069cd |
gtk_clutter_texture_error_quark (void)
|
|
Packit |
1069cd |
{
|
|
Packit |
1069cd |
return g_quark_from_static_string ("gtk-clutter-texture-error");
|
|
Packit |
1069cd |
}
|
|
Packit |
1069cd |
|
|
Packit |
1069cd |
/**
|
|
Packit |
1069cd |
* gtk_clutter_texture_new:
|
|
Packit |
1069cd |
*
|
|
Packit |
1069cd |
* Creates a new #GtkClutterTexture actor.
|
|
Packit |
1069cd |
*
|
|
Packit |
1069cd |
* Return value: the newly created #GtkClutterTexture
|
|
Packit |
1069cd |
* instance
|
|
Packit |
1069cd |
*
|
|
Packit |
1069cd |
* Since: 1.0
|
|
Packit |
1069cd |
*/
|
|
Packit |
1069cd |
ClutterActor *
|
|
Packit |
1069cd |
gtk_clutter_texture_new (void)
|
|
Packit |
1069cd |
{
|
|
Packit |
1069cd |
return g_object_new (GTK_CLUTTER_TYPE_TEXTURE, NULL);
|
|
Packit |
1069cd |
}
|
|
Packit |
1069cd |
|
|
Packit |
1069cd |
/**
|
|
Packit |
1069cd |
* gtk_clutter_texture_set_from_pixbuf:
|
|
Packit |
1069cd |
* @texture: a #GtkClutterTexture
|
|
Packit |
1069cd |
* @pixbuf: a #GdkPixbuf
|
|
Packit |
1069cd |
* @error: a return location for errors
|
|
Packit |
1069cd |
*
|
|
Packit |
1069cd |
* Sets the contents of @texture with a copy of @pixbuf.
|
|
Packit |
1069cd |
*
|
|
Packit |
1069cd |
* Return value: %TRUE on success, %FALSE on failure.
|
|
Packit |
1069cd |
*/
|
|
Packit |
1069cd |
gboolean
|
|
Packit |
1069cd |
gtk_clutter_texture_set_from_pixbuf (GtkClutterTexture *texture,
|
|
Packit |
1069cd |
GdkPixbuf *pixbuf,
|
|
Packit |
1069cd |
GError **error)
|
|
Packit |
1069cd |
{
|
|
Packit |
1069cd |
g_return_val_if_fail (GTK_CLUTTER_IS_TEXTURE (texture), FALSE);
|
|
Packit |
1069cd |
g_return_val_if_fail (GDK_IS_PIXBUF (pixbuf), FALSE);
|
|
Packit |
1069cd |
|
|
Packit |
1069cd |
return clutter_texture_set_from_rgb_data (CLUTTER_TEXTURE (texture),
|
|
Packit |
1069cd |
gdk_pixbuf_get_pixels (pixbuf),
|
|
Packit |
1069cd |
gdk_pixbuf_get_has_alpha (pixbuf),
|
|
Packit |
1069cd |
gdk_pixbuf_get_width (pixbuf),
|
|
Packit |
1069cd |
gdk_pixbuf_get_height (pixbuf),
|
|
Packit |
1069cd |
gdk_pixbuf_get_rowstride (pixbuf),
|
|
Packit |
1069cd |
gdk_pixbuf_get_has_alpha (pixbuf) ? 4 : 3,
|
|
Packit |
1069cd |
0,
|
|
Packit |
1069cd |
error);
|
|
Packit |
1069cd |
}
|
|
Packit |
1069cd |
|
|
Packit |
1069cd |
/**
|
|
Packit |
1069cd |
* gtk_clutter_texture_set_from_stock:
|
|
Packit |
1069cd |
* @texture: a #GtkClutterTexture
|
|
Packit |
1069cd |
* @widget: a #GtkWidget
|
|
Packit |
1069cd |
* @stock_id: the stock id of the icon
|
|
Packit |
1069cd |
* @icon_size: the size of the icon, or -1
|
|
Packit |
1069cd |
* @error: a return location for errors, or %NULL
|
|
Packit |
1069cd |
*
|
|
Packit |
1069cd |
* Sets the contents of @texture using the stock icon @stock_id, as
|
|
Packit |
1069cd |
* rendered by @widget.
|
|
Packit |
1069cd |
*
|
|
Packit |
1069cd |
* Return value: %TRUE on success, %FALSE on failure.
|
|
Packit |
1069cd |
*/
|
|
Packit |
1069cd |
gboolean
|
|
Packit |
1069cd |
gtk_clutter_texture_set_from_stock (GtkClutterTexture *texture,
|
|
Packit |
1069cd |
GtkWidget *widget,
|
|
Packit |
1069cd |
const gchar *stock_id,
|
|
Packit |
1069cd |
GtkIconSize icon_size,
|
|
Packit |
1069cd |
GError **error)
|
|
Packit |
1069cd |
{
|
|
Packit |
1069cd |
GdkPixbuf *pixbuf;
|
|
Packit |
1069cd |
gboolean returnval;
|
|
Packit |
1069cd |
|
|
Packit |
1069cd |
g_return_val_if_fail (GTK_CLUTTER_IS_TEXTURE (texture), FALSE);
|
|
Packit |
1069cd |
g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
|
|
Packit |
1069cd |
g_return_val_if_fail (stock_id != NULL, FALSE);
|
|
Packit |
1069cd |
g_return_val_if_fail ((icon_size > GTK_ICON_SIZE_INVALID) || (icon_size == -1), FALSE);
|
|
Packit |
1069cd |
|
|
Packit |
1069cd |
G_GNUC_BEGIN_IGNORE_DEPRECATIONS
|
|
Packit |
1069cd |
pixbuf = gtk_widget_render_icon_pixbuf (widget, stock_id, icon_size);
|
|
Packit |
1069cd |
G_GNUC_END_IGNORE_DEPRECATIONS
|
|
Packit |
1069cd |
|
|
Packit |
1069cd |
if (pixbuf == NULL)
|
|
Packit |
1069cd |
{
|
|
Packit |
1069cd |
g_set_error (error,
|
|
Packit |
1069cd |
GTK_CLUTTER_TEXTURE_ERROR,
|
|
Packit |
1069cd |
GTK_CLUTTER_TEXTURE_ERROR_INVALID_STOCK_ID,
|
|
Packit |
1069cd |
_("Stock ID '%s' not found"),
|
|
Packit |
1069cd |
stock_id);
|
|
Packit |
1069cd |
return FALSE;
|
|
Packit |
1069cd |
}
|
|
Packit |
1069cd |
|
|
Packit |
1069cd |
returnval = gtk_clutter_texture_set_from_pixbuf (texture, pixbuf, error);
|
|
Packit |
1069cd |
g_object_unref (pixbuf);
|
|
Packit |
1069cd |
|
|
Packit |
1069cd |
return returnval;
|
|
Packit |
1069cd |
}
|
|
Packit |
1069cd |
|
|
Packit |
1069cd |
/**
|
|
Packit |
1069cd |
* gtk_clutter_texture_set_from_icon_name:
|
|
Packit |
1069cd |
* @texture: a #GtkClutterTexture
|
|
Packit |
1069cd |
* @widget: (allow-none): a #GtkWidget or %NULL
|
|
Packit |
1069cd |
* @icon_name: the name of the icon
|
|
Packit |
1069cd |
* @icon_size: the icon size or -1
|
|
Packit |
1069cd |
* @error: a return location for errors, or %NULL
|
|
Packit |
1069cd |
*
|
|
Packit |
1069cd |
* Sets the contents of @texture using the @icon_name from the
|
|
Packit |
1069cd |
* current icon theme.
|
|
Packit |
1069cd |
*
|
|
Packit |
1069cd |
* Return value: %TRUE on success, %FALSE on failure
|
|
Packit |
1069cd |
*
|
|
Packit |
1069cd |
* Since: 1.0
|
|
Packit |
1069cd |
*/
|
|
Packit |
1069cd |
gboolean
|
|
Packit |
1069cd |
gtk_clutter_texture_set_from_icon_name (GtkClutterTexture *texture,
|
|
Packit |
1069cd |
GtkWidget *widget,
|
|
Packit |
1069cd |
const gchar *icon_name,
|
|
Packit |
1069cd |
GtkIconSize icon_size,
|
|
Packit |
1069cd |
GError **error)
|
|
Packit |
1069cd |
{
|
|
Packit |
1069cd |
GError *local_error = NULL;
|
|
Packit |
1069cd |
GtkSettings *settings;
|
|
Packit |
1069cd |
GtkIconTheme *icon_theme;
|
|
Packit |
1069cd |
gboolean returnval;
|
|
Packit |
1069cd |
gint width, height;
|
|
Packit |
1069cd |
GdkPixbuf *pixbuf;
|
|
Packit |
1069cd |
|
|
Packit |
1069cd |
g_return_val_if_fail (CLUTTER_IS_TEXTURE (texture), FALSE);
|
|
Packit |
1069cd |
g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
|
|
Packit |
1069cd |
g_return_val_if_fail (icon_name != NULL, FALSE);
|
|
Packit |
1069cd |
g_return_val_if_fail ((icon_size > GTK_ICON_SIZE_INVALID) || (icon_size == -1), FALSE);
|
|
Packit |
1069cd |
|
|
Packit |
1069cd |
if (widget && gtk_widget_has_screen (widget))
|
|
Packit |
1069cd |
{
|
|
Packit |
1069cd |
GdkScreen *screen;
|
|
Packit |
1069cd |
|
|
Packit |
1069cd |
screen = gtk_widget_get_screen (widget);
|
|
Packit |
1069cd |
settings = gtk_settings_get_for_screen (screen);
|
|
Packit |
1069cd |
icon_theme = gtk_icon_theme_get_for_screen (screen);
|
|
Packit |
1069cd |
}
|
|
Packit |
1069cd |
else
|
|
Packit |
1069cd |
{
|
|
Packit |
1069cd |
settings = gtk_settings_get_default ();
|
|
Packit |
1069cd |
icon_theme = gtk_icon_theme_get_default ();
|
|
Packit |
1069cd |
}
|
|
Packit |
1069cd |
|
|
Packit |
1069cd |
G_GNUC_BEGIN_IGNORE_DEPRECATIONS
|
|
Packit |
1069cd |
if (icon_size == -1 ||
|
|
Packit |
1069cd |
!gtk_icon_size_lookup_for_settings (settings, icon_size, &width, &height))
|
|
Packit |
1069cd |
{
|
|
Packit |
1069cd |
width = height = 48;
|
|
Packit |
1069cd |
}
|
|
Packit |
1069cd |
G_GNUC_END_IGNORE_DEPRECATIONS
|
|
Packit |
1069cd |
|
|
Packit |
1069cd |
pixbuf = gtk_icon_theme_load_icon (icon_theme,
|
|
Packit |
1069cd |
icon_name,
|
|
Packit |
1069cd |
MIN (width, height), 0,
|
|
Packit |
1069cd |
&local_error);
|
|
Packit |
1069cd |
if (local_error)
|
|
Packit |
1069cd |
{
|
|
Packit |
1069cd |
g_propagate_error (error, local_error);
|
|
Packit |
1069cd |
return FALSE;
|
|
Packit |
1069cd |
}
|
|
Packit |
1069cd |
|
|
Packit |
1069cd |
returnval = gtk_clutter_texture_set_from_pixbuf (texture, pixbuf, error);
|
|
Packit |
1069cd |
g_object_unref (pixbuf);
|
|
Packit |
1069cd |
|
|
Packit |
1069cd |
return returnval;
|
|
Packit |
1069cd |
}
|