tuple [ 2drop t ] "class<" set-word-prop
PREDICATE: word tuple-class metaclass tuple = ;
+
+: is? ( obj pred -- ? | pred: obj -- ? )
+ #! Tests if the object satisfies the predicate, or if
+ #! it delegates to an object satisfying it.
+ [ call ] 2keep rot [
+ 2drop t
+ ] [
+ over [ >r delegate r> is? ] [ 2drop f ] ifte
+ ] ifte ;
SYMBOL: underline
-SYMBOL: presented
-
SYMBOL: icon
+
+SYMBOL: presented
DEFER: pick-up
-: pick-up-list ( point list -- gadget )
+: (pick-up) ( point list -- gadget )
dup [
2dup car pick-up dup
- [ 2nip ] [ drop cdr pick-up-list ] ifte
+ [ 2nip ] [ drop cdr (pick-up) ] ifte
] [
2drop f
] ifte ;
-: pick-up* ( point gadget -- gadget/t )
+: pick-up ( point gadget -- gadget )
#! The logic is thus. If the point is definately outside the
#! box, return f. Otherwise, see if the point is contained
#! in any subgadget. If not, see if it is contained in the
#! box delegate.
2dup inside? [
- 2dup [ translate ] keep
- gadget-children reverse pick-up-list dup
- [ 2nip ] [ 3drop t ] ifte
+ [
+ [ translate ] keep
+ gadget-children reverse (pick-up) dup
+ ] keep ?
] [
2drop f
] ifte ;
-: pick-up ( point gadget -- gadget )
- #! pick-up* returns t to mean 'this gadget', avoiding the
- #! exposed facade issue.
- tuck pick-up* dup t = [ drop ] [ nip ] ifte ;
-
! The hand is a special gadget that holds mouse position and
! mouse button click state. The hand's parent is the world, but
! it is special in that the world does not list it as part of
! - hand-gadget is the gadget under the mouse position
! - hand-clicked is the most recently clicked gadget
! - hand-focus is the gadget holding keyboard focus
-TUPLE: hand
- world
- click-loc click-rel clicked buttons
- gadget focus ;
+TUPLE: hand click-loc click-rel clicked buttons gadget focus ;
C: hand ( world -- hand )
<empty-gadget> over set-delegate
- [ set-hand-world ] 2keep
[ set-gadget-parent ] 2keep
[ set-hand-gadget ] keep ;
hand-gadget [ screen-loc v- ] keep mouse-enter ;
: update-hand-gadget ( hand -- )
- dup dup hand-world pick-up swap set-hand-gadget ;
+ [ world get pick-up ] keep set-hand-gadget ;
: motion-gesture ( hand gadget gesture -- )
#! Send a gesture like [ drag 2 ].
: applicable ( object -- )
commands get >list
- [ car "predicate" word-prop call ] subset-with ;
+ [ car call ] subset-with ;
DEFER: pane-call
<label> swap alist>hash over set-gadget-paint ;
: <presentation> ( style text pane -- presentation )
- >r <styled-label> dup r> init-commands ;
+ pick gadget swap assoc dup [
+ >r 3drop r>
+ ] [
+ drop >r <styled-label> dup r> init-commands
+ ] ifte ;
+
+: gadget. ( gadget -- )
+ gadget swons unit "" swap write-attr ;
+
+[ drop t ] "Prettyprint" [ prettyprint ] define-command
+[ drop t ] "Inspect" [ inspect ] define-command
+[ drop t ] "References" [ references inspect ] define-command
-object "Prettyprint" [ prettyprint ] define-command
-object "Inspect" [ inspect ] define-command
-object "References" [ references inspect ] define-command
+[ word? ] "See" [ see ] define-command
+[ word? ] "Execute" [ execute ] define-command
+[ word? ] "Usage" [ usage . ] define-command
+[ word? ] "jEdit" [ jedit ] define-command
-\ word "See" [ see ] define-command
-\ word "Execute" [ execute ] define-command
-\ word "Usage" [ usage . ] define-command
-\ word "jEdit" [ jedit ] define-command
+[ [ gadget? ] is? ] "Display" [ ] define-command
shape-bounds >r origin v+ r> <rectangle> ;
M: rectangle inside? ( loc rect -- ? )
- screen-bounds shape-bounds
+ screen-bounds shape-bounds { 1 1 1 } v- { 0 0 0 } vmax
>r v- { 0 0 0 } r> vbetween? conj ;
M: rectangle draw-shape drop ;
: ui ( -- )
#! Start the Factor graphics subsystem with the given screen
#! dimensions.
+ ttf-init
?init-world
world get shape-dim 2unseq 0 SDL_RESIZABLE [
0 x set 0 y set [
"Factor " version append dup SDL_WM_SetCaption
- ttf-init
start-world
run-world
] with-screen
: world-step ( -- ? )
world get dup world-invalid >r layout-world r>
- [ draw-world ] [ drop ] ifte ;
+ [ dup world-hand update-hand draw-world ] [ drop ] ifte ;
: next-event ( -- event ? )
<event> dup SDL_PollEvent ;