module Graphics.XOSD (
XOSD,
Attribute(..),
Format(..), VAlign(..), HAlign(..),
runXOSD,
initialize,
destroy,
set,
display,
wait,
scroll,
) where
import Control.Exception
import Graphics.XOSD.Base
data Attribute
= Lines !Int
| BarLength !Int
| VAlign !VAlign
| HAlign !HAlign
| VOffset !Int
| HOffset !Int
| ShadowOffset !Int
| OutlineOffset !Int
| OutlineColor String
| ShadowColor String
| Color String
| Font String
| Timeout !Int
| Hidden
| Visible
| Scroll !Int
| Display !Format
deriving (Show,Eq)
initialize :: [Attribute] -> IO XOSD
initialize attrs = do
xosd <- create size
set xosd attrs
return xosd
where
size = case reverse [ n | Lines n <- attrs ] of
[] -> 1
n:_ -> n
set :: XOSD -> [Attribute] -> IO ()
set xosd attrs = mapM_ setAttr attrs
where
setAttr :: Attribute -> IO ()
setAttr (Lines _) = return ()
setAttr (BarLength n) = setBarLength xosd n
setAttr (VAlign v) = setVAlign xosd v
setAttr (HAlign v) = setHAlign xosd v
setAttr (ShadowOffset o) = setShadowOffset xosd o
setAttr (OutlineOffset o) = setOutlineOffset xosd o
setAttr (OutlineColor c) = setOutlineColor xosd c
setAttr (ShadowColor c) = setShadowColor xosd c
setAttr (VOffset c) = setVerticalOffset xosd c
setAttr (HOffset c) = setHorizontalOffset xosd c
setAttr (Timeout i) = setTimeout xosd i
setAttr (Color c) = setColor xosd c
setAttr (Font f) = setFont xosd f
setAttr Hidden = setHidden xosd
setAttr Visible = setVisible xosd
setAttr (Scroll n) = scroll xosd n
setAttr (Display d) = display xosd 0 d
runXOSD :: [Attribute] -> (XOSD -> IO ()) -> IO ()
runXOSD n a = do
bracket
(initialize n)
(\x -> wait x >> destroy x)
a