From d49e64abf1a770a28d7beecf68555d45bd8c2e06 Mon Sep 17 00:00:00 2001 From: Matthew Willis Date: Sat, 3 May 2008 14:30:41 -0700 Subject: [PATCH] renamed cairo.gadget to cairo.gadgets and added pixel and png gadgets --- .../gadget.factor => gadgets/gadgets.factor} | 36 ++++++++++++++++--- 1 file changed, 32 insertions(+), 4 deletions(-) rename extra/cairo/{gadget/gadget.factor => gadgets/gadgets.factor} (53%) diff --git a/extra/cairo/gadget/gadget.factor b/extra/cairo/gadgets/gadgets.factor similarity index 53% rename from extra/cairo/gadget/gadget.factor rename to extra/cairo/gadgets/gadgets.factor index 2033f77a38..e5b18f72b7 100644 --- a/extra/cairo/gadget/gadget.factor +++ b/extra/cairo/gadgets/gadgets.factor @@ -1,8 +1,12 @@ USING: cairo ui.render kernel opengl.gl opengl math byte-arrays ui.gadgets accessors arrays -namespaces ; +namespaces io.backend ; -IN: cairo.gadget +IN: cairo.gadgets + +! We need two kinds of gadgets: +! one performs the cairo ops once and caches the bytes, the other +! performs cairo ops every refresh TUPLE: cairo-gadget width height quot ; : ( width height quot -- cairo-gadget ) @@ -37,6 +41,30 @@ M: cairo-gadget draw-gadget* ( gadget -- ) [ drop GL_BGRA GL_UNSIGNED_BYTE ] [ cairo>bytes ] 3bi glDrawPixels ] with-translation ; - + M: cairo-gadget pref-dim* ( gadget -- rect ) - [ width>> ] [ height>> ] bi 2array ; \ No newline at end of file + [ width>> ] [ height>> ] bi 2array ; + +TUPLE: pixels-gadget width height bytes ; +: ( width height bytes -- pixel-gadget ) + pixels-gadget construct-gadget + swap >>bytes + swap >>height + swap >>width ; + +M: pixels-gadget draw-gadget* ( gadget -- ) + origin get [ + 0 0 glRasterPos2i + 1.0 -1.0 glPixelZoom + [ width>> ] [ height>> ] [ bytes>> ] tri + GL_BGRA GL_UNSIGNED_BYTE rot glDrawPixels + ] with-translation ; + +M: pixels-gadget pref-dim* ( gadget -- rect ) + [ width>> ] [ height>> ] bi 2array ; + +: ( path -- gadget ) + normalize-path cairo_image_surface_create_from_png + [ cairo_image_surface_get_width ] [ cairo_image_surface_get_height 2dup ] + [ [ dupd 0 0 cairo_set_source_surface cairo_paint ] curry cairo>bytes ] tri + ; \ No newline at end of file -- 2.34.1