{-# OPTIONS_HADDOCK hide #-}
{- | 
This FunGEn module controls timing (how time-based functions will behave).
-}
{- 

FunGEN - Functional Game Engine
http://www.cin.ufpe.br/~haskell/fungen
Copyright (C) 2002  Andre Furtado <awbf@cin.ufpe.br>

This code is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

-}

module Graphics.UI.Fungen.Timer (
        RefreshType(..),
        setRefresh
) where

import Graphics.UI.GLUT
import Graphics.UI.GLUT.Input

-- | Used by 'Graphics.UI.Fungen.funInit' to configure the main loop's timing strategy.
data RefreshType
        = Idle
        | Timer Int

-- | Change the current timing strategy.
setRefresh :: RefreshType -> StillDownHandler -> IO ()
setRefresh :: RefreshType -> IdleCallback -> IdleCallback
setRefresh RefreshType
Idle IdleCallback
stillDown = SettableStateVar (Maybe IdleCallback)
idleCallback forall t a (m :: * -> *).
(HasSetter t a, MonadIO m) =>
t -> a -> m ()
$= forall a. a -> Maybe a
Just (IdleCallback
stillDown forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> forall (m :: * -> *). MonadIO m => Maybe Window -> m ()
postRedisplay forall a. Maybe a
Nothing)
setRefresh (Timer Int
t) IdleCallback
stillDown = Int -> IdleCallback -> IdleCallback
addTimerCallback Int
t (IdleCallback -> Int -> IdleCallback
timer IdleCallback
stillDown Int
t)

-- | Generate a GLUT timer callback.
timer :: StillDownHandler -> Int -> TimerCallback
timer :: IdleCallback -> Int -> IdleCallback
timer IdleCallback
stillDown Int
t = do
        IdleCallback
stillDown
        forall (m :: * -> *). MonadIO m => Maybe Window -> m ()
postRedisplay forall a. Maybe a
Nothing
        Int -> IdleCallback -> IdleCallback
addTimerCallback Int
t (IdleCallback -> Int -> IdleCallback
timer IdleCallback
stillDown Int
t)