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 : find-world ( gadget -- world/f ) [ world? ] find-parent ;
18 : show-status ( string/f gadget -- )
20 status>> dup [ set-model ] [ 2drop ] if
23 : hide-status ( gadget -- ) f swap show-status ;
25 ERROR: no-world-found ;
27 : find-gl-context ( gadget -- )
29 [ handle>> select-gl-context ] [ no-world-found ] if ;
31 : (request-focus) ( child world ? -- )
32 pick parent>> pick eq? [
33 [ dup parent>> dup ] 2dip
34 [ (request-focus) ] keep
35 ] unless focus-child ;
37 M: world request-focus-on ( child gadget -- )
39 [ 2drop ] [ dup focused?>> (request-focus) ] if ;
41 : new-world ( gadget title status class -- world )
42 { 0 1 } swap new-track
52 : <world> ( gadget title status -- world )
58 [ dup rect-dim ] dip (>>dim)
61 M: world focusable-child* gadget-child ;
63 M: world children-on nip children>> ;
65 : (draw-world) ( world -- )
67 [ dup init-gl ] keep draw-gadget
70 : draw-world? ( world -- ? )
71 #! We don't draw deactivated worlds, or those with 0 size.
72 #! On Windows, the latter case results in GL errors.
73 [ active?>> ] [ handle>> ] [ dim>> [ 0 > ] all? ] tri and and ;
75 TUPLE: world-error error world ;
77 C: <world-error> world-error
81 : ui-error ( error -- )
82 ui-error-hook get [ call ] [ die ] if* ;
84 ui-error-hook [ [ rethrow ] ] initialize
86 : draw-world ( world -- )
92 over <world-error> ui-error
101 { T{ key-down f { C+ } "x" } [ T{ cut-action } send-action ] }
102 { T{ key-down f { C+ } "c" } [ T{ copy-action } send-action ] }
103 { T{ key-down f { C+ } "v" } [ T{ paste-action } send-action ] }
104 { T{ key-down f { C+ } "a" } [ T{ select-all-action } send-action ] }
105 { T{ button-down f { C+ } 1 } [ drop T{ button-down f f 3 } button-gesture ] }
106 { T{ button-down f { A+ } 1 } [ drop T{ button-down f f 2 } button-gesture ] }
107 { T{ button-down f { M+ } 1 } [ drop T{ button-down f f 2 } button-gesture ] }
108 { T{ button-up f { C+ } 1 } [ drop T{ button-up f f 3 } button-gesture ] }
109 { T{ button-up f { A+ } 1 } [ drop T{ button-up f f 2 } button-gesture ] }
110 { T{ button-up f { M+ } 1 } [ drop T{ button-up f f 2 } button-gesture ] }
113 PREDICATE: specific-button-up < button-up #>> ;
114 PREDICATE: specific-button-down < button-down #>> ;
115 PREDICATE: specific-drag < drag #>> ;
117 : generalize-gesture ( gesture -- )
118 clone f >># button-gesture ;
120 M: world handle-gesture ( gesture gadget -- ? )
121 2dup call-next-method [
123 { [ over specific-button-up? ] [ drop generalize-gesture f ] }
124 { [ over specific-button-down? ] [ drop generalize-gesture f ] }
125 { [ over specific-drag? ] [ drop generalize-gesture f ] }
130 : close-global ( world global -- )
131 [ get-global find-world eq? ] keep '[ f _ set-global ] when ;