2008-06-25 23:06:34 -04:00
|
|
|
! Copyright (C) 2005, 2008 Slava Pestov.
|
2007-09-20 18:09:08 -04:00
|
|
|
! See http://factorcode.org/license.txt for BSD license.
|
2008-07-10 21:32:17 -04:00
|
|
|
USING: accessors arrays assocs continuations kernel math models
|
2007-09-20 18:09:08 -04:00
|
|
|
namespaces opengl sequences io combinators math.vectors
|
2008-07-10 21:32:17 -04:00
|
|
|
ui.gadgets ui.gestures ui.render ui.backend ui.gadgets.tracks
|
2008-07-11 19:34:43 -04:00
|
|
|
debugger math.geometry.rect ;
|
2007-09-20 18:09:08 -04:00
|
|
|
IN: ui.gadgets.worlds
|
|
|
|
|
2008-07-10 21:32:17 -04:00
|
|
|
TUPLE: world < track
|
2007-09-20 18:09:08 -04:00
|
|
|
active? focused?
|
|
|
|
glass
|
|
|
|
title status
|
|
|
|
fonts handle
|
2008-07-10 21:32:17 -04:00
|
|
|
window-loc ;
|
2007-09-20 18:09:08 -04:00
|
|
|
|
2008-09-01 23:45:40 -04:00
|
|
|
: find-world ( gadget -- world/f ) [ world? ] find-parent ;
|
2007-09-20 18:09:08 -04:00
|
|
|
|
|
|
|
: show-status ( string/f gadget -- )
|
2008-09-01 23:45:40 -04:00
|
|
|
find-world dup [ status>> set-model ] [ 2drop ] if ;
|
2007-09-20 18:09:08 -04:00
|
|
|
|
|
|
|
: hide-status ( gadget -- ) f swap show-status ;
|
|
|
|
|
|
|
|
: (request-focus) ( child world ? -- )
|
2008-08-29 19:44:19 -04:00
|
|
|
pick parent>> pick eq? [
|
|
|
|
>r >r dup parent>> dup r> r>
|
2007-09-20 18:09:08 -04:00
|
|
|
[ (request-focus) ] keep
|
|
|
|
] unless focus-child ;
|
|
|
|
|
|
|
|
M: world request-focus-on ( child gadget -- )
|
|
|
|
2dup eq?
|
2008-08-31 02:42:30 -04:00
|
|
|
[ 2drop ] [ dup focused?>> (request-focus) ] if ;
|
2007-09-20 18:09:08 -04:00
|
|
|
|
|
|
|
: <world> ( gadget title status -- world )
|
2008-07-10 21:32:17 -04:00
|
|
|
{ 0 1 } world new-track
|
|
|
|
t >>root?
|
|
|
|
t >>active?
|
|
|
|
H{ } clone >>fonts
|
|
|
|
{ 0 0 } >>window-loc
|
|
|
|
swap >>status
|
|
|
|
swap >>title
|
2008-07-24 17:16:13 -04:00
|
|
|
swap 1 track-add
|
2007-09-20 18:09:08 -04:00
|
|
|
dup request-focus ;
|
|
|
|
|
|
|
|
M: world layout*
|
2008-07-10 21:32:17 -04:00
|
|
|
dup call-next-method
|
2008-08-31 02:42:30 -04:00
|
|
|
dup glass>> [
|
2008-07-21 18:18:17 -04:00
|
|
|
>r dup rect-dim r> (>>dim)
|
2007-09-20 18:09:08 -04:00
|
|
|
] when* drop ;
|
|
|
|
|
|
|
|
M: world focusable-child* gadget-child ;
|
|
|
|
|
2008-08-29 19:44:19 -04:00
|
|
|
M: world children-on nip children>> ;
|
2007-09-20 18:09:08 -04:00
|
|
|
|
2007-10-21 18:10:27 -04:00
|
|
|
: (draw-world) ( world -- )
|
2008-08-31 02:42:30 -04:00
|
|
|
dup handle>> [
|
2007-10-21 18:10:27 -04:00
|
|
|
[ dup init-gl ] keep draw-gadget
|
2007-09-20 18:09:08 -04:00
|
|
|
] with-gl-context ;
|
|
|
|
|
|
|
|
: draw-world? ( world -- ? )
|
|
|
|
#! We don't draw deactivated worlds, or those with 0 size.
|
|
|
|
#! On Windows, the latter case results in GL errors.
|
2008-08-31 02:42:30 -04:00
|
|
|
dup active?>>
|
|
|
|
over handle>>
|
2007-09-20 18:09:08 -04:00
|
|
|
rot rect-dim [ 0 > ] all? and and ;
|
|
|
|
|
2008-07-11 01:01:22 -04:00
|
|
|
TUPLE: world-error error world ;
|
2007-09-20 18:09:08 -04:00
|
|
|
|
2008-07-11 01:01:22 -04:00
|
|
|
C: <world-error> world-error
|
2007-09-20 18:09:08 -04:00
|
|
|
|
|
|
|
SYMBOL: ui-error-hook
|
|
|
|
|
2008-06-25 23:06:34 -04:00
|
|
|
: ui-error ( error -- )
|
|
|
|
ui-error-hook get [ call ] [ print-error ] if* ;
|
2007-09-20 18:09:08 -04:00
|
|
|
|
|
|
|
[ rethrow ] ui-error-hook set-global
|
|
|
|
|
2007-10-21 18:10:27 -04:00
|
|
|
: draw-world ( world -- )
|
2007-09-20 18:09:08 -04:00
|
|
|
dup draw-world? [
|
|
|
|
dup world [
|
|
|
|
[
|
|
|
|
(draw-world)
|
|
|
|
] [
|
|
|
|
over <world-error> ui-error
|
2008-08-31 02:42:30 -04:00
|
|
|
f swap (>>active?)
|
2007-09-20 18:09:08 -04:00
|
|
|
] recover
|
|
|
|
] with-variable
|
|
|
|
] [
|
2007-10-21 18:10:27 -04:00
|
|
|
drop
|
2007-09-20 18:09:08 -04:00
|
|
|
] if ;
|
|
|
|
|
|
|
|
world H{
|
|
|
|
{ T{ key-down f { C+ } "x" } [ T{ cut-action } send-action ] }
|
|
|
|
{ T{ key-down f { C+ } "c" } [ T{ copy-action } send-action ] }
|
|
|
|
{ T{ key-down f { C+ } "v" } [ T{ paste-action } send-action ] }
|
|
|
|
{ T{ key-down f { C+ } "a" } [ T{ select-all-action } send-action ] }
|
|
|
|
{ T{ button-down f { C+ } 1 } [ T{ button-down f f 3 } swap resend-button-down ] }
|
|
|
|
{ T{ button-down f { A+ } 1 } [ T{ button-down f f 2 } swap resend-button-down ] }
|
|
|
|
{ T{ button-up f { C+ } 1 } [ T{ button-up f f 3 } swap resend-button-up ] }
|
|
|
|
{ T{ button-up f { A+ } 1 } [ T{ button-up f f 2 } swap resend-button-up ] }
|
|
|
|
} set-gestures
|
|
|
|
|
|
|
|
: close-global ( world global -- )
|
|
|
|
dup get-global find-world rot eq?
|
|
|
|
[ f swap set-global ] [ drop ] if ;
|