module Graphics.UI.GLUT.Callbacks.Global (
MenuUsage(..), MenuStatusCallback, menuStatusCallback,
IdleCallback, idleCallback,
Timeout, TimerCallback, addTimerCallback
) where
import Control.Monad.Fix ( mfix )
import Data.StateVar ( SettableStateVar, makeSettableStateVar )
import Foreign.C.Types ( CInt )
import Graphics.Rendering.OpenGL ( Position(..) )
import Graphics.UI.GLUT.Callbacks.Registration
import Graphics.UI.GLUT.Raw
data
= NotInUse
| InUse
deriving ( MenuUsage -> MenuUsage -> Bool
(MenuUsage -> MenuUsage -> Bool)
-> (MenuUsage -> MenuUsage -> Bool) -> Eq MenuUsage
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: MenuUsage -> MenuUsage -> Bool
$c/= :: MenuUsage -> MenuUsage -> Bool
== :: MenuUsage -> MenuUsage -> Bool
$c== :: MenuUsage -> MenuUsage -> Bool
Eq, Eq MenuUsage
Eq MenuUsage
-> (MenuUsage -> MenuUsage -> Ordering)
-> (MenuUsage -> MenuUsage -> Bool)
-> (MenuUsage -> MenuUsage -> Bool)
-> (MenuUsage -> MenuUsage -> Bool)
-> (MenuUsage -> MenuUsage -> Bool)
-> (MenuUsage -> MenuUsage -> MenuUsage)
-> (MenuUsage -> MenuUsage -> MenuUsage)
-> Ord MenuUsage
MenuUsage -> MenuUsage -> Bool
MenuUsage -> MenuUsage -> Ordering
MenuUsage -> MenuUsage -> MenuUsage
forall a.
Eq a
-> (a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
min :: MenuUsage -> MenuUsage -> MenuUsage
$cmin :: MenuUsage -> MenuUsage -> MenuUsage
max :: MenuUsage -> MenuUsage -> MenuUsage
$cmax :: MenuUsage -> MenuUsage -> MenuUsage
>= :: MenuUsage -> MenuUsage -> Bool
$c>= :: MenuUsage -> MenuUsage -> Bool
> :: MenuUsage -> MenuUsage -> Bool
$c> :: MenuUsage -> MenuUsage -> Bool
<= :: MenuUsage -> MenuUsage -> Bool
$c<= :: MenuUsage -> MenuUsage -> Bool
< :: MenuUsage -> MenuUsage -> Bool
$c< :: MenuUsage -> MenuUsage -> Bool
compare :: MenuUsage -> MenuUsage -> Ordering
$ccompare :: MenuUsage -> MenuUsage -> Ordering
$cp1Ord :: Eq MenuUsage
Ord, Int -> MenuUsage -> ShowS
[MenuUsage] -> ShowS
MenuUsage -> String
(Int -> MenuUsage -> ShowS)
-> (MenuUsage -> String)
-> ([MenuUsage] -> ShowS)
-> Show MenuUsage
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [MenuUsage] -> ShowS
$cshowList :: [MenuUsage] -> ShowS
show :: MenuUsage -> String
$cshow :: MenuUsage -> String
showsPrec :: Int -> MenuUsage -> ShowS
$cshowsPrec :: Int -> MenuUsage -> ShowS
Show )
unmarshalMenuUsage :: CInt -> MenuUsage
CInt
x
| CInt
x CInt -> CInt -> Bool
forall a. Eq a => a -> a -> Bool
== CInt
glut_MENU_NOT_IN_USE = MenuUsage
NotInUse
| CInt
x CInt -> CInt -> Bool
forall a. Eq a => a -> a -> Bool
== CInt
glut_MENU_IN_USE = MenuUsage
InUse
| Bool
otherwise = String -> MenuUsage
forall a. HasCallStack => String -> a
error (String
"unmarshalMenuUsage: illegal value " String -> ShowS
forall a. [a] -> [a] -> [a]
++ CInt -> String
forall a. Show a => a -> String
show CInt
x)
type = MenuUsage -> Position -> IO ()
menuStatusCallback :: SettableStateVar (Maybe MenuStatusCallback)
=
(Maybe MenuStatusCallback -> IO ())
-> SettableStateVar (Maybe MenuStatusCallback)
forall a. (a -> IO ()) -> SettableStateVar a
makeSettableStateVar ((Maybe MenuStatusCallback -> IO ())
-> SettableStateVar (Maybe MenuStatusCallback))
-> (Maybe MenuStatusCallback -> IO ())
-> SettableStateVar (Maybe MenuStatusCallback)
forall a b. (a -> b) -> a -> b
$
CallbackType
-> (FunPtr MenuStatusFunc -> IO ())
-> (MenuStatusCallback -> IO (FunPtr MenuStatusFunc))
-> Maybe MenuStatusCallback
-> IO ()
forall a b.
CallbackType
-> (FunPtr a -> IO ()) -> (b -> IO (FunPtr a)) -> Maybe b -> IO ()
setCallback CallbackType
MenuStatusCB FunPtr MenuStatusFunc -> IO ()
forall (m :: * -> *). MonadIO m => FunPtr MenuStatusFunc -> m ()
glutMenuStatusFunc
(MenuStatusFunc -> IO (FunPtr MenuStatusFunc)
makeMenuStatusFunc (MenuStatusFunc -> IO (FunPtr MenuStatusFunc))
-> (MenuStatusCallback -> MenuStatusFunc)
-> MenuStatusCallback
-> IO (FunPtr MenuStatusFunc)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. MenuStatusCallback -> MenuStatusFunc
forall a a t.
(Integral a, Integral a) =>
(MenuUsage -> Position -> t) -> CInt -> a -> a -> t
unmarshal)
where unmarshal :: (MenuUsage -> Position -> t) -> CInt -> a -> a -> t
unmarshal MenuUsage -> Position -> t
cb CInt
s a
x a
y =
MenuUsage -> Position -> t
cb (CInt -> MenuUsage
unmarshalMenuUsage CInt
s)
(GLint -> GLint -> Position
Position (a -> GLint
forall a b. (Integral a, Num b) => a -> b
fromIntegral a
x) (a -> GLint
forall a b. (Integral a, Num b) => a -> b
fromIntegral a
y))
type IdleCallback = IO ()
idleCallback :: SettableStateVar (Maybe IdleCallback)
idleCallback :: SettableStateVar (Maybe (IO ()))
idleCallback =
(Maybe (IO ()) -> IO ()) -> SettableStateVar (Maybe (IO ()))
forall a. (a -> IO ()) -> SettableStateVar a
makeSettableStateVar ((Maybe (IO ()) -> IO ()) -> SettableStateVar (Maybe (IO ())))
-> (Maybe (IO ()) -> IO ()) -> SettableStateVar (Maybe (IO ()))
forall a b. (a -> b) -> a -> b
$ CallbackType
-> (FunPtr (IO ()) -> IO ())
-> (IO () -> IO (FunPtr (IO ())))
-> Maybe (IO ())
-> IO ()
forall a b.
CallbackType
-> (FunPtr a -> IO ()) -> (b -> IO (FunPtr a)) -> Maybe b -> IO ()
setCallback CallbackType
IdleCB FunPtr (IO ()) -> IO ()
forall (m :: * -> *). MonadIO m => FunPtr (IO ()) -> m ()
glutIdleFunc IO () -> IO (FunPtr (IO ()))
makeIdleFunc
type Timeout = Int
type TimerCallback = IO ()
addTimerCallback :: Timeout -> TimerCallback -> IO ()
addTimerCallback :: Int -> IO () -> IO ()
addTimerCallback Int
msecs IO ()
timerCallback = do
FunPtr TimerFunc
funPtr <- (FunPtr TimerFunc -> IO (FunPtr TimerFunc))
-> IO (FunPtr TimerFunc)
forall (m :: * -> *) a. MonadFix m => (a -> m a) -> m a
mfix (\FunPtr TimerFunc
self -> TimerFunc -> IO (FunPtr TimerFunc)
makeTimerFunc (\CInt
_ -> do FunPtr TimerFunc -> IO ()
forall a. FunPtr a -> IO ()
registerForCleanup FunPtr TimerFunc
self
IO ()
timerCallback))
CUInt -> FunPtr TimerFunc -> TimerFunc
forall (m :: * -> *).
MonadIO m =>
CUInt -> FunPtr TimerFunc -> CInt -> m ()
glutTimerFunc (Int -> CUInt
forall a b. (Integral a, Num b) => a -> b
fromIntegral Int
msecs) FunPtr TimerFunc
funPtr CInt
0