]> gitweb.factorcode.org Git - factor.git/commitdiff
new module images.viewer.prettyprint
authorJoe Groff <arcata@gmail.com>
Sun, 13 Nov 2011 20:10:23 +0000 (12:10 -0800)
committerJoe Groff <arcata@gmail.com>
Sun, 13 Nov 2011 20:12:23 +0000 (12:12 -0800)
Pretty-prints image objects as images.

basis/ui/gadgets/panes/panes.factor
extra/images/viewer/prettyprint/prettyprint.factor [new file with mode: 0644]

index 1680e7b2a874e015cb4882bde544889f9cd8e0e0..7752ae2ed6d54412f7c11f865f1f220af3a01645 100644 (file)
@@ -144,6 +144,9 @@ PRIVATE>
 
 GENERIC: write-gadget ( gadget stream -- )
 
+M: filter-writer write-gadget
+    stream>> write-gadget ;
+
 M: pane-stream write-gadget ( gadget pane-stream -- )
     pane>> current>> swap add-gadget drop ;
 
diff --git a/extra/images/viewer/prettyprint/prettyprint.factor b/extra/images/viewer/prettyprint/prettyprint.factor
new file mode 100644 (file)
index 0000000..771a0e6
--- /dev/null
@@ -0,0 +1,24 @@
+USING: accessors hashtables images images.viewer io io.styles
+kernel math namespaces prettyprint.custom prettyprint.sections
+sequences ui.gadgets.panes ;
+FROM: images => image ;
+IN: images.viewer.prettyprint
+
+TUPLE: image-section < section
+    image ;
+
+CONSTANT: approx-pixels-per-cell 8
+
+: <image-section> ( image -- section )
+    dup dim>> first approx-pixels-per-cell /i image-section new-section
+        over >>image
+        swap presented associate >>style ;
+
+M: image-section long-section
+    short-section ;
+M: image-section short-section
+    image>> <image-gadget> output-stream get write-gadget ;
+
+M: image pprint*
+    <image-section> add-section ;
+