renamed cairo.gadget to cairo.gadgets and added pixel and png gadgets
parent
bbd78cf9d7
commit
d49e64abf1
|
@ -1,8 +1,12 @@
|
||||||
USING: cairo ui.render kernel opengl.gl opengl
|
USING: cairo ui.render kernel opengl.gl opengl
|
||||||
math byte-arrays ui.gadgets accessors arrays
|
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 ;
|
TUPLE: cairo-gadget width height quot ;
|
||||||
: <cairo-gadget> ( width height quot -- cairo-gadget )
|
: <cairo-gadget> ( width height quot -- cairo-gadget )
|
||||||
|
@ -40,3 +44,27 @@ M: cairo-gadget draw-gadget* ( gadget -- )
|
||||||
|
|
||||||
M: cairo-gadget pref-dim* ( gadget -- rect )
|
M: cairo-gadget pref-dim* ( gadget -- rect )
|
||||||
[ width>> ] [ height>> ] bi 2array ;
|
[ width>> ] [ height>> ] bi 2array ;
|
||||||
|
|
||||||
|
TUPLE: pixels-gadget width height bytes ;
|
||||||
|
: <pixels-gadget> ( 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 ;
|
||||||
|
|
||||||
|
: <png-gadget> ( 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
|
||||||
|
<pixels-gadget> ;
|
Loading…
Reference in New Issue