]> gitweb.factorcode.org Git - factor.git/blob - basis/ui/pens/polygon/polygon.factor
Specialized array overhaul
[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 math.vectors ui.gadgets ui.pens
5 specialized-arrays ;
6 SPECIALIZED-ARRAY: float
7 IN: ui.pens.polygon
8
9 ! Polygon pen
10 TUPLE: polygon color
11 interior-vertices
12 interior-count
13 boundary-vertices
14 boundary-count ;
15
16 : close-path ( points -- points' )
17     dup first suffix ;
18
19 : <polygon> ( color points -- polygon )
20     dup close-path [ [ concat >float-array ] [ length ] bi ] bi@
21     polygon boa ;
22
23 M: polygon draw-boundary
24     nip
25     [ color>> gl-color ]
26     [ boundary-vertices>> gl-vertex-pointer ]
27     [ [ GL_LINE_STRIP 0 ] dip boundary-count>> glDrawArrays ]
28     tri ;
29
30 M: polygon draw-interior
31     nip
32     [ color>> gl-color ]
33     [ interior-vertices>> gl-vertex-pointer ]
34     [ [ GL_POLYGON 0 ] dip interior-count>> glDrawArrays ]
35     tri ;
36
37 : <polygon-gadget> ( color points -- gadget )
38     [ <polygon> ] [ { 0 0 } [ vmax ] reduce ] bi
39     [ <gadget> ] 2dip [ >>interior ] [ >>dim ] bi* ;