factor/basis/ui/render/render.factor

115 lines
2.8 KiB
Factor
Raw Normal View History

! Copyright (C) 2005, 2009 Slava Pestov.
2007-09-20 18:09:08 -04:00
! See http://factorcode.org/license.txt for BSD license.
2009-02-12 04:58:42 -05:00
USING: math.rectangles math.vectors namespaces kernel accessors
2009-02-14 21:46:35 -05:00
combinators sequences opengl opengl.gl opengl.glu colors
colors.constants ui.gadgets ui.pens ;
2007-09-20 18:09:08 -04:00
IN: ui.render
SYMBOL: clip
SYMBOL: viewport-translation
: flip-rect ( rect -- loc dim )
rect-bounds [
[ { 1 -1 } v* ] dip { 0 -1 } v* v+
2007-09-20 18:09:08 -04:00
viewport-translation get v+
] keep ;
: do-clip ( -- ) clip get flip-rect gl-set-clip ;
2009-01-27 00:11:45 -05:00
: init-clip ( clip-rect -- )
[
dim>>
[ { 0 1 } v* viewport-translation set ]
[ [ { 0 0 } ] dip gl-viewport ]
[ [ 0 ] dip first2 0 gluOrtho2D ] tri
]
[ clip set ] bi
2007-09-20 18:09:08 -04:00
do-clip ;
2009-01-27 00:11:45 -05:00
: init-gl ( clip-rect -- )
2007-09-20 18:09:08 -04:00
GL_SMOOTH glShadeModel
2009-01-27 00:11:45 -05:00
GL_SCISSOR_TEST glEnable
2007-09-20 18:09:08 -04:00
GL_BLEND glEnable
GL_SRC_ALPHA GL_ONE_MINUS_SRC_ALPHA glBlendFunc
GL_VERTEX_ARRAY glEnableClientState
2007-09-20 18:09:08 -04:00
init-matrices
init-clip
! white gl-clear is broken w.r.t window resizing
! Linux/PPC Radeon 9200
COLOR: white gl-color
clip get dim>> gl-fill-rect ;
2007-09-20 18:09:08 -04:00
GENERIC: draw-gadget* ( gadget -- )
M: gadget draw-gadget* drop ;
SYMBOL: origin
{ 0 0 } origin set-global
: visible-children ( gadget -- seq )
[ clip get origin get vneg offset-rect ] dip children-on ;
2007-09-20 18:09:08 -04:00
: translate ( rect/point -- ) loc>> origin [ v+ ] change ;
2007-09-20 18:09:08 -04:00
2009-02-14 22:53:39 -05:00
GENERIC: draw-children ( gadget -- )
2007-09-20 18:09:08 -04:00
: (draw-gadget) ( gadget -- )
dup loc>> origin get v+ origin [
[
origin get [
[ dup interior>> dup [ draw-interior ] [ 2drop ] if ]
[ draw-gadget* ]
bi
] with-translation
]
2009-02-14 22:53:39 -05:00
[ draw-children ]
[
dup boundary>> dup [
origin get [ draw-boundary ] with-translation
] [ 2drop ] if
] tri
] with-variable ;
2007-09-20 18:09:08 -04:00
: >absolute ( rect -- rect )
origin get offset-rect ;
: change-clip ( gadget -- )
>absolute clip [ rect-intersect ] change ;
: with-clipping ( gadget quot -- )
clip get [ over change-clip do-clip call ] dip clip set do-clip ; inline
2007-09-20 18:09:08 -04:00
: draw-gadget ( gadget -- )
{
2008-08-29 19:44:19 -04:00
{ [ dup visible?>> not ] [ drop ] }
{ [ dup clipped?>> not ] [ (draw-gadget) ] }
2008-04-11 13:54:33 -04:00
[ [ (draw-gadget) ] with-clipping ]
2009-02-14 20:50:22 -05:00
} cond ;
2009-02-14 22:53:39 -05:00
! For text rendering
SYMBOL: background
SYMBOL: foreground
GENERIC: gadget-background ( gadget -- color )
M: gadget gadget-background dup interior>> pen-background ;
GENERIC: gadget-foreground ( gadget -- color )
M: gadget gadget-foreground dup interior>> pen-foreground ;
M: gadget draw-children
[ visible-children ]
[ gadget-background ]
[ gadget-foreground ] tri [
[ foreground set ] when*
[ background set ] when*
[ draw-gadget ] each
] with-scope ;
2009-02-14 20:50:22 -05:00
CONSTANT: selection-color T{ rgba f 0.8 0.8 1.0 1.0 }
CONSTANT: focus-border-color COLOR: dark-gray