module Graphics.GPipe.Context.GLFW.Wrappers where
import Control.Monad.IO.Class (MonadIO)
import qualified Graphics.UI.GLFW as GLFW
import qualified Graphics.GPipe.Context as GPipe (ContextT, Window())
import qualified Graphics.GPipe.Context.GLFW.Handler as Handler
import qualified Graphics.GPipe.Context.GLFW.Calls as Call
import qualified Graphics.GPipe.Context.GLFW.RPC as RPC
withWindow :: MonadIO m => (GLFW.Window -> IO a) -> GPipe.Window os c ds -> GPipe.ContextT Handler.Handle os m (Maybe a)
withWindow fun wid = Handler.withContextFromGPipe "withWindowNoRPC" wid go
where
go = fun . Handler.contextRaw
withWindowRPC :: MonadIO m => (Call.OnMain a -> GLFW.Window -> IO a) -> GPipe.Window os c ds -> GPipe.ContextT Handler.Handle os m (Maybe a)
withWindowRPC fun wid = Handler.withBothFromGPipe "withWindowRPC" wid go
where
go handle = fun (RPC.fetchResult . Handler.handleComm $ handle) . Handler.contextRaw
wrapWindowFun :: MonadIO m => (Call.OnMain b -> GLFW.Window -> a -> IO b) -> GPipe.Window os c ds -> a -> GPipe.ContextT Handler.Handle os m (Maybe b)
wrapWindowFun fun wid x = flip withWindowRPC wid $ \onMain window -> fun onMain window x
wrapCallbackSetter :: (MonadIO m, Functor g) => (Call.OnMain a -> GLFW.Window -> g (GLFW.Window -> b) -> IO a) -> GPipe.Window os c ds -> g b -> GPipe.ContextT Handler.Handle os m (Maybe a)
wrapCallbackSetter setter wid cb = flip withWindowRPC wid $ \onMain window -> setter onMain window (const <$> cb)