ibis/src/Util.hs

66 lines
1.2 KiB
Haskell

{-# LANGUAGE ForeignFunctionInterface #-}
module Util where
import qualified SDL
import Options.Applicative
import Control.Monad (when)
import System.IO
import Foreign.C.Types (CInt(..))
-- internal imports
import Types
foreign import ccall unsafe "glewInit"
glewInit :: IO CInt
glWindowConfig :: SDL.WindowConfig
glWindowConfig = SDL.defaultWindow
{ SDL.windowOpenGL = Just SDL.defaultOpenGL
{ SDL.glProfile = SDL.Core SDL.Normal 3 3
}
}
putErrLn :: String -> IO ()
putErrLn s = hPutStrLn stderr s
options :: Parser Options
options = Options
<$> switch
( long "fullscreen"
<> short 'f'
<> help "Toggle fullscreen"
<> showDefault
)
<*> switch
( long "flip"
<> short 'p'
<> help "Flip screens"
<> showDefault
)
<*> switch
( long "verbose"
<> short 'v'
<> help "Show verbose console output"
<> showDefault
)
<*> argument str
( help "Input file"
<> metavar "FILE"
)
makeWindowConfig :: SDL.Display -> SDL.WindowConfig
makeWindowConfig d =
glWindowConfig
{ SDL.windowPosition = SDL.Absolute (SDL.displayBoundsPosition d)
}
verb :: Options -> String -> IO ()
verb opts str = do
when (optVerbose opts) $
putStrLn str