├── .gitignore ├── LICENSE ├── README.md ├── SFML.cabal ├── Setup.hs ├── cbits └── SFML │ ├── Audio │ ├── Listener_helper.c │ ├── Music_helper.c │ ├── SoundBuffer_helper.c │ ├── SoundStream_helper.c │ └── Sound_helper.c │ ├── Graphics │ ├── CircleShape_helper.c │ ├── ConvexShape_helper.c │ ├── Font_helper.c │ ├── Image_helper.c │ ├── RectangleShape_helper.c │ ├── RenderTexture_helper.c │ ├── RenderWindow_helper.c │ ├── Shader_helper.c │ ├── Shape_helper.c │ ├── Sprite_helper.c │ ├── Text_helper.c │ ├── Texture_helper.c │ ├── VertexArray_helper.c │ └── View_helper.c │ ├── System │ ├── Clock_helper.c │ ├── Sleep_helper.c │ └── Time_helper.c │ └── Window │ ├── Joystick_helper.c │ ├── VideoMode_helper.c │ └── Window_helper.c ├── demos ├── LICENSE ├── assets │ ├── DST-BreakOut.ogg │ ├── DST-BreakOut.txt │ ├── Haskell-Logo.png │ ├── Vera.ttf │ └── ttf-bitstream-vera-1.10 │ │ ├── COPYRIGHT.TXT │ │ ├── README.TXT │ │ ├── RELEASENOTES.TXT │ │ ├── Vera.ttf │ │ └── local.conf ├── events │ └── main.hs ├── fingerpaint │ └── main.hs ├── hello │ └── main.hs ├── sfml-demos.cabal ├── time │ ├── main.hs │ └── test.c ├── transform │ └── main.hs ├── unicode │ └── main.hs └── window │ └── main.hs └── src └── SFML ├── Audio.hs ├── Audio ├── Listener.hs ├── Music.hs ├── SFSampled.hs ├── SFSound.hs ├── SFSoundBuffer.hs ├── SFSoundRecorder.hs ├── Sound.hs ├── SoundBuffer.hs ├── SoundBufferRecorder.hs ├── SoundRecorder.hs ├── SoundStatus.hs ├── SoundStream.hsc └── Types.hs ├── Graphics.hs ├── Graphics ├── BlendMode.hsc ├── CircleShape.hs ├── Color.hsc ├── ConvexShape.hs ├── Font.hs ├── FontInfo.hsc ├── Glyph.hsc ├── Image.hs ├── PrimitiveType.hs ├── Rect.hsc ├── RectangleShape.hs ├── RenderStates.hsc ├── RenderTexture.hs ├── RenderWindow.hs ├── SFBindable.hs ├── SFBounded.hs ├── SFCoordSpace.hs ├── SFDrawable.hs ├── SFRenderTarget.hs ├── SFShape.hs ├── SFShapeResizable.hs ├── SFSmoothTexture.hs ├── SFTexturable.hs ├── SFTransformable.hs ├── SFViewable.hs ├── Shader.hs ├── Shape.hs ├── Sprite.hs ├── Text.hs ├── Texture.hs ├── Transform.hsc ├── Types.hs ├── Vertex.hsc ├── VertexArray.hs └── View.hs ├── SFCopyable.hs ├── SFDisplayable.hs ├── SFException.hs ├── SFResource.hs ├── System.hs ├── System ├── Clock.hs ├── InputStream.hsc ├── Sleep.hsc ├── Time.hsc ├── Vector2.hsc └── Vector3.hsc ├── Utils.hs ├── Window.hs └── Window ├── Context.hsc ├── ContextSettings.hsc ├── Event.hsc ├── Joystick.hsc ├── JoystickIdentification.hsc ├── Keyboard.hsc ├── Mouse.hsc ├── SFWindow.hs ├── Types.hs ├── VideoMode.hsc ├── Window.hsc └── WindowHandle.hs /.gitignore: -------------------------------------------------------------------------------- 1 | dist* 2 | .hsenv* 3 | .cabal* 4 | cabal.sandbox.config 5 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2012 Marc Sunet 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: 4 | 5 | The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. 6 | 7 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 8 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | SFML 2 | ==== 3 | 4 | Low level Haskell bindings for SFML 2.x 5 | 6 | ### What's been wrapped: 7 | 8 | * Window module 9 | * System module 10 | * Graphics module 11 | * Audio module 12 | 13 | ### What's been left out: 14 | 15 | * Threading and networking, since Haskell has better alternatives 16 | 17 | ### What's been tested: 18 | 19 | * Window module, partially 20 | * System module, all but vectors 21 | * Graphics module, partially 22 | * Audio module, partially 23 | 24 | ### Where it's been tested: 25 | 26 | * Arch Linux 32-bit 27 | * Ubuntu Linux 32-bit 28 | * Windows 7 32-bit 29 | 30 | ### Installation (brief) 31 | 32 | - Download latest CSFML 2.x 33 | - Make sure your compiler can find CSFML's headers and libraries, then run: 34 | 35 | ``` 36 | $ git clone https://github.com/SFML-haskell/SFML.git 37 | $ cd SFML 38 | $ cabal install 39 | ``` 40 | 41 | For detailed installation instructions, please head to the [wiki][1]. 42 | 43 | [0]: https://github.com/jeannekamikaze/SFML/blob/master/demos/demos.cabal 44 | [1]: https://github.com/jeannekamikaze/SFML/wiki 45 | -------------------------------------------------------------------------------- /SFML.cabal: -------------------------------------------------------------------------------- 1 | name: SFML 2 | version: 2.3.2.4 3 | synopsis: SFML bindings 4 | description: 5 | Low level bindings for SFML 2.3.2. 6 | license: MIT 7 | license-file: LICENSE 8 | author: Marc Sunet 9 | maintainer: jeannekamikaze@gmail.com 10 | homepage: https://github.com/jeannekamikaze/SFML 11 | bug-reports: https://github.com/jeannekamikaze/SFML/issues 12 | category: Game 13 | build-type: Simple 14 | cabal-version: >=1.8 15 | 16 | source-repository head 17 | type: git 18 | location: https://github.com/SFML-haskell/SFML 19 | 20 | Flag OfficialCSFMLForWindows 21 | Description: Use the official CSFML bundle for Windows from http://www.sfml-dev.org/download/csfml/ 22 | default: False 23 | 24 | 25 | library 26 | hs-source-dirs: 27 | src 28 | 29 | exposed-modules: 30 | SFML.Audio 31 | SFML.Graphics 32 | SFML.System 33 | SFML.Window 34 | SFML.Audio.Listener 35 | SFML.Audio.Music 36 | SFML.Audio.SFSampled 37 | SFML.Audio.SFSound 38 | SFML.Audio.SFSoundBuffer 39 | SFML.Audio.SFSoundRecorder 40 | SFML.Audio.Sound 41 | SFML.Audio.SoundBuffer 42 | SFML.Audio.SoundBufferRecorder 43 | SFML.Audio.SoundRecorder 44 | SFML.Audio.SoundStatus 45 | SFML.Audio.SoundStream 46 | SFML.Audio.Types 47 | SFML.Graphics.BlendMode 48 | SFML.Graphics.CircleShape 49 | SFML.Graphics.Color 50 | SFML.Graphics.ConvexShape 51 | SFML.Graphics.Font 52 | SFML.Graphics.FontInfo 53 | SFML.Graphics.Glyph 54 | SFML.Graphics.Image 55 | SFML.Graphics.PrimitiveType 56 | SFML.Graphics.Rect 57 | SFML.Graphics.RectangleShape 58 | SFML.Graphics.RenderStates 59 | SFML.Graphics.RenderTexture 60 | SFML.Graphics.RenderWindow 61 | SFML.Graphics.SFBindable 62 | SFML.Graphics.SFBounded 63 | SFML.Graphics.SFDrawable 64 | SFML.Graphics.SFCoordSpace 65 | SFML.Graphics.SFRenderTarget 66 | SFML.Graphics.SFShape 67 | SFML.Graphics.SFShapeResizable 68 | SFML.Graphics.SFSmoothTexture 69 | SFML.Graphics.SFTexturable 70 | SFML.Graphics.SFTransformable 71 | SFML.Graphics.SFViewable 72 | SFML.Graphics.Shader 73 | SFML.Graphics.Shape 74 | SFML.Graphics.Sprite 75 | SFML.Graphics.Text 76 | SFML.Graphics.Texture 77 | SFML.Graphics.Transform 78 | SFML.Graphics.Types 79 | SFML.Graphics.Vertex 80 | SFML.Graphics.VertexArray 81 | SFML.Graphics.View 82 | SFML.SFCopyable 83 | SFML.SFDisplayable 84 | SFML.SFException 85 | SFML.SFResource 86 | SFML.System.Clock 87 | SFML.System.InputStream 88 | SFML.System.Sleep 89 | SFML.System.Time 90 | SFML.System.Vector2 91 | SFML.System.Vector3 92 | SFML.Utils 93 | SFML.Window.Context 94 | SFML.Window.ContextSettings 95 | SFML.Window.Event 96 | SFML.Window.Joystick 97 | SFML.Window.JoystickIdentification 98 | SFML.Window.Keyboard 99 | SFML.Window.Mouse 100 | SFML.Window.SFWindow 101 | SFML.Window.Types 102 | SFML.Window.VideoMode 103 | SFML.Window.Window 104 | SFML.Window.WindowHandle 105 | 106 | c-sources: 107 | cbits/SFML/Audio/Listener_helper.c 108 | cbits/SFML/Audio/Music_helper.c 109 | cbits/SFML/Audio/Sound_helper.c 110 | cbits/SFML/Audio/SoundBuffer_helper.c 111 | cbits/SFML/Audio/SoundStream_helper.c 112 | cbits/SFML/Graphics/CircleShape_helper.c 113 | cbits/SFML/Graphics/ConvexShape_helper.c 114 | cbits/SFML/Graphics/Font_helper.c 115 | cbits/SFML/Graphics/Image_helper.c 116 | cbits/SFML/Graphics/RectangleShape_helper.c 117 | cbits/SFML/Graphics/RenderTexture_helper.c 118 | cbits/SFML/Graphics/RenderWindow_helper.c 119 | cbits/SFML/Graphics/Shader_helper.c 120 | cbits/SFML/Graphics/Shape_helper.c 121 | cbits/SFML/Graphics/Sprite_helper.c 122 | cbits/SFML/Graphics/Text_helper.c 123 | cbits/SFML/Graphics/Texture_helper.c 124 | cbits/SFML/Graphics/VertexArray_helper.c 125 | cbits/SFML/Graphics/View_helper.c 126 | cbits/SFML/System/Clock_helper.c 127 | cbits/SFML/System/Time_helper.c 128 | cbits/SFML/System/Sleep_helper.c 129 | cbits/SFML/Window/Joystick_helper.c 130 | cbits/SFML/Window/VideoMode_helper.c 131 | cbits/SFML/Window/Window_helper.c 132 | 133 | build-depends: 134 | base > 4 && < 5 135 | 136 | build-tools: 137 | hsc2hs -any 138 | 139 | extensions: 140 | ForeignFunctionInterface 141 | DeriveDataTypeable 142 | 143 | if os(windows) 144 | extra-libraries: 145 | csfml-window, 146 | csfml-system, 147 | csfml-graphics, 148 | csfml-network, 149 | csfml-audio 150 | else 151 | extra-libraries: 152 | csfml-window, 153 | csfml-system, 154 | csfml-graphics, 155 | csfml-network, 156 | csfml-audio, 157 | sfml-window, 158 | sfml-system, 159 | sfml-graphics, 160 | sfml-network, 161 | sfml-audio 162 | -------------------------------------------------------------------------------- /Setup.hs: -------------------------------------------------------------------------------- 1 | import Distribution.Simple 2 | main = defaultMain 3 | 4 | -------------------------------------------------------------------------------- /cbits/SFML/Audio/Listener_helper.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | 4 | void sfListener_setPosition_helper (sfVector3f* position) 5 | { 6 | sfListener_setPosition (*position); 7 | } 8 | 9 | 10 | void sfListener_getPosition_helper (sfVector3f* position) 11 | { 12 | *position = sfListener_getPosition (); 13 | } 14 | 15 | 16 | void sfListener_setDirection_helper (sfVector3f* orientation) 17 | { 18 | sfListener_setDirection (*orientation); 19 | } 20 | 21 | 22 | void sfListener_getDirection_helper (sfVector3f* direction) 23 | { 24 | *direction = sfListener_getDirection (); 25 | } 26 | 27 | 28 | void sfListener_setUpVector_helper (sfVector3f* upVector) 29 | { 30 | sfListener_setUpVector (*upVector); 31 | } 32 | 33 | 34 | void sfListener_getUpVector_helper (sfVector3f* upVector) 35 | { 36 | *upVector = sfListener_getUpVector (); 37 | } 38 | 39 | -------------------------------------------------------------------------------- /cbits/SFML/Audio/Music_helper.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | 4 | void sfMusic_getDuration_helper (const sfMusic* music, sfTime* time) 5 | { 6 | *time = sfMusic_getDuration (music); 7 | } 8 | 9 | 10 | void sfMusic_getPlayingOffset_helper (const sfMusic* music, sfTime* time) 11 | { 12 | *time = sfMusic_getPlayingOffset (music); 13 | } 14 | 15 | 16 | void sfMusic_setPosition_helper (sfMusic* music, sfVector3f* position) 17 | { 18 | sfMusic_setPosition (music, *position); 19 | } 20 | 21 | 22 | void sfMusic_getPosition_helper (const sfMusic* music, sfVector3f* position) 23 | { 24 | *position = sfMusic_getPosition (music); 25 | } 26 | 27 | -------------------------------------------------------------------------------- /cbits/SFML/Audio/SoundBuffer_helper.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | 4 | void sfSoundBuffer_getDuration_helper (const sfSoundBuffer* soundBuffer, sfTime* time) 5 | { 6 | *time = sfSoundBuffer_getDuration (soundBuffer); 7 | } 8 | 9 | -------------------------------------------------------------------------------- /cbits/SFML/Audio/SoundStream_helper.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | 4 | void sfSoundStream_getPlayingOffset_helper (const sfSoundStream* stream, sfTime* time) 5 | { 6 | *time = sfSoundStream_getPlayingOffset (stream); 7 | } 8 | 9 | 10 | void sfSoundStream_setPosition_helper (sfSoundStream* stream, sfVector3f* position) 11 | { 12 | sfSoundStream_setPosition (stream, *position); 13 | } 14 | 15 | 16 | void sfSoundStream_getPosition_helper (const sfSoundStream* stream, sfVector3f* position) 17 | { 18 | *position = sfSoundStream_getPosition (stream); 19 | } 20 | 21 | -------------------------------------------------------------------------------- /cbits/SFML/Audio/Sound_helper.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | 4 | void sfSound_setPosition_helper (sfSound* sound, sfVector3f* position) 5 | { 6 | sfSound_setPosition (sound, *position); 7 | } 8 | 9 | 10 | void sfSound_getPosition_helper (const sfSound* sound, sfVector3f* position) 11 | { 12 | *position = sfSound_getPosition (sound); 13 | } 14 | 15 | 16 | void sfSound_getPlayingOffset_helper (const sfSound* sound, sfTime* time) 17 | { 18 | *time = sfSound_getPlayingOffset (sound); 19 | } 20 | 21 | -------------------------------------------------------------------------------- /cbits/SFML/Graphics/CircleShape_helper.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | 4 | void sfCircleShape_setPosition_helper (sfCircleShape* shape, sfVector2f* position) 5 | { 6 | sfCircleShape_setPosition (shape, *position); 7 | } 8 | 9 | 10 | void sfCircleShape_setScale_helper (sfCircleShape* shape, sfVector2f* scale) 11 | { 12 | sfCircleShape_setScale (shape, *scale); 13 | } 14 | 15 | 16 | void sfCircleShape_setOrigin_helper (sfCircleShape* shape, sfVector2f* origin) 17 | { 18 | sfCircleShape_setOrigin (shape, *origin); 19 | } 20 | 21 | 22 | void sfCircleShape_getPosition_helper (const sfCircleShape* shape, sfVector2f* position) 23 | { 24 | *position = sfCircleShape_getPosition (shape); 25 | } 26 | 27 | 28 | void sfCircleShape_getScale_helper (const sfCircleShape* shape, sfVector2f* scale) 29 | { 30 | *scale = sfCircleShape_getScale (shape); 31 | } 32 | 33 | 34 | void sfCircleShape_getOrigin_helper (const sfCircleShape* shape, sfVector2f* origin) 35 | { 36 | *origin = sfCircleShape_getOrigin (shape); 37 | } 38 | 39 | 40 | void sfCircleShape_move_helper (sfCircleShape* shape, sfVector2f* offset) 41 | { 42 | sfCircleShape_move (shape, *offset); 43 | } 44 | 45 | 46 | void sfCircleShape_scale_helper (sfCircleShape* shape, sfVector2f* factors) 47 | { 48 | sfCircleShape_scale (shape, *factors); 49 | } 50 | 51 | 52 | void sfCircleShape_getTransform_helper (const sfCircleShape* shape, sfTransform* transform) 53 | { 54 | *transform = sfCircleShape_getTransform (shape); 55 | } 56 | 57 | 58 | void sfCircleShape_getInverseTransform_helper (const sfCircleShape* shape, sfTransform* itransform) 59 | { 60 | *itransform = sfCircleShape_getInverseTransform (shape); 61 | } 62 | 63 | 64 | void sfCircleShape_setTextureRect_helper (sfCircleShape* shape, sfIntRect* rect) 65 | { 66 | sfCircleShape_setTextureRect (shape, *rect); 67 | } 68 | 69 | 70 | void sfCircleShape_getTextureRect_helper (const sfCircleShape* shape, sfIntRect* rect) 71 | { 72 | *rect = sfCircleShape_getTextureRect (shape); 73 | } 74 | 75 | 76 | void sfCircleShape_setFillColor_helper (sfCircleShape* shape, sfColor* color) 77 | { 78 | sfCircleShape_setFillColor (shape, *color); 79 | } 80 | 81 | 82 | void sfCircleShape_setOutlineColor_helper (sfCircleShape* shape, sfColor* color) 83 | { 84 | sfCircleShape_setOutlineColor (shape, *color); 85 | } 86 | 87 | 88 | void sfCircleShape_getFillColor_helper (const sfCircleShape* shape, sfColor* color) 89 | { 90 | *color = sfCircleShape_getFillColor (shape); 91 | } 92 | 93 | 94 | void sfCircleShape_getOutlineColor_helper (const sfCircleShape* shape, sfColor* color) 95 | { 96 | *color = sfCircleShape_getOutlineColor (shape); 97 | } 98 | 99 | 100 | void sfCircleShape_getPoint_helper (const sfCircleShape* shape, unsigned int index, sfVector2f* point) 101 | { 102 | *point = sfCircleShape_getPoint (shape, index); 103 | } 104 | 105 | 106 | void sfCircleShape_getLocalBounds_helper (const sfCircleShape* shape, sfFloatRect* rect) 107 | { 108 | *rect = sfCircleShape_getLocalBounds (shape); 109 | } 110 | 111 | 112 | void sfCircleShape_getGlobalBounds_helper (const sfCircleShape* shape, sfFloatRect* rect) 113 | { 114 | *rect = sfCircleShape_getGlobalBounds (shape); 115 | } 116 | 117 | -------------------------------------------------------------------------------- /cbits/SFML/Graphics/ConvexShape_helper.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | 4 | void sfConvexShape_setPosition_helper (sfConvexShape* shape, sfVector2f* position) 5 | { 6 | sfConvexShape_setPosition (shape, *position); 7 | } 8 | 9 | 10 | void sfConvexShape_setScale_helper (sfConvexShape* shape, sfVector2f* scale) 11 | { 12 | sfConvexShape_setScale (shape, *scale); 13 | } 14 | 15 | 16 | void sfConvexShape_setOrigin_helper (sfConvexShape* shape, sfVector2f* origin) 17 | { 18 | sfConvexShape_setOrigin (shape, *origin); 19 | } 20 | 21 | 22 | void sfConvexShape_getPosition_helper (const sfConvexShape* shape, sfVector2f* position) 23 | { 24 | *position = sfConvexShape_getPosition (shape); 25 | } 26 | 27 | 28 | void sfConvexShape_getScale_helper (const sfConvexShape* shape, sfVector2f* scale) 29 | { 30 | *scale = sfConvexShape_getScale (shape); 31 | } 32 | 33 | 34 | void sfConvexShape_getOrigin_helper (const sfConvexShape* shape, sfVector2f* origin) 35 | { 36 | *origin = sfConvexShape_getOrigin (shape); 37 | } 38 | 39 | 40 | void sfConvexShape_move_helper (sfConvexShape* shape, sfVector2f* offset) 41 | { 42 | sfConvexShape_move (shape, *offset); 43 | } 44 | 45 | 46 | void sfConvexShape_scale_helper (sfConvexShape* shape, sfVector2f* factors) 47 | { 48 | sfConvexShape_scale (shape, *factors); 49 | } 50 | 51 | 52 | void sfConvexShape_getTransform_helper (const sfConvexShape* shape, sfTransform* transform) 53 | { 54 | *transform = sfConvexShape_getTransform (shape); 55 | } 56 | 57 | 58 | void sfConvexShape_getInverseTransform_helper (const sfConvexShape* shape, sfTransform* itransform) 59 | { 60 | *itransform = sfConvexShape_getInverseTransform (shape); 61 | } 62 | 63 | 64 | void sfConvexShape_setTextureRect_helper (sfConvexShape* shape, sfIntRect* rect) 65 | { 66 | sfConvexShape_setTextureRect (shape, *rect); 67 | } 68 | 69 | 70 | void sfConvexShape_getTextureRect_helper (const sfConvexShape* shape, sfIntRect* rect) 71 | { 72 | *rect = sfConvexShape_getTextureRect (shape); 73 | } 74 | 75 | 76 | void sfConvexShape_setFillColor_helper (sfConvexShape* shape, sfColor* color) 77 | { 78 | sfConvexShape_setFillColor (shape, *color); 79 | } 80 | 81 | 82 | void sfConvexShape_setOutlineColor_helper (sfConvexShape* shape, sfColor* color) 83 | { 84 | sfConvexShape_setOutlineColor (shape, *color); 85 | } 86 | 87 | 88 | void sfConvexShape_getFillColor_helper (const sfConvexShape* shape, sfColor* color) 89 | { 90 | *color = sfConvexShape_getFillColor (shape); 91 | } 92 | 93 | 94 | void sfConvexShape_getOutlineColor_helper (const sfConvexShape* shape, sfColor* color) 95 | { 96 | *color = sfConvexShape_getOutlineColor (shape); 97 | } 98 | 99 | 100 | void sfConvexShape_getPoint_helper (const sfConvexShape* shape, unsigned int index, sfVector2f* point) 101 | { 102 | *point = sfConvexShape_getPoint (shape, index); 103 | } 104 | 105 | 106 | void sfConvexShape_getLocalBounds_helper (const sfConvexShape* shape, sfFloatRect* rect) 107 | { 108 | *rect = sfConvexShape_getLocalBounds (shape); 109 | } 110 | 111 | 112 | void sfConvexShape_getGlobalBounds_helper (const sfConvexShape* shape, sfFloatRect* rect) 113 | { 114 | *rect = sfConvexShape_getGlobalBounds (shape); 115 | } 116 | 117 | 118 | void sfConvexShape_setPoint_helper (sfConvexShape* shape, unsigned int index, sfVector2f* point) 119 | { 120 | sfConvexShape_setPoint (shape, index, *point); 121 | } 122 | 123 | -------------------------------------------------------------------------------- /cbits/SFML/Graphics/Font_helper.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | 4 | void sfFont_getGlyph_helper (sfFont* font, sfUint32 codePoint, unsigned int characterSize, float outline, sfBool bold, sfGlyph* glyph) 5 | { 6 | *glyph = sfFont_getGlyph (font, codePoint, characterSize, bold, outline); 7 | } 8 | 9 | 10 | void sfFont_getInfo_helper (sfFont* font, sfFontInfo* info) 11 | { 12 | *info = sfFont_getInfo (font); 13 | } 14 | -------------------------------------------------------------------------------- /cbits/SFML/Graphics/Image_helper.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | 4 | sfImage* sfImage_createFromColor_helper (unsigned int width, unsigned int height, sfColor* color) 5 | { 6 | return sfImage_createFromColor (width, height, *color); 7 | } 8 | 9 | 10 | void sfImage_getSize_helper (const sfImage* image, sfVector2u* size) 11 | { 12 | *size = sfImage_getSize (image); 13 | } 14 | 15 | 16 | void sfImage_createMaskFromColor_helper (sfImage* image, sfColor* color, sfUint8 alpha) 17 | { 18 | sfImage_createMaskFromColor (image, *color, alpha); 19 | } 20 | 21 | 22 | void sfImage_copyImage_helper 23 | (sfImage* image, const sfImage* source, unsigned int destX, unsigned int destY, sfIntRect* sourceRect, sfBool applyAlpha) 24 | { 25 | sfImage_copyImage (image, source, destX, destY, *sourceRect, applyAlpha); 26 | } 27 | 28 | 29 | void sfImage_setPixel_helper (sfImage* image, unsigned int x, unsigned int y, sfColor* color) 30 | { 31 | sfImage_setPixel (image, x, y, *color); 32 | } 33 | 34 | 35 | void sfImage_getPixel_helper (const sfImage* image, unsigned int x, unsigned int y, sfColor* color) 36 | { 37 | *color = sfImage_getPixel (image, x, y); 38 | } 39 | 40 | -------------------------------------------------------------------------------- /cbits/SFML/Graphics/RectangleShape_helper.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | 4 | void sfRectangleShape_setPosition_helper (sfRectangleShape* shape, sfVector2f* position) 5 | { 6 | sfRectangleShape_setPosition (shape, *position); 7 | } 8 | 9 | 10 | void sfRectangleShape_setScale_helper (sfRectangleShape* shape, sfVector2f* scale) 11 | { 12 | sfRectangleShape_setScale (shape, *scale); 13 | } 14 | 15 | 16 | void sfRectangleShape_setOrigin_helper (sfRectangleShape* shape, sfVector2f* origin) 17 | { 18 | sfRectangleShape_setOrigin (shape, *origin); 19 | } 20 | 21 | 22 | void sfRectangleShape_getPosition_helper (const sfRectangleShape* shape, sfVector2f* position) 23 | { 24 | *position = sfRectangleShape_getPosition (shape); 25 | } 26 | 27 | 28 | void sfRectangleShape_getScale_helper (const sfRectangleShape* shape, sfVector2f* scale) 29 | { 30 | *scale = sfRectangleShape_getScale (shape); 31 | } 32 | 33 | 34 | void sfRectangleShape_getOrigin_helper (const sfRectangleShape* shape, sfVector2f* origin) 35 | { 36 | *origin = sfRectangleShape_getOrigin (shape); 37 | } 38 | 39 | 40 | void sfRectangleShape_move_helper (sfRectangleShape* shape, sfVector2f* offset) 41 | { 42 | sfRectangleShape_move (shape, *offset); 43 | } 44 | 45 | 46 | void sfRectangleShape_scale_helper (sfRectangleShape* shape, sfVector2f* factors) 47 | { 48 | sfRectangleShape_scale (shape, *factors); 49 | } 50 | 51 | 52 | void sfRectangleShape_getTransform_helper (const sfRectangleShape* shape, sfTransform* transform) 53 | { 54 | *transform = sfRectangleShape_getTransform (shape); 55 | } 56 | 57 | 58 | void sfRectangleShape_getInverseTransform_helper (const sfRectangleShape* shape, sfTransform* itransform) 59 | { 60 | *itransform = sfRectangleShape_getInverseTransform (shape); 61 | } 62 | 63 | 64 | void sfRectangleShape_setTextureRect_helper (sfRectangleShape* shape, sfIntRect* rect) 65 | { 66 | sfRectangleShape_setTextureRect (shape, *rect); 67 | } 68 | 69 | 70 | void sfRectangleShape_getTextureRect_helper (const sfRectangleShape* shape, sfIntRect* rect) 71 | { 72 | *rect = sfRectangleShape_getTextureRect (shape); 73 | } 74 | 75 | 76 | void sfRectangleShape_setFillColor_helper (sfRectangleShape* shape, sfColor* color) 77 | { 78 | sfRectangleShape_setFillColor (shape, *color); 79 | } 80 | 81 | 82 | void sfRectangleShape_setOutlineColor_helper (sfRectangleShape* shape, sfColor* color) 83 | { 84 | sfRectangleShape_setOutlineColor (shape, *color); 85 | } 86 | 87 | 88 | void sfRectangleShape_getFillColor_helper (const sfRectangleShape* shape, sfColor* color) 89 | { 90 | *color = sfRectangleShape_getFillColor (shape); 91 | } 92 | 93 | 94 | void sfRectangleShape_getOutlineColor_helper (const sfRectangleShape* shape, sfColor* color) 95 | { 96 | *color = sfRectangleShape_getOutlineColor (shape); 97 | } 98 | 99 | 100 | void sfRectangleShape_getPoint_helper (const sfRectangleShape* shape, unsigned int index, sfVector2f* point) 101 | { 102 | *point = sfRectangleShape_getPoint (shape, index); 103 | } 104 | 105 | 106 | void sfRectangleShape_getLocalBounds_helper (const sfRectangleShape* shape, sfFloatRect* rect) 107 | { 108 | *rect = sfRectangleShape_getLocalBounds (shape); 109 | } 110 | 111 | 112 | void sfRectangleShape_getGlobalBounds_helper (const sfRectangleShape* shape, sfFloatRect* rect) 113 | { 114 | *rect = sfRectangleShape_getGlobalBounds (shape); 115 | } 116 | 117 | 118 | void sfRectangleShape_setSize_helper (sfRectangleShape* shape, sfVector2f* size) 119 | { 120 | sfRectangleShape_setSize (shape, *size); 121 | } 122 | 123 | 124 | void sfRectangleShape_getSize_helper (const sfRectangleShape* shape, sfVector2f* size) 125 | { 126 | *size = sfRectangleShape_getSize (shape); 127 | } 128 | 129 | -------------------------------------------------------------------------------- /cbits/SFML/Graphics/RenderTexture_helper.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | 4 | void sfRenderTexture_getSize_helper (const sfRenderTexture* renderTexture, sfVector2u* size) 5 | { 6 | *size = sfRenderTexture_getSize (renderTexture); 7 | } 8 | 9 | 10 | void sfRenderTexture_clear_helper (sfRenderTexture* renderTexture, sfColor* color) 11 | { 12 | sfRenderTexture_clear (renderTexture, *color); 13 | } 14 | 15 | 16 | void sfRenderTexture_getViewport_helper (const sfRenderTexture* renderTexture, const sfView* view, sfIntRect* vp) 17 | { 18 | *vp = sfRenderTexture_getViewport (renderTexture, view); 19 | } 20 | 21 | 22 | void sfRenderTexture_mapPixelToCoords_helper 23 | (const sfRenderTexture* renderTexture, sfVector2i* point, const sfView* targetView, sfVector2f* coords) 24 | { 25 | *coords = sfRenderTexture_mapPixelToCoords (renderTexture, *point, targetView); 26 | } 27 | 28 | -------------------------------------------------------------------------------- /cbits/SFML/Graphics/RenderWindow_helper.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | 4 | sfRenderWindow* sfRenderWindow_create_helper 5 | (sfVideoMode* mode, const char* title, sfUint32 style, const sfContextSettings* settings) 6 | { 7 | return sfRenderWindow_create (*mode, title, style, settings); 8 | } 9 | 10 | 11 | void sfRenderWindow_getSettings_helper (const sfRenderWindow* renderWindow, sfContextSettings* settings) 12 | { 13 | *settings = sfRenderWindow_getSettings (renderWindow); 14 | } 15 | 16 | 17 | void sfRenderWindow_getPosition_helper (const sfRenderWindow* renderWindow, sfVector2i* position) 18 | { 19 | *position = sfRenderWindow_getPosition (renderWindow); 20 | } 21 | 22 | 23 | void sfRenderWindow_setPosition_helper (sfRenderWindow* renderWindow, sfVector2i* position) 24 | { 25 | sfRenderWindow_setPosition (renderWindow, *position); 26 | } 27 | 28 | 29 | void sfRenderWindow_getSize_helper (const sfRenderWindow* renderWindow, sfVector2u* size) 30 | { 31 | *size = sfRenderWindow_getSize (renderWindow); 32 | } 33 | 34 | 35 | void sfRenderWindow_setSize_helper (sfRenderWindow* renderWindow, sfVector2u* size) 36 | { 37 | sfRenderWindow_setSize (renderWindow, *size); 38 | } 39 | 40 | 41 | void sfRenderWindow_clear_helper (sfRenderWindow* renderWindow, sfColor* color) 42 | { 43 | sfRenderWindow_clear (renderWindow, *color); 44 | } 45 | 46 | 47 | void sfRenderWindow_getViewport_helper (const sfRenderWindow* renderWindow, const sfView* view, sfIntRect* rect) 48 | { 49 | *rect = sfRenderWindow_getViewport (renderWindow, view); 50 | } 51 | 52 | 53 | void sfRenderWindow_mapPixelToCoords_helper 54 | (const sfRenderWindow* renderWindow, sfVector2i point, const sfView* targetView, sfVector2f* out) 55 | { 56 | *out = sfRenderWindow_mapPixelToCoords (renderWindow, point, targetView); 57 | } 58 | 59 | 60 | void sfMouse_getPositionRenderWindow_helper (const sfRenderWindow* relativeTo, sfVector2i* position) 61 | { 62 | *position = sfMouse_getPositionRenderWindow (relativeTo); 63 | } 64 | 65 | 66 | void sfMouse_setPositionRenderWindow_helper (sfVector2i* position, const sfRenderWindow* relativeTo) 67 | { 68 | sfMouse_setPositionRenderWindow (*position, relativeTo); 69 | } 70 | 71 | -------------------------------------------------------------------------------- /cbits/SFML/Graphics/Shader_helper.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | 4 | void sfShader_setVector2Parameter_helper (sfShader* shader, const char* name, sfVector2f* vector) 5 | { 6 | sfShader_setVector2Parameter (shader, name, *vector); 7 | } 8 | 9 | 10 | void sfShader_setVector3Parameter_helper (sfShader* shader, const char* name, sfVector3f* vector) 11 | { 12 | sfShader_setVector3Parameter (shader, name, *vector); 13 | } 14 | 15 | 16 | void sfShader_setColorParameter_helper (sfShader* shader, const char* name, sfColor* color) 17 | { 18 | sfShader_setColorParameter (shader, name, *color); 19 | } 20 | 21 | 22 | void sfShader_setTransformParameter_helper (sfShader* shader, const char* name, sfTransform* transform) 23 | { 24 | sfShader_setTransformParameter (shader, name, *transform); 25 | } 26 | 27 | -------------------------------------------------------------------------------- /cbits/SFML/Graphics/Shape_helper.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | 4 | void sfShape_setPosition_helper (sfShape* shape, sfVector2f* position) 5 | { 6 | sfShape_setPosition (shape, *position); 7 | } 8 | 9 | 10 | void sfShape_setScale_helper (sfShape* shape, sfVector2f* scale) 11 | { 12 | sfShape_setScale (shape, *scale); 13 | } 14 | 15 | 16 | void sfShape_setOrigin_helper (sfShape* shape, sfVector2f* origin) 17 | { 18 | sfShape_setOrigin (shape, *origin); 19 | } 20 | 21 | 22 | void sfShape_getPosition_helper (const sfShape* shape, sfVector2f* position) 23 | { 24 | *position = sfShape_getPosition (shape); 25 | } 26 | 27 | 28 | void sfShape_getScale_helper (const sfShape* shape, sfVector2f* scale) 29 | { 30 | *scale = sfShape_getScale (shape); 31 | } 32 | 33 | 34 | void sfShape_getOrigin_helper (const sfShape* shape, sfVector2f* origin) 35 | { 36 | *origin = sfShape_getOrigin (shape); 37 | } 38 | 39 | 40 | void sfShape_move_helper (sfShape* shape, sfVector2f* offset) 41 | { 42 | sfShape_move (shape, *offset); 43 | } 44 | 45 | 46 | void sfShape_scale_helper (sfShape* shape, sfVector2f* factors) 47 | { 48 | sfShape_scale (shape, *factors); 49 | } 50 | 51 | 52 | void sfShape_getTransform_helper (const sfShape* shape, sfTransform* transform) 53 | { 54 | *transform = sfShape_getTransform (shape); 55 | } 56 | 57 | 58 | void sfShape_getInverseTransform_helper (const sfShape* shape, sfTransform* itransform) 59 | { 60 | *itransform = sfShape_getInverseTransform (shape); 61 | } 62 | 63 | 64 | void sfShape_setTextureRect_helper (sfShape* shape, sfIntRect* rect) 65 | { 66 | sfShape_setTextureRect (shape, *rect); 67 | } 68 | 69 | 70 | void sfShape_getTextureRect_helper (const sfShape* shape, sfIntRect* rect) 71 | { 72 | *rect = sfShape_getTextureRect (shape); 73 | } 74 | 75 | 76 | void sfShape_setFillColor_helper (sfShape* shape, sfColor* color) 77 | { 78 | sfShape_setFillColor (shape, *color); 79 | } 80 | 81 | 82 | void sfShape_setOutlineColor_helper (sfShape* shape, sfColor* color) 83 | { 84 | sfShape_setOutlineColor (shape, *color); 85 | } 86 | 87 | 88 | void sfShape_getFillColor_helper (const sfShape* shape, sfColor* color) 89 | { 90 | *color = sfShape_getFillColor (shape); 91 | } 92 | 93 | 94 | void sfShape_getOutlineColor_helper (const sfShape* shape, sfColor* color) 95 | { 96 | *color = sfShape_getOutlineColor (shape); 97 | } 98 | 99 | 100 | void sfShape_getPoint_helper (const sfShape* shape, unsigned int index, sfVector2f* point) 101 | { 102 | *point = sfShape_getPoint (shape, index); 103 | } 104 | 105 | 106 | void sfShape_getLocalBounds_helper (const sfShape* shape, sfFloatRect* rect) 107 | { 108 | *rect = sfShape_getLocalBounds (shape); 109 | } 110 | 111 | 112 | void sfShape_getGlobalBounds_helper (const sfShape* shape, sfFloatRect* rect) 113 | { 114 | *rect = sfShape_getGlobalBounds (shape); 115 | } 116 | 117 | -------------------------------------------------------------------------------- /cbits/SFML/Graphics/Sprite_helper.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | 4 | void sfSprite_setPosition_helper (sfSprite* sprite, sfVector2f* position) 5 | { 6 | sfSprite_setPosition (sprite, *position); 7 | } 8 | 9 | 10 | void sfSprite_setScale_helper (sfSprite* sprite, sfVector2f* scale) 11 | { 12 | sfSprite_setScale (sprite, *scale); 13 | } 14 | 15 | 16 | void sfSprite_setOrigin_helper (sfSprite* sprite, sfVector2f* origin) 17 | { 18 | sfSprite_setOrigin (sprite, *origin); 19 | } 20 | 21 | 22 | void sfSprite_getPosition_helper (const sfSprite* sprite, sfVector2f* position) 23 | { 24 | *position = sfSprite_getPosition (sprite); 25 | } 26 | 27 | 28 | void sfSprite_getScale_helper (const sfSprite* sprite, sfVector2f* scale) 29 | { 30 | *scale = sfSprite_getScale (sprite); 31 | } 32 | 33 | 34 | void sfSprite_getOrigin_helper (const sfSprite* sprite, sfVector2f* origin) 35 | { 36 | *origin = sfSprite_getOrigin (sprite); 37 | } 38 | 39 | 40 | void sfSprite_move_helper (sfSprite* sprite, sfVector2f* offset) 41 | { 42 | sfSprite_move (sprite, *offset); 43 | } 44 | 45 | 46 | void sfSprite_scale_helper (sfSprite* sprite, sfVector2f* factors) 47 | { 48 | sfSprite_scale (sprite, *factors); 49 | } 50 | 51 | 52 | void sfSprite_getTransform_helper (const sfSprite* sprite, sfTransform* transform) 53 | { 54 | *transform = sfSprite_getTransform (sprite); 55 | } 56 | 57 | 58 | void sfSprite_getInverseTransform_helper (const sfSprite* sprite, sfTransform* transform) 59 | { 60 | *transform = sfSprite_getInverseTransform (sprite); 61 | } 62 | 63 | 64 | void sfSprite_setColor_helper (sfSprite* sprite, sfColor* color) 65 | { 66 | sfSprite_setColor (sprite, *color); 67 | } 68 | 69 | 70 | void sfSprite_getColor_helper (const sfSprite* sprite, sfColor* color) 71 | { 72 | *color = sfSprite_getColor (sprite); 73 | } 74 | 75 | 76 | void sfSprite_setTextureRect_helper (sfSprite* sprite, sfIntRect* rectangle) 77 | { 78 | sfSprite_setTextureRect (sprite, *rectangle); 79 | } 80 | 81 | 82 | void sfSprite_getTextureRect_helper (const sfSprite* sprite, sfIntRect* rect) 83 | { 84 | *rect = sfSprite_getTextureRect (sprite); 85 | } 86 | 87 | 88 | void sfSprite_getLocalBounds_helper (const sfSprite* sprite, sfFloatRect* rect) 89 | { 90 | *rect = sfSprite_getLocalBounds (sprite); 91 | } 92 | 93 | 94 | void sfSprite_getGlobalBounds_helper (const sfSprite* sprite, sfFloatRect* rect) 95 | { 96 | *rect = sfSprite_getGlobalBounds (sprite); 97 | } 98 | 99 | -------------------------------------------------------------------------------- /cbits/SFML/Graphics/Text_helper.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | 4 | void sfText_setPosition_helper (sfText* text, sfVector2f* position) 5 | { 6 | sfText_setPosition (text, *position); 7 | } 8 | 9 | 10 | void sfText_setScale_helper (sfText* text, sfVector2f* scale) 11 | { 12 | sfText_setScale (text, *scale); 13 | } 14 | 15 | 16 | void sfText_setOrigin_helper (sfText* text, sfVector2f* origin) 17 | { 18 | sfText_setOrigin (text, *origin); 19 | } 20 | 21 | 22 | void sfText_getPosition_helper (const sfText* text, sfVector2f* position) 23 | { 24 | *position = sfText_getPosition (text); 25 | } 26 | 27 | 28 | void sfText_getScale_helper (const sfText* text, sfVector2f* scale) 29 | { 30 | *scale = sfText_getScale (text); 31 | } 32 | 33 | 34 | void sfText_getOrigin_helper (const sfText* text, sfVector2f* origin) 35 | { 36 | *origin = sfText_getOrigin (text); 37 | } 38 | 39 | 40 | void sfText_move_helper (sfText* text, sfVector2f* offset) 41 | { 42 | sfText_move (text, *offset); 43 | } 44 | 45 | 46 | void sfText_scale_helper (sfText* text, sfVector2f* factors) 47 | { 48 | sfText_scale (text, *factors); 49 | } 50 | 51 | 52 | void sfText_getTransform_helper (const sfText* text, sfTransform* transform) 53 | { 54 | *transform = sfText_getTransform (text); 55 | } 56 | 57 | 58 | void sfText_getInverseTransform_helper (const sfText* text, sfTransform* itransform) 59 | { 60 | *itransform = sfText_getInverseTransform (text); 61 | } 62 | 63 | 64 | void sfText_setColor_helper (sfText* text, sfColor* color) 65 | { 66 | sfText_setColor (text, *color); 67 | } 68 | 69 | 70 | void sfText_getColor_helper (const sfText* text, sfColor* color) 71 | { 72 | *color = sfText_getColor (text); 73 | } 74 | 75 | 76 | void sfText_findCharacterPos_helper (const sfText* text, size_t index, sfVector2f* position) 77 | { 78 | *position = sfText_findCharacterPos (text, index); 79 | } 80 | 81 | 82 | void sfText_getLocalBounds_helper (const sfText* text, sfFloatRect* rect) 83 | { 84 | *rect = sfText_getLocalBounds (text); 85 | } 86 | 87 | 88 | void sfText_getGlobalBounds_helper (const sfText* text, sfFloatRect* rect) 89 | { 90 | *rect = sfText_getGlobalBounds (text); 91 | } 92 | 93 | -------------------------------------------------------------------------------- /cbits/SFML/Graphics/Texture_helper.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | 4 | void sfTexture_getSize_helper (const sfTexture* texture, sfVector2u* size) 5 | { 6 | *size = sfTexture_getSize (texture); 7 | } 8 | 9 | -------------------------------------------------------------------------------- /cbits/SFML/Graphics/VertexArray_helper.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | 4 | void sfVertexArray_append_helper (sfVertexArray* vertexArray, sfVertex* vertex) 5 | { 6 | sfVertexArray_append (vertexArray, *vertex); 7 | } 8 | 9 | 10 | void sfVertexArray_getBounds_helper (sfVertexArray* vertexArray, sfFloatRect* rect) 11 | { 12 | *rect = sfVertexArray_getBounds (vertexArray); 13 | } 14 | 15 | -------------------------------------------------------------------------------- /cbits/SFML/Graphics/View_helper.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | 4 | sfView* sfView_createFromRect_helper (sfFloatRect* rectangle) 5 | { 6 | return sfView_createFromRect (*rectangle); 7 | } 8 | 9 | 10 | void sfView_setCenter_helper (sfView* view, sfVector2f* center) 11 | { 12 | sfView_setCenter (view, *center); 13 | } 14 | 15 | 16 | void sfView_setSize_helper (sfView* view, sfVector2f* size) 17 | { 18 | sfView_setSize (view, *size); 19 | } 20 | 21 | 22 | void sfView_setViewport_helper (sfView* view, sfFloatRect* viewport) 23 | { 24 | sfView_setViewport (view, *viewport); 25 | } 26 | 27 | 28 | void sfView_reset_helper (sfView* view, sfFloatRect* rectangle) 29 | { 30 | sfView_reset (view, *rectangle); 31 | } 32 | 33 | 34 | void sfView_getSize_helper (const sfView* view, sfVector2f* size) 35 | { 36 | *size = sfView_getSize (view); 37 | } 38 | 39 | 40 | void sfView_getViewport_helper (const sfView* view, sfFloatRect* vp) 41 | { 42 | *vp = sfView_getViewport (view); 43 | } 44 | 45 | 46 | void sfView_move_helper (sfView* view, sfVector2f* offset) 47 | { 48 | sfView_move (view, *offset); 49 | } 50 | 51 | -------------------------------------------------------------------------------- /cbits/SFML/System/Clock_helper.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | 4 | void sfClock_getElapsedTime_helper (const sfClock* clock, sfTime* time) 5 | { 6 | *time = sfClock_getElapsedTime (clock); 7 | } 8 | 9 | 10 | void sfClock_restart_helper (sfClock* clock, sfTime* time) 11 | { 12 | *time = sfClock_restart (clock); 13 | } 14 | 15 | -------------------------------------------------------------------------------- /cbits/SFML/System/Sleep_helper.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | 4 | void sfSleep_helper (sfTime* duration) 5 | { 6 | sfSleep (*duration); 7 | } 8 | 9 | -------------------------------------------------------------------------------- /cbits/SFML/System/Time_helper.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | 4 | void sfSeconds_helper (float amount, sfTime* time) 5 | { 6 | *time = sfSeconds (amount); 7 | } 8 | 9 | 10 | void sfMilliseconds_helper (sfInt32 amount, sfTime* time) 11 | { 12 | *time = sfMilliseconds (amount); 13 | } 14 | 15 | 16 | void sfMicroseconds_helper (sfInt64 amount, sfTime* time) 17 | { 18 | *time = sfMicroseconds (amount); 19 | } 20 | 21 | -------------------------------------------------------------------------------- /cbits/SFML/Window/Joystick_helper.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | 4 | void sfJoystick_getIdentification_helper (unsigned int joystick, sfJoystickIdentification* ident) 5 | { 6 | *ident = sfJoystick_getIdentification(joystick); 7 | } 8 | -------------------------------------------------------------------------------- /cbits/SFML/Window/VideoMode_helper.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | 4 | sfBool sfVideoMode_isValid_helper (sfVideoMode* mode) 5 | { 6 | return sfVideoMode_isValid (*mode); 7 | } 8 | 9 | 10 | void sfVideoMode_getDesktopMode_helper (sfVideoMode* mode) 11 | { 12 | *mode = sfVideoMode_getDesktopMode (); 13 | } 14 | 15 | -------------------------------------------------------------------------------- /cbits/SFML/Window/Window_helper.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | 5 | sfWindow* sfWindow_create_helper 6 | (sfVideoMode* mode, char* title, sfUint32 style, sfContextSettings* settings) 7 | { 8 | return sfWindow_create (*mode, title, style, settings); 9 | } 10 | 11 | 12 | void sfWindow_getSettings_helper (sfWindow* window, sfContextSettings* settings) 13 | { 14 | *settings = sfWindow_getSettings (window); 15 | } 16 | 17 | 18 | void sfWindow_getPosition_helper (sfWindow* window, sfVector2i* pos) 19 | { 20 | *pos = sfWindow_getPosition (window); 21 | } 22 | 23 | 24 | void sfWindow_setPosition_helper (sfWindow* window, sfVector2i* position) 25 | { 26 | sfWindow_setPosition (window, *position); 27 | } 28 | 29 | 30 | void sfWindow_getSize_helper (const sfWindow* window, sfVector2u* size) 31 | { 32 | *size = sfWindow_getSize (window); 33 | } 34 | 35 | 36 | void sfWindow_setSize_helper (sfWindow* window, sfVector2u* size) 37 | { 38 | sfWindow_setSize (window, *size); 39 | } 40 | 41 | 42 | void sfMouse_getPosition_helper (const sfWindow* relativeTo, sfVector2i* pos) 43 | { 44 | *pos = sfMouse_getPosition (relativeTo); 45 | } 46 | 47 | 48 | void sfMouse_setPosition_helper (sfVector2i* position, const sfWindow* relativeTo) 49 | { 50 | sfMouse_setPosition (*position, relativeTo); 51 | } 52 | 53 | 54 | -------------------------------------------------------------------------------- /demos/LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2012 Marc Sunet 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: 4 | 5 | The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. 6 | 7 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 8 | -------------------------------------------------------------------------------- /demos/assets/DST-BreakOut.ogg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SFML-haskell/SFML/1d1ceee6bc782f4f194853fbd0cc4acb33b86d41/demos/assets/DST-BreakOut.ogg -------------------------------------------------------------------------------- /demos/assets/DST-BreakOut.txt: -------------------------------------------------------------------------------- 1 | Free music downloaded from http://www.dreade.org/nosoap/ 2 | 3 | -------------------------------------------------------------------------------- /demos/assets/Haskell-Logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SFML-haskell/SFML/1d1ceee6bc782f4f194853fbd0cc4acb33b86d41/demos/assets/Haskell-Logo.png -------------------------------------------------------------------------------- /demos/assets/Vera.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SFML-haskell/SFML/1d1ceee6bc782f4f194853fbd0cc4acb33b86d41/demos/assets/Vera.ttf -------------------------------------------------------------------------------- /demos/assets/ttf-bitstream-vera-1.10/COPYRIGHT.TXT: -------------------------------------------------------------------------------- 1 | Bitstream Vera Fonts Copyright 2 | 3 | The fonts have a generous copyright, allowing derivative works (as 4 | long as "Bitstream" or "Vera" are not in the names), and full 5 | redistribution (so long as they are not *sold* by themselves). They 6 | can be be bundled, redistributed and sold with any software. 7 | 8 | The fonts are distributed under the following copyright: 9 | 10 | Copyright 11 | ========= 12 | 13 | Copyright (c) 2003 by Bitstream, Inc. All Rights Reserved. Bitstream 14 | Vera is a trademark of Bitstream, Inc. 15 | 16 | Permission is hereby granted, free of charge, to any person obtaining 17 | a copy of the fonts accompanying this license ("Fonts") and associated 18 | documentation files (the "Font Software"), to reproduce and distribute 19 | the Font Software, including without limitation the rights to use, 20 | copy, merge, publish, distribute, and/or sell copies of the Font 21 | Software, and to permit persons to whom the Font Software is furnished 22 | to do so, subject to the following conditions: 23 | 24 | The above copyright and trademark notices and this permission notice 25 | shall be included in all copies of one or more of the Font Software 26 | typefaces. 27 | 28 | The Font Software may be modified, altered, or added to, and in 29 | particular the designs of glyphs or characters in the Fonts may be 30 | modified and additional glyphs or characters may be added to the 31 | Fonts, only if the fonts are renamed to names not containing either 32 | the words "Bitstream" or the word "Vera". 33 | 34 | This License becomes null and void to the extent applicable to Fonts 35 | or Font Software that has been modified and is distributed under the 36 | "Bitstream Vera" names. 37 | 38 | The Font Software may be sold as part of a larger software package but 39 | no copy of one or more of the Font Software typefaces may be sold by 40 | itself. 41 | 42 | THE FONT SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 43 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO ANY WARRANTIES OF 44 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT 45 | OF COPYRIGHT, PATENT, TRADEMARK, OR OTHER RIGHT. IN NO EVENT SHALL 46 | BITSTREAM OR THE GNOME FOUNDATION BE LIABLE FOR ANY CLAIM, DAMAGES OR 47 | OTHER LIABILITY, INCLUDING ANY GENERAL, SPECIAL, INDIRECT, INCIDENTAL, 48 | OR CONSEQUENTIAL DAMAGES, WHETHER IN AN ACTION OF CONTRACT, TORT OR 49 | OTHERWISE, ARISING FROM, OUT OF THE USE OR INABILITY TO USE THE FONT 50 | SOFTWARE OR FROM OTHER DEALINGS IN THE FONT SOFTWARE. 51 | 52 | Except as contained in this notice, the names of Gnome, the Gnome 53 | Foundation, and Bitstream Inc., shall not be used in advertising or 54 | otherwise to promote the sale, use or other dealings in this Font 55 | Software without prior written authorization from the Gnome Foundation 56 | or Bitstream Inc., respectively. For further information, contact: 57 | fonts at gnome dot org. 58 | 59 | Copyright FAQ 60 | ============= 61 | 62 | 1. I don't understand the resale restriction... What gives? 63 | 64 | Bitstream is giving away these fonts, but wishes to ensure its 65 | competitors can't just drop the fonts as is into a font sale system 66 | and sell them as is. It seems fair that if Bitstream can't make money 67 | from the Bitstream Vera fonts, their competitors should not be able to 68 | do so either. You can sell the fonts as part of any software package, 69 | however. 70 | 71 | 2. I want to package these fonts separately for distribution and 72 | sale as part of a larger software package or system. Can I do so? 73 | 74 | Yes. A RPM or Debian package is a "larger software package" to begin 75 | with, and you aren't selling them independently by themselves. 76 | See 1. above. 77 | 78 | 3. Are derivative works allowed? 79 | Yes! 80 | 81 | 4. Can I change or add to the font(s)? 82 | Yes, but you must change the name(s) of the font(s). 83 | 84 | 5. Under what terms are derivative works allowed? 85 | 86 | You must change the name(s) of the fonts. This is to ensure the 87 | quality of the fonts, both to protect Bitstream and Gnome. We want to 88 | ensure that if an application has opened a font specifically of these 89 | names, it gets what it expects (though of course, using fontconfig, 90 | substitutions could still could have occurred during font 91 | opening). You must include the Bitstream copyright. Additional 92 | copyrights can be added, as per copyright law. Happy Font Hacking! 93 | 94 | 6. If I have improvements for Bitstream Vera, is it possible they might get 95 | adopted in future versions? 96 | 97 | Yes. The contract between the Gnome Foundation and Bitstream has 98 | provisions for working with Bitstream to ensure quality additions to 99 | the Bitstream Vera font family. Please contact us if you have such 100 | additions. Note, that in general, we will want such additions for the 101 | entire family, not just a single font, and that you'll have to keep 102 | both Gnome and Jim Lyles, Vera's designer, happy! To make sense to add 103 | glyphs to the font, they must be stylistically in keeping with Vera's 104 | design. Vera cannot become a "ransom note" font. Jim Lyles will be 105 | providing a document describing the design elements used in Vera, as a 106 | guide and aid for people interested in contributing to Vera. 107 | 108 | 7. I want to sell a software package that uses these fonts: Can I do so? 109 | 110 | Sure. Bundle the fonts with your software and sell your software 111 | with the fonts. That is the intent of the copyright. 112 | 113 | 8. If applications have built the names "Bitstream Vera" into them, 114 | can I override this somehow to use fonts of my choosing? 115 | 116 | This depends on exact details of the software. Most open source 117 | systems and software (e.g., Gnome, KDE, etc.) are now converting to 118 | use fontconfig (see www.fontconfig.org) to handle font configuration, 119 | selection and substitution; it has provisions for overriding font 120 | names and subsituting alternatives. An example is provided by the 121 | supplied local.conf file, which chooses the family Bitstream Vera for 122 | "sans", "serif" and "monospace". Other software (e.g., the XFree86 123 | core server) has other mechanisms for font substitution. 124 | 125 | -------------------------------------------------------------------------------- /demos/assets/ttf-bitstream-vera-1.10/README.TXT: -------------------------------------------------------------------------------- 1 | Contained herin is the Bitstream Vera font family. 2 | 3 | The Copyright information is found in the COPYRIGHT.TXT file (along 4 | with being incoporated into the fonts themselves). 5 | 6 | The releases notes are found in the file "RELEASENOTES.TXT". 7 | 8 | We hope you enjoy Vera! 9 | 10 | Bitstream, Inc. 11 | The Gnome Project 12 | -------------------------------------------------------------------------------- /demos/assets/ttf-bitstream-vera-1.10/RELEASENOTES.TXT: -------------------------------------------------------------------------------- 1 | Bitstream Vera Fonts - April 16, 2003 2 | ===================================== 3 | 4 | The version number of these fonts is 1.10 to distinguish them from the 5 | beta test fonts. 6 | 7 | Note that the Vera copyright is incorporated in the fonts themselves. 8 | The License field in the fonts contains the copyright license as it 9 | appears below. The TrueType copyright field is not large enough to 10 | contain the full license, so the license is incorporated (as you might 11 | think if you thought about it) into the license field, which 12 | unfortunately can be obscure to find. (In pfaedit, see: Element->Font 13 | Info->TTFNames->License). 14 | 15 | Our apologies for it taking longer to complete the fonts than planned. 16 | Beta testers requested a tighter line spacing (less leading) and Jim 17 | Lyles redesigned Vera's accents to bring its line spacing to more 18 | typical of other fonts. This took additional time and effort. Our 19 | thanks to Jim for this effort above and beyond the call of duty. 20 | 21 | There are four monospace and sans faces (normal, oblique, bold, bold 22 | oblique) and two serif faces (normal and bold). Fontconfig/Xft2 (see 23 | www.fontconfig.org) can artificially oblique the serif faces for you: 24 | this loses hinting and distorts the faces slightly, but is visibly 25 | different than normal and bold, and reasonably pleasing. 26 | 27 | On systems with fontconfig 2.0 or 2.1 installed, making your sans, 28 | serif and monospace fonts default to these fonts is very easy. Just 29 | drop the file local.conf into your /etc/fonts directory. This will 30 | make the Bitstream fonts your default fonts for all applications using 31 | fontconfig (if sans, serif, or monospace names are used, as they often 32 | are as default values in many desktops). The XML in local.conf may 33 | need modification to enable subpixel decimation, if appropriate, 34 | however, the commented out phrase does so for XFree86 4.3, in the case 35 | that the server does not have sufficient information to identify the 36 | use of a flat panel. Fontconfig 2.2 adds Vera to the list of font 37 | families and will, by default use it as the default sans, serif and 38 | monospace fonts. 39 | 40 | During the testing of the final Vera fonts, we learned that screen 41 | fonts in general are only typically hinted to work correctly at 42 | integer pixel sizes. Vera is coded internally for integer sizes only. 43 | We need to investigate further to see if there are commonly used fonts 44 | that are hinted to be rounded but are not rounded to integer sizes due 45 | to oversights in their coding. 46 | 47 | Most fonts work best at 8 pixels and below if anti-aliased only, as 48 | the amount of work required to hint well at smaller and smaller sizes 49 | becomes astronomical. GASP tables are typically used to control 50 | whether hinting is used or not, but Freetype/Xft does not currently 51 | support GASP tables (which are present in Vera). 52 | 53 | To mitigate this problem, both for Vera and other fonts, there will be 54 | (very shortly) a new fontconfig 2.2 release that will, by default not 55 | apply hints if the size is below 8 pixels. if you should have a font 56 | that in fact has been hinted more agressively, you can use fontconfig 57 | to note this exception. We believe this should improve many hinted 58 | fonts in addition to Vera, though implemeting GASP support is likely 59 | the right long term solution. 60 | 61 | Font rendering in Gnome or KDE is the combination of algorithms in 62 | Xft2 and Freetype, along with hinting in the fonts themselves. It is 63 | vital to have sufficient information to disentangle problems that you 64 | may observe. 65 | 66 | Note that having your font rendering system set up correctly is vital 67 | to proper judgement of problems of the fonts: 68 | 69 | * Freetype may or may not be configured to in ways that may 70 | implement execution of possibly patented (in some parts of the world) 71 | TrueType hinting algorithms, particularly at small sizes. Best 72 | results are obtained while using these algorithms. 73 | 74 | * The freetype autohinter (used when the possibly patented 75 | algorithms are not used) continues to improve with each release. If 76 | you are using the autohinter, please ensure you are using an up to 77 | date version of freetype before reporting problems. 78 | 79 | * Please identify what version of freetype you are using in any 80 | bug reports, and how your freetype is configured. 81 | 82 | * Make sure you are not using the freetype version included in 83 | XFree86 4.3, as it has bugs that significantly degrade most fonts, 84 | including Vera. if you build XFree86 4.3 from source yourself, you may 85 | have installed this broken version without intending it (as I 86 | did). Vera was verified with the recently released Freetype 2.1.4. On 87 | many systems, 'ldd" can be used to see which freetype shared library 88 | is actually being used. 89 | 90 | * Xft/X Render does not (yet) implement gamma correction. This 91 | causes significant problems rendering white text on a black background 92 | (causing partial pixels to be insufficiently shaded) if the gamma of 93 | your monitor has not been compensated for, and minor problems with 94 | black text on a while background. The program "xgamma" can be used to 95 | set a gamma correction value in the X server's color pallette. Most 96 | monitors have a gamma near 2. 97 | 98 | * Note that the Vera family uses minimal delta hinting. Your 99 | results on other systems when not used anti-aliased may not be 100 | entirely satisfying. We are primarily interested in reports of 101 | problems on open source systems implementing Xft2/fontconfig/freetype 102 | (which implements antialiasing and hinting adjustements, and 103 | sophisticated subpixel decimation on flatpanels). Also, the 104 | algorithms used by Xft2 adjust the hints to integer widths and the 105 | results are crisper on open source systems than on Windows or 106 | MacIntosh. 107 | 108 | * Your fontconfig may (probably does) predate the release of 109 | fontconfig 2.2, and you may see artifacts not present when the font is 110 | used at very small sizes with hinting enabled. "vc-list -V" can be 111 | used to see what version you have installed. 112 | 113 | We believe and hope that these fonts will resolve the problems 114 | reported during beta test. The largest change is the reduction of 115 | leading (interline spacing), which had annoyed a number of people, and 116 | reduced Vera's utility for some applcations. The Vera monospace font 117 | should also now make '0' and 'O' and '1' and 'l' more clearly 118 | distinguishable. 119 | 120 | The version of these fonts is version 1.10. Fontconfig should be 121 | choosing the new version of the fonts if both the released fonts and 122 | beta test fonts are installed (though please discard them: they have 123 | names of form tt20[1-12]gn.ttf). Note that older versions of 124 | fontconfig sometimes did not rebuild their cache correctly when new 125 | fonts are installed: please upgrade to fontconfig 2.2. "fc-cache -f" 126 | can be used to force rebuilding fontconfig's cache files. 127 | 128 | If you note problems, please send them to fonts at gnome dot org, with 129 | exactly which face and size and unicode point you observe the problem 130 | at. The xfd utility from XFree86 CVS may be useful for this (e.g. "xfd 131 | -fa sans"). A possibly more useful program to examine fonts at a 132 | variety of sizes is the "waterfall" program found in Keith Packard's 133 | CVS. 134 | 135 | $ cvs -d :pserver:anoncvs@keithp.com:/local/src/CVS login 136 | Logging in to :pserver:anoncvs@keithp.com:2401/local/src/CVS 137 | CVS password: 138 | $ cvs -d :pserver:anoncvs@keithp.com:/local/src/CVS co waterfall 139 | $ cd waterfall 140 | $ xmkmf -a 141 | $ make 142 | # make install 143 | # make install.man 144 | 145 | Again, please make sure you are running an up-to-date freetype, and 146 | that you are only examining integer sizes. 147 | 148 | Reporting Problems 149 | ================== 150 | 151 | Please send problem reports to fonts at gnome org, with the following 152 | information: 153 | 154 | 1. Version of Freetype, Xft2 and fontconfig 155 | 2. Whether TT hinting is being used, or the autohinter 156 | 3. Application being used 157 | 4. Character/Unicode code point that has problems (if applicable) 158 | 5. Version of which operating system 159 | 6. Please include a screenshot, when possible. 160 | 161 | Please check the fonts list archives before reporting problems to cut 162 | down on duplication. 163 | -------------------------------------------------------------------------------- /demos/assets/ttf-bitstream-vera-1.10/Vera.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SFML-haskell/SFML/1d1ceee6bc782f4f194853fbd0cc4acb33b86d41/demos/assets/ttf-bitstream-vera-1.10/Vera.ttf -------------------------------------------------------------------------------- /demos/assets/ttf-bitstream-vera-1.10/local.conf: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 13 | 14 | 15 | serif 16 | 17 | Bitstream Vera Serif 18 | 19 | 20 | 21 | sans-serif 22 | 23 | Bitstream Vera Sans 24 | 25 | 26 | 27 | monospace 28 | 29 | Bitstream Vera Sans Mono 30 | 31 | 32 | 33 | -------------------------------------------------------------------------------- /demos/events/main.hs: -------------------------------------------------------------------------------- 1 | import SFML.Audio 2 | import SFML.Graphics 3 | import SFML.Window 4 | 5 | import Foreign.Ptr (nullPtr) 6 | import Paths_sfml_demos 7 | 8 | 9 | txtSize = 24 10 | 11 | 12 | data DemoState = DemoState 13 | { xmouse :: Int 14 | , ymouse :: Int 15 | , key :: String 16 | } 17 | 18 | 19 | main = do 20 | let ctxSettings = Just $ ContextSettings 24 8 0 1 2 [ContextDefault] 21 | wnd <- createRenderWindow (VideoMode 640 480 32) "SFML Haskell Demo" [SFDefaultStyle] ctxSettings 22 | fontPath <- getDataFileName "Vera.ttf" 23 | fnt <- err $ fontFromFile fontPath 24 | txt <- err $ createText 25 | setTextFont txt fnt 26 | setTextCharacterSize txt txtSize 27 | setTextColor txt blue 28 | let ds = DemoState 0 0 "" 29 | loop wnd txt ds 30 | destroy txt 31 | destroy fnt 32 | destroy wnd 33 | 34 | 35 | loop :: RenderWindow -> Text -> DemoState -> IO () 36 | loop wnd txt ds = do 37 | ret <- processEvt wnd ds 38 | case ret of 39 | Nothing -> return () 40 | Just ds' -> do 41 | clearRenderWindow wnd $ Color 240 240 240 255 42 | setTextString txt $ "Mouse: " ++ show (xmouse ds') ++ ", " ++ show (ymouse ds') 43 | drawText wnd txt Nothing 44 | setTextString txt $ "Keyboard: " ++ key ds' 45 | let rs = renderStates { transform = (translation 0 $ 2 * fromIntegral txtSize) } 46 | drawText wnd txt $ Just rs 47 | display wnd 48 | loop wnd txt ds' 49 | 50 | 51 | processEvt :: RenderWindow -> DemoState -> IO (Maybe DemoState) 52 | processEvt wnd ds = do 53 | evt <- pollEvent wnd 54 | case evt of 55 | Just SFEvtClosed -> return Nothing 56 | Just (SFEvtMouseMoved x y) -> processEvt wnd $ ds { xmouse = x, ymouse = y } 57 | Just e@SFEvtKeyPressed{} -> processEvt wnd $ ds { key = show . code $ e } 58 | Nothing -> return . Just $ ds 59 | _ -> processEvt wnd ds 60 | -------------------------------------------------------------------------------- /demos/fingerpaint/main.hs: -------------------------------------------------------------------------------- 1 | import SFML.Graphics 2 | import SFML.Window 3 | 4 | 5 | colors :: [Color] 6 | colors = [red, blue, green, magenta, cyan, yellow] 7 | 8 | nColors :: Int 9 | nColors = length colors 10 | 11 | 12 | main = do 13 | vMode <- getDesktopMode 14 | wnd <- createRenderWindow vMode "SFML Haskell Demo" [SFFullscreen] Nothing 15 | va <- createVA 16 | setPrimitiveType va Triangles 17 | loop wnd va 18 | destroy va 19 | destroy wnd 20 | 21 | 22 | loop :: RenderWindow -> VertexArray -> IO () 23 | loop wnd va = do 24 | ret <- processEvt wnd va 25 | case ret of 26 | False -> return () 27 | True -> do 28 | clearRenderWindow wnd black 29 | drawVertexArray wnd va Nothing 30 | display wnd 31 | loop wnd va 32 | 33 | 34 | appendVertex :: VertexArray -> Int -> Int -> Int -> IO () 35 | appendVertex va f x y = do 36 | let color = colors !! (f `mod` nColors) 37 | x1 = fromIntegral $ x - 10 38 | x2 = fromIntegral $ x + 10 39 | y1 = fromIntegral $ y - 10 40 | y2 = fromIntegral $ y + 10 41 | corners = [ Vec2f x1 y1, Vec2f x1 y2, Vec2f x2 y2, 42 | Vec2f x1 y1, Vec2f x2 y2, Vec2f x2 y1 ] 43 | vtx v = Vertex v color v 44 | vertices = map vtx corners 45 | mapM_ (appendVA va) vertices 46 | 47 | 48 | processEvt :: RenderWindow -> VertexArray -> IO Bool 49 | processEvt wnd va = do 50 | evt <- pollEvent wnd 51 | case evt of 52 | Just SFEvtClosed -> return False 53 | Just (SFEvtKeyPressed {code = KeyEscape}) -> return False 54 | Just (SFEvtTouchBegan f x y) -> appendVertex va f x y >> processEvt wnd va 55 | Just (SFEvtTouchMoved f x y) -> appendVertex va f x y >> processEvt wnd va 56 | Just (SFEvtTouchEnded f x y) -> appendVertex va f x y >> processEvt wnd va 57 | Nothing -> return True 58 | _ -> processEvt wnd va 59 | -------------------------------------------------------------------------------- /demos/hello/main.hs: -------------------------------------------------------------------------------- 1 | import SFML.Audio 2 | import SFML.Graphics 3 | import SFML.Window 4 | 5 | import Foreign.Ptr (nullPtr) 6 | 7 | import Paths_sfml_demos 8 | 9 | 10 | main = do 11 | let ctxSettings = Just $ ContextSettings 24 8 0 1 2 [ContextDefault] 12 | wnd <- createRenderWindow (VideoMode 640 480 32) "SFML Haskell Demo" [SFDefaultStyle] ctxSettings 13 | logoPath <- getDataFileName "Haskell-Logo.png" 14 | fontPath <- getDataFileName "Vera.ttf" 15 | musicPath <- getDataFileName "DST-BreakOut.ogg" 16 | tex <- err $ textureFromFile logoPath Nothing 17 | spr <- err $ createSprite 18 | fnt <- err $ fontFromFile fontPath 19 | txt <- err $ createText 20 | setTextString txt "Haskell SFML\n Version 2.0" 21 | setTextFont txt fnt 22 | setTextCharacterSize txt 20 23 | setTextColor txt blue 24 | msc <- err $ musicFromFile musicPath 25 | play msc 26 | setTexture spr tex True 27 | loop wnd spr txt 28 | destroy msc 29 | destroy txt 30 | destroy fnt 31 | destroy spr 32 | destroy tex 33 | destroy wnd 34 | 35 | 36 | loop :: RenderWindow -> Sprite -> Text -> IO () 37 | loop wnd spr txt = do 38 | drawSprite wnd spr Nothing 39 | drawText wnd txt $ Just (renderStates { transform = translation 460 40 }) 40 | display wnd 41 | evt <- waitEvent wnd 42 | case evt of 43 | Nothing -> return () 44 | Just SFEvtClosed -> return () 45 | _ -> loop wnd spr txt 46 | -------------------------------------------------------------------------------- /demos/sfml-demos.cabal: -------------------------------------------------------------------------------- 1 | name: sfml-demos 2 | version: 0.1.0.0 3 | cabal-version: >=1.8 4 | build-type: Simple 5 | license: MIT 6 | license-file: "LICENSE" 7 | synopsis: SFML demos 8 | category: Game 9 | author: Marc Sunet 10 | data-dir: assets 11 | data-files: DST-BreakOut.ogg, Haskell-Logo.png, Vera.ttf 12 | 13 | executable sfml-window 14 | hs-source-dirs: window 15 | build-depends: base, SFML 16 | main-is: main.hs 17 | buildable: True 18 | ghc-options: -debug 19 | 20 | executable sfml-time 21 | hs-source-dirs: time 22 | build-depends: base, SFML 23 | main-is: main.hs 24 | buildable: True 25 | ghc-options: -debug 26 | 27 | executable sfml-transform 28 | hs-source-dirs: transform 29 | build-depends: base, SFML 30 | main-is: main.hs 31 | buildable: True 32 | ghc-options: -debug 33 | 34 | executable sfml-hello 35 | hs-source-dirs: hello 36 | build-depends: base, SFML 37 | main-is: main.hs 38 | other-modules: Paths_sfml_demos 39 | buildable: True 40 | ghc-options: -debug 41 | 42 | executable sfml-events 43 | hs-source-dirs: events 44 | build-depends: base, SFML 45 | main-is: main.hs 46 | other-modules: Paths_sfml_demos 47 | buildable: True 48 | ghc-options: -debug 49 | 50 | executable sfml-unicode 51 | hs-source-dirs: unicode 52 | build-depends: base, SFML 53 | main-is: main.hs 54 | other-modules: Paths_sfml_demos 55 | buildable: True 56 | ghc-options: -debug 57 | 58 | executable sfml-fingerpaint 59 | hs-source-dirs: fingerpaint 60 | build-depends: base, SFML 61 | main-is: main.hs 62 | buildable: True 63 | ghc-options: -debug 64 | -------------------------------------------------------------------------------- /demos/time/main.hs: -------------------------------------------------------------------------------- 1 | import SFML.System 2 | 3 | 4 | main = do 5 | clock <- createClock 6 | loop clock 3 7 | destroy clock 8 | 9 | 10 | loop clock 0 = return () 11 | loop clock n = do 12 | sfSleep $ seconds 0.150 13 | time <- getElapsedTime clock 14 | if asSeconds time >= 1 15 | then putStrLn "tick" >> restartClock clock >> loop clock (n-1) 16 | else loop clock n 17 | 18 | -------------------------------------------------------------------------------- /demos/time/test.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #include 4 | 5 | 6 | int main (void) 7 | { 8 | sfClock* clock = sfClock_create (); 9 | 10 | int i = 2; 11 | while (i >= 0) 12 | { 13 | sfTime t = sfClock_getElapsedTime (clock); 14 | if (sfTime_asSeconds (t) >= 1.0f) 15 | { 16 | printf ("tick\n"); 17 | sfClock_restart (clock); 18 | i--; 19 | } 20 | } 21 | 22 | sfClock_destroy (clock); 23 | return 0; 24 | } 25 | 26 | -------------------------------------------------------------------------------- /demos/transform/main.hs: -------------------------------------------------------------------------------- 1 | import SFML.Graphics.Transform 2 | 3 | 4 | main = do 5 | let 6 | t = translation 10 10 7 | r = rotation 45 8 | s = scaling 2 4 9 | 10 | printmat' "Translation:" t 11 | printmat' "Rotation:" r 12 | printmat' "Scale:" s 13 | 14 | let 15 | t0 = t * r 16 | i = inverse t0 17 | fi = fastInverse t0 18 | i0 = t0 * i 19 | i1 = t0 * fi 20 | 21 | printmat' "Transform:" t0 22 | printmat' "Inverse:" i 23 | printmat' "Fast inverse:" fi 24 | printmat' "Transform * Inverse:" i0 25 | printmat' "Transform * Fast Inverse:" i1 26 | 27 | 28 | printmat' title t = do 29 | putStrLn title 30 | putStrLn "" 31 | printmat t 32 | putStrLn "" 33 | 34 | 35 | printmat t = 36 | let 37 | f = 0.00001 38 | m00' = if (abs $ m00 t) < f then 0 else m00 t 39 | m01' = if (abs $ m01 t) < f then 0 else m01 t 40 | m02' = if (abs $ m02 t) < f then 0 else m02 t 41 | m10' = if (abs $ m10 t) < f then 0 else m10 t 42 | m11' = if (abs $ m11 t) < f then 0 else m11 t 43 | m12' = if (abs $ m12 t) < f then 0 else m12 t 44 | m20' = if (abs $ m20 t) < f then 0 else m20 t 45 | m21' = if (abs $ m21 t) < f then 0 else m21 t 46 | m22' = if (abs $ m22 t) < f then 0 else m22 t 47 | in do 48 | putStrLn $ show m00' ++ "\t" ++ show m10' ++ "\t" ++ show m20' 49 | putStrLn $ show m01' ++ "\t" ++ show m11' ++ "\t" ++ show m21' 50 | putStrLn $ show m02' ++ "\t" ++ show m12' ++ "\t" ++ show m22' 51 | 52 | -------------------------------------------------------------------------------- /demos/unicode/main.hs: -------------------------------------------------------------------------------- 1 | import SFML.Graphics 2 | import SFML.Window 3 | 4 | import Paths_sfml_demos 5 | 6 | 7 | txtSize = 24 8 | angry = "è_é" 9 | 10 | 11 | main = do 12 | let ctxSettings = Just $ ContextSettings 24 8 0 1 2 [ContextDefault] 13 | wnd <- createRenderWindow (VideoMode 40 32 32) "SFML Haskell Demo" [SFDefaultStyle] ctxSettings 14 | fontPath <- getDataFileName "Vera.ttf" 15 | fnt <- err $ fontFromFile fontPath 16 | txt <- err $ createText 17 | setTextFont txt fnt 18 | setTextCharacterSize txt txtSize 19 | setTextColor txt blue 20 | setTextStringU txt angry 21 | loop wnd txt 22 | destroy txt 23 | destroy fnt 24 | destroy wnd 25 | 26 | 27 | loop :: RenderWindow -> Text -> IO () 28 | loop wnd txt = do 29 | evt <- waitEvent wnd 30 | case evt of 31 | Nothing -> return () 32 | Just SFEvtClosed -> return () 33 | Just _ -> do 34 | clearRenderWindow wnd $ Color 240 240 240 255 35 | drawText wnd txt Nothing 36 | display wnd 37 | loop wnd txt 38 | -------------------------------------------------------------------------------- /demos/window/main.hs: -------------------------------------------------------------------------------- 1 | import SFML.Window 2 | 3 | 4 | main = do 5 | desktopMode <- getDesktopMode 6 | fsModes <- getFullscreenModes 7 | 8 | putStrLn $ "Current desktop mode:\n\n" ++ show desktopMode 9 | putStrLn "" 10 | putStrLn $ "Fullscreen modes:" 11 | putStrLn "" 12 | mapM_ (\m -> putStrLn (show m) >> putStrLn "") fsModes 13 | 14 | let ctxSettings = Just $ ContextSettings 24 8 0 1 2 [ContextDefault] 15 | wnd <- createWindow (VideoMode 640 480 32) "SFML Haskell Demo" [SFDefaultStyle] ctxSettings 16 | loop wnd 17 | destroy wnd 18 | 19 | 20 | loop :: Window -> IO () 21 | loop wnd = do 22 | evt <- waitEvent wnd 23 | case evt of 24 | Just SFEvtClosed -> return () 25 | _ -> loop wnd 26 | 27 | -------------------------------------------------------------------------------- /src/SFML/Audio.hs: -------------------------------------------------------------------------------- 1 | module SFML.Audio 2 | ( 3 | module SFML.Audio.Listener 4 | , module SFML.Audio.Music 5 | , module SFML.Audio.SFSampled 6 | , module SFML.Audio.SFSound 7 | , module SFML.Audio.SFSoundRecorder 8 | , module SFML.Audio.Sound 9 | , module SFML.Audio.SoundBuffer 10 | , module SFML.Audio.SoundBufferRecorder 11 | , module SFML.Audio.SoundRecorder 12 | , module SFML.Audio.SoundStatus 13 | , module SFML.Audio.SoundStream 14 | , module SFML.Audio.Types 15 | ) 16 | where 17 | 18 | 19 | import SFML.Audio.Listener 20 | import SFML.Audio.Music 21 | import SFML.Audio.SFSampled 22 | import SFML.Audio.SFSound 23 | import SFML.Audio.SFSoundRecorder 24 | import SFML.Audio.Sound 25 | import SFML.Audio.SoundBuffer 26 | import SFML.Audio.SoundBufferRecorder 27 | import SFML.Audio.SoundRecorder 28 | import SFML.Audio.SoundStatus 29 | import SFML.Audio.SoundStream 30 | import SFML.Audio.Types 31 | 32 | -------------------------------------------------------------------------------- /src/SFML/Audio/Listener.hs: -------------------------------------------------------------------------------- 1 | module SFML.Audio.Listener 2 | ( 3 | setGlobalVolume 4 | , getGlobalVolume 5 | , setListenerPosition 6 | , getListenerPosition 7 | , setListenerDirection 8 | , getListenerDirection 9 | , setListenerUpVector 10 | , getListenerUpVector 11 | ) 12 | where 13 | 14 | 15 | import SFML.System.Vector3 16 | 17 | import Control.Monad ((>=>)) 18 | import Foreign.C.Types 19 | import Foreign.Marshal.Alloc (alloca) 20 | import Foreign.Marshal.Utils (with) 21 | import Foreign.Ptr (Ptr) 22 | import Foreign.Storable (peek) 23 | 24 | 25 | -- | Change the global volume of all the sounds and musics. 26 | -- 27 | -- The volume is a number between 0 and 100; it is combined with 28 | -- the individual volume of each sound or music. 29 | -- 30 | -- The default value for the volume is 100 (maximum). 31 | setGlobalVolume 32 | :: Float -- ^ New global volume, in the range [0, 100] 33 | -> IO () 34 | 35 | setGlobalVolume = sfListener_setGlobalVolume . realToFrac 36 | 37 | foreign import ccall unsafe "sfListener_setGlobalVolume" 38 | sfListener_setGlobalVolume :: CFloat -> IO () 39 | 40 | --CSFML_AUDIO_API void sfListener_setGlobalVolume(float volume); 41 | 42 | 43 | -- | Get the current value of the global volume. 44 | getGlobalVolume :: IO Float -- ^ Current global volume, in the range [0, 100] 45 | getGlobalVolume = fmap realToFrac sfListener_getGlobalVolume 46 | 47 | foreign import ccall unsafe "sfListener_getGlobalVolume" 48 | sfListener_getGlobalVolume :: IO CFloat 49 | 50 | --CSFML_AUDIO_API float sfListener_getGlobalVolume(void); 51 | 52 | 53 | -- | Set the position of the listener in the scene. 54 | -- 55 | -- The default listener's position is (0, 0, 0). 56 | setListenerPosition :: Vec3f -> IO () 57 | setListenerPosition pos = with pos sfListener_setPosition_helper 58 | 59 | foreign import ccall unsafe "sfListener_setPosition_helper" 60 | sfListener_setPosition_helper :: Ptr Vec3f -> IO () 61 | 62 | --CSFML_AUDIO_API void sfListener_setPosition(sfVector3f position); 63 | 64 | 65 | -- | Get the current position of the listener in the scene. 66 | getListenerPosition :: IO Vec3f 67 | getListenerPosition = alloca $ \ptr -> sfListener_getPosition_helper ptr >> peek ptr 68 | 69 | foreign import ccall unsafe "sfListener_getPosition_helper" 70 | sfListener_getPosition_helper :: Ptr Vec3f -> IO () 71 | 72 | --CSFML_AUDIO_API sfVector3f sfListener_getPosition(); 73 | 74 | 75 | -- | Set the orientation of the forward vector in the scene. 76 | -- 77 | -- The direction (also called "at vector") is the vector 78 | -- pointing forward from the listener's perspective. Together 79 | -- with the up vector, it defines the 3D orientation of the 80 | -- listener in the scene. The direction vector doesn't 81 | -- have to be normalized. 82 | -- 83 | -- The default listener's direction is (0, 0, -1). 84 | setListenerDirection :: Vec3f -> IO () 85 | setListenerDirection dir = with dir sfListener_setDirection_helper 86 | 87 | foreign import ccall unsafe "sfListener_setDirection_helper" 88 | sfListener_setDirection_helper :: Ptr Vec3f -> IO () 89 | 90 | --CSFML_AUDIO_API void sfListener_setDirection(sfVector3f orientation); 91 | 92 | 93 | -- | Get the current orientation of the listener in the scene. 94 | getListenerDirection :: IO Vec3f 95 | getListenerDirection = alloca $ \ptr -> sfListener_getDirection_helper ptr >> peek ptr 96 | 97 | foreign import ccall unsafe "sfListener_getDirection_helper" 98 | sfListener_getDirection_helper :: Ptr Vec3f -> IO () 99 | 100 | --CSFML_AUDIO_API sfVector3f sfListener_getDirection(); 101 | 102 | 103 | -- | Set the upward vector of the listener in the scene 104 | -- 105 | -- The up vector is the vector that points upward from the 106 | -- listener's perspective. Together with the direction, it 107 | -- defines the 3D orientation of the listener in the scene. 108 | -- The up vector doesn't have to be normalized. 109 | -- The default listener's up vector is (0, 1, 0). It is usually 110 | -- not necessary to change it, especially in 2D scenarios. 111 | setListenerUpVector :: Vec3f -> IO () 112 | setListenerUpVector dir = with dir sfListener_setUpVector_helper 113 | 114 | foreign import ccall unsafe "sfListener_setUpVector_helper" 115 | sfListener_setUpVector_helper :: Ptr Vec3f -> IO () 116 | 117 | --CSFML_AUDIO_API void sfListener_setUpVector(sfVector3f upVector); 118 | 119 | 120 | -- | Get the current upward vector (unnormalised) of the listener in the scene. 121 | getListenerUpVector :: IO Vec3f 122 | getListenerUpVector = alloca $ \ptr -> sfListener_getUpVector_helper ptr >> peek ptr 123 | 124 | foreign import ccall unsafe "sfListener_getUpVector_helper" 125 | sfListener_getUpVector_helper :: Ptr Vec3f -> IO () 126 | 127 | --CSFML_AUDIO_API sfVector3f sfListener_getUpVector(); 128 | -------------------------------------------------------------------------------- /src/SFML/Audio/SFSampled.hs: -------------------------------------------------------------------------------- 1 | module SFML.Audio.SFSampled 2 | where 3 | 4 | 5 | class SFSampled a where 6 | 7 | -- | Get the sample rate of a sound buffer. 8 | -- 9 | -- The sample rate is the number of samples played per second. 10 | -- The higher, the better the quality (for example, 44100 11 | -- samples/s is CD quality). 12 | getSampleRate :: a -> IO Int 13 | 14 | -------------------------------------------------------------------------------- /src/SFML/Audio/SFSound.hs: -------------------------------------------------------------------------------- 1 | module SFML.Audio.SFSound 2 | where 3 | 4 | 5 | import SFML.Audio.SoundStatus 6 | import SFML.System.Time 7 | import SFML.System.Vector3 8 | 9 | 10 | class SFSound a where 11 | 12 | -- | Start or resume playing a sound. 13 | -- 14 | -- This function starts the sound if it was stopped, resumes 15 | -- it if it was paused, and restarts it from beginning if it 16 | -- was it already playing. 17 | -- 18 | -- This function uses its own thread so that it doesn't block 19 | -- the rest of the program while the sound is played. 20 | play :: a -> IO () 21 | 22 | -- | Pause a sound. 23 | -- 24 | -- This function pauses the sound if it was playing, 25 | -- otherwise (sound already paused or stopped) it has no effect. 26 | pause :: a -> IO () 27 | 28 | -- | Stop playing a sound. 29 | -- 30 | -- This function stops the sound if it was playing or paused, 31 | -- and does nothing if it was already stopped. 32 | -- 33 | -- It also resets the playing position (unlike 'pause'). 34 | stop :: a -> IO () 35 | 36 | -- | Get the attenuation factor of a sound. 37 | getAttenuation :: a -> IO Float 38 | 39 | -- | Tell whether or not a sound is in loop mode. 40 | getLoop :: a -> IO Bool 41 | 42 | -- | Get the minimum distance of a sound. 43 | getMinDistance :: a -> IO Float 44 | 45 | -- | Get the pitch of a sound. 46 | getPitch :: a -> IO Float 47 | 48 | -- | Get the current playing position of a sound. 49 | getPlayingOffset :: a -> IO Time 50 | 51 | -- | Get the 3D position of a sound in the audio scene. 52 | getPosition :: a -> IO Vec3f 53 | 54 | -- | Get the current status of a sound (stopped, paused, playing). 55 | getStatus :: a -> IO SoundStatus 56 | 57 | -- | Get the volume of a sound. 58 | getVolume :: a -> IO Float 59 | 60 | -- | Tell whether a sound's position is relative to the listener or is absolute. 61 | isRelativeToListener :: a -> IO Bool 62 | 63 | -- | Set the attenuation factor of a sound. 64 | -- 65 | -- The attenuation is a multiplicative factor which makes 66 | -- the sound more or less loud according to its distance 67 | -- from the listener. An attenuation of 0 will produce a 68 | -- non-attenuated sound, i.e. its volume will always be the same 69 | -- whether it is heard from near or from far. On the other hand, 70 | -- an attenuation value such as 100 will make the sound fade out 71 | -- very quickly as it gets further from the listener. 72 | -- 73 | -- The default value of the attenuation is 1. 74 | setAttenuation :: a -> Float -> IO () 75 | 76 | -- | Set whether or not a sound should loop after reaching the end. 77 | -- 78 | -- If set, the sound will restart from beginning after 79 | -- reaching the end and so on, until it is stopped or 80 | -- 'setLoop' 'False' is called. 81 | -- 82 | -- The default looping state for sounds is false. 83 | setLoop :: a -> Bool -> IO () 84 | 85 | -- | Set the minimum distance of a sound. 86 | -- 87 | -- The minimum distance of a sound is the maximum 88 | -- distance at which it is heard at its maximum volume. Further 89 | -- than the minimum distance, it will start to fade out according 90 | -- to its attenuation factor. A value of 0 (inside the head 91 | -- of the listener) is an invalid value and is forbidden. 92 | -- 93 | -- The default value of the minimum distance is 1. 94 | setMinDistance :: a -> Float -> IO () 95 | 96 | -- | Set the pitch of a sound. 97 | -- 98 | -- The pitch represents the perceived fundamental frequency 99 | -- of a sound; thus you can make a sound more acute or grave 100 | -- by changing its pitch. A side effect of changing the pitch 101 | -- is to modify the playing speed of the sound as well. 102 | -- 103 | -- The default value for the pitch is 1. 104 | setPitch :: a -> Float -> IO () 105 | 106 | -- | Change the current playing position of a sound. 107 | -- 108 | -- The playing position can be changed when the sound is 109 | -- either paused or playing. 110 | setPlayingOffset :: a -> Time -> IO () 111 | 112 | -- | Set the 3D position of a sound in the audio scene. 113 | -- 114 | -- Only sounds with one channel (mono sounds) can be 115 | -- spatialized. 116 | -- 117 | -- The default position of a sound is (0, 0, 0). 118 | setPosition :: a -> Vec3f -> IO () 119 | 120 | -- | Make the sound's position relative to the listener or absolute. 121 | -- 122 | -- Making a sound relative to the listener will ensure that it will always 123 | -- be played the same way regardless the position of the listener. 124 | -- This can be useful for non-spatialized sounds, sounds that are 125 | -- produced by the listener, or sounds attached to it. 126 | -- 127 | -- The default value is false (position is absolute). 128 | setRelativeToListener :: a -> Bool -> IO () 129 | 130 | -- | Set the volume of a sound. 131 | -- 132 | -- The volume is a value between 0 (mute) and 100 (full volume). 133 | -- 134 | -- The default value for the volume is 100. 135 | setVolume :: a -> Float -> IO () 136 | 137 | -------------------------------------------------------------------------------- /src/SFML/Audio/SFSoundBuffer.hs: -------------------------------------------------------------------------------- 1 | module SFML.Audio.SFSoundBuffer 2 | where 3 | 4 | 5 | import SFML.System.Time (Time) 6 | 7 | 8 | class SFSoundBuffer a where 9 | 10 | -- | Get the number of channels used by a sound buffer. 11 | -- 12 | -- If the sound is mono then the number of channels will 13 | -- be 1, 2 for stereo, etc. 14 | getChannelCount :: a -> IO Int 15 | 16 | -- | Get the total duration of a sound buffer. 17 | getDuration :: a -> IO Time 18 | 19 | -------------------------------------------------------------------------------- /src/SFML/Audio/SFSoundRecorder.hs: -------------------------------------------------------------------------------- 1 | module SFML.Audio.SFSoundRecorder 2 | where 3 | 4 | 5 | class SFSoundRecorder a where 6 | 7 | -- | Start the capture of a sound recorder. 8 | -- 9 | -- The sample rate parameter defines the number of audio samples 10 | -- captured per second. The higher, the better the quality 11 | -- (for example, 44100 samples/sec is CD quality). 12 | -- 13 | -- This function uses its own thread so that it doesn't block 14 | -- the rest of the program while the capture runs. 15 | -- 16 | -- Please note that only one capture can happen at the same time. 17 | -- 18 | -- Return 'True' if start of capture was successful, 'False' otherwise. 19 | startRecording 20 | :: a 21 | -> Int -- ^ Desired capture rate, in number of samples per second 22 | -> IO Bool 23 | 24 | -- | Stop the capture of a sound recorder. 25 | stopRecording :: a -> IO () 26 | 27 | -------------------------------------------------------------------------------- /src/SFML/Audio/SoundBuffer.hs: -------------------------------------------------------------------------------- 1 | module SFML.Audio.SoundBuffer 2 | ( 3 | module SFML.Utils 4 | , soundBufferFromFile 5 | , soundBufferFromMemory 6 | , soundBufferFromStream 7 | , soundBufferFromSamples 8 | , copySoundBuffer 9 | , destroy 10 | , saveSoundBufferToFile 11 | , getSamples 12 | , getSampleCount 13 | , getSampleRate 14 | , getChannelCount 15 | , getDuration 16 | ) 17 | where 18 | 19 | 20 | import SFML.Audio.SFSampled 21 | import SFML.Audio.SFSoundBuffer 22 | import SFML.Audio.Types 23 | import SFML.SFException 24 | import SFML.SFResource 25 | import SFML.System.InputStream 26 | import SFML.System.Time 27 | import SFML.Utils 28 | 29 | import Control.Monad ((>=>)) 30 | import Foreign.C.String 31 | import Foreign.C.Types 32 | import Foreign.Marshal.Alloc (alloca) 33 | import Foreign.Marshal.Utils (with) 34 | import Foreign.Ptr (Ptr, nullPtr) 35 | import Foreign.Storable (peek) 36 | 37 | 38 | checkNull :: SoundBuffer -> Maybe SoundBuffer 39 | checkNull buf@(SoundBuffer ptr) = if ptr == nullPtr then Nothing else Just buf 40 | 41 | 42 | -- | Create a new sound buffer and load it from a file. 43 | -- 44 | -- Here is a complete list of all the supported audio formats: 45 | -- ogg, wav, flac, aiff, au, raw, paf, svx, nist, voc, ircam, 46 | -- w64, mat4, mat5 pvf, htk, sds, avr, sd2, caf, wve, mpc2k, rf64. 47 | soundBufferFromFile :: FilePath -> IO (Either SFException SoundBuffer) 48 | soundBufferFromFile path = 49 | let err = SFException $ "Failed loading sound buffer from file: " ++ show path 50 | in fmap (tagErr err . checkNull) $ withCAString path sfSoundBuffer_createFromFile 51 | 52 | foreign import ccall unsafe "sfSoundBuffer_createFromFile" 53 | sfSoundBuffer_createFromFile :: CString -> IO SoundBuffer 54 | 55 | -- \return A new sfSoundBuffer object (NULL if failed) 56 | 57 | -- CSFML_AUDIO_API sfSoundBuffer* sfSoundBuffer_createFromFile(const char* filename); 58 | 59 | 60 | -- | Create a new sound buffer and load it from a file in memory. 61 | -- 62 | -- Here is a complete list of all the supported audio formats: 63 | -- ogg, wav, flac, aiff, au, raw, paf, svx, nist, voc, ircam, 64 | -- w64, mat4, mat5 pvf, htk, sds, avr, sd2, caf, wve, mpc2k, rf64. 65 | soundBufferFromMemory 66 | :: Ptr a -- ^ Pointer to the file data in memory 67 | -> Int -- ^ Size of the data to load, in bytes 68 | -> IO (Either SFException SoundBuffer) -- ^ A new sfSoundBuffer object ('Nothing' if failed) 69 | 70 | soundBufferFromMemory ptr size = 71 | let err = SFException $ "Failed loading sound buffer from memory address " ++ show ptr 72 | in sfSoundBuffer_createFromMemory ptr (fromIntegral size) >>= return . tagErr err . checkNull 73 | 74 | foreign import ccall unsafe "sfSoundBuffer_createFromMemory" 75 | sfSoundBuffer_createFromMemory :: Ptr a -> CUInt -> IO SoundBuffer 76 | 77 | -- CSFML_AUDIO_API sfSoundBuffer* sfSoundBuffer_createFromMemory(const void* data, size_t sizeInBytes); 78 | 79 | 80 | -- | Create a new sound buffer and load it from a custom stream. 81 | -- 82 | -- Here is a complete list of all the supported audio formats: 83 | -- ogg, wav, flac, aiff, au, raw, paf, svx, nist, voc, ircam, 84 | -- w64, mat4, mat5 pvf, htk, sds, avr, sd2, caf, wve, mpc2k, rf64. 85 | soundBufferFromStream 86 | :: InputStream 87 | -> IO (Either SFException SoundBuffer) -- ^ A new sfSoundBuffer object ('Nothing' if failed) 88 | 89 | soundBufferFromStream is = 90 | let err = SFException $ "Failed loading sound buffer from input stream " ++ show is 91 | in with is sfSoundBuffer_createFromStream >>= return . tagErr err . checkNull 92 | 93 | foreign import ccall unsafe "sfSoundBuffer_createFromStream" 94 | sfSoundBuffer_createFromStream :: Ptr InputStream -> IO SoundBuffer 95 | 96 | -- CSFML_AUDIO_API sfSoundBuffer* sfSoundBuffer_createFromStream(sfInputStream* stream); 97 | 98 | 99 | -- | Create a new sound buffer and load it from an array of samples in memory. 100 | -- 101 | -- The assumed format of the audio samples is 16 bits signed integer 102 | -- (sfInt16). 103 | soundBufferFromSamples 104 | :: Ptr a -- ^ Pointer to the array of samples in memory 105 | -> Int -- ^ Number of samples in the array 106 | -> Int -- ^ Number of channels (1 = mono, 2 = stereo, ...) 107 | -> Int -- ^ Sample rate (number of samples to play per second) 108 | -> IO (Maybe SoundBuffer) -- ^ A new sfSoundBuffer object ('Nothing' if failed) 109 | 110 | soundBufferFromSamples ptr i j k = 111 | sfSoundBuffer_createFromSamples ptr (fromIntegral i) (fromIntegral j) (fromIntegral k) >>= return . checkNull 112 | 113 | foreign import ccall unsafe "sfSoundBuffer_createFromSamples" 114 | sfSoundBuffer_createFromSamples :: Ptr a -> CUInt -> CUInt -> CUInt -> IO SoundBuffer 115 | 116 | -- CSFML_AUDIO_API sfSoundBuffer* sfSoundBuffer_createFromSamples(const sfInt16* samples, size_t sampleCount, unsigned int channelCount, unsigned int sampleRate); 117 | 118 | 119 | -- | Create a new sound buffer by copying an existing one. 120 | copySoundBuffer :: SoundBuffer -> IO SoundBuffer 121 | copySoundBuffer = sfSoundBuffer_copy 122 | 123 | foreign import ccall unsafe "sfSoundBuffer_copy" 124 | sfSoundBuffer_copy :: SoundBuffer -> IO SoundBuffer 125 | 126 | -- CSFML_AUDIO_API sfSoundBuffer* sfSoundBuffer_copy(sfSoundBuffer* soundBuffer); 127 | 128 | 129 | instance SFResource SoundBuffer where 130 | 131 | {-# INLINABLE destroy #-} 132 | destroy = sfSoundBuffer_destroy 133 | 134 | foreign import ccall unsafe "sfSoundBuffer_destroy" 135 | sfSoundBuffer_destroy :: SoundBuffer -> IO () 136 | 137 | -- CSFML_AUDIO_API void sfSoundBuffer_destroy(sfSoundBuffer* soundBuffer); 138 | 139 | 140 | -- | Save a sound buffer to an audio file. 141 | -- 142 | -- Here is a complete list of all the supported audio formats: 143 | -- ogg, wav, flac, aiff, au, raw, paf, svx, nist, voc, ircam, 144 | -- w64, mat4, mat5 pvf, htk, sds, avr, sd2, caf, wve, mpc2k, rf64. 145 | saveSoundBufferToFile 146 | :: SoundBuffer 147 | -> FilePath -- ^ Path of the sound file to write 148 | -> IO Bool -- ^ 'True' if saving succeeded, 'False' if it failed 149 | 150 | saveSoundBufferToFile sb path = fmap (toEnum . fromIntegral) . withCAString path $ sfSoundBuffer_saveToFile sb 151 | 152 | foreign import ccall unsafe "sfSoundBuffer_saveToFile" 153 | sfSoundBuffer_saveToFile :: SoundBuffer -> CString -> IO CInt 154 | 155 | -- CSFML_AUDIO_API sfBool sfSoundBuffer_saveToFile(const sfSoundBuffer* soundBuffer, const char* filename); 156 | 157 | 158 | -- | Get the array of audio samples stored in a sound buffer. 159 | -- 160 | -- The format of the returned samples is 16 bits signed integer 161 | -- (sfInt16). The total number of samples in this array 162 | -- is given by the 'getSampleCount' function. 163 | getSamples 164 | :: SoundBuffer 165 | -> IO (Ptr a) -- ^ Read-only pointer to the array of sound samples 166 | 167 | getSamples = sfSoundBuffer_getSamples 168 | 169 | foreign import ccall unsafe "sfSoundBuffer_getSamples" 170 | sfSoundBuffer_getSamples :: SoundBuffer -> IO (Ptr a) 171 | 172 | -- CSFML_AUDIO_API const sfInt16* sfSoundBuffer_getSamples(const sfSoundBuffer* soundBuffer); 173 | 174 | 175 | -- | Get the number of samples stored in a sound buffer. 176 | -- 177 | -- The array of samples can be accessed with the 178 | -- sfSoundBuffer_getSamples function. 179 | getSampleCount :: SoundBuffer -> IO Int 180 | getSampleCount = sfSoundBuffer_getSampleCount >=> return . fromIntegral 181 | 182 | foreign import ccall unsafe "sfSoundBuffer_getSampleCount" 183 | sfSoundBuffer_getSampleCount :: SoundBuffer -> IO CUInt 184 | 185 | -- CSFML_AUDIO_API size_t sfSoundBuffer_getSampleCount(const sfSoundBuffer* soundBuffer); 186 | 187 | 188 | instance SFSoundBuffer SoundBuffer where 189 | 190 | {-# INLINABLE getChannelCount #-} 191 | getChannelCount = sfSoundBuffer_getChannelCount >=> return . fromIntegral 192 | 193 | {-# INLINABLE getDuration #-} 194 | getDuration sb = alloca $ \ptr -> sfSoundBuffer_getDuration_helper sb ptr >> peek ptr 195 | 196 | 197 | foreign import ccall unsafe "sfSoundBuffer_getChannelCount" 198 | sfSoundBuffer_getChannelCount :: SoundBuffer -> IO CUInt 199 | 200 | -- CSFML_AUDIO_API unsigned int sfSoundBuffer_getChannelCount(const sfSoundBuffer* soundBuffer); 201 | 202 | foreign import ccall unsafe "sfSoundBuffer_getDuration_helper" 203 | sfSoundBuffer_getDuration_helper :: SoundBuffer -> Ptr Time -> IO () 204 | 205 | -- CSFML_AUDIO_API sfTime sfSoundBuffer_getDuration(const sfSoundBuffer* soundBuffer); 206 | 207 | 208 | instance SFSampled SoundBuffer where 209 | 210 | {-# INLINABLE getSampleRate #-} 211 | getSampleRate = sfSoundBuffer_getSampleRate >=> return . fromIntegral 212 | 213 | 214 | foreign import ccall unsafe "sfSoundBuffer_getSampleRate" 215 | sfSoundBuffer_getSampleRate :: SoundBuffer -> IO CUInt 216 | 217 | -- CSFML_AUDIO_API unsigned int sfSoundBuffer_getSampleRate(const sfSoundBuffer* soundBuffer); 218 | 219 | -------------------------------------------------------------------------------- /src/SFML/Audio/SoundBufferRecorder.hs: -------------------------------------------------------------------------------- 1 | module SFML.Audio.SoundBufferRecorder 2 | ( 3 | module SFML.Utils 4 | , createSoundBufferRecorder 5 | , destroy 6 | , startRecording 7 | , stopRecording 8 | , getSampleRate 9 | , getRecorderBuffer 10 | ) 11 | where 12 | 13 | 14 | import SFML.Audio.SFSampled 15 | import SFML.Audio.SFSoundRecorder 16 | import SFML.Audio.Types 17 | import SFML.SFException 18 | import SFML.SFResource 19 | import SFML.Utils 20 | 21 | import Control.Applicative ((<$>), (<*>)) 22 | import Control.Exception 23 | import Control.Monad ((>=>)) 24 | import Foreign.C.Types 25 | import Foreign.Ptr (nullPtr) 26 | 27 | 28 | checkNull :: SoundBufferRecorder -> Maybe SoundBufferRecorder 29 | checkNull sbr@(SoundBufferRecorder ptr) = if ptr == nullPtr then Nothing else Just sbr 30 | 31 | 32 | -- | Create a new sound buffer recorder. 33 | createSoundBufferRecorder :: IO (Either SFException SoundBufferRecorder) 34 | createSoundBufferRecorder = 35 | let err = SFException $ "Failed creating sound buffer recorder" 36 | in fmap (tagErr err . checkNull) sfSoundBufferRecorder_create 37 | 38 | foreign import ccall unsafe "sfSoundBufferRecorder_create" 39 | sfSoundBufferRecorder_create :: IO SoundBufferRecorder 40 | 41 | -- \return A new sfSoundBufferRecorder object (NULL if failed) 42 | 43 | -- CSFML_AUDIO_API sfSoundBufferRecorder* sfSoundBufferRecorder_create(void); 44 | 45 | 46 | instance SFResource SoundBufferRecorder where 47 | 48 | {-# INLINABLE destroy #-} 49 | destroy = sfSoundBufferRecorder_destroy 50 | 51 | foreign import ccall unsafe "sfSoundBufferRecorder_destroy" 52 | sfSoundBufferRecorder_destroy :: SoundBufferRecorder -> IO () 53 | 54 | -- CSFML_AUDIO_API void sfSoundBufferRecorder_destroy(sfSoundBufferRecorder* soundBufferRecorder); 55 | 56 | 57 | instance SFSoundRecorder SoundBufferRecorder where 58 | 59 | {-# INLINABLE startRecording #-} 60 | startRecording rec rate = ((/=0) . fromIntegral) <$> sfSoundBufferRecorder_start rec (fromIntegral rate) 61 | 62 | {-# INLINABLE stopRecording #-} 63 | stopRecording = sfSoundBufferRecorder_stop 64 | 65 | 66 | foreign import ccall unsafe "sfSoundBufferRecorder_start" 67 | sfSoundBufferRecorder_start :: SoundBufferRecorder -> CUInt -> IO CInt 68 | 69 | -- CSFML_AUDIO_API void sfSoundBufferRecorder_start(sfSoundBufferRecorder* soundBufferRecorder, unsigned int sampleRate); 70 | 71 | foreign import ccall unsafe "sfSoundBufferRecorder_stop" 72 | sfSoundBufferRecorder_stop :: SoundBufferRecorder -> IO () 73 | 74 | -- CSFML_AUDIO_API void sfSoundBufferRecorder_stop(sfSoundBufferRecorder* soundBufferRecorder); 75 | 76 | 77 | instance SFSampled SoundBufferRecorder where 78 | 79 | {-# INLINABLE getSampleRate #-} 80 | getSampleRate = sfSoundBufferRecorder_getSampleRate >=> return . fromIntegral 81 | 82 | 83 | foreign import ccall unsafe "sfSoundBufferRecorder_getSampleRate" 84 | sfSoundBufferRecorder_getSampleRate :: SoundBufferRecorder -> IO CUInt 85 | 86 | -- CSFML_AUDIO_API unsigned int sfSoundBufferRecorder_getSampleRate(const sfSoundBufferRecorder* soundBufferRecorder); 87 | 88 | 89 | -- | Get the sound buffer containing the captured audio data. 90 | -- 91 | -- The sound buffer is valid only after the capture has ended. 92 | -- This function provides a read-only access to the internal 93 | -- sound buffer, but it can be copied if you need to 94 | -- make any modification to it. 95 | getRecorderBuffer 96 | :: SoundBufferRecorder 97 | -> IO SoundBuffer -- ^ Read-only access to the sound buffer 98 | 99 | getRecorderBuffer = sfSoundBufferRecorder_getBuffer 100 | 101 | foreign import ccall unsafe "sfSoundBufferRecorder_getBuffer" 102 | sfSoundBufferRecorder_getBuffer :: SoundBufferRecorder -> IO SoundBuffer 103 | 104 | -- CSFML_AUDIO_API const sfSoundBuffer* sfSoundBufferRecorder_getBuffer(const sfSoundBufferRecorder* soundBufferRecorder); 105 | 106 | -------------------------------------------------------------------------------- /src/SFML/Audio/SoundStatus.hs: -------------------------------------------------------------------------------- 1 | module SFML.Audio.SoundStatus 2 | where 3 | 4 | 5 | -- | Enumeration of statuses for sounds and musics 6 | data SoundStatus 7 | = Stopped -- ^ Sound or music is not playing 8 | | Paused -- ^ Sound or music is paused 9 | | Playing -- ^ Sound or music is playing 10 | deriving (Eq, Enum, Bounded, Show) 11 | 12 | -------------------------------------------------------------------------------- /src/SFML/Audio/Types.hs: -------------------------------------------------------------------------------- 1 | module SFML.Audio.Types 2 | where 3 | 4 | 5 | import Foreign.Ptr 6 | 7 | 8 | newtype Music = Music (Ptr Music) 9 | newtype Sound = Sound (Ptr Sound) 10 | newtype SoundBuffer = SoundBuffer (Ptr SoundBuffer) 11 | newtype SoundBufferRecorder = SoundBufferRecorder (Ptr SoundBufferRecorder) 12 | newtype SoundRecorder = SoundRecorder (Ptr SoundRecorder) 13 | newtype SoundStream = SoundStream (Ptr SoundStream) 14 | 15 | -------------------------------------------------------------------------------- /src/SFML/Graphics.hs: -------------------------------------------------------------------------------- 1 | module SFML.Graphics 2 | ( 3 | module SFML.Graphics.BlendMode 4 | , module SFML.Graphics.CircleShape 5 | , module SFML.Graphics.Color 6 | , module SFML.Graphics.ConvexShape 7 | , module SFML.Graphics.Font 8 | , module SFML.Graphics.Glyph 9 | , module SFML.Graphics.Image 10 | , module SFML.Graphics.PrimitiveType 11 | , module SFML.Graphics.Rect 12 | , module SFML.Graphics.RectangleShape 13 | , module SFML.Graphics.RenderStates 14 | , module SFML.Graphics.RenderTexture 15 | , module SFML.Graphics.RenderWindow 16 | , module SFML.Graphics.SFBindable 17 | , module SFML.Graphics.SFBounded 18 | , module SFML.Graphics.SFCoordSpace 19 | , module SFML.Graphics.SFDrawable 20 | , module SFML.Graphics.SFRenderTarget 21 | , module SFML.Graphics.SFShape 22 | , module SFML.Graphics.SFShapeResizable 23 | , module SFML.Graphics.SFSmoothTexture 24 | , module SFML.Graphics.SFTexturable 25 | , module SFML.Graphics.SFTransformable 26 | , module SFML.Graphics.SFViewable 27 | , module SFML.Graphics.Shader 28 | , module SFML.Graphics.Shape 29 | , module SFML.Graphics.Sprite 30 | , module SFML.Graphics.Text 31 | , module SFML.Graphics.Texture 32 | , module SFML.Graphics.Transform 33 | , module SFML.Graphics.Types 34 | , module SFML.Graphics.Vertex 35 | , module SFML.Graphics.VertexArray 36 | , module SFML.Graphics.View 37 | ) 38 | where 39 | 40 | 41 | import SFML.Graphics.BlendMode 42 | import SFML.Graphics.CircleShape 43 | import SFML.Graphics.Color 44 | import SFML.Graphics.ConvexShape 45 | import SFML.Graphics.Font 46 | import SFML.Graphics.Glyph 47 | import SFML.Graphics.Image 48 | import SFML.Graphics.PrimitiveType 49 | import SFML.Graphics.Rect 50 | import SFML.Graphics.RectangleShape 51 | import SFML.Graphics.RenderStates 52 | import SFML.Graphics.RenderTexture 53 | import SFML.Graphics.RenderWindow 54 | import SFML.Graphics.SFBindable 55 | import SFML.Graphics.SFBounded 56 | import SFML.Graphics.SFCoordSpace 57 | import SFML.Graphics.SFDrawable 58 | import SFML.Graphics.SFRenderTarget 59 | import SFML.Graphics.SFShape 60 | import SFML.Graphics.SFShapeResizable 61 | import SFML.Graphics.SFSmoothTexture 62 | import SFML.Graphics.SFTexturable 63 | import SFML.Graphics.SFTransformable 64 | import SFML.Graphics.SFViewable 65 | import SFML.Graphics.Shader 66 | import SFML.Graphics.Shape 67 | import SFML.Graphics.Sprite 68 | import SFML.Graphics.Text 69 | import SFML.Graphics.Texture 70 | import SFML.Graphics.Transform 71 | import SFML.Graphics.Types 72 | import SFML.Graphics.Vertex 73 | import SFML.Graphics.VertexArray 74 | import SFML.Graphics.View 75 | -------------------------------------------------------------------------------- /src/SFML/Graphics/BlendMode.hsc: -------------------------------------------------------------------------------- 1 | module SFML.Graphics.BlendMode 2 | ( 3 | BlendFactor(..) 4 | , BlendEquation(..) 5 | , BlendMode(..) 6 | , blendAlpha 7 | , blendAdd 8 | , blendMultiply 9 | , blendNone 10 | ) 11 | where 12 | 13 | 14 | import Control.Applicative ((<$>), (<*>)) 15 | import Foreign.C.Types (CInt) 16 | import Foreign.Ptr 17 | import Foreign.Storable 18 | 19 | #include 20 | 21 | 22 | -- | Enumeration of the blending factors 23 | data BlendFactor 24 | = BlendFactorZero -- ^ (0, 0, 0, 0) 25 | | BlendFactorOne -- ^ (1, 1, 1, 1) 26 | | BlendFactorSrcColor -- ^ (src.r, src.g, src.b, src.a) 27 | | BlendFactorOneMinusSrcColor -- ^ (1, 1, 1, 1) - (src.r, src.g, src.b, src.a) 28 | | BlendFactorDstColor -- ^ (dst.r, dst.g, dst.b, dst.a) 29 | | BlendFactorOneMinusDstColor -- ^ (1, 1, 1, 1) - (dst.r, dst.g, dst.b, dst.a) 30 | | BlendFactorSrcAlpha -- ^ (src.a, src.a, src.a, src.a) 31 | | BlendFactorOneMinusSrcAlpha -- ^ (1, 1, 1, 1) - (src.a, src.a, src.a, src.a) 32 | | BlendFactorDstAlpha -- ^ (dst.a, dst.a, dst.a, dst.a) 33 | | BlendFactorOneMinusDstAlpha -- ^ (1, 1, 1, 1) - (dst.a, dst.a, dst.a, dst.a) 34 | deriving (Eq, Enum, Bounded, Show) 35 | 36 | 37 | -- | Enumeration of the blending equations 38 | data BlendEquation 39 | = BlendEquationAdd -- ^ Pixel = Src * SrcFactor + Dst * DstFactor 40 | | BlendEquationSubtract -- ^ Pixel = Src * SrcFactor - Dst * DstFactor 41 | deriving (Eq, Enum, Bounded, Show) 42 | 43 | 44 | -- | Available blending modes for drawing. 45 | data BlendMode 46 | = BlendMode 47 | { colorSrcFactor :: BlendFactor -- ^ Source blending factor for the color channels 48 | , colorDstFactor :: BlendFactor -- ^ Destination blending factor for the color channels 49 | , colorEquation :: BlendEquation -- ^ Blending equation for the color channels 50 | , alphaSrcFactor :: BlendFactor -- ^ Source blending factor for the alpha channel 51 | , alphaDstFactor :: BlendFactor -- ^ Destination blending factor for the alpha channel 52 | , alphaEquation :: BlendEquation -- ^ Blending equation for the alpha channel 53 | } deriving (Eq, Show) 54 | 55 | 56 | instance Storable BlendFactor where 57 | sizeOf _ = #{size sfBlendFactor} 58 | alignment _ = #{alignment sfBlendFactor} 59 | 60 | peek ptr = fmap (toEnum . fromIntegral) $ peek (castPtr ptr :: Ptr CInt) 61 | poke ptr bm = poke (castPtr ptr :: Ptr CInt) (fromIntegral . fromEnum $ bm) 62 | 63 | 64 | instance Storable BlendEquation where 65 | sizeOf _ = #{size sfBlendEquation} 66 | alignment _ = #{alignment sfBlendEquation} 67 | 68 | peek ptr = fmap (toEnum . fromIntegral) $ peek (castPtr ptr :: Ptr CInt) 69 | poke ptr bm = poke (castPtr ptr :: Ptr CInt) (fromIntegral . fromEnum $ bm) 70 | 71 | 72 | instance Storable BlendMode where 73 | sizeOf _ = #{size sfBlendMode} 74 | alignment _ = #{alignment sfBlendMode} 75 | 76 | peek ptr = BlendMode <$> #{peek sfBlendMode, colorSrcFactor} ptr 77 | <*> #{peek sfBlendMode, colorDstFactor} ptr 78 | <*> #{peek sfBlendMode, colorEquation} ptr 79 | <*> #{peek sfBlendMode, alphaSrcFactor} ptr 80 | <*> #{peek sfBlendMode, alphaDstFactor} ptr 81 | <*> #{peek sfBlendMode, alphaEquation} ptr 82 | poke ptr bm = do 83 | #{poke sfBlendMode, colorSrcFactor} ptr (colorSrcFactor bm) 84 | #{poke sfBlendMode, colorDstFactor} ptr (colorDstFactor bm) 85 | #{poke sfBlendMode, colorEquation} ptr (colorEquation bm) 86 | #{poke sfBlendMode, alphaSrcFactor} ptr (alphaSrcFactor bm) 87 | #{poke sfBlendMode, alphaDstFactor} ptr (alphaDstFactor bm) 88 | #{poke sfBlendMode, alphaEquation} ptr (alphaEquation bm) 89 | 90 | 91 | blendAlpha = BlendMode BlendFactorSrcAlpha 92 | BlendFactorOneMinusSrcAlpha 93 | BlendEquationAdd 94 | BlendFactorOne 95 | BlendFactorOneMinusSrcAlpha 96 | BlendEquationAdd 97 | 98 | 99 | blendAdd = BlendMode BlendFactorSrcAlpha 100 | BlendFactorOne 101 | BlendEquationAdd 102 | BlendFactorOne 103 | BlendFactorOne 104 | BlendEquationAdd 105 | 106 | 107 | blendMultiply = BlendMode BlendFactorDstColor 108 | BlendFactorZero 109 | BlendEquationAdd 110 | BlendFactorDstColor 111 | BlendFactorZero 112 | BlendEquationAdd 113 | 114 | 115 | blendNone = BlendMode BlendFactorOne 116 | BlendFactorZero 117 | BlendEquationAdd 118 | BlendFactorOne 119 | BlendFactorZero 120 | BlendEquationAdd 121 | -------------------------------------------------------------------------------- /src/SFML/Graphics/Color.hsc: -------------------------------------------------------------------------------- 1 | module SFML.Graphics.Color 2 | ( 3 | Color(..) 4 | , black 5 | , white 6 | , red 7 | , green 8 | , blue 9 | , yellow 10 | , magenta 11 | , cyan 12 | , transparent 13 | ) 14 | where 15 | 16 | 17 | import Control.Applicative ((<$>), (<*>)) 18 | import Data.Bits ((.&.), shiftR) 19 | import Data.Word (Word8, Word32) 20 | import Foreign.Storable 21 | 22 | #include 23 | 24 | 25 | -- | Utility data type for manpulating RGBA colors. 26 | data Color = Color 27 | { r :: Word8 28 | , g :: Word8 29 | , b :: Word8 30 | , a :: Word8 31 | } 32 | deriving (Eq, Show) 33 | 34 | 35 | instance Storable Color where 36 | sizeOf _ = 4 * sizeOf (undefined :: Word8) 37 | alignment _ = alignment (undefined :: Word8) 38 | 39 | peek ptr = Color 40 | <$> #{peek sfColor, r} ptr 41 | <*> #{peek sfColor, g} ptr 42 | <*> #{peek sfColor, b} ptr 43 | <*> #{peek sfColor, a} ptr 44 | 45 | poke ptr (Color r g b a) = do 46 | #{poke sfColor, r} ptr r 47 | #{poke sfColor, g} ptr g 48 | #{poke sfColor, b} ptr b 49 | #{poke sfColor, a} ptr a 50 | 51 | 52 | black = Color 0 0 0 255 53 | white = Color 255 255 255 255 54 | red = Color 255 0 0 255 55 | green = Color 0 255 0 255 56 | blue = Color 0 0 255 255 57 | yellow = Color 255 255 0 255 58 | magenta = Color 255 0 255 255 59 | cyan = Color 0 255 255 255 60 | transparent = Color 0 0 0 0 61 | 62 | 63 | instance Num Color where 64 | 65 | (Color r1 g1 b1 a1) + (Color r2 g2 b2 a2) = Color (r1+r2) (g1+g2) (b1+b2) (a1+a2) 66 | (Color r1 g1 b1 a1) - (Color r2 g2 b2 a2) = Color (r1-r2) (g1-g2) (b1-b2) (a1-a2) 67 | (Color r1 g1 b1 a1) * (Color r2 g2 b2 a2) = Color (r1*r2) (g1*g2) (b1*b2) (a1*a2) 68 | negate (Color r g b a) = Color (-r) (-g) (-b) (-a) 69 | abs (Color r g b a) = Color (abs r) (abs g) (abs b) (abs a) 70 | signum (Color r g b a) = Color (signum r) (signum g) (signum b) (signum a) 71 | fromInteger i' = 72 | let i = fromIntegral i' :: Word32 73 | r = fromIntegral $ (i .&. 0xFF000000) `shiftR` 24 74 | g = fromIntegral $ (i .&. 0x00FF0000) `shiftR` 16 75 | b = fromIntegral $ (i .&. 0x0000FF00) `shiftR` 8 76 | a = fromIntegral $ i .&. 0x000000FF 77 | in Color r g b a 78 | -------------------------------------------------------------------------------- /src/SFML/Graphics/Font.hs: -------------------------------------------------------------------------------- 1 | module SFML.Graphics.Font 2 | ( 3 | module SFML.Utils 4 | , fontFromFile 5 | , fontFromMemory 6 | , fontFromStream 7 | , copy 8 | , destroy 9 | , getGlyph 10 | , getGlyphWithOutline 11 | , getKerning 12 | , getLineSpacing 13 | , getUnderlinePosition 14 | , getUnderlineThickness 15 | , getFontTexture 16 | , getInfo 17 | ) 18 | where 19 | 20 | 21 | import SFML.Graphics.FontInfo 22 | import SFML.Graphics.Glyph 23 | import SFML.Graphics.Types 24 | import SFML.SFCopyable 25 | import SFML.SFException 26 | import SFML.SFResource 27 | import SFML.System.InputStream 28 | import SFML.Utils 29 | 30 | import Data.Word 31 | import Foreign.C.String 32 | import Foreign.C.Types 33 | import Foreign.Marshal.Alloc (alloca) 34 | import Foreign.Marshal.Utils (with) 35 | import Foreign.Ptr 36 | import Foreign.Storable 37 | 38 | 39 | checkNull :: Font -> Maybe Font 40 | checkNull font@(Font ptr) = if ptr == nullPtr then Nothing else Just font 41 | 42 | 43 | -- | Create a new font from a file. 44 | fontFromFile :: FilePath -> IO (Either SFException Font) 45 | fontFromFile path = 46 | let err = SFException $ "Failed loading font from file " ++ show path 47 | in fmap (tagErr err . checkNull) $ withCAString path sfFont_createFromFile 48 | 49 | foreign import ccall unsafe "sfFont_createFromFile" 50 | sfFont_createFromFile :: CString -> IO Font 51 | 52 | -- \return A new sfFont object, or NULL if it failed 53 | 54 | --CSFML_GRAPHICS_API sfFont* sfFont_createFromFile(const char* filename); 55 | 56 | 57 | -- | Create a new image font a file in memory. 58 | fontFromMemory 59 | :: Ptr Char -- ^ Pointer to the file data in memory 60 | -> Int -- ^ Size of the data to load, in bytes 61 | -> IO (Either SFException Font) 62 | 63 | fontFromMemory pixels size = 64 | let err = SFException $ "Failed loading font from memory address " ++ show pixels 65 | in fmap (tagErr err . checkNull) $ sfFont_createFromMemory pixels (fromIntegral size) 66 | 67 | foreign import ccall unsafe "sfFont_createFromMemory" 68 | sfFont_createFromMemory :: Ptr a -> CInt -> IO Font 69 | 70 | -- \return A new sfFont object, or NULL if it failed 71 | 72 | --CSFML_GRAPHICS_API sfFont* sfFont_createFromMemory(const void* data, size_t sizeInBytes); 73 | 74 | 75 | -- | Create a new image font a custom stream. 76 | fontFromStream :: InputStream -> IO (Either SFException Font) 77 | fontFromStream stream = 78 | let err = SFException $ "Failed loading font from stream " ++ show stream 79 | in fmap (tagErr err . checkNull) $ with stream sfFont_createFromStream 80 | 81 | foreign import ccall "sfFont_createFromStream" 82 | sfFont_createFromStream :: Ptr InputStream -> IO Font 83 | 84 | -- \return A new sfFont object, or NULL if it failed 85 | 86 | --CSFML_GRAPHICS_API sfFont* sfFont_createFromStream(sfInputStream* stream); 87 | 88 | 89 | instance SFCopyable Font where 90 | 91 | {-# INLINABLE copy #-} 92 | copy = sfFont_copy 93 | 94 | 95 | foreign import ccall unsafe "sfFont_copy" 96 | sfFont_copy :: Font -> IO Font 97 | 98 | --CSFML_GRAPHICS_API sfFont* sfFont_copy(sfFont* font); 99 | 100 | 101 | instance SFResource Font where 102 | 103 | {-# INLINABLE destroy #-} 104 | destroy = sfFont_destroy 105 | 106 | foreign import ccall unsafe "sfFont_destroy" 107 | sfFont_destroy :: Font -> IO () 108 | 109 | --CSFML_GRAPHICS_API void sfFont_destroy(sfFont* font); 110 | 111 | 112 | -- | Get a glyph in a font. Defaults outline to zero. 113 | getGlyph 114 | :: Font -- ^ Source font 115 | -> Int -- ^ Unicode code point of the character to get 116 | -> Int -- ^ Character size, in pixels 117 | -> Bool -- ^ Retrieve the bold version or the regular one? 118 | -> IO Glyph 119 | 120 | getGlyph font codePoint size bold = 121 | alloca $ \glyphPtr -> do 122 | sfFont_getGlyph_helper 123 | font (fromIntegral codePoint) (fromIntegral size) (fromIntegral . fromEnum $ bold) 0.0 glyphPtr 124 | peek glyphPtr 125 | 126 | -- | Get a glyph in a font with an outline. 127 | getGlyphWithOutline 128 | :: Font -- ^ Source font 129 | -> Int -- ^ Unicode code point of the character to get 130 | -> Int -- ^ Character size, in pixels 131 | -> Bool -- ^ Retrieve the bold version or the regular one? 132 | -> Float -- ^ Outline parameter 133 | -> IO Glyph 134 | 135 | getGlyphWithOutline font codePoint size bold outline = 136 | alloca $ \glyphPtr -> do 137 | sfFont_getGlyph_helper 138 | font (fromIntegral codePoint) (fromIntegral size) (fromIntegral . fromEnum $ bold) (realToFrac outline) glyphPtr 139 | peek glyphPtr 140 | 141 | foreign import ccall unsafe "sfFont_getGlyph_helper" 142 | sfFont_getGlyph_helper :: Font -> Word32 -> CUInt -> CInt -> CFloat -> Ptr Glyph -> IO () 143 | 144 | --CSFML_GRAPHICS_API sfGlyph sfFont_getGlyph(sfFont* font, sfUint32 codePoint, unsigned int characterSize, sfBool bold); 145 | 146 | 147 | -- | Get the kerning value corresponding to a given pair of characters in a font. 148 | getKerning 149 | :: Font -- ^ Source font 150 | -> Int -- ^ Unicode code point of the first character 151 | -> Int -- ^ Unicode code point of the second character 152 | -> Int -- ^ Character size, in pixels 153 | -> IO Float 154 | 155 | getKerning font first second size = 156 | fmap realToFrac $ sfFont_getKerning font (fromIntegral first) (fromIntegral second) (fromIntegral size) 157 | 158 | foreign import ccall unsafe "sfFont_getKerning" 159 | sfFont_getKerning :: Font -> Word32 -> Word32 -> CUInt -> IO CFloat 160 | 161 | --CSFML_GRAPHICS_API int sfFont_getKerning(sfFont* font, sfUint32 first, sfUint32 second, unsigned int characterSize); 162 | 163 | 164 | -- | Get the line spacing value. 165 | getLineSpacing 166 | :: Font -- ^ Source font 167 | -> Int -- ^ Character size, in pixels 168 | -> IO Float 169 | 170 | getLineSpacing font size = fmap realToFrac $ sfFont_getLineSpacing font (fromIntegral size) 171 | 172 | foreign import ccall unsafe "sfFont_getLineSpacing" 173 | sfFont_getLineSpacing :: Font -> CUInt -> IO CFloat 174 | 175 | --CSFML_GRAPHICS_API int sfFont_getLineSpacing(sfFont* font, unsigned int characterSize); 176 | 177 | 178 | -- | Get the position of the underline. 179 | -- 180 | -- Underline position is the vertical offset to apply between the 181 | -- baseline and the underline. 182 | getUnderlinePosition 183 | :: Font -- ^ Source font 184 | -> Int -- ^ Reference character size 185 | -> IO Float 186 | 187 | getUnderlinePosition font size 188 | = fmap realToFrac $ sfFont_getUnderlinePosition font (fromIntegral size) 189 | 190 | foreign import ccall unsafe "sfFont_getUnderlinePosition" 191 | sfFont_getUnderlinePosition :: Font -> CUInt -> IO CFloat 192 | 193 | --CSFML_GRAPHICS_API float sfFont_getUnderlinePosition(sfFont* font, unsigned int characterSize); 194 | 195 | 196 | -- | Get the thickness of the underline. 197 | -- 198 | -- Underline thickness is the vertical size of the underline. 199 | getUnderlineThickness 200 | :: Font -- ^ Source font 201 | -> Int -- ^ Reference character size 202 | -> IO Float 203 | 204 | getUnderlineThickness font size 205 | = fmap realToFrac $ sfFont_getUnderlineThickness font (fromIntegral size) 206 | 207 | foreign import ccall unsafe "sfFont_getUnderlineThickness" 208 | sfFont_getUnderlineThickness :: Font -> CUInt -> IO CFloat 209 | 210 | --CSFML_GRAPHICS_API float sfFont_getUnderlineThickness(sfFont* font, unsigned int characterSize); 211 | 212 | 213 | -- | Get the texture containing the glyphs of a given size in a font. 214 | getFontTexture 215 | :: Font -- ^ Source font 216 | -> Int -- ^ Character size, in pixels 217 | -> IO Texture 218 | 219 | getFontTexture font size = sfFont_getTexture font (fromIntegral size) 220 | 221 | foreign import ccall unsafe "sfFont_getTexture" 222 | sfFont_getTexture :: Font -> CUInt -> IO Texture 223 | 224 | --CSFML_GRAPHICS_API const sfTexture* sfFont_getTexture(sfFont* font, unsigned int characterSize); 225 | 226 | 227 | -- | Get the font information. 228 | -- 229 | -- The returned structure will remain valid only if the font 230 | -- is still valid. If the font is invalid an invalid structure 231 | -- is returned. 232 | getInfo :: Font -> IO FontInfo 233 | getInfo font = alloca $ \ptr -> sfFont_getInfo_helper font ptr >> peek ptr 234 | 235 | foreign import ccall unsafe "sfFont_getInfo_helper" 236 | sfFont_getInfo_helper :: Font -> Ptr FontInfo -> IO () 237 | 238 | --CSFML_GRAPHICS_API sfFontInfo sfFont_getInfo(const sfFont* font); 239 | -------------------------------------------------------------------------------- /src/SFML/Graphics/FontInfo.hsc: -------------------------------------------------------------------------------- 1 | module SFML.Graphics.FontInfo 2 | ( 3 | FontInfo(..) 4 | ) 5 | where 6 | 7 | import Control.Applicative ((<$>), (<*>)) 8 | import Foreign.C.String 9 | import Foreign.Ptr 10 | import Foreign.Storable 11 | 12 | #include 13 | 14 | 15 | data FontInfo 16 | = FontInfo 17 | { family :: String 18 | } deriving (Show) 19 | 20 | 21 | instance Storable FontInfo where 22 | sizeOf _ = #{size sfFontInfo} 23 | alignment _ = #{alignment sfFontInfo} 24 | 25 | peek ptr = FontInfo <$> peekCString (castPtr ptr) 26 | 27 | poke ptr fontInfo = withCString (family fontInfo) $ \cstring -> poke (castPtr ptr) cstring 28 | -------------------------------------------------------------------------------- /src/SFML/Graphics/Glyph.hsc: -------------------------------------------------------------------------------- 1 | {-# LANGUAGE CPP, ForeignFunctionInterface #-} 2 | module SFML.Graphics.Glyph 3 | ( 4 | Glyph(..) 5 | ) 6 | where 7 | 8 | 9 | import SFML.Graphics.Rect 10 | 11 | import Control.Applicative ((<$>), (<*>)) 12 | import Foreign.C.Types 13 | import Foreign.Storable 14 | 15 | #include 16 | 17 | 18 | sizeInt = #{size int} 19 | sizeIntRect = #{size sfIntRect} 20 | 21 | 22 | -- | Describes a glyph (a visual character). 23 | data Glyph = Glyph 24 | { advance :: Int -- ^ Offset to move horizontically to the next character 25 | , bounds :: IntRect -- ^ Bounding rectangle of the glyph, in coordinates relative to the baseline 26 | , textureRect :: IntRect -- ^ Texture coordinates of the glyph inside the font's image 27 | } 28 | 29 | 30 | instance Storable Glyph where 31 | sizeOf _ = sizeInt + 2*sizeIntRect 32 | alignment _ = alignment (undefined :: IntRect) 33 | 34 | peek ptr = Glyph 35 | <$> fmap fromIntegral (#{peek sfGlyph, advance} ptr :: IO CInt) 36 | <*> #{peek sfGlyph, bounds} ptr 37 | <*> #{peek sfGlyph, textureRect} ptr 38 | 39 | poke ptr (Glyph advance bounds rect) = do 40 | #{poke sfGlyph, advance} ptr (fromIntegral advance :: CInt) 41 | #{poke sfGlyph, bounds} ptr bounds 42 | #{poke sfGlyph, textureRect} ptr rect 43 | 44 | -------------------------------------------------------------------------------- /src/SFML/Graphics/PrimitiveType.hs: -------------------------------------------------------------------------------- 1 | module SFML.Graphics.PrimitiveType 2 | ( 3 | PrimitiveType(..) 4 | ) 5 | where 6 | 7 | 8 | import Foreign.C.Types (CInt) 9 | import Foreign.Ptr 10 | import Foreign.Storable 11 | 12 | 13 | -- | Types of primitives that a sf::VertexArray can render. 14 | -- 15 | -- Points and lines have no area, therefore their thickness 16 | -- will always be 1 pixel, regardless of the current transform 17 | -- and view. 18 | data PrimitiveType 19 | = Points -- ^ List of individual points 20 | | Lines -- ^ List of individual lines 21 | | LineStrip -- ^ List of connected lines, a point uses the previous point to form a line 22 | | Triangles -- ^ List of individual triangles 23 | | TriangleStrip -- ^ List of connected triangles, a point uses the two previous points to form a triangle 24 | | TriangleFan -- ^ List of connected triangles, a point uses the common center and the previous point to form a triangle 25 | | Quads -- ^ List of individual quads 26 | deriving (Eq, Enum, Bounded, Show) 27 | 28 | 29 | instance Storable PrimitiveType where 30 | sizeOf _ = sizeOf (undefined :: CInt) 31 | alignment _ = alignment (undefined :: CInt) 32 | 33 | peek ptr = peek (castPtr ptr :: Ptr CInt) >>= return . toEnum . fromIntegral 34 | poke ptr pt = poke (castPtr ptr :: Ptr CInt) (fromIntegral . fromEnum $ pt) 35 | 36 | 37 | {-typedef enum 38 | { 39 | sfPoints, 40 | sfLines, 41 | sfLinesStrip, 42 | sfTriangles, 43 | sfTrianglesStrip, 44 | sfTrianglesFan, 45 | sfQuads 46 | } sfPrimitiveType;-} 47 | 48 | -------------------------------------------------------------------------------- /src/SFML/Graphics/Rect.hsc: -------------------------------------------------------------------------------- 1 | {-# LANGUAGE CPP, ForeignFunctionInterface #-} 2 | module SFML.Graphics.Rect 3 | ( 4 | FloatRect(..) 5 | , IntRect(..) 6 | , Rect(..) 7 | , floatRectContains 8 | , intRectContains 9 | ) 10 | where 11 | 12 | 13 | import Control.Applicative ((<$>), (<*>)) 14 | import Foreign.C.Types 15 | import Foreign.Marshal.Alloc (alloca) 16 | import Foreign.Marshal.Utils (with) 17 | import Foreign.Ptr (Ptr) 18 | import Foreign.Storable 19 | import System.IO.Unsafe 20 | 21 | #include 22 | 23 | 24 | sizeInt = #{size int} 25 | sizeFloat = #{size float} 26 | 27 | 28 | -- | Utility class for manipulating rectangles. 29 | data FloatRect = FloatRect 30 | { fleft :: Float 31 | , ftop :: Float 32 | , fwidth :: Float 33 | , fheight :: Float 34 | } 35 | 36 | 37 | instance Storable FloatRect where 38 | sizeOf _ = 4 * sizeFloat 39 | alignment _ = alignment (undefined :: CFloat) 40 | 41 | peek ptr = FloatRect 42 | <$> fmap realToFrac (#{peek sfFloatRect, left} ptr :: IO CFloat) 43 | <*> fmap realToFrac (#{peek sfFloatRect, top} ptr :: IO CFloat) 44 | <*> fmap realToFrac (#{peek sfFloatRect, width} ptr :: IO CFloat) 45 | <*> fmap realToFrac (#{peek sfFloatRect, height} ptr :: IO CFloat) 46 | 47 | poke ptr (FloatRect l t w h) = do 48 | #{poke sfFloatRect, left} ptr (realToFrac l :: CFloat) 49 | #{poke sfFloatRect, top} ptr (realToFrac t :: CFloat) 50 | #{poke sfFloatRect, width} ptr (realToFrac w :: CFloat) 51 | #{poke sfFloatRect, height} ptr (realToFrac h :: CFloat) 52 | 53 | 54 | -- | Utility class for manipulating rectangles. 55 | data IntRect = IntRect 56 | { ileft :: Int 57 | , itop :: Int 58 | , iwidth :: Int 59 | , iheight :: Int 60 | } 61 | 62 | 63 | instance Storable IntRect where 64 | sizeOf _ = 4 * sizeInt 65 | alignment _ = alignment (undefined :: CInt) 66 | 67 | peek ptr = IntRect 68 | <$> fmap fromIntegral (#{peek sfIntRect, left} ptr :: IO CInt) 69 | <*> fmap fromIntegral (#{peek sfIntRect, top} ptr :: IO CInt) 70 | <*> fmap fromIntegral (#{peek sfIntRect, width} ptr :: IO CInt) 71 | <*> fmap fromIntegral (#{peek sfIntRect, height} ptr :: IO CInt) 72 | 73 | poke ptr (IntRect l t w h) = do 74 | #{poke sfIntRect, left} ptr (fromIntegral l :: CInt) 75 | #{poke sfIntRect, top} ptr (fromIntegral t :: CInt) 76 | #{poke sfIntRect, width} ptr (fromIntegral w :: CInt) 77 | #{poke sfIntRect, height} ptr (fromIntegral h :: CInt) 78 | 79 | 80 | -- | Check if a point is inside a rectangle's area. 81 | floatRectContains 82 | :: Float -- ^ X coordinate of the point to test 83 | -> Float -- ^ Y coordinate of the point to test 84 | -> FloatRect -- ^ Rectangle to test 85 | -> Bool 86 | 87 | floatRectContains x y r = unsafeDupablePerformIO $ fmap (/=0) . with r $ \ptr -> sfFloatRect_contains ptr x y 88 | 89 | foreign import ccall unsafe "sfFloatRect_contains" 90 | sfFloatRect_contains :: Ptr FloatRect -> Float -> Float -> IO CInt 91 | 92 | --CSFML_GRAPHICS_API sfBool sfFloatRect_contains(const sfFloatRect* rect, float x, float y); 93 | 94 | 95 | -- | Check if a point is inside a rectangle's area. 96 | intRectContains 97 | :: Int -- ^ X coordinate of the point to test 98 | -> Int -- ^ Y coordinate of the point to test 99 | -> IntRect -- ^ Rectangle to test 100 | -> Bool 101 | 102 | intRectContains x y r = unsafeDupablePerformIO $ fmap (/=0) . with r $ 103 | \ptr -> sfIntRect_contains ptr (fromIntegral x) (fromIntegral y) 104 | 105 | foreign import ccall unsafe "sfIntRect_contains" 106 | sfIntRect_contains :: Ptr IntRect -> CInt -> CInt -> IO CInt 107 | 108 | --CSFML_GRAPHICS_API sfBool sfIntRect_contains(const sfIntRect* rect, int x, int y); 109 | 110 | 111 | class Rect a where 112 | -- | Check intersection between two rectangles. 113 | intersectRect 114 | :: a -- ^ First rectangle to test 115 | -> a -- ^ Second rectangle to test 116 | -> Maybe a -- ^ Overlapping rect 117 | 118 | 119 | instance Rect FloatRect where 120 | 121 | intersectRect r1 r2 = unsafeDupablePerformIO $ 122 | alloca $ \ptr1 -> 123 | alloca $ \ptr2 -> 124 | alloca $ \ptrOut -> do 125 | poke ptr1 r1 126 | poke ptr2 r2 127 | result <- sfFloatRect_intersects ptr1 ptr2 ptrOut 128 | case result of 129 | 0 -> return Nothing 130 | _ -> peek ptrOut >>= return . Just 131 | 132 | 133 | foreign import ccall unsafe "sfFloatRect_intersects" 134 | sfFloatRect_intersects :: Ptr FloatRect -> Ptr FloatRect -> Ptr FloatRect -> IO CInt 135 | 136 | --CSFML_GRAPHICS_API sfBool sfFloatRect_intersects(const sfFloatRect* rect1, const sfFloatRect* rect2, sfFloatRect* intersection); 137 | 138 | 139 | instance Rect IntRect where 140 | 141 | intersectRect r1 r2 = unsafeDupablePerformIO $ 142 | alloca $ \ptr1 -> 143 | alloca $ \ptr2 -> 144 | alloca $ \ptrOut -> do 145 | poke ptr1 r1 146 | poke ptr2 r2 147 | result <- sfIntRect_intersects ptr1 ptr2 ptrOut 148 | case result of 149 | 0 -> return Nothing 150 | _ -> peek ptrOut >>= return . Just 151 | 152 | 153 | foreign import ccall unsafe "sfIntRect_intersects" 154 | sfIntRect_intersects :: Ptr IntRect -> Ptr IntRect -> Ptr IntRect -> IO CInt 155 | 156 | --CSFML_GRAPHICS_API sfBool sfIntRect_intersects(const sfIntRect* rect1, const sfIntRect* rect2, sfIntRect* intersection); 157 | 158 | -------------------------------------------------------------------------------- /src/SFML/Graphics/RenderStates.hsc: -------------------------------------------------------------------------------- 1 | {-# LANGUAGE CPP, ForeignFunctionInterface #-} 2 | module SFML.Graphics.RenderStates 3 | ( 4 | RenderStates(..) 5 | , renderStates 6 | ) 7 | where 8 | 9 | 10 | import SFML.Graphics.BlendMode 11 | import SFML.Graphics.Transform 12 | import SFML.Graphics.Types 13 | 14 | import Control.Applicative ((<$>), (<*>)) 15 | import Foreign.C.Types (CIntPtr) 16 | import Foreign.Ptr (nullPtr) 17 | import Foreign.Storable 18 | 19 | #include 20 | 21 | 22 | -- | Define the states used for drawing to a RenderTarget. 23 | data RenderStates = RenderStates 24 | { blendMode :: BlendMode 25 | , transform :: Transform 26 | , texture :: Texture 27 | , shader :: Shader 28 | } 29 | 30 | 31 | instance Storable RenderStates where 32 | sizeOf _ = #{size sfRenderStates} 33 | alignment _ = #{alignment sfRenderStates} 34 | 35 | peek ptr = RenderStates 36 | <$> #{peek sfRenderStates, blendMode} ptr 37 | <*> #{peek sfRenderStates, transform} ptr 38 | <*> #{peek sfRenderStates, texture} ptr 39 | <*> #{peek sfRenderStates, shader} ptr 40 | 41 | poke ptr (RenderStates bm tr tx sh) = do 42 | #{poke sfRenderStates, blendMode} ptr bm 43 | #{poke sfRenderStates, transform} ptr tr 44 | #{poke sfRenderStates, texture} ptr tx 45 | #{poke sfRenderStates, shader} ptr sh 46 | 47 | -- | Default render states, defined as 48 | -- 49 | -- @ 50 | -- renderStates = RenderStates 'blendAlpha' 'idTransform' (Texture 'nullPtr') (Shader 'nullPtr') 51 | -- @ 52 | -- 53 | -- This constant tries to mimic the C++ RenderStates default constructor to ease 54 | -- the construction of render states. For example, instead of typing 55 | -- 56 | -- @ 57 | -- states = RenderStates blendAlpha idTransform tex (Shader nullptr) 58 | -- @ 59 | -- 60 | -- Now we can simply type 61 | -- 62 | -- @ 63 | -- states = renderStates { texture = tex } 64 | -- @ 65 | renderStates = RenderStates blendAlpha idTransform (Texture nullPtr) (Shader nullPtr) 66 | 67 | {-typedef struct 68 | { 69 | sfBlendMode blendMode; ///< Blending mode 70 | sfTransform transform; ///< Transform 71 | const sfTexture* texture; ///< Texture 72 | const sfShader* shader; ///< Shader 73 | } sfRenderStates;-} 74 | -------------------------------------------------------------------------------- /src/SFML/Graphics/SFBindable.hs: -------------------------------------------------------------------------------- 1 | module SFML.Graphics.SFBindable 2 | where 3 | 4 | class SFBindable a where 5 | -- | Bind the resource for rendering (activate it). 6 | -- 7 | -- This function is not part of the graphics API, it mustn't be 8 | -- used when drawing SFML entities. It must be used only if you 9 | -- mix sfShader with OpenGL code. 10 | bind :: a -> IO () 11 | -------------------------------------------------------------------------------- /src/SFML/Graphics/SFBounded.hs: -------------------------------------------------------------------------------- 1 | module SFML.Graphics.SFBounded 2 | where 3 | 4 | 5 | import SFML.Graphics.Rect 6 | 7 | 8 | class SFBounded a where 9 | 10 | -- | Get the local bounding rectangle of a boundable. 11 | -- 12 | -- The returned rectangle is in local coordinates, which means 13 | -- that it ignores the transformations (translation, rotation, 14 | -- scale, ...) that are applied to the entity. 15 | -- In other words, this function returns the bounds of the 16 | -- entity in the entity's coordinate system. 17 | getLocalBounds :: a -> IO FloatRect 18 | 19 | -- | Get the global bounding rectangle of a shape. 20 | -- 21 | -- The returned rectangle is in global coordinates, which means 22 | -- that it takes in account the transformations (translation, 23 | -- rotation, scale, ...) that are applied to the entity. 24 | -- In other words, this function returns the bounds of the 25 | -- sprite in the global 2D world's coordinate system. 26 | getGlobalBounds :: a -> IO FloatRect 27 | -------------------------------------------------------------------------------- /src/SFML/Graphics/SFCoordSpace.hs: -------------------------------------------------------------------------------- 1 | module SFML.Graphics.SFCoordSpace 2 | where 3 | 4 | 5 | import SFML.Graphics.Types 6 | import SFML.System.Vector2 7 | 8 | 9 | class SFCoordSpace a where 10 | 11 | -- | Convert a point to world coordinates 12 | -- 13 | -- This function finds the 2D position that matches the 14 | -- given pixel of the coord space. In other words, it does 15 | -- the inverse of what the graphics card does, to find the 16 | -- initial position of a rendered pixel. 17 | -- 18 | -- Initially, both coordinate systems (world units and target pixels) 19 | -- match perfectly. But if you define a custom view or resize your 20 | -- coord space, this assertion is not true anymore, ie. a point 21 | -- located at (10, 50) in your coord space may map to the point 22 | -- (150, 75) in your 2D world -- if the view is translated by (140, 25). 23 | -- 24 | -- This version uses a custom view for calculations, see the other 25 | -- overload of the function if you want to use the current view of the 26 | -- render-texture. 27 | mapPixelToCoords 28 | :: a 29 | -> Vec2i -- ^ Pixel to convert 30 | -> Maybe View -- ^ The view to use for converting the point 31 | -> IO Vec2f 32 | 33 | -------------------------------------------------------------------------------- /src/SFML/Graphics/SFDrawable.hs: -------------------------------------------------------------------------------- 1 | module SFML.Graphics.SFDrawable where 2 | 3 | import SFML.Graphics.CircleShape 4 | import SFML.Graphics.ConvexShape 5 | import SFML.Graphics.RenderStates 6 | import SFML.Graphics.Shape 7 | import SFML.Graphics.SFRenderTarget 8 | import SFML.Graphics.Text 9 | import SFML.Graphics.Types 10 | import SFML.Graphics.VertexArray 11 | 12 | class SFDrawable a where 13 | draw :: SFRenderTarget t => t -> a -> Maybe RenderStates -> IO () 14 | 15 | instance SFDrawable Sprite where 16 | draw = drawSprite 17 | 18 | instance SFDrawable Text where 19 | draw = drawText 20 | 21 | instance SFDrawable Shape where 22 | draw = drawShape 23 | 24 | instance SFDrawable CircleShape where 25 | draw = drawCircle 26 | 27 | instance SFDrawable ConvexShape where 28 | draw = drawConvexShape 29 | 30 | instance SFDrawable VertexArray where 31 | draw = drawVertexArray 32 | -------------------------------------------------------------------------------- /src/SFML/Graphics/SFRenderTarget.hs: -------------------------------------------------------------------------------- 1 | module SFML.Graphics.SFRenderTarget 2 | where 3 | 4 | 5 | import SFML.Graphics.PrimitiveType 6 | import SFML.Graphics.RenderStates 7 | import SFML.Graphics.Types 8 | import SFML.Graphics.Vertex 9 | 10 | import Foreign.Ptr (Ptr) 11 | 12 | 13 | class SFRenderTarget a where 14 | 15 | -- | Draw a sprite to the render-target. 16 | drawSprite 17 | :: a 18 | -> Sprite -- ^ Sprite to draw 19 | -> Maybe RenderStates -- ^ Render states to use for drawing ('Nothing' to use the default states) 20 | -> IO () 21 | 22 | -- | Draw text to the render-target. 23 | drawText 24 | :: a 25 | -> Text -- ^ Text to draw 26 | -> Maybe RenderStates -- ^ Render states to use for drawing ('Nothing' to use the default states) 27 | -> IO () 28 | 29 | -- | Draw a shape to the render-target. 30 | drawShape 31 | :: a 32 | -> Shape -- ^ Shape to draw 33 | -> Maybe RenderStates -- ^ Render states to use for drawing ('Nothing' to use the default states) 34 | -> IO () 35 | 36 | -- | Draw a circle to the render-target. 37 | drawCircle 38 | :: a 39 | -> CircleShape -- ^ CircleShape to draw 40 | -> Maybe RenderStates -- ^ Render states to use for drawing ('Nothing' to use the default states) 41 | -> IO () 42 | 43 | -- | Draw a convex shape to the render-target. 44 | drawConvexShape 45 | :: a 46 | -> ConvexShape -- ^ ConvexShape to draw 47 | -> Maybe RenderStates -- ^ Render states to use for drawing ('Nothing' to use the default states) 48 | -> IO () 49 | 50 | -- | Draw a rectangle to the render-target. 51 | drawRectangle 52 | :: a 53 | -> RectangleShape -- ^ RectangleShape to draw 54 | -> Maybe RenderStates -- ^ Render states to use for drawing ('Nothing' to use the default states) 55 | -> IO () 56 | 57 | -- | Draw a vertex array to the render-target. 58 | drawVertexArray 59 | :: a 60 | -> VertexArray -- ^ VertexArray to draw 61 | -> Maybe RenderStates -- ^ Render states to use for drawing ('Nothing' to use the default states) 62 | -> IO () 63 | 64 | -- | Draw primitives defined by an array of vertices to a render texture. 65 | drawPrimitives 66 | :: a 67 | -> [Vertex] -- ^ Vertices to render 68 | -> PrimitiveType -- ^ Type of primitives to draw 69 | -> Maybe RenderStates -- ^ Render states to use for drawing ('Nothing' to use the default states) 70 | -> IO () 71 | 72 | drawPrimitives' 73 | :: a 74 | -> Ptr Vertex -- ^ Pointer to the vertices 75 | -> Int -- ^ Number of vertices in the array 76 | -> PrimitiveType -- ^ Type of primitives to draw 77 | -> Maybe RenderStates -- ^ Render states to use for drawing ('Nothing' to use the default states) 78 | -> IO () 79 | 80 | -- | Save the current OpenGL render states and matrices. 81 | -- 82 | -- This function can be used when you mix SFML drawing 83 | -- and direct OpenGL rendering. Combined with popGLStates, 84 | -- it ensures that: 85 | -- 86 | -- * SFML's internal states are not messed up by your OpenGL code 87 | -- 88 | -- * Your OpenGL states are not modified by a call to a SFML function 89 | -- 90 | -- Note that this function is quite expensive: it saves all the 91 | -- possible OpenGL states and matrices, even the ones you 92 | -- don't care about. Therefore it should be used wisely. 93 | -- It is provided for convenience, but the best results will 94 | -- be achieved if you handle OpenGL states yourself (because 95 | -- you know which states have really changed, and need to be 96 | -- saved and restored). Take a look at the resetGLStates 97 | -- function if you do so. 98 | pushGLStates :: a -> IO () 99 | 100 | -- | Restore the previously saved OpenGL render states and matrices. 101 | -- 102 | -- See the description of pushGLStates to get a detailed 103 | -- description of these functions. 104 | popGLStates :: a -> IO () 105 | 106 | -- | Reset the internal OpenGL states so that the target is ready for drawing 107 | -- 108 | -- This function can be used when you mix SFML drawing 109 | -- and direct OpenGL rendering, if you choose not to use 110 | -- 'pushGLStates' or 'popGLStates'. It makes sure that all OpenGL 111 | -- states needed by SFML are set, so that subsequent draw 112 | -- calls will work as expected. 113 | resetGLStates :: a -> IO () 114 | 115 | -------------------------------------------------------------------------------- /src/SFML/Graphics/SFShape.hs: -------------------------------------------------------------------------------- 1 | module SFML.Graphics.SFShape 2 | where 3 | 4 | 5 | import SFML.Graphics.Color 6 | import SFML.System.Vector2 7 | 8 | 9 | class SFShape a where 10 | 11 | -- | Set the fill color of a shape. 12 | -- 13 | -- This color is modulated (multiplied) with the shape's 14 | -- texture if any. It can be used to colorize the shape, 15 | -- or change its global opacity. 16 | -- 17 | -- You can use 'Transparent' to make the inside of 18 | -- the shape transparent, and have the outline alone. 19 | -- 20 | -- By default, the shape's fill color is opaque white. 21 | setFillColor :: a -> Color -> IO () 22 | 23 | -- | Set the outline color of a shape. 24 | -- 25 | -- You can use 'Transparent' to disable the outline. 26 | -- 27 | -- By default, the shape's outline color is opaque white. 28 | setOutlineColor :: a -> Color -> IO () 29 | 30 | -- | Set the thickness of a shape's outline. 31 | -- 32 | -- This number cannot be negative. Using zero disables 33 | -- the outline. 34 | -- 35 | -- By default, the outline thickness is 0. 36 | setOutlineThickness 37 | :: a 38 | -> Float -- ^ New outline thickness 39 | -> IO () 40 | 41 | -- | Get the fill color of a shape. 42 | getFillColor :: a -> IO Color 43 | 44 | -- | Get the outline color of a shape. 45 | getOutlineColor :: a -> IO Color 46 | 47 | -- | Get the outline thickness of a shape. 48 | getOutlineThickness :: a -> IO Float 49 | 50 | -- | Get the total number of points of a shape. 51 | getPointCount :: a -> IO Int 52 | 53 | -- | Get the ith point of a shape. 54 | -- 55 | -- The result is undefined if index is out of the valid range. 56 | getPoint 57 | :: a 58 | -> Int -- ^ Index of the point to get, in range [0 .. 'getPointCount' - 1] 59 | -> IO Vec2f 60 | 61 | -------------------------------------------------------------------------------- /src/SFML/Graphics/SFShapeResizable.hs: -------------------------------------------------------------------------------- 1 | module SFML.Graphics.SFShapeResizable 2 | where 3 | 4 | 5 | class SFShapeResizable a where 6 | 7 | -- | Set the number of points of a resizable shape. 8 | setPointCount 9 | :: a 10 | -> Int -- ^ New number of points of the shape 11 | -> IO () 12 | 13 | -------------------------------------------------------------------------------- /src/SFML/Graphics/SFSmoothTexture.hs: -------------------------------------------------------------------------------- 1 | module SFML.Graphics.SFSmoothTexture 2 | where 3 | 4 | 5 | import SFML.Graphics.Types 6 | 7 | 8 | class SFSmoothTexture a where 9 | 10 | -- | Enable or disable the smooth filter on a texture. 11 | setSmooth :: a -> Bool -> IO () 12 | 13 | -- | Tell whether the smooth filter is enabled or not for a texture. 14 | isSmooth :: a -> IO Bool 15 | 16 | -------------------------------------------------------------------------------- /src/SFML/Graphics/SFTexturable.hs: -------------------------------------------------------------------------------- 1 | module SFML.Graphics.SFTexturable 2 | where 3 | 4 | 5 | import SFML.Graphics.Color 6 | import SFML.Graphics.Rect 7 | import SFML.Graphics.Types 8 | 9 | 10 | class SFTexturable a where 11 | 12 | -- | Change the source texture of a Texturable. 13 | -- 14 | -- The texture argument refers to a texture that must 15 | -- exist as long as the texturable uses it. Indeed, the texturable 16 | -- doesn't store its own copy of the texture, but rather keeps 17 | -- a pointer to the one that you passed to this function. 18 | -- 19 | -- If the source texture is destroyed and the texturable tries to 20 | -- use it, the behaviour is undefined. 21 | -- 22 | -- If resetRect is 'True', the TextureRect property of 23 | -- the texturable is automatically adjusted to the size of the new 24 | -- texture. If it is false, the texture rect is left unchanged. 25 | setTexture 26 | :: a 27 | -> Texture -- ^ New texture 28 | -> Bool -- ^ Should the texture rect be reset to the size of the new texture? 29 | -> IO () 30 | 31 | -- | Set the sub-rectangle of the texture that a texturable will display. 32 | -- 33 | -- The texture rect is useful when you don't want to display 34 | -- the whole texture, but rather a part of it. 35 | -- 36 | -- By default, the texture rect covers the entire texture. 37 | setTextureRect 38 | :: a 39 | -> IntRect -- ^ Rectangle defining the region of the texture to display 40 | -> IO () 41 | 42 | -- | Get the source texture of a texturable. 43 | -- 44 | -- If the texturable has no source texture, 'Nothing' is returned. 45 | -- 46 | -- The returned pointer is const, which means that you can't 47 | -- modify the texture when you retrieve it with this function. 48 | getTexture :: a -> IO (Maybe Texture) 49 | 50 | -- | Get the sub-rectangle of the texture displayed by a texturable. 51 | getTextureRect :: a -> IO IntRect 52 | 53 | -------------------------------------------------------------------------------- /src/SFML/Graphics/SFTransformable.hs: -------------------------------------------------------------------------------- 1 | module SFML.Graphics.SFTransformable 2 | where 3 | 4 | 5 | import SFML.Graphics.Transform 6 | import SFML.System.Vector2 7 | 8 | 9 | class SFTransformable a where 10 | 11 | -- | Set the position of a transformable. 12 | -- 13 | -- This function completely overwrites the previous position. 14 | -- 15 | -- See 'move' to apply an offset based on the previous position instead. 16 | -- 17 | -- The default position of a transformable object is (0, 0). 18 | setPosition :: a -> Vec2f -> IO () 19 | 20 | -- | Set the orientation of a transformable. 21 | -- 22 | -- This function completely overwrites the previous rotation. 23 | -- 24 | -- See 'rotate' to add an angle based on the previous rotation instead. 25 | -- 26 | -- The default rotation of a transformable SFTransformable object is 0. 27 | setRotation 28 | :: a 29 | -> Float -- ^ New rotation, in degrees 30 | -> IO () 31 | 32 | -- | Set the scale factors of a transformable. 33 | -- 34 | -- This function completely overwrites the previous scale. 35 | -- 36 | -- See 'scale' to add a factor based on the previous scale instead. 37 | -- 38 | -- The default scale of a transformable SFTransformable object is (1, 1). 39 | setScale :: a -> Vec2f -> IO () 40 | 41 | -- | Set the local origin of a transformable. 42 | -- 43 | -- The origin of an object defines the center point for 44 | -- all transformations (position, scale, rotation). 45 | -- 46 | -- The coordinates of this point must be relative to the 47 | -- top-left corner of the object, and ignore all 48 | -- transformations (position, scale, rotation). 49 | -- 50 | -- The default origin of a transformable SFTransformable object is (0, 0). 51 | setOrigin :: a -> Vec2f -> IO () 52 | 53 | -- | Get the position of a transformable. 54 | getPosition :: a -> IO Vec2f 55 | 56 | -- | Get the orientation of a transformable. 57 | getRotation 58 | :: a 59 | -> IO Float -- ^ Current rotation, in degrees 60 | 61 | -- | Get the current scale of a transformable 62 | getScale :: a -> IO Vec2f 63 | 64 | -- | Get the local origin of a transformable. 65 | getOrigin :: a -> IO Vec2f 66 | 67 | -- | Move a transformable by a given offset 68 | -- 69 | -- This function adds to the current position of the object, 70 | -- unlike 'setPosition' which overwrites it. 71 | move :: a -> Vec2f -> IO () 72 | 73 | -- | Rotate a transformable. 74 | -- 75 | -- This function adds to the current rotation of the object, 76 | -- unlike 'setRotation' which overwrites it. 77 | rotate 78 | :: a 79 | -> Float -- ^ Angle of rotation, in degrees 80 | -> IO () 81 | 82 | -- | Scale a transformable. 83 | -- 84 | -- This function multiplies the current scale of the object, 85 | -- unlike 'setScale' which overwrites it. 86 | scale :: a -> Vec2f -> IO () 87 | 88 | -- | Get the combined transform of a transformable. 89 | getTransform :: a -> IO Transform 90 | 91 | -- | Get the inverse of the combined transform of a transformable. 92 | getInverseTransform :: a -> IO Transform 93 | 94 | -------------------------------------------------------------------------------- /src/SFML/Graphics/SFViewable.hs: -------------------------------------------------------------------------------- 1 | module SFML.Graphics.SFViewable 2 | where 3 | 4 | 5 | import SFML.Graphics.Rect 6 | import SFML.Graphics.Types 7 | 8 | 9 | class SFViewable a where 10 | 11 | -- | Change the target's current active view. 12 | setView :: a -> View -> IO () 13 | 14 | -- | Get the target's current active view. 15 | getView :: a -> IO View 16 | 17 | -- | Get the target's default view. 18 | getDefaultView :: a -> IO View 19 | 20 | -- | Get the viewport of a view applied to this target, expressed in pixels in the current target. 21 | getViewport :: a -> View -> IO IntRect 22 | 23 | -------------------------------------------------------------------------------- /src/SFML/Graphics/Types.hs: -------------------------------------------------------------------------------- 1 | module SFML.Graphics.Types 2 | where 3 | 4 | 5 | import Foreign.C.Types (CIntPtr) 6 | import Foreign.Ptr 7 | import Foreign.Storable 8 | 9 | 10 | newtype CircleShape = CircleShape (Ptr CircleShape) 11 | newtype ConvexShape = ConvexShape (Ptr ConvexShape) 12 | newtype Font = Font (Ptr Font) 13 | newtype Image = Image (Ptr Image) 14 | newtype Shader = Shader (Ptr Shader) 15 | newtype RectangleShape = RectangleShape (Ptr RectangleShape) 16 | newtype RenderTexture = RenderTexture (Ptr RenderTexture) 17 | newtype RenderWindow = RenderWindow (Ptr RenderWindow) 18 | newtype Shape = Shape (Ptr Shape) 19 | newtype Sprite = Sprite (Ptr Sprite) 20 | newtype Text = Text (Ptr Text) 21 | newtype Texture = Texture (Ptr Texture) 22 | newtype VertexArray = VertexArray (Ptr VertexArray) 23 | newtype View = View (Ptr View) 24 | 25 | 26 | instance Storable Texture where 27 | sizeOf _ = sizeOf (undefined :: CIntPtr) 28 | alignment _ = alignment (undefined :: CIntPtr) 29 | 30 | peek ptr = peek (castPtr ptr) >>= return . Texture 31 | poke ptr (Texture p) = poke (castPtr ptr) p 32 | 33 | 34 | instance Storable Shader where 35 | sizeOf _ = sizeOf (undefined :: CIntPtr) 36 | alignment _ = alignment (undefined :: CIntPtr) 37 | 38 | peek ptr = peek (castPtr ptr) >>= return . Shader 39 | poke ptr (Shader p) = poke (castPtr ptr) p 40 | 41 | -------------------------------------------------------------------------------- /src/SFML/Graphics/Vertex.hsc: -------------------------------------------------------------------------------- 1 | {-# LANGUAGE CPP, ForeignFunctionInterface #-} 2 | module SFML.Graphics.Vertex 3 | ( 4 | Vertex(..) 5 | ) 6 | where 7 | 8 | 9 | import SFML.Graphics.Color 10 | import SFML.System.Vector2 11 | 12 | import Control.Applicative ((<$>), (<*>)) 13 | import Foreign.C.Types (CFloat) 14 | import Foreign.Storable 15 | 16 | #include 17 | 18 | 19 | -- | Define a point with color and texture coordinates. 20 | data Vertex = Vertex 21 | { position :: Vec2f 22 | , color :: Color 23 | , texCoords :: Vec2f 24 | } 25 | deriving (Show) 26 | 27 | 28 | instance Storable Vertex where 29 | sizeOf _ = size_sfVertex 30 | alignment _ = alignment (undefined :: CFloat) 31 | 32 | peek ptr = Vertex 33 | <$> #{peek sfVertex, position} ptr 34 | <*> #{peek sfVertex, color} ptr 35 | <*> #{peek sfVertex, texCoords} ptr 36 | 37 | poke ptr (Vertex pos col tex) = do 38 | #{poke sfVertex, position} ptr pos 39 | #{poke sfVertex, color} ptr col 40 | #{poke sfVertex, texCoords} ptr tex 41 | 42 | 43 | size_sfVertex = #{size sfVertex} 44 | 45 | {-typedef struct 46 | { 47 | sfVector2f position; ///< Position of the vertex 48 | sfColor color; ///< Color of the vertex 49 | sfVector2f texCoords; ///< Coordinates of the texture's pixel to map to the vertex 50 | } sfVertex;-} 51 | 52 | -------------------------------------------------------------------------------- /src/SFML/Graphics/VertexArray.hs: -------------------------------------------------------------------------------- 1 | module SFML.Graphics.VertexArray 2 | ( 3 | createVA 4 | , copy 5 | , destroy 6 | , getVertexCount 7 | , getVertex 8 | , clearVA 9 | , resizeVA 10 | , appendVA 11 | , setPrimitiveType 12 | , getPrimitiveType 13 | , getVABounds 14 | ) 15 | where 16 | 17 | 18 | import SFML.Graphics.PrimitiveType 19 | import SFML.Graphics.Rect 20 | import SFML.Graphics.Types 21 | import SFML.Graphics.Vertex 22 | import SFML.SFCopyable 23 | import SFML.SFResource 24 | 25 | import Control.Monad 26 | import Foreign.C.Types 27 | import Foreign.Marshal.Alloc (alloca) 28 | import Foreign.Marshal.Utils (with) 29 | import Foreign.Ptr 30 | import Foreign.Storable (peek) 31 | 32 | 33 | -- | Create a new vertex array. 34 | createVA :: IO VertexArray 35 | createVA = sfVertexArray_create 36 | 37 | foreign import ccall unsafe "sfVertexArray_create" 38 | sfVertexArray_create :: IO VertexArray 39 | 40 | --CSFML_GRAPHICS_API sfVertexArray* sfVertexArray_create(void); 41 | 42 | 43 | instance SFCopyable VertexArray where 44 | 45 | {-# INLINABLE copy #-} 46 | copy = sfVertexArray_copy 47 | 48 | 49 | foreign import ccall unsafe "sfVertexArray_copy" 50 | sfVertexArray_copy :: VertexArray -> IO VertexArray 51 | 52 | --CSFML_GRAPHICS_API sfVertexArray* sfVertexArray_copy(sfVertexArray* vertexArray); 53 | 54 | 55 | instance SFResource VertexArray where 56 | 57 | {-# INLINABLE destroy #-} 58 | destroy = sfVertexArray_destroy 59 | 60 | foreign import ccall unsafe "sfVertexArray_destroy" 61 | sfVertexArray_destroy :: VertexArray -> IO () 62 | 63 | --CSFML_GRAPHICS_API void sfVertexArray_destroy(sfVertexArray* vertexArray); 64 | 65 | 66 | -- | Return the vertex count of a vertex array. 67 | getVertexCount :: VertexArray -> IO Int 68 | getVertexCount = sfVertexArray_getVertexCount >=> return . fromIntegral 69 | 70 | foreign import ccall unsafe "sfVertexArray_getVertexCount" 71 | sfVertexArray_getVertexCount :: VertexArray -> IO CUInt 72 | 73 | --CSFML_GRAPHICS_API unsigned int sfVertexArray_getVertexCount(const sfVertexArray* vertexArray); 74 | 75 | 76 | -- | Return the ith vertex. 77 | 78 | -- This function doesn't check the index; it must be in range 79 | -- [0, vertex count - 1]. The behaviour is otherwise undefined. 80 | getVertex :: VertexArray -> Int -> IO (Ptr Vertex) 81 | getVertex va i = sfVertexArray_getVertex va (fromIntegral i) 82 | 83 | foreign import ccall unsafe "sfVertexArray_getVertex" 84 | sfVertexArray_getVertex :: VertexArray -> CUInt -> IO (Ptr Vertex) 85 | 86 | --CSFML_GRAPHICS_API sfVertex* sfVertexArray_getVertex(sfVertexArray* vertexArray, unsigned int index); 87 | 88 | 89 | -- | Clear a vertex array. 90 | -- 91 | -- This function removes all the vertices from the array. 92 | -- It doesn't deallocate the corresponding memory, so that 93 | -- adding new vertices after clearing doesn't involve 94 | -- reallocating all the memory. 95 | clearVA :: VertexArray -> IO () 96 | clearVA = sfVertexArray_clear 97 | 98 | foreign import ccall unsafe "sfVertexArray_clear" 99 | sfVertexArray_clear :: VertexArray -> IO () 100 | 101 | --CSFML_GRAPHICS_API void sfVertexArray_clear(sfVertexArray* vertexArray); 102 | 103 | 104 | -- | Resize the vertex array. 105 | -- 106 | -- If vertex count is greater than the current size, the previous 107 | -- vertices are kept and new (default-constructed) vertices are 108 | -- added. 109 | -- 110 | -- If vertex count is less than the current size, existing vertices 111 | -- are removed from the array. 112 | resizeVA 113 | :: VertexArray 114 | -> Int -- ^ Vertex count; New size of the array (number of vertices) 115 | -> IO () 116 | 117 | resizeVA va size = sfVertexArray_resize va (fromIntegral size) 118 | 119 | foreign import ccall unsafe "sfVertexArray_resize" 120 | sfVertexArray_resize :: VertexArray -> CUInt -> IO () 121 | 122 | --CSFML_GRAPHICS_API void sfVertexArray_resize(sfVertexArray* vertexArray, unsigned int vertexCount); 123 | 124 | 125 | -- | Add a vertex to a vertex array array. 126 | appendVA :: VertexArray -> Vertex -> IO () 127 | appendVA va v = with v $ sfVertexArray_append_helper va 128 | 129 | foreign import ccall unsafe "sfVertexArray_append_helper" 130 | sfVertexArray_append_helper :: VertexArray -> Ptr Vertex -> IO () 131 | 132 | --CSFML_GRAPHICS_API void sfVertexArray_append(sfVertexArray* vertexArray, sfVertex vertex); 133 | 134 | 135 | -- | Set the type of primitives of a vertex array. 136 | -- 137 | -- This function defines how the vertices must be interpreted 138 | -- when it's time to draw them: 139 | -- 140 | -- * As points 141 | -- 142 | -- * As lines 143 | -- 144 | -- * As triangles 145 | -- 146 | -- * As quads 147 | -- 148 | -- The default primitive type is sfPoints. 149 | setPrimitiveType :: VertexArray -> PrimitiveType -> IO () 150 | setPrimitiveType va pt = sfVertexArray_setPrimitiveType va (fromIntegral . fromEnum $ pt) 151 | 152 | foreign import ccall unsafe "sfVertexArray_setPrimitiveType" 153 | sfVertexArray_setPrimitiveType :: VertexArray -> CInt -> IO () 154 | 155 | --CSFML_GRAPHICS_API void sfVertexArray_setPrimitiveType(sfVertexArray* vertexArray, sfPrimitiveType type); 156 | 157 | 158 | -- | Get the type of primitives drawn by a vertex array. 159 | getPrimitiveType :: VertexArray -> IO PrimitiveType 160 | getPrimitiveType = sfVertexArray_getPrimitiveType >=> return . toEnum . fromIntegral 161 | 162 | foreign import ccall unsafe "sfVertexArray_getPrimitiveType" 163 | sfVertexArray_getPrimitiveType :: VertexArray -> IO CInt 164 | 165 | --CSFML_GRAPHICS_API sfPrimitiveType sfVertexArray_getPrimitiveType(sfVertexArray* vertexArray); 166 | 167 | 168 | -- | Compute the bounding rectangle of a vertex array. 169 | -- 170 | -- This function returns the axis-aligned rectangle that 171 | -- contains all the vertices of the array. 172 | getVABounds :: VertexArray -> IO FloatRect 173 | getVABounds va = alloca $ \ptr -> sfVertexArray_getBounds_helper va ptr >> peek ptr 174 | 175 | foreign import ccall unsafe "sfVertexArray_getBounds_helper" 176 | sfVertexArray_getBounds_helper :: VertexArray -> Ptr FloatRect -> IO () 177 | 178 | --CSFML_GRAPHICS_API sfFloatRect sfVertexArray_getBounds(sfVertexArray* vertexArray); 179 | 180 | -------------------------------------------------------------------------------- /src/SFML/Graphics/View.hs: -------------------------------------------------------------------------------- 1 | module SFML.Graphics.View 2 | ( 3 | createView 4 | , viewFromRect 5 | , copyView 6 | , destroy 7 | , setViewCenter 8 | , setViewSize 9 | , setViewRotation 10 | , setViewport 11 | , resetView 12 | , getViewCenter 13 | , getViewSize 14 | , getViewRotation 15 | , getViewViewport 16 | , moveView 17 | , rotateView 18 | , zoomView 19 | ) 20 | where 21 | 22 | 23 | import SFML.Graphics.Rect 24 | import SFML.Graphics.Types 25 | import SFML.SFResource 26 | import SFML.System.Vector2 27 | 28 | import Control.Monad ((>=>)) 29 | import Foreign.C.Types 30 | import Foreign.Marshal.Alloc (alloca) 31 | import Foreign.Marshal.Utils (with) 32 | import Foreign.Ptr 33 | import Foreign.Storable (peek) 34 | 35 | 36 | -- | Create a default view. 37 | -- 38 | -- This function creates a default view of (0, 0, 1000, 1000) 39 | createView :: IO View 40 | createView = sfView_create 41 | 42 | foreign import ccall unsafe "sfView_create" 43 | sfView_create :: IO View 44 | 45 | --CSFML_GRAPHICS_API sfView* sfView_create(void); 46 | 47 | 48 | -- | Construct a view from a rectangle 49 | viewFromRect 50 | :: FloatRect -- ^ Rectangle defining the zone to display 51 | -> IO View 52 | 53 | viewFromRect rect = with rect sfView_createFromRect 54 | 55 | foreign import ccall unsafe "sfView_createFromRect_helper" 56 | sfView_createFromRect :: Ptr FloatRect -> IO View 57 | 58 | --CSFML_GRAPHICS_API sfView* sfView_createFromRect(sfFloatRect rectangle); 59 | 60 | 61 | -- | Copy an existing view. 62 | copyView :: View -> IO View 63 | copyView = sfView_copy 64 | 65 | foreign import ccall unsafe "sfView_copy" 66 | sfView_copy :: View -> IO View 67 | 68 | --CSFML_GRAPHICS_API sfView* sfView_copy(sfView* view); 69 | 70 | 71 | instance SFResource View where 72 | 73 | {-# INLINABLE destroy #-} 74 | destroy = sfView_destroy 75 | 76 | foreign import ccall unsafe "sfView_destroy" 77 | sfView_destroy :: View -> IO () 78 | 79 | --CSFML_GRAPHICS_API void sfView_destroy(sfView* view); 80 | 81 | 82 | -- | Set the center of a view. 83 | setViewCenter :: View -> Vec2f -> IO () 84 | setViewCenter view center = with center $ sfView_setCenter_helper view 85 | 86 | foreign import ccall unsafe "sfView_setCenter_helper" 87 | sfView_setCenter_helper :: View -> Ptr Vec2f -> IO () 88 | 89 | --CSFML_GRAPHICS_API void sfView_setCenter(sfView* view, sfVector2f center); 90 | 91 | 92 | -- | Set the size of a view. 93 | setViewSize :: View -> Vec2f -> IO () 94 | setViewSize view size = with size $ sfView_setSize_helper view 95 | 96 | foreign import ccall unsafe "sfView_setSize_helper" 97 | sfView_setSize_helper :: View -> Ptr Vec2f -> IO () 98 | 99 | --CSFML_GRAPHICS_API void sfView_setSize(sfView* view, sfVector2f size); 100 | 101 | 102 | -- | Set the orientation of a view. 103 | -- 104 | -- The default rotation of a view is 0 degrees. 105 | setViewRotation 106 | :: View -- ^ View object 107 | -> Float -- ^ New angle, in degrees 108 | -> IO () 109 | 110 | setViewRotation v r = sfView_setRotation v (realToFrac r) 111 | 112 | foreign import ccall unsafe "sfView_setRotation" 113 | sfView_setRotation :: View -> CFloat -> IO () 114 | 115 | --CSFML_GRAPHICS_API void sfView_setRotation(sfView* view, float angle); 116 | 117 | 118 | -- | Set the target viewport of a view 119 | -- 120 | -- The viewport is the rectangle into which the contents of the 121 | -- view are displayed, expressed as a factor (between 0 and 1) 122 | -- of the size of the render target to which the view is applied. 123 | -- For example, a view which takes the left side of the target would 124 | -- be defined by a rect of (0, 0, 0.5, 1). 125 | -- 126 | -- By default, a view has a viewport which covers the entire target. 127 | setViewport 128 | :: View -- ^ View object 129 | -> FloatRect -- ^ New viewport rectangle 130 | -> IO () 131 | 132 | setViewport view rect = with rect $ sfView_setViewport_helper view 133 | 134 | foreign import ccall unsafe "sfView_setViewport_helper" 135 | sfView_setViewport_helper :: View -> Ptr FloatRect -> IO () 136 | 137 | --CSFML_GRAPHICS_API void sfView_setViewport(sfView* view, sfFloatRect viewport); 138 | 139 | 140 | -- | Reset a view to the given rectangle. 141 | -- 142 | -- Note that this function resets the rotation angle to 0. 143 | resetView 144 | :: View -- ^ View object 145 | -> FloatRect -- ^ Rectangle defining the zone to display 146 | -> IO () 147 | 148 | resetView view rect = with rect $ sfView_reset_helper view 149 | 150 | foreign import ccall unsafe "sfView_reset_helper" 151 | sfView_reset_helper :: View -> Ptr FloatRect -> IO () 152 | 153 | --CSFML_GRAPHICS_API void sfView_reset(sfView* view, sfFloatRect rectangle); 154 | 155 | 156 | -- | Get the center of a view. 157 | getViewCenter :: View -> IO Vec2f 158 | getViewCenter view = alloca $ \ptr -> sfView_getCenter view ptr >> peek ptr 159 | 160 | foreign import ccall unsafe "sfView_getCenter" 161 | sfView_getCenter :: View -> Ptr Vec2f -> IO () 162 | 163 | --CSFML_GRAPHICS_API sfVector2f sfView_getCenter(const sfView* view); 164 | 165 | 166 | -- | Get the size of a view. 167 | getViewSize :: View -> IO Vec2f 168 | getViewSize view = alloca $ \ptr -> sfView_getSize_helper view ptr >> peek ptr 169 | 170 | foreign import ccall unsafe "sfView_getSize_helper" 171 | sfView_getSize_helper :: View -> Ptr Vec2f -> IO () 172 | 173 | --CSFML_GRAPHICS_API sfVector2f sfView_getSize(const sfView* view); 174 | 175 | 176 | -- | Get the current orientation of a view, in degrees. 177 | getViewRotation :: View -> IO Float 178 | getViewRotation = sfView_getRotation >=> return . realToFrac 179 | 180 | foreign import ccall unsafe "sfView_getRotation" 181 | sfView_getRotation :: View -> IO CFloat 182 | 183 | --CSFML_GRAPHICS_API float sfView_getRotation(const sfView* view); 184 | 185 | 186 | -- | Get the target viewport rectangle of a view, expressed as a factor of the target size. 187 | getViewViewport :: View -> IO FloatRect 188 | getViewViewport view = alloca $ \ptr -> sfView_getViewport_helper view ptr >> peek ptr 189 | 190 | foreign import ccall unsafe "sfView_getViewport_helper" 191 | sfView_getViewport_helper :: View -> Ptr FloatRect -> IO () 192 | 193 | --CSFML_GRAPHICS_API sfFloatRect sfView_getViewport(const sfView* view); 194 | 195 | 196 | -- | Move a view relatively to its current position. 197 | moveView 198 | :: View -- ^ View object 199 | -> Vec2f -- ^ Offset 200 | -> IO () 201 | 202 | moveView view pos = with pos $ sfView_move_helper view 203 | 204 | foreign import ccall unsafe "sfView_move_helper" 205 | sfView_move_helper :: View -> Ptr Vec2f -> IO () 206 | 207 | --CSFML_GRAPHICS_API void sfView_move(sfView* view, sfVector2f offset); 208 | 209 | 210 | -- | Rotate a view relatively to its current orientation. 211 | rotateView 212 | :: View -- ^ View object 213 | -> Float -- ^ Angle to rotate, in degrees 214 | -> IO () 215 | 216 | rotateView v a = sfView_rotate v (realToFrac a) 217 | 218 | foreign import ccall unsafe "sfView_rotate" 219 | sfView_rotate :: View -> CFloat -> IO () 220 | 221 | --CSFML_GRAPHICS_API void sfView_rotate(sfView* view, float angle); 222 | 223 | 224 | -- | Resize a view rectangle relatively to its current size 225 | -- 226 | -- Resizing the view simulates a zoom, as the zone displayed on 227 | -- screen grows or shrinks. 228 | -- 229 | -- factor is a multiplier: 230 | -- 231 | -- * 1 keeps the size unchanged 232 | -- 233 | -- * > 1 makes the view bigger (objects appear smaller) 234 | -- 235 | -- * < 1 makes the view smaller (objects appear bigger) 236 | zoomView 237 | :: View -- ^ View object 238 | -> Float -- ^ Zoom factor to apply 239 | -> IO () 240 | 241 | zoomView v z = sfView_zoom v (realToFrac z) 242 | 243 | foreign import ccall unsafe "sfView_zoom" 244 | sfView_zoom :: View -> CFloat -> IO () 245 | 246 | --CSFML_GRAPHICS_API void sfView_zoom(sfView* view, float factor); 247 | 248 | -------------------------------------------------------------------------------- /src/SFML/SFCopyable.hs: -------------------------------------------------------------------------------- 1 | module SFML.SFCopyable 2 | where 3 | 4 | 5 | class SFCopyable a where 6 | 7 | -- | Copy the given SFML resource. 8 | copy :: a -> IO a 9 | 10 | -------------------------------------------------------------------------------- /src/SFML/SFDisplayable.hs: -------------------------------------------------------------------------------- 1 | module SFML.SFDisplayable 2 | where 3 | 4 | 5 | class SFDisplayable a where 6 | 7 | -- | Update the target's contents. 8 | display :: a -> IO () 9 | 10 | -------------------------------------------------------------------------------- /src/SFML/SFException.hs: -------------------------------------------------------------------------------- 1 | {-# LANGUAGE DeriveDataTypeable #-} 2 | module SFML.SFException where 3 | 4 | import Control.Exception 5 | import Data.Typeable 6 | 7 | data SFException = SFException String deriving (Show, Typeable) 8 | 9 | instance Exception SFException 10 | -------------------------------------------------------------------------------- /src/SFML/SFResource.hs: -------------------------------------------------------------------------------- 1 | module SFML.SFResource 2 | where 3 | 4 | 5 | class SFResource a where 6 | 7 | -- | Destroy the given SFML resource. 8 | destroy :: a -> IO () 9 | 10 | -------------------------------------------------------------------------------- /src/SFML/System.hs: -------------------------------------------------------------------------------- 1 | module SFML.System 2 | ( 3 | module SFML.System.Clock 4 | , module SFML.System.Sleep 5 | , module SFML.System.Time 6 | , module SFML.System.Vector2 7 | , module SFML.System.Vector3 8 | ) 9 | where 10 | 11 | 12 | import SFML.System.Clock 13 | import SFML.System.Sleep 14 | import SFML.System.Time 15 | import SFML.System.Vector2 16 | import SFML.System.Vector3 17 | 18 | -------------------------------------------------------------------------------- /src/SFML/System/Clock.hs: -------------------------------------------------------------------------------- 1 | {-# LANGUAGE CPP, ForeignFunctionInterface #-} 2 | module SFML.System.Clock 3 | ( 4 | Clock(..) 5 | , createClock 6 | , copy 7 | , destroy 8 | , getElapsedTime 9 | , restartClock 10 | ) 11 | where 12 | 13 | 14 | import SFML.SFCopyable 15 | import SFML.SFResource 16 | import SFML.System.Time 17 | 18 | import Foreign.Marshal.Alloc (alloca) 19 | import Foreign.Ptr 20 | import Foreign.Storable (peek) 21 | 22 | 23 | newtype Clock = Clock (Ptr Clock) 24 | 25 | 26 | -- | Create a new clock and start it. 27 | createClock :: IO Clock 28 | createClock = sfClock_create 29 | 30 | foreign import ccall unsafe "sfClock_create" 31 | sfClock_create :: IO Clock 32 | 33 | --CSFML_SYSTEM_API sfClock* sfClock_create(void); 34 | 35 | 36 | instance SFCopyable Clock where 37 | 38 | {-# INLINABLE copy #-} 39 | copy = sfClock_copy 40 | 41 | 42 | foreign import ccall unsafe "sfClock_copy" 43 | sfClock_copy :: Clock -> IO Clock 44 | 45 | --CSFML_SYSTEM_API sfClock* sfClock_copy(sfClock* clock); 46 | 47 | 48 | instance SFResource Clock where 49 | 50 | {-# INLINABLE destroy #-} 51 | destroy = sfClock_destroy 52 | 53 | foreign import ccall unsafe "sfClock_destroy" 54 | sfClock_destroy :: Clock -> IO () 55 | 56 | --CSFML_SYSTEM_API void sfClock_destroy(sfClock* clock); 57 | 58 | 59 | -- | Get the time elapsed in a clock. 60 | -- 61 | -- This function returns the time elapsed since the last call 62 | -- to sfClock_restart (or the construction of the object if 63 | -- sfClock_restart has not been called). 64 | 65 | getElapsedTime :: Clock -> IO Time 66 | getElapsedTime clock = alloca $ \ptr -> sfClock_getElapsedTime_helper clock ptr >> peek ptr 67 | 68 | foreign import ccall unsafe "sfClock_getElapsedTime_helper" 69 | sfClock_getElapsedTime_helper :: Clock -> Ptr Time -> IO () 70 | 71 | --CSFML_SYSTEM_API sfTime sfClock_getElapsedTime(const sfClock* clock); 72 | 73 | 74 | -- | Restart a clock. 75 | -- 76 | -- This function puts the time counter back to zero. 77 | -- It also returns the time elapsed since the clock was started. 78 | 79 | restartClock :: Clock -> IO Time 80 | restartClock clock = alloca $ \ptr -> sfClock_restart_helper clock ptr >> peek ptr 81 | 82 | foreign import ccall unsafe "sfClock_restart_helper" 83 | sfClock_restart_helper :: Clock -> Ptr Time -> IO () 84 | 85 | --CSFML_SYSTEM_API sfTime sfClock_restart(sfClock* clock); 86 | 87 | -------------------------------------------------------------------------------- /src/SFML/System/InputStream.hsc: -------------------------------------------------------------------------------- 1 | {-# LANGUAGE CPP, ForeignFunctionInterface, ExistentialQuantification #-} 2 | module SFML.System.InputStream 3 | ( 4 | InputStreamReadFunc 5 | , InputStreamSeekFunc 6 | , InputStreamTellFunc 7 | , InputStreamGetSizeFunc 8 | , InputStream(..) 9 | ) 10 | where 11 | 12 | 13 | import Control.Applicative ((<$>), (<*>)) 14 | import Data.Word (Word64) 15 | import Foreign.C.Types (CInt) 16 | import Foreign.Ptr (Ptr) 17 | import Foreign.Storable 18 | 19 | 20 | #include 21 | 22 | 23 | -- | Function to read data from the stream. 24 | type InputStreamReadFunc a 25 | = Ptr Char -- ^ Buffer where to copy the read data 26 | -> Word64 -- ^ Desired number of bytes to read 27 | -> Ptr a -- ^ User data 28 | -> IO Word64 -- ^ The number of bytes actually read 29 | 30 | -- | Function to set the current read position. 31 | type InputStreamSeekFunc a 32 | = Word64 -- ^ The position to seek to, from the beginning 33 | -> Ptr a -- ^ User data 34 | -> IO Word64 -- ^ The position actually sought to, or -1 on error 35 | 36 | -- | Function to get the current read position. 37 | type InputStreamTellFunc a 38 | = Ptr a -- ^ User data 39 | -> IO Word64 -- ^ The current position, or -1 on error 40 | 41 | -- | Function to get the total number of bytes in the stream. 42 | type InputStreamGetSizeFunc a 43 | = Ptr a -- ^ User data 44 | -> IO Word64 -- ^ The total number of bytes available in the stream, or -1 on error 45 | 46 | 47 | -- | Set of callbacks that allow users to define custom file streams. 48 | data InputStream = forall a. InputStream 49 | { read :: Ptr (InputStreamReadFunc a) 50 | , seek :: Ptr (InputStreamSeekFunc a) 51 | , tell :: Ptr (InputStreamTellFunc a) 52 | , getSize :: Ptr (InputStreamGetSizeFunc a) 53 | , userData :: Ptr a 54 | } 55 | 56 | instance Storable InputStream where 57 | sizeOf _ = size_InputStream 58 | alignment _ = alignment (undefined :: CInt) 59 | 60 | peek ptr = InputStream 61 | <$> #{peek sfInputStream, read} ptr 62 | <*> #{peek sfInputStream, seek} ptr 63 | <*> #{peek sfInputStream, tell} ptr 64 | <*> #{peek sfInputStream, getSize} ptr 65 | <*> #{peek sfInputStream, userData} ptr 66 | 67 | poke ptr (InputStream read seek tell gets udata) = do 68 | #{poke sfInputStream, read} ptr read 69 | #{poke sfInputStream, seek} ptr seek 70 | #{poke sfInputStream, tell} ptr tell 71 | #{poke sfInputStream, getSize} ptr gets 72 | #{poke sfInputStream, userData} ptr udata 73 | 74 | 75 | size_InputStream = #{size sfInputStream} 76 | 77 | 78 | instance Show InputStream where 79 | 80 | show (InputStream read seek tell getSize userData) = 81 | "InputStream { read = " ++ show read ++ 82 | ", seek = " ++ show seek ++ 83 | ", tell = " ++ show tell ++ 84 | ", getSize = " ++ show getSize ++ 85 | ", userData = " ++ show userData ++ 86 | "}" 87 | 88 | -------------------------------------------------------------------------------- /src/SFML/System/Sleep.hsc: -------------------------------------------------------------------------------- 1 | {-# LANGUAGE CPP, ForeignFunctionInterface #-} 2 | module SFML.System.Sleep 3 | ( 4 | sfSleep 5 | ) 6 | where 7 | 8 | 9 | import SFML.System.Time 10 | 11 | import Foreign.Marshal.Utils (with) 12 | import Foreign.Ptr (Ptr) 13 | 14 | 15 | -- | Make the current thread sleep for a given duration. 16 | -- 17 | -- sfSleep is the best way to block a program or one of its 18 | -- threads, as it doesn't consume any CPU power. 19 | 20 | sfSleep :: Time -> IO () 21 | sfSleep t = with t sfSleep_helper 22 | 23 | foreign import ccall unsafe "sfSleep_helper" 24 | sfSleep_helper :: Ptr Time -> IO () 25 | 26 | --CSFML_SYSTEM_API void sfSleep(sfTime duration); 27 | 28 | -------------------------------------------------------------------------------- /src/SFML/System/Time.hsc: -------------------------------------------------------------------------------- 1 | {-# LANGUAGE CPP, ForeignFunctionInterface #-} 2 | module SFML.System.Time 3 | ( 4 | Time 5 | , timeZero 6 | , asSeconds 7 | , asMilliseconds 8 | , asMicroseconds 9 | , seconds 10 | , milliseconds 11 | , microseconds 12 | ) 13 | where 14 | 15 | 16 | import Control.Monad ((>=>)) 17 | import Data.Int (Int64, Int32) 18 | import Foreign.C.Types 19 | import Foreign.Marshal.Alloc (alloca) 20 | import Foreign.Ptr 21 | import Foreign.Storable 22 | import System.IO.Unsafe (unsafePerformIO) 23 | 24 | #include 25 | 26 | sizeInt64 = #{size sfInt64} 27 | 28 | type Time = Int64 29 | 30 | 31 | -- | Predefined "zero" time value. 32 | timeZero :: Time 33 | timeZero = 0 34 | 35 | --CSFML_SYSTEM_API sfTime sfTime_Zero; 36 | 37 | 38 | -- | Return a time value as a number of seconds. 39 | asSeconds :: Time -> Float 40 | asSeconds = realToFrac . sfTime_asSeconds 41 | 42 | foreign import ccall unsafe "sfTime_asSeconds" 43 | sfTime_asSeconds :: Time -> CFloat 44 | 45 | --CSFML_SYSTEM_API float sfTime_asSeconds(sfTime time); 46 | 47 | 48 | -- | Return a time value as a number of milliseconds. 49 | asMilliseconds :: Time -> Int 50 | asMilliseconds t = fromIntegral $ sfTime_asMilliseconds t 51 | 52 | foreign import ccall unsafe "sfTime_asMilliseconds" 53 | sfTime_asMilliseconds :: Time -> Int32 54 | 55 | --CSFML_SYSTEM_API sfInt32 sfTime_asMilliseconds(sfTime time); 56 | 57 | 58 | -- | Return a time value as a number of microseconds. 59 | asMicroseconds :: Time -> Int64 60 | asMicroseconds t = sfTime_asMicroseconds t 61 | 62 | foreign import ccall unsafe "sfTime_asMicroseconds" 63 | sfTime_asMicroseconds :: Time -> Int64 64 | 65 | --CSFML_SYSTEM_API sfInt64 sfTime_asMicroseconds(sfTime time); 66 | 67 | 68 | -- | Construct a time value from a number of seconds. 69 | seconds 70 | :: Float -- ^ Number of seconds 71 | -> Time 72 | seconds s = unsafePerformIO $ alloca $ \ptr -> sfSeconds_helper (realToFrac s) ptr >> peek ptr 73 | 74 | foreign import ccall unsafe "sfSeconds_helper" 75 | sfSeconds_helper :: CFloat -> Ptr Time -> IO () 76 | 77 | --CSFML_SYSTEM_API sfTime sfSeconds(float amount); 78 | 79 | 80 | -- | Construct a time value from a number of milliseconds. 81 | milliseconds 82 | :: Int -- ^ Number of milliseconds 83 | -> Time 84 | milliseconds t = 85 | unsafePerformIO $ alloca $ \ptr -> sfMilliseconds_helper (fromIntegral t) ptr >> peek ptr 86 | 87 | foreign import ccall unsafe "sfMilliseconds_helper" 88 | sfMilliseconds_helper :: Int32 -> Ptr Time -> IO () 89 | 90 | --CSFML_SYSTEM_API sfTime sfMilliseconds(sfInt32 amount); 91 | 92 | 93 | -- | Construct a time value from a number of microseconds. 94 | microseconds 95 | :: Int64 -- ^ Number of microseconds 96 | -> Time 97 | microseconds t = unsafePerformIO $ alloca $ \ptr -> sfMicroseconds_helper t ptr >> peek ptr 98 | 99 | foreign import ccall unsafe "sfMicroseconds_helper" 100 | sfMicroseconds_helper :: Int64 -> Ptr Time -> IO () 101 | 102 | --CSFML_SYSTEM_API sfTime sfMicroseconds(sfInt64 amount); 103 | 104 | -------------------------------------------------------------------------------- /src/SFML/System/Vector2.hsc: -------------------------------------------------------------------------------- 1 | {-# LANGUAGE CPP, ForeignFunctionInterface #-} 2 | module SFML.System.Vector2 3 | ( 4 | Vec2i(..) 5 | , Vec2u(..) 6 | , Vec2f(..) 7 | ) 8 | where 9 | 10 | 11 | import Control.Applicative ((<$>), (<*>)) 12 | import Data.Word 13 | import Foreign.C.Types 14 | import Foreign.Storable 15 | 16 | #include 17 | 18 | 19 | sizeFloat = #{size float} 20 | sizeInt = #{size int} 21 | 22 | 23 | data Vec2i = Vec2i {-# UNPACK #-} !Int {-# UNPACK #-} !Int deriving Show 24 | 25 | 26 | instance Storable Vec2i where 27 | sizeOf _ = 2*sizeInt 28 | alignment _ = alignment (undefined :: CInt) 29 | 30 | peek ptr = Vec2i 31 | <$> fmap fromIntegral (#{peek sfVector2i, x} ptr :: IO CInt) 32 | <*> fmap fromIntegral (#{peek sfVector2i, y} ptr :: IO CInt) 33 | 34 | poke ptr (Vec2i x y) = do 35 | #{poke sfVector2i, x} ptr (fromIntegral x :: CInt) 36 | #{poke sfVector2i, y} ptr (fromIntegral y :: CInt) 37 | 38 | 39 | instance Num Vec2i where 40 | Vec2i ax ay + Vec2i bx by = Vec2i (ax + bx) (ay + by) 41 | Vec2i ax ay - Vec2i bx by = Vec2i (ax - bx) (ay - by) 42 | Vec2i ax ay * Vec2i bx by = Vec2i (ax * bx) (ay * by) 43 | abs (Vec2i ax ay) = Vec2i (abs ax) (abs ay) 44 | signum (Vec2i ax ay) = Vec2i (signum ax) (signum ay) 45 | fromInteger i = Vec2i i' i' where i' = fromInteger i 46 | 47 | 48 | data Vec2u = Vec2u {-# UNPACK #-} !Word {-# UNPACK #-} !Word deriving Show 49 | 50 | 51 | instance Storable Vec2u where 52 | sizeOf _ = 2*sizeInt 53 | alignment _ = alignment (undefined :: CUInt) 54 | 55 | peek ptr = Vec2u 56 | <$> fmap fromIntegral (#{peek sfVector2u, x} ptr :: IO CUInt) 57 | <*> fmap fromIntegral (#{peek sfVector2u, y} ptr :: IO CUInt) 58 | 59 | poke ptr (Vec2u x y) = do 60 | #{poke sfVector2u, x} ptr (fromIntegral x :: CUInt) 61 | #{poke sfVector2u, y} ptr (fromIntegral y :: CUInt) 62 | 63 | 64 | instance Num Vec2u where 65 | Vec2u ax ay + Vec2u bx by = Vec2u (ax + bx) (ay + by) 66 | Vec2u ax ay - Vec2u bx by = Vec2u (ax - bx) (ay - by) 67 | Vec2u ax ay * Vec2u bx by = Vec2u (ax * bx) (ay * by) 68 | abs (Vec2u ax ay) = Vec2u (abs ax) (abs ay) 69 | signum (Vec2u ax ay) = Vec2u (signum ax) (signum ay) 70 | fromInteger i = Vec2u i' i' where i' = fromInteger i 71 | 72 | 73 | data Vec2f = Vec2f {-# UNPACK #-} !Float {-# UNPACK #-} !Float deriving Show 74 | 75 | 76 | instance Storable Vec2f where 77 | sizeOf _ = 2*sizeFloat 78 | alignment _ = alignment (undefined :: CFloat) 79 | 80 | peek ptr = Vec2f 81 | <$> fmap realToFrac (#{peek sfVector2f, x} ptr :: IO CFloat) 82 | <*> fmap realToFrac (#{peek sfVector2f, y} ptr :: IO CFloat) 83 | 84 | poke ptr (Vec2f x y) = do 85 | #{poke sfVector2f, x} ptr (realToFrac x :: CFloat) 86 | #{poke sfVector2f, y} ptr (realToFrac y :: CFloat) 87 | 88 | 89 | instance Num Vec2f where 90 | Vec2f ax ay + Vec2f bx by = Vec2f (ax + bx) (ay + by) 91 | Vec2f ax ay - Vec2f bx by = Vec2f (ax - bx) (ay - by) 92 | Vec2f ax ay * Vec2f bx by = Vec2f (ax * bx) (ay * by) 93 | abs (Vec2f ax ay) = Vec2f (abs ax) (abs ay) 94 | signum (Vec2f ax ay) = Vec2f (signum ax) (signum ay) 95 | fromInteger i = Vec2f i' i' where i' = fromInteger i 96 | 97 | 98 | instance Fractional Vec2f where 99 | Vec2f ax ay / Vec2f bx by = Vec2f (ax / bx) (ay / by) 100 | fromRational r = Vec2f r' r' where r' = fromRational r 101 | 102 | -------------------------------------------------------------------------------- /src/SFML/System/Vector3.hsc: -------------------------------------------------------------------------------- 1 | {-# LANGUAGE CPP, ForeignFunctionInterface #-} 2 | module SFML.System.Vector3 3 | ( 4 | Vec3f(..) 5 | ) 6 | where 7 | 8 | 9 | import Control.Applicative ((<$>), (<*>)) 10 | import Foreign.C.Types 11 | import Foreign.Storable 12 | 13 | #include 14 | 15 | 16 | sizeFloat = #{size float} 17 | 18 | 19 | data Vec3f = Vec3f {-# UNPACK #-} !Float {-# UNPACK #-} !Float {-# UNPACK #-} !Float deriving Show 20 | 21 | 22 | instance Storable Vec3f where 23 | sizeOf _ = 3*sizeFloat 24 | alignment _ = alignment (undefined :: CFloat) 25 | 26 | peek ptr = Vec3f 27 | <$> fmap realToFrac (#{peek sfVector3f, x} ptr :: IO CFloat) 28 | <*> fmap realToFrac (#{peek sfVector3f, y} ptr :: IO CFloat) 29 | <*> fmap realToFrac (#{peek sfVector3f, z} ptr :: IO CFloat) 30 | 31 | poke ptr (Vec3f x y z) = do 32 | #{poke sfVector3f, x} ptr (realToFrac x :: CFloat) 33 | #{poke sfVector3f, y} ptr (realToFrac y :: CFloat) 34 | #{poke sfVector3f, z} ptr (realToFrac z :: CFloat) 35 | 36 | -------------------------------------------------------------------------------- /src/SFML/Utils.hs: -------------------------------------------------------------------------------- 1 | module SFML.Utils 2 | ( 3 | err 4 | , tagErr 5 | ) 6 | where 7 | 8 | 9 | import Control.Exception (Exception, throwIO) 10 | 11 | 12 | -- | Run the given IO action and throw an error if it fails. 13 | err :: Exception e => IO (Either e a) -> IO a 14 | err = (either throwIO return =<<) 15 | 16 | 17 | -- | Potentially tag a 'Maybe' value with an error. 18 | tagErr :: e -> Maybe a -> Either e a 19 | tagErr err Nothing = Left err 20 | tagErr err (Just x) = Right x 21 | 22 | -------------------------------------------------------------------------------- /src/SFML/Window.hs: -------------------------------------------------------------------------------- 1 | module SFML.Window 2 | ( 3 | module SFML.System 4 | , module SFML.Window.Context 5 | , module SFML.Window.ContextSettings 6 | , module SFML.Window.Event 7 | , module SFML.Window.Joystick 8 | , module SFML.Window.Keyboard 9 | , module SFML.Window.Mouse 10 | , module SFML.Window.SFWindow 11 | , module SFML.Window.Types 12 | , module SFML.Window.VideoMode 13 | , module SFML.Window.Window 14 | ) 15 | where 16 | 17 | 18 | import SFML.System 19 | import SFML.Window.Context 20 | import SFML.Window.ContextSettings 21 | import SFML.Window.Event 22 | import SFML.Window.Joystick 23 | import SFML.Window.Keyboard 24 | import SFML.Window.Mouse 25 | import SFML.Window.SFWindow 26 | import SFML.Window.Types 27 | import SFML.Window.VideoMode 28 | import SFML.Window.Window 29 | 30 | -------------------------------------------------------------------------------- /src/SFML/Window/Context.hsc: -------------------------------------------------------------------------------- 1 | {-# LANGUAGE CPP, ForeignFunctionInterface #-} 2 | module SFML.Window.Context 3 | ( 4 | createContext 5 | , destroy 6 | , setActiveContext 7 | ) 8 | where 9 | 10 | 11 | import SFML.SFResource 12 | import SFML.Window.Types 13 | 14 | import Foreign.C.Types 15 | 16 | #include 17 | 18 | 19 | -- | Create a new context. 20 | -- 21 | -- This function activates the new context. 22 | createContext = sfContext_create 23 | 24 | foreign import ccall unsafe "sfContext_create" 25 | sfContext_create :: IO Context 26 | 27 | -- CSFML_WINDOW_API sfContext* sfContext_create(void); 28 | 29 | 30 | instance SFResource Context where 31 | 32 | {-# INLINABLE destroy #-} 33 | destroy = sfContext_destroy 34 | 35 | foreign import ccall unsafe "sfContext_destroy" 36 | sfContext_destroy :: Context -> IO () 37 | 38 | -- CSFML_WINDOW_API void sfContext_destroy(sfContext* context); 39 | 40 | 41 | -- | Activate or deactivate explicitely a context. 42 | setActiveContext :: Context -> Bool -> IO () 43 | setActiveContext ctx val = sfContext_setActive ctx (fromIntegral . fromEnum $ val) 44 | 45 | foreign import ccall unsafe "sfContext_setActive" 46 | sfContext_setActive :: Context -> CInt -> IO () 47 | 48 | -- CSFML_WINDOW_API void sfContext_setActive(sfContext* context, sfBool active); 49 | 50 | -------------------------------------------------------------------------------- /src/SFML/Window/ContextSettings.hsc: -------------------------------------------------------------------------------- 1 | {-# LANGUAGE CPP, ForeignFunctionInterface #-} 2 | module SFML.Window.ContextSettings 3 | ( 4 | ContextSettings(..) 5 | , ContextAttribute(..) 6 | ) 7 | where 8 | 9 | 10 | import Control.Applicative ((<$>), (<*>)) 11 | import Data.Word (Word32) 12 | import Foreign.C.Types 13 | import Foreign.Storable 14 | 15 | 16 | #include 17 | 18 | 19 | data ContextSettings = ContextSettings 20 | { depthBits :: Int -- ^ Bits of the depth buffer 21 | , stencilBits :: Int -- ^ Bits of the stencil buffer 22 | , antialiasingLevel :: Int -- ^ Level of antialiasing 23 | , majorVersion :: Int -- ^ Major number of the context version to create 24 | , minorVersion :: Int -- ^ Minor number of the context version to create 25 | , attributeFlags :: [ContextAttribute] -- ^ The attribute flags to create the context with 26 | } 27 | deriving (Show) 28 | 29 | 30 | instance Storable ContextSettings where 31 | sizeOf _ = #{size sfContextSettings} 32 | alignment _ = #{alignment sfContextSettings} 33 | 34 | peek ptr = ContextSettings 35 | <$> fmap fromIntegral (#{peek sfContextSettings, depthBits} ptr :: IO CInt) 36 | <*> fmap fromIntegral (#{peek sfContextSettings, stencilBits} ptr :: IO CInt) 37 | <*> fmap fromIntegral (#{peek sfContextSettings, antialiasingLevel} ptr :: IO CInt) 38 | <*> fmap fromIntegral (#{peek sfContextSettings, majorVersion} ptr :: IO CInt) 39 | <*> fmap fromIntegral (#{peek sfContextSettings, minorVersion} ptr :: IO CInt) 40 | <*> fmap (toFlags . fromIntegral) (#{peek sfContextSettings, attributeFlags} ptr :: IO Word32) 41 | 42 | poke ptr (ContextSettings db sb al ma mi af) = do 43 | #{poke sfContextSettings, depthBits} ptr (fromIntegral db :: CInt) 44 | #{poke sfContextSettings, stencilBits} ptr (fromIntegral sb :: CInt) 45 | #{poke sfContextSettings, antialiasingLevel} ptr (fromIntegral al :: CInt) 46 | #{poke sfContextSettings, majorVersion} ptr (fromIntegral ma :: CInt) 47 | #{poke sfContextSettings, minorVersion} ptr (fromIntegral mi :: CInt) 48 | #{poke sfContextSettings, attributeFlags} ptr ((fromIntegral . fromFlags) af :: Word32) 49 | 50 | 51 | data ContextAttribute 52 | = ContextDefault -- ^ Non-debug, compatibility context (this and the core attribute are mutually exclusive) 53 | | ContextCore -- ^ Core attribute 54 | | ContextDebug -- ^ Debug attribute 55 | deriving (Eq, Show) 56 | 57 | 58 | instance Enum ContextAttribute where 59 | 60 | fromEnum ContextDefault = 0 61 | fromEnum ContextCore = 1 62 | fromEnum ContextDebug = 2 63 | 64 | toEnum 0 = ContextDefault 65 | toEnum 1 = ContextCore 66 | toEnum 2 = ContextDebug 67 | 68 | fromFlags :: [ContextAttribute] -> Int 69 | fromFlags = sum . map fromEnum 70 | 71 | toFlags :: Int -> [ContextAttribute] 72 | toFlags = return . toEnum 73 | -------------------------------------------------------------------------------- /src/SFML/Window/Event.hsc: -------------------------------------------------------------------------------- 1 | {-# LANGUAGE CPP, ForeignFunctionInterface #-} 2 | module SFML.Window.Event 3 | ( 4 | SFEvent(..) 5 | ) 6 | where 7 | 8 | 9 | import SFML.Window.Joystick 10 | import SFML.Window.Keyboard 11 | import SFML.Window.Mouse 12 | 13 | import Control.Applicative ((<$>), (<*>)) 14 | import Foreign.C.String 15 | import Foreign.C.Types 16 | import Foreign.Marshal.Array 17 | import Foreign.Ptr 18 | import Foreign.Storable 19 | 20 | #include 21 | 22 | 23 | data SFEvent 24 | = SFEvtClosed 25 | | SFEvtResized 26 | { width :: Int 27 | , height :: Int 28 | } 29 | | SFEvtLostFocus 30 | | SFEvtGainedFocus 31 | | SFEvtTextEntered 32 | { text :: String 33 | } 34 | | SFEvtKeyPressed 35 | { code :: KeyCode 36 | , alt :: Bool 37 | , ctrl :: Bool 38 | , shift :: Bool 39 | , sys :: Bool 40 | } 41 | | SFEvtKeyReleased 42 | { code :: KeyCode 43 | , alt :: Bool 44 | , ctrl :: Bool 45 | , shift :: Bool 46 | , sys :: Bool 47 | } 48 | | SFEvtMouseWheelMoved 49 | { moveDelta :: Int 50 | , x :: Int 51 | , y :: Int 52 | } 53 | | SFEvtMouseWheelScrolled 54 | { wheel :: MouseWheel 55 | , scrollDelta :: Float 56 | , x :: Int 57 | , y :: Int 58 | } 59 | | SFEvtMouseButtonPressed 60 | { button :: MouseButton 61 | , x :: Int 62 | , y :: Int 63 | } 64 | | SFEvtMouseButtonReleased 65 | { button :: MouseButton 66 | , x :: Int 67 | , y :: Int 68 | } 69 | | SFEvtMouseMoved 70 | { x :: Int 71 | , y :: Int 72 | } 73 | | SFEvtMouseEntered 74 | | SFEvtMouseLeft 75 | | SFEvtJoystickButtonPressed 76 | { joystickId :: Int 77 | , joystickBt :: Int 78 | } 79 | | SFEvtJoystickButtonReleased 80 | { joystickId :: Int 81 | , joystickBt :: Int 82 | } 83 | | SFEvtJoystickMoved 84 | { joystickId :: Int 85 | , joystickAxis :: JoystickAxis 86 | , position :: Float 87 | } 88 | | SFEvtJoystickConnected 89 | { joystickId :: Int 90 | } 91 | | SFEvtJoystickDisconnected 92 | { joystickId :: Int 93 | } 94 | | SFEvtTouchBegan 95 | { finger :: Int 96 | , x :: Int 97 | , y :: Int 98 | } 99 | | SFEvtTouchMoved 100 | { finger :: Int 101 | , x :: Int 102 | , y :: Int 103 | } 104 | | SFEvtTouchEnded 105 | { finger :: Int 106 | , x :: Int 107 | , y :: Int 108 | } 109 | deriving (Eq, Show) 110 | 111 | 112 | sizeInt = #{size int} 113 | sizeChar = #{size char} 114 | 115 | 116 | instance Storable SFEvent where 117 | sizeOf _ = #{size sfEvent} 118 | alignment _ = alignment (undefined :: CInt) 119 | 120 | peek ptr' = 121 | let ptr'' = castPtr ptr' :: Ptr CInt 122 | in do 123 | let ptr = castPtr ptr'' 124 | eventType <- peek ptr'' :: IO CInt 125 | case eventType of 126 | 0 -> return SFEvtClosed 127 | 1 -> SFEvtResized 128 | <$> fmap fromIntegral (#{peek sfSizeEvent, width} ptr :: IO CUInt) 129 | <*> fmap fromIntegral (#{peek sfSizeEvent, height} ptr :: IO CUInt) 130 | 2 -> return SFEvtLostFocus 131 | 3 -> return SFEvtGainedFocus 132 | 4 -> peekCAString (plusPtr ptr sizeInt) >>= return . SFEvtTextEntered 133 | 5 -> SFEvtKeyPressed 134 | <$> #{peek sfKeyEvent, code} ptr 135 | <*> fmap (toEnum . fromIntegral) (#{peek sfKeyEvent, alt} ptr :: IO CInt) 136 | <*> fmap (toEnum . fromIntegral) (#{peek sfKeyEvent, control} ptr :: IO CInt) 137 | <*> fmap (toEnum . fromIntegral) (#{peek sfKeyEvent, shift} ptr :: IO CInt) 138 | <*> fmap (toEnum . fromIntegral) (#{peek sfKeyEvent, system} ptr :: IO CInt) 139 | 6 -> SFEvtKeyReleased 140 | <$> #{peek sfKeyEvent, code} ptr 141 | <*> fmap (toEnum . fromIntegral) (#{peek sfKeyEvent, alt} ptr :: IO CInt) 142 | <*> fmap (toEnum . fromIntegral) (#{peek sfKeyEvent, control} ptr :: IO CInt) 143 | <*> fmap (toEnum . fromIntegral) (#{peek sfKeyEvent, shift} ptr :: IO CInt) 144 | <*> fmap (toEnum . fromIntegral) (#{peek sfKeyEvent, system} ptr :: IO CInt) 145 | 7 -> SFEvtMouseWheelMoved 146 | <$> fmap fromIntegral (#{peek sfMouseWheelEvent, delta} ptr :: IO CInt) 147 | <*> fmap fromIntegral (#{peek sfMouseWheelEvent, x} ptr :: IO CInt) 148 | <*> fmap fromIntegral (#{peek sfMouseWheelEvent, y} ptr :: IO CInt) 149 | 8 -> SFEvtMouseWheelScrolled 150 | <$> (#{peek sfMouseWheelScrollEvent, wheel} ptr :: IO MouseWheel) 151 | <*> fmap realToFrac (#{peek sfMouseWheelScrollEvent, delta} ptr :: IO CFloat) 152 | <*> fmap fromIntegral (#{peek sfMouseWheelScrollEvent, x} ptr :: IO CInt) 153 | <*> fmap fromIntegral (#{peek sfMouseWheelScrollEvent, y} ptr :: IO CInt) 154 | 9 -> SFEvtMouseButtonPressed 155 | <$> #{peek sfMouseButtonEvent, button} ptr 156 | <*> fmap fromIntegral (#{peek sfMouseButtonEvent, x} ptr :: IO CInt) 157 | <*> fmap fromIntegral (#{peek sfMouseButtonEvent, y} ptr :: IO CInt) 158 | 10 -> SFEvtMouseButtonReleased 159 | <$> #{peek sfMouseButtonEvent, button} ptr 160 | <*> fmap fromIntegral (#{peek sfMouseButtonEvent, x} ptr :: IO CInt) 161 | <*> fmap fromIntegral (#{peek sfMouseButtonEvent, y} ptr :: IO CInt) 162 | 11 -> SFEvtMouseMoved 163 | <$> fmap fromIntegral (#{peek sfMouseMoveEvent, x} ptr :: IO CInt) 164 | <*> fmap fromIntegral (#{peek sfMouseMoveEvent, y} ptr :: IO CInt) 165 | 12 -> return SFEvtMouseEntered 166 | 13 -> return SFEvtMouseLeft 167 | 14 -> SFEvtJoystickButtonPressed 168 | <$> fmap fromIntegral (#{peek sfJoystickButtonEvent, joystickId} ptr :: IO CUInt) 169 | <*> fmap fromIntegral (#{peek sfJoystickButtonEvent, button} ptr :: IO CUInt) 170 | 15 -> SFEvtJoystickButtonReleased 171 | <$> fmap fromIntegral (#{peek sfJoystickButtonEvent, joystickId} ptr :: IO CUInt) 172 | <*> fmap fromIntegral (#{peek sfJoystickButtonEvent, button} ptr :: IO CUInt) 173 | 16 -> SFEvtJoystickMoved 174 | <$> fmap fromIntegral (#{peek sfJoystickMoveEvent, joystickId} ptr :: IO CUInt) 175 | <*> #{peek sfJoystickMoveEvent, axis} ptr 176 | <*> fmap realToFrac (#{peek sfJoystickMoveEvent, position} ptr :: IO CFloat) 177 | 17 -> peekByteOff ptr sizeInt >>= return . SFEvtJoystickConnected 178 | 18 -> peekByteOff ptr sizeInt >>= return . SFEvtJoystickDisconnected 179 | 19 -> SFEvtTouchBegan 180 | <$> fmap fromIntegral (#{peek sfTouchEvent, finger} ptr :: IO CUInt) 181 | <*> fmap fromIntegral (#{peek sfTouchEvent, x} ptr :: IO CInt) 182 | <*> fmap fromIntegral (#{peek sfTouchEvent, y} ptr :: IO CInt) 183 | 20 -> SFEvtTouchMoved 184 | <$> fmap fromIntegral (#{peek sfTouchEvent, finger} ptr :: IO CUInt) 185 | <*> fmap fromIntegral (#{peek sfTouchEvent, x} ptr :: IO CInt) 186 | <*> fmap fromIntegral (#{peek sfTouchEvent, y} ptr :: IO CInt) 187 | 21 -> SFEvtTouchEnded 188 | <$> fmap fromIntegral (#{peek sfTouchEvent, finger} ptr :: IO CUInt) 189 | <*> fmap fromIntegral (#{peek sfTouchEvent, x} ptr :: IO CInt) 190 | <*> fmap fromIntegral (#{peek sfTouchEvent, y} ptr :: IO CInt) 191 | 192 | poke ptr evt = return () 193 | 194 | -------------------------------------------------------------------------------- /src/SFML/Window/Joystick.hsc: -------------------------------------------------------------------------------- 1 | {-# LANGUAGE CPP, ForeignFunctionInterface #-} 2 | module SFML.Window.Joystick 3 | ( 4 | JoystickCap(..) 5 | , JoystickAxis(..) 6 | , isJoystickConnected 7 | , getButtonCount 8 | , hasAxis 9 | , isJoystickButtonPressed 10 | , getAxisPosition 11 | , getJoystickIdentification 12 | , updateJoystick 13 | ) 14 | where 15 | 16 | 17 | import SFML.Window.JoystickIdentification 18 | 19 | import Foreign.C.Types 20 | import Foreign.Marshal.Alloc (alloca) 21 | import Foreign.Storable 22 | import Foreign.Ptr (Ptr, castPtr) 23 | 24 | 25 | -- | Global joysticks capabilities 26 | data JoystickCap 27 | = JoystickCount -- ^ Maximum number of supported joysticks 28 | | JoystickButtonCount -- ^ Maximum number of supported buttons 29 | | JoystickAxisCount -- ^ Maximum number of supported axes 30 | deriving (Eq, Bounded, Show) 31 | 32 | 33 | instance Enum JoystickCap where 34 | 35 | fromEnum JoystickCount = 8 36 | fromEnum JoystickButtonCount = 32 37 | fromEnum JoystickAxisCount = 8 38 | 39 | toEnum 8 = JoystickCount 40 | toEnum 32 = JoystickButtonCount 41 | --toEnum 8 = JoystickAxisCount 42 | 43 | 44 | -- | Axes supported by SFML joysticks 45 | data JoystickAxis 46 | = JoystickX -- ^ The X axis 47 | | JoystickY -- ^ The Y axis 48 | | JoystickZ -- ^ The Z axis 49 | | JoystickR -- ^ The R axis 50 | | JoystickU -- ^ The U axis 51 | | JoystickV -- ^ The V axis 52 | | JoystickPovX -- ^ The X axis of the point-of-view hat 53 | | JoystickPovY -- ^ The Y axis of the point-of-view hat 54 | deriving (Eq, Enum, Bounded, Show) 55 | 56 | 57 | sizeInt = #{size int} 58 | 59 | 60 | instance Storable JoystickAxis where 61 | sizeOf _ = sizeInt 62 | alignment _ = alignment (undefined :: CInt) 63 | 64 | peek ptr = peek (castPtr ptr :: Ptr CInt) >>= return . toEnum . fromIntegral 65 | poke ptr bt = poke (castPtr ptr :: Ptr CInt) (fromIntegral . fromEnum $ bt) 66 | 67 | 68 | -- | Check if a joystick is connected. 69 | isJoystickConnected 70 | :: Int -- ^ Index of the joystick to check 71 | -> IO Bool 72 | 73 | isJoystickConnected j = sfJoystick_isConnected (fromIntegral j) >>= return . (/=0) 74 | 75 | foreign import ccall unsafe "sfJoystick_isConnected" 76 | sfJoystick_isConnected :: CUInt -> IO CChar 77 | 78 | --CSFML_WINDOW_API sfBool sfJoystick_isConnected(unsigned int joystick); 79 | 80 | 81 | -- | Return the number of buttons supported by a joystick. 82 | -- 83 | -- If the joystick is not connected, this function returns 0. 84 | getButtonCount 85 | :: Int -- ^ Index of the joystick 86 | -> IO Int 87 | 88 | getButtonCount j = fmap fromIntegral $ sfJoystick_getButtonCount (fromIntegral j) 89 | 90 | foreign import ccall unsafe "sfJoystick_getButtonCount" 91 | sfJoystick_getButtonCount :: CUInt -> IO CUInt 92 | 93 | --CSFML_WINDOW_API unsigned int sfJoystick_getButtonCount(unsigned int joystick); 94 | 95 | 96 | -- | Check if a joystick supports a given axis. 97 | -- 98 | -- If the joystick is not connected, this function returns 'False'. 99 | hasAxis 100 | :: Int -- ^ Index of the joystick 101 | -> Int -- ^ Axis to check 102 | -> IO Bool 103 | 104 | hasAxis j a = sfJoystick_hasAxis (fromIntegral j) (fromIntegral a) >>= return . (/=0) 105 | 106 | foreign import ccall unsafe "sfJoystick_hasAxis" 107 | sfJoystick_hasAxis :: CUInt -> CUInt -> IO CChar 108 | 109 | --CSFML_WINDOW_API sfBool sfJoystick_hasAxis(unsigned int joystick, sfJoystickAxis axis); 110 | 111 | 112 | -- | Check if a joystick button is pressed. 113 | -- 114 | -- If the joystick is not connected, this function returns 'False'. 115 | isJoystickButtonPressed 116 | :: Int -- ^ Index of the joystick 117 | -> Int -- ^ Button to check 118 | -> IO Bool 119 | 120 | isJoystickButtonPressed j b = sfJoystick_isButtonPressed (fromIntegral j) (fromIntegral b) >>= return . (/=0) 121 | 122 | foreign import ccall unsafe "sfJoystick_isButtonPressed" 123 | sfJoystick_isButtonPressed :: CUInt -> CUInt -> IO CChar 124 | 125 | --CSFML_WINDOW_API sfBool sfJoystick_isButtonPressed(unsigned int joystick, unsigned int button); 126 | 127 | 128 | -- | Get the current position of a joystick axis. 129 | -- 130 | -- If the joystick is not connected, this function returns 0. 131 | getAxisPosition 132 | :: Int -- ^ Index of the joystick 133 | -> Int -- ^ Axis to check 134 | -> IO Float 135 | 136 | getAxisPosition j a = sfJoystick_getAxisPosition (fromIntegral j) (fromIntegral a) >>= return . realToFrac 137 | 138 | foreign import ccall unsafe "sfJoystick_getAxisPosition" 139 | sfJoystick_getAxisPosition :: CUInt -> CUInt -> IO CFloat 140 | 141 | --CSFML_WINDOW_API float sfJoystick_getAxisPosition(unsigned int joystick, sfJoystickAxis axis); 142 | 143 | 144 | -- | Get the joystick information. 145 | -- 146 | -- The result of this function will only remain valid until 147 | -- the next time the function is called. 148 | getJoystickIdentification 149 | :: Int -- ^ Index of the joystick 150 | -> IO JoystickIdentification 151 | 152 | getJoystickIdentification j 153 | = alloca $ \ptr -> sfJoystick_getIdentification_helper (fromIntegral j) ptr >> peek ptr 154 | 155 | foreign import ccall unsafe "sfJoystick_getIdentification_helper" 156 | sfJoystick_getIdentification_helper :: CUInt -> Ptr JoystickIdentification -> IO () 157 | 158 | --CSFML_WINDOW_API sfJoystickIdentification sfJoystick_getIdentification(unsigned int joystick); 159 | 160 | 161 | -- | Update the states of all joysticks. 162 | -- 163 | -- This function is used internally by SFML, so you normally 164 | -- don't have to call it explicitely. However, you may need to 165 | -- call it if you have no window yet (or no window at all): 166 | -- in this case the joysticks states are not updated automatically. 167 | updateJoystick :: IO () 168 | updateJoystick = sfJoystick_update 169 | 170 | foreign import ccall unsafe "sfJoystick_update" 171 | sfJoystick_update :: IO () 172 | 173 | --CSFML_WINDOW_API void sfJoystick_update(void); 174 | 175 | -------------------------------------------------------------------------------- /src/SFML/Window/JoystickIdentification.hsc: -------------------------------------------------------------------------------- 1 | {-# LANGUAGE CPP, ForeignFunctionInterface #-} 2 | module SFML.Window.JoystickIdentification 3 | ( 4 | JoystickIdentification(..) 5 | ) 6 | where 7 | 8 | 9 | import Control.Applicative ((<$>), (<*>)) 10 | import Foreign.C.String 11 | import Foreign.C.Types 12 | import Foreign.Storable 13 | import Foreign.Ptr (Ptr, castPtr) 14 | 15 | #include 16 | 17 | 18 | -- | Joystick's identification 19 | data JoystickIdentification = JoystickIdentification 20 | { name :: String 21 | , vendorId :: Int 22 | , productId :: Int 23 | } deriving (Eq, Show) 24 | 25 | 26 | instance Storable JoystickIdentification where 27 | sizeOf _ = #{size sfJoystickIdentification} 28 | alignment _ = #{alignment sfJoystickIdentification} 29 | 30 | peek ptr = JoystickIdentification 31 | <$> (#{peek sfJoystickIdentification, name} ptr >>= peekCString) 32 | <*> fmap fromIntegral (#{peek sfJoystickIdentification, vendorId} ptr :: IO CUInt) 33 | <*> fmap fromIntegral (#{peek sfJoystickIdentification, productId} ptr :: IO CUInt) 34 | 35 | poke ptr ji = do 36 | withCString (name ji) $ #{poke sfJoystickIdentification, name} ptr 37 | #{poke sfJoystickIdentification, vendorId} ptr ((fromIntegral . vendorId) ji :: CUInt) 38 | #{poke sfJoystickIdentification, productId} ptr ((fromIntegral . productId) ji :: CUInt) 39 | -------------------------------------------------------------------------------- /src/SFML/Window/Keyboard.hsc: -------------------------------------------------------------------------------- 1 | {-# LANGUAGE CPP, ForeignFunctionInterface #-} 2 | module SFML.Window.Keyboard 3 | ( 4 | KeyCode(..) 5 | , isKeyPressed 6 | ) 7 | where 8 | 9 | 10 | import Foreign.C.Types 11 | import Foreign.Ptr 12 | import Foreign.Storable 13 | 14 | 15 | -- | Key codes. 16 | data KeyCode 17 | = KeyA -- ^ The A key 18 | | KeyB -- ^ The B key 19 | | KeyC -- ^ The C key 20 | | KeyD -- ^ The D key 21 | | KeyE -- ^ The E key 22 | | KeyF -- ^ The F key 23 | | KeyG -- ^ The G key 24 | | KeyH -- ^ The H key 25 | | KeyI -- ^ The I key 26 | | KeyJ -- ^ The J key 27 | | KeyK -- ^ The K key 28 | | KeyL -- ^ The L key 29 | | KeyM -- ^ The M key 30 | | KeyN -- ^ The N key 31 | | KeyO -- ^ The O key 32 | | KeyP -- ^ The P key 33 | | KeyQ -- ^ The Q key 34 | | KeyR -- ^ The R key 35 | | KeyS -- ^ The S key 36 | | KeyT -- ^ The T key 37 | | KeyU -- ^ The U key 38 | | KeyV -- ^ The V key 39 | | KeyW -- ^ The W key 40 | | KeyX -- ^ The X key 41 | | KeyY -- ^ The Y key 42 | | KeyZ -- ^ The Z key 43 | | KeyNum0 -- ^ The 0 key 44 | | KeyNum1 -- ^ The 1 key 45 | | KeyNum2 -- ^ The 2 key 46 | | KeyNum3 -- ^ The 3 key 47 | | KeyNum4 -- ^ The 4 key 48 | | KeyNum5 -- ^ The 5 key 49 | | KeyNum6 -- ^ The 6 key 50 | | KeyNum7 -- ^ The 7 key 51 | | KeyNum8 -- ^ The 8 key 52 | | KeyNum9 -- ^ The 9 key 53 | | KeyEscape -- ^ The Escape key 54 | | KeyLControl -- ^ The left Control key 55 | | KeyLShift -- ^ The left Shift key 56 | | KeyLAlt -- ^ The left Alt key 57 | | KeyLSystem -- ^ The left OS specific key: window (Windows and Linux), apple (MacOS X), ... 58 | | KeyRControl -- ^ The right Control key 59 | | KeyRShift -- ^ The right Shift key 60 | | KeyRAlt -- ^ The right Alt key 61 | | KeyRSystem -- ^ The right OS specific key: window (Windows and Linux), apple (MacOS X), ... 62 | | KeyMenu -- ^ The Menu key 63 | | KeyLBracket -- ^ The [ key 64 | | KeyRBracket -- ^ The ] key 65 | | KeySemiColon -- ^ The ; key 66 | | KeyComma -- ^ The , key 67 | | KeyPeriod -- ^ The . key 68 | | KeyQuote -- ^ The ' key 69 | | KeySlash -- ^ The / key 70 | | KeyBackSlash -- ^ The \ key 71 | | KeyTilde -- ^ The ~ key 72 | | KeyEqual -- ^ The = key 73 | | KeyDash -- ^ The - key 74 | | KeySpace -- ^ The Space key 75 | | KeyReturn -- ^ The Return key 76 | | KeyBack -- ^ The Backspace key 77 | | KeyTab -- ^ The Tabulation key 78 | | KeyPageUp -- ^ The Page up key 79 | | KeyPageDown -- ^ The Page down key 80 | | KeyEnd -- ^ The End key 81 | | KeyHome -- ^ The Home key 82 | | KeyInsert -- ^ The Insert key 83 | | KeyDelete -- ^ The Delete key 84 | | KeyAdd -- ^ + 85 | | KeySubtract -- ^ - 86 | | KeyMultiply -- ^ * 87 | | KeyDivide -- ^ / 88 | | KeyLeft -- ^ Left arrow 89 | | KeyRight -- ^ Right arrow 90 | | KeyUp -- ^ Up arrow 91 | | KeyDown -- ^ Down arrow 92 | | KeyNumpad0 -- ^ The numpad 0 key 93 | | KeyNumpad1 -- ^ The numpad 1 key 94 | | KeyNumpad2 -- ^ The numpad 2 key 95 | | KeyNumpad3 -- ^ The numpad 3 key 96 | | KeyNumpad4 -- ^ The numpad 4 key 97 | | KeyNumpad5 -- ^ The numpad 5 key 98 | | KeyNumpad6 -- ^ The numpad 6 key 99 | | KeyNumpad7 -- ^ The numpad 7 key 100 | | KeyNumpad8 -- ^ The numpad 8 key 101 | | KeyNumpad9 -- ^ The numpad 9 key 102 | | KeyF1 -- ^ The F1 key 103 | | KeyF2 -- ^ The F2 key 104 | | KeyF3 -- ^ The F3 key 105 | | KeyF4 -- ^ The F4 key 106 | | KeyF5 -- ^ The F5 key 107 | | KeyF6 -- ^ The F6 key 108 | | KeyF7 -- ^ The F7 key 109 | | KeyF8 -- ^ The F8 key 110 | | KeyF9 -- ^ The F8 key 111 | | KeyF10 -- ^ The F10 key 112 | | KeyF11 -- ^ The F11 key 113 | | KeyF12 -- ^ The F12 key 114 | | KeyF13 -- ^ The F13 key 115 | | KeyF14 -- ^ The F14 key 116 | | KeyF15 -- ^ The F15 key 117 | | KeyPause -- ^ The Pause key 118 | | Undefined -- ^ Undefined key 119 | deriving (Eq, Enum, Bounded, Show) 120 | 121 | 122 | sizeInt = #{size int} 123 | 124 | 125 | instance Storable KeyCode where 126 | sizeOf _ = sizeInt 127 | alignment _ = alignment (undefined :: CInt) 128 | 129 | peek ptr = peek (castPtr ptr :: Ptr CInt) >>= return . toEnum . checkUndef . fromIntegral 130 | poke ptr bt = poke (castPtr ptr :: Ptr CInt) (fromIntegral . fromEnum $ bt) 131 | 132 | 133 | checkUndef = min (fromEnum Undefined) . (\k -> if k < 0 then (fromEnum Undefined) else k) 134 | 135 | 136 | -- | Check if a key is pressed 137 | isKeyPressed :: KeyCode -> IO Bool 138 | isKeyPressed k = sfKeyboard_isKeyPressed (fromEnum k) >>= return . (/=0) 139 | 140 | 141 | foreign import ccall unsafe "sfKeyboard_isKeyPressed" 142 | sfKeyboard_isKeyPressed :: Int -> IO CChar 143 | 144 | --CSFML_WINDOW_API sfBool sfKeyboard_isKeyPressed(sfKeyCode key); 145 | 146 | -------------------------------------------------------------------------------- /src/SFML/Window/Mouse.hsc: -------------------------------------------------------------------------------- 1 | {-# LANGUAGE CPP, ForeignFunctionInterface #-} 2 | module SFML.Window.Mouse 3 | ( 4 | MouseButton(..) 5 | , MouseWheel(..) 6 | , isMouseButtonPressed 7 | ) 8 | where 9 | 10 | 11 | import SFML.Window.Types 12 | import SFML.System.Vector2 13 | 14 | import Foreign.C.Types 15 | import Foreign.Marshal.Alloc (alloca) 16 | import Foreign.Ptr 17 | import Foreign.Storable 18 | 19 | #include 20 | 21 | 22 | data MouseButton 23 | = MouseLeft 24 | | MouseRight 25 | | MouseMiddle 26 | | MouseXButton1 27 | | MouseXButton2 28 | deriving (Eq, Enum, Bounded, Show) 29 | 30 | 31 | data MouseWheel 32 | = MouseVerticalWheel -- ^ The vertical mouse wheel 33 | | MouseHorizontalWheel -- ^ The horizontal mouse wheel 34 | deriving (Eq, Enum, Bounded, Show) 35 | 36 | 37 | instance Storable MouseWheel where 38 | sizeOf _ = #{size sfMouseWheel} 39 | alignment _ = #{alignment sfMouseWheel} 40 | 41 | peek ptr = peek (castPtr ptr :: Ptr CInt) >>= return . toEnum . fromIntegral 42 | poke ptr mw = poke (castPtr ptr :: Ptr CInt) (fromIntegral . fromEnum $ mw) 43 | 44 | 45 | instance Storable MouseButton where 46 | sizeOf _ = #{size sfMouseButton} 47 | alignment _ = #{alignment sfMouseButton} 48 | 49 | peek ptr = peek (castPtr ptr :: Ptr CInt) >>= return . toEnum . fromIntegral 50 | poke ptr bt = poke (castPtr ptr :: Ptr CInt) (fromIntegral . fromEnum $ bt) 51 | 52 | 53 | -- | Check if a mouse button is pressed. 54 | isMouseButtonPressed :: MouseButton -> IO Bool 55 | isMouseButtonPressed bt = sfMouse_isButtonPressed (fromEnum bt) >>= return . (/=0) 56 | 57 | foreign import ccall unsafe "sfMouse_isButtonPressed" 58 | sfMouse_isButtonPressed :: Int -> IO CChar 59 | 60 | --CSFML_WINDOW_API sfBool sfMouse_isButtonPressed(sfMouseButton button); 61 | -------------------------------------------------------------------------------- /src/SFML/Window/SFWindow.hs: -------------------------------------------------------------------------------- 1 | module SFML.Window.SFWindow 2 | where 3 | 4 | 5 | import SFML.SFDisplayable 6 | import SFML.SFResource 7 | import SFML.System.Vector2 8 | import SFML.Window.ContextSettings 9 | import SFML.Window.Event 10 | import SFML.Window.Types 11 | import SFML.Window.WindowHandle 12 | 13 | import Foreign.Ptr (Ptr) 14 | 15 | 16 | class (SFResource a, SFDisplayable a) => SFWindow a where 17 | 18 | -- | Close the window. 19 | -- 20 | -- After calling this function, the window object remains 21 | -- valid; you must call 'destroy' to actually delete it. 22 | close :: a -> IO () 23 | 24 | -- | Tell whether or not a window is opened 25 | -- 26 | -- This function returns whether or not the window exists. 27 | -- 28 | -- Note that a hidden window (setWindowVisible 'False' ) will return 29 | -- 'True'. 30 | isWindowOpen :: a -> IO Bool 31 | 32 | -- | Get the settings of the OpenGL context of a window. 33 | -- 34 | -- Note that these settings may be different from what was 35 | -- passed to the window create function, 36 | -- if one or more settings were not supported. In this case, 37 | -- SFML chose the closest match. 38 | getWindowSettings :: a -> IO ContextSettings 39 | 40 | -- | Pop the event on top of events stack, if any, and return it. 41 | -- 42 | -- This function is not blocking: if there's no pending event then 43 | -- it will return false and leave \a event unmodified. 44 | -- Note that more than one event may be present in the events stack, 45 | -- thus you should always call this function in a loop 46 | -- to make sure that you process every pending event. 47 | pollEvent :: a -> IO (Maybe SFEvent) 48 | 49 | -- | Wait for an event and return it. 50 | -- 51 | -- This function is blocking: if there's no pending event then 52 | -- it will wait until an event is received. 53 | -- 54 | -- After this function returns (and no error occured), 55 | -- the event object is always valid and filled properly. 56 | -- 57 | -- This function is typically used when you have a thread that 58 | -- is dedicated to events handling: you want to make this thread 59 | -- sleep as long as no new event is received. 60 | waitEvent :: a -> IO (Maybe SFEvent) 61 | 62 | -- | Get the position of a window. 63 | getWindowPosition :: a -> IO Vec2i 64 | 65 | -- | Change the position of a window on screen. 66 | -- 67 | -- This function only works for top-level windows 68 | -- (i.e. it will be ignored for windows created from 69 | -- the handle of a child window/control). 70 | setWindowPosition :: a -> Vec2i -> IO () 71 | 72 | -- | Get the size of the rendering region of a window. 73 | -- 74 | -- The size doesn't include the titlebar and borders 75 | -- of the window. 76 | getWindowSize :: a -> IO Vec2u 77 | 78 | -- | Change the size of the rendering region of a window. 79 | setWindowSize :: a -> Vec2u -> IO () 80 | 81 | -- | Change the title of a window. 82 | setWindowTitle :: a -> String -> IO () 83 | 84 | -- | Change a window's icon. 85 | -- 86 | -- Pixels must be an array of width x height pixels 87 | -- in 32-bits RGBA format. 88 | setWindowIcon 89 | :: a 90 | -> Int -- ^ Icon's width, in pixels 91 | -> Int -- ^ Icon's height, in pixels 92 | -> Ptr b -- ^ Pixel data 93 | -> IO () 94 | 95 | -- | Show or hide a window. 96 | setWindowVisible :: a -> Bool -> IO () 97 | 98 | -- | Show or hide the mouse cursor. 99 | setMouseVisible :: a -> Bool -> IO () 100 | 101 | -- | Enable or disable vertical synchronization. 102 | -- Activating vertical synchronization will limit the number 103 | -- of frames displayed to the refresh rate of the monitor. 104 | -- 105 | -- This can avoid some visual artifacts, and limit the framerate 106 | -- to a good value (but not constant across different computers). 107 | setVSync :: a -> Bool -> IO () 108 | 109 | -- | Enable or disable automatic key-repeat. 110 | -- 111 | -- If key repeat is enabled, you will receive repeated 112 | -- KeyPress events while keeping a key pressed. If it is disabled, 113 | -- you will only get a single event when the key is pressed. 114 | -- 115 | -- Key repeat is enabled by default. 116 | setKeyRepeat :: a -> Bool -> IO () 117 | 118 | -- | Activate or deactivate a window as the current target for OpenGL rendering. 119 | -- 120 | -- A window is active only on the current thread, if you want to 121 | -- make it active on another thread you have to deactivate it 122 | -- on the previous thread first if it was active. 123 | -- 124 | -- Only one window can be active on a thread at a time, thus 125 | -- the window previously active (if any) automatically gets deactivated. 126 | setWindowActive :: a -> Bool -> IO () 127 | 128 | -- | Request the current window to be made the active foreground window. 129 | -- 130 | -- At any given time, only one window may have the input focus 131 | -- to receive input events such as keystrokes or mouse events. 132 | -- If a window requests focus, it only hints to the operating 133 | -- system, that it would like to be focused. The operating system 134 | -- is free to deny the request. 135 | -- This is not to be confused with 'setWindowActive'. 136 | requestFocus :: a -> IO () 137 | 138 | -- | Check whether the render window has the input focus. 139 | -- 140 | -- At any given time, only one window may have the input focus 141 | -- to receive input events such as keystrokes or most mouse 142 | -- events. 143 | hasFocus :: a -> IO Bool 144 | 145 | -- | Limit the framerate to a maximum fixed frequency. 146 | -- 147 | -- If a limit is set, the window will use a small delay after 148 | -- each call to 'display' to ensure that the current frame 149 | -- lasted long enough to match the framerate limit. 150 | setFramerateLimit :: a -> Int -> IO () 151 | 152 | -- | Change the joystick threshold. 153 | -- 154 | -- The joystick threshold is the value below which 155 | -- no JoyMoved event will be generated. 156 | setJoystickThreshold :: a -> Float -> IO () 157 | 158 | -- | Get the OS-specific handle of the window. 159 | -- 160 | -- The type of the returned handle is 'WindowHandle', 161 | -- which is a typedef to the handle type defined by the OS. 162 | -- 163 | -- You shouldn't need to use this function, unless you have 164 | -- very specific stuff to implement that SFML doesn't support, 165 | -- or implement a temporary workaround until a bug is fixed. 166 | getSystemHandle :: a -> IO WindowHandle 167 | 168 | -- | Get the current position of the mouse 169 | -- 170 | -- This function returns the current position of the mouse 171 | -- cursor relative to the given window, or desktop if 'Nothing' is passed. 172 | getMousePosition :: Maybe a -> IO Vec2i 173 | 174 | -- | Set the current position of the mouse 175 | -- 176 | -- This function sets the current position of the mouse 177 | -- cursor relative to the given window, or desktop if 'Nothing' is passed. 178 | setMousePosition :: Vec2i -> Maybe a -> IO () 179 | 180 | -------------------------------------------------------------------------------- /src/SFML/Window/Types.hs: -------------------------------------------------------------------------------- 1 | module SFML.Window.Types 2 | ( 3 | Context(..) 4 | , Window(..) 5 | ) 6 | where 7 | 8 | 9 | import Foreign.Ptr 10 | 11 | 12 | newtype Context = Context (Ptr Context) 13 | newtype Window = Window (Ptr Window) 14 | 15 | -------------------------------------------------------------------------------- /src/SFML/Window/VideoMode.hsc: -------------------------------------------------------------------------------- 1 | {-# LANGUAGE CPP, ForeignFunctionInterface #-} 2 | module SFML.Window.VideoMode 3 | ( 4 | VideoMode(..) 5 | , getDesktopMode 6 | , getFullscreenModes 7 | , isValid 8 | ) 9 | where 10 | 11 | 12 | import Control.Applicative ((<$>), (<*>), (*>), liftA2) 13 | import Foreign.C.Types 14 | import Foreign.Ptr 15 | import Foreign.Marshal.Alloc (alloca) 16 | import Foreign.Marshal.Array (peekArray) 17 | import Foreign.Marshal.Utils (with) 18 | import Foreign.Storable 19 | 20 | #include 21 | 22 | 23 | sizeInt = #{size int} 24 | 25 | 26 | data VideoMode = VideoMode 27 | { windowWidth :: Int -- ^ Video mode width, in pixels 28 | , windowHeight :: Int -- ^ Video mode height, in pixels 29 | , windowBPP :: Int -- ^ Video mode pixel depth, in bits per pixels 30 | } 31 | deriving (Show) 32 | 33 | 34 | instance Storable VideoMode where 35 | sizeOf _ = 3*sizeInt 36 | alignment _ = alignment (undefined :: CInt) 37 | 38 | peek ptr = VideoMode 39 | <$> fmap fromIntegral (#{peek sfVideoMode, width} ptr :: IO CUInt) 40 | <*> fmap fromIntegral (#{peek sfVideoMode, height} ptr :: IO CUInt) 41 | <*> fmap fromIntegral (#{peek sfVideoMode, bitsPerPixel} ptr :: IO CUInt) 42 | 43 | poke ptr (VideoMode w h b) = do 44 | #{poke sfVideoMode, width} ptr (fromIntegral w :: CUInt) 45 | #{poke sfVideoMode, height} ptr (fromIntegral h :: CUInt) 46 | #{poke sfVideoMode, bitsPerPixel} ptr (fromIntegral b :: CUInt) 47 | 48 | 49 | -- | Get the current desktop video mode 50 | getDesktopMode = alloca $ liftA2 (*>) sfVideoMode_getDesktopMode_helper peek 51 | 52 | foreign import ccall unsafe "sfVideoMode_getDesktopMode_helper" 53 | sfVideoMode_getDesktopMode_helper :: Ptr VideoMode -> IO () 54 | 55 | --CSFML_WINDOW_API sfVideoMode sfVideoMode_getDesktopMode(void); 56 | 57 | 58 | -- | Retrieve all the video modes supported in fullscreen mode 59 | -- 60 | -- When creating a fullscreen window, the video mode is restricted 61 | -- to be compatible with what the graphics driver and monitor 62 | -- support. 63 | 64 | -- This function returns the complete list of all video 65 | -- modes that can be used in fullscreen mode. 66 | -- 67 | -- The returned array is sorted from best to worst, so that 68 | -- the first element will always give the best mode (higher 69 | -- width, height and bits-per-pixel). 70 | getFullscreenModes :: IO [VideoMode] 71 | getFullscreenModes = do 72 | alloca $ \countPtr -> do 73 | ptrVM <- sfVideoMode_getFullscreenModes countPtr 74 | count <- peek countPtr 75 | peekArray (fromIntegral count) ptrVM 76 | 77 | foreign import ccall unsafe "sfVideoMode_getFullscreenModes" 78 | sfVideoMode_getFullscreenModes :: Ptr CUInt -> IO (Ptr VideoMode) 79 | 80 | --CSFML_WINDOW_API const sfVideoMode* sfVideoMode_getFullscreenModes(size_t* Count); 81 | 82 | 83 | -- | Tell whether or not a video mode is valid 84 | -- 85 | -- The validity of video modes is only relevant when using 86 | -- fullscreen windows; otherwise any video mode can be used 87 | -- with no restriction. 88 | isValid :: VideoMode -> IO Bool 89 | isValid vm = with vm $ \ptrVm -> sfVideoMode_isValid_helper ptrVm >>= return . (/=0) 90 | 91 | foreign import ccall unsafe "sfVideoMode_isValid_helper" 92 | sfVideoMode_isValid_helper :: Ptr VideoMode -> IO CChar 93 | 94 | --CSFML_WINDOW_API sfBool sfVideoMode_isValid(sfVideoMode mode); 95 | 96 | -------------------------------------------------------------------------------- /src/SFML/Window/WindowHandle.hs: -------------------------------------------------------------------------------- 1 | module SFML.Window.WindowHandle 2 | ( 3 | WindowHandle(..) 4 | ) 5 | where 6 | 7 | 8 | import Foreign.Ptr (Ptr) 9 | 10 | 11 | newtype WindowHandle = WindowHandle (Ptr WindowHandle) 12 | 13 | --------------------------------------------------------------------------------