From 130d9417791d17c621b68871b41a5203e88e8248 Mon Sep 17 00:00:00 2001 From: nek0 Date: Fri, 24 Feb 2017 17:11:10 +0100 Subject: [PATCH] only drawing on available surface area --- src/Affection/Draw.hs | 62 ++++++++++++++++++++++++++----------------- 1 file changed, 37 insertions(+), 25 deletions(-) diff --git a/src/Affection/Draw.hs b/src/Affection/Draw.hs index 620297a..c22aa8d 100644 --- a/src/Affection/Draw.hs +++ b/src/Affection/Draw.hs @@ -12,6 +12,8 @@ module Affection.Draw import Affection.Types +import Data.Maybe (maybe) + import Foreign import Foreign.C.Types @@ -75,18 +77,23 @@ handleDrawRequest handleDrawRequest pixels stride cpp dr@DrawRequest{..} = do ad <- get let surf = drawSurface ad - liftIO $ SDL.lockSurface surf - liftIO $ G.gegl_buffer_get - requestBuffer - (Just requestArea) - 1 - (Just $ drawFormat ad) - (pixels `plusPtr` - (rectangleX requestArea * cpp + rectangleY requestArea * stride)) - stride - G.GeglAbyssNone - liftIO $ SDL.unlockSurface surf - -- liftIO $ SDL.updateWindowSurface $ drawWindow ad + mrealRect <- liftIO $ G.gegl_rectangle_intersect + requestArea + (G.GeglRectangle 0 0 (fst $ drawDimensions ad) (snd $ drawDimensions ad)) + maybe (return()) (\realRect -> do + liftIO $ SDL.lockSurface surf + liftIO $ G.gegl_buffer_get + requestBuffer + (Just realRect) + 1 + (Just $ drawFormat ad) + (pixels `plusPtr` + (rectangleX realRect * cpp + rectangleY realRect * stride)) + stride + G.GeglAbyssNone + liftIO $ SDL.unlockSurface surf + -- liftIO $ SDL.updateWindowSurface $ drawWindow ad + ) mrealRect case requestPersist of Yes -> return Nothing @@ -103,19 +110,24 @@ invalidateDrawRequest -> Affection us () invalidateDrawRequest pixels stride cpp dr@DrawRequest{..} = do ad <- get - let surf = drawSurface ad - liftIO $ clearArea requestBuffer requestArea - liftIO $ SDL.lockSurface surf - liftIO $ G.gegl_buffer_get - requestBuffer - (Just requestArea) - 1 - (Just $ drawFormat ad) - (pixels `plusPtr` - (rectangleX requestArea * cpp + rectangleY requestArea * stride)) - stride - G.GeglAbyssNone - liftIO $ SDL.unlockSurface surf + mrealRect <- liftIO $ G.gegl_rectangle_intersect + requestArea + (G.GeglRectangle 0 0 (fst $ drawDimensions ad) (snd $ drawDimensions ad)) + maybe (return()) (\realRect -> do + let surf = drawSurface ad + liftIO $ clearArea requestBuffer realRect + liftIO $ SDL.lockSurface surf + liftIO $ G.gegl_buffer_get + requestBuffer + (Just realRect) + 1 + (Just $ drawFormat ad) + (pixels `plusPtr` + (rectangleX realRect * cpp + rectangleY realRect * stride)) + stride + G.GeglAbyssNone + liftIO $ SDL.unlockSurface surf + ) mrealRect case requestPersist of Kill (Just victim) -> liftIO $ G.gegl_node_drop victim