2008-05-10 18:15:34 -04:00
|
|
|
! Copyright (C) 2008 Matthew Willis.
|
|
|
|
! See http://factorcode.org/license.txt for BSD license.
|
2008-05-30 13:42:06 -04:00
|
|
|
USING: sequences math opengl.gadgets kernel
|
|
|
|
byte-arrays cairo.ffi cairo io.backend
|
2008-06-01 13:35:40 -04:00
|
|
|
ui.gadgets accessors opengl.gl
|
|
|
|
arrays ;
|
2008-05-03 12:59:59 -04:00
|
|
|
|
2008-05-03 17:30:41 -04:00
|
|
|
IN: cairo.gadgets
|
|
|
|
|
2008-05-10 17:22:12 -04:00
|
|
|
: width>stride ( width -- stride ) 4 * ;
|
|
|
|
|
2008-05-30 13:42:06 -04:00
|
|
|
: copy-cairo ( dim quot -- byte-array )
|
|
|
|
>r first2 over width>stride
|
2008-05-03 12:59:59 -04:00
|
|
|
[ * nip <byte-array> dup CAIRO_FORMAT_ARGB32 ]
|
|
|
|
[ cairo_image_surface_create_for_data ] 3bi
|
2008-05-10 17:22:12 -04:00
|
|
|
r> with-cairo-from-surface ;
|
|
|
|
|
2008-06-01 13:35:40 -04:00
|
|
|
TUPLE: cairo-gadget < texture-gadget quot ;
|
|
|
|
|
|
|
|
: <cairo-gadget> ( dim quot -- gadget )
|
|
|
|
cairo-gadget construct-gadget
|
|
|
|
swap >>quot
|
|
|
|
swap >>dim ;
|
|
|
|
|
|
|
|
M: cairo-gadget graft* ( gadget -- )
|
|
|
|
GL_BGRA >>format dup
|
|
|
|
[ dim>> 2^-bounds ] [ quot>> copy-cairo ] bi
|
|
|
|
>>bytes call-next-method ;
|
2008-05-24 23:04:12 -04:00
|
|
|
|
2008-05-30 13:42:06 -04:00
|
|
|
! maybe also texture>png
|
|
|
|
! : cairo>png ( gadget path -- )
|
|
|
|
! >r [ cairo>bytes CAIRO_FORMAT_ARGB32 ] [ width>> ]
|
|
|
|
! [ height>> ] tri over width>stride
|
|
|
|
! cairo_image_surface_create_for_data
|
|
|
|
! r> [ cairo_surface_write_to_png check-cairo ] curry with-surface ;
|
2008-05-03 17:30:41 -04:00
|
|
|
|
2008-05-10 17:22:12 -04:00
|
|
|
: copy-surface ( surface -- )
|
|
|
|
cr swap 0 0 cairo_set_source_surface
|
|
|
|
cr cairo_paint ;
|
2008-05-03 17:30:41 -04:00
|
|
|
|
|
|
|
: <png-gadget> ( path -- gadget )
|
|
|
|
normalize-path cairo_image_surface_create_from_png
|
2008-05-10 17:22:12 -04:00
|
|
|
[ cairo_image_surface_get_width ]
|
2008-05-30 13:42:06 -04:00
|
|
|
[ cairo_image_surface_get_height 2array dup 2^-bounds ]
|
2008-05-10 17:22:12 -04:00
|
|
|
[ [ copy-surface ] curry copy-cairo ] tri
|
2008-05-30 13:42:06 -04:00
|
|
|
GL_BGRA rot <texture-gadget> ;
|
2008-05-24 23:04:12 -04:00
|
|
|
|
|
|
|
|