wumpus-basic-0.10.0: Common drawing utilities built on wumpus-core.

PortabilityGHC
Stabilityhighly unstable
Maintainerstephen.tetley@gmail.com

Wumpus.Basic.Graphic.Base

Contents

Description

Base types for Drawing Objects, Graphics / Images (a Graphic that also returns an answer), etc.

Base classes for monadic drawing.

Note on suffix names. Function types suffixed F are functions from same-to-same, e.g.:

 type Point2F u = Point2 u -> Point2 u

Functional types subfixed R are functions from some static context to the answer type (c.f the ReaderMonad), e.g.:

 newtype DrawingR a = DrawingR { getDrawingR :: DrawingContext -> a }

The suffix M is used for classes defining monadic actions.

** WARNING ** - some names are expected to change.

Synopsis

Drawing monads.

type family MonUnit m :: *Source

DUnit is always for fully saturated type constructors, so (seemingly) an equivalent type family is needed for monads.

class Monad m => TraceM m whereSource

Collect elementary graphics as part of a larger drawing.

TraceM works much like a writer monad.

Methods

trace :: HPrim (MonUnit m) -> m ()Source

Instances

(Monad m, TraceM m) => TraceM (DirectionT m) 
TraceM (Drawing u) 
Monad m => TraceM (DrawingT u m) 
(u ~ MonUnit m, Monad m, TraceM m) => TraceM (TurtleT u m) 
(u ~ MonUnit m, Monad m, TraceM m) => TraceM (ScalingT ux uy u m) 

asksDC :: DrawingCtxM m => (DrawingContext -> a) -> m aSource

Project a value out of a context.

class Monad m => PointSupplyM m whereSource

A monad that supplies points, e.g. a turtle monad.

Methods

position :: u ~ MonUnit m => m (Point2 u)Source

Instances

(u ~ MonUnit m, Monad m, Num u) => PointSupplyM (TurtleT u m) 

Base types

data HPrim u Source

Graphics objects, even simple ones (line, arrow, dot) might need more than one primitive (path or text label) for their construction. Hence, the primary representation that all the others are built upon must support concatenation of primitives.

Wumpus-Core has a type Picture - made from one or more Primitives - but Pictures include support for affine frames. For drawing many simple graphics (dots, connector lines...) that do not need individual affine transformations this is a penalty. A list of Primitives is therefore more suitable representation, and a Hughes list which supports efficient concatenation is wise.

Instances

type Point2F u = Point2 u -> Point2 uSource

Point transformation function.

data DrawingR a Source

Drawings in Wumpus-Basic have an implicit graphics state the DrawingContext, the most primitive building block is a function from the DrawingContext to some polymorphic answer.

This functional type is represented concretely as DrawingR.

 DrawingR :: DrawingContext -> a 

runDrawingR :: DrawingContext -> DrawingR a -> aSource

Run a Drawing Function with the supplied Drawing Context.

type LocGraphic u = Point2 u -> Graphic uSource

Commonly graphics take a start point as well as a drawing context.

Here they are called a LocGraphic - graphic with a (starting) location.

type Image u a = DrawingR (a, HPrim u)Source

Images return a value as well as drawing. A node is a typical example - nodes are drawing but the also support taking anchor points.

type LocImage u a = Point2 u -> Image u aSource

type ConnDrawingR u a = Point2 u -> Point2 u -> DrawingR aSource

type ConnGraphic u = Point2 u -> Point2 u -> Graphic uSource

ConnGraphic is a connector drawn between two points contructing a Graphic.

type ConnImage u a = Point2 u -> Point2 u -> Image u aSource

ConImage is a connector drawn between two points constructing an Image.