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 : init-gl ( clip-rect -- )
31 GL_SMOOTH glShadeModel
32 GL_SCISSOR_TEST glEnable
34 GL_SRC_ALPHA GL_ONE_MINUS_SRC_ALPHA glBlendFunc
35 GL_VERTEX_ARRAY glEnableClientState
39 : clear-gl ( transparent? -- )
41 0.0 0.0 0.0 0.0 glClearColor
42 GL_COLOR_BUFFER_BIT glClear
44 ! white gl-clear is broken w.r.t window resizing
45 ! Linux/PPC Radeon 9200
47 { 0 0 } clip get dim>> gl-fill-rect
50 GENERIC: draw-gadget* ( gadget -- )
52 M: gadget draw-gadget* drop ;
56 { 0 0 } origin set-global
58 : visible-children ( gadget -- seq )
59 [ clip get origin get vneg offset-rect ] dip children-on ;
61 : translate ( rect/point -- ) loc>> origin [ v+ ] change ;
63 GENERIC: draw-children ( gadget -- )
65 ! For gadget selection
66 SYMBOL: selected-gadgets
68 SYMBOL: selection-background
70 GENERIC: selected-children ( gadget -- assoc/f selection-background )
72 M: gadget selected-children drop f f ;
79 GENERIC: gadget-background ( gadget -- color )
81 M: gadget gadget-background dup interior>> pen-background ;
83 GENERIC: gadget-foreground ( gadget -- color )
85 M: gadget gadget-foreground dup interior>> pen-foreground ;
89 : draw-selection-background ( gadget -- )
90 selection-background get background set
91 selection-background get gl-color
92 [ { 0 0 } ] dip dim>> gl-fill-rect ;
94 : draw-standard-background ( object -- )
95 dup interior>> dup [ draw-interior ] [ 2drop ] if ;
97 : draw-background ( gadget -- )
100 dup selected-gadgets get key?
101 [ draw-selection-background ]
102 [ draw-standard-background ] if
103 ] [ draw-gadget* ] bi
106 : draw-border ( object -- )
108 origin get [ draw-boundary ] with-translation
113 : (draw-gadget) ( gadget -- )
114 dup loc>> origin get v+ origin [
115 [ draw-background ] [ draw-children ] [ draw-border ] tri
118 : >absolute ( rect -- rect )
119 origin get offset-rect ;
121 : change-clip ( gadget -- )
122 >absolute clip [ rect-intersect ] change ;
124 : with-clipping ( gadget quot -- )
125 clip get [ over change-clip do-clip call ] dip clip set do-clip ; inline
127 : draw-gadget ( gadget -- )
129 { [ dup visible?>> not ] [ drop ] }
130 { [ dup clipped?>> not ] [ (draw-gadget) ] }
131 [ [ (draw-gadget) ] with-clipping ]
134 M: gadget draw-children
138 [ selected-children ]
139 [ gadget-background ]
140 [ gadget-foreground ]
144 [ [ selected-gadgets set ] when* ]
145 [ [ selection-background set ] when* ]
146 [ [ background set ] when* ]
147 [ [ foreground set ] when* ]
153 CONSTANT: selection-color T{ rgba f 0.8 0.8 1.0 1.0 }
155 CONSTANT: panel-background-color
163 CONSTANT: focus-border-color COLOR: dark-gray