]> gitweb.factorcode.org Git - factor.git/blob - basis/ui/pens/polygon/polygon.factor
d244cc71d2d3aa9f32c39f6e840b9c106f1625e8
[factor.git] / basis / ui / pens / polygon / polygon.factor
1 ! Copyright (C) 2009 Slava Pestov.
2 ! See http://factorcode.org/license.txt for BSD license.
3 USING: accessors colors help.markup help.syntax kernel opengl
4 opengl.gl sequences specialized-arrays.float math.vectors
5 ui.gadgets ui.pens ;
6 IN: ui.pens.polygon
7
8 ! Polygon pen
9 TUPLE: polygon color
10 interior-vertices
11 interior-count
12 boundary-vertices
13 boundary-count ;
14
15 : close-path ( points -- points' )
16     dup first suffix ;
17
18 : <polygon> ( color points -- polygon )
19     dup close-path [ [ concat >float-array ] [ length ] bi ] bi@
20     polygon boa ;
21
22 M: polygon draw-boundary
23     nip
24     [ color>> gl-color ]
25     [ boundary-vertices>> gl-vertex-pointer ]
26     [ [ GL_LINE_STRIP 0 ] dip boundary-count>> glDrawArrays ]
27     tri ;
28
29 M: polygon draw-interior
30     nip
31     [ color>> gl-color ]
32     [ interior-vertices>> gl-vertex-pointer ]
33     [ [ GL_POLYGON 0 ] dip interior-count>> glDrawArrays ]
34     tri ;
35
36 : <polygon-gadget> ( color points -- gadget )
37     [ <polygon> ] [ { 0 0 } [ vmax ] reduce ] bi
38     [ <gadget> ] 2dip [ >>interior ] [ >>dim ] bi* ;