factor/library/ui/world.factor

53 lines
1.6 KiB
Factor
Raw Normal View History

2006-03-12 23:21:01 -05:00
! Copyright (C) 2005, 2006 Slava Pestov.
! See http://factorcode.org/license.txt for BSD license.
2005-01-31 22:32:06 -05:00
IN: gadgets
2006-06-07 23:51:28 -04:00
USING: errors freetype gadgets-frames generic hashtables kernel
math namespaces opengl sequences ;
2005-02-01 19:00:16 -05:00
2005-01-31 22:32:06 -05:00
! The world gadget is the top level gadget that all (visible)
! gadgets are contained in. There is one world per top-level
! native window.
2006-03-18 01:57:57 -05:00
! fonts: mapping font tuples to sprite vectors
! handle: native resource
! loc: location of native window on the screen.
! we don't store this in the world's rect-loc, since the
! co-ordinate system might be different, and generally the
! UI code assumes that everything starts at { 0 0 0 }.
TUPLE: world gadget status focus fonts handle loc ;
2006-03-18 01:57:57 -05:00
: free-fonts ( world -- )
dup world-handle select-gl-context
world-fonts hash-values [ free-sprites ] each ;
2006-03-18 01:57:57 -05:00
: font-sprites ( font world -- sprites )
world-fonts [ drop V{ } clone ] cache ;
2005-08-26 00:55:56 -04:00
2006-03-25 01:06:52 -05:00
DEFER: request-focus
C: world ( gadget status -- world )
2006-05-19 22:29:01 -04:00
{
{ [ ] set-world-status @bottom }
{ [ ] set-world-gadget @center }
} make-frame*
t over set-gadget-root?
2006-03-18 01:57:57 -05:00
H{ } clone over set-world-fonts
dup world-gadget request-focus
{ 0 0 0 } over set-world-loc ;
2005-07-08 01:32:29 -04:00
2006-05-22 21:55:28 -04:00
: find-world [ world? ] find-parent ;
2006-03-17 20:24:28 -05:00
M: world pref-dim* ( world -- dim )
delegate pref-dim* { 1024 768 0 } vmin ;
2006-03-19 01:07:36 -05:00
: focused-ancestors ( world -- seq )
2006-05-14 23:25:34 -04:00
world-focus parents <reversed> ;
2006-04-01 19:51:48 -05:00
: draw-string ( open-fonts string -- )
>r dup world get font-sprites r> (draw-string) ;
: reset-world ( world -- )
f over set-world-focus
f over set-world-handle
world-fonts clear-hash ;