Author: tpapp Date: Sat Aug 25 08:34:48 2007 New Revision: 14
Modified: context.lisp package.lisp tutorial/x11-example.lisp Log: with-sync-lock added, x11-example.lisp fixed
Modified: context.lisp ============================================================================== --- context.lisp (original) +++ context.lisp Sat Aug 25 08:34:48 2007 @@ -67,6 +67,15 @@ (defmethod sync-unlock ((object context))) (defmethod sync-reset ((object context)))
+(defmacro with-sync-lock ((context) &body body) + "Lock sync for context for the duration of body. Protected against +nonlocal exits." + (once-only (context) + `(progn + (sync-lock ,context) + (unwind-protect (progn ,@body) + (sync-unlock ,context))))) + ;;;; ;;;; default context and convenience macros ;;;;
Modified: package.lisp ============================================================================== --- package.lisp (original) +++ package.lisp Sat Aug 25 08:34:48 2007 @@ -15,8 +15,8 @@
;; context
- create-context sync sync-lock sync - sync-unlock sync-reset *context* save restore push-group pop-group + create-context sync sync-lock sync sync-unlock sync-reset + with-sync-lock *context* save restore push-group pop-group pop-group-to-source set-source-rgb set-source-rgba clip clip-preserve reset-clip copy-page show-page fill-preserve paint paint-with-alpha stroke stroke-preserve set-source-color
Modified: tutorial/x11-example.lisp ============================================================================== --- tutorial/x11-example.lisp (original) +++ tutorial/x11-example.lisp Sat Aug 25 08:34:48 2007 @@ -7,11 +7,9 @@ (in-package :cairo-xlib-example)
;; open display -(defparameter *display* (open-x11-display ":0")) - (let ((width 400) (height 300)) - (setf *context* (create-x11-context width height *display*)) + (setf *context* (create-xlib-context width height :window-name "diagonal lines")) ;; clear the whole canvas with blue (rectangle 0 0 width height) (set-source-rgb 0.2 0.2 0.5) @@ -44,7 +42,7 @@ (defparameter width 800) (defparameter height 600) (defparameter max-angle 90d0) -(setf *context* (create-x11-context width height *display*)) +(setf *context* (create-xlib-context width height :window-name "rectangles")) ;; fill with white (rectangle 0 0 width height) (set-source-rgb 1 1 1) @@ -52,9 +50,9 @@ ;; draw the rectangles (dotimes (i 500) (let ((scaling (+ 5d0 (random 40d0)))) - (reset-matrix) ; reset matrix + (reset-trans-matrix) ; reset matrix (translate (random width) (random height)) ; move the origin - (scale scaling scaling) ; scale - (rotate (deg-to-rad (random max-angle))) ; rotate + (scale scaling scaling) ; scale + (rotate (deg-to-rad (random max-angle))) ; rotate (random-square (+ 0.1 (random 0.4))))) ;; need to close window manually