1 ! Copyright (C) 2009 Eduardo Cavazos
2 ! See http://factorcode.org/license.txt for BSD license.
4 USING: accessors arrays combinators kernel math opengl opengl.gl
5 sequences ui.gadgets ui.gadgets.worlds ui.render ;
9 TUPLE: slate < gadget action pdim graft ungraft ;
11 : init-slate ( slate -- slate )
17 : <slate> ( action -- slate )
22 M: slate pref-dim* ( slate -- dim ) pdim>> ;
24 : width ( rect -- w ) dim>> first ;
26 : height ( rect -- h ) dim>> second ;
28 : screen-y* ( gadget -- loc )
29 [ find-world height ] [ screen-loc second ] [ height ] tri + - ;
31 : screen-loc* ( gadget -- loc )
32 [ screen-loc first ] [ screen-y* ] bi 2array ;
34 : setup-viewport ( gadget -- gadget )
35 dup { [ screen-loc* ] [ dim>> ] } cleave gl-viewport ;
37 : default-coordinate-system ( gadget -- gadget )
39 [ drop 0 ] [ width 1 - ] [ height 1 - ] [ drop 0 ]
40 } cleave -1 1 glOrtho ;
42 M: slate graft* graft>> call( -- ) ;
44 M: slate ungraft* ungraft>> call( -- ) ;
46 GENERIC: establish-coordinate-system ( gadget -- gadget )
48 M: slate establish-coordinate-system default-coordinate-system ;
50 GENERIC: draw-slate ( slate -- slate )
52 M: slate draw-slate dup action>> call( slate -- slate ) ;
54 M: slate draw-gadget* ( slate -- )
56 GL_PROJECTION glMatrixMode glPushMatrix glLoadIdentity
58 establish-coordinate-system
60 GL_MODELVIEW glMatrixMode glPushMatrix glLoadIdentity
66 GL_PROJECTION glMatrixMode glPopMatrix glLoadIdentity
67 GL_MODELVIEW glMatrixMode glPopMatrix glLoadIdentity
71 ! The world coordinate system is a little wacky:
72 dup { [ drop 0 ] [ width ] [ height ] [ drop 0 ] } cleave -1 1 glOrtho