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 : (request-focus) ( child world ? -- )
26 pick parent>> pick eq? [
27 >r >r dup parent>> dup r> r>
28 [ (request-focus) ] keep
29 ] unless focus-child ;
31 M: world request-focus-on ( child gadget -- )
33 [ 2drop ] [ dup focused?>> (request-focus) ] if ;
35 : <world> ( gadget title status -- world )
36 { 0 1 } world new-track
49 >r dup rect-dim r> (>>dim)
52 M: world focusable-child* gadget-child ;
54 M: world children-on nip children>> ;
56 : (draw-world) ( world -- )
58 [ dup init-gl ] keep draw-gadget
61 : draw-world? ( world -- ? )
62 #! We don't draw deactivated worlds, or those with 0 size.
63 #! On Windows, the latter case results in GL errors.
66 rot rect-dim [ 0 > ] all? and and ;
68 TUPLE: world-error error world ;
70 C: <world-error> world-error
74 : ui-error ( error -- )
75 ui-error-hook get [ call ] [ print-error ] if* ;
77 [ rethrow ] ui-error-hook set-global
79 : draw-world ( world -- )
85 over <world-error> ui-error
94 { T{ key-down f { C+ } "x" } [ T{ cut-action } send-action ] }
95 { T{ key-down f { C+ } "c" } [ T{ copy-action } send-action ] }
96 { T{ key-down f { C+ } "v" } [ T{ paste-action } send-action ] }
97 { T{ key-down f { C+ } "a" } [ T{ select-all-action } send-action ] }
98 { T{ button-down f { C+ } 1 } [ T{ button-down f f 3 } swap resend-button-down ] }
99 { T{ button-down f { A+ } 1 } [ T{ button-down f f 2 } swap resend-button-down ] }
100 { T{ button-up f { C+ } 1 } [ T{ button-up f f 3 } swap resend-button-up ] }
101 { T{ button-up f { A+ } 1 } [ T{ button-up f f 2 } swap resend-button-up ] }
104 : close-global ( world global -- )
105 dup get-global find-world rot eq?
106 [ f swap set-global ] [ drop ] if ;