sdl2-compositor-1.2.0.7: image compositing with sdl2 - declarative style

Safe HaskellNone
LanguageHaskell2010

SDL.Compositor

Contents

Description

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.

Synopsis

Interface

class Compositor c where #

A Compositor is a thing that can overlap, rotate and mirror objects.

Minimal complete definition

overC, rotateC, flipC

Methods

overC :: c -> c -> c infixr 5 #

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 #

flipC :: V2 Bool -> c -> c #

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).

class Blender b where #

This class modells a graphics object that supports switching of BlendMode.

Minimal complete definition

blendMode

Methods

blendMode :: BlendMode -> b -> b #

This method sets the BlendMode of an object. If the object has children, their BlendMode property will be preserved.

class Manipulator m where #

This class models a graphics object that supports color modulation.

Methods

modulateAlphaM :: Int -> m -> m #

Modulate the alpha channel of picture. This behavior stacks multiplicatively.

modulateRedM :: Int -> m -> m #

Modulate the red channel of picture. This behavior stacks multiplicatively.

modulateGreenM :: Int -> m -> m #

Modulate the green channel of picture. This behavior stacks multiplicatively.

modulateBlueM :: Int -> m -> m #

Modulate the blue channel of picture. This behavior stacks multiplicatively.

class Drawer d where #

Minimal complete definition

rectangleC, lineC, filledRectangleC

Methods

rectangleC :: V2 Int -> Color -> d #

lineC :: V2 Int -> Color -> d #

filledRectangleC :: V2 Int -> Color -> d #

class AbsoluteSize c where #

Minimal complete definition

translateA, sizedA

Methods

translateA :: V2 Int -> c a -> c a #

sizedA :: V2 Int -> a -> c a #

class Renderer rend where #

Minimal complete definition

rendererDrawColor, clear, present, drawRect, fillRect, drawLine

Methods

rendererDrawColor :: rend -> StateVar (V4 Word8) #

clear :: rend -> IO () #

present :: rend -> IO () #

drawRect :: rend -> Maybe (Rectangle Int) -> IO () #

fillRect :: rend -> Maybe (Rectangle Int) -> IO () #

drawLine :: rend -> Point V2 Int -> Point V2 Int -> IO () #

class Renderable rend tex where #

This class modells that something can be rendered to another thing.

Minimal complete definition

copyEx, createTexture, rendererRenderTarget

Methods

copyEx :: rend -> tex -> Maybe (Rectangle Int) -> Maybe (Rectangle Int) -> Double -> Maybe (Point V2 Int) -> V2 Bool -> IO () #

createTexture :: rend -> PixelFormat -> TextureAccess -> V2 Int -> IO tex #

rendererRenderTarget :: rend -> StateVar (Maybe tex) #

Utility

withZIndex :: (Compositor c, Monoid c) => [(Int, c)] -> c #

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 #

A compositing node represents a compound graphical resource.

Instances

AbsoluteSize CompositingNode # 
Eq a => Eq (CompositingNode a) # 
Show a => Show (CompositingNode a) # 
Monoid (CompositingNode a) #

mempty represents no painting at all. Also

mappend a b == overC a b
Manipulator (CompositingNode a) # 
Drawer (CompositingNode a) # 
Blender (CompositingNode a) # 
Compositor (CompositingNode a) # 

runRenderer :: forall tex rend. (Texture tex, Renderer rend, Renderable rend tex) => rend -> CompositingNode tex -> IO () #

Render a composed image.

Colors

data Color #

Represents the value of color.

rgba :: Word8 -> Word8 -> Word8 -> Word8 -> Color #

construct a color value from red green blue and alpha values.