]> gitweb.factorcode.org Git - factor.git/blob - unmaintained/cairo/cairo.factor
Move vocabularies which use delegation to unmaintained, and delete older unmaintained...
[factor.git] / unmaintained / cairo / cairo.factor
1 ! Copyright (C) 2008 Doug Coleman.
2 ! See http://factorcode.org/license.txt for BSD license.
3 USING: cairo.ffi kernel accessors sequences
4 namespaces fry continuations destructors ;
5 IN: cairo
6
7 TUPLE: cairo-t alien ;
8 C: <cairo-t> cairo-t
9 M: cairo-t dispose ( alien -- ) alien>> cairo_destroy ;
10
11 TUPLE: cairo-surface-t alien ;
12 C: <cairo-surface-t> cairo-surface-t
13 M: cairo-surface-t dispose ( alien -- ) alien>> cairo_surface_destroy ;
14
15 : check-cairo ( cairo_status_t -- )
16     dup CAIRO_STATUS_SUCCESS = [ drop ]
17     [ cairo_status_to_string "Cairo error: " prepend throw ] if ;
18
19 SYMBOL: cairo
20 : cr ( -- cairo ) cairo get ;
21
22 : (with-cairo) ( cairo-t quot -- )
23     >r alien>> cairo r> [ cr cairo_status check-cairo ]
24     compose with-variable ; inline
25     
26 : with-cairo ( cairo quot -- )
27     >r <cairo-t> r> [ (with-cairo) ] curry with-disposal ; inline
28
29 : (with-surface) ( cairo-surface-t quot -- )
30     >r alien>> r> [ cairo_surface_status check-cairo ] bi ; inline
31
32 : with-surface ( cairo_surface quot -- )
33     >r <cairo-surface-t> r> [ (with-surface) ] curry with-disposal ; inline
34
35 : with-cairo-from-surface ( cairo_surface quot -- )
36     '[ cairo_create , with-cairo ] with-surface ; inline