summaryrefslogtreecommitdiffstats
path: root/lib/Phi/Widgets/AlphaBox.hs
blob: eacda5ae1e8867a48e09681d4cf331fa378d8280 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
{-# LANGUAGE MultiParamTypeClasses, StandaloneDeriving, ExistentialQuantification, FlexibleInstances #-}

module Phi.Widgets.AlphaBox ( AlphaBox
                            , alphaBox
                            ) where

import Phi.Types
import Phi.Widget

import Control.Monad

import Graphics.Rendering.Cairo


data AlphaBox w d = (Widget w d) => AlphaBox !Double !w
deriving instance Show (AlphaBox w d)
deriving instance Eq (AlphaBox w d)

instance Eq d => Widget (AlphaBox w d) d where
  initWidget (AlphaBox _ w) = initWidget w
  
  minSize (AlphaBox _ w) = minSize w
  
  weight (AlphaBox _ w) = weight w
  
  layout (AlphaBox _ w) = layout w

  render (AlphaBox alpha w) d x y width height screen = do
    renderWithSimilarSurface ContentColorAlpha width height $ \surface -> do
      renderWith surface $ do
        render w d x y width height screen
        
        setOperator OperatorDestIn
        setSourceRGBA 0 0 0 alpha
        paint
      
      withPatternForSurface surface setSource
      paint
  
  handleMessage (AlphaBox _ w) = handleMessage w


alphaBox :: (Widget w d) => Double -> w -> AlphaBox w d
alphaBox = AlphaBox