2009-01-21 20:34:42 -05:00
|
|
|
! Copyright (C) 2005, 2009 Slava Pestov.
|
2007-09-20 18:09:08 -04:00
|
|
|
! See http://factorcode.org/license.txt for BSD license.
|
2015-11-30 22:49:36 -05:00
|
|
|
USING: accessors colors colors.constants combinators kernel
|
|
|
|
math.rectangles math.vectors namespaces opengl opengl.capabilities
|
|
|
|
opengl.gl opengl.textures sequences sets 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 [
|
2008-11-28 01:02:02 -05:00
|
|
|
[ { 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 ;
|
|
|
|
|
2015-11-30 22:49:36 -05:00
|
|
|
: init-clip ( gadget -- )
|
2009-01-27 00:11:45 -05:00
|
|
|
[
|
|
|
|
dim>>
|
2016-03-29 20:14:42 -04:00
|
|
|
[ { 0 1 } v* viewport-translation namespaces:set ]
|
2009-01-27 00:11:45 -05:00
|
|
|
[ [ { 0 0 } ] dip gl-viewport ]
|
2009-04-11 16:17:08 -04:00
|
|
|
[ [ 0 ] dip first2 0 1 -1 glOrtho ] tri
|
2009-01-27 00:11:45 -05:00
|
|
|
]
|
2016-03-29 20:14:42 -04:00
|
|
|
[ clip namespaces:set ] bi
|
2007-09-20 18:09:08 -04:00
|
|
|
do-clip ;
|
|
|
|
|
2009-09-25 10:42:09 -04:00
|
|
|
SLOT: background-color
|
|
|
|
|
2015-11-30 22:49:36 -05:00
|
|
|
: gl-init ( -- )
|
|
|
|
check-extensions "1.0" require-gl-version
|
2007-09-20 18:09:08 -04:00
|
|
|
GL_SMOOTH glShadeModel
|
|
|
|
GL_BLEND glEnable
|
2008-11-11 01:28:37 -05:00
|
|
|
GL_VERTEX_ARRAY glEnableClientState
|
2010-06-01 07:52:00 -04:00
|
|
|
GL_PACK_ALIGNMENT 1 glPixelStorei
|
2015-11-30 22:49:36 -05:00
|
|
|
GL_UNPACK_ALIGNMENT 1 glPixelStorei ;
|
|
|
|
|
|
|
|
: gl-draw-init ( world -- )
|
|
|
|
GL_SCISSOR_TEST glEnable
|
2017-11-20 18:02:39 -05:00
|
|
|
GL_SRC_ALPHA GL_ONE_MINUS_SRC_ALPHA glBlendFunc
|
2007-09-20 18:09:08 -04:00
|
|
|
init-matrices
|
2009-09-25 10:42:09 -04:00
|
|
|
[ init-clip ]
|
2009-09-24 14:05:27 -04:00
|
|
|
[
|
2009-09-25 10:42:09 -04:00
|
|
|
background-color>> >rgba-components glClearColor
|
2009-09-24 14:05:27 -04:00
|
|
|
GL_COLOR_BUFFER_BIT glClear
|
2009-09-25 10:42:09 -04:00
|
|
|
] bi ;
|
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 )
|
2009-02-10 19:47:34 -05:00
|
|
|
[ clip get origin get vneg offset-rect ] dip children-on ;
|
2007-09-20 18:09:08 -04:00
|
|
|
|
2009-02-01 21:31:42 -05: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
|
|
|
|
2009-04-02 10:09:09 -04:00
|
|
|
! For gadget selection
|
|
|
|
SYMBOL: selected-gadgets
|
|
|
|
|
|
|
|
SYMBOL: selection-background
|
|
|
|
|
|
|
|
GENERIC: selected-children ( gadget -- assoc/f selection-background )
|
|
|
|
|
|
|
|
M: gadget selected-children drop f f ;
|
|
|
|
|
|
|
|
! 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 ;
|
|
|
|
|
|
|
|
<PRIVATE
|
|
|
|
|
|
|
|
: draw-selection-background ( gadget -- )
|
2016-03-29 20:14:42 -04:00
|
|
|
selection-background get background namespaces:set
|
2009-04-02 10:09:09 -04:00
|
|
|
selection-background get gl-color
|
|
|
|
[ { 0 0 } ] dip dim>> gl-fill-rect ;
|
|
|
|
|
|
|
|
: draw-standard-background ( object -- )
|
2016-07-12 00:01:03 -04:00
|
|
|
dup interior>> [ draw-interior ] [ drop ] if* ;
|
2009-04-02 10:09:09 -04:00
|
|
|
|
|
|
|
: draw-background ( gadget -- )
|
|
|
|
origin get [
|
|
|
|
[
|
2013-03-10 14:29:26 -04:00
|
|
|
dup selected-gadgets get in?
|
2009-04-02 10:09:09 -04:00
|
|
|
[ draw-selection-background ]
|
|
|
|
[ draw-standard-background ] if
|
|
|
|
] [ draw-gadget* ] bi
|
|
|
|
] with-translation ;
|
|
|
|
|
|
|
|
: draw-border ( object -- )
|
2017-07-01 01:51:10 -04:00
|
|
|
dup boundary>> [
|
2009-04-02 10:09:09 -04:00
|
|
|
origin get [ draw-boundary ] with-translation
|
2017-07-01 01:51:10 -04:00
|
|
|
] [ drop ] if* ;
|
2009-04-02 10:09:09 -04:00
|
|
|
|
|
|
|
PRIVATE>
|
|
|
|
|
2007-09-20 18:09:08 -04:00
|
|
|
: (draw-gadget) ( gadget -- )
|
2009-02-10 19:47:34 -05:00
|
|
|
dup loc>> origin get v+ origin [
|
2009-04-02 10:09:09 -04:00
|
|
|
[ draw-background ] [ draw-children ] [ draw-border ] tri
|
2009-02-10 19:47:34 -05:00
|
|
|
] 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 -- )
|
2016-03-29 20:14:42 -04:00
|
|
|
clip get [ over change-clip do-clip call ] dip
|
|
|
|
clip namespaces: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
|
|
|
M: gadget draw-children
|
2009-04-02 10:09:09 -04:00
|
|
|
dup children>> [
|
|
|
|
{
|
|
|
|
[ visible-children ]
|
|
|
|
[ selected-children ]
|
|
|
|
[ gadget-background ]
|
|
|
|
[ gadget-foreground ]
|
|
|
|
} cleave [
|
2012-07-19 16:55:34 -04:00
|
|
|
|
2009-04-02 10:09:09 -04:00
|
|
|
{
|
2016-03-29 20:14:42 -04:00
|
|
|
[ [ selected-gadgets namespaces:set ] when* ]
|
|
|
|
[ [ selection-background namespaces:set ] when* ]
|
|
|
|
[ [ background namespaces:set ] when* ]
|
|
|
|
[ [ foreground namespaces:set ] when* ]
|
2009-04-02 10:09:09 -04:00
|
|
|
} spread
|
|
|
|
[ draw-gadget ] each
|
|
|
|
] with-scope
|
|
|
|
] [ drop ] if ;
|