From 10c889af56841a32a5d0fdb8af06704ca846fbd5 Mon Sep 17 00:00:00 2001 From: nek0 Date: Mon, 26 Dec 2016 14:14:54 +0100 Subject: [PATCH] rename drawRect' to drawRect and clean Affection.Draw --- examples/example01.hs | 2 +- examples/example02.hs | 2 +- src/Affection/Draw.hs | 77 ++----------------------------------------- 3 files changed, 5 insertions(+), 76 deletions(-) diff --git a/examples/example01.hs b/examples/example01.hs index 89675e5..d13abd1 100644 --- a/examples/example01.hs +++ b/examples/example01.hs @@ -86,7 +86,7 @@ draw :: Affection UserData () draw = do traceM "drawing" UserData{..} <- getAffection - drawRect' (nodeGraph M.! "nop") (G.RGB 1 0 0) Fill (G.GeglRectangle 10 10 500 500) foreground + drawRect (nodeGraph M.! "nop") (G.RGB 1 0 0) Fill (G.GeglRectangle 10 10 500 500) foreground liftIO $ G.gegl_node_process $ nodeGraph M.! "sink" update :: Double -> AffectionState (AffectionData UserData) IO () diff --git a/examples/example02.hs b/examples/example02.hs index dcd0142..00f538a 100644 --- a/examples/example02.hs +++ b/examples/example02.hs @@ -90,7 +90,7 @@ draw = do let (w, h) = (fromIntegral rw, fromIntegral rh) liftIO $ clearArea foreground (GeglRectangle 0 0 w h) maybe (return ()) (\(x, y) -> - drawRect' + drawRect (nodeGraph M.! "nop") (G.RGBA 1 0 0 0.5) (Fill) diff --git a/src/Affection/Draw.hs b/src/Affection/Draw.hs index 8826e10..557c5ab 100644 --- a/src/Affection/Draw.hs +++ b/src/Affection/Draw.hs @@ -2,9 +2,7 @@ -- | Module for drawing primitives module Affection.Draw - ( - -- drawRect - drawRect' + ( drawRect -- , clear , handleDrawRequest , invalidateDrawRequest @@ -30,53 +28,14 @@ import qualified GEGL as G import Debug.Trace --- | Draw a rectangle on target buffer --- drawRect --- :: G.GeglBuffer -- ^ Target buffer --- -> G.GeglNode -- ^ Target node --- -> G.Color -- ^ Color to draw in --- -> DrawType -- ^ Draw type --- -> GeglRectangle -- ^ Dimensions of Rectangle --- -> Affection us () --- drawRect buf node color (Fill) rect@G.GeglRectangle{..} = do --- liftIO $ G.pixelPoke buf rect (B.PixelFormat B.RGBA B.CFdouble) G.GeglAccessReadWrite G.GeglAbyssNone $ --- (\(x, y) -> --- let col = unsafeColorize color --- in --- G.Pixel x y col --- ) --- ad@AffectionData{..} <- get --- put $ ad --- { drawStack = (DrawRequest rect buf False) : drawStack --- } --- drawRect buf node color (Line size) rect@G.GeglRectangle{..} = do --- liftIO $ G.pixelPoke buf rect (B.PixelFormat B.RGBA B.CFdouble) G.GeglAccessReadWrite G.GeglAbyssNone $ --- (\(x, y) -> --- let col = unsafeColorize color --- in if not ((x >= rectangleX + size && x < rectangleX + rectangleWidth - size) && --- (y >= rectangleY + size && y < rectangleY + rectangleHeight - size)) --- then --- G.Pixel x y col --- else --- G.Pixel x y $ unsafeColorize $ G.RGBA 0 0 0 0 --- ) --- ad@AffectionData{..} <- get --- put $ ad --- { drawStack = (DrawRequest rect buf False) : drawStack --- } --- -- drawRect buf node color Fill (G.GeglRectangle rectangleX rectangleY rectangleWidth size) --- -- drawRect buf node color Fill (G.GeglRectangle rectangleX rectangleY size rectangleHeight) --- -- drawRect buf node color Fill (G.GeglRectangle (rectangleX + rectangleWidth - size) rectangleY size rectangleHeight) --- -- drawRect buf node color Fill (G.GeglRectangle rectangleX (rectangleY + rectangleHeight - size) rectangleWidth size) - -drawRect' +drawRect :: G.GeglNode -- ^ Target Node -> G.Color -- ^ Color to draw in -> DrawType -- ^ Draw type -> G.GeglRectangle -- ^ Dimensions of Rectangle -> G.GeglBuffer -- ^ Final Buffer -> Affection us () -drawRect' node color Fill rect@GeglRectangle{..} buf = do +drawRect node color Fill rect@GeglRectangle{..} buf = do ad <- get tempRoot <- liftIO $ G.gegl_node_new opNode <- liftIO $ G.gegl_node_new_child tempRoot $ G.Operation "gegl:rectangle" @@ -105,30 +64,6 @@ present rect buf kill = do { drawStack = (DrawRequest rect buf k) : drawStack ad } --- -- | force a blit of a specified area. Do not use often as it slows down the program --- present --- :: G.GeglNode -- ^ Node to blit --- -> G.GeglBuffer -- ^ BUffer to draw --- -> G.GeglRectangle -- ^ Area to blit --- -> Bool -- ^ Shall the drawing be cleared in the next run? --- -> Affection us () --- present node buf rect pers = do --- ad <- get --- put $ ad --- { drawStack = (DrawRequest rect buf pers) : drawStack ad --- } --- ad <- get --- format <- liftIO $ B.babl_format $ B.PixelFormat B.RGBA B.CFu8 --- liftIO $ SDL.lockSurface $ drawSurface ad --- liftIO $ G.gegl_node_blit --- rect --- format --- nullPtr --- 0 --- [G.GeglBlitDefault] --- liftIO $ SDL.unlockSurface $ drawSurface ad --- liftIO $ SDL.updateWindowSurface $ drawWindow ad - -- | function for handling 'DrawRequest's and updating the output handleDrawRequest :: Ptr a -- ^ Pixel buffer to blit to @@ -233,12 +168,6 @@ unsafeColorize col = , G.CVdouble $ CDouble $ a ) --- -- | Clear all data from a buffer --- clear --- :: G.GeglBuffer -- ^ Target buffer --- -> IO () --- clear buf = clearArea buf =<< G.gegl_rectangle_infinite_plane - -- | Clear a specified area of a buffer from all data clearArea :: G.GeglBuffer -- ^ Target buffer