never executed always true always false
1 {- |
2 Parameters define the global context of an animation. They are set once
3 before an animation is rendered and may not change during rendering.
4 -}
5 module Reanimate.Parameters
6 ( Raster(..)
7 , Width
8 , Height
9 , FPS
10 , pRaster
11 , pFPS
12 , pWidth
13 , pHeight
14 , pNoExternals
15 , pRootDirectory
16 , setRaster
17 , setFPS
18 , setWidth
19 , setHeight
20 , setNoExternals
21 , setRootDirectory
22 ) where
23
24 import System.IO.Unsafe
25 import Data.IORef
26
27 -- | Width of animation in pixels.
28 type Width = Int
29 -- | Height of animation in pixels.
30 type Height = Int
31 -- | Framerate of animation in frames per second.
32 type FPS = Int
33
34 -- | Raster engines turn SVG images into pixels.
35 data Raster
36 = RasterNone -- ^ Do not use any external raster engine. Rely on the browser or ffmpeg.
37 | RasterAuto -- ^ Scan for installed raster engines and pick the fastest one.
38 | RasterInkscape -- ^ Use Inkscape to raster SVG images.
39 | RasterRSvg -- ^ Use rsvg-convert to raster SVG images.
40 | RasterMagick -- ^ Use imagemagick to raster SVG images.
41 deriving (Show, Eq)
42
43 {-# NOINLINE pRasterRef #-}
44 pRasterRef :: IORef Raster
45 pRasterRef = unsafePerformIO (newIORef RasterNone)
46
47 {-# NOINLINE pRaster #-}
48 -- | Selected raster engine.
49 pRaster :: Raster
50 pRaster = unsafePerformIO (readIORef pRasterRef)
51
52 -- | Set raster engine.
53 setRaster :: Raster -> IO ()
54 setRaster = writeIORef pRasterRef
55
56 {-# NOINLINE pFPSRef #-}
57 pFPSRef :: IORef FPS
58 pFPSRef = unsafePerformIO (newIORef 0)
59
60 {-# NOINLINE pFPS #-}
61 -- | Selected framerate.
62 pFPS :: FPS
63 pFPS = unsafePerformIO (readIORef pFPSRef)
64
65 -- | Set desired framerate.
66 setFPS :: FPS -> IO ()
67 setFPS = writeIORef pFPSRef
68
69 {-# NOINLINE pWidthRef #-}
70 pWidthRef :: IORef FPS
71 pWidthRef = unsafePerformIO (newIORef 0)
72
73 {-# NOINLINE pWidth #-}
74 -- | Width of animation in pixel.
75 pWidth :: Width
76 pWidth = unsafePerformIO (readIORef pWidthRef)
77
78 -- | Set desired width of animation in pixel.
79 setWidth :: Width -> IO ()
80 setWidth = writeIORef pWidthRef
81
82 {-# NOINLINE pHeightRef #-}
83 pHeightRef :: IORef FPS
84 pHeightRef = unsafePerformIO (newIORef 0)
85
86 {-# NOINLINE pHeight #-}
87 -- | Height of animation in pixel.
88 pHeight :: Height
89 pHeight = unsafePerformIO (readIORef pHeightRef)
90
91 -- | Set desired height of animation in pixel.
92 setHeight :: Height -> IO ()
93 setHeight = writeIORef pHeightRef
94
95 {-# NOINLINE pNoExternalsRef #-}
96 pNoExternalsRef :: IORef Bool
97 pNoExternalsRef = unsafePerformIO (newIORef False)
98
99 {-# NOINLINE pNoExternals #-}
100 -- | This parameter determined whether or not external tools are allowed.
101 -- If this flag is True then tools such as 'Reanimate.LaTeX.latex' and
102 -- 'Reanimate.Blender.blender' will not be invoked.
103 pNoExternals :: Bool
104 pNoExternals = unsafePerformIO (readIORef pNoExternalsRef)
105
106 -- | Set whether external tools are allowed.
107 setNoExternals :: Bool -> IO ()
108 setNoExternals = writeIORef pNoExternalsRef
109
110 {-# NOINLINE pRootDirectoryRef #-}
111 pRootDirectoryRef :: IORef FilePath
112 pRootDirectoryRef = unsafePerformIO (newIORef (error "root directory not set"))
113
114 {-# NOINLINE pRootDirectory #-}
115 -- | Root directory of animation. Images and other data has to be placed
116 -- here if they are referenced in an SVG image.
117 pRootDirectory :: FilePath
118 pRootDirectory = unsafePerformIO (readIORef pRootDirectoryRef)
119
120 -- | Set the root animation directory.
121 setRootDirectory :: FilePath -> IO ()
122 setRootDirectory = writeIORef pRootDirectoryRef