summaryrefslogtreecommitdiffstats
path: root/lib/Phi/Border.hs
diff options
context:
space:
mode:
Diffstat (limited to 'lib/Phi/Border.hs')
-rw-r--r--lib/Phi/Border.hs14
1 files changed, 10 insertions, 4 deletions
diff --git a/lib/Phi/Border.hs b/lib/Phi/Border.hs
index c6e7531..0c6c9c4 100644
--- a/lib/Phi/Border.hs
+++ b/lib/Phi/Border.hs
@@ -16,6 +16,9 @@ import Phi.Types
import Phi.Widget
import Control.Monad
+import Control.Monad.State.Strict
+
+import Data.Maybe
import Graphics.Rendering.Cairo
@@ -61,6 +64,7 @@ data BorderCache w s c = (Widget w s c) => BorderCache !c
instance Eq s => Widget (Border w s c) s (BorderCache w s c) where
initWidget (Border _ w) = initWidget w
+ initCache (Border _ w) = BorderCache $ initCache w
minSize (Border config w) s height screen =
case True of
@@ -90,17 +94,19 @@ instance Eq s => Widget (Border w s c) s (BorderCache w s c) where
render (Border config w) s x y width height screen = case () of
_ | (width > borderH m - 2*bw - borderH p) -> do
- border <- createImageSurface FormatARGB32 width height
+ border <- liftIO $ createImageSurface FormatARGB32 width height
renderWith border $ do
setOperator OperatorClear
paint
setOperator OperatorOver
drawBorder config 0 0 width height
- surfaces <- render w s (x+dx) (y+dy) width' height' screen
+ BorderCache c <- get
+ (surfaces, c') <- liftIO $ flip runStateT c $ render w s (x+dx) (y+dy) width' height' screen
+ put $ BorderCache c'
let surfaces' = (True, 0, Nothing):(map (\(updated, SurfaceSlice x surf) -> (updated, x+dx, Just surf)) surfaces)++[(True, width-rightWidth, Nothing)]
surfacesWidths = zipWith (\(updated, x, surf) (_, x', _) -> (updated, x, x'-x, surf)) surfaces' (tail surfaces' ++ [(False, width, Nothing)])
forM surfacesWidths $ \(updated, x, surfWidth, surf) -> do
- surf' <- createImageSurface FormatARGB32 surfWidth height
+ surf' <- liftIO $ createImageSurface FormatARGB32 surfWidth height
renderWith surf' $ do
setOperator OperatorClear
paint
@@ -121,7 +127,7 @@ instance Eq s => Widget (Border w s c) s (BorderCache w s c) where
return (updated, SurfaceSlice x surf')
| otherwise -> do
- surface <- createImageSurface FormatARGB32 width height
+ surface <- liftIO $ createImageSurface FormatARGB32 width height
return [(True, SurfaceSlice 0 surface)]
where
m = margin config