]> gitweb.factorcode.org Git - factor.git/commitdiff
more UI work, new shapes, tuple in/out syntax
authorSlava Pestov <slava@factorcode.org>
Sun, 6 Feb 2005 03:51:41 +0000 (03:51 +0000)
committerSlava Pestov <slava@factorcode.org>
Sun, 6 Feb 2005 03:51:41 +0000 (03:51 +0000)
12 files changed:
TODO.FACTOR.txt
factor/parser/Tuple.java
library/generic/tuple.factor
library/kernel.factor
library/syntax/parse-syntax.factor
library/syntax/prettyprint.factor
library/ui/buttons.factor
library/ui/gadgets.factor
library/ui/hand.factor
library/ui/layouts.factor
library/ui/paint.factor
library/ui/shapes.factor

index 219225c5cce02c21c84e3b05c7344702d964e271..caa4f8f6cffd357bb014a984d554af0bae562297 100644 (file)
@@ -1,3 +1,7 @@
++ ui:\r
+\r
+- if gadgets are moved, added or deleted, update hand.\r
+\r
 + compiler:\r
 \r
 - type inference fails with some assembler words;\r
@@ -15,7 +19,6 @@
 - make see work with union, builtin, predicate\r
 - doc comments of generics\r
 - proper ordering for classes\r
-- tuples: in/out syntax\r
 - tuples: gracefully handle changing shape\r
 - keep a list of getter/setter words\r
 - default constructor\r
index a8e5fac8a5f1ab176fdbb48cc24d9702260b6a22..db6a2f5c26ae80838e03a4b255f04d640bab685a 100644 (file)
@@ -56,8 +56,11 @@ public class Tuple extends FactorParsingDefinition
                {
                        next = reader.next(false,false);
                        if(next == FactorScanner.EOF)
+                       {
                                reader.getScanner().error("Expected ;");
-                       if(next.equals(";"))
+                               break;
+                       }
+                       else if(next.equals(";"))
                                break;
                        else if(next instanceof String)
                        {
index c56083970a8bc5736676fa2005f4da1c42dbd8de..224b0aed0563e2414c691ffe1787c80b41243aa9 100644 (file)
@@ -4,10 +4,27 @@ IN: generic
 USING: words parser kernel namespaces lists strings
 kernel-internals math hashtables errors ;
 
-: make-tuple ( class -- )
+: make-tuple ( class -- tuple )
     dup "tuple-size" word-property <tuple>
     [ 0 swap set-array-nth ] keep ;
 
+: (literal-tuple) ( list size -- tuple )
+    dup <tuple> swap [
+        ( list tuple n -- list tuple n )
+        pick car pick pick swap set-array-nth
+        >r >r cdr r> r>
+    ] repeat nip ;
+
+: literal-tuple ( list -- tuple )
+    dup car "tuple-size" word-property over length over = [
+        (literal-tuple)
+    ] [
+        "Incorrect tuple length" throw
+    ] ifte ;
+
+: tuple>list ( tuple -- list )
+    >tuple array>list ;
+
 : define-tuple-generic ( tuple word def -- )
     over >r [ single-combination ] \ GENERIC: r> define-generic
     define-method ;
index 6002ab66c5e7d7ff8ca207dabea2523a8ec22871..567cc5bf8393f995f9ef0e9d6d21bf584e44cc56 100644 (file)
@@ -7,7 +7,7 @@ IN: kernel-internals USING: generic kernel vectors ;
     #! call it directly.
     vector-array array-nth call ;
 
-BUILTIN: tuple 18
+IN: generic BUILTIN: tuple 18
 
 IN: kernel
 
index d9f03126d8f5b0d491299ecc517886e2cb8fb5e8..4d91472734dda5b8a1e6d2ef9506e99044ced556 100644 (file)
@@ -1,45 +1,10 @@
-! :folding=indent:collapseFolds=1:
-
-! $Id$
-!
 ! Copyright (C) 2004, 2005 Slava Pestov.
-! 
-! Redistribution and use in source and binary forms, with or without
-! modification, are permitted provided that the following conditions are met:
-! 
-! 1. Redistributions of source code must retain the above copyright notice,
-!    this list of conditions and the following disclaimer.
-! 
-! 2. Redistributions in binary form must reproduce the above copyright notice,
-!    this list of conditions and the following disclaimer in the documentation
-!    and/or other materials provided with the distribution.
-! 
-! THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
-! INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
-! FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
-! DEVELOPERS AND CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
-! SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
-! PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
-! OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
-! WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
-! OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
-! ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+! See http://factor.sf.net/license.txt for BSD license.
 
 ! Bootstrapping trick; see doc/bootstrap.txt.
 IN: !syntax
-USE: syntax
-
-USE: errors
-USE: hashtables
-USE: kernel
-USE: lists
-USE: math
-USE: namespaces
-USE: parser
-USE: strings
-USE: words
-USE: vectors
-USE: unparser
+USING: syntax errors generic hashtables kernel lists
+math namespaces parser strings words vectors unparse ;
 
 : parsing ( -- )
     #! Mark the most recently defined word to execute at parse
@@ -75,6 +40,10 @@ USE: unparser
 : {{ f ; parsing
 : }} alist>hash swons ; parsing
 
+! Tuples.
+: << f ; parsing
+: >> reverse literal-tuple swons ; parsing
+
 ! Complex numbers
 : #{ f ; parsing
 : }# 2unlist swap rect> swons ; parsing
index f067f7d7ed8288dd28bf4fdce4d43e6ba730e9da..7437a8a51242be9ed656d7b15042624b363d062b 100644 (file)
@@ -1,44 +1,8 @@
-! :folding=indent:collapseFolds=1:
-
-! $Id$
-!
 ! Copyright (C) 2003, 2005 Slava Pestov.
-! 
-! Redistribution and use in source and binary forms, with or without
-! modification, are permitted provided that the following conditions are met:
-! 
-! 1. Redistributions of source code must retain the above copyright notice,
-!    this list of conditions and the following disclaimer.
-! 
-! 2. Redistributions in binary form must reproduce the above copyright notice,
-!    this list of conditions and the following disclaimer in the documentation
-!    and/or other materials provided with the distribution.
-! 
-! THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
-! INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
-! FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
-! DEVELOPERS AND CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
-! SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
-! PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
-! OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
-! WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
-! OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
-! ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-
+! See http://factor.sf.net/license.txt for BSD license.
 IN: prettyprint
-USE: errors
-USE: generic
-USE: kernel
-USE: lists
-USE: math
-USE: namespaces
-USE: stdio
-USE: strings
-USE: presentation
-USE: unparser
-USE: vectors
-USE: words
-USE: hashtables
+USING: errors generic kernel lists math namespaces stdio strings
+presentation unparser vectors words hashtables ;
 
 SYMBOL: prettyprint-limit
 
@@ -168,6 +132,12 @@ M: hashtable prettyprint* ( indent hashtable -- indent )
         swap prettyprint-{{ swap prettyprint-list prettyprint-}}
     ] ifte ;
 
+M: tuple prettyprint* ( indent tuple -- indent )
+    \ << prettyprint*
+    " " write
+    tuple>list [ prettyprint-element ] each
+    \ >> prettyprint* ;
+
 : prettyprint-1 ( obj -- )
     0 swap prettyprint* drop ;
 
index 629cd7bba9a33dfb4e3b60245c1822dfff4e6f26..f393e23ebd2695c831cdeba0dac6e147f2ec7662 100644 (file)
@@ -9,13 +9,50 @@ USING: generic kernel lists math namespaces sdl ;
 : button-released ( button -- )
     dup t bevel-up? set-paint-property redraw ;
 
+: mouse-over? ( gadget -- ? ) my-hand hand-gadget child? ;
+
+: rollover-update ( button -- )
+    dup mouse-over? blue black ? foreground set-paint-property ;
+
+: button-pressed? ( button -- ? )
+    dup mouse-over? [
+        my-hand hand-buttons 1 swap contains? [
+            my-hand hand-clicked child?
+        ] [
+            drop f
+        ] ifte
+    ] [
+        drop f
+    ] ifte ;
+
+: bevel-update ( button -- )
+    dup button-pressed? not bevel-up? set-paint-property ;
+
+: button-update ( button -- )
+    dup rollover-update dup bevel-update redraw ;
+
+: button-clicked ( button -- )
+    #! If the mouse is released while still inside the button,
+    #! fire an action gesture.
+    dup button-update
+    dup mouse-over? [
+        [ action ] swap handle-gesture
+    ] [
+        drop
+    ] ifte ;
+
+: button-actions ( button quot -- )
+    dupd [ action ] set-action
+    dup [ button-clicked ] [ button-up 1 ] set-action
+    dup [ button-update ] [ button-down 1 ] set-action
+    dup [ button-update ] [ mouse-leave ] set-action
+    dup [ button-update ] [ mouse-enter ] set-action ;
+
 : <button> ( label quot -- button )
-    >r <label> bevel-border
-    dup [ dup button-released ] r> append
-    [ button-up 1 ] set-action
-    dup [ button-pressed ]
-    [ button-down 1 ] set-action
-    dup [ USE: prettyprint . "Mouse left" USE: stdio print ]
-    [ mouse-leave ] set-action
-    dup [ USE: prettyprint . "Mouse enter" USE: stdio print ]
-    [ mouse-enter ] set-action ;
+    >r <label> bevel-border dup r> button-actions ;
+
+: <check-box> ( label quot -- checkbox )
+    >r 0 0 0 0 <rectangle> <shelf>
+    [ >r <label> r> add-gadget ] keep
+    [ >r f bevel-border r> add-gadget ] keep dup
+    r> button-actions ;
index ff628d745e4f65568f348f55457c9caf23c5cbc9..2bcfe53cc81017698a99860fe9f151567a65dad5 100644 (file)
@@ -72,3 +72,10 @@ C: gadget ( shape -- gadget )
 : screen-pos ( gadget -- point )
     #! The position of the gadget on the screen.
     0 swap [ shape-pos + t ] each-parent ;
+
+: child? ( parent child -- ? )
+    dup [
+        2dup eq? [ 2drop t ] [ gadget-parent child? ] ifte
+    ] [
+        2drop f
+    ] ifte ;
index 3d7951735753d8fce1ca1af89465291f627e3216..b8a3ebe1b1b7969c09d78f4c27a0743a02e5371e 100644 (file)
@@ -60,25 +60,24 @@ C: hand ( world -- hand )
 : button\ ( n hand -- )
     [ hand-buttons remove ] keep set-hand-buttons ;
 
-: fire-leave ( hand -- )
-    dup hand-gadget [ swap shape-pos swap screen-pos - ] keep
-    mouse-leave ;
+: fire-leave ( hand gadget -- )
+    [ swap shape-pos swap screen-pos - ] keep mouse-leave ;
 
 : fire-enter ( oldpos hand -- )
-    hand-gadget [ screen-pos - ] keep
-    mouse-enter ;
-
-: gadget-at-hand ( hand -- gadget )
-    dup gadget-children [ car ] [ world get pick-up ] ?ifte ;
+    hand-gadget [ screen-pos - ] keep mouse-enter ;
 
 : update-hand-gadget ( hand -- )
     #! The hand gadget is the gadget under the hand right now.
-    dup gadget-at-hand [ swap set-hand-gadget ] keep ;
+    dup world get pick-up swap set-hand-gadget ;
+
+: fire-motion ( hand -- )
+    [ motion ] swap hand-gadget handle-gesture ;
 
 : move-hand ( x y hand -- )
     dup shape-pos >r
     [ move-gadget ] keep
-    dup fire-leave
+    dup hand-gadget >r
     dup update-hand-gadget
-    [ motion ] swap handle-gesture
+    dup r> fire-leave
+    dup fire-motion
     r> swap fire-enter ;
index 1fabba7cf9ef87fbb96bdd47272a4489c7dea1c6..a6b18d209e1e91b1968dc90c2890e67d0a311408 100644 (file)
@@ -55,7 +55,7 @@ C: border ( delegate size -- border )
     [ set-border-size ] keep [ set-border-delegate ] keep ;
 
 : standard-border ( child delegate -- border )
-    5 <border> [ add-gadget ] keep ;
+    5 <border> [ over [ add-gadget ] [ 2drop ] ifte ] keep ;
 
 : empty-border ( child -- border )
     0 0 0 0 <rectangle> <gadget> standard-border ;
index b1d4a92588fd35d2700e67146189962006412de1..e6be95a10d793bfd8a4e2a541bafcbb05bbf7c92 100644 (file)
@@ -27,11 +27,13 @@ SYMBOL: font  ! a list of two elements, a font name and size.
 : shape>screen ( shape -- x1 y1 x2 y2 )
     [ shape-x x get + ] keep
     [ shape-y y get + ] keep
-    [ dup shape-x swap shape-w + x get + ] keep
-    dup shape-y swap shape-h + y get + ;
+    [ shape-w pick + ] keep
+    shape-h pick + ;
 
 GENERIC: draw-shape ( obj -- )
 
+! Actual rectangles don't draw; use a hollow-rect, plain-rect
+! or bevel-rect instead.
 M: rectangle draw-shape drop ;
 
 TUPLE: hollow-rect delegate ;
@@ -93,6 +95,38 @@ C: bevel-rect ( bevel x y w h -- rect )
 M: bevel-rect draw-shape ( rect -- )
     shape>screen >r >r rect> r> r> rect> 3 draw-bevel ;
 
+M: line draw-shape ( line -- )
+    >r surface get r>
+    shape>screen
+    foreground get rgb
+    lineColor ;
+
+M: ellipse draw-shape drop ;
+
+: ellipse>screen ( shape -- x y rx ry )
+    [ dup shape-x swap shape-w 2 /i + x get + ] keep
+    [ dup shape-y swap shape-h 2 /i + y get + ] keep
+    [ shape-w 2 /i ] keep
+    shape-h 2 /i ;
+
+TUPLE: hollow-ellipse delegate ;
+
+C: hollow-ellipse ( x y w h -- ellipse )
+    [ >r <ellipse> r> set-hollow-ellipse-delegate ] keep ;
+
+M: hollow-ellipse draw-shape ( ellipse -- )
+    >r surface get r> ellipse>screen foreground get rgb
+    ellipseColor ;
+
+TUPLE: plain-ellipse delegate ;
+
+C: plain-ellipse ( x y w h -- ellipse )
+    [ >r <ellipse> r> set-plain-ellipse-delegate ] keep ;
+
+M: plain-ellipse draw-shape ( ellipse -- )
+    >r surface get r> ellipse>screen background get rgb
+     filledEllipseColor ;
+
 : draw-gadget ( gadget -- )
     #! All drawing done inside draw-shape is done with the
     #! gadget's paint. If the gadget does not have any custom
index 86ff250bbca6cb4bae2a957293b3fbd28e188959..94a97e100812f3b97fa692885a976cba2ff7459e 100644 (file)
@@ -35,11 +35,11 @@ GENERIC: resize-shape ( w h shape -- )
 
 : max-width ( list -- n )
     #! The width of the widest shape.
-    [ shape-w ] map [ > ] top ;
+    [ [ shape-w ] map [ > ] top ] [ 0 ] ifte* ;
 
 : max-height ( list -- n )
     #! The height of the tallest shape.
-    [ shape-h ] map [ > ] top ;
+    [ [ shape-h ] map [ > ] top ] [ 0 ] ifte* ;
 
 : run-widths ( list -- w list )
     #! Compute a list of running sums of widths of shapes.
@@ -100,3 +100,51 @@ M: rectangle resize-shape ( w h rect -- )
 M: rectangle inside? ( point rect -- ? )
     over shape-x over rectangle-x-extents between? >r
     swap shape-y swap rectangle-y-extents between? r> and ;
+
+! A line.
+TUPLE: line x y w h ;
+M: line shape-x line-x ;
+M: line shape-y line-y ;
+M: line shape-w line-w ;
+M: line shape-h line-h ;
+
+C: line ( x y w h -- line )
+    #! We handle negative w/h for convinience.
+    >r fix-neg >r fix-neg r> r>
+    [ set-line-h ] keep
+    [ set-line-w ] keep
+    [ set-line-y ] keep
+    [ set-line-x ] keep ;
+
+M: line move-shape ( x y line -- )
+    tuck set-line-y set-line-x ;
+
+M: line resize-shape ( w h line -- )
+    tuck set-line-h set-line-w ;
+
+M: line inside? ( point line -- ? )
+    2drop f ;
+
+! An ellipse.
+TUPLE: ellipse x y w h ;
+M: ellipse shape-x ellipse-x ;
+M: ellipse shape-y ellipse-y ;
+M: ellipse shape-w ellipse-w ;
+M: ellipse shape-h ellipse-h ;
+
+C: ellipse ( x y w h -- line )
+    #! We handle negative w/h for convinience.
+    >r fix-neg >r fix-neg r> r>
+    [ set-ellipse-h ] keep
+    [ set-ellipse-w ] keep
+    [ set-ellipse-y ] keep
+    [ set-ellipse-x ] keep ;
+
+M: ellipse move-shape ( x y line -- )
+    tuck set-ellipse-y set-ellipse-x ;
+
+M: ellipse resize-shape ( w h line -- )
+    tuck set-ellipse-h set-ellipse-w ;
+
+M: ellipse inside? ( point line -- ? )
+    2drop f ;