Gdk.Paintable
Description: Reference for Gdk.Paintable

### Interface

# GdkPaintable

since: 4.0

#### Description [src]

    interface Gdk.Paintable : GObject.Object

`GdkPaintable` is a simple interface used by GTK to represent content that can be painted.

The content of a `GdkPaintable` can be painted anywhere at any size without requiring any sort of layout. The interface is inspired by similar concepts elsewhere, such as ClutterContent, HTML/CSS Paint Sources, or SVG Paint Servers.

A `GdkPaintable` can be snapshot at any time and size using `gdk_paintable_snapshot()`. How the paintable interprets that size and if it scales or centers itself into the given rectangle is implementation defined, though if you are implementing a `GdkPaintable` and don’t know what to do, it is suggested that you scale your paintable ignoring any potential aspect ratio.

The contents that a `GdkPaintable` produces may depend on the `GdkSnapshot` passed to it. For example, paintables may decide to use more detailed images on higher resolution screens or when OpenGL is available. A `GdkPaintable` will however always produce the same output for the same snapshot.

A `GdkPaintable` may change its contents, meaning that it will now produce a different output with the same snapshot. Once that happens, it will call `gdk_paintable_invalidate_contents()` which will emit the `GdkPaintable::invalidate-contents` signal. If a paintable is known to never change its contents, it will set the `GDK_PAINTABLE_STATIC_CONTENTS` flag. If a consumer cannot deal with changing contents, it may call `gdk_paintable_get_current_image()` which will return a static paintable and use that.

A paintable can report an intrinsic (or preferred) size or aspect ratio it wishes to be rendered at, though it doesn’t have to. Consumers of the interface can use this information to layout thepaintable appropriately. Just like the contents, the size of a paintable can change. A paintable will indicate this by calling `gdk_paintable_invalidate_size()` which will emit the `GdkPaintable::invalidate-size` signal. And just like for contents, if a paintable is known to never change its size, it will set the `GDK_PAINTABLE_STATIC_SIZE` flag.

Besides API for applications, there are some functions that are only useful for implementing subclasses and should not be used by applications: `gdk_paintable_invalidate_contents()`, `gdk_paintable_invalidate_size()`, `gdk_paintable_new_empty()`.

Available since: 4.0

#### Prerequisite

In order to implement Paintable, your type must inherit from`GObject`.

#### Implementations

- GdkDmabufTexture
- GdkGLTexture
- GdkMemoryTexture
- GdkTexture

#### Functions

###### gdk_paintable_new_empty

Returns a paintable that has the given intrinsic size and draws nothing.

since: 4.0

#### Instance methods

###### gdk_paintable_compute_concrete_size

Compute a concrete size for the `GdkPaintable`.

since: 4.0

###### gdk_paintable_get_current_image

Gets an immutable paintable for the current contents displayed by `paintable`.

since: 4.0

###### gdk_paintable_get_flags

Get flags for the paintable.

since: 4.0

###### gdk_paintable_get_intrinsic_aspect_ratio

Gets the preferred aspect ratio the `paintable` would like to be displayed at.

since: 4.0

###### gdk_paintable_get_intrinsic_height

Gets the preferred height the `paintable` would like to be displayed at.

since: 4.0

###### gdk_paintable_get_intrinsic_width

Gets the preferred width the `paintable` would like to be displayed at.

since: 4.0

###### gdk_paintable_invalidate_contents

Called by implementations of `GdkPaintable` to invalidate their contents.

since: 4.0

###### gdk_paintable_invalidate_size

Called by implementations of `GdkPaintable` to invalidate their size.

since: 4.0

###### gdk_paintable_snapshot

Snapshots the given paintable with the given `width` and `height`.

since: 4.0

#### Signals

###### Gdk.Paintable::invalidate-contents

Emitted when the contents of the `paintable` change.

since: 4.0

###### Gdk.Paintable::invalidate-size

Emitted when the intrinsic size of the `paintable` changes.

since: 4.0

#### Interface structure

    struct GdkPaintableInterface {
      void (* snapshot) (
        GdkPaintable* paintable,
        GdkSnapshot* snapshot,
        double width,
        double height
      );
      GdkPaintable* (* get_current_image) (
        GdkPaintable* paintable
      );
      GdkPaintableFlags (* get_flags) (
        GdkPaintable* paintable
      );
      int (* get_intrinsic_width) (
        GdkPaintable* paintable
      );
      int (* get_intrinsic_height) (
        GdkPaintable* paintable
      );
      double (* get_intrinsic_aspect_ratio) (
        GdkPaintable* paintable
      );

    }

The list of functions that can be implemented for the `GdkPaintable` interface.

Note that apart from the `Gdk.PaintableInterface.snapshot` function, no virtual function of this interface is mandatory to implement, though it is a good idea to implement `Gdk.PaintableInterface.get_current_image` for non-static paintables and `Gdk.PaintableInterface.get_flags` if the image is not dynamic as the default implementation returns no flags and that will make the implementation likely quite slow.

###### Interface members

`snapshot` |
    void (* snapshot) (
        GdkPaintable* paintable,
        GdkSnapshot* snapshot,
        double width,
        double height
      )
| Snapshot the paintable. The given `width` and `height` are guaranteed to be larger than 0.0. The resulting snapshot must modify only the area in the rectangle from (0,0) to (width, height). This is the only function that must be implemented for this interface.
`get_current_image` |
    GdkPaintable* (* get_current_image) (
        GdkPaintable* paintable
      )
| Return a `GdkPaintable` that does not change over time. This means the `GDK_PAINTABLE_STATIC_SIZE` and `GDK_PAINTABLE_STATIC_CONTENTS` flag are set.
`get_flags` |
    GdkPaintableFlags (* get_flags) (
        GdkPaintable* paintable
      )
| Get the flags for this instance. See `GdkPaintableFlags` for details.
`get_intrinsic_width` |
    int (* get_intrinsic_width) (
        GdkPaintable* paintable
      )
| The preferred width for this object to be snapshot at or 0 if none. This is purely a hint. The object must still be able to render at any size.
`get_intrinsic_height` |
    int (* get_intrinsic_height) (
        GdkPaintable* paintable
      )
| The preferred height for this object to be snapshot at or 0 if none. This is purely a hint. The object must still be able to render at any size.
`get_intrinsic_aspect_ratio` |
    double (* get_intrinsic_aspect_ratio) (
        GdkPaintable* paintable
      )
| The preferred aspect ratio for this object or 0 if none. If both `Gdk.PaintableInterface.get_intrinsic_width` and `Gdk.PaintableInterface.get_intrinsic_height` return non-zero values, this function should return the aspect ratio computed from those.

#### Virtual methods

###### Gdk.Paintable.get_current_image

Gets an immutable paintable for the current contents displayed by `paintable`.

since: 4.0

###### Gdk.Paintable.get_flags

Get flags for the paintable.

since: 4.0

###### Gdk.Paintable.get_intrinsic_aspect_ratio

Gets the preferred aspect ratio the `paintable` would like to be displayed at.

since: 4.0

###### Gdk.Paintable.get_intrinsic_height

Gets the preferred height the `paintable` would like to be displayed at.

since: 4.0

###### Gdk.Paintable.get_intrinsic_width

Gets the preferred width the `paintable` would like to be displayed at.

since: 4.0

###### Gdk.Paintable.snapshot

Snapshots the given paintable with the given `width` and `height`.

since: 4.0