module Wumpus.Basic.Graphic
(
Graphic
, DGraphic
, GraphicF
, DGraphicF
, cc
, drawGraphic
, wrapG
, text
, straightLine
, strokedRectangle
, filledRectangle
, circle
) where
import Wumpus.Core
import Wumpus.Basic.Utils.HList
import Data.AffineSpace
type Graphic u = H (Primitive u)
type DGraphic = Graphic Double
type GraphicF u = Point2 u -> Graphic u
type DGraphicF = GraphicF Double
infixr 9 `cc`
cc :: (r1 -> a -> ans) -> (r1 -> r2 -> a) -> r1 -> r2 -> ans
cc f g = \x y -> f x (g x y)
drawGraphic :: (Real u, Floating u) => Graphic u -> Maybe (Picture u)
drawGraphic f = post $ f []
where
post [] = Nothing
post xs = Just $ frameMulti $ xs
wrapG :: Primitive u -> Graphic u
wrapG = wrapH
text :: (TextLabel t, Num u) => t -> String -> GraphicF u
text t ss = wrapG . textlabel t ss
straightLine :: (Stroke t, Num u) => t -> Vec2 u -> GraphicF u
straightLine t v = \pt -> wrapG $ ostroke t $ path pt [lineTo $ pt .+^ v]
strokedRectangle :: (Stroke t, Num u) => t -> u -> u -> GraphicF u
strokedRectangle t w h = wrapG . cstroke t . rectangle w h
filledRectangle :: (Fill t, Num u) => t -> u -> u -> GraphicF u
filledRectangle t w h = wrapG . fill t . rectangle w h
rectangle :: Num u => u -> u -> Point2 u -> Path u
rectangle w h bl = path bl [ lineTo br, lineTo tr, lineTo tl ]
where
br = bl .+^ hvec w
tr = br .+^ vvec h
tl = bl .+^ vvec h
circle :: (Ellipse t, Fractional u) => t -> u -> GraphicF u
circle t radius = wrapG . ellipse t radius radius