1 ! Copyright (C) 2009 Slava Pestov.
2 ! See http://factorcode.org/license.txt for BSD license.
3 USING: accessors assocs cache combinators images.loader kernel
4 math memoize namespaces opengl opengl.textures sequences
5 splitting system ui.gadgets.worlds vocabs ;
8 TUPLE: image-name path ;
10 C: <image-name> image-name
14 MEMO: cached-image-path ( path -- image )
15 [ load-image ] [ "@2x" swap subseq? >>2x? ] bi ;
19 : cached-image ( image-name -- image )
20 path>> gl-scale-factor get-global 1.0 > [
21 "." split1-last "@2x." glue
22 ] when cached-image-path ;
26 : image-texture-cache ( world -- texture-cache )
27 [ [ <cache-assoc> ] unless* ] change-images images>> ;
31 : rendered-image ( image-name -- texture )
32 world get image-texture-cache
33 [ cached-image { 0 0 } <texture> ] cache ;
35 : draw-image ( image-name -- )
36 rendered-image draw-texture ;
38 : draw-scaled-image ( dim image-name -- )
39 rendered-image draw-scaled-texture ;
41 : image-dim ( image-name -- dim )
42 cached-image [ dim>> ] [ 2x?>> [ [ 2 / ] map ] when ] bi ;
45 { [ os macosx? ] [ "images.loader.cocoa" require ] }
46 { [ os windows? ] [ "images.loader.gdiplus" require ] }
47 { [ os { freebsd } member? ] [
51 [ "images.loader.gtk" require ]