typograffiti-0.1.0.0: Display TTF fonts in OpenGL. Includes caching for fast rendering.

Copyright(c) 2018 Schell Scivally
LicenseMIT
MaintainerSchell Scivally <schell@takt.com>
Safe HaskellNone
LanguageHaskell2010

Typograffiti.Cache

Description

This module provides a method of caching rendererd text, making it suitable for interactive rendering. You can use the defaultCache or provide your own.

Synopsis

Documentation

class Layout t where Source #

Generic operations for text layout.

Minimal complete definition

translate

Methods

translate :: t -> V2 Float -> t Source #

Instances
Layout [TextTransform] Source # 
Instance details

Defined in Typograffiti.Cache

data AllocatedRendering t Source #

Holds an allocated draw function for some amount of text. The function takes one parameter that can be used to transform the text in various ways. This type is generic and can be used to take advantage of your own font rendering shaders.

Constructors

AllocatedRendering 

Fields

  • arDraw :: t -> IO ()

    Draw the text with some transformation in some monad.

  • arRelease :: IO ()

    Release the allocated draw function in some monad.

  • arSize :: V2 Int

    The size (in pixels) of the drawn text.

newtype WordCache t Source #

Constructors

WordCache 
Instances
Semigroup (WordCache t) Source # 
Instance details

Defined in Typograffiti.Cache

Methods

(<>) :: WordCache t -> WordCache t -> WordCache t #

sconcat :: NonEmpty (WordCache t) -> WordCache t #

stimes :: Integral b => b -> WordCache t -> WordCache t #

Monoid (WordCache t) Source # 
Instance details

Defined in Typograffiti.Cache

loadWords Source #

Arguments

:: (MonadIO m, MonadError TypograffitiError m) 
=> (Atlas -> String -> m (AllocatedRendering t))

Operation used to allocate a word.

-> Atlas

The character atlas that holds our letters, which is used to generate the word geometry.

-> WordCache t

The atlas to load the words into.

-> String

The string of words to load, with each word separated by spaces.

-> m (WordCache t) 

Load a string of words into the WordCache.

unloadMissingWords Source #

Arguments

:: MonadIO m 
=> WordCache t

The WordCache to unload words from.

-> String

The source string.

-> m (WordCache t) 

Unload any words from the cache that are not contained in the source string.

loadText Source #

Arguments

:: (MonadIO m, MonadError TypograffitiError m, Layout t) 
=> (Atlas -> String -> m (AllocatedRendering t))

Operation used to allocate a word.

-> Atlas

The character atlas that holds our letters.

-> WordCache t

The WordCache to load AllocatedRenderings into.

-> String

The string to render. This string may contain newlines, which will be respected.

-> m (t -> IO (), V2 Int, WordCache t)

Returns a function for rendering the text, the size of the text and the new WordCache with the allocated renderings of the text.

Constructs a Renderer2 from the given color and string. The WordMap record of the given Atlas is used to construct the string geometry, greatly improving performance and allowing longer strings to be compiled and renderered in real time. To create a new Atlas see allocAtlas.

Note that since word geometries are stored in the Atlas WordMap and multiple renderers can reference the same Atlas, the returned Renderer2 contains a clean up operation that does nothing. It is expected that the programmer will call freeAtlas manually when the Atlas is no longer needed.

makeDefaultAllocateWord Source #

Arguments

:: (MonadIO m, MonadError TypograffitiError m, Integral i) 
=> IO (V2 i)

A monadic operation that returns the current context's dimentions. This is used to set the orthographic projection for rendering text.

-> m (Atlas -> String -> IO (Either TypograffitiError (AllocatedRendering [TextTransform])))