texture: Add gdk_texture_new_from_file()
authorBenjamin Otte <otte@redhat.com>
Sat, 4 Nov 2017 14:08:25 +0000 (15:08 +0100)
committerBenjamin Otte <otte@redhat.com>
Sat, 4 Nov 2017 14:22:25 +0000 (15:22 +0100)
and gdk_texture_new_from_resource().

While doing set, turn all GDK_AVAILABLE_IN_3_90 into
GDK_AVAILABLE_IN_3_94 because that's now true after the renaming.

docs/reference/gdk/gdk4-sections.txt
gdk/gdktexture.c
gdk/gdktexture.h

index ebd74cdcefc52a67c2ea1c4c3ea2eb72bc000a68..d62d40ba837aba8a35688b0666e54d926d685c20 100644 (file)
@@ -810,6 +810,8 @@ gdk_owner_change_get_type
 gdk_texture_new_for_data
 gdk_texture_new_for_surface
 gdk_texture_new_for_pixbuf
+gdk_texture_new_from_resource
+gdk_texture_new_from_file
 gdk_texture_get_width
 gdk_texture_get_height
 gdk_texture_download
index 7614457d127b6413bf8ce87f68aa34f057d702a7..72f3fc7526739a0bd723bf61da4b989e3f24e7ac 100644 (file)
@@ -43,7 +43,7 @@
  *
  * The `GdkTexture` structure contains only private data.
  *
- * Since: 3.90
+ * Since: 3.94
  */
 
 enum {
@@ -159,7 +159,7 @@ gdk_texture_class_init (GdkTextureClass *klass)
    *
    * The width of the texture.
    *
-   * Since: 3.90
+   * Since: 3.94
    */
   properties[PROP_WIDTH] =
     g_param_spec_int ("width",
@@ -178,7 +178,7 @@ gdk_texture_class_init (GdkTextureClass *klass)
    *
    * The height of the texture.
    *
-   * Since: 3.90
+   * Since: 3.94
    */
   properties[PROP_HEIGHT] =
     g_param_spec_int ("height",
@@ -436,6 +436,79 @@ gdk_texture_new_for_pixbuf (GdkPixbuf *pixbuf)
   return GDK_TEXTURE (self);
 }
 
+/**
+ * gdk_texture_new_from_resource:
+ * @resource_path: the path of the resource file
+ *
+ * Creates a new texture by loading an image from a resource.
+ * The file format is detected automatically.
+ *
+ * It is a fatal error if @resource_path does not specify a valid
+ * image resource and the program will abort if that happens.
+ * If you are unsure about the validity of a resource, use
+ * gdk_texture_new_from_file() to load it.
+ *
+ * Return value: A newly-created texture
+ *
+ * Since: 3.94
+ */
+GdkTexture *
+gdk_texture_new_from_resource (const char *resource_path)
+{
+  GError *error = NULL;
+  GdkTexture *texture;
+  GdkPixbuf *pixbuf;
+
+  g_return_val_if_fail (resource_path != NULL, NULL);
+
+  pixbuf = gdk_pixbuf_new_from_resource (resource_path, &error);
+  if (pixbuf == NULL)
+    g_error ("Resource path %s is not a valid image: %s", resource_path, error->message);
+
+  texture = gdk_texture_new_for_pixbuf (pixbuf);
+  g_object_unref (pixbuf);
+
+  return texture;
+}
+
+/**
+ * gdk_pixbuf_new_from_file:
+ * @file: #GFile to load
+ * @error: Return location for an error
+ *
+ * Creates a new texture by loading an image from a file.  The file format is
+ * detected automatically. If %NULL is returned, then @error will be set.
+ *
+ * Return value: A newly-created #GdkTexture or %NULL if an error occured.
+ *
+ * Since: 3.94
+ **/
+GdkTexture *
+gdk_texture_new_from_file (GFile   *file,
+                           GError **error)
+{
+  GdkTexture *texture;
+  GdkPixbuf *pixbuf;
+  GInputStream *stream;
+
+  g_return_val_if_fail (G_IS_FILE (file), NULL);
+  g_return_val_if_fail (error == NULL || *error == NULL, NULL);
+
+  stream = G_INPUT_STREAM (g_file_read (file, NULL, error));
+  if (stream == NULL)
+    return NULL;
+
+  pixbuf = gdk_pixbuf_new_from_stream (stream, NULL, error);
+  g_object_unref (stream);
+  if (pixbuf == NULL)
+    return NULL;
+
+  texture = gdk_texture_new_for_pixbuf (pixbuf);
+  g_object_unref (pixbuf);
+
+  return texture;
+}
+
 /**
  * gdk_texture_get_width:
  * @texture: a #GdkTexture
@@ -444,7 +517,7 @@ gdk_texture_new_for_pixbuf (GdkPixbuf *pixbuf)
  *
  * Returns: the width of the #GdkTexture
  *
- * Since: 3.90
+ * Since: 3.94
  */
 int
 gdk_texture_get_width (GdkTexture *texture)
@@ -462,7 +535,7 @@ gdk_texture_get_width (GdkTexture *texture)
  *
  * Returns: the height of the #GdkTexture
  *
- * Since: 3.90
+ * Since: 3.94
  */
 int
 gdk_texture_get_height (GdkTexture *texture)
index 0ac7213ba15a66e4a55269cc2ddced0492e7fad5..7d61192adc51e16999691287c65341a58621edf2 100644 (file)
@@ -39,23 +39,28 @@ G_DEFINE_AUTOPTR_CLEANUP_FUNC(GdkTexture, g_object_unref)
 typedef struct _GdkTextureClass        GdkTextureClass;
 
 
-GDK_AVAILABLE_IN_3_90
-GType gdk_texture_get_type (void) G_GNUC_CONST;
+GDK_AVAILABLE_IN_3_94
+GType                   gdk_texture_get_type                   (void) G_GNUC_CONST;
 
-GDK_AVAILABLE_IN_3_90
+GDK_AVAILABLE_IN_3_94
 GdkTexture *            gdk_texture_new_for_data               (const guchar    *data,
                                                                 int              width,
                                                                 int              height,
                                                                 int              stride);
-GDK_AVAILABLE_IN_3_90
+GDK_AVAILABLE_IN_3_94
 GdkTexture *            gdk_texture_new_for_pixbuf             (GdkPixbuf       *pixbuf);
+GDK_AVAILABLE_IN_3_94
+GdkTexture *            gdk_texture_new_from_resource          (const char      *resource_path);
+GDK_AVAILABLE_IN_3_94
+GdkTexture *            gdk_texture_new_from_file              (GFile           *file,
+                                                                GError         **error);
 
-GDK_AVAILABLE_IN_3_90
+GDK_AVAILABLE_IN_3_94
 int                     gdk_texture_get_width                  (GdkTexture      *texture);
-GDK_AVAILABLE_IN_3_90
+GDK_AVAILABLE_IN_3_94
 int                     gdk_texture_get_height                 (GdkTexture      *texture);
 
-GDK_AVAILABLE_IN_3_90
+GDK_AVAILABLE_IN_3_94
 void                    gdk_texture_download                   (GdkTexture      *texture,
                                                                 guchar          *data,
                                                                 gsize            stride);