]> gitweb.factorcode.org Git - factor.git/commitdiff
ui.images: support image tuples as well as image-names
authortimor <timor.dd@googlemail.com>
Fri, 13 Nov 2020 19:20:58 +0000 (20:20 +0100)
committerJohn Benediktsson <mrjbq7@gmail.com>
Fri, 13 Nov 2020 19:34:25 +0000 (19:34 +0000)
Allows objects created by <image> to be used with <image-pen>, using the
image-texture-cache.

basis/ui/images/images.factor
basis/ui/pens/image/image.factor

index 49341263f4062ad2a7e85654fd6ac4a75c86631f..d35ba2fca2d3ab1e16616336ba4418380f2395a7 100644 (file)
@@ -1,8 +1,8 @@
 ! Copyright (C) 2009 Slava Pestov.
 ! See http://factorcode.org/license.txt for BSD license.
-USING: accessors assocs cache combinators images.loader kernel
-math memoize namespaces opengl opengl.textures sequences
-splitting system ui.gadgets.worlds vocabs ;
+USING: accessors assocs cache combinators images images.loader kernel math
+memoize namespaces opengl opengl.textures sequences splitting system
+ui.gadgets.worlds vocabs ;
 IN: ui.images
 
 TUPLE: image-name path ;
@@ -16,11 +16,15 @@ MEMO: cached-image-path ( path -- image )
 
 PRIVATE>
 
-: cached-image ( image-name -- image )
+GENERIC: cached-image ( image -- image )
+
+M: image-name cached-image
     path>> gl-scale-factor get-global [ 1.0 > ] [ f ] if* [
         "." split1-last "@2x." glue
     ] when cached-image-path ;
 
+M: image cached-image ;
+
 <PRIVATE
 
 : image-texture-cache ( world -- texture-cache )
@@ -28,17 +32,17 @@ PRIVATE>
 
 PRIVATE>
 
-: rendered-image ( image-name -- texture )
+: rendered-image ( image -- texture )
     world get image-texture-cache
     [ cached-image { 0 0 } <texture> ] cache ;
 
-: draw-image ( image-name -- )
+: draw-image ( image -- )
     rendered-image draw-texture ;
 
-: draw-scaled-image ( dim image-name -- )
+: draw-scaled-image ( dim image -- )
     rendered-image draw-scaled-texture ;
 
-: image-dim ( image-name -- dim )
+: image-dim ( image -- dim )
     cached-image [ dim>> ] [ 2x?>> [ [ 2 / ] map ] when ] bi ;
 
 {
index a8ec51ee2ac43f652eb07d364b023bbd6a13e284..d22ebe79637f9a2d16a76c681066f0ae2bfc6046 100644 (file)
@@ -7,7 +7,7 @@ IN: ui.pens.image
 ! Image pen
 TUPLE: image-pen image fill? ;
 
-: <image-pen> ( image-name -- pen ) f image-pen boa ;
+: <image-pen> ( image -- pen ) f image-pen boa ;
 
 M: image-pen draw-interior
     [ dim>> ] [ [ image>> ] [ fill?>> ] bi ] bi*