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-17 03:21:54 -05:00
|
|
|
USING: alien arrays errors freetype gadgets-labels
|
|
|
|
gadgets-layouts gadgets-theme generic io kernel lists math
|
|
|
|
memory namespaces opengl prettyprint queues sequences sequences
|
|
|
|
strings styles threads ;
|
2006-03-12 23:21:01 -05:00
|
|
|
|
|
|
|
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-15 18:24:59 -05:00
|
|
|
TUPLE: world glass status handle ;
|
2005-08-26 00:55:56 -04:00
|
|
|
|
2006-03-17 03:21:54 -05:00
|
|
|
C: world ( gadget status dim -- world )
|
2006-01-20 01:26:50 -05:00
|
|
|
<stack> over set-delegate
|
2006-03-17 03:21:54 -05:00
|
|
|
t over set-gadget-root?
|
2006-03-15 18:24:59 -05:00
|
|
|
[ set-gadget-dim ] keep
|
2006-03-17 03:21:54 -05:00
|
|
|
[ set-world-status ] keep
|
|
|
|
[ add-gadget ] keep ;
|
2005-07-08 01:32:29 -04:00
|
|
|
|
2006-03-17 03:21:54 -05:00
|
|
|
: hide-glass ( world -- )
|
|
|
|
dup world-glass unparent f swap set-world-glass ;
|
2005-06-27 16:50:21 -04:00
|
|
|
|
2006-03-17 03:21:54 -05:00
|
|
|
: <glass> ( gadget -- glass )
|
|
|
|
<gadget> 2dup add-gadget swap prefer ;
|
2005-07-12 20:30:05 -04:00
|
|
|
|
2006-03-17 03:21:54 -05:00
|
|
|
: show-glass ( gadget world -- )
|
|
|
|
dup hide-glass
|
|
|
|
>r <glass> r> 2dup add-gadget
|
|
|
|
set-world-glass ;
|
2005-10-08 01:15:14 -04:00
|
|
|
|
2006-03-17 03:21:54 -05:00
|
|
|
: relevant-help ( seq -- help )
|
|
|
|
[ gadget-help ] map [ ] find nip ;
|
2005-10-08 01:15:14 -04:00
|
|
|
|
|
|
|
: show-message ( string/f -- )
|
|
|
|
#! Show a message in the status bar.
|
2006-03-17 03:21:54 -05:00
|
|
|
world-status set-label-text* ;
|
2005-12-22 18:38:10 -05:00
|
|
|
|
2006-03-17 03:21:54 -05:00
|
|
|
: update-help ( -- string )
|
2005-10-08 01:15:14 -04:00
|
|
|
#! Update mouse-over help message.
|
2006-03-17 03:21:54 -05:00
|
|
|
hand get hand-gadget parents [ relevant-help ] keep
|
|
|
|
dup empty? [ 2drop ] [ peek show-message ] if ;
|
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 ;
|
|
|
|
|
2006-03-17 03:21:54 -05:00
|
|
|
: hand-grab ( world -- gadget )
|
|
|
|
hand get rect-loc swap pick-up ;
|
2005-10-09 21:27:14 -04:00
|
|
|
|
2006-03-17 03:21:54 -05:00
|
|
|
: update-hand-gadget ( world -- )
|
2005-11-15 12:58:44 -05:00
|
|
|
hand-grab hand get set-hand-gadget ;
|
|
|
|
|
2006-03-17 03:21:54 -05:00
|
|
|
: move-hand ( loc world -- )
|
|
|
|
swap 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
|
|
|
|
2006-03-17 03:21:54 -05:00
|
|
|
: update-hand ( world -- )
|
2005-10-07 20:26:21 -04:00
|
|
|
#! Called when a gadget is removed or added.
|
2006-03-17 03:21:54 -05:00
|
|
|
hand get rect-loc swap move-hand ;
|
2005-10-07 20:26:21 -04:00
|
|
|
|
2006-03-17 19:47:35 -05:00
|
|
|
: world-step ( world -- )
|
|
|
|
do-timers invalid queue-empty? >r layout-queued r>
|
|
|
|
[ drop ] [ dup update-hand redraw-world ] if ;
|
2005-10-07 20:26:21 -04:00
|
|
|
|
2006-03-17 19:47:35 -05:00
|
|
|
GENERIC: find-world ( gadget -- world )
|
|
|
|
|
|
|
|
M: f find-world ;
|
|
|
|
|
|
|
|
M: gadget find-world gadget-parent find-world ;
|
|
|
|
|
|
|
|
M: world find-world ;
|