tpapp / cl-cairo2

Cairo bindings for Common Lisp

This URL has Read+Write access

cl-cairo2 / gtk-context.lisp
100644 38 lines (29 sloc) 1.444 kb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
(in-package :cl-cairo2)
 
 
;; library functions to create a gdk-surface
;; written by Peter Hildebrandt <peter.hildebrandt@washbear-network.de>
 
(defcfun ("gdk_cairo_create" gdk-cairo-create) :pointer (window :pointer))
 
(defclass gtk-context (context)
  ())
                          
(defun create-gtk-context (gdk-window)
  "creates an context to draw on a GTK widget, more precisely on the
associated gdk-window. This should only be called from within the
expose event. In cells-gtk, use (gtk-adds-widget-window gtk-pointer)
to obtain the gdk-window. 'gtk-pointer' is the pointer parameter
passed to the expose event handler."
  (make-instance 'gtk-context
                 :pointer (gdk-cairo-create gdk-window)))
 
(defmethod destroy ((self gtk-context))
  (cairo_destroy (slot-value self 'pointer)))
 
(defmacro with-gtk-context ((context gdk-window) &body body)
  "Executes body while context is bound to a valid cairo context for
gdk-window. This should only be called from within an expose event
handler. In cells-gtk, use (gtk-adds-widget-window gtk-pointer) to
obtain the gdk-window. 'gtk-pointer' is the pointer parameter passed
to the expose event handler."
  (with-gensyms (context-pointer)
    `(let ((,context (create-gtk-context ,gdk-window)))
       (with-context-pointer (,context ,context-pointer)
         ,@body)
       (destroy ,context))))
 
;; export manually
(export '(xlib-image-context create-xlib-image-context))