packages feed

SFML-control 0.2.0.0 → 0.2.0.1

raw patch · 4 files changed

+99/−32 lines, 4 files

Files

SFML-control.cabal view
@@ -1,5 +1,5 @@ name:                SFML-control-version:             0.2.0.0+version:             0.2.0.1 synopsis:            Higher level library on top of SFML license:             MIT license-file:        LICENSE@@ -7,6 +7,7 @@ maintainer:          alfredo.dinapoli@gmail.com category:            Graphics build-type:          Simple+homepage:            https://github.com/SFML-haskell/SFML-control extra-source-files:  README.md cabal-version:       >=1.10 @@ -14,11 +15,10 @@   exposed-modules:       Control.Monad.SFML       Control.Monad.SFML.Types-      Control.Monad.SFML.Types.TH   other-modules:+      Control.Monad.SFML.Types.TH       Control.Monad.SFML.Types.Internal       Control.Monad.SFML.Conversions-  -- other-extensions:   build-depends:       base >= 4.6 && < 5,       mtl >= 2.0.0.0,
src/Control/Monad/SFML.hs view
@@ -1,9 +1,64 @@ {-# LANGUAGE TemplateHaskell #-} {-# LANGUAGE NoMonomorphismRestriction #-} ++{-|++This package builds on top of @SFML@ and offers an higher level of+abstraction over the original library, mainly exposing the 'SFML' monad,+which is responsible for allocating and running the destructors for your+managed objects. This allow us to program at an higher level of abstraction:+++> import Control.Monad.SFML+> import qualified SFML.Graphics as G+> import qualified SFML.Window as W+> import SFML.Graphics.Color+> +> import Paths_SFMLExamples+> +> main :: IO ()+> main = runSFML $ do+>     let ctxSettings = Just $ W.ContextSettings 24 8 0 1 2+>     wnd <- createRenderWindow (W.VideoMode 640 480 32)+>            "SFML-Control Demo" [W.SFDefaultStyle] ctxSettings+>     logoPath  <- liftIO $ getDataFileName "Haskell-Logo.png"+>     fontPath  <- liftIO $ getDataFileName "Vera.ttf"+>     musicPath <- liftIO $ getDataFileName "DST-BreakOut.ogg"+>     tex <- textureFromFile logoPath Nothing+>     spr <- createSprite+>     fnt <- fontFromFile fontPath+>     txt <- createText+>     setTextString txt "Haskell-Control\nhandles memory\nfor you"+>     setTextFont txt fnt+>     setTextCharacterSize txt 20+>     setTextColor txt blue+>     msc <- musicFromFile musicPath+>     play msc+>     setTexture spr tex True+>     loop wnd spr txt+> +> +> loop :: G.RenderWindow -> G.Sprite -> G.Text -> SFML ()+> loop wnd spr txt = do+>     drawSprite wnd spr Nothing+>     drawText   wnd txt $ Just (G.renderStates { G.transform = G.translation 460 40 })+>     display wnd+>     evt <- waitEvent wnd+>     case evt of+>         Nothing -> return ()+>         Just W.SFEvtClosed -> return ()+>         _ -> loop wnd spr txt++-}++ module Control.Monad.SFML   ( module Control.Monad.SFML.Types+  -- * Conversions+  -- $THConversion   , module Control.Monad.SFML.Conversions+  -- * Re-exports for your convenience   , liftIO   ) where @@ -18,6 +73,11 @@ import Control.Monad.SFML.Types import Control.Monad.SFML.Conversions +{- $THConversion++Almost the totality of this package is generated via Template Haskell.++-}  -------------------------------------------------------------------------------- drawRectangleOfSize :: Vec2f -> SFML G.RectangleShape
src/Control/Monad/SFML/Conversions.hs view
@@ -12,11 +12,16 @@ import Data.Maybe  -- | Run the given IO action and throw an error if it fails.+-- This function is the dual of SFML's 'err'. The idea here+-- is that we accept a certain level of pragmatism and assume+-- the underlying C library is unlikely to fail for out-of-memory+-- errors or data corruption. 'SFML' follows a more disciplined+-- approach. mb :: IO (Maybe a) -> IO a mb = (maybe (error "Nothing found.") return =<<)  --- Audio / Listener.hs+-- * Audio / Listener.hs $(lift 'A.setGlobalVolume) $(lift 'A.getGlobalVolume) $(lift 'A.setListenerPosition)@@ -24,7 +29,7 @@ $(lift 'A.setListenerDirection) $(lift 'A.getListenerDirection) --- Audio / Music.hs+-- * Audio / Music.hs $(liftWithDestroy 'G.err 'A.musicFromFile) $(liftWithDestroy 'G.err 'A.musicFromMemory) $(liftWithDestroy 'G.err 'A.musicFromStream)@@ -52,13 +57,13 @@ $(lift 'A.getMinDistance) $(lift 'A.getAttenuation) --- Audio / Sound.hs+-- * Audio / Sound.hs $(liftWithDestroy 'id 'A.createSound) $(lift 'A.copySound) $(lift 'A.setSoundBuffer) $(lift 'A.getSoundBuffer) --- Audio / SoundBuffer.hs+-- * Audio / SoundBuffer.hs $(liftWithDestroy 'G.err 'A.soundBufferFromFile) $(liftWithDestroy 'G.err 'A.soundBufferFromMemory) $(liftWithDestroy 'G.err 'A.soundBufferFromStream)@@ -68,19 +73,19 @@ $(lift 'A.getSamples) $(lift 'A.getSampleCount) --- Audio / SoundBufferRecorder.hs+-- * Audio / SoundBufferRecorder.hs $(liftWithDestroy 'G.err 'A.createSoundBufferRecorder) $(lift 'A.startRecording) $(lift 'A.stopRecording) --- Audio / SoundRecorder.hs+-- * Audio / SoundRecorder.hs $(liftWithDestroy 'G.err 'A.createSoundRecorder) $(lift 'A.isSoundRecorderAvailable) --- Audio / SoundStream.hs+-- * Audio / SoundStream.hs $(liftWithDestroy 'id 'A.createSoundStream) --- Graphics / CircleShape.hs+-- * Graphics / CircleShape.hs $(liftWithDestroy 'G.err 'G.createCircleShape) $(lift 'G.copy) $(lift 'G.setRotation)@@ -112,11 +117,11 @@ $(lift 'G.getLocalBounds) $(lift 'G.getGlobalBounds) --- Graphics / ConvexShape.hs+-- * Graphics / ConvexShape.hs $(liftWithDestroy 'G.err 'G.createConvexShape) $(lift 'G.setPoint) --- Graphics / Font.hs+-- * Graphics / Font.hs $(liftWithDestroy 'G.err 'G.fontFromFile) $(liftWithDestroy 'G.err 'G.fontFromMemory) $(liftWithDestroy 'G.err 'G.fontFromStream)@@ -125,7 +130,7 @@ $(lift 'G.getLineSpacing) $(lift 'G.getFontTexture) --- Graphics / Image.hs+-- * Graphics / Image.hs $(liftWithDestroy 'G.err 'G.createImage) $(liftWithDestroy 'id 'G.imageFromColor) $(liftWithDestroy 'id 'G.imageFromPixels)@@ -143,12 +148,12 @@ $(lift 'G.flipHorizontally) $(lift 'G.flipVertically) --- Graphics / RectangleShape.hs+-- * Graphics / RectangleShape.hs $(liftWithDestroy 'G.err 'G.createRectangleShape) $(lift 'G.setSize) $(lift 'G.getSize) --- Graphics / RenderTexture.hs+-- * Graphics / RenderTexture.hs $(liftWithDestroy 'G.err 'G.createRenderTexture) $(lift 'G.getTextureSize) $(lift 'G.setActive)@@ -174,7 +179,7 @@ $(lift 'G.setSmooth) $(lift 'G.isSmooth) --- Graphics / RenderWindow.hs+-- * Graphics / RenderWindow.hs $(liftWithDestroy 'id 'G.createRenderWindow) $(liftWithDestroy 'id 'G.renderWindowFromHandle) $(lift 'G.close)@@ -202,7 +207,7 @@ $(lift 'G.getMousePosition) $(lift 'G.setMousePosition) --- Graphics / Shader.hs+-- * Graphics / Shader.hs $(liftWithDestroy 'G.err 'G.shaderFromFile) $(liftWithDestroy 'G.err 'G.shaderFromMemory) $(liftWithDestroy 'G.err 'G.shaderFromStream)@@ -219,16 +224,16 @@ $(lift 'G.bind) $(lift 'G.isShaderAvailable) --- Graphics / Shape.hs+-- * Graphics / Shape.hs $(liftWithDestroy 'id 'G.createShape) $(lift 'G.updateShape) --- Graphics / Sprite.hs+-- * Graphics / Sprite.hs $(liftWithDestroy 'G.err 'G.createSprite) $(lift 'G.setColor) $(lift 'G.getColor) --- Graphics / Text.hs+-- * Graphics / Text.hs $(liftWithDestroy 'G.err 'G.createText) $(lift 'G.setTextString) $(lift 'G.setTextStringU)@@ -246,7 +251,7 @@ $(lift 'G.getTextLocalBounds) $(lift 'G.getTextGlobalBounds) --- Graphics / Texture.hs+-- * Graphics / Texture.hs $(liftWithDestroy 'G.err 'G.createTexture) $(liftWithDestroy 'G.err 'G.textureFromFile) $(liftWithDestroy 'G.err 'G.textureFromMemory)@@ -261,7 +266,7 @@ $(lift 'G.setRepeated) $(lift 'G.isRepeated) --- Graphics / VertexArray.hs+-- * Graphics / VertexArray.hs $(liftWithDestroy 'id 'G.createVA) $(lift 'G.getVertexCount) $(lift 'G.getVertex)@@ -272,7 +277,7 @@ $(lift 'G.getPrimitiveType) $(lift 'G.getVABounds) --- Graphics / View.hs+-- * Graphics / View.hs $(liftWithDestroy 'id 'G.createView) $(lift 'G.viewFromRect) $(lift 'G.copyView)@@ -289,20 +294,20 @@ $(lift 'G.rotateView) $(lift 'G.zoomView) --- System / Clock.hs+-- * System / Clock.hs $(liftWithDestroy 'id 'S.createClock) $(lift 'S.getElapsedTime) $(lift 'S.restartClock) --- System / Sleep.hsc+-- * System / Sleep.hsc $(lift 'S.sfSleep)  --- Window / Context.hsc+-- * Window / Context.hsc $(liftWithDestroy 'id 'W.createContext) $(lift 'W.setActiveContext) --- Window / Joystick.hs+-- * Window / Joystick.hs $(lift 'W.isJoystickConnected) $(lift 'W.getButtonCount) $(lift 'W.hasAxis)@@ -310,17 +315,17 @@ $(lift 'W.getAxisPosition) $(lift 'W.updateJoystick) --- Window / Keyboard.hs+-- * Window / Keyboard.hs $(lift 'W.isKeyPressed) --- Window / Mouse.hs+-- * Window / Mouse.hs $(lift 'W.isMouseButtonPressed) --- Window / VideoMode.hs+-- * Window / VideoMode.hs $(lift 'W.getDesktopMode) $(lift 'W.getFullscreenModes) $(lift 'W.isValid) --- Window / Window.hsc+-- * Window / Window.hsc $(liftWithDestroy 'id 'W.createWindow) $(liftWithDestroy 'id 'W.windowFromHandle)
src/Control/Monad/SFML/Types.hs view
@@ -8,5 +8,7 @@  -------------------------------------------------------------------------------- -- | Run the SFML monad, calling all the destructors appropriately.+-- The library is designed to force you to call this function to get back into+-- the 'IO' monad, so that every object is appropriately destroyed. runSFML :: SFML a -> IO () runSFML (SFML m) = join . fmap sequence_ . flip execStateT [] $ m