]> gitweb.factorcode.org Git - factor.git/commitdiff
removed boxes; all gadgets can contain children now
authorSlava Pestov <slava@factorcode.org>
Thu, 3 Feb 2005 23:18:47 +0000 (23:18 +0000)
committerSlava Pestov <slava@factorcode.org>
Thu, 3 Feb 2005 23:18:47 +0000 (23:18 +0000)
library/bootstrap/boot-stage2.factor
library/ui/boxes.factor [deleted file]
library/ui/gadgets.factor
library/ui/hand.factor
library/ui/layouts.factor
library/ui/paint.factor
library/ui/world.factor

index 6c148429380ed581c58223ab3ccf7116c233ee44..8b9ae69ec7b27fbfd49f51b1f2e6eae991fb79c6 100644 (file)
@@ -153,9 +153,8 @@ cpu "x86" = [
         "/library/ui/line-editor.factor"\r
         "/library/ui/console.factor"\r
         "/library/ui/shapes.factor"\r
-        "/library/ui/paint.factor"\r
         "/library/ui/gadgets.factor"\r
-        "/library/ui/boxes.factor"\r
+        "/library/ui/paint.factor"\r
         "/library/ui/gestures.factor"\r
         "/library/ui/hand.factor"\r
         "/library/ui/world.factor"\r
diff --git a/library/ui/boxes.factor b/library/ui/boxes.factor
deleted file mode 100644 (file)
index 97f5545..0000000
+++ /dev/null
@@ -1,60 +0,0 @@
-! Copyright (C) 2005 Slava Pestov.
-! See http://factor.sf.net/license.txt for BSD license.
-IN: gadgets
-USING: generic hashtables kernel lists namespaces ;
-
-! A box is a gadget holding other gadgets.
-TUPLE: box children delegate ;
-
-C: box ( gadget -- box )
-    [ set-box-delegate ] keep ;
-
-M: box gadget-children box-children ;
-
-M: box draw-shape ( box -- )
-    dup box-delegate draw-gadget
-    dup [ box-children [ draw-gadget ] each ] with-translation ;
-
-M: general-list pick-up* ( point list -- gadget )
-    dup [
-        2dup car pick-up dup [
-            2nip
-        ] [
-            drop cdr pick-up
-        ] ifte
-    ] [
-        2drop f
-    ] ifte ;
-
-M: box pick-up* ( point box -- 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 box-children pick-up dup [
-            2nip
-        ] [
-            drop box-delegate pick-up*
-        ] ifte
-    ] [
-        2drop f
-    ] ifte ;
-
-: box- ( gadget box -- )
-    [ 2dup box-children remq swap set-box-children ] keep
-    relayout
-    f swap set-gadget-parent ;
-
-: (box+) ( gadget box -- )
-    [ box-children cons ] keep set-box-children ;
-
-: unparent ( gadget -- )
-    dup gadget-parent dup [ box- ] [ 2drop ] ifte ;
-
-: box+ ( gadget box -- )
-    #! Add a gadget to a box.
-    over unparent
-    dup pick set-gadget-parent
-    tuck (box+)
-    relayout ;
index 3840bbba9b6319d02c1bcfc99047af7501cd0fe7..4d04a706608458aab1b1dbff847c1ddd59f460b7 100644 (file)
@@ -6,34 +6,10 @@ USING: generic hashtables kernel lists namespaces ;
 ! A gadget is a shape, a paint, a mapping of gestures to
 ! actions, and a reference to the gadget's parent. A gadget
 ! delegates to its shape.
-TUPLE: gadget paint gestures parent relayout? redraw? delegate ;
-
-! Gadget protocol.
-GENERIC: pick-up* ( point gadget -- gadget/t )
-
-: 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 ;
-
-GENERIC: gadget-children ( gadget -- list )
-M: gadget gadget-children drop f ;
-
-GENERIC: layout* ( gadget -- )
-M: gadget layout* drop ;
-
-: layout ( gadget -- )
-    #! Set the gadget's width and height to its preferred width
-    #! and height. The gadget's children are laid out first.
-    #! Note that nothing is done if the gadget does not need to
-    #! be laid out.
-    dup gadget-relayout? [
-        f over set-gadget-relayout?
-        dup gadget-children [ layout ] each
-        layout*
-    ] [
-        drop
-    ] ifte ;
+TUPLE: gadget
+    paint gestures
+    relayout? redraw?
+    parent children delegate ;
 
 C: gadget ( shape -- gadget )
     [ set-gadget-delegate ] keep
@@ -54,30 +30,26 @@ C: gadget ( shape -- gadget )
 : set-action ( gadget quot gesture -- )
     rot gadget-gestures set-hash ;
 
-: draw-gadget ( gadget -- )
-    #! All drawing done inside draw-shape is done with the
-    #! gadget's paint. If the gadget does not have any custom
-    #! paint, just call the quotation.
-    dup gadget-paint [ draw-shape ] bind ;
-
-M: gadget pick-up* inside? ;
-
-: redraw ( gadget -- )
-    #! Redraw a gadget before the next iteration of the event
-    #! loop.
-    t over set-gadget-redraw?
-    gadget-parent [ redraw ] when* ;
-
-: relayout ( gadget -- )
-    #! Relayout a gadget before the next iteration of the event
-    #! loop. Since relayout also implies the visual
-    #! representation changed, we redraw the gadget too.
-    t over set-gadget-redraw?
-    t over set-gadget-relayout?
-    gadget-parent [ relayout ] when* ;
-
 : move-gadget ( x y gadget -- )
     [ move-shape ] keep redraw ;
 
 : resize-gadget ( w h gadget -- )
     [ resize-shape ] keep redraw ;
+
+: box- ( gadget box -- )
+    [ 2dup gadget-children remq swap set-gadget-children ] keep
+    relayout
+    f swap set-gadget-parent ;
+
+: (box+) ( gadget box -- )
+    [ gadget-children cons ] keep set-gadget-children ;
+
+: unparent ( gadget -- )
+    dup gadget-parent dup [ box- ] [ 2drop ] ifte ;
+
+: box+ ( gadget box -- )
+    #! Add a gadget to a box.
+    over unparent
+    dup pick set-gadget-parent
+    tuck (box+)
+    relayout ;
index 8ac4df57c245a05360d21d79b7610281676176c3..16fe9cff9107b415f6db3b3651d341dcf426cd65 100644 (file)
@@ -4,7 +4,41 @@ IN: gadgets
 USING: alien generic kernel lists math namespaces sdl sdl-event
 sdl-video ;
 
-SYMBOL: world
+DEFER: pick-up*
+
+: pick-up-list ( point list -- gadget )
+    dup [
+        2dup car pick-up dup [
+            2nip
+        ] [
+            drop cdr pick-up-list
+        ] ifte
+    ] [
+        2drop f
+    ] ifte ;
+
+: pick-up* ( point gadget -- gadget/t )
+    #! 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 pick-up-list dup [
+            2nip
+        ] [
+            drop inside?
+        ] ifte
+    ] [
+        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 ;
+
+DEFER: world
 
 ! The hand is a special gadget that holds mouse position and
 ! mouse button click state. The hand's parent is the world, but
@@ -13,7 +47,7 @@ SYMBOL: world
 TUPLE: hand click-pos clicked buttons delegate ;
 
 C: hand ( world -- hand )
-    0 0 <point> <gadget> <box>
+    0 0 <point> <gadget>
     over set-hand-delegate
     [ set-gadget-parent ] keep ;
 
index 98b64764dc9f399169ebac94eaf9122bd30215d3..3aa42fce4ca59bc2e0ebc727fa336f37a5fa8010 100644 (file)
@@ -3,11 +3,14 @@
 IN: gadgets
 USING: generic hashtables kernel lists math namespaces ;
 
+GENERIC: layout* ( gadget -- )
+M: gadget layout* drop ;
+
 ! A pile is a box that lays out its contents vertically.
 TUPLE: pile delegate ;
 
-C: pile ( gadget -- pile )
-    [ >r <box> r> set-pile-delegate ] keep ;
+C: pile ( shape -- pile )
+    [ >r <gadget> r> set-pile-delegate ] keep ;
 
 M: pile layout* ( pile -- )
     dup gadget-children run-heights >r >r
@@ -19,8 +22,8 @@ M: pile layout* ( pile -- )
 ! A shelf is a box that lays out its contents horizontally.
 TUPLE: shelf delegate ;
 
-C: shelf ( gadget -- pile )
-    [ >r <box> r> set-shelf-delegate ] keep ;
+C: shelf ( shape -- pile )
+    [ >r <gadget> r> set-shelf-delegate ] keep ;
 
 M: shelf layout* ( pile -- )
     dup gadget-children run-widths >r >r
@@ -28,3 +31,24 @@ M: shelf layout* ( pile -- )
     gadget-children r> zip [
         uncons 0 rot move-gadget
     ] each ;
+
+: relayout ( gadget -- )
+    #! Relayout a gadget before the next iteration of the event
+    #! loop. Since relayout also implies the visual
+    #! representation changed, we redraw the gadget too.
+    t over set-gadget-redraw?
+    t over set-gadget-relayout?
+    gadget-parent [ relayout ] when* ;
+
+: layout ( gadget -- )
+    #! Set the gadget's width and height to its preferred width
+    #! and height. The gadget's children are laid out first.
+    #! Note that nothing is done if the gadget does not need to
+    #! be laid out.
+    dup gadget-relayout? [
+        f over set-gadget-relayout?
+        dup gadget-children [ layout ] each
+        layout*
+    ] [
+        drop
+    ] ifte ;
index fa47112aa38e7f666333ec53dd07bc6c2fb20887..c45e6aafaf5e8548d4c71f1942c708fcacfe604a 100644 (file)
@@ -84,3 +84,20 @@ M: bevel-rect draw-shape ( rect -- )
         [[ color [ 160 160 160 ] ]]
         [[ font [[ "Monospaced" 12 ]] ]]
     }} ;
+
+: draw-gadget ( gadget -- )
+    #! All drawing done inside draw-shape is done with the
+    #! gadget's paint. If the gadget does not have any custom
+    #! paint, just call the quotation.
+    dup gadget-paint [
+        dup draw-shape
+        dup [
+            gadget-children [ draw-gadget ] each
+        ] with-translation
+    ] bind ;
+
+: redraw ( gadget -- )
+    #! Redraw a gadget before the next iteration of the event
+    #! loop.
+    t over set-gadget-redraw?
+    gadget-parent [ redraw ] when* ;
index 739e512867339cb6f34fa622d376035c9953b62f..27ba50ef986c996d9ef6c8f53a1444b3232bea9b 100644 (file)
@@ -11,8 +11,7 @@ TUPLE: world running? hand delegate ;
 
 : <world-box> ( -- box )
     0 0 0 0 <plain-rect> <everywhere> <gadget>
-    dup [ 216 216 216 ] color set-paint-property
-    <box> ;
+    dup [ 216 216 216 ] color set-paint-property ;
 
 C: world ( -- world )
     <world-box> over set-world-delegate