I've added Cairo graphics library support in cl-gtk2. I've gone the easy way by integrating with cl-cairo2.
The main use case for Cairo in Gtk+ is widget custom drawing. For this, in the expose-event
handler, the Cairo context is created on which the drawing is performed.
To create a drawing context a cl-gtk2-cairo:with-gdk-context
macro is used which creates and releases the Cairo context. Widget size is obtained with the gdk:drawable-get-size
function that returns the width and the height as multiple return values.
As a result, the expose-event
handler looks something like this:
(lambda (widget event)
(declare (ignore event))
(multiple-value-bind (w h) (gdk:drawable-get-size (widget-window widget))
(with-gdk-context (ctx (widget-window widget))
(with-context (ctx)
(rectangle 0 0 w h)
(set-source-rgb 1 1 1)
(fill-path)
nil))))
And here's a screenshot for the cl-gtk2-cairo-demo:demo
: