factor/library/ui/world.factor

103 lines
2.7 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-03-12 23:21:01 -05:00
USING: alien arrays errors freetype gadgets-layouts
gadgets-theme generic io kernel lists math memory namespaces
opengl prettyprint sequences sequences strings styles threads ;
DEFER: redraw-world
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. The current world is stored in the
2005-07-08 01:32:29 -04:00
! world variable. The invalid slot is a list of gadgets that
! need to be layout.
2006-03-12 23:21:01 -05:00
TUPLE: world glass status invalid timers handle ;
: timers ( -- hash ) world get world-timers ;
2005-08-26 00:55:56 -04:00
: add-layer ( gadget -- )
world get add-gadget ;
2005-01-31 22:32:06 -05:00
C: world ( -- world )
<stack> over set-delegate
2006-03-15 00:24:00 -05:00
dup solid-interior
t over set-gadget-root?
H{ } clone over set-world-timers ;
2005-10-08 01:15:14 -04:00
: add-invalid ( gadget -- )
world get [ world-invalid cons ] keep set-world-invalid ;
2005-07-08 01:32:29 -04:00
: pop-invalid ( -- list )
world get [ world-invalid f ] keep set-world-invalid ;
2005-07-08 01:32:29 -04:00
: layout-world ( -- )
world get world-invalid
[ pop-invalid [ layout ] each layout-world ] when ;
2005-07-08 01:32:29 -04:00
: hide-glass ( -- )
2005-10-01 01:44:49 -04:00
f world get dup world-glass unparent set-world-glass ;
: show-glass ( gadget -- )
hide-glass
2005-08-26 22:22:00 -04:00
<gadget> dup add-layer dup world get set-world-glass
dupd add-gadget prefer ;
2005-10-08 01:15:14 -04:00
! Status bar protocol
GENERIC: set-message ( string/f status -- )
M: f set-message 2drop ;
: show-message ( string/f -- )
#! Show a message in the status bar.
world get world-status set-message ;
: relevant-help ( -- string )
hand get hand-gadget
parents [ gadget-help ] map [ ] find nip ;
2005-10-08 01:15:14 -04:00
: update-help ( -- )
#! Update mouse-over help message.
relevant-help show-message ;
2005-02-01 19:00:16 -05:00
2005-10-09 21:27:14 -04:00
: under-hand ( -- seq )
#! A sequence whose first element is the world and last is
#! the current gadget, with all parents in between.
hand get hand-gadget parents reverse-slice ;
: hand-grab ( -- gadget )
hand get rect-loc world get pick-up ;
2005-11-15 12:58:44 -05:00
: update-hand-gadget ( -- )
hand-grab hand get set-hand-gadget ;
2005-10-08 01:15:14 -04:00
: move-hand ( loc -- )
2005-10-09 21:27:14 -04:00
under-hand >r hand get set-rect-loc
2005-11-14 01:54:40 -05:00
update-hand-gadget
2005-10-09 21:27:14 -04:00
under-hand r> hand-gestures update-help ;
2005-10-07 20:26:21 -04:00
2005-10-08 01:15:14 -04:00
: update-hand ( -- )
2005-10-07 20:26:21 -04:00
#! Called when a gadget is removed or added.
2005-10-08 01:15:14 -04:00
hand get rect-loc move-hand ;
2005-10-07 20:26:21 -04:00
: ui-title
[ "Factor " % version % " - " % image % ] "" make ;
: world-step ( -- )
2006-03-12 23:21:01 -05:00
do-timers
2005-10-08 01:15:14 -04:00
world get world-invalid >r layout-world r>
2006-03-13 00:41:59 -05:00
[ update-hand world get redraw-world ] when ;
2006-03-12 23:21:01 -05:00
SYMBOL: first-time
global [ first-time on ] bind
: init-world ( -- )
global [
first-time get [
<world> world set
{ 600 700 0 } world get set-gadget-dim
<hand> hand set
first-time off
] when
] bind ;