factor/library/ui/world.factor

48 lines
1.5 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-23 02:25:08 -04:00
USING: arrays 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
2006-06-23 00:06:53 -04:00
! UI code assumes that everything starts at { 0 0 }.
TUPLE: world gadget status focus focused? fonts handle loc ;
2006-03-18 01:57:57 -05:00
: free-fonts ( world -- )
dup world-handle select-gl-context
2006-06-23 02:25:08 -04:00
world-fonts hash-values [ second free-sprites ] each ;
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
2006-06-23 00:06:53 -04:00
{ 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 )
2006-06-23 00:06:53 -04:00
delegate pref-dim* { 1024 768 } 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
2006-06-23 02:25:08 -04:00
: font-sprites ( font world -- { open-font sprites } )
world-fonts [ lookup-font V{ } clone 2array ] cache ;
: draw-string ( font string -- )
>r world get font-sprites first2 r> (draw-string) ;