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 combinators sequences opengl opengl.gl opengl.glu 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 gluOrtho2D ] 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 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 : (draw-gadget) ( gadget -- )
59 dup loc>> origin get v+ origin [
62 [ dup interior>> dup [ draw-interior ] [ 2drop ] if ]
70 origin get [ draw-boundary ] with-translation
75 : >absolute ( rect -- rect )
76 origin get offset-rect ;
78 : change-clip ( gadget -- )
79 >absolute clip [ rect-intersect ] change ;
81 : with-clipping ( gadget quot -- )
82 clip get [ over change-clip do-clip call ] dip clip set do-clip ; inline
84 : draw-gadget ( gadget -- )
86 { [ dup visible?>> not ] [ drop ] }
87 { [ dup clipped?>> not ] [ (draw-gadget) ] }
88 [ [ (draw-gadget) ] with-clipping ]
96 GENERIC: gadget-background ( gadget -- color )
98 M: gadget gadget-background dup interior>> pen-background ;
100 GENERIC: gadget-foreground ( gadget -- color )
102 M: gadget gadget-foreground dup interior>> pen-foreground ;
104 M: gadget draw-children
106 [ gadget-background ]
107 [ gadget-foreground ] tri [
108 [ foreground set ] when*
109 [ background set ] when*
113 CONSTANT: selection-color T{ rgba f 0.8 0.8 1.0 1.0 }
115 CONSTANT: focus-border-color COLOR: dark-gray