1 ! Copyright (C) 2005, 2009 Slava Pestov.
2 ! See http://factorcode.org/license.txt for BSD license.
3 USING: math.rectangles math.vectors namespaces kernel accessors
4 assocs combinators sequences opengl opengl.gl colors
5 colors.constants ui.gadgets ui.pens ;
10 SYMBOL: viewport-translation
12 : flip-rect ( rect -- loc dim )
14 [ { 1 -1 } v* ] dip { 0 -1 } v* v+
15 viewport-translation get v+
18 : do-clip ( -- ) clip get flip-rect gl-set-clip ;
20 : init-clip ( clip-rect -- )
23 [ { 0 1 } v* viewport-translation set ]
24 [ [ { 0 0 } ] dip gl-viewport ]
25 [ [ 0 ] dip first2 0 1 -1 glOrtho ] tri
30 SLOT: background-color
32 : init-gl ( world -- )
33 GL_SMOOTH glShadeModel
34 GL_SCISSOR_TEST glEnable
36 GL_SRC_ALPHA GL_ONE_MINUS_SRC_ALPHA glBlendFunc
37 GL_VERTEX_ARRAY glEnableClientState
41 background-color>> >rgba-components glClearColor
42 GL_COLOR_BUFFER_BIT glClear
45 GENERIC: draw-gadget* ( gadget -- )
47 M: gadget draw-gadget* drop ;
51 { 0 0 } origin set-global
53 : visible-children ( gadget -- seq )
54 [ clip get origin get vneg offset-rect ] dip children-on ;
56 : translate ( rect/point -- ) loc>> origin [ v+ ] change ;
58 GENERIC: draw-children ( gadget -- )
60 ! For gadget selection
61 SYMBOL: selected-gadgets
63 SYMBOL: selection-background
65 GENERIC: selected-children ( gadget -- assoc/f selection-background )
67 M: gadget selected-children drop f f ;
74 GENERIC: gadget-background ( gadget -- color )
76 M: gadget gadget-background dup interior>> pen-background ;
78 GENERIC: gadget-foreground ( gadget -- color )
80 M: gadget gadget-foreground dup interior>> pen-foreground ;
84 : draw-selection-background ( gadget -- )
85 selection-background get background set
86 selection-background get gl-color
87 [ { 0 0 } ] dip dim>> gl-fill-rect ;
89 : draw-standard-background ( object -- )
90 dup interior>> dup [ draw-interior ] [ 2drop ] if ;
92 : draw-background ( gadget -- )
95 dup selected-gadgets get key?
96 [ draw-selection-background ]
97 [ draw-standard-background ] if
101 : draw-border ( object -- )
103 origin get [ draw-boundary ] with-translation
108 : (draw-gadget) ( gadget -- )
109 dup loc>> origin get v+ origin [
110 [ draw-background ] [ draw-children ] [ draw-border ] tri
113 : >absolute ( rect -- rect )
114 origin get offset-rect ;
116 : change-clip ( gadget -- )
117 >absolute clip [ rect-intersect ] change ;
119 : with-clipping ( gadget quot -- )
120 clip get [ over change-clip do-clip call ] dip clip set do-clip ; inline
122 : draw-gadget ( gadget -- )
124 { [ dup visible?>> not ] [ drop ] }
125 { [ dup clipped?>> not ] [ (draw-gadget) ] }
126 [ [ (draw-gadget) ] with-clipping ]
129 M: gadget draw-children
133 [ selected-children ]
134 [ gadget-background ]
135 [ gadget-foreground ]
139 [ [ selected-gadgets set ] when* ]
140 [ [ selection-background set ] when* ]
141 [ [ background set ] when* ]
142 [ [ foreground set ] when* ]
148 CONSTANT: selection-color T{ rgba f 0.8 0.8 1.0 1.0 }
150 CONSTANT: panel-background-color
158 CONSTANT: focus-border-color COLOR: dark-gray