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 math.vectors
5 ui.gadgets ui.gestures ui.render ui.backend ui.gadgets.tracks
6 debugger math.geometry.rect ;
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 >r >r dup parent>> dup r> r>
34 [ (request-focus) ] keep
35 ] unless focus-child ;
37 M: world request-focus-on ( child gadget -- )
39 [ 2drop ] [ dup focused?>> (request-focus) ] if ;
41 : <world> ( gadget title status -- world )
42 { 0 1 } world new-track
55 >r dup rect-dim r> (>>dim)
58 M: world focusable-child* gadget-child ;
60 M: world children-on nip children>> ;
62 : (draw-world) ( world -- )
64 [ dup init-gl ] keep draw-gadget
67 : draw-world? ( world -- ? )
68 #! We don't draw deactivated worlds, or those with 0 size.
69 #! On Windows, the latter case results in GL errors.
72 rot rect-dim [ 0 > ] all? and and ;
74 TUPLE: world-error error world ;
76 C: <world-error> world-error
80 : ui-error ( error -- )
81 ui-error-hook get [ call ] [ print-error ] if* ;
83 [ rethrow ] ui-error-hook set-global
85 : draw-world ( world -- )
91 over <world-error> ui-error
100 { T{ key-down f { C+ } "x" } [ T{ cut-action } send-action ] }
101 { T{ key-down f { C+ } "c" } [ T{ copy-action } send-action ] }
102 { T{ key-down f { C+ } "v" } [ T{ paste-action } send-action ] }
103 { T{ key-down f { C+ } "a" } [ T{ select-all-action } send-action ] }
104 { T{ button-down f { C+ } 1 } [ drop T{ button-down f f 3 } button-gesture ] }
105 { T{ button-down f { A+ } 1 } [ drop T{ button-down f f 2 } button-gesture ] }
106 { T{ button-up f { C+ } 1 } [ drop T{ button-up f f 3 } button-gesture ] }
107 { T{ button-up f { A+ } 1 } [ drop T{ button-up f f 2 } button-gesture ] }
110 : close-global ( world global -- )
111 dup get-global find-world rot eq?
112 [ f swap set-global ] [ drop ] if ;