gtkmm  4.0.0
Public Member Functions | Static Public Member Functions | Protected Member Functions | Related Functions | List of all members
Gdk::Texture Class Reference

Pixel data. More...

#include <gdkmm/texture.h>

Inheritance diagram for Gdk::Texture:
Inheritance graph
[legend]

Public Member Functions

 Texture (Texture&& src) noexcept
 
Textureoperator= (Texture&& src) noexcept
 
 ~Texture () noexcept override
 
GdkTexture* gobj ()
 Provides access to the underlying C GObject. More...
 
const GdkTexture* gobj () const
 Provides access to the underlying C GObject. More...
 
GdkTexture* gobj_copy ()
 Provides access to the underlying C instance. The caller is responsible for unrefing it. Use when directly setting fields in structs. More...
 
int get_width () const
 Returns the width of texture, in pixels. More...
 
int get_height () const
 Returns the height of the texture, in pixels. More...
 
void download (guchar* data, gsize stride) const
 Downloads the texture into local memory. More...
 
bool save_to_png (const Glib::ustring& filename) const
 Store the given texture to the filename as a PNG file. More...
 
Glib::PropertyProxy_ReadOnly< int > property_width () const
 The width of the texture, in pixels. More...
 
Glib::PropertyProxy_ReadOnly< int > property_height () const
 The height of the texture, in pixels. More...
 
- Public Member Functions inherited from Gdk::Paintable
 Paintable (Paintable&& src) noexcept
 
Paintableoperator= (Paintable&& src) noexcept
 
 ~Paintable () noexcept override
 
GdkPaintable* gobj ()
 Provides access to the underlying C GObject. More...
 
const GdkPaintable* gobj () const
 Provides access to the underlying C GObject. More...
 
void snapshot (const Glib::RefPtr< Gdk::Snapshot >& snapshot, double width, double height)
 Snapshots the given paintable with the given width and height at the current (0,0) offset of the snapshot. More...
 
Glib::RefPtr< const Paintableget_current_image () const
 Gets an immutable paintable for the current contents displayed by paintable. More...
 
Flags get_flags () const
 Get flags for the paintable. More...
 
int get_intrinsic_width () const
 Gets the preferred width the paintable would like to be displayed at. More...
 
int get_intrinsic_height () const
 Gets the preferred height the paintable would like to be displayed at. More...
 
double get_intrinsic_aspect_ratio () const
 Gets the preferred aspect ratio the paintable would like to be displayed at. More...
 
void compute_concrete_size (double specified_width, double specified_height, double default_width, double default_height, double& concrete_width, double& concrete_height) const
 Applies the sizing algorithm outlined in https://drafts.csswg.org/css-images-3/#default-sizing to the given paintable. More...
 
void invalidate_contents ()
 Called by implementations of Gdk::Paintable to invalidate their contents. More...
 
void invalidate_size ()
 Called by implementations of Gdk::Paintable to invalidate their size. More...
 
Glib::SignalProxy< void()> signal_invalidate_contents ()
 
Glib::SignalProxy< void()> signal_invalidate_size ()
 

Static Public Member Functions

static GType get_type ()
 Get the GType for this class, for use with the underlying GObject type system. More...
 
static Glib::RefPtr< Texturecreate_for_pixbuf (const Glib::RefPtr< Pixbuf >& pixbuf)
 Creates a new texture object representing the Gdk::Pixbuf. More...
 
static Glib::RefPtr< Texturecreate_from_resource (const std::string& resource_path)
 Creates a new texture by loading an image from a resource. More...
 
static Glib::RefPtr< Texturecreate_from_file (const Glib::RefPtr< Gio::File >& file)
 Creates a new texture by loading an image from a file. More...
 
- Static Public Member Functions inherited from Gdk::Paintable
static void add_interface (GType gtype_implementer)
 
static GType get_type ()
 Get the GType for this class, for use with the underlying GObject type system. More...
 

Protected Member Functions

 Texture ()
 
- Protected Member Functions inherited from Gdk::Paintable
 Paintable ()
 You should derive from this class to use it. More...
 
virtual void snapshot_vfunc (const Glib::RefPtr< Gdk::Snapshot >&snapshot, double width, double height)
 
virtual Glib::RefPtr< Paintableget_current_image_vfunc () const
 
virtual Flags get_flags_vfunc () const
 
virtual int get_intrinsic_width_vfunc () const
 
virtual int get_intrinsic_height_vfunc () const
 
virtual double get_intrinsic_aspect_ratio_vfunc () const
 

Related Functions

(Note that these are not member functions.)

Glib::RefPtr< Gdk::Texturewrap (GdkTexture* object, bool take_copy=false)
 A Glib::wrap() method for this object. More...
 

Additional Inherited Members

- Public Types inherited from Gdk::Paintable
enum  Flags {
  Flags::STATIC_SIZE = 1 << 0,
  Flags::STATIC_CONTENTS = 1 << 1
}
 Flags about this object. More...
 

Detailed Description

Pixel data.

Gdk::Texture is the basic element used to refer to pixel data. It is primarily meant for pixel data that will not change over multiple frames, and will be used for a long time.

There are various ways to create Gdk::Texture objects from a Gdk::Pixbuf, or a Cairo surface, or other pixel data.

The ownership of the pixel data is transferred to the Gdk::Texture instance; you can only make a copy of it, via download().

Gdk::Texture is an immutable object: That means you cannot change anything about it.

Since gtkmm 3.94:

Constructor & Destructor Documentation

◆ Texture() [1/2]

Gdk::Texture::Texture ( Texture&&  src)
noexcept

◆ ~Texture()

Gdk::Texture::~Texture ( )
overridenoexcept

◆ Texture() [2/2]

Gdk::Texture::Texture ( )
protected

Member Function Documentation

◆ create_for_pixbuf()

static Glib::RefPtr<Texture> Gdk::Texture::create_for_pixbuf ( const Glib::RefPtr< Pixbuf >&  pixbuf)
static

Creates a new texture object representing the Gdk::Pixbuf.

Parameters
pixbufA Gdk::Pixbuf.
Returns
A new Gdk::Texture.

◆ create_from_file()

static Glib::RefPtr<Texture> Gdk::Texture::create_from_file ( const Glib::RefPtr< Gio::File > &  file)
static

Creates a new texture by loading an image from a file.

The file format is detected automatically, and can be any format that is supported by the gdk-pixbuf library, such as JPEG or PNG.

If nullptr is returned, then error will be set.

Parameters
fileFile to load.
Returns
A newly-created Gdk::Texture or nullptr if an error occurred.
Exceptions
Glib::Error

◆ create_from_resource()

static Glib::RefPtr<Texture> Gdk::Texture::create_from_resource ( const std::string &  resource_path)
static

Creates a new texture by loading an image from a resource.

The file format is detected automatically, and can be any format that is supported by the gdk-pixbuf library, such as JPEG or PNG.

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 new_from_file() to load it.

Parameters
resource_pathThe path of the resource file.
Returns
A newly-created texture.

◆ download()

void Gdk::Texture::download ( guchar *  data,
gsize  stride 
) const

Downloads the texture into local memory.

This may be an expensive operation, as the actual texture data may reside on a GPU or on a remote display server.

The data format of the downloaded data is equivalent to Cairo::Surface::Format::ARGB32, so every downloaded pixel requires 4 bytes of memory.

Downloading a texture into a Cairo image surface:

[C example ellipted]

Parameters
dataPointer to enough memory to be filled with the downloaded data of texture.
strideRowstride in bytes.

◆ get_height()

int Gdk::Texture::get_height ( ) const

Returns the height of the texture, in pixels.

Returns
The height of the Gdk::Texture.

◆ get_type()

static GType Gdk::Texture::get_type ( )
static

Get the GType for this class, for use with the underlying GObject type system.

◆ get_width()

int Gdk::Texture::get_width ( ) const

Returns the width of texture, in pixels.

Returns
The width of the Gdk::Texture.

◆ gobj() [1/2]

GdkTexture* Gdk::Texture::gobj ( )
inline

Provides access to the underlying C GObject.

◆ gobj() [2/2]

const GdkTexture* Gdk::Texture::gobj ( ) const
inline

Provides access to the underlying C GObject.

◆ gobj_copy()

GdkTexture* Gdk::Texture::gobj_copy ( )

Provides access to the underlying C instance. The caller is responsible for unrefing it. Use when directly setting fields in structs.

◆ operator=()

Texture& Gdk::Texture::operator= ( Texture&&  src)
noexcept

◆ property_height()

Glib::PropertyProxy_ReadOnly< int > Gdk::Texture::property_height ( ) const

The height of the texture, in pixels.

Default value: 1

Returns
A PropertyProxy_ReadOnly that allows you to get the value of the property, or receive notification when the value of the property changes.

◆ property_width()

Glib::PropertyProxy_ReadOnly< int > Gdk::Texture::property_width ( ) const

The width of the texture, in pixels.

Default value: 1

Returns
A PropertyProxy_ReadOnly that allows you to get the value of the property, or receive notification when the value of the property changes.

◆ save_to_png()

bool Gdk::Texture::save_to_png ( const Glib::ustring &  filename) const

Store the given texture to the filename as a PNG file.

This is a utility function intended for debugging and testing. If you want more control over formats, proper error handling or want to store to a File or other location, you might want to look into using the gdk-pixbuf library.

Parameters
filenameThe filename to store to.
Returns
true if saving succeeded, false on failure.

Friends And Related Function Documentation

◆ wrap()

Glib::RefPtr< Gdk::Texture > wrap ( GdkTexture *  object,
bool  take_copy = false 
)
related

A Glib::wrap() method for this object.

Parameters
objectThe C instance.
take_copyFalse if the result should take ownership of the C instance. True if it should take a new copy or ref.
Returns
A C++ instance that wraps this C instance.