1 ! Copyright (C) 2005, 2007 Slava Pestov.
2 ! See http://factorcode.org/license.txt for BSD license.
3 USING: arrays assocs continuations kernel math models
4 namespaces opengl sequences io combinators math.vectors
5 ui.gadgets ui.gestures ui.render ui.backend inspector ;
8 TUPLE: world < identity-tuple
15 : find-world [ world? ] find-parent ;
19 : show-status ( string/f gadget -- )
20 find-world world-status [ set-model ] [ drop ] if* ;
22 : show-summary ( object gadget -- )
23 >r [ summary ] [ "" ] if* r> show-status ;
25 : hide-status ( gadget -- ) f swap show-status ;
27 : (request-focus) ( child world ? -- )
28 pick gadget-parent pick eq? [
29 >r >r dup gadget-parent dup r> r>
30 [ (request-focus) ] keep
31 ] unless focus-child ;
33 M: world request-focus-on ( child gadget -- )
35 [ 2drop ] [ dup world-focused? (request-focus) ] if ;
37 : <world> ( gadget title status -- world )
38 t H{ } clone { 0 0 } {
46 t over set-gadget-root?
49 M: world hashcode* drop world hashcode* ;
54 >r dup rect-dim r> set-layout-dim
57 M: world focusable-child* gadget-child ;
59 M: world children-on nip gadget-children ;
61 : (draw-world) ( world -- )
63 [ dup init-gl ] keep draw-gadget
66 : draw-world? ( world -- ? )
67 #! We don't draw deactivated worlds, or those with 0 size.
68 #! On Windows, the latter case results in GL errors.
71 rot rect-dim [ 0 > ] all? and and ;
73 TUPLE: world-error world ;
75 : <world-error> ( error world -- error )
76 { set-delegate set-world-error-world }
77 world-error construct ;
81 : ui-error ( error -- ) ui-error-hook get call ;
83 [ rethrow ] ui-error-hook set-global
85 : draw-world ( world -- )
91 over <world-error> ui-error
92 f swap set-world-active?
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 } [ T{ button-down f f 3 } swap resend-button-down ] }
105 { T{ button-down f { A+ } 1 } [ T{ button-down f f 2 } swap resend-button-down ] }
106 { T{ button-up f { C+ } 1 } [ T{ button-up f f 3 } swap resend-button-up ] }
107 { T{ button-up f { A+ } 1 } [ T{ button-up f f 2 } swap resend-button-up ] }
110 : close-global ( world global -- )
111 dup get-global find-world rot eq?
112 [ f swap set-global ] [ drop ] if ;