 {-#LANGUAGE ForeignFunctionInterface, TypeFamilies, MultiParamTypeClasses, TypeSynonymInstances#-}
 #include "cvWrapLEO.h"
+-- | Module for exposing opencv drawing functions. These are meant for quick and dirty marking
+--   and not for anything presentable. For any real drawing
+--   you should figure out how to use cairo or related package, such as diagrams. They are
+--   way better.
+--
+--   Consult the "CV.ImageOp" module for functions to apply the operations in this module to images.
 
-module CV.Drawing(ShapeStyle(Filled,Stroked),circle
-              ,Drawable(..)
-              ,floodfill,drawLinesOp,drawLines,rectangle
-              ,rectOpS,fillPoly) where
+module CV.Drawing(
+                -- * Drawable class
+                 ShapeStyle(Filled,Stroked)
+                ,Drawable(..)
+                -- * Extra drawing operations
+                ,drawLinesOp
+                ,rectOpS
+                -- * Floodfill operations
+                ,fillOp
+                ,floodfill
+                -- * Shorthand for drawing single shapes
+                ,circle
+                ,drawLines
+                ,rectangle
+                ,fillPoly) where
 
 import Foreign.Ptr
 import Foreign.C.Types

                                  free ys'


rectOpS c t pos@(x,y) (w,h) = rectOp c t pos (x+w,y+h)

fillOp :: (Int,Int) -> D32 -> D32 -> D32 -> Bool -> ImageOperation GrayScale D32
fillOp (x,y) color low high floats = 
    ImgOp $ \i -> do

     toCINT False = 0
     toCINT True  = 1

-- | Apply rectOp to an image
rectangle :: Drawable c d => Color c d -> Int -> (Int, Int) -> (Int, Int) -> Image c d
             -> IO (Image c d)
rectangle color thickness a b i = 
    operate (rectOp color thickness a b ) i

-- | Apply fillPolyOp to an image
fillPoly :: Drawable c d => Color c d -> [(Int, Int)] -> Image c d -> IO (Image c d)
fillPoly c pts i = operate (fillPolyOp c pts) i

-- | Draw a polyline
drawLinesOp :: Drawable c d => Color c d -> Int -> [((Int, Int), (Int, Int))] -> CV.ImageOp.ImageOperation c d
drawLinesOp color thickness segments = 
    foldl (#>) nonOp 
     $ map (\(a,b) -> lineOp color thickness a b) segments

-- | Apply drawLinesOp to an image
drawLines :: Drawable c d => Image c d -> Color c d -> Int -> [((Int, Int), (Int, Int))]
                                -> IO (Image c d)
drawLines img color thickness segments = operateOn img
                    (drawLinesOp color thickness segments)

-- | Apply circleOp to an image
circle :: Drawable c d => (Int, Int) -> Int -> Color c d -> ShapeStyle -> Image c d -> Image c d
circle center r color s i = unsafeOperate (circleOp color center r s) i

-- | Apply fillOp to an image
floodfill :: (Int, Int) -> D32 -> D32 -> D32 -> Bool -> Image GrayScale D32 -> Image GrayScale D32
floodfill (x,y) color low high floats = 
    unsafeOperate (fillOp (x,y) color low high floats) 

