sdl2-ttf 0.2.1 → 0.2.2
raw patch · 7 files changed
+130/−84 lines, 7 filesdep ~sdl2new-component:exe:font-testbinary-added
Dependency ranges changed: sdl2
Files
- examples/ARIAL.TTF binary
- examples/font_test.c +46/−0
- examples/font_test.hs +62/−0
- sdl2-ttf.cabal +19/−16
- src/Graphics/UI/SDL/TTF.hsc +1/−1
- src/Graphics/UI/SDL/TTF/FFI.hsc +2/−2
- test/font_test.hs +0/−65
+ examples/ARIAL.TTF view
binary file changed (absent → 273020 bytes)
+ examples/font_test.c view
@@ -0,0 +1,46 @@+#include "SDL2/SDL.h"+#include "SDL2/SDL_video.h"+#include "SDL2/SDL_ttf.h"++int handle_event()+{+ SDL_Event event;+ while (SDL_PollEvent(&event)) {+ if (event.type == SDL_QUIT) {+ return -1;+ }+ }+ return 0;+}++int main()+{+ SDL_Init(SDL_INIT_EVERYTHING);+ TTF_Init();++ SDL_Window *window = SDL_CreateWindow("test", 100, 100, 640, 480, SDL_WINDOW_SHOWN);+ SDL_Renderer *renderer = SDL_CreateRenderer(window, -1, SDL_RENDERER_ACCELERATED);++ TTF_Font *font = TTF_OpenFont("/usr/share/fonts/truetype/DroidSans.ttf", 13);+ if (font == NULL)+ printf("null font\n");++ SDL_Color color = {255, 255, 255};+ SDL_Surface *textSurface = TTF_RenderText_Solid(font, "some text", color);+ if (textSurface == NULL)+ printf("null text surface\n");++ SDL_Texture *textTexture = SDL_CreateTextureFromSurface(renderer, textSurface);+ if (textTexture == NULL)+ printf("null text texture\n");++ SDL_Rect rect = { 0, 0, 640, 480 };++ while (handle_event() == 0) {+ SDL_RenderClear(renderer);+ SDL_RenderCopy(renderer, textTexture, &rect, &rect);+ SDL_RenderPresent(renderer);+ }++ return 0;+}
+ examples/font_test.hs view
@@ -0,0 +1,62 @@+module Main where++import qualified Graphics.UI.SDL.TTF as TTF+import qualified SDL.Raw as SDL++import Foreign.C.String (withCAString)+import Foreign (peek,alloca,with,maybePeek,nullPtr)++arial :: String+arial = "./examples/ARIAL.TTF"++main :: IO ()+main = do+ _ <- SDL.init SDL.SDL_INIT_VIDEO+ window <- createWindow+ renderer <- createRenderer window++ TTF.withInit $ do+ font <- TTF.openFont arial 150 -- Pt size for retina screen. :<+ textSurface <- TTF.renderUTF8Solid font "some text" (SDL.Color 255 255 255 0)+ textTexture <- SDL.createTextureFromSurface renderer textSurface+ SDL.freeSurface textSurface+ loop window renderer textTexture++ TTF.closeFont font+ SDL.destroyRenderer renderer+ SDL.destroyWindow window+ SDL.quit++createRenderer :: SDL.Window -> IO (SDL.Renderer)+createRenderer w = SDL.createRenderer w (-1) 0++createWindow :: IO (SDL.Window)+createWindow = withCAString "test" $ \t ->+ SDL.createWindow t+ SDL.SDL_WINDOWPOS_UNDEFINED+ SDL.SDL_WINDOWPOS_UNDEFINED+ 640 480+ SDL.SDL_WINDOW_SHOWN++loop :: t -> SDL.Renderer -> SDL.Texture -> IO ()+loop window renderer textTexture = do+ let loc = SDL.Rect 320 240 150 100+ _ <- SDL.renderClear renderer+ _ <- with loc $ \loc' ->+ SDL.renderCopy renderer textTexture nullPtr loc'+ SDL.renderPresent renderer+ handleEvents window renderer textTexture++pollEvent :: IO (Maybe SDL.Event)+pollEvent = alloca $ \ptr -> do+ status <- SDL.pollEvent ptr+ if status == 1+ then maybePeek peek ptr+ else return Nothing++handleEvents :: t -> SDL.Renderer -> SDL.Texture -> IO ()+handleEvents window renderer textTexture = do+ mbEvent <- pollEvent+ case mbEvent of+ Just (SDL.QuitEvent _ _) -> return ()+ _ -> loop window renderer textTexture
sdl2-ttf.cabal view
@@ -1,6 +1,6 @@-Cabal-Version: >= 1.8+Cabal-Version: >= 1.10 Name: sdl2-ttf-Version: 0.2.1+Version: 0.2.2 Maintainer: Sean Chalmers (sclhiannan@gmail.com) Author: Ömer Sinan Ağacan (omeragacan@gmail.com) License-File: LICENSE@@ -11,26 +11,29 @@ Description: Haskell bindings to the sdl2-ttf C++ library <http://www.libsdl.org/projects/SDL_ttf/>. Data-files: extra-source-files: cbits/rendering.h+ examples/ARIAL.TTF+ examples/font_test.c Library- Hs-source-dirs: src- Build-Depends: base >= 3 && < 5, sdl2- Extensions: ForeignFunctionInterface- Exposed-Modules: Graphics.UI.SDL.TTF.Types,- Graphics.UI.SDL.TTF.FFI- Graphics.UI.SDL.TTF- GHC-Options: -Wall- include-dirs: cbits- C-sources: cbits/rendering.c- extra-libraries: SDL2, SDL2_ttf+ Hs-source-dirs: src+ Build-Depends: base >= 3 && < 5, sdl2+ default-extensions: ForeignFunctionInterface+ Exposed-Modules: Graphics.UI.SDL.TTF.Types,+ Graphics.UI.SDL.TTF.FFI+ Graphics.UI.SDL.TTF+ GHC-Options: -Wall+ include-dirs: cbits+ C-sources: cbits/rendering.c+ extra-libraries: SDL2, SDL2_ttf+ default-language: Haskell2010 -test-suite test- type: exitcode-stdio-1.0+executable font-test main-is: font_test.hs- hs-source-dirs: test+ hs-source-dirs: examples build-depends: base >= 3 && <5, sdl2, sdl2-ttf GHC-Options: -Wall- + default-language: Haskell2010+ source-repository head type: git location: https://github.com/mankyKitty/sdl2-ttf
src/Graphics/UI/SDL/TTF.hsc view
@@ -38,7 +38,7 @@ import qualified Graphics.UI.SDL.TTF.FFI as FFI import Graphics.UI.SDL.TTF.Types-import Graphics.UI.SDL.Types+import SDL.Raw.Types import Prelude hiding (init)
src/Graphics/UI/SDL/TTF/FFI.hsc view
@@ -4,8 +4,8 @@ import Foreign.C import Foreign.Ptr -import qualified Graphics.UI.SDL.Types as SDL-import Graphics.UI.SDL.Types (Color)+import qualified SDL.Raw.Types as SDL+import SDL.Raw.Types (Color) type TTFFont = Ptr ()
− test/font_test.hs
@@ -1,65 +0,0 @@-module Main where--import qualified Graphics.UI.SDL.TTF as TTF-import qualified Graphics.UI.SDL as SDL--import Foreign.C.String (withCAString)-import Foreign (peek,alloca,with,maybePeek,nullPtr)--arial :: String-arial = "./test/ARIAL.TTF"--main :: IO ()-main = do- _ <- SDL.init SDL.SDL_INIT_VIDEO- window <- createWindow- renderer <- createRenderer window- - TTF.withInit $ do- font <- TTF.openFont arial 150 -- Pt size for retina screen. :<- textSurface <- TTF.renderUTF8Solid font "some text" (SDL.Color 255 255 255 0)- textTexture <- SDL.createTextureFromSurface renderer textSurface- SDL.freeSurface textSurface- loop window renderer textTexture- - TTF.closeFont font- SDL.destroyRenderer renderer- SDL.destroyWindow window- SDL.quit--createRenderer :: SDL.Window -> IO (SDL.Renderer)-createRenderer w = SDL.createRenderer w (-1) 0--createWindow :: IO (SDL.Window)-createWindow = withCAString "test" $ \t ->- SDL.createWindow t - SDL.SDL_WINDOWPOS_UNDEFINED - SDL.SDL_WINDOWPOS_UNDEFINED - 640 480 - SDL.SDL_WINDOW_SHOWN--loop :: t -> SDL.Renderer -> SDL.Texture -> IO ()-loop window renderer textTexture = do- let loc = SDL.Rect 320 240 150 100- _ <- SDL.renderClear renderer- _ <- with loc $ \loc' ->- SDL.renderCopy renderer textTexture nullPtr loc'- SDL.renderPresent renderer-- handleEvents window renderer textTexture--pollEvent :: IO (Maybe SDL.Event)-pollEvent = alloca $ \ptr -> do- status <- SDL.pollEvent ptr- if status == 1- then maybePeek peek ptr- else return Nothing--handleEvents :: t -> SDL.Renderer -> SDL.Texture -> IO ()-handleEvents window renderer textTexture = do- mbEvent <- pollEvent- case mbEvent of- Just (SDL.QuitEvent _ _) -> return ()- _ -> loop window renderer textTexture--