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
|
2006-06-27 03:26:52 -04:00
|
|
|
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)
|
2006-05-27 17:39:38 -04:00
|
|
|
! 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
|
2006-05-27 17:39:38 -04:00
|
|
|
! 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-05 17:12:30 -04:00
|
|
|
TUPLE: world gadget title status focus focused? fonts handle loc ;
|
2006-03-18 01:57:57 -05:00
|
|
|
|
|
|
|
: free-fonts ( world -- )
|
2006-03-21 15:20:16 -05:00
|
|
|
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
|
|
|
|
|
2006-06-27 03:26:52 -04:00
|
|
|
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
|
2006-06-29 01:54:11 -04:00
|
|
|
{ { f set-world-gadget f @center } } make-frame*
|
2006-03-17 03:21:54 -05:00
|
|
|
t over set-gadget-root?
|
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
|
|
|
|
2006-03-24 19:26:06 -05:00
|
|
|
M: world pref-dim* ( world -- dim )
|
2006-06-23 00:06:53 -04:00
|
|
|
delegate pref-dim* { 1024 768 } vmin ;
|
2006-03-24 19:26:06 -05:00
|
|
|
|
2006-07-05 17:12:30 -04:00
|
|
|
: activate-world-model ( world model -- )
|
|
|
|
[ add-connection ] keep activate-model ;
|
|
|
|
|
|
|
|
M: world graft* ( world -- )
|
|
|
|
dup dup world-title activate-world-model
|
|
|
|
dup dup world-status activate-world-model
|
|
|
|
model-changed ;
|
|
|
|
|
|
|
|
: deactivate-world-model ( world model -- )
|
|
|
|
[ remove-connection ] keep deactivate-model ;
|
|
|
|
|
|
|
|
M: world ungraft* ( world -- )
|
|
|
|
dup
|
|
|
|
dup world-title deactivate-world-model
|
|
|
|
dup world-status deactivate-world-model ;
|
|
|
|
|
|
|
|
M: world model-changed ( world -- )
|
|
|
|
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-06-23 02:25:08 -04:00
|
|
|
: font-sprites ( font world -- { open-font sprites } )
|
|
|
|
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 ;
|