Package: gdk

VTable gdk:paintable-vtable

Declaration

(gobject:define-vtable ("GdkPaintable" paintable)
  (:skip parent-instance (:struct g:type-interface))
  ;; Methods of the GdkPaintable interface
  (snapshot (:void (paintable (g:object paintable))
                   (snapshot (g:object snapshot))
                   (width :double)
                   (height :double)))
  (get-current-image ((g:object paintable) (paintable (g:object paintable))))
  (get-flags (paintable-flags (paintable (g:object paintable))))
  (get-intrinsic-width (:int (paintable (g:object paintable))))
  (get-intrinsic-height (:int (paintable (g:object paintable))))
  (get-intrinsic-aspect-ratio (:double (paintable (g:object paintable)))))  

Values

snapshot
Virtual function called by the gdk:paintable-snapshot function. You must implement the gdk:paintable-snapshot-impl method, when subclassing from the gdk:paintable interface.
get-current-image
Virtual function called by the gdk:paintable-current-image function. You must implement the gdk:paintable-get-current-image-impl method, when subclassing from the gdk:paintable interface.
get-flags
Virtual function called by the gdk:paintable-flags function. You must implement the gdk:paintable-get-flags-impl method, when subclassing from the gdk:paintable interface.
get-intrinsic-width
Virtual function called by the gdk:paintable-intrinsic-width function. You must implement the gdk:paintable-get-intrinsic-width-impl method, when subclassing from the gdk:paintable interface.
get-intrinsic-height
Virtual function called by the gdk:paintable-intrinsic-height function. You must implement the gdk:paintable-get-intrinsic-height-impl method, when subclassing from the gdk:paintable interface.
get-intrinsic-aspect-ratio-impl
Virtual function called by the gdk:paintable-intrinsic-aspect-ratio function. You must implement the gdk:paintable-get-intrinsic-aspect-ratio-impl method, when subclassing from the gdk:paintable interface.

Details

The list of functions that can be implemented for the gdk:paintable interface.

Note that apart from the gdk:paintable-snapshot-impl method, no method of this interface is mandatory to implement, though it is a good idea to implement the gdk:paintable-get-current-image-impl method for non-static paintables and the gdk:paintable-get-flags-impl method if the paintable is not dynamic as the default implementation returns no flags and that will make the implementation likely quite slow.

Examples

This is a complete example for the implementation of a subclass which implements the gdk:paintable interface.
;; Implementation of a NUCLEAR-ICON subclass
(gobject:define-gobject-subclass "NuclearIcon" nuclear-icon
  (:superclass g:object
   :export t
   :interfaces ("GdkPaintable"))
  ((rotation
    nuclear-icon-rotation
    "rotation" "gdouble" t t)))

;; This is the function that draws the actual icon (defun nuclear-snapshot (snapshot foreground background width height rotation) (let ((size (min width height)) (radius 0.3) (cr nil)) (graphene:with-rects ((rect1 0 0 width height) (rect2 (/ (- width size) 2.0) (/ (- height size) 2.0) size size)) (gtk:snapshot-append-color snapshot background rect1) (setf cr (gtk:snapshot-append-cairo snapshot rect2)) (cairo-set-source-rgba cr foreground) (cairo:translate cr (/ width 2.0) (/ height 2.0)) (cairo:scale cr size size) (cairo:rotate cr rotation) (cairo:arc cr 0 0 0.1 (- pi) pi) (cairo:fill cr) (setf (cairo:line-width cr) radius) (setf (cairo:dash cr 0.0) (list (/ (* radius pi) 3))) (cairo:arc cr 0 0 radius (- pi) pi) (cairo:stroke cr) (cairo:destroy cr))))

;; Here, we implement the methods required by the GdkPaintable interface (defmethod paintable-snapshot-impl ((paintable nuclear-icon) snapshot width height) (nuclear-snapshot snapshot (rgba-new :red 0 :green 0 :blue 0 :alpha 1) (rgba-new :red 0.9 :green 0.75 :blue 0.15 :alpha 1) width height (nuclear-icon-rotation paintable)))

(defmethod paintable-get-flags-impl ((paintable nuclear-icon)) (list :static-contents :static-size))
 

See also

2025-05-09