draw-gadget* ( gadget -- )
Factor handbook » UI framework » Implementing new gadgets » Customizing gadget appearance » Implementing custom drawing logic

Next:find-gl-context ( gadget -- )


Vocabulary
ui.render

Inputs
gadgeta gadget


Outputs
None

Generic word contract
Draws the gadget by making OpenGL calls. The top-left corner of the gadget should be drawn at the location stored in the origin variable.

Notes
This word should not be called directly. To force a gadget to redraw, call relayout-1.

Definition


Methods




























M:: frame-buffer draw-gadget* ( FRAME-BUFFER -- )
FRAME-BUFFER dim>> { 0 1 } v* first2 glRasterPos2i
FRAME-BUFFER draw-pixels FRAME-BUFFER update-frame-buffer
glFlush FRAME-BUFFER read-pixels ;
















































M: nehe5-gadget draw-gadget*
GL_PROJECTION glMatrixMode
glLoadIdentity 45.0 width height /
>float 0.1 100.0 gluPerspective GL_MODELVIEW glMatrixMode
glLoadIdentity GL_SMOOTH glShadeModel
0.0 0.0 0.0 0.0 glClearColor 1.0 glClearDepth
GL_DEPTH_TEST glEnable GL_LEQUAL glDepthFunc
GL_PERSPECTIVE_CORRECTION_HINT GL_NICEST glHint
GL_COLOR_BUFFER_BIT GL_DEPTH_BUFFER_BIT bitor glClear
glLoadIdentity -1.5 0.0 -6.0 glTranslatef
dup rtri>> 0.0 1.0 0.0 glRotatef GL_TRIANGLES [
1.0 0.0 0.0 glColor3f 0.0 1.0 0.0 glVertex3f
0.0 1.0 0.0 glColor3f -1.0 -1.0 1.0 glVertex3f
0.0 0.0 1.0 glColor3f 1.0 -1.0 1.0 glVertex3f
1.0 0.0 0.0 glColor3f 0.0 1.0 0.0 glVertex3f
0.0 0.0 1.0 glColor3f 1.0 -1.0 1.0 glVertex3f
0.0 1.0 0.0 glColor3f 1.0 -1.0 -1.0 glVertex3f
1.0 0.0 0.0 glColor3f 0.0 1.0 0.0 glVertex3f
0.0 1.0 0.0 glColor3f 1.0 -1.0 -1.0 glVertex3f
0.0 0.0 1.0 glColor3f -1.0 -1.0 -1.0 glVertex3f
1.0 0.0 0.0 glColor3f 0.0 1.0 0.0 glVertex3f
0.0 0.0 1.0 glColor3f -1.0 -1.0 -1.0 glVertex3f
0.0 1.0 0.0 glColor3f -1.0 -1.0 1.0 glVertex3f
] do-state glLoadIdentity 1.5 0.0 -7.0 glTranslatef
dup rquad>> 1.0 0.0 0.0 glRotatef GL_QUADS [
0.0 1.0 0.0 glColor3f 1.0 1.0 -1.0 glVertex3f
-1.0 1.0 -1.0 glVertex3f -1.0 1.0 1.0 glVertex3f
1.0 1.0 1.0 glVertex3f 1.0 0.5 0.0 glColor3f
1.0 -1.0 1.0 glVertex3f -1.0 -1.0 1.0 glVertex3f
-1.0 -1.0 -1.0 glVertex3f 1.0 -1.0 -1.0 glVertex3f
1.0 0.0 0.0 glColor3f 1.0 1.0 1.0 glVertex3f
-1.0 1.0 1.0 glVertex3f -1.0 -1.0 1.0 glVertex3f
1.0 -1.0 1.0 glVertex3f 1.0 1.0 0.0 glColor3f
1.0 -1.0 -1.0 glVertex3f -1.0 -1.0 -1.0 glVertex3f
-1.0 1.0 -1.0 glVertex3f 1.0 1.0 -1.0 glVertex3f
0.0 0.0 1.0 glColor3f -1.0 1.0 1.0 glVertex3f
-1.0 1.0 -1.0 glVertex3f -1.0 -1.0 -1.0 glVertex3f
-1.0 -1.0 1.0 ~21 more~
] do-state [ 0.2 + ] change-rtri [ 0.15 - ] change-rquad
drop ;















M:: spline-gadget draw-gadget* ( gadget -- )
0 0 0 glColor3f gadget [ polynomials>> ] [ steps>> ] bi
eval-polynomials :> pts pts [ first ] [ max ] map-reduce
:> x-max pts [ first ] [ min ] map-reduce :> x-min pts
[ second ] [ max ] map-reduce :> y-max pts
[ second ] [ min ] map-reduce :> y-min pts [
[
first x-min - x-max x-min - /
gadget spline-dim>> first *
] [
second y-min - y-max y-min - /
gadget spline-dim>> second *
] bi 2array
] map :> pts GL_LINE_STRIP [
pts
[ first2 neg gadget spline-dim>> second + glVertex2f ]
each
] do-state ;









M:: trails-gadget draw-gadget* ( GADGET -- )
T{ rgba { red 1 } { green 1 } { blue 1 } { alpha 0.4 } }
fill-color set
T{ rgba { red 0 } { green 0 } { blue 0 } { alpha 0 } }
stroke-color set COLOR: black gl-clear GADGET points>>
[ dot ] each-percent ;