1 ! Copyright (C) 2005, 2008 Slava Pestov.
2 ! See http://factorcode.org/license.txt for BSD license.
3 USING: accessors arrays assocs continuations kernel math models
4 namespaces opengl sequences io combinators fry math.vectors
5 ui.gadgets ui.gestures ui.render ui.backend ui.gadgets.tracks
16 TUPLE: offscreen-world < world ;
18 : find-world ( gadget -- world/f ) [ world? ] find-parent ;
20 : show-status ( string/f gadget -- )
22 status>> dup [ set-model ] [ 2drop ] if
25 : hide-status ( gadget -- ) f swap show-status ;
27 ERROR: no-world-found ;
29 : find-gl-context ( gadget -- )
31 [ handle>> select-gl-context ] [ no-world-found ] if ;
33 : (request-focus) ( child world ? -- )
34 pick parent>> pick eq? [
35 [ dup parent>> dup ] 2dip
36 [ (request-focus) ] keep
37 ] unless focus-child ;
39 M: world request-focus-on ( child gadget -- )
41 [ 2drop ] [ dup focused?>> (request-focus) ] if ;
43 : new-world ( gadget title status class -- world )
44 { 0 1 } swap new-track
54 : <world> ( gadget title status -- world )
56 : <offscreen-world> ( gadget title status -- world )
57 offscreen-world new-world ;
62 [ dup rect-dim ] dip (>>dim)
65 M: world focusable-child* gadget-child ;
67 M: world children-on nip children>> ;
69 : (draw-world) ( world -- )
71 [ dup init-gl ] keep draw-gadget
74 : draw-world? ( world -- ? )
75 #! We don't draw deactivated worlds, or those with 0 size.
76 #! On Windows, the latter case results in GL errors.
77 [ active?>> ] [ handle>> ] [ dim>> [ 0 > ] all? ] tri and and ;
79 TUPLE: world-error error world ;
81 C: <world-error> world-error
85 : ui-error ( error -- )
86 ui-error-hook get [ call ] [ die ] if* ;
88 ui-error-hook global [ [ rethrow ] or ] change-at
90 : draw-world ( world -- )
96 over <world-error> ui-error
105 { T{ key-down f { C+ } "x" } [ T{ cut-action } send-action ] }
106 { T{ key-down f { C+ } "c" } [ T{ copy-action } send-action ] }
107 { T{ key-down f { C+ } "v" } [ T{ paste-action } send-action ] }
108 { T{ key-down f { C+ } "a" } [ T{ select-all-action } send-action ] }
109 { T{ button-down f { C+ } 1 } [ drop T{ button-down f f 3 } button-gesture ] }
110 { T{ button-down f { A+ } 1 } [ drop T{ button-down f f 2 } button-gesture ] }
111 { T{ button-down f { M+ } 1 } [ drop T{ button-down f f 2 } button-gesture ] }
112 { T{ button-up f { C+ } 1 } [ drop T{ button-up f f 3 } button-gesture ] }
113 { T{ button-up f { A+ } 1 } [ drop T{ button-up f f 2 } button-gesture ] }
114 { T{ button-up f { M+ } 1 } [ drop T{ button-up f f 2 } button-gesture ] }
117 PREDICATE: specific-button-up < button-up #>> ;
118 PREDICATE: specific-button-down < button-down #>> ;
119 PREDICATE: specific-drag < drag #>> ;
121 : generalize-gesture ( gesture -- )
122 clone f >># button-gesture ;
124 M: world handle-gesture ( gesture gadget -- ? )
125 2dup call-next-method [
127 { [ over specific-button-up? ] [ drop generalize-gesture f ] }
128 { [ over specific-button-down? ] [ drop generalize-gesture f ] }
129 { [ over specific-drag? ] [ drop generalize-gesture f ] }
134 : close-global ( world global -- )
135 [ get-global find-world eq? ] keep '[ f _ set-global ] when ;