factor/library/ui/world.factor

87 lines
2.3 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 models 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 }.
2006-07-18 02:26:17 -04:00
TUPLE: world
active?
2006-10-07 02:17:32 -04:00
gadget glass
2006-07-18 02:26:17 -04:00
title status
focus focused?
fonts handle
loc ;
2006-03-18 01:57:57 -05:00
2006-10-10 01:07:11 -04:00
SYMBOL: menu-mode?
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 -- world )
f <model> over set-world-status
2006-07-11 00:57:46 -04:00
[ >r dup gadget-title r> set-world-title ] keep
{ { f set-world-gadget f @center } } make-frame*
t over set-gadget-root?
2006-07-18 02:26:17 -04:00
t over set-world-active?
2006-03-18 01:57:57 -05:00
H{ } clone over set-world-fonts
2006-07-11 00:57:46 -04:00
{ 0 0 } over set-world-loc
dup world-gadget request-focus ;
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*
2006-08-23 22:14:53 -04:00
delegate pref-dim* [ >fixnum ] map { 1024 768 } vmin ;
M: world graft*
2006-10-04 00:40:10 -04:00
dup dup world-title add-connection
dup dup world-status add-connection
2006-07-05 17:12:30 -04:00
model-changed ;
M: world ungraft*
2006-07-05 17:12:30 -04:00
dup
2006-10-04 00:40:10 -04:00
dup world-title remove-connection
dup world-status remove-connection ;
2006-07-05 17:12:30 -04:00
M: world model-changed
2006-07-05 17:12:30 -04:00
dup world-title model-value swap set-title ;
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-08-15 04:57:12 -04:00
: font-sprites ( font world -- pair )
2006-06-23 02:25:08 -04:00
world-fonts [ lookup-font V{ } clone 2array ] cache ;
: draw-string ( font string -- )
>r world get font-sprites first2 r> (draw-string) ;
2006-07-11 00:57:46 -04:00
M: world gadget-title world-gadget gadget-title ;
2006-10-07 02:17:32 -04:00
M: world layout*
dup delegate layout*
dup world-glass [
>r dup rect-dim r> set-layout-dim
] when* drop ;
: hide-glass ( world -- )
2006-10-09 23:57:32 -04:00
f menu-mode? set-global
2006-10-07 02:17:32 -04:00
dup world-glass [ unparent ] when*
f swap set-world-glass ;
: show-glass ( gadget world -- )
[ hide-glass ] keep
[ add-gadget ] 2keep
set-world-glass ;