sdl2-cairo-image-1.0.0.2: An image loading and rendering library for sdl2 / sdl2-cairo

CopyrightCopyright (c) 2015 Yun-Yan Chi
LicenseMIT
Maintainerjaiyalas@gmail.com
Safe HaskellNone
LanguageHaskell2010

SDL.Cairo.Image.Render

Contents

Description

This module provides functions for directly/indirectly rendering a JuicyPixel's Image onto a sdl2's Texture.

This module is actually implemented with both of Render and Canvas, therefore it provides functions in both way. In fact, There are three simple ways to use this module. Assume we alread have following code,

import SDL
import Linear.V2 (V2(..))
import SDL.Cairo
import SDL.Cairo.Canvas
import SDL.Cairo.Image.Renderer
import Codec.Picture

main :: IO ()
main = do
  initialize [InitEverything]
  window <- createWindow "SDL2 Cairo Canvas" defaultWindow
  renderer <- createRenderer window (-1) defaultRenderer
  texture <- createCairoTexture' renderer window
  withCanvas texture $ do
    background $ gray 102
    -- location A

  Right (ImageRGB8 img) <- readPng "pic.png"
  -- location B

  copy renderer texture Nothing Nothing
  present renderer
  delay 5000
using renderImgCanvas

The first way to draw image is replacing

-- location A

by

renderImgCanvas (V2 50 50) img
using drawImg or drawImgC

The other ways are replacing

-- location B

by

drawImg texture (V2 50 50) img

or

drawImgC texture (V2 50 50) img

Synopsis

draw Image in IO ()

drawImg Source

Arguments

:: RenderablePixel a 
=> Texture

a Texture

-> V2 Int

a V2 coordinate of the top left corner

-> Image a

an Image

-> IO () 

draw a JuicyPixel Image on the given SDL Texture (at the specified coordinate).

drawImgC Source

Arguments

:: RenderablePixelC a 
=> Texture

a Texture

-> V2 Int

a V2 coordinate of the top left corner

-> Image a

an Image

-> IO () 

draw a JuicyPixel Image on the given SDL Texture (at the specified coordinate). Using Cairo's Render underneath.

draw Image in Canvas ()

renderImgCanvas Source

Arguments

:: RenderablePixel a 
=> V2 Int

a V2 coordinate of the top left corner

-> Image a

an Image

-> Canvas ()

a Canvas action

render an JuicyPixel Image through Cairo Canvas

draw Image in Render ()

renderImgCairo Source

Arguments

:: RenderablePixelC a 
=> V2 Int

a V2 coordinate of the top left corner

-> Image a

a JuicyPixel Image

-> Render ()

an Cairo Render action

render an Image through Cairo Render

renderOnTexture Source

Arguments

:: Texture

target Texture

-> Render ()

a Render action

-> IO () 

perform a Render action on the given Texture

Type class

class Pixel px => RenderablePixel px where Source

A pixel structure is RenderablePixel if how to draw on Canvas is defined.

Methods

drawPx Source

Arguments

:: (V2 Int, px)

(coordinate, pixel)

-> Canvas () 

class Pixel px => RenderablePixelC px where Source

A pixel structure is RenderablePixelC if how to render on Render can be provided.

Methods

renderPx Source

Arguments

:: (V2 Int, px)

(coordinate, pixel)

-> Render ()