About all my projects
Gnome::Gdk4::R-Paintable

Gnome::Gdk4::R-Paintable

Description

Gnome::Gdk4::R-Paintable is a simple interface used by GTK to represent content that can be painted.

The content of a Gnome::Gdk4::R-Paintable can be painted anywhere at any size without requiring any sort of layout. The interface is inspired by similar concepts elsewhere, such as [ClutterContent](https://developer.gnome.org/clutter/stable/ClutterContent.html), [HTML/CSS Paint Sources](https://www.w3.org/TR/css-images-4/#paint-source), or [SVG Paint Servers](https://www.w3.org/TR/SVG2/pservers.html).

A Gnome::Gdk4::R-Paintable can be snapshot at any time and size using .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 Gnome::Gdk4::R-Paintable and don't know what to do, it is suggested that you scale your paintable ignoring any potential aspect ratio.

The contents that a Gnome::Gdk4::R-Paintable 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 Gnome::Gdk4::R-Paintable will however always produce the same output for the same snapshot.

A Gnome::Gdk4::R-Paintable may change its contents, meaning that it will now produce a different output with the same snapshot. Once that happens, it will call .invalidate-contents() which will emit the [signal $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 .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 .invalidate-size() which will emit the [signal $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: .invalidate-contents(), .invalidate-size(), .Paintable.new-empty().

Methods

compute-concrete-size

Compute a concrete size for the Gnome::Gdk4::R-Paintable.

Applies the sizing algorithm outlined in the [CSS Image spec](https://drafts.csswg.org/css-images-3/#default-sizing) to the given $paintable. See that link for more details.

It is not necessary to call this function when both $specified-width and $specified-height are known, but it is useful to call this function in GtkWidget:measure implementations to compute the other dimension when only one dimension is given.

method compute-concrete-size ( Num() $specified-width, Num() $specified-height, Num() $default-width, Num() $default-height, Num() $concrete-width, Num() $concrete-height )
  • $specified-width; the width $paintable could be drawn into or 0.0 if unknown.

  • $specified-height; the height $paintable could be drawn into or 0.0 if unknown.

  • $default-width; the width $paintable would be drawn into if no other constraints were given.

  • $default-height; the height $paintable would be drawn into if no other constraints were given.

  • $concrete-width; (transfer ownership: full) will be set to the concrete width computed.

  • $concrete-height; (transfer ownership: full) will be set to the concrete height computed.

get-current-image

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

This is useful when you want to retain the current state of an animation, for example to take a screenshot of a running animation.

If the $paintable is already immutable, it will return itself.

method get-current-image (--> N-Object )

Return value; An immutable paintable for the current contents of $paintable.

get-flags

Get flags for the paintable.

This is oftentimes useful for optimizations.

See [flags $Gdk.PaintableFlags] for the flags and what they mean.

method get-flags (--> UInt )

Return value; The bit field GdkPaintableFlags defined in Gnome::Gdk4::T-paintable for this paintable.

get-intrinsic-aspect-ratio

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

The aspect ratio is the width divided by the height, so a value of 0.5 means that the $paintable prefers to be displayed twice as high as it is wide. Consumers of this interface can use this to preserve aspect ratio when displaying the paintable.

This is a purely informational value and does not in any way limit the values that may be passed to .snapshot().

Usually when a $paintable returns nonzero values from .get-intrinsic-width() and .get-intrinsic-height() the aspect ratio should conform to those values, though that is not required.

If the $paintable does not have a preferred aspect ratio, it returns 0. Negative values are never returned.

method get-intrinsic-aspect-ratio (--> Num )

Return value; the intrinsic aspect ratio of $paintable or 0 if none..

get-intrinsic-height

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

Consumers of this interface can use this to reserve enough space to draw the paintable.

This is a purely informational value and does not in any way limit the values that may be passed to .snapshot().

If the $paintable does not have a preferred height, it returns 0. Negative values are never returned.

method get-intrinsic-height (--> Int )

Return value; the intrinsic height of $paintable or 0 if none..

get-intrinsic-width

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

Consumers of this interface can use this to reserve enough space to draw the paintable.

This is a purely informational value and does not in any way limit the values that may be passed to .snapshot().

If the $paintable does not have a preferred width, it returns 0. Negative values are never returned.

method get-intrinsic-width (--> Int )

Return value; the intrinsic width of $paintable or 0 if none..

invalidate-contents

Called by implementations of Gnome::Gdk4::R-Paintable to invalidate their contents.

Unless the contents are invalidated, implementations must guarantee that multiple calls of .snapshot() produce the same output.

This function will emit the invalidate-contents signal.

If a $paintable reports the GDK_PAINTABLE_STATIC_CONTENTS flag, it must not call this function.

method invalidate-contents ( )

invalidate-size

Called by implementations of Gnome::Gdk4::R-Paintable to invalidate their size.

As long as the size is not invalidated, $paintable must return the same values for its intrinsic width, height and aspect ratio.

This function will emit the invalidate-size signal.

If a $paintable reports the GDK_PAINTABLE_STATIC_SIZE flag, it must not call this function.

method invalidate-size ( )

snapshot

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

The paintable is drawn at the current (0,0) offset of the $snapshot. If $width and $height are not larger than zero, this function will do nothing.

method snapshot ( N-Object() $snapshot, Num() $width, Num() $height )
  • $snapshot; a Gnome::Gdk4::Snapshot to snapshot to.

  • $width; width to snapshot in.

  • $height; height to snapshot in.

Functions

new-empty

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

This is often useful for implementing the [vfunc $Gdk.Paintable.get_current_image] virtual function when the paintable is in an incomplete state (like a Gnome::Gtk4::MediaStream before receiving the first frame).

method new-empty ( Int() $intrinsic-width, Int() $intrinsic-height --> N-Object )
  • $intrinsic-width; The intrinsic width to report. Can be 0 for no width..

  • $intrinsic-height; The intrinsic height to report. Can be 0 for no height..

Return value; a Gnome::Gdk4::R-Paintable.

Signals

invalidate-contents

Emitted when the contents of the $paintable change.

Examples for such an event would be videos changing to the next frame or the icon theme for an icon changing.

method handler (
  Int :$_handle_id,
  N-GObject :$_native-object,
  Gnome::Gdk4::Paintable :$_widget,
  *C<user>-options
)
  • $_handle_id; The registered event handler id.

  • $_native-object; The native object provided by the Raku object which registered this event. This a native Gnome::Gdk4::Paintable object.

  • $_widget; The object which registered the signal. User code may have left the object going out of scope.

  • user-options; A list of named arguments provided at the .register-signal() method from Gnome::GObject::Object.

invalidate-size

Emitted when the intrinsic size of the $paintable changes.

This means the values reported by at least one of .get-intrinsic-width(), .get-intrinsic-height() or .get-intrinsic-aspect-ratio() has changed.

Examples for such an event would be a paintable displaying the contents of a toplevel surface being resized.

method handler (
  Int :$_handle_id,
  N-GObject :$_native-object,
  Gnome::Gdk4::Paintable :$_widget,
  *C<user>-options
)
  • $_handle_id; The registered event handler id.

  • $_native-object; The native object provided by the Raku object which registered this event. This a native Gnome::Gdk4::Paintable object.

  • $_widget; The object which registered the signal. User code may have left the object going out of scope.

  • user-options; A list of named arguments provided at the .register-signal() method from Gnome::GObject::Object.