    -----------------------------------------------------------------------------
    -- |
    -- Module      :  Graphics.UI.SDL.Framerate
    -- Copyright   :  (c) David Himmelstrup 2005
    -- License     :  BSD-like
    --
    -- Maintainer  :  lemmih@gmail.com
    -- Stability   :  provisional
    -- Portability :  portable
    --
    -----------------------------------------------------------------------------
    module Graphics.UI.SDL.Framerate
        ( new
        , init
        , set
        , get
        , delay
        , FPSManager
        ) where

    import Foreign as Foreign hiding (new)
    import Foreign.C

    import Prelude hiding (init)

    data FPSManagerStruct
    type FPSManager = ForeignPtr FPSManagerStruct

    sizeOfManager :: Int
    sizeOfManager :: Int
    sizeOfManager = 16

    new :: IO FPSManager
    new :: IO FPSManager
    new  = do FPSManager
    manager <- Int -> IO (Ptr FPSManagerStruct)
    forall a. Int -> IO (Ptr a)
    Foreign.mallocBytes Int
    sizeOfManager IO (Ptr FPSManagerStruct)
    -> (Ptr FPSManagerStruct -> IO FPSManager) -> IO FPSManager
    forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
    >>= FinalizerPtr FPSManagerStruct
    -> Ptr FPSManagerStruct -> IO FPSManager
    forall a. FinalizerPtr a -> Ptr a -> IO (ForeignPtr a)
    newForeignPtr FinalizerPtr FPSManagerStruct
    forall a. FinalizerPtr a
    finalizerFree
              FPSManager -> IO ()
    init FPSManager
    manager
              FPSManager -> IO FPSManager
    forall (m :: * -> *) a. Monad m => a -> m a
    return FPSManager
    manager

    -- void SDL_initFramerate(FPSmanager * manager);
    foreign import ccall unsafe "SDL_initFramerate" sdlInitFramerate :: Ptr FPSManagerStruct -> IO ()
    init :: FPSManager -> IO ()
    init :: FPSManager -> IO ()
    init manager :: FPSManager
    manager
        = FPSManager -> (Ptr FPSManagerStruct -> IO ()) -> IO ()
    forall a b. ForeignPtr a -> (Ptr a -> IO b) -> IO b
    withForeignPtr FPSManager
    manager Ptr FPSManagerStruct -> IO ()
    sdlInitFramerate

    -- int SDL_setFramerate(FPSmanager * manager, int rate);
    foreign import ccall unsafe "SDL_setFramerate" sdlSetFramerate :: Ptr FPSManagerStruct -> Int -> IO Int
    set :: FPSManager -> Int -> IO Bool
    set :: FPSManager -> Int -> IO Bool
    set manager :: FPSManager
    manager hz :: Int
    hz
        = FPSManager -> (Ptr FPSManagerStruct -> IO Bool) -> IO Bool
    forall a b. ForeignPtr a -> (Ptr a -> IO b) -> IO b
    withForeignPtr FPSManager
    manager ((Ptr FPSManagerStruct -> IO Bool) -> IO Bool)
    -> (Ptr FPSManagerStruct -> IO Bool) -> IO Bool
    forall a b. (a -> b) -> a -> b
    $ \fpsPtr :: Ptr FPSManagerStruct
    fpsPtr ->
          do Int
    ret <- Ptr FPSManagerStruct -> Int -> IO Int
    sdlSetFramerate Ptr FPSManagerStruct
    fpsPtr Int
    hz
             case Int
    ret of
               (-1) -> Bool -> IO Bool
    forall (m :: * -> *) a. Monad m => a -> m a
    return Bool
    False
               _    -> Bool -> IO Bool
    forall (m :: * -> *) a. Monad m => a -> m a
    return Bool
    True

    -- int SDL_getFramerate(FPSmanager * manager);
    foreign import ccall unsafe "SDL_getFramerate" sdlGetFramerate :: Ptr FPSManagerStruct -> IO Int
    get :: FPSManager -> IO Int
    get :: FPSManager -> IO Int
    get manager :: FPSManager
    manager = FPSManager -> (Ptr FPSManagerStruct -> IO Int) -> IO Int
    forall a b. ForeignPtr a -> (Ptr a -> IO b) -> IO b
    withForeignPtr FPSManager
    manager Ptr FPSManagerStruct -> IO Int
    sdlGetFramerate

    -- void SDL_framerateDelay(FPSmanager * manager);
    foreign import ccall unsafe "SDL_framerateDelay" sdlFramerateDelay :: Ptr FPSManagerStruct -> IO ()
    delay :: FPSManager -> IO ()
    delay :: FPSManager -> IO ()
    delay manager :: FPSManager
    manager = FPSManager -> (Ptr FPSManagerStruct -> IO ()) -> IO ()
    forall a b. ForeignPtr a -> (Ptr a -> IO b) -> IO b
    withForeignPtr FPSManager
    manager Ptr FPSManagerStruct -> IO ()
    sdlFramerateDelay