summaryrefslogtreecommitdiffstats
path: root/lib/Phi/Widgets/AlphaBox.hs
blob: c09b911e84a2468c9e329e334900a7dcc5b0b5c6 (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
46
47
48
49
{-# LANGUAGE TypeFamilies #-}

module Phi.Widgets.AlphaBox ( alphaBox
                            ) where

import Phi.Types
import Phi.Widget

import Control.Monad

import Graphics.Rendering.Cairo


data AlphaBoxState = AlphaBoxState [WidgetState] deriving Show

data AlphaBox = AlphaBox Double [Widget] deriving Show


instance WidgetClass AlphaBox where
  type WidgetData AlphaBox = AlphaBoxState
  initWidget (AlphaBox _ widgets) phi disp = liftM AlphaBoxState $ mapM (createWidgetState phi disp) widgets
  
  minSize (AlphaBox _ _) (AlphaBoxState widgetStates) height screen =
    sum (map (\(WidgetState {stateWidget = w, statePrivateData = priv}) -> minSize w priv height screen) widgetStates)
  
  weight (AlphaBox _ widgets) = sum (map (\(Widget w) -> weight w) widgets)
  
  layout (AlphaBox _ _) (AlphaBoxState widgetStates) width height screen = AlphaBoxState $ layoutWidgets widgetStates 0 0 width height screen

  render (AlphaBox alpha _) (AlphaBoxState widgetStates) w h screen = do
    renderWithSimilarSurface ContentColorAlpha w h $ \surface -> do
      renderWith surface $ do
        renderWidgets widgetStates screen
        
        setOperator OperatorDestIn
        setSourceRGBA 0 0 0 alpha
        paint
      
      withPatternForSurface surface setSource
      paint
        
        
    
  handleMessage _ (AlphaBoxState widgetStates) m = AlphaBoxState $ handleMessageWidgets m widgetStates


alphaBox :: Double -> [Widget] -> Widget
alphaBox alpha = Widget . AlphaBox alpha