module Graphics.XOSD.Base (
XOSD
, create
, create_
, destroy
, withXOSD
, setFont
, setColor
, Format(..)
, XOSD_Command
, display
, xosd_percentage, xosd_string, xosd_slider
, xosd_create
, xosd_uninit
, xosd_set_timeout
, xosd_set_vertical_offset
, xosd_set_horizontal_offset
, xosd_set_pos
, xosd_set_font
, xosd_set_colour
, xosd_is_onscreen
, xosd_error
, xosd_get_colour
, xosd_get_number_lines
, xosd_wait_until_no_display
, xosd_hide
, xosd_show
, xosd_scroll
, xosd_display_string
) where
import Foreign
import Foreign.C.Types
import Foreign.C.String
import Control.Exception
data XOSD_
type XOSD = Ptr XOSD_
create :: Int -> IO (Either String XOSD)
create n = do p <- xosd_create (fromIntegral n)
if p == nullPtr
then do err <- peekCString =<< xosd_error
return (Left err)
else return (Right p)
create_ :: Int -> IO XOSD
create_ n = do
r_xosd <- create n
case r_xosd of
Left err -> error err
Right xosd -> return xosd
destroy :: XOSD -> IO ()
destroy xosd = xosd_uninit xosd >> return ()
withXOSD :: Int -> (XOSD -> IO ()) -> IO ()
withXOSD n a = do
bracket
(create_ n)
(destroy)
a
display :: XOSD -> Int -> Format -> IO ()
display xosd n fmt = case fmt of
Percent n -> undefined
Slider n -> undefined
String s -> withCString s $ \cstr -> do
v <- xosd_display_string xosd (fromIntegral n) xosd_string cstr
return ()
setFont :: XOSD -> String -> IO ()
setFont xosd s = do
withCString s $ \cstr -> do
n <- xosd_set_font xosd cstr
return ()
setColor :: XOSD -> String -> IO ()
setColor xosd s = do
withCString s $ \cstr -> do
n <- xosd_set_colour xosd cstr
return ()
data Format = Percent !Int
| Slider !Int
| String String
deriving (Eq,Show)
type XOSD_Command = CInt
xosd_percentage :: XOSD_Command
xosd_percentage = 0
xosd_string :: XOSD_Command
xosd_string = 1
xosd_slider :: XOSD_Command
xosd_slider = 3
foreign import ccall unsafe
xosd_create :: CInt -> IO XOSD
foreign import ccall unsafe
xosd_uninit :: XOSD -> IO CInt
foreign import ccall unsafe
xosd_set_timeout :: XOSD -> CInt -> IO CInt
foreign import ccall unsafe
xosd_set_vertical_offset :: XOSD -> CInt -> IO CInt
foreign import ccall unsafe
xosd_set_horizontal_offset :: XOSD -> CInt -> IO CInt
foreign import ccall unsafe
xosd_set_pos :: XOSD -> CInt -> IO CInt
foreign import ccall unsafe
xosd_set_font :: XOSD -> CString -> IO CInt
foreign import ccall unsafe
xosd_set_colour :: XOSD -> CString -> IO CInt
foreign import ccall unsafe
xosd_is_onscreen :: XOSD -> IO CInt
foreign import ccall unsafe
xosd_error :: IO CString
foreign import ccall unsafe
xosd_get_colour :: XOSD -> Ptr CInt -> Ptr CInt -> Ptr CInt -> IO CInt
foreign import ccall unsafe
xosd_get_number_lines :: XOSD -> IO CInt
foreign import ccall unsafe
xosd_wait_until_no_display :: XOSD -> IO CInt
foreign import ccall unsafe
xosd_hide :: XOSD -> IO CInt
foreign import ccall unsafe
xosd_show :: XOSD -> IO CInt
foreign import ccall unsafe
xosd_scroll :: XOSD -> CInt -> IO CInt
foreign import ccall unsafe "xosd_display"
xosd_display_string :: XOSD -> CInt -> XOSD_Command -> CString -> IO CInt