~alcinnz/Mondrian

ref: 6236cf8ab70f087f4348706e4d677874ec5002cb Mondrian/lib/Graphics/Rendering/Rect/Backgrounds.hs -rw-r--r-- 788 bytes
6236cf8a — Adrian Cochrane Add support for background-clip & prepare for multilayered backgrounds! 1 year, 4 months ago
                                                                                
eba0f9a2 Adrian Cochrane
6236cf8a Adrian Cochrane
eba0f9a2 Adrian Cochrane
7a7ce8ff Adrian Cochrane
6236cf8a Adrian Cochrane
eba0f9a2 Adrian Cochrane
10e61b66 Adrian Cochrane
eba0f9a2 Adrian Cochrane
049383f6 Adrian Cochrane
eba0f9a2 Adrian Cochrane
7a7ce8ff Adrian Cochrane
6236cf8a Adrian Cochrane
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
module Graphics.Rendering.Rect.Backgrounds(Backgrounds(..), renderBackgrounds) where

import Graphics.Rendering.Rect.CSS.Backgrounds
import Graphics.Rendering.Rect.Types
import qualified Data.ByteString.Char8 as B8
import Linear (M44)
import Control.Monad.IO.Class (MonadIO(..))
import Data.Maybe (fromMaybe, listToMaybe)

baseFragmentShader = B8.pack $ unlines [
    "#version 330 core",
    "out vec4 fcolour;",
    "uniform vec4 colour;",
    "void main() { fcolour = colour; }"
  ]

renderBackgrounds :: (MonadIO m, MonadIO n) =>
    n (Backgrounds -> Rects -> M44 Float -> m ())
renderBackgrounds = do
    base <- renderRectWith baseFragmentShader ["colour"]
    return $ \self -> base [c $ background self] $ headDef borderBox $ clip self

headDef def = fromMaybe def . listToMaybe