/[cl-cairo2]/gtk-context.lisp
ViewVC logotype

Contents of /gtk-context.lisp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 16 - (show annotations)
Thu Dec 20 13:17:49 2007 UTC (6 years, 4 months ago) by tpapp
File size: 1564 byte(s)
added gtk-context, contributed by Peter Hildebrandt
1 (in-package :cl-cairo2)
2
3
4 ;; library functions to create a gdk-surface
5 ;; written by Peter Hildebrandt <peter.hildebrandt@washbear-network.de>
6
7 (define-foreign-library :gdk
8 (cffi-features:unix "libgdk-x11-2.0.so")
9 (cffi-features:windows "libgdk-win32-2.0-0.dll")
10 (cffi-features:darwin "libgdk-win32-2.0-0.dylib"))
11
12 (load-foreign-library :gdk)
13 (defcfun ("gdk_cairo_create" gdk-cairo-create) :pointer (window :pointer))
14
15 (defclass gtk-context (context)
16 ())
17
18 (defun create-gtk-context (gdk-window)
19 "creates an context to draw on a GTK widget, more precisely on the
20 associated gdk-window. This should only be called from within the
21 expose event. In cells-gtk, use (gtk-adds-widget-window gtk-pointer)
22 to obtain the gdk-window. 'gtk-pointer' is the pointer parameter
23 passed to the expose event handler."
24 (make-instance 'gtk-context
25 :pointer (gdk-cairo-create gdk-window)))
26
27 (defmethod destroy ((self gtk-context))
28 (cairo_destroy (slot-value self 'pointer)))
29
30 (defmacro with-gtk-context ((context gdk-window) &body body)
31 "Executes body while context is bound to a valid cairo context for
32 gdk-window. This should only be called from within an expose event
33 handler. In cells-gtk, use (gtk-adds-widget-window gtk-pointer) to
34 obtain the gdk-window. 'gtk-pointer' is the pointer parameter passed
35 to the expose event handler."
36 (with-gensyms (context-pointer)
37 `(let ((,context (create-gtk-context ,gdk-window)))
38 (with-context (,context ,context-pointer)
39 ,@body)
40 (destroy ,context))))

  ViewVC Help
Powered by ViewVC 1.1.5