1 ! Copyright (C) 2009 Slava Pestov.
2 ! See http://factorcode.org/license.txt for BSD license.
3 USING: kernel accessors math math.vectors locals sequences
4 specialized-arrays.float colors arrays combinators
5 opengl opengl.gl ui.pens ui.pens.caching ;
9 TUPLE: gradient < caching-pen colors last-vertices last-colors ;
11 : <gradient> ( colors -- gradient ) gradient new swap >>colors ;
15 :: gradient-vertices ( direction dim colors -- seq )
16 direction dim v* dim over v- swap
17 colors length dup 1 - v/n [ v*n ] with map
18 swap [ over v+ 2array ] curry map
19 concat concat >float-array ;
21 : gradient-colors ( colors -- seq )
22 [ >rgba-components 4array dup 2array ] map concat concat
25 M: gradient recompute-pen ( gadget gradient -- )
26 [ nip ] [ [ [ orientation>> ] [ dim>> ] bi ] [ colors>> ] bi* ] 2bi
27 [ gradient-vertices >>last-vertices ]
28 [ gradient-colors >>last-colors ]
31 : draw-gradient ( colors -- )
33 [ GL_QUAD_STRIP 0 ] dip length 2 * glDrawArrays
34 ] do-enabled-client-state ;
38 M: gradient draw-interior
41 [ last-vertices>> gl-vertex-pointer ]
42 [ last-colors>> gl-color-pointer ]
43 [ colors>> draw-gradient ]
46 M: gradient pen-background 2drop transparent ;