]> gitweb.factorcode.org Git - factor.git/commitdiff
inside method for ellipses
authorSlava Pestov <slava@factorcode.org>
Sun, 6 Feb 2005 05:21:26 +0000 (05:21 +0000)
committerSlava Pestov <slava@factorcode.org>
Sun, 6 Feb 2005 05:21:26 +0000 (05:21 +0000)
TODO.FACTOR.txt
library/bootstrap/boot-stage2.factor
library/kernel.factor
library/syntax/prettyprint.factor
library/syntax/see.factor
library/ui/buttons.factor
library/ui/shapes.factor

index caa4f8f6cffd357bb014a984d554af0bae562297..928e67e71b3091804fdcaa50eb4557be95d75f63 100644 (file)
@@ -22,6 +22,7 @@
 - tuples: gracefully handle changing shape\r
 - keep a list of getter/setter words\r
 - default constructor\r
+- move tuple to generic vocab\r
 \r
 + ffi:\r
 \r
index d31a1673c41f8c4e2e90156607eb6e3c17bfec86..1ecaf4912c92fb2596d99b1329caa4c9f6e3ff46 100644 (file)
@@ -160,6 +160,7 @@ cpu "x86" = [
         "/library/ui/layouts.factor"\r
         "/library/ui/world.factor"\r
         "/library/ui/labels.factor"\r
+        "/library/ui/buttons.factor"\r
         "/library/ui/events.factor"\r
     ] [\r
         dup print\r
index 567cc5bf8393f995f9ef0e9d6d21bf584e44cc56..6002ab66c5e7d7ff8ca207dabea2523a8ec22871 100644 (file)
@@ -7,7 +7,7 @@ IN: kernel-internals USING: generic kernel vectors ;
     #! call it directly.
     vector-array array-nth call ;
 
-IN: generic BUILTIN: tuple 18
+BUILTIN: tuple 18
 
 IN: kernel
 
index 7437a8a51242be9ed656d7b15042624b363d062b..7ddcd92516248edaa39f24e0fd80d14a01b3b03d 100644 (file)
@@ -1,20 +1,23 @@
 ! Copyright (C) 2003, 2005 Slava Pestov.
 ! See http://factor.sf.net/license.txt for BSD license.
 IN: prettyprint
-USING: errors generic kernel lists math namespaces stdio strings
-presentation unparser vectors words hashtables ;
+
+! This using kernel-internals is pretty bad. Remove the
+! kernel-internals usage as soon as the tuple class is moved
+! to the generic vocabulary.
+USING: errors generic kernel kernel-internals lists math
+namespaces stdio strings presentation unparser vectors words
+hashtables ;
 
 SYMBOL: prettyprint-limit
+SYMBOL: one-line
+SYMBOL: tab-size
 
 GENERIC: prettyprint* ( indent obj -- indent )
 
 M: object prettyprint* ( indent obj -- indent )
     unparse write ;
 
-: tab-size
-    #! Change this to suit your tastes.
-    4 ;
-
 : indent ( indent -- )
     #! Print the given number of spaces.
     " " fill write ;
@@ -30,18 +33,15 @@ M: object prettyprint* ( indent obj -- indent )
     ] ifte " " write ;
 
 : <prettyprint ( indent -- indent )
-    tab-size +
-    "prettyprint-single-line" get [
+    tab-size get + one-line get [
         " " write
     ] [
         dup prettyprint-newline
     ] ifte ;
 
 : prettyprint> ( indent -- indent )
-    tab-size -
-    "prettyprint-single-line" get [
-        dup prettyprint-newline
-    ] unless ;
+    tab-size get - one-line get
+    [ dup prettyprint-newline ] unless ;
 
 : word-link ( word -- link )
     [
@@ -74,69 +74,34 @@ M: word prettyprint* ( indent word -- indent )
     swap dup word-attrs swap word-style append
     write-attr ;
 
-: prettyprint-[ ( indent -- indent )
-    \ [ prettyprint* <prettyprint ;
-
-: prettyprint-] ( indent -- indent )
-    prettyprint> \ ] prettyprint* ;
-
-: prettyprint-list ( indent list -- indent )
-    #! Pretty-print a list, without [ and ].
-    [ prettyprint-element ] each ;
+: prettyprint-sequence ( indent start list end -- indent )
+    #! Prettyprint a list, with start/end delimiters; eg, [ ],
+    #! or { }, or << >>. The body of the list is indented,
+    #! unless the list is empty.
+    over [
+        >r
+        >r prettyprint* <prettyprint
+        r> [ prettyprint-element ] each
+        prettyprint> r> prettyprint*
+    ] [
+        >r >r prettyprint* " " write r> drop r> prettyprint*
+    ] ifte ;
 
 M: list prettyprint* ( indent list -- indent )
-    [
-        swap prettyprint-[ swap prettyprint-list prettyprint-]
-    ] [
-        f unparse write
-    ] ifte* ;
+    \ [ swap \ ] prettyprint-sequence ;
 
 M: cons prettyprint* ( indent cons -- indent )
-    \ [[ prettyprint* " " write
-            uncons >r prettyprint-element r> prettyprint-element
-    \ ]] prettyprint* ;
-
-: prettyprint-{ ( indent -- indent )
-    \ { prettyprint* <prettyprint ;
-
-: prettyprint-} ( indent -- indent )
-    prettyprint> \ } prettyprint* ;
-
-: prettyprint-vector ( indent list -- indent )
-    #! Pretty-print a vector, without { and }.
-    [ prettyprint-element ] vector-each ;
+    #! Here we turn the cons into a list of two elements.
+    \ [[ swap uncons 2list \ ]] prettyprint-sequence ;
 
 M: vector prettyprint* ( indent vector -- indent )
-    dup vector-length 0 = [
-        drop
-        \ { prettyprint*
-        " " write
-        \ } prettyprint*
-    ] [
-        swap prettyprint-{ swap prettyprint-vector prettyprint-}
-    ] ifte ;
-
-: prettyprint-{{ ( indent -- indent )
-    \ {{ prettyprint* <prettyprint ;
-
-: prettyprint-}} ( indent -- indent )
-    prettyprint> \ }} prettyprint* ;
+    \ { swap vector>list \ } prettyprint-sequence ;
 
 M: hashtable prettyprint* ( indent hashtable -- indent )
-    hash>alist dup length 0 = [
-        drop
-        \ {{ prettyprint*
-        " " write 
-        \ }} prettyprint*
-    ] [
-        swap prettyprint-{{ swap prettyprint-list prettyprint-}}
-    ] ifte ;
+    \ {{ swap hash>alist \ }} prettyprint-sequence ;
 
 M: tuple prettyprint* ( indent tuple -- indent )
-    \ << prettyprint*
-    " " write
-    tuple>list [ prettyprint-element ] each
-    \ >> prettyprint* ;
+    \ << swap tuple>list \ >> prettyprint-sequence ;
 
 : prettyprint-1 ( obj -- )
     0 swap prettyprint* drop ;
@@ -149,7 +114,7 @@ M: tuple prettyprint* ( indent tuple -- indent )
 
 : . ( obj -- )
     [
-        "prettyprint-single-line" on
+        one-line on
         16 prettyprint-limit set
         prettyprint
     ] with-scope ;
@@ -172,4 +137,4 @@ M: tuple prettyprint* ( indent tuple -- indent )
 : .o >oct print ;
 : .h >hex print ;
 
-global [ 40 prettyprint-limit set ] bind
+global [ 40 prettyprint-limit set  4 tab-size set ] bind
index 3f6fe183fe479a01f5b20d83e7eb87ff18fe2a55..3b7805246335fc1825f8e7d33ee79d38b9a67d58 100644 (file)
@@ -1,41 +1,8 @@
-! :folding=indent:collapseFolds=1:
-
-! $Id$
-!
-! Copyright (C) 2003, 2004 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.
-
+! Copyright (C) 2003, 2005 Slava Pestov.
+! See http://factor.sf.net/license.txt for BSD license.
 IN: prettyprint
-USE: generic
-USE: kernel
-USE: lists
-USE: math
-USE: namespaces
-USE: stdio
-USE: strings
-USE: presentation
-USE: unparser
-USE: words
+USING: generic kernel lists math namespaces stdio strings
+presentation unparser words ;
 
 ! Prettyprinting words
 : vocab-actions ( search -- list )
@@ -59,11 +26,11 @@ USE: words
 
 : prettyprint-: ( indent -- indent )
     \ : prettyprint* " " write
-    tab-size + ;
+    tab-size get + ;
 
 : prettyprint-; ( indent -- indent )
     \ ; prettyprint*
-    tab-size - ;
+    tab-size get - ;
 
 : prettyprint-prop ( word prop -- )
     tuck word-name word-property [
@@ -100,7 +67,7 @@ USE: words
     ] keep documentation. ;
 
 : prettyprint-M: ( indent -- indent )
-    \ M: prettyprint-1 " " write tab-size + ;
+    \ M: prettyprint-1 " " write tab-size get + ;
 
 GENERIC: see ( word -- )
 
@@ -109,7 +76,10 @@ M: compound see ( word -- )
     0 prettyprint-: swap
     [ prettyprint-1 ] keep
     [ prettyprint-docs ] keep
-    [ word-parameter prettyprint-list prettyprint-; ] keep
+    [
+        word-parameter [ prettyprint-element ] each
+        prettyprint-;
+    ] keep
     prettyprint-plist prettyprint-newline ;
 
 : see-method ( indent word class method -- indent )
@@ -117,7 +87,7 @@ M: compound see ( word -- )
     r> r> prettyprint-1 " " write
     prettyprint-1 " " write
     dup prettyprint-newline
-    r> prettyprint-list
+    r> [ prettyprint-element ] each
     prettyprint-;
     terpri ;
 
index f393e23ebd2695c831cdeba0dac6e147f2ec7662..bfb6a793df7d0255415f3caf240f4651c56c93b0 100644 (file)
@@ -46,7 +46,7 @@ USING: generic kernel lists math namespaces sdl ;
     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-update ] [ mouse-enter ] set-action ;
 
 : <button> ( label quot -- button )
     >r <label> bevel-border dup r> button-actions ;
index 94a97e100812f3b97fa692885a976cba2ff7459e..3b144a399b67f9cd0a7032782531d317072bb39d 100644 (file)
@@ -123,7 +123,7 @@ M: line resize-shape ( w h line -- )
     tuck set-line-h set-line-w ;
 
 M: line inside? ( point line -- ? )
-    2drop f ;
+    2drop t ;
 
 ! An ellipse.
 TUPLE: ellipse x y w h ;
@@ -133,7 +133,7 @@ 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.
+    #! We handle negative w/h for convenience.
     >r fix-neg >r fix-neg r> r>
     [ set-ellipse-h ] keep
     [ set-ellipse-w ] keep
@@ -146,5 +146,9 @@ M: ellipse move-shape ( x y line -- )
 M: ellipse resize-shape ( w h line -- )
     tuck set-ellipse-h set-ellipse-w ;
 
-M: ellipse inside? ( point line -- ? )
-    2drop f ;
+M: ellipse inside? ( point ellipse -- ? )
+    ellipse>screen swap sq swap sq
+    2dup * >r >r >r
+    pick shape-y - sq
+    >r swap shape-x - sq r>
+    r> * r> rot * + r> <= ;