only drawing on available surface area

This commit is contained in:
nek0 2017-02-24 17:11:10 +01:00
parent ea8fdf37ee
commit 130d941779

View file

@ -12,6 +12,8 @@ module Affection.Draw
import Affection.Types import Affection.Types
import Data.Maybe (maybe)
import Foreign import Foreign
import Foreign.C.Types import Foreign.C.Types
@ -75,18 +77,23 @@ handleDrawRequest
handleDrawRequest pixels stride cpp dr@DrawRequest{..} = do handleDrawRequest pixels stride cpp dr@DrawRequest{..} = do
ad <- get ad <- get
let surf = drawSurface ad let surf = drawSurface 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 $ SDL.lockSurface surf
liftIO $ G.gegl_buffer_get liftIO $ G.gegl_buffer_get
requestBuffer requestBuffer
(Just requestArea) (Just realRect)
1 1
(Just $ drawFormat ad) (Just $ drawFormat ad)
(pixels `plusPtr` (pixels `plusPtr`
(rectangleX requestArea * cpp + rectangleY requestArea * stride)) (rectangleX realRect * cpp + rectangleY realRect * stride))
stride stride
G.GeglAbyssNone G.GeglAbyssNone
liftIO $ SDL.unlockSurface surf liftIO $ SDL.unlockSurface surf
-- liftIO $ SDL.updateWindowSurface $ drawWindow ad -- liftIO $ SDL.updateWindowSurface $ drawWindow ad
) mrealRect
case requestPersist of case requestPersist of
Yes -> Yes ->
return Nothing return Nothing
@ -103,19 +110,24 @@ invalidateDrawRequest
-> Affection us () -> Affection us ()
invalidateDrawRequest pixels stride cpp dr@DrawRequest{..} = do invalidateDrawRequest pixels stride cpp dr@DrawRequest{..} = do
ad <- get ad <- get
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 let surf = drawSurface ad
liftIO $ clearArea requestBuffer requestArea liftIO $ clearArea requestBuffer realRect
liftIO $ SDL.lockSurface surf liftIO $ SDL.lockSurface surf
liftIO $ G.gegl_buffer_get liftIO $ G.gegl_buffer_get
requestBuffer requestBuffer
(Just requestArea) (Just realRect)
1 1
(Just $ drawFormat ad) (Just $ drawFormat ad)
(pixels `plusPtr` (pixels `plusPtr`
(rectangleX requestArea * cpp + rectangleY requestArea * stride)) (rectangleX realRect * cpp + rectangleY realRect * stride))
stride stride
G.GeglAbyssNone G.GeglAbyssNone
liftIO $ SDL.unlockSurface surf liftIO $ SDL.unlockSurface surf
) mrealRect
case requestPersist of case requestPersist of
Kill (Just victim) -> Kill (Just victim) ->
liftIO $ G.gegl_node_drop victim liftIO $ G.gegl_node_drop victim