]> gitweb.factorcode.org Git - factor.git/commitdiff
Split off ui.pens from ui.render
authorSlava Pestov <slava@slava-pestovs-macbook-pro.local>
Thu, 12 Feb 2009 09:58:42 +0000 (03:58 -0600)
committerSlava Pestov <slava@slava-pestovs-macbook-pro.local>
Thu, 12 Feb 2009 09:58:42 +0000 (03:58 -0600)
42 files changed:
basis/ui/gadgets/buttons/buttons-docs.factor
basis/ui/gadgets/buttons/buttons.factor
basis/ui/gadgets/editors/editors.factor
basis/ui/gadgets/grid-lines/grid-lines-docs.factor
basis/ui/gadgets/grid-lines/grid-lines.factor
basis/ui/gadgets/icons/icons.factor
basis/ui/gadgets/labelled/labelled-docs.factor
basis/ui/gadgets/labels/labels.factor
basis/ui/gadgets/sliders/sliders-docs.factor
basis/ui/gadgets/sliders/sliders.factor
basis/ui/gadgets/theme/theme.factor
basis/ui/gadgets/worlds/worlds-docs.factor
basis/ui/gestures/gestures-docs.factor
basis/ui/pens/authors.txt [new file with mode: 0644]
basis/ui/pens/caching/authors.txt [new file with mode: 0644]
basis/ui/pens/caching/caching-tests.factor [new file with mode: 0644]
basis/ui/pens/caching/caching.factor [new file with mode: 0644]
basis/ui/pens/gradient/authors.txt [new file with mode: 0644]
basis/ui/pens/gradient/gradient-docs.factor [new file with mode: 0644]
basis/ui/pens/gradient/gradient-tests.factor [new file with mode: 0644]
basis/ui/pens/gradient/gradient.factor [new file with mode: 0644]
basis/ui/pens/image/authors.txt [new file with mode: 0644]
basis/ui/pens/image/image-tests.factor [new file with mode: 0644]
basis/ui/pens/image/image.factor [new file with mode: 0644]
basis/ui/pens/pens-docs.factor [new file with mode: 0644]
basis/ui/pens/pens-tests.factor [new file with mode: 0644]
basis/ui/pens/pens.factor [new file with mode: 0644]
basis/ui/pens/polygon/authors.txt [new file with mode: 0644]
basis/ui/pens/polygon/polygon-docs.factor [new file with mode: 0644]
basis/ui/pens/polygon/polygon-tests.factor [new file with mode: 0644]
basis/ui/pens/polygon/polygon.factor [new file with mode: 0644]
basis/ui/pens/solid/authors.txt [new file with mode: 0644]
basis/ui/pens/solid/solid-docs.factor [new file with mode: 0644]
basis/ui/pens/solid/solid-tests.factor [new file with mode: 0644]
basis/ui/pens/solid/solid.factor [new file with mode: 0644]
basis/ui/pens/tile/authors.txt [new file with mode: 0644]
basis/ui/pens/tile/tile-tests.factor [new file with mode: 0644]
basis/ui/pens/tile/tile.factor [new file with mode: 0644]
basis/ui/render/render-docs.factor
basis/ui/render/render.factor
basis/ui/tools/listener/completion/completion.factor
basis/ui/tools/listener/listener.factor

index d6878517a13e8a41d09944ecc96e2f289a1a806f..1a3096cce544ea9e67981aa063fef2aaf1eb5f89 100644 (file)
@@ -1,5 +1,5 @@
 USING: help.markup help.syntax ui.gadgets ui.gadgets.labels
-ui.render kernel models classes ;
+ui.pens kernel models classes ;
 IN: ui.gadgets.buttons
 
 HELP: button
index 46bb984e0ccd38beae34095bc39d943ca1cf37ef..346e1fd4d71a41375e0c7a3b0d274a026a0b1e56 100644 (file)
@@ -5,7 +5,7 @@ strings quotations assocs combinators classes colors colors.constants
 classes.tuple opengl opengl.gl math.vectors ui.commands ui.gadgets
 ui.gadgets.borders ui.gadgets.labels ui.gadgets.theme
 ui.gadgets.tracks ui.gadgets.packs ui.gadgets.worlds ui.gestures
-ui.render math.rectangles locals alien.c-types
+ui.pens ui.pens.solid ui.pens.caching math.rectangles locals
 specialized-arrays.float fry combinators.smart ;
 IN: ui.gadgets.buttons
 
index 622d388894f06dbb94417423eb8d3e1b11b9eddc..2c3e82059a54087c1c93524da69f9bae950b5854 100755 (executable)
@@ -7,8 +7,8 @@ colors.constants combinators assocs math.order fry calendar alarms
 continuations ui.clipboards ui.commands ui.gadgets ui.gadgets.borders
 ui.gadgets.buttons ui.gadgets.labels ui.gadgets.scrollers
 ui.gadgets.theme ui.gadgets.menus ui.gadgets.wrappers ui.render
-ui.gadgets.line-support ui.text ui.gestures math.rectangles splitting
-unicode.categories fonts ;
+ui.pens.solid ui.gadgets.line-support ui.text ui.gestures
+math.rectangles splitting unicode.categories fonts ;
 IN: ui.gadgets.editors
 
 TUPLE: editor < gadget
index 942ee9af49c5e03de8bd318507e0727f795a6a11..2101e3598e1177cf20c6b9fb737a0387c0f62f0b 100644 (file)
@@ -1,5 +1,5 @@
 USING: ui.gadgets help.markup help.syntax ui.gadgets.grids
-ui.render colors ;
+ui.pens colors ;
 IN: ui.gadgets.grid-lines
 
 HELP: grid-lines
index 3fbcad8a028b4da70a70ed17e98587bf56684e4a..ef9264668bef8fb20f4b36d346519734c7cb01ae 100755 (executable)
@@ -1,7 +1,7 @@
 ! Copyright (C) 2006, 2009 Slava Pestov.
 ! See http://factorcode.org/license.txt for BSD license.
 USING: kernel accessors math namespaces opengl opengl.gl
-sequences math.vectors ui.gadgets ui.gadgets.grids
+sequences math.vectors ui.pens ui.gadgets ui.gadgets.grids
 ui.gadgets.grids.private ui.render math.rectangles
 fry locals arrays assocs ;
 IN: ui.gadgets.grid-lines
index 27ffc3bd0587c5a0a4b9b02a387955df0cd41b30..ddadb6b99edce0e53cce10ce9d32eb185160086b 100644 (file)
@@ -1,6 +1,7 @@
 ! Copyright (C) 2009 Slava Pestov.
 ! See http://factorcode.org/license.txt for BSD license.
-USING: kernel accessors ui.images ui.render ui.gadgets ;
+USING: kernel accessors ui.images ui.pens
+ui.pens.image ui.gadgets ;
 IN: ui.gadgets.icons
 
 TUPLE: icon < gadget ;
index 6b7d948ae1325872039b66acda5de637c36a376b..b574263285bf454d92d7f2ac3e63347d35807a05 100644 (file)
@@ -9,14 +9,6 @@ HELP: <labelled-gadget>
 { $values { "gadget" gadget } { "title" string } { "newgadget" "a new " { $link <labelled-gadget> } } }
 { $description "Creates a new " { $link labelled-gadget } " display " { $snippet "gadget" } " with " { $snippet "title" } " on top." } ;
 
-HELP: closable-gadget
-{ $class-description "A closable gadget displays a title bar with a close box on top of another gadget. Clicking the close box invokes a quotation. Closable gadgets are created by calling " { $link <closable-gadget> } "." } ;
-
-HELP: <closable-gadget>
-{ $values { "gadget" gadget } { "title" string } { "quot" { $quotation "( button -- )" } } }
-{ $description "Creates a new " { $link closable-gadget } ". Clicking the close box calls " { $snippet "quot" } "." }
-{ $notes "The quotation can find the " { $link closable-gadget } " instance, or any other parent gadget by calling " { $link find-parent } " with the gadget it receives on the stack." } ;
-
 HELP: <labelled-pane>
 { $values { "model" model } { "quot" { $quotation "( value -- )" } } { "scrolls?" "a boolean" } { "title" string } { "gadget" "a new " { $link gadget } } }
 { $description "Creates a new control delegating to a " { $link pane } ", and wraps it in a " { $link labelled-gadget } ". When the value of the model changes, the value is pushed on the stack and the quotation is called using " { $link with-pane } "." } ;
@@ -26,9 +18,6 @@ HELP: <labelled-pane>
 ARTICLE: "ui.gadgets.labelled" "Labelled gadgets"
 "The " { $vocab-link "ui.gadgets.labelled" } " vocabulary implements labelled borders around child gadgets."
 { $subsection labelled-gadget }
-{ $subsection <labelled-gadget> }
-"Or a labelled border with a close box:"
-{ $subsection closable-gadget }
-{ $subsection <closable-gadget> } ;
+{ $subsection <labelled-gadget> } ;
 
 ABOUT: "ui.gadgets.labelled"
index 32037310ee893939ae84e02d3cd97b758a11a4bf..4619aecbf28e8b9616264f2f89c5a9d8b15d6262 100644 (file)
@@ -2,8 +2,8 @@
 ! See http://factorcode.org/license.txt for BSD license.
 USING: accessors arrays hashtables io kernel math math.functions
 namespaces make opengl sequences strings splitting ui.gadgets
-ui.gadgets.tracks ui.gadgets.packs fonts ui.render ui.text
-colors colors.constants models combinators ;
+ui.gadgets.tracks ui.gadgets.packs fonts ui.render ui.pens.solid
+ui.text colors colors.constants models combinators ;
 IN: ui.gadgets.labels
 
 ! A label gadget draws a string.
index f58628e5c620982495e0ffd558e094875f7336d9..38f4b5ac1540d2f43feb4694ba2dd6257a8749f0 100644 (file)
@@ -1,4 +1,5 @@
-USING: help.markup help.syntax ui.gadgets models models.range ;
+USING: help.markup help.syntax ui.gadgets models models.range
+ui.gadgets.sliders.private ;
 IN: ui.gadgets.sliders
 
 HELP: elevator
index f6353112cde1d020a3d90a668aa395d06e4131bd..fc1ce968039c21f7a1665df315d887c7b373a08b 100644 (file)
@@ -3,8 +3,8 @@
 USING: accessors arrays assocs kernel math namespaces sequences
 vectors models models.range math.vectors math.functions quotations
 colors colors.constants math.rectangles fry combinators ui.gestures
-ui.gadgets ui.gadgets.buttons ui.gadgets.tracks math.order
-ui.gadgets.theme ui.gadgets.icons ui.render ;
+ui.pens ui.gadgets ui.gadgets.buttons ui.gadgets.tracks math.order
+ui.gadgets.theme ui.gadgets.icons ui.pens.tile ui.pens.image ;
 IN: ui.gadgets.sliders
 
 TUPLE: slider < track elevator thumb saved line ;
index 3a9ed46330937819806cc456972c5b9891eea00d..d168a868e13ae4f58d6cb694495a6730eb64c5a0 100644 (file)
@@ -1,11 +1,15 @@
 ! Copyright (C) 2005, 2009 Slava Pestov.
 ! Copyright (C) 2006, 2007 Alex Chapman.
 ! See http://factorcode.org/license.txt for BSD license.
-USING: arrays kernel sequences ui.gadgets ui.render
-ui.text colors colors.gray colors.constants accessors ;
+USING: arrays kernel sequences ui.gadgets ui.pens.solid
+ui.pens.gradient ui.text ui.images colors colors.gray
+colors.constants accessors io.pathnames ;
 QUALIFIED: colors
 IN: ui.gadgets.theme
 
+: theme-image ( name -- image-name )
+    "resource:basis/ui/gadgets/theme/" prepend-path ".tiff" append <image-name> ;
+
 : solid-interior ( gadget color -- gadget )
     <solid> >>interior ; inline
 
index c948cb73b9d3ebc7b2a4295f84a19bf8130636a1..ac066593e140bda2cd591351cc8e00234adfd940 100644 (file)
@@ -1,6 +1,6 @@
 USING: ui.gadgets ui.render ui.text ui.text.private
 ui.gestures ui.backend help.markup help.syntax
-models opengl opengl.sprites strings ;
+models opengl strings ;
 IN: ui.gadgets.worlds
 
 HELP: user-input
index 6ac7d4bcd5d95088da895191fd3302958cb63e88..ebffb0bfbc8888f354328be505dee45980454504 100644 (file)
@@ -1,4 +1,4 @@
-USING: ui.gadgets ui.gadgets.worlds help.markup help.syntax
+USING: ui.gadgets help.markup help.syntax
 hashtables strings kernel system ;
 IN: ui.gestures
 
diff --git a/basis/ui/pens/authors.txt b/basis/ui/pens/authors.txt
new file mode 100644 (file)
index 0000000..d4f5d6b
--- /dev/null
@@ -0,0 +1 @@
+Slava Pestov
\ No newline at end of file
diff --git a/basis/ui/pens/caching/authors.txt b/basis/ui/pens/caching/authors.txt
new file mode 100644 (file)
index 0000000..d4f5d6b
--- /dev/null
@@ -0,0 +1 @@
+Slava Pestov
\ No newline at end of file
diff --git a/basis/ui/pens/caching/caching-tests.factor b/basis/ui/pens/caching/caching-tests.factor
new file mode 100644 (file)
index 0000000..3a655b2
--- /dev/null
@@ -0,0 +1,4 @@
+! Copyright (C) 2009 Slava Pestov.
+! See http://factorcode.org/license.txt for BSD license.
+USING: tools.test ui.pens.caching ;
+IN: ui.pens.caching.tests
diff --git a/basis/ui/pens/caching/caching.factor b/basis/ui/pens/caching/caching.factor
new file mode 100644 (file)
index 0000000..f137ac3
--- /dev/null
@@ -0,0 +1,16 @@
+! Copyright (C) 2009 Slava Pestov.
+! See http://factorcode.org/license.txt for BSD license.
+USING: accessors kernel ;
+IN: ui.pens.caching
+
+! A pen that caches vertex arrays, etc
+TUPLE: caching-pen last-dim ;
+
+GENERIC: recompute-pen ( gadget pen -- )
+
+: compute-pen ( gadget pen -- )
+    2dup [ dim>> ] [ last-dim>> ] bi* eq? [
+        2drop
+    ] [
+        [ swap dim>> >>last-dim drop ] [ recompute-pen ] 2bi
+    ] if ;
diff --git a/basis/ui/pens/gradient/authors.txt b/basis/ui/pens/gradient/authors.txt
new file mode 100644 (file)
index 0000000..d4f5d6b
--- /dev/null
@@ -0,0 +1 @@
+Slava Pestov
\ No newline at end of file
diff --git a/basis/ui/pens/gradient/gradient-docs.factor b/basis/ui/pens/gradient/gradient-docs.factor
new file mode 100644 (file)
index 0000000..35697a8
--- /dev/null
@@ -0,0 +1,6 @@
+IN: ui.pens.gradient
+USING: help.markup help.syntax ui.pens colors ;
+
+HELP: gradient
+{ $class-description "A class implementing the " { $link draw-interior } " generic word to draw a smoothly shaded transition between colors. The " { $snippet "colors" } " slot stores a sequence of " { $link color } " instances, and the gradient is drawn in the direction given by the " { $snippet "orientation" } " slot of the gadget." }
+{ $notes "See " { $link "colors" } "." } ;
diff --git a/basis/ui/pens/gradient/gradient-tests.factor b/basis/ui/pens/gradient/gradient-tests.factor
new file mode 100644 (file)
index 0000000..63134b3
--- /dev/null
@@ -0,0 +1,4 @@
+! Copyright (C) 2009 Slava Pestov.
+! See http://factorcode.org/license.txt for BSD license.
+USING: tools.test ui.pens.gradient ;
+IN: ui.pens.gradient.tests
diff --git a/basis/ui/pens/gradient/gradient.factor b/basis/ui/pens/gradient/gradient.factor
new file mode 100644 (file)
index 0000000..a137ae0
--- /dev/null
@@ -0,0 +1,44 @@
+! Copyright (C) 2009 Slava Pestov.
+! See http://factorcode.org/license.txt for BSD license.
+USING: kernel accessors math math.vectors locals sequences
+specialized-arrays.float colors arrays combinators
+opengl opengl.gl ui.pens ui.pens.caching ;
+IN: ui.pens.gradient
+
+! Gradient pen
+TUPLE: gradient < caching-pen colors last-vertices last-colors ;
+
+: <gradient> ( colors -- gradient ) gradient new swap >>colors ;
+
+<PRIVATE
+
+:: gradient-vertices ( direction dim colors -- seq )
+    direction dim v* dim over v- swap
+    colors length dup 1- v/n [ v*n ] with map
+    swap [ over v+ 2array ] curry map
+    concat concat >float-array ;
+
+: gradient-colors ( colors -- seq )
+    [ >rgba-components 4array dup 2array ] map concat concat
+    >float-array ;
+
+M: gradient recompute-pen ( gadget gradient -- )
+    [ nip ] [ [ [ orientation>> ] [ dim>> ] bi ] [ colors>> ] bi* ] 2bi
+    [ gradient-vertices >>last-vertices ]
+    [ gradient-colors >>last-colors ]
+    bi drop ;
+
+: draw-gradient ( colors -- )
+    GL_COLOR_ARRAY [
+        [ GL_QUAD_STRIP 0 ] dip length 2 * glDrawArrays
+    ] do-enabled-client-state ;
+
+PRIVATE>
+
+M: gradient draw-interior
+    {
+        [ compute-pen ]
+        [ last-vertices>> gl-vertex-pointer ]
+        [ last-colors>> gl-color-pointer ]
+        [ colors>> draw-gradient ]
+    } cleave ;
\ No newline at end of file
diff --git a/basis/ui/pens/image/authors.txt b/basis/ui/pens/image/authors.txt
new file mode 100644 (file)
index 0000000..d4f5d6b
--- /dev/null
@@ -0,0 +1 @@
+Slava Pestov
\ No newline at end of file
diff --git a/basis/ui/pens/image/image-tests.factor b/basis/ui/pens/image/image-tests.factor
new file mode 100644 (file)
index 0000000..797a203
--- /dev/null
@@ -0,0 +1,4 @@
+! Copyright (C) 2009 Slava Pestov.
+! See http://factorcode.org/license.txt for BSD license.
+USING: tools.test ui.pens.image ;
+IN: ui.pens.image.tests
diff --git a/basis/ui/pens/image/image.factor b/basis/ui/pens/image/image.factor
new file mode 100644 (file)
index 0000000..a1ed32e
--- /dev/null
@@ -0,0 +1,19 @@
+! Copyright (C) 2009 Slava Pestov.
+! See http://factorcode.org/license.txt for BSD license.
+USING: kernel accessors sequences fry math
+opengl ui.pens ui.images ;
+IN: ui.pens.image
+
+! Image pen
+TUPLE: image-pen image fill? ;
+
+: <image-pen> ( image -- pen ) f image-pen boa ;
+
+M: image-pen draw-interior
+    [ dim>> ] [ [ image>> ] [ fill?>> ] bi ] bi*
+    [ draw-scaled-image ] [
+        [ image-dim [ - 2/ ] 2map ] keep
+        '[ _ draw-image ] with-translation
+    ] if ;
+
+M: image-pen pen-pref-dim nip image>> image-dim ;
\ No newline at end of file
diff --git a/basis/ui/pens/pens-docs.factor b/basis/ui/pens/pens-docs.factor
new file mode 100644 (file)
index 0000000..d12a0c8
--- /dev/null
@@ -0,0 +1,24 @@
+IN: ui.pens
+USING: help.markup help.syntax kernel ui.gadgets ;
+
+HELP: draw-interior
+{ $values { "interior" object } { "gadget" gadget } } 
+{ $contract "Draws the interior of a gadget by making OpenGL calls. The " { $snippet "interior" } " slot may be set to objects implementing this generic word." } ;
+
+HELP: draw-boundary
+{ $values { "boundary" object } { "gadget" gadget } } 
+{ $contract "Draws the boundary of a gadget by making OpenGL calls. The " { $snippet "boundary" } " slot may be set to objects implementing this generic word." } ;
+
+ARTICLE: "ui-pen-protocol" "UI pen protocol"
+"The " { $snippet "interior" } " and " { $snippet "boundary" } " slots of a gadget facilitate easy factoring and sharing of drawing logic. Objects stored in these slots must implement the pen protocol:"
+{ $subsection draw-interior }
+{ $subsection draw-boundary }
+"The default value of these slots is the " { $link f } " singleton, which implements the above protocol by doing nothing."
+$nl
+"Some other pre-defined implementations:"
+{ $vocab-subsection "ui.pens.gradient" }
+{ $vocab-subsection "ui.pens.image" }
+{ $vocab-subsection "ui.pens.polygon" }
+{ $vocab-subsection "ui.pens.solid" }
+{ $vocab-subsection "ui.pens.tile" }
+"Custom implementations must follow the guidelines set forth in " { $link "ui-paint-custom" } "." ;
\ No newline at end of file
diff --git a/basis/ui/pens/pens-tests.factor b/basis/ui/pens/pens-tests.factor
new file mode 100644 (file)
index 0000000..422e352
--- /dev/null
@@ -0,0 +1,4 @@
+! Copyright (C) 2009 Slava Pestov.
+! See http://factorcode.org/license.txt for BSD license.
+USING: tools.test ui.pens ;
+IN: ui.pens.tests
diff --git a/basis/ui/pens/pens.factor b/basis/ui/pens/pens.factor
new file mode 100644 (file)
index 0000000..01724f1
--- /dev/null
@@ -0,0 +1,12 @@
+! Copyright (C) 2009 Slava Pestov.
+! See http://factorcode.org/license.txt for BSD license.
+USING: kernel ;
+IN: ui.pens
+
+GENERIC: draw-interior ( gadget interior -- )
+
+GENERIC: draw-boundary ( gadget boundary -- )
+
+GENERIC: pen-pref-dim ( gadget pen -- dim )
+
+M: object pen-pref-dim 2drop { 0 0 } ;
\ No newline at end of file
diff --git a/basis/ui/pens/polygon/authors.txt b/basis/ui/pens/polygon/authors.txt
new file mode 100644 (file)
index 0000000..d4f5d6b
--- /dev/null
@@ -0,0 +1 @@
+Slava Pestov
\ No newline at end of file
diff --git a/basis/ui/pens/polygon/polygon-docs.factor b/basis/ui/pens/polygon/polygon-docs.factor
new file mode 100644 (file)
index 0000000..706c144
--- /dev/null
@@ -0,0 +1,14 @@
+IN: ui.pens.polygon
+USING: help.markup help.syntax ;
+
+HELP: polygon
+{ $class-description "A class implementing the " { $link draw-boundary } " and " { $link draw-interior } " generic words to draw a solid outline or a solid filled polygon, respectively. Instances of " { $link polygon } " have two slots:"
+    { $list
+        { { $snippet "color" } " - a " { $link color } }
+        { { $snippet "points" } " - a sequence of points" }
+    }
+} ;
+
+HELP: <polygon>
+{ $values { "color" color } { "points" "a sequence of points" } { "polygon" polygon } }
+{ $description "Creates a new instance of " { $link polygon } "." } ;
diff --git a/basis/ui/pens/polygon/polygon-tests.factor b/basis/ui/pens/polygon/polygon-tests.factor
new file mode 100644 (file)
index 0000000..529b4f4
--- /dev/null
@@ -0,0 +1,4 @@
+! Copyright (C) 2009 Slava Pestov.
+! See http://factorcode.org/license.txt for BSD license.
+USING: tools.test ui.pens.polygon ;
+IN: ui.pens.polygon.tests
diff --git a/basis/ui/pens/polygon/polygon.factor b/basis/ui/pens/polygon/polygon.factor
new file mode 100644 (file)
index 0000000..fa2aa22
--- /dev/null
@@ -0,0 +1,29 @@
+! Copyright (C) 2009 Slava Pestov.
+! See http://factorcode.org/license.txt for BSD license.
+USING: ;
+IN: ui.pens.polygon
+
+! Polygon pen
+TUPLE: polygon color
+interior-vertices
+interior-count
+boundary-vertices
+boundary-count ;
+
+: <polygon> ( color points -- polygon )
+    dup close-path [ [ concat >float-array ] [ length ] bi ] bi@
+    polygon boa ;
+
+M: polygon draw-boundary
+    nip
+    [ color>> gl-color ]
+    [ boundary-vertices>> gl-vertex-pointer ]
+    [ [ GL_LINE_STRIP 0 ] dip boundary-count>> glDrawArrays ]
+    tri ;
+
+M: polygon draw-interior
+    nip
+    [ color>> gl-color ]
+    [ interior-vertices>> gl-vertex-pointer ]
+    [ [ GL_POLYGON 0 ] dip interior-count>> glDrawArrays ]
+    tri ;
\ No newline at end of file
diff --git a/basis/ui/pens/solid/authors.txt b/basis/ui/pens/solid/authors.txt
new file mode 100644 (file)
index 0000000..d4f5d6b
--- /dev/null
@@ -0,0 +1 @@
+Slava Pestov
\ No newline at end of file
diff --git a/basis/ui/pens/solid/solid-docs.factor b/basis/ui/pens/solid/solid-docs.factor
new file mode 100644 (file)
index 0000000..2dc1db1
--- /dev/null
@@ -0,0 +1,6 @@
+IN: ui.pens.solid
+USING: help.markup help.syntax ui.pens colors ;
+
+HELP: solid
+{ $class-description "A class implementing the " { $link draw-boundary } " and " { $link draw-interior } " generic words to draw a solid outline or a solid fill, respectively. The " { $snippet "color" } " slot stores an instance of " { $link color } "." }
+{ $notes "See " { $link "colors" } "." } ;
diff --git a/basis/ui/pens/solid/solid-tests.factor b/basis/ui/pens/solid/solid-tests.factor
new file mode 100644 (file)
index 0000000..ab6234a
--- /dev/null
@@ -0,0 +1,4 @@
+! Copyright (C) 2009 Slava Pestov.
+! See http://factorcode.org/license.txt for BSD license.
+USING: tools.test ui.pens.solid ;
+IN: ui.pens.solid.tests
diff --git a/basis/ui/pens/solid/solid.factor b/basis/ui/pens/solid/solid.factor
new file mode 100644 (file)
index 0000000..d8f839e
--- /dev/null
@@ -0,0 +1,31 @@
+! Copyright (C) 2009 Slava Pestov.
+! See http://factorcode.org/license.txt for BSD license.
+USING: kernel accessors opengl ui.pens ui.pens.caching ;
+IN: ui.pens.solid
+
+! Solid fill/border
+TUPLE: solid < caching-pen color interior-vertices boundary-vertices ;
+
+: <solid> ( color -- solid ) solid new swap >>color ;
+
+M: solid recompute-pen
+    swap dim>>
+    [ (fill-rect-vertices) >>interior-vertices ]
+    [ (rect-vertices) >>boundary-vertices ]
+    bi drop ;
+
+<PRIVATE
+
+! Solid pen
+: (solid) ( gadget pen -- )
+    [ compute-pen ] [ color>> gl-color ] bi ;
+
+PRIVATE>
+
+M: solid draw-interior
+    [ (solid) ] [ interior-vertices>> gl-vertex-pointer ] bi
+    (gl-fill-rect) ;
+
+M: solid draw-boundary
+    [ (solid) ] [ boundary-vertices>> gl-vertex-pointer ] bi
+    (gl-rect) ;
\ No newline at end of file
diff --git a/basis/ui/pens/tile/authors.txt b/basis/ui/pens/tile/authors.txt
new file mode 100644 (file)
index 0000000..d4f5d6b
--- /dev/null
@@ -0,0 +1 @@
+Slava Pestov
\ No newline at end of file
diff --git a/basis/ui/pens/tile/tile-tests.factor b/basis/ui/pens/tile/tile-tests.factor
new file mode 100644 (file)
index 0000000..b406b7b
--- /dev/null
@@ -0,0 +1,4 @@
+! Copyright (C) 2009 Slava Pestov.
+! See http://factorcode.org/license.txt for BSD license.
+USING: tools.test ui.pens.tile ;
+IN: ui.pens.tile.tests
diff --git a/basis/ui/pens/tile/tile.factor b/basis/ui/pens/tile/tile.factor
new file mode 100644 (file)
index 0000000..2909aa4
--- /dev/null
@@ -0,0 +1,48 @@
+! Copyright (C) 2009 Slava Pestov.
+! See http://factorcode.org/license.txt for BSD license.
+USING: kernel accessors math.vectors ui.images opengl fry
+combinators ui.pens ;
+IN: ui.pens.tile
+
+! Tile pen
+TUPLE: tile-pen left center right ;
+
+: <tile-pen> ( left center right -- pen )
+    tile-pen boa ;
+
+: >tile-pen< ( pen -- left center right )
+    [ left>> ] [ center>> ] [ right>> ] tri ; inline
+
+M: tile-pen pen-pref-dim
+    swap [
+        >tile-pen< [ image-dim ] tri@
+        [ vmax vmax ] [ v+ v+ ] 3bi
+    ] dip orientation>> set-axis ;
+
+: compute-tile-xs ( gadget pen -- x1 x2 x3 )
+    [ 2drop { 0 0 } ]
+    [ nip left>> image-dim ]
+    [ [ dim>> ] [ right>> image-dim ] bi* v- ]
+    2tri ;
+
+: compute-tile-widths ( gadget pen -- w1 w2 w3 )
+    [ nip left>> image-dim ]
+    [ [ dim>> ] [ [ left>> ] [ right>> ] bi [ image-dim ] bi@ ] bi* v+ v- ]
+    [ nip right>> image-dim ]
+    2tri ;
+
+: render-tile ( tile x width gadget -- )
+    [ orientation>> '[ _ v* ] dip ] keep
+   '[
+       _ _ [ dim>> swap ] [ orientation>> ] bi set-axis
+       swap draw-scaled-image
+   ] with-translation ;
+
+M: tile-pen draw-interior ( gadget pen -- )
+    {
+        [ nip >tile-pen< ]
+        [ compute-tile-xs ]
+        [ compute-tile-widths ]
+        [ drop ]
+    } 2cleave
+    [ render-tile ] curry tri-curry@ tri-curry* tri* ;
\ No newline at end of file
index 09bace0ab0e221544ddcea4453f4c3f6de767202..dd499896649656c6e005af46e5c9306676c23000 100644 (file)
@@ -1,4 +1,4 @@
-USING: ui.gadgets ui.gestures help.markup help.syntax
+USING: ui.gadgets ui.pens ui.gestures help.markup help.syntax
 kernel classes strings opengl opengl.gl models
 math.rectangles math colors ;
 IN: ui.render
@@ -14,8 +14,8 @@ HELP: gadget
         { { $snippet "visible?" } " - a boolean indicating if the gadget should display and receive user input." }
         { { $snippet "root?" } " - if set to " { $link t } ", layout changes in this gadget will not propagate to the gadget's parent." }
         { { $snippet "clipped?" } " - a boolean indicating if clipping will be enabled when drawing this gadget's children." }
-        { { $snippet "interior" } " - an object whose class implements the " { $link draw-interior } " generic word." }
-        { { $snippet "boundary" } " - an object whose class implements the " { $link draw-boundary } " generic word." }
+        { { $snippet "interior" } " - an implementation of the " { $link "ui-pen-protocol" } }
+        { { $snippet "boundary" } " - an implementation of the " { $link "ui-pen-protocol" } }
         { { $snippet "model" } " - a " { $link model } " or " { $link f } "; see " { $link "ui-control-impl" } }
     }
 "Gadgets subclass the " { $link rect } " class, and thus all instances have " { $snippet "loc" } " and " { $snippet "dim" } " instances holding their location and dimensions." }
@@ -30,49 +30,6 @@ HELP: draw-gadget*
 { $contract "Draws the gadget by making OpenGL calls. The top-left corner of the gadget should be drawn at the location stored in the " { $link origin } " variable." }
 { $notes "This word should not be called directly. To force a gadget to redraw, call " { $link relayout-1 } "." } ;
 
-HELP: draw-interior
-{ $values { "interior" object } { "gadget" gadget } } 
-{ $contract "Draws the interior of a gadget by making OpenGL calls. The " { $snippet "interior" } " slot may be set to objects implementing this generic word." } ;
-
-HELP: draw-boundary
-{ $values { "boundary" object } { "gadget" gadget } } 
-{ $contract "Draws the boundary of a gadget by making OpenGL calls. The " { $snippet "boundary" } " slot may be set to objects implementing this generic word." } ;
-
-HELP: solid
-{ $class-description "A class implementing the " { $link draw-boundary } " and " { $link draw-interior } " generic words to draw a solid outline or a solid fill, respectively. The " { $snippet "color" } " slot stores an instance of " { $link color } "." }
-{ $notes "See " { $link "colors" } "." } ;
-
-HELP: gradient
-{ $class-description "A class implementing the " { $link draw-interior } " generic word to draw a smoothly shaded transition between colors. The " { $snippet "colors" } " slot stores a sequence of " { $link color } " instances, and the gradient is drawn in the direction given by the " { $snippet "orientation" } " slot of the gadget." }
-{ $notes "See " { $link "colors" } "." } ;
-
-HELP: polygon
-{ $class-description "A class implementing the " { $link draw-boundary } " and " { $link draw-interior } " generic words to draw a solid outline or a solid filled polygon, respectively. Instances of " { $link polygon } " have two slots:"
-    { $list
-        { { $snippet "color" } " - a " { $link color } }
-        { { $snippet "points" } " - a sequence of points" }
-    }
-} ;
-
-HELP: <polygon>
-{ $values { "color" color } { "points" "a sequence of points" } { "polygon" polygon } }
-{ $description "Creates a new instance of " { $link polygon } "." } ;
-
-HELP: <polygon-gadget>
-{ $values { "color" color } { "points" "a sequence of points" } { "gadget" "a new " { $link gadget } } }
-{ $description "Creates a gadget which is drawn as a solid filled polygon. The gadget's size is the minimum bounding box containing all the points of the polygon." } ;
-
-ARTICLE: "gadgets-polygons" "Polygon gadgets"
-"A polygon gadget renders a simple shaded polygon."
-{ $subsection <polygon-gadget> }
-"Some pre-made polygons:"
-{ $subsection arrow-up }
-{ $subsection arrow-right }
-{ $subsection arrow-down }
-{ $subsection arrow-left }
-{ $subsection close-box }
-"Polygon gadgets are rendered by the " { $link polygon } " pen protocol implementation." ;
-
 ARTICLE: "ui-paint" "Customizing gadget appearance"
 "The UI carries out the following steps when drawing a gadget:"
 { $list
@@ -85,23 +42,9 @@ ARTICLE: "ui-paint" "Customizing gadget appearance"
 { $subsection "ui-pen-protocol" }
 { $subsection "ui-paint-custom" } ;
 
-ARTICLE: "ui-pen-protocol" "UI pen protocol"
-"The " { $snippet "interior" } " and " { $snippet "boundary" } " slots of a gadget facilitate easy factoring and sharing of drawing logic. Objects stored in these slots must implement the pen protocol:"
-{ $subsection draw-interior }
-{ $subsection draw-boundary }
-"The default value of these slots is the " { $link f } " singleton, which implements the above protocol by doing nothing."
-$nl
-"Some other pre-defined implementations:"
-{ $subsection solid }
-{ $subsection gradient }
-{ $subsection polygon }
-"Custom implementations must follow the guidelines set forth in " { $link "ui-paint-custom" } "." ;
-
 ARTICLE: "ui-paint-coord" "The UI co-ordinate system"
-"The UI uses a co-ordinate system where the y axis is oriented down. The OpenGL " { $link GL_MODELVIEW } " matrix is not saved or restored when rendering a gadget. Instead, the origin of the gadget relative to the OpenGL context is stored in a variable:"
+"The UI uses a co-ordinate system where the y axis is oriented down. The OpenGL " { $link GL_MODELVIEW } " matrix is saved or restored when rendering a gadget, and the origin is translated to the gadget's origin within the window. The current origin is stored in a variable:"
 { $subsection origin }
-"Custom drawing implementations can translate co-ordinates manually, or save and restore the " { $link GL_MODELVIEW } " matrix using a word such as " { $link with-translation } "."
-$nl
 "Gadgets must not draw outside of their bounding box, however clipping is not enforced by default, for performance reasons. This can be changed by setting the " { $slot "clipped?" } " slot to " { $link t } " in the gadget's constructor." ;
 
 ABOUT: "ui-paint"
index 5712765949450fa3bf5e73038b52917b4fd5e01f..89bf3066ca84497a8fec4003bcfc41c5a5042e86 100755 (executable)
@@ -1,10 +1,8 @@
 ! Copyright (C) 2005, 2009 Slava Pestov.
 ! See http://factorcode.org/license.txt for BSD license.
-USING: accessors alien alien.c-types arrays hashtables io io.pathnames
-kernel math namespaces opengl opengl.gl opengl.glu sequences strings
-vectors combinators math.vectors ui.gadgets ui.images colors fry
-colors.constants math.order math.rectangles locals
-specialized-arrays.float ;
+USING: math.rectangles math.vectors namespaces kernel accessors
+combinators sequences opengl opengl.gl opengl.glu colors.constants
+ui.gadgets ui.pens ;
 IN: ui.render
 
 SYMBOL: clip
@@ -46,14 +44,6 @@ GENERIC: draw-gadget* ( gadget -- )
 
 M: gadget draw-gadget* drop ;
 
-GENERIC: draw-interior ( gadget interior -- )
-
-GENERIC: draw-boundary ( gadget boundary -- )
-
-GENERIC: pen-pref-dim ( gadget pen -- dim )
-
-M: object pen-pref-dim 2drop { 0 0 } ;
-
 SYMBOL: origin
 
 { 0 0 } origin set-global
@@ -96,166 +86,4 @@ DEFER: draw-gadget
         { [ dup visible?>> not ] [ drop ] }
         { [ dup clipped?>> not ] [ (draw-gadget) ] }
         [ [ (draw-gadget) ] with-clipping ]
-    } cond ;
-
-! A pen that caches vertex arrays, etc
-TUPLE: caching-pen last-dim ;
-
-GENERIC: recompute-pen ( gadget pen -- )
-
-: compute-pen ( gadget pen -- )
-    2dup [ dim>> ] [ last-dim>> ] bi* = [
-        2drop
-    ] [
-        [ swap dim>> >>last-dim drop ] [ recompute-pen ] 2bi
-    ] if ;
-
-! Solid fill/border
-TUPLE: solid < caching-pen color interior-vertices boundary-vertices ;
-
-: <solid> ( color -- solid ) solid new swap >>color ;
-
-M: solid recompute-pen
-    swap dim>>
-    [ (fill-rect-vertices) >>interior-vertices ]
-    [ (rect-vertices) >>boundary-vertices ]
-    bi drop ;
-
-<PRIVATE
-
-! Solid pen
-: (solid) ( gadget pen -- )
-    [ compute-pen ] [ color>> gl-color ] bi ;
-
-PRIVATE>
-
-M: solid draw-interior
-    [ (solid) ] [ interior-vertices>> gl-vertex-pointer ] bi
-    (gl-fill-rect) ;
-
-M: solid draw-boundary
-    [ (solid) ] [ boundary-vertices>> gl-vertex-pointer ] bi
-    (gl-rect) ;
-
-! Gradient pen
-TUPLE: gradient < caching-pen colors last-vertices last-colors ;
-
-: <gradient> ( colors -- gradient ) gradient new swap >>colors ;
-
-<PRIVATE
-
-:: gradient-vertices ( direction dim colors -- seq )
-    direction dim v* dim over v- swap
-    colors length dup 1- v/n [ v*n ] with map
-    swap [ over v+ 2array ] curry map
-    concat concat >float-array ;
-
-: gradient-colors ( colors -- seq )
-    [ >rgba-components 4array dup 2array ] map concat concat
-    >float-array ;
-
-M: gradient recompute-pen ( gadget gradient -- )
-    [ nip ] [ [ [ orientation>> ] [ dim>> ] bi ] [ colors>> ] bi* ] 2bi
-    [ gradient-vertices >>last-vertices ]
-    [ gradient-colors >>last-colors ]
-    bi drop ;
-
-: draw-gradient ( colors -- )
-    GL_COLOR_ARRAY [
-        [ GL_QUAD_STRIP 0 ] dip length 2 * glDrawArrays
-    ] do-enabled-client-state ;
-
-PRIVATE>
-
-M: gradient draw-interior
-    {
-        [ compute-pen ]
-        [ last-vertices>> gl-vertex-pointer ]
-        [ last-colors>> gl-color-pointer ]
-        [ colors>> draw-gradient ]
-    } cleave ;
-
-! Polygon pen
-TUPLE: polygon color
-interior-vertices
-interior-count
-boundary-vertices
-boundary-count ;
-
-: <polygon> ( color points -- polygon )
-    dup close-path [ [ concat >float-array ] [ length ] bi ] bi@
-    polygon boa ;
-
-M: polygon draw-boundary
-    nip
-    [ color>> gl-color ]
-    [ boundary-vertices>> gl-vertex-pointer ]
-    [ [ GL_LINE_STRIP 0 ] dip boundary-count>> glDrawArrays ]
-    tri ;
-
-M: polygon draw-interior
-    nip
-    [ color>> gl-color ]
-    [ interior-vertices>> gl-vertex-pointer ]
-    [ [ GL_POLYGON 0 ] dip interior-count>> glDrawArrays ]
-    tri ;
-
-: theme-image ( name -- image-name )
-    "resource:basis/ui/gadgets/theme/" prepend-path ".tiff" append <image-name> ;
-
-! Image pen
-TUPLE: image-pen image fill? ;
-
-: <image-pen> ( image -- pen ) f image-pen boa ;
-
-M: image-pen draw-interior
-    [ dim>> ] [ [ image>> ] [ fill?>> ] bi ] bi*
-    [ draw-scaled-image ] [
-        [ image-dim [ - 2/ ] 2map ] keep
-        '[ _ draw-image ] with-translation
-    ] if ;
-
-M: image-pen pen-pref-dim nip image>> image-dim ;
-
-! Tile pen
-TUPLE: tile-pen left center right ;
-
-: <tile-pen> ( left center right -- pen )
-    tile-pen boa ;
-
-: >tile-pen< ( pen -- left center right )
-    [ left>> ] [ center>> ] [ right>> ] tri ; inline
-
-M: tile-pen pen-pref-dim
-    swap [
-        >tile-pen< [ image-dim ] tri@
-        [ vmax vmax ] [ v+ v+ ] 3bi
-    ] dip orientation>> set-axis ;
-
-: compute-tile-xs ( gadget pen -- x1 x2 x3 )
-    [ 2drop { 0 0 } ]
-    [ nip left>> image-dim ]
-    [ [ dim>> ] [ right>> image-dim ] bi* v- ]
-    2tri ;
-
-: compute-tile-widths ( gadget pen -- w1 w2 w3 )
-    [ nip left>> image-dim ]
-    [ [ dim>> ] [ [ left>> ] [ right>> ] bi [ image-dim ] bi@ ] bi* v+ v- ]
-    [ nip right>> image-dim ]
-    2tri ;
-
-: render-tile ( tile x width gadget -- )
-    [ orientation>> '[ _ v* ] dip ] keep
-   '[
-       _ _ [ dim>> swap ] [ orientation>> ] bi set-axis
-       swap draw-scaled-image
-   ] with-translation ;
-
-M: tile-pen draw-interior ( gadget pen -- )
-    {
-        [ nip >tile-pen< ]
-        [ compute-tile-xs ]
-        [ compute-tile-widths ]
-        [ drop ]
-    } 2cleave
-    [ render-tile ] curry tri-curry@ tri-curry* tri* ;
\ No newline at end of file
+    } cond ;
\ No newline at end of file
index 563856ee9db656baef126dff4c12f32c6392d73c..1b9d0fb08d2348fc9161ca26e72b0416454e0378 100644 (file)
@@ -8,7 +8,7 @@ generic.standard.engines.tuple fonts definitions.icons ui.images
 ui.commands ui.operations ui.gadgets ui.gadgets.editors
 ui.gadgets.glass ui.gadgets.scrollers ui.gadgets.tables
 ui.gadgets.tracks ui.gadgets.labelled ui.gadgets.theme
-ui.gadgets.worlds ui.gadgets.wrappers ui.gestures ui.render
+ui.gadgets.worlds ui.gadgets.wrappers ui.gestures ui.pens.solid
 ui.tools.listener.history combinators vocabs ui.tools.listener.popups ;
 IN: ui.tools.listener.completion
 
index 61046787b087f8f984f02126499f5f65b94fe941..929d6035f5b3058be59732bca62896f432acfd2e 100644 (file)
@@ -7,7 +7,7 @@ documents documents.elements fry hashtables help help.markup io
 io.styles kernel lexer listener math models models.delay models.filter
 namespaces parser prettyprint quotations sequences strings threads
 tools.vocabs vocabs vocabs.loader vocabs.parser words ui ui.commands
-ui.render ui.gadgets ui.gadgets.buttons ui.gadgets.editors
+ui.pens.solid ui.gadgets ui.gadgets.buttons ui.gadgets.editors
 ui.gadgets.labelled ui.gadgets.panes ui.gadgets.scrollers
 ui.gadgets.status-bar ui.gadgets.tracks ui.gadgets.borders ui.gestures
 ui.operations ui.tools.browser ui.tools.common ui.tools.debugger