1 ! Copyright (C) 2005, 2008 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
9 TUPLE: world < identity-tuple
16 : find-world ( gadget -- world ) [ world? ] find-parent ;
20 : show-status ( string/f gadget -- )
21 find-world world-status [ set-model ] [ drop ] if* ;
23 : show-summary ( object gadget -- )
24 >r [ summary ] [ "" ] if* r> show-status ;
26 : hide-status ( gadget -- ) f swap show-status ;
28 : (request-focus) ( child world ? -- )
29 pick gadget-parent pick eq? [
30 >r >r dup gadget-parent dup r> r>
31 [ (request-focus) ] keep
32 ] unless focus-child ;
34 M: world request-focus-on ( child gadget -- )
36 [ 2drop ] [ dup world-focused? (request-focus) ] if ;
38 : <world> ( gadget title status -- world )
39 t H{ } clone { 0 0 } {
47 t over set-gadget-root?
50 M: world hashcode* drop world hashcode* ;
55 >r dup rect-dim r> set-layout-dim
58 M: world focusable-child* gadget-child ;
60 M: world children-on nip gadget-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 world ;
76 : <world-error> ( error world -- error )
77 { set-delegate set-world-error-world }
78 world-error construct ;
82 : ui-error ( error -- )
83 ui-error-hook get [ call ] [ print-error ] if* ;
85 [ rethrow ] ui-error-hook set-global
87 : draw-world ( world -- )
93 over <world-error> ui-error
94 f swap set-world-active?
102 { T{ key-down f { C+ } "x" } [ T{ cut-action } send-action ] }
103 { T{ key-down f { C+ } "c" } [ T{ copy-action } send-action ] }
104 { T{ key-down f { C+ } "v" } [ T{ paste-action } send-action ] }
105 { T{ key-down f { C+ } "a" } [ T{ select-all-action } send-action ] }
106 { T{ button-down f { C+ } 1 } [ T{ button-down f f 3 } swap resend-button-down ] }
107 { T{ button-down f { A+ } 1 } [ T{ button-down f f 2 } swap resend-button-down ] }
108 { T{ button-up f { C+ } 1 } [ T{ button-up f f 3 } swap resend-button-up ] }
109 { T{ button-up f { A+ } 1 } [ T{ button-up f f 2 } swap resend-button-up ] }
112 : close-global ( world global -- )
113 dup get-global find-world rot eq?
114 [ f swap set-global ] [ drop ] if ;