]> gitweb.factorcode.org Git - factor.git/blobdiff - basis/ui/images/images.factor
core: subseq-index? -> subseq-of?
[factor.git] / basis / ui / images / images.factor
index 31d2000fadb48b55a6a3e8dcdf0a155092a62ea5..7247f0c1d9226f467001e8d3925d6a4a23abde6a 100644 (file)
@@ -1,7 +1,7 @@
 ! 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
+USING: accessors assocs cache combinators images images.loader
+kernel math namespaces opengl opengl.textures sequences
 splitting system ui.gadgets.worlds vocabs ;
 IN: ui.images
 
@@ -12,15 +12,19 @@ C: <image-name> image-name
 <PRIVATE
 
 MEMO: cached-image-path ( path -- image )
-    [ load-image ] [ "@2x" swap subseq? >>2x? ] bi ;
+    [ load-image ] [ "@2x" subseq-of? >>2x? ] bi ;
 
 PRIVATE>
 
-: cached-image ( image-name -- image )
-    path>> gl-scale-factor get-global 1.0 > [
+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 ;
 
 {