module Graphics.UI.SDL.TTF.Management
( tryOpenFont
, openFont
, closeFont
, tryOpenFontRW
, openFontRW
, tryOpenFontIndex
, openFontIndex
) where
import Graphics.UI.SDL.TTF.Types
import Graphics.UI.SDL.General (unwrapMaybe)
import Graphics.UI.SDL.Types
import Foreign
import Foreign.C
foreign import ccall unsafe "&TTF_CloseFont" ttfCloseFontFinal :: FunPtr (Ptr FontStruct -> IO ())
mkFinalizedFont :: Ptr FontStruct -> IO Font
mkFinalizedFont :: Ptr FontStruct -> IO Font
mkFinalizedFont = FinalizerPtr FontStruct -> Ptr FontStruct -> IO Font
forall a. FinalizerPtr a -> Ptr a -> IO (ForeignPtr a)
newForeignPtr FinalizerPtr FontStruct
ttfCloseFontFinal
foreign import ccall unsafe "TTF_CloseFont" ttfCloseFont :: Ptr FontStruct -> IO ()
closeFont :: Font -> IO ()
closeFont :: Font -> IO ()
closeFont font :: Font
font = Font -> (Ptr FontStruct -> IO ()) -> IO ()
forall a b. ForeignPtr a -> (Ptr a -> IO b) -> IO b
withForeignPtr Font
font Ptr FontStruct -> IO ()
ttfCloseFont
foreign import ccall unsafe "TTF_OpenFont" ttfOpenFont :: CString -> CInt -> IO (Ptr FontStruct)
tryOpenFont :: String -> Int -> IO (Maybe Font)
tryOpenFont :: String -> Int -> IO (Maybe Font)
tryOpenFont path :: String
path ptsize :: Int
ptsize
= String -> (CString -> IO (Maybe Font)) -> IO (Maybe Font)
forall a. String -> (CString -> IO a) -> IO a
withCString String
path ((CString -> IO (Maybe Font)) -> IO (Maybe Font))
-> (CString -> IO (Maybe Font)) -> IO (Maybe Font)
forall a b. (a -> b) -> a -> b
$ \cPath :: CString
cPath ->
CString -> CInt -> IO (Ptr FontStruct)
ttfOpenFont CString
cPath (Int -> CInt
forall a b. (Integral a, Num b) => a -> b
fromIntegral Int
ptsize) IO (Ptr FontStruct)
-> (Ptr FontStruct -> IO (Maybe Font)) -> IO (Maybe Font)
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= (Ptr FontStruct -> IO Font) -> Ptr FontStruct -> IO (Maybe Font)
forall a b. (Ptr a -> IO b) -> Ptr a -> IO (Maybe b)
maybePeek Ptr FontStruct -> IO Font
mkFinalizedFont
openFont :: String -> Int -> IO Font
openFont :: String -> Int -> IO Font
openFont path :: String
path ptsize :: Int
ptsize = String -> IO (Maybe Font) -> IO Font
forall a. String -> IO (Maybe a) -> IO a
unwrapMaybe "TTF_OpenFont" (String -> Int -> IO (Maybe Font)
tryOpenFont String
path Int
ptsize)
foreign import ccall unsafe "TTF_OpenFontRW" ttfOpenFontRW :: Ptr RWopsStruct -> CInt -> Int -> IO (Ptr FontStruct)
tryOpenFontRW :: RWops -> Bool -> Int -> IO (Maybe Font)
tryOpenFontRW :: RWops -> Bool -> Int -> IO (Maybe Font)
tryOpenFontRW rw :: RWops
rw freesrc :: Bool
freesrc ptsize :: Int
ptsize
= RWops -> (Ptr RWopsStruct -> IO (Maybe Font)) -> IO (Maybe Font)
forall a b. ForeignPtr a -> (Ptr a -> IO b) -> IO b
withForeignPtr RWops
rw ((Ptr RWopsStruct -> IO (Maybe Font)) -> IO (Maybe Font))
-> (Ptr RWopsStruct -> IO (Maybe Font)) -> IO (Maybe Font)
forall a b. (a -> b) -> a -> b
$ \rwPtr :: Ptr RWopsStruct
rwPtr ->
Ptr RWopsStruct -> CInt -> Int -> IO (Ptr FontStruct)
ttfOpenFontRW Ptr RWopsStruct
rwPtr (Bool -> CInt
forall a. Num a => Bool -> a
fromBool Bool
freesrc) Int
ptsize IO (Ptr FontStruct)
-> (Ptr FontStruct -> IO (Maybe Font)) -> IO (Maybe Font)
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= (Ptr FontStruct -> IO Font) -> Ptr FontStruct -> IO (Maybe Font)
forall a b. (Ptr a -> IO b) -> Ptr a -> IO (Maybe b)
maybePeek Ptr FontStruct -> IO Font
mkFinalizedFont
openFontRW :: RWops -> Bool -> Int -> IO Font
openFontRW :: RWops -> Bool -> Int -> IO Font
openFontRW rw :: RWops
rw freesrc :: Bool
freesrc ptsize :: Int
ptsize
= String -> IO (Maybe Font) -> IO Font
forall a. String -> IO (Maybe a) -> IO a
unwrapMaybe "TTF_OpenFontRW" (RWops -> Bool -> Int -> IO (Maybe Font)
tryOpenFontRW RWops
rw Bool
freesrc Int
ptsize)
foreign import ccall unsafe "TTF_OpenFontIndex" ttfOpenFontIndex :: CString -> CInt -> Int -> IO (Ptr FontStruct)
tryOpenFontIndex :: String -> Int -> Int -> IO (Maybe Font)
tryOpenFontIndex :: String -> Int -> Int -> IO (Maybe Font)
tryOpenFontIndex file :: String
file ptsize :: Int
ptsize index :: Int
index
= String -> (CString -> IO (Maybe Font)) -> IO (Maybe Font)
forall a. String -> (CString -> IO a) -> IO a
withCString String
file ((CString -> IO (Maybe Font)) -> IO (Maybe Font))
-> (CString -> IO (Maybe Font)) -> IO (Maybe Font)
forall a b. (a -> b) -> a -> b
$ \cFile :: CString
cFile ->
CString -> CInt -> Int -> IO (Ptr FontStruct)
ttfOpenFontIndex CString
cFile (Int -> CInt
forall a b. (Integral a, Num b) => a -> b
fromIntegral Int
ptsize) (Int -> Int
forall a b. (Integral a, Num b) => a -> b
fromIntegral Int
index) IO (Ptr FontStruct)
-> (Ptr FontStruct -> IO (Maybe Font)) -> IO (Maybe Font)
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= (Ptr FontStruct -> IO Font) -> Ptr FontStruct -> IO (Maybe Font)
forall a b. (Ptr a -> IO b) -> Ptr a -> IO (Maybe b)
maybePeek Ptr FontStruct -> IO Font
mkFinalizedFont
openFontIndex :: String -> Int -> Int -> IO Font
openFontIndex :: String -> Int -> Int -> IO Font
openFontIndex file :: String
file ptsize :: Int
ptsize index :: Int
index = String -> IO (Maybe Font) -> IO Font
forall a. String -> IO (Maybe a) -> IO a
unwrapMaybe "TTF_OpenFontIndex" (String -> Int -> Int -> IO (Maybe Font)
tryOpenFontIndex String
file Int
ptsize Int
index)