2019-10-18 09:05:08 -04:00
|
|
|
! Copyright (C) 2006, 2007 Slava Pestov.
|
2019-10-18 09:05:04 -04:00
|
|
|
! See http://factorcode.org/license.txt for BSD license.
|
|
|
|
|
IN: gadgets
|
|
|
|
|
USING: arrays errors gadgets gadgets-buttons
|
|
|
|
|
gadgets-labels gadgets-panes gadgets-presentations
|
|
|
|
|
gadgets-scrolling gadgets-theme gadgets-viewports gadgets-lists
|
2019-10-18 09:05:08 -04:00
|
|
|
generic assocs io kernel math models namespaces prettyprint
|
2019-10-18 09:05:04 -04:00
|
|
|
queues sequences test threads sequences words timers ;
|
|
|
|
|
|
|
|
|
|
: update-hand ( world -- )
|
|
|
|
|
dup hand-world get-global eq?
|
|
|
|
|
[ hand-loc get-global swap move-hand ] [ drop ] if ;
|
|
|
|
|
|
2019-10-18 09:05:08 -04:00
|
|
|
: post-layout ( hash gadget -- )
|
|
|
|
|
dup find-world dup [
|
|
|
|
|
rot [
|
|
|
|
|
>r screen-rect r> [ rect-union ] when*
|
|
|
|
|
] change-at
|
|
|
|
|
] [
|
|
|
|
|
3drop
|
|
|
|
|
] if ;
|
2019-10-18 09:05:04 -04:00
|
|
|
|
|
|
|
|
: layout-queued ( -- hash )
|
2019-10-18 09:05:08 -04:00
|
|
|
H{ } clone invalid [
|
|
|
|
|
dup layout dupd post-layout
|
|
|
|
|
] queue-each ;
|
2019-10-18 09:05:04 -04:00
|
|
|
|
|
|
|
|
SYMBOL: ui-hook
|
|
|
|
|
|
|
|
|
|
: init-ui ( -- )
|
|
|
|
|
<queue> \ invalid set-global
|
|
|
|
|
V{ } clone windows set-global ;
|
|
|
|
|
|
|
|
|
|
: start-ui ( -- )
|
|
|
|
|
init-timers
|
|
|
|
|
restore-windows? [
|
|
|
|
|
restore-windows
|
|
|
|
|
] [
|
|
|
|
|
init-ui ui-hook get-global call
|
|
|
|
|
] if ;
|
|
|
|
|
|
2019-10-18 09:05:08 -04:00
|
|
|
: draw-world? ( world -- ? )
|
|
|
|
|
#! We don't draw deactivated worlds, or those with 0 size.
|
|
|
|
|
#! On Windows, the latter case results in GL errors.
|
|
|
|
|
dup world-active?
|
|
|
|
|
over world-handle
|
|
|
|
|
rot rect-dim [ zero? not ] all? and and ;
|
2019-10-18 09:05:04 -04:00
|
|
|
|
|
|
|
|
TUPLE: world-error world ;
|
|
|
|
|
|
|
|
|
|
C: world-error ( error world -- error )
|
|
|
|
|
[ set-world-error-world ] keep
|
|
|
|
|
[ set-delegate ] keep ;
|
|
|
|
|
|
|
|
|
|
M: world-error error.
|
|
|
|
|
"An error occurred while drawing the world " write
|
|
|
|
|
dup world-error-world pprint-short "." print
|
|
|
|
|
"This world has been deactivated to prevent cascading errors." print
|
|
|
|
|
delegate error. ;
|
|
|
|
|
|
2019-10-18 09:05:08 -04:00
|
|
|
: draw-world ( rect world -- )
|
2019-10-18 09:05:04 -04:00
|
|
|
dup draw-world? [
|
|
|
|
|
[
|
|
|
|
|
dup world set [
|
2019-10-18 09:05:08 -04:00
|
|
|
(draw-world)
|
2019-10-18 09:05:04 -04:00
|
|
|
] [
|
|
|
|
|
over <world-error> debugger-window
|
2019-10-18 09:05:08 -04:00
|
|
|
f swap set-world-active?
|
|
|
|
|
drop
|
2019-10-18 09:05:04 -04:00
|
|
|
] recover
|
|
|
|
|
] with-scope
|
2019-10-18 09:05:08 -04:00
|
|
|
] [
|
|
|
|
|
2drop
|
|
|
|
|
] if ;
|
|
|
|
|
|
|
|
|
|
: redraw-worlds ( hash -- )
|
|
|
|
|
[
|
|
|
|
|
swap dup update-hand
|
|
|
|
|
dup world-handle [ draw-world ] [ 2drop ] if
|
|
|
|
|
] assoc-each ;
|
|
|
|
|
|
|
|
|
|
: ui-step ( -- )
|
|
|
|
|
[
|
|
|
|
|
do-timers layout-queued redraw-worlds 10 sleep
|
|
|
|
|
] assert-depth ;
|
2019-10-18 09:05:04 -04:00
|
|
|
|
|
|
|
|
IN: shells
|
|
|
|
|
|
|
|
|
|
DEFER: ui
|