sdl2-ttf 2.0.2 → 2.1.0
raw patch · 4 files changed
+69/−3 lines, 4 files
Files
- cbits/helpers.c +30/−0
- sdl2-ttf.cabal +3/−2
- src/SDL/Font.hs +19/−0
- src/SDL/Raw/Font.hsc +17/−1
cbits/helpers.c view
@@ -117,3 +117,33 @@ return TTF_RenderGlyph_Blended(font, glyph, *fg); }++extern DECLSPEC SDL_Surface * SDLCALL+ TTF_RenderUTF8_Blended_Wrapped_p(+ TTF_Font *font,+ const char *text,+ SDL_Color *fg,+ uint32_t wrapLength) {++ return TTF_RenderUTF8_Blended_Wrapped(font, text, *fg, wrapLength);+}++extern DECLSPEC SDL_Surface * SDLCALL+ TTF_RenderUNICODE_Blended_Wrapped_p(+ TTF_Font *font,+ uint16_t *text,+ SDL_Color *fg,+ uint32_t wrapLength) {++ return TTF_RenderUNICODE_Blended_Wrapped(font, text, *fg, wrapLength);+}++extern DECLSPEC SDL_Surface * SDLCALL+ TTF_RenderText_Blended_Wrapped_p(+ TTF_Font *font,+ const char *text,+ SDL_Color *fg,+ uint32_t wrapLength) {++ return TTF_RenderText_Blended_Wrapped(font, text, *fg, wrapLength);+}
sdl2-ttf.cabal view
@@ -1,5 +1,5 @@ name: sdl2-ttf-version: 2.0.2+version: 2.1.0 synopsis: Bindings to SDL2_ttf. description: Haskell bindings to SDL2_ttf C++ library <http://www.libsdl.org/projects/SDL_ttf/>. bug-reports: https://github.com/haskell-game/sdl2-ttf/issues@@ -14,6 +14,7 @@ category: Font, Foreign binding, Graphics build-type: Simple cabal-version: >=1.10+tested-with: GHC==7.10.3, GHC==8.0.2, GHC==8.2.2, GHC==8.4.2 source-repository head type: git@@ -34,7 +35,7 @@ pkgconfig-depends: sdl2 >= 2.0.3,- SDL2_ttf >= 2.0.0+ SDL2_ttf >= 2.0.12 c-sources: cbits/helpers.c
src/SDL/Font.hs view
@@ -9,6 +9,7 @@ <http://www.libsdl.org/projects/SDL_ttf/docs/SDL_ttf.html> which itself is a wrapper around the FreeType library. The bindings should allow you to load fonts and+render 'Text' in various styles to an @SDL@ 'Surface'. You can safely assume that any monadic function listed here is capable of throwing an 'SDLException' in case it encounters an error.@@ -71,6 +72,7 @@ , ascent , descent , lineSkip+ , getKerningSize -- * Glyphs --@@ -81,6 +83,7 @@ , solidGlyph , shadedGlyph , blendedGlyph+ , blendedWrapped ) where import Control.Exception (throwIO)@@ -501,3 +504,19 @@ liftIO . with (SDL.Raw.Color r g b a) $ \fg -> SDL.Raw.Font.renderGlyph_Blended font (fromChar ch) fg++-- | Same as 'blended', but renders across multiple lines. +-- Text is wrapped to multiple lines on line endings and on word boundaries+-- if it extends beyond wrapLength in pixels.+blendedWrapped :: MonadIO m => Font -> Color -> Int -> Text -> m SDL.Surface+blendedWrapped (Font font) (V4 r g b a) wrapLength text =+ fmap unmanaged .+ throwIfNull "SDL.Font.blended" "TTF_RenderUNICODE_Blended_Wrapped" .+ liftIO . withText text $ \ptr ->+ with (SDL.Raw.Color r g b a) $ \fg ->+ SDL.Raw.Font.renderUNICODE_Blended_Wrapped font (castPtr ptr) fg $ fromIntegral wrapLength++-- | From a given 'Font' get the kerning size of two glyphs.+getKerningSize :: MonadIO m => Font -> Index -> Index -> m Int+getKerningSize (Font font) prevIndex index =+ fmap fromIntegral $ SDL.Raw.Font.getFontKerningSize font (fromIntegral prevIndex) (fromIntegral index)
src/SDL/Raw/Font.hsc view
@@ -63,6 +63,7 @@ , fontFaceStyleName , glyphIsProvided , glyphMetrics+ , getFontKerningSize -- * Getting text size , sizeText@@ -73,12 +74,15 @@ , renderText_Solid , renderText_Shaded , renderText_Blended+ , renderText_Blended_Wrapped , renderUTF8_Solid , renderUTF8_Shaded , renderUTF8_Blended+ , renderUTF8_Blended_Wrapped , renderUNICODE_Solid , renderUNICODE_Shaded , renderUNICODE_Blended+ , renderUNICODE_Blended_Wrapped , renderGlyph_Solid , renderGlyph_Shaded , renderGlyph_Blended@@ -92,7 +96,7 @@ #include "SDL_ttf.h" import Foreign.C.String (CString)-import Foreign.C.Types (CInt(..), CLong(..), CUShort(..))+import Foreign.C.Types (CInt(..), CLong(..), CUShort(..), CUInt(..)) import Foreign.Ptr (Ptr) import Prelude hiding (init) import SDL.Raw.Types (Version, Surface, RWops, Color)@@ -255,3 +259,15 @@ liftF "renderGlyph_Blended" "TTF_RenderGlyph_Blended_p" [t|Ptr Font -> CUShort -> Ptr Color -> IO (Ptr Surface)|]++liftF "renderText_Blended_Wrapped" "TTF_RenderText_Blended_Wrapped_p"+ [t|Ptr Font -> CString -> Ptr Color -> CUInt -> IO (Ptr Surface)|]++liftF "renderUTF8_Blended_Wrapped" "TTF_RenderUTF8_Blended_Wrapped_p"+ [t|Ptr Font -> CString -> Ptr Color -> CUInt -> IO (Ptr Surface)|]++liftF "renderUNICODE_Blended_Wrapped" "TTF_RenderUNICODE_Blended_Wrapped_p"+ [t|Ptr Font -> Ptr CUShort -> Ptr Color -> CUInt -> IO (Ptr Surface)|]++liftF "getFontKerningSize" "TTF_GetFontKerningSize"+ [t|Ptr Font -> CInt -> CInt -> IO CInt|]