1 ! Copyright (C) 2005, 2006 Slava Pestov.
2 ! See http://factorcode.org/license.txt for BSD license.
4 USING: arrays errors freetype gadgets-frames generic hashtables
5 kernel math models namespaces opengl sequences ;
7 ! The world gadget is the top level gadget that all (visible)
8 ! gadgets are contained in. There is one world per top-level
11 ! fonts: mapping font tuples to sprite vectors
12 ! handle: native resource
13 ! loc: location of native window on the screen.
14 ! we don't store this in the world's rect-loc, since the
15 ! co-ordinate system might be different, and generally the
16 ! UI code assumes that everything starts at { 0 0 }.
27 : free-fonts ( world -- )
28 dup world-handle select-gl-context
29 world-fonts hash-values [ second free-sprites ] each ;
33 C: world ( gadget -- world )
34 f <model> over set-world-status
35 [ >r dup gadget-title r> set-world-title ] keep
36 { { f set-world-gadget f @center } } make-frame*
37 t over set-gadget-root?
38 t over set-world-active?
39 H{ } clone over set-world-fonts
40 { 0 0 } over set-world-loc
41 dup world-gadget request-focus ;
43 : find-world [ world? ] find-parent ;
46 delegate pref-dim* [ >fixnum ] map { 1024 768 } vmin ;
49 dup dup world-title add-connection
50 dup dup world-status add-connection
55 dup world-title remove-connection
56 dup world-status remove-connection ;
58 M: world model-changed
59 dup world-title model-value swap set-title ;
61 : focused-ancestors ( world -- seq )
62 world-focus parents <reversed> ;
64 : font-sprites ( font world -- pair )
65 world-fonts [ lookup-font V{ } clone 2array ] cache ;
67 : draw-string ( font string -- )
68 >r world get font-sprites first2 r> (draw-string) ;
70 M: world gadget-title world-gadget gadget-title ;
75 >r dup rect-dim r> set-layout-dim
78 : hide-glass ( world -- )
79 f menu-mode? set-global
80 dup world-glass [ unparent ] when*
81 f swap set-world-glass ;
83 : show-glass ( gadget world -- )