diff --git a/src/play_clj/core.clj b/src/play_clj/core.clj index 5a84b9a..213bb0f 100644 --- a/src/play_clj/core.clj +++ b/src/play_clj/core.clj @@ -6,7 +6,6 @@ InputMultiplexer InputProcessor Net Screen] [com.badlogic.gdx.audio Sound] [com.badlogic.gdx.assets AssetManager] - [com.badlogic.gdx.files FileHandle] [com.badlogic.gdx.graphics Camera Color GL20 OrthographicCamera PerspectiveCamera Pixmap Pixmap$Format PixmapIO Texture VertexAttributes$Usage] [com.badlogic.gdx.graphics.g2d SpriteBatch] diff --git a/src/play_clj/core_utils.clj b/src/play_clj/core_utils.clj index fec49e1..5fa3c1d 100644 --- a/src/play_clj/core_utils.clj +++ b/src/play_clj/core_utils.clj @@ -7,34 +7,29 @@ [& body] `(app! :post-runnable (fn [] ~@body))) -(defn new-file! - "Creates a new [File](http://docs.oracle.com/javase/7/docs/api/java/io/File.html)" - ([name extension] - (new-file! "./" name extension)) - ([path name extension] - (java.io.File. (str path name extension)))) - -(defn capture-screen! - "Returns a [Pixmap](http://libgdx.badlogicgames.com/nightlies/docs/api/com/badlogic/gdx/graphics/Pixmap.html) that contains a capture of the current screen. - Note that you must call [dispose](http://libgdx.badlogicgames.com/nightlies/docs/api/com/badlogic/gdx/graphics/Pixmap.html#dispose) on the Pixmap or you will cause a memory leak on the native heap. - screenshot! captures and disposes the Pixmap automatically." - [] - (let [pixmap (Pixmap. (game :width) (game :height) (Pixmap$Format/RGBA8888)) - pixel-data (ScreenUtils/getFrameBufferPixels true) - pixels (.getPixels pixmap)] - (doto pixels - (.clear) - (.put pixel-data) - (.position)) - pixmap)) - (defn screenshot! - "Captures a screenshot and writes it to disk." - [] - (let [pixmap (capture-screen!) - handle (FileHandle. (new-file! (str (System/currentTimeMillis)) ".png"))] - (do (PixmapIO/writePNG handle pixmap) - (.dispose pixmap)))) + "Captures a screenshot and either returns it as a `pixmap` or saves it to the +specified path. + + (screenshot!) + (screenshot! \"out.png\") + (screenshot! (files! :external \"out.png\"))" + ([] + (let [pic (Pixmap. (game :width) (game :height) (Pixmap$Format/RGBA8888)) + pixel-data (ScreenUtils/getFrameBufferPixels true) + pixels (.getPixels pic)] + (doto pixels + (.clear) + (.put pixel-data) + (.position)) + pic)) + ([path] + (let [pic (screenshot!) + handle (if (string? path) + (files! :local path) + path)] + (PixmapIO/writePNG handle pic) + (.dispose pic)))) ; static fields