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
38 ! white gl-clear is broken w.r.t window resizing
39 ! Linux/PPC Radeon 9200
41 { 0 0 } clip get dim>> gl-fill-rect ;
43 GENERIC: draw-gadget* ( gadget -- )
45 M: gadget draw-gadget* drop ;
49 { 0 0 } origin set-global
51 : visible-children ( gadget -- seq )
52 [ clip get origin get vneg offset-rect ] dip children-on ;
54 : translate ( rect/point -- ) loc>> origin [ v+ ] change ;
56 GENERIC: draw-children ( gadget -- )
58 ! For gadget selection
59 SYMBOL: selected-gadgets
61 SYMBOL: selection-background
63 GENERIC: selected-children ( gadget -- assoc/f selection-background )
65 M: gadget selected-children drop f f ;
72 GENERIC: gadget-background ( gadget -- color )
74 M: gadget gadget-background dup interior>> pen-background ;
76 GENERIC: gadget-foreground ( gadget -- color )
78 M: gadget gadget-foreground dup interior>> pen-foreground ;
82 : draw-selection-background ( gadget -- )
83 selection-background get background set
84 selection-background get gl-color
85 [ { 0 0 } ] dip dim>> gl-fill-rect ;
87 : draw-standard-background ( object -- )
88 dup interior>> dup [ draw-interior ] [ 2drop ] if ;
90 : draw-background ( gadget -- )
93 dup selected-gadgets get key?
94 [ draw-selection-background ]
95 [ draw-standard-background ] if
99 : draw-border ( object -- )
101 origin get [ draw-boundary ] with-translation
106 : (draw-gadget) ( gadget -- )
107 dup loc>> origin get v+ origin [
108 [ draw-background ] [ draw-children ] [ draw-border ] tri
111 : >absolute ( rect -- rect )
112 origin get offset-rect ;
114 : change-clip ( gadget -- )
115 >absolute clip [ rect-intersect ] change ;
117 : with-clipping ( gadget quot -- )
118 clip get [ over change-clip do-clip call ] dip clip set do-clip ; inline
120 : draw-gadget ( gadget -- )
122 { [ dup visible?>> not ] [ drop ] }
123 { [ dup clipped?>> not ] [ (draw-gadget) ] }
124 [ [ (draw-gadget) ] with-clipping ]
127 M: gadget draw-children
131 [ selected-children ]
132 [ gadget-background ]
133 [ gadget-foreground ]
137 [ [ selected-gadgets set ] when* ]
138 [ [ selection-background set ] when* ]
139 [ [ background set ] when* ]
140 [ [ foreground set ] when* ]
146 CONSTANT: selection-color T{ rgba f 0.8 0.8 1.0 1.0 }
148 CONSTANT: panel-background-color
156 CONSTANT: focus-border-color COLOR: dark-gray