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 colors arrays combinators
5 opengl opengl.gl ui.pens ui.pens.caching ;
6 FROM: alien.c-types => float ;
7 SPECIALIZED-ARRAY: float
11 TUPLE: gradient < caching-pen colors last-vertices last-colors ;
13 : <gradient> ( colors -- gradient ) gradient new swap >>colors ;
17 :: gradient-vertices ( direction dim colors -- seq )
18 direction dim v* dim over v- swap
19 colors length dup 1 - v/n [ v*n ] with map
20 swap [ over v+ 2array ] curry map
21 concat concat >float-array ;
23 : gradient-colors ( colors -- seq )
24 [ >rgba-components 4array dup 2array ] map concat concat
27 M: gradient recompute-pen ( gadget gradient -- )
28 [ nip ] [ [ [ orientation>> ] [ dim>> ] bi ] [ colors>> ] bi* ] 2bi
29 [ gradient-vertices >>last-vertices ]
30 [ gradient-colors >>last-colors ]
33 : draw-gradient ( colors -- )
35 [ GL_QUAD_STRIP 0 ] dip length 2 * glDrawArrays
36 ] do-enabled-client-state ;
40 M: gradient draw-interior
43 [ last-vertices>> gl-vertex-pointer ]
44 [ last-colors>> gl-color-pointer ]
45 [ colors>> draw-gradient ]
48 M: gradient pen-background 2drop transparent ;