Safe Haskell | None |
---|---|
Language | Haskell2010 |
This module provides the means for declarative image generation using sdl2 primitives as a basis. Atomical operations for image composition are rotation, translation, mirroring, color modulation, changing blend modes and primitive drawing.
This packages aims to provide a basic interface via type classes. This means that you could write your own implementation but still use eventual utility functions provided by this package. The authors decided to split the functionality into several typeclasses to allow partial implementations while preserving type safety.
- class Compositor c where
- class Blender b where
- class Manipulator m where
- modulateAlphaM :: Int -> m -> m
- modulateRedM :: Int -> m -> m
- modulateGreenM :: Int -> m -> m
- modulateBlueM :: Int -> m -> m
- class Drawer d where
- class AbsoluteSize c where
- class Texture tex where
- textureAlphaMod :: tex -> StateVar Word8
- textureColorMod :: tex -> StateVar (V3 Word8)
- textureBlendMode :: tex -> StateVar BlendMode
- textureWidth :: tex -> IO Int
- textureHeight :: tex -> IO Int
- textureDims :: tex -> IO (V2 Int)
- destroyTexture :: tex -> IO ()
- class Renderer rend where
- class Renderable rend tex where
- withZIndex :: (Compositor c, Monoid c) => [(Int, c)] -> c
- data CompositingNode a
- runRenderer :: forall tex rend. (Texture tex, Renderer rend, Renderable rend tex) => rend -> CompositingNode tex -> IO ()
- data Color
- rgba :: Word8 -> Word8 -> Word8 -> Word8 -> Color
Interface
class Compositor c where Source
A Compositor is a thing that can overlap, rotate and mirror objects.
overC :: c -> c -> c infixr 5 Source
overC x y
positions x over y. The meaning of this depends on
the context. For Textures and drawings this means that x should
be drawn after y was drawn.
rotateC :: Double -> c -> c Source
flipC :: V2 Bool -> c -> c Source
This function takes a 'V2 Bool' that represents mirroring action. The first component of the vector represents mirroring along the y-axis (horizontally) and the second component represents mirroring along the x-axis (vertically).
Compositor (CompositingNode a) Source | |
Compositor (c a) => Compositor (ResIndependent c a) Source |
This class modells a graphics object that supports switching of
BlendMode
.
Blender (CompositingNode a) Source | |
Blender (c a) => Blender (ResIndependent c a) Source |
class Manipulator m where Source
This class models a graphics object that supports color modulation.
modulateAlphaM :: Int -> m -> m Source
Modulate the alpha channel of picture. This behavior stacks multiplicatively.
modulateRedM :: Int -> m -> m Source
Modulate the red channel of picture. This behavior stacks multiplicatively.
modulateGreenM :: Int -> m -> m Source
Modulate the green channel of picture. This behavior stacks multiplicatively.
modulateBlueM :: Int -> m -> m Source
Modulate the blue channel of picture. This behavior stacks multiplicatively.
Manipulator (CompositingNode a) Source | |
Manipulator (c a) => Manipulator (ResIndependent c a) Source |
class AbsoluteSize c where Source
class Texture tex where Source
textureAlphaMod :: tex -> StateVar Word8 Source
textureColorMod :: tex -> StateVar (V3 Word8) Source
textureBlendMode :: tex -> StateVar BlendMode Source
textureWidth :: tex -> IO Int Source
textureHeight :: tex -> IO Int Source
textureDims :: tex -> IO (V2 Int) Source
destroyTexture :: tex -> IO () Source
class Renderable rend tex where Source
This class modells that something can be rendered to another thing.
:: rend | rendering context |
-> tex | texture |
-> Maybe (Rectangle Int) | source rectangle |
-> Maybe (Rectangle Int) | destination rectangle |
-> Double | rotation |
-> Maybe (Point V2 Int) | rotation center |
-> V2 Bool | flipping |
-> IO () |
createTexture :: rend -> PixelFormat -> TextureAccess -> V2 Int -> IO tex Source
rendererRenderTarget :: rend -> StateVar (Maybe tex) Source
Utility
withZIndex :: (Compositor c, Monoid c) => [(Int, c)] -> c Source
Arrange all given compositions in one composition.
This function takes a list of pairs where the first element of the pair is the z-index and the second element is the composition. Elements of with a higher z-index will be rendered "in front of" elements with lower indices. If elements have the same index then the element that comes first in the list will be drawn over all the later ones.
This method can only arrange compositions that are in the "the same list of arguments". That means that
withZIndex [(1,a),(2,b)] `overC` withZIndex [(3,c)]
will always result in b
being rendered "in front of" a
and c
,
no matter how large the z-index of c
is.
Implementation
data CompositingNode a Source
A compositing node represents a compound graphical resource.
AbsoluteSize CompositingNode Source | |
Eq a => Eq (CompositingNode a) Source | |
Show a => Show (CompositingNode a) Source | |
Monoid (CompositingNode a) Source |
mappend a b == overC a b |
Manipulator (CompositingNode a) Source | |
Drawer (CompositingNode a) Source | |
Blender (CompositingNode a) Source | |
Compositor (CompositingNode a) Source |
runRenderer :: forall tex rend. (Texture tex, Renderer rend, Renderable rend tex) => rend -> CompositingNode tex -> IO () Source
Render a composed image.