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 }.
25 : free-fonts ( world -- )
26 dup world-handle select-gl-context
27 world-fonts hash-values [ second free-sprites ] each ;
31 C: world ( gadget -- world )
32 f <model> over set-world-status
33 [ >r dup gadget-title r> set-world-title ] keep
34 { { f set-world-gadget f @center } } make-frame*
35 t over set-gadget-root?
36 t over set-world-active?
37 H{ } clone over set-world-fonts
38 { 0 0 } over set-world-loc
39 dup world-gadget request-focus ;
41 : find-world [ world? ] find-parent ;
44 delegate pref-dim* [ >fixnum ] map { 1024 768 } vmin ;
47 dup dup world-title add-connection
48 dup dup world-status add-connection
53 dup world-title remove-connection
54 dup world-status remove-connection ;
56 M: world model-changed
57 dup world-title model-value swap set-title ;
59 : focused-ancestors ( world -- seq )
60 world-focus parents <reversed> ;
62 : font-sprites ( font world -- pair )
63 world-fonts [ lookup-font V{ } clone 2array ] cache ;
65 : draw-string ( font string -- )
66 >r world get font-sprites first2 r> (draw-string) ;
68 M: world gadget-title world-gadget gadget-title ;