2.3 <GdkPaintable>

Interface: <GdkPaintable>

An interface for 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 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 paintable:invalidate-contents which will emit the paintable:invalidate-contents signal. If a paintable is known to never change its contents, it will set the static-contents flag. If a consumer cannot deal with changing contents, it may call 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 paintable:invalidate-size which will emit the paintable:invalidate-size signal. And just like for contents, if a paintable is known to never change its size, it will set the 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: paintable:invalidate-contents, paintable:invalidate-size, paintable:new-empty.

Procedures

Method: paintable:compute-concrete-size self specified-width specified-height default-width default-height ⇒ concrete-width concrete-height
Method: compute-concrete-size self specified-width specified-height default-width default-height ⇒ concrete-width concrete-height

Compute a concrete size for the <GdkPaintable>.

Applies the sizing algorithm outlined in the CSS Image spec to the given self. 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.

self

Passed: a <GdkPaintable>.

a <GdkPaintable>

specified-width

Passed: a real number.

the width self could be drawn into or 0.0 if unknown

specified-height

Passed: a real number.

the height self could be drawn into or 0.0 if unknown

default-width

Passed: a real number.

the width self would be drawn into if no other constraints were given

default-height

Passed: a real number.

the height self would be drawn into if no other constraints were given

concrete-width

Returned: a real number.

will be set to the concrete width computed

concrete-height

Returned: a real number.

will be set to the concrete height computed

Method: paintable:get-current-image self ⇒ %return
Method: get-current-image self ⇒ %return

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

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 self is already immutable, it will return itself.

self

Passed: a <GdkPaintable>.

a <GdkPaintable>

%return

Returned: a <GdkPaintable>.

An immutable paintable for the current contents of self

Method: paintable:get-flags self ⇒ %return
Method: get-flags self ⇒ %return

Get flags for the paintable.

This is oftentimes useful for optimizations.

See <GdkPaintableFlags> for the flags and what they mean.

self

Passed: a <GdkPaintable>.

a <GdkPaintable>

%return

Returned: a <GdkPaintableFlags>.

The <GdkPaintableFlags> for this paintable

Method: paintable:get-intrinsic-aspect-ratio self ⇒ %return
Method: get-intrinsic-aspect-ratio self ⇒ %return

Gets the preferred aspect ratio the self 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 self 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 paintable:snapshot.

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

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

self

Passed: a <GdkPaintable>.

a <GdkPaintable>

%return

Returned: a real number.

the intrinsic aspect ratio of self or 0 if none.

Method: paintable:get-intrinsic-height self ⇒ %return
Method: get-intrinsic-height self ⇒ %return

Gets the preferred height the self 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 paintable:snapshot.

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

self

Passed: a <GdkPaintable>.

a <GdkPaintable>

%return

Returned: a 32-bit integer.

the intrinsic height of self or 0 if none.

Method: paintable:get-intrinsic-width self ⇒ %return
Method: get-intrinsic-width self ⇒ %return

Gets the preferred width the self 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 paintable:snapshot.

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

self

Passed: a <GdkPaintable>.

a <GdkPaintable>

%return

Returned: a 32-bit integer.

the intrinsic width of self or 0 if none.

Method: paintable:invalidate-contents self
Method: invalidate-contents self

Called by implementations of <GdkPaintable> to invalidate their contents.

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

This function will emit the paintable:invalidate-contents signal.

If a self reports the static-contents flag, it must not call this function.

self

Passed: a <GdkPaintable>.

a <GdkPaintable>

Method: paintable:invalidate-size self
Method: invalidate-size self

Called by implementations of <GdkPaintable> to invalidate their size.

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

This function will emit the paintable:invalidate-size signal.

If a self reports the static-size flag, it must not call this function.

self

Passed: a <GdkPaintable>.

a <GdkPaintable>

Procedure: paintable:new-empty intrinsic-width intrinsic-height ⇒ %return

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

This is often useful for implementing the paintable:do-get-current-image virtual function when the paintable is in an incomplete state (like a GtkMediaStream before receiving the first frame).

intrinsic-width

Passed: a 32-bit integer.

The intrinsic width to report. Can be 0 for no width.

intrinsic-height

Passed: a 32-bit integer.

The intrinsic height to report. Can be 0 for no height.

%return

Returned: a <GdkPaintable>.

a <GdkPaintable>

Method: paintable:snapshot self snapshot width height
Method: snapshot self snapshot width height

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.

self

Passed: a <GdkPaintable>.

a <GdkPaintable>

snapshot

Passed: a <GdkSnapshot>.

a <GdkSnapshot> to snapshot to

width

Passed: a real number.

width to snapshot in

height

Passed: a real number.

height to snapshot in

Signals

Signal: paintable:invalidate-contents

Connect a handler with (connect object paintable:invalidate-contents handler). It is called as (handler self).

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.

self

Passed: a <GdkPaintable>.

Signal: paintable:invalidate-size

Connect a handler with (connect object paintable:invalidate-size handler). It is called as (handler self).

Emitted when the intrinsic size of the paintable changes.

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

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

self

Passed: a <GdkPaintable>.

Virtual methods

Virtual method: paintable:do-get-current-image implementor self ⇒ %return

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

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 self is already immutable, it will return itself.

To override it in a new class, give register-type #:vfuncs `((get-current-image . ,procedure)). The procedure is called as (procedure self) ⇒ %return.

implementor

Passed: the class whose implementation to call: a class that implements <GdkPaintable>, or its GType number.

self

Passed: a <GdkPaintable>.

a <GdkPaintable>

%return

Returned: a <GdkPaintable>.

An immutable paintable for the current contents of self

Virtual method: paintable:do-get-flags implementor self ⇒ %return

Get flags for the paintable.

This is oftentimes useful for optimizations.

See <GdkPaintableFlags> for the flags and what they mean.

To override it in a new class, give register-type #:vfuncs `((get-flags . ,procedure)). The procedure is called as (procedure self) ⇒ %return.

implementor

Passed: the class whose implementation to call: a class that implements <GdkPaintable>, or its GType number.

self

Passed: a <GdkPaintable>.

a <GdkPaintable>

%return

Returned: a <GdkPaintableFlags>.

The <GdkPaintableFlags> for this paintable

Virtual method: paintable:do-get-intrinsic-aspect-ratio implementor self ⇒ %return

Gets the preferred aspect ratio the self 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 self 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 paintable:snapshot.

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

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

To override it in a new class, give register-type #:vfuncs `((get-intrinsic-aspect-ratio . ,procedure)). The procedure is called as (procedure self) ⇒ %return.

implementor

Passed: the class whose implementation to call: a class that implements <GdkPaintable>, or its GType number.

self

Passed: a <GdkPaintable>.

a <GdkPaintable>

%return

Returned: a real number.

the intrinsic aspect ratio of self or 0 if none.

Virtual method: paintable:do-get-intrinsic-height implementor self ⇒ %return

Gets the preferred height the self 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 paintable:snapshot.

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

To override it in a new class, give register-type #:vfuncs `((get-intrinsic-height . ,procedure)). The procedure is called as (procedure self) ⇒ %return.

implementor

Passed: the class whose implementation to call: a class that implements <GdkPaintable>, or its GType number.

self

Passed: a <GdkPaintable>.

a <GdkPaintable>

%return

Returned: a 32-bit integer.

the intrinsic height of self or 0 if none.

Virtual method: paintable:do-get-intrinsic-width implementor self ⇒ %return

Gets the preferred width the self 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 paintable:snapshot.

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

To override it in a new class, give register-type #:vfuncs `((get-intrinsic-width . ,procedure)). The procedure is called as (procedure self) ⇒ %return.

implementor

Passed: the class whose implementation to call: a class that implements <GdkPaintable>, or its GType number.

self

Passed: a <GdkPaintable>.

a <GdkPaintable>

%return

Returned: a 32-bit integer.

the intrinsic width of self or 0 if none.

Virtual method: paintable:do-snapshot implementor self snapshot width height

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.

To override it in a new class, give register-type #:vfuncs `((snapshot . ,procedure)). The procedure is called as (procedure self snapshot width height).

implementor

Passed: the class whose implementation to call: a class that implements <GdkPaintable>, or its GType number.

self

Passed: a <GdkPaintable>.

a <GdkPaintable>

snapshot

Passed: a <GdkSnapshot>.

a <GdkSnapshot> to snapshot to

width

Passed: a real number.

width to snapshot in

height

Passed: a real number.

height to snapshot in