Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
  • 20 commits
  • 24 files changed
  • 0 commit comments
  • 3 contributors
View
BIN  Examples/twinklebear/background.bmp
Binary file not shown
View
BIN  Examples/twinklebear/background.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
BIN  Examples/twinklebear/hello.bmp
Binary file not shown
View
BIN  Examples/twinklebear/image.bmp
Binary file not shown
View
BIN  Examples/twinklebear/image.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
21 Examples/twinklebear/lesson1.hs
@@ -0,0 +1,21 @@
+module Main where
+
+import Control.Concurrent
+
+import Graphics.UI.SDL as SDL
+
+
+
+main :: IO ()
+main =
+ withInit [InitEverything] $
+ withWindow "Hello World!" (Position 100 100) (Size 640 480) [WindowShown] $ \win ->
+ withRenderer win (Device (-1)) [Accelerated, PresentVSync] $ \ren -> do
+ bmp <- loadBMP "hello.bmp"
+ tex <- createTextureFromSurface ren bmp
+ renderClear ren
+ renderCopy ren tex Nothing Nothing
+ renderPresent ren
+
+ threadDelay (10^6 * 2)
+ return ()
View
57 Examples/twinklebear/lesson2.hs
@@ -0,0 +1,57 @@
+module Main where
+
+import Control.Concurrent
+
+import Graphics.UI.SDL as SDL
+
+-----------------------
+-- Window parameters --
+
+screenSize :: Size
+screenSize = Size 640 480
+
+screenPosition :: Position
+screenPosition = Position 100 100
+
+screenTitle :: String
+screenTitle = "Lession 2"
+
+
+------------------
+-- Main program --
+
+main :: IO ()
+main =
+ withInit [InitEverything] $
+ withWindow screenTitle screenPosition screenSize [WindowShown] $ \win ->
+ withRenderer win (Device (-1)) [Accelerated, PresentVSync] $ \renderer -> do
+ background <- loadTexture "background.bmp" renderer
+ image <- loadTexture "image.bmp" renderer
+
+ renderClear renderer
+ Size bW bH <- queryTextureSize background
+ renderTexture background renderer (Position 0 0)
+ renderTexture background renderer (Position bW 0)
+ renderTexture background renderer (Position 0 bH)
+ renderTexture background renderer (Position bW bH)
+
+ Size iW iH <- queryTextureSize image
+ let x = sizeWidth screenSize `div` 2 - iW `div` 2
+ y = sizeHeight screenSize `div` 2 - iH `div` 2
+ renderTexture image renderer (Position x y)
+
+ renderPresent renderer
+ threadDelay (10^6 * 2)
+
+-------------
+-- Helpers --
+
+loadTexture :: FilePath -> Renderer -> IO Texture
+loadTexture path renderer = createTextureFromSurface renderer =<< loadBMP path
+
+renderTexture :: Texture -> Renderer -> Position -> IO ()
+renderTexture texture renderer (Position x y) = do
+ Size w h <- queryTextureSize texture
+ let dst = Rect x y w h
+ renderCopy renderer texture Nothing (Just dst)
+
View
59 Examples/twinklebear/lesson3.hs
@@ -0,0 +1,59 @@
+module Main where
+
+import Control.Concurrent
+
+import Graphics.UI.SDL as SDL
+import Graphics.UI.SDL.Image as Image
+
+-----------------------
+-- Window parameters --
+
+screenSize :: Size
+screenSize = Size 640 480
+
+screenPosition :: Position
+screenPosition = Position 100 100
+
+screenTitle :: String
+screenTitle = "Lession 2"
+
+
+------------------
+-- Main program --
+
+main :: IO ()
+main =
+ SDL.withInit [InitEverything] $
+ Image.withInit [InitPNG] $
+ withWindow screenTitle screenPosition screenSize [WindowShown] $ \win ->
+ withRenderer win (Device (-1)) [Accelerated, PresentVSync] $ \renderer -> do
+ background <- loadTexture "background.png" renderer
+ image <- loadTexture "image.png" renderer
+
+ renderClear renderer
+ Size bW bH <- queryTextureSize background
+ renderTexture background renderer (Position 0 0)
+ renderTexture background renderer (Position bW 0)
+ renderTexture background renderer (Position 0 bH)
+ renderTexture background renderer (Position bW bH)
+
+ Size iW iH <- queryTextureSize image
+ let x = sizeWidth screenSize `div` 2 - iW `div` 2
+ y = sizeHeight screenSize `div` 2 - iH `div` 2
+ renderTexture image renderer (Position x y)
+
+ renderPresent renderer
+ threadDelay (10^6 * 2)
+
+-------------
+-- Helpers --
+
+loadTexture :: FilePath -> Renderer -> IO Texture
+loadTexture path renderer = createTextureFromSurface renderer =<< load path
+
+renderTexture :: Texture -> Renderer -> Position -> IO ()
+renderTexture texture renderer (Position x y) = do
+ Size w h <- queryTextureSize texture
+ let dst = Rect x y w h
+ renderCopy renderer texture Nothing (Just dst)
+
View
15 Graphics/UI/SDL/Events.hsc
@@ -13,8 +13,9 @@
module Graphics.UI.SDL.Events where
import Control.Applicative
+import Control.Monad ((>=>), void)
import Data.Word
-import Foreign
+import Foreign hiding (void)
import Foreign.C
import Graphics.UI.SDL.Keysym
import Graphics.UI.SDL.Types (Position, Size, mkPosition, mkSize)
@@ -247,3 +248,15 @@ pollEvent = alloca $ \ptr -> do
case ret of
0 -> return Nothing
_ -> maybePeek peek ptr
+
+foreign import ccall "wrapper"
+ mkEventFilter :: (Ptr () -> Ptr Event -> IO ()) -> IO (FunPtr (Ptr () -> Ptr Event -> IO ()))
+
+foreign import ccall "SDL_AddEventWatch"
+ sdlAddEventWatch :: FunPtr (Ptr () -> Ptr Event -> IO ()) -> Ptr () -> IO ()
+
+-- TODO Adding an event watch seems to stop ^C terminating the program
+addEventWatch :: (Event -> IO a) -> IO ()
+addEventWatch callback = do
+ cb <- mkEventFilter $ \_ -> peek >=> void . callback
+ sdlAddEventWatch cb nullPtr
View
477 Graphics/UI/SDL/Keycode.hsc
@@ -0,0 +1,477 @@
+#include "SDL.h"
+module Graphics.UI.SDL.Keycode where
+
+import Prelude hiding (Either(Left,Right))
+import Foreign
+
+data Keycode
+ = A
+ | B
+ | C
+ | D
+ | E
+ | F
+ | G
+ | H
+ | I
+ | J
+ | K
+ | L
+ | M
+ | N
+ | O
+ | P
+ | Q
+ | R
+ | S
+ | T
+ | U
+ | V
+ | W
+ | X
+ | Y
+ | Z
+ | Number1
+ | Number2
+ | Number3
+ | Number4
+ | Number5
+ | Number6
+ | Number7
+ | Number8
+ | Number9
+ | Number0
+ | Return
+ | Escape
+ | Backspace
+ | Tab
+ | Space
+ | Minus
+ | Equals
+ | LeftBracket
+ | RightBracket
+ | Backslash
+ | Semicolon
+ | Comma
+ | Period
+ | Slash
+ | Capslock
+ | F1
+ | F2
+ | F3
+ | F4
+ | F5
+ | F6
+ | F7
+ | F8
+ | F9
+ | F10
+ | F11
+ | F12
+ | PrintScreen
+ | ScrollLock
+ | Pause
+ | Insert
+ | Home
+ | PageUp
+ | Delete
+ | End
+ | PageDown
+ | Right
+ | Left
+ | Down
+ | Up
+ | NumLockClear
+ | KeypadDivide
+ | KeypadMultiply
+ | KeypadMinus
+ | KeypadPlus
+ | KeypadEnter
+ | Keypad1
+ | Keypad2
+ | Keypad3
+ | Keypad4
+ | Keypad5
+ | Keypad6
+ | Keypad7
+ | Keypad8
+ | Keypad9
+ | Keypad0
+ | KeypadPeriod
+ | Application
+ | Power
+ | KeypadEquals
+ | F13
+ | F14
+ | F15
+ | F16
+ | F17
+ | F18
+ | F19
+ | F20
+ | F21
+ | F22
+ | F23
+ | F24
+ | Execute
+ | Help
+ | Menu
+ | Select
+ | Stop
+ | Again
+ | Undo
+ | Cut
+ | Copy
+ | Paste
+ | Find
+ | Mute
+ | VolumeUp
+ | VolumeDown
+ | KeypadComma
+ | KeyPadEqualsAs400
+ | AltErase
+ | SysReq
+ | Cancel
+ | Clear
+ | Prior
+ | Return2
+ | Separator
+ | Out
+ | Oper
+ | ClearAgain
+ | CrSel
+ | ExSel
+ | Keypad00
+ | Keypad000
+ | ThousandSeparator
+ | DecimalSeparator
+ | CurrencyUnit
+ | CurrencySubunit
+ | KeypadLeftParen
+ | KeypadRightParen
+ | KeypadLeftBrace
+ | KeypadRightBrace
+ | KeypadTab
+ | KeypadBackspace
+ | KeypadA
+ | KeypadB
+ | KeypadC
+ | KeypadD
+ | KeypadE
+ | KeypadF
+ | KeypadXOR
+ | KeypadPower
+ | KeypadPercent
+ | KeypadLess
+ | KeypadGreater
+ | KeypadAmpersand
+ | KeypadDoubleAmpersand
+ | KeypadVerticalBar
+ | KeypadDoubleVerticalBar
+ | KeypadColon
+ | KeypadHash
+ | KeypadSpace
+ | KeypadAt
+ | KeypadExclamation
+ | KeypadMemStore
+ | KeypadMemRecall
+ | KeypadMemClear
+ | KeypadMemAdd
+ | KeypadMemSubstract
+ | KeypadMemMultiply
+ | KeypadMemDivide
+ | KeypadPlusMinus
+ | KeypadClear
+ | KeypadClearEntry
+ | KeypadBinary
+ | KeypadOctal
+ | KeypadDecimal
+ | KeypadHexadecimal
+ | LeftControl
+ | LeftShift
+ | LeftAlt
+ | LeftGUI
+ | RightControl
+ | RightShift
+ | RightAlt
+ | RightGUI
+ | Mode
+ | AudioNext
+ | AudioPrevious
+ | AudioStop
+ | AudioPlay
+ | AudioMute
+ | MediaSelect
+ | WWW
+ | Mail
+ | Calculator
+ | Computer
+ | ACSearch
+ | ACHome
+ | ACBack
+ | ACForward
+ | ACStop
+ | ACRefresh
+ | ACBookmarks
+ | BrightnessDown
+ | BrightnessUp
+ | DisplaySwitch
+ | KBIllumToggle
+ | KBIllumDown
+ | KBIllumUp
+ | Eject
+ | Sleep
+ | Ampersand
+ | Asterisk
+ | At
+ | Caret
+ | Colon
+ | Dollar
+ | Exclaim
+ | Greater
+ | Hash
+ | LeftParen
+ | Less
+ | Percent
+ | Plus
+ | Question
+ | DoubleQuote
+ | RightParen
+ | Underscore
+ deriving (Eq, Show)
+
+
+sdlKeycode :: #{type SDL_Keycode} -> Keycode
+sdlKeycode #{const SDLK_a} = A
+sdlKeycode #{const SDLK_b} = B
+sdlKeycode #{const SDLK_c} = C
+sdlKeycode #{const SDLK_d} = D
+sdlKeycode #{const SDLK_e} = E
+sdlKeycode #{const SDLK_f} = F
+sdlKeycode #{const SDLK_g} = G
+sdlKeycode #{const SDLK_h} = H
+sdlKeycode #{const SDLK_i} = I
+sdlKeycode #{const SDLK_j} = J
+sdlKeycode #{const SDLK_k} = K
+sdlKeycode #{const SDLK_l} = L
+sdlKeycode #{const SDLK_m} = M
+sdlKeycode #{const SDLK_n} = N
+sdlKeycode #{const SDLK_o} = O
+sdlKeycode #{const SDLK_p} = P
+sdlKeycode #{const SDLK_q} = Q
+sdlKeycode #{const SDLK_r} = R
+sdlKeycode #{const SDLK_s} = S
+sdlKeycode #{const SDLK_t} = T
+sdlKeycode #{const SDLK_u} = U
+sdlKeycode #{const SDLK_v} = V
+sdlKeycode #{const SDLK_w} = W
+sdlKeycode #{const SDLK_x} = X
+sdlKeycode #{const SDLK_y} = Y
+sdlKeycode #{const SDLK_z} = Z
+sdlKeycode #{const SDLK_1} = Number1
+sdlKeycode #{const SDLK_2} = Number2
+sdlKeycode #{const SDLK_3} = Number3
+sdlKeycode #{const SDLK_4} = Number4
+sdlKeycode #{const SDLK_5} = Number5
+sdlKeycode #{const SDLK_6} = Number6
+sdlKeycode #{const SDLK_7} = Number7
+sdlKeycode #{const SDLK_8} = Number8
+sdlKeycode #{const SDLK_9} = Number9
+sdlKeycode #{const SDLK_0} = Number0
+sdlKeycode #{const SDLK_RETURN} = Return
+sdlKeycode #{const SDLK_ESCAPE} = Escape
+sdlKeycode #{const SDLK_BACKSPACE} = Backspace
+sdlKeycode #{const SDLK_TAB} = Tab
+sdlKeycode #{const SDLK_SPACE} = Space
+sdlKeycode #{const SDLK_MINUS} = Minus
+sdlKeycode #{const SDLK_EQUALS} = Equals
+sdlKeycode #{const SDLK_LEFTBRACKET} = LeftBracket
+sdlKeycode #{const SDLK_RIGHTBRACKET} = RightBracket
+sdlKeycode #{const SDLK_BACKSLASH} = Backslash
+sdlKeycode #{const SDLK_SEMICOLON} = Semicolon
+sdlKeycode #{const SDLK_COMMA} = Comma
+sdlKeycode #{const SDLK_PERIOD} = Period
+sdlKeycode #{const SDLK_SLASH} = Slash
+sdlKeycode #{const SDLK_CAPSLOCK} = Capslock
+sdlKeycode #{const SDLK_F1} = F1
+sdlKeycode #{const SDLK_F2} = F2
+sdlKeycode #{const SDLK_F3} = F3
+sdlKeycode #{const SDLK_F4} = F4
+sdlKeycode #{const SDLK_F5} = F5
+sdlKeycode #{const SDLK_F6} = F6
+sdlKeycode #{const SDLK_F7} = F7
+sdlKeycode #{const SDLK_F8} = F8
+sdlKeycode #{const SDLK_F9} = F9
+sdlKeycode #{const SDLK_F10} = F10
+sdlKeycode #{const SDLK_F11} = F11
+sdlKeycode #{const SDLK_F12} = F12
+sdlKeycode #{const SDLK_PRINTSCREEN} = PrintScreen
+sdlKeycode #{const SDLK_SCROLLLOCK} = ScrollLock
+sdlKeycode #{const SDLK_PAUSE} = Pause
+sdlKeycode #{const SDLK_INSERT} = Insert
+sdlKeycode #{const SDLK_HOME} = Home
+sdlKeycode #{const SDLK_PAGEUP} = PageUp
+sdlKeycode #{const SDLK_DELETE} = Delete
+sdlKeycode #{const SDLK_END} = End
+sdlKeycode #{const SDLK_PAGEDOWN} = PageDown
+sdlKeycode #{const SDLK_RIGHT} = Right
+sdlKeycode #{const SDLK_LEFT} = Left
+sdlKeycode #{const SDLK_DOWN} = Down
+sdlKeycode #{const SDLK_UP} = Up
+sdlKeycode #{const SDLK_NUMLOCKCLEAR} = NumLockClear
+sdlKeycode #{const SDLK_KP_DIVIDE} = KeypadDivide
+sdlKeycode #{const SDLK_KP_MULTIPLY} = KeypadMultiply
+sdlKeycode #{const SDLK_KP_MINUS} = KeypadMinus
+sdlKeycode #{const SDLK_KP_PLUS} = KeypadPlus
+sdlKeycode #{const SDLK_KP_ENTER} = KeypadEnter
+sdlKeycode #{const SDLK_KP_1} = Keypad1
+sdlKeycode #{const SDLK_KP_2} = Keypad2
+sdlKeycode #{const SDLK_KP_3} = Keypad3
+sdlKeycode #{const SDLK_KP_4} = Keypad4
+sdlKeycode #{const SDLK_KP_5} = Keypad5
+sdlKeycode #{const SDLK_KP_6} = Keypad6
+sdlKeycode #{const SDLK_KP_7} = Keypad7
+sdlKeycode #{const SDLK_KP_8} = Keypad8
+sdlKeycode #{const SDLK_KP_9} = Keypad9
+sdlKeycode #{const SDLK_KP_0} = Keypad0
+sdlKeycode #{const SDLK_KP_PERIOD} = KeypadPeriod
+sdlKeycode #{const SDLK_APPLICATION} = Application
+sdlKeycode #{const SDLK_POWER} = Power
+sdlKeycode #{const SDLK_KP_EQUALS} = KeypadEquals
+sdlKeycode #{const SDLK_F13} = F13
+sdlKeycode #{const SDLK_F14} = F14
+sdlKeycode #{const SDLK_F15} = F15
+sdlKeycode #{const SDLK_F16} = F16
+sdlKeycode #{const SDLK_F17} = F17
+sdlKeycode #{const SDLK_F18} = F18
+sdlKeycode #{const SDLK_F19} = F19
+sdlKeycode #{const SDLK_F20} = F20
+sdlKeycode #{const SDLK_F21} = F21
+sdlKeycode #{const SDLK_F22} = F22
+sdlKeycode #{const SDLK_F23} = F23
+sdlKeycode #{const SDLK_F24} = F24
+sdlKeycode #{const SDLK_EXECUTE} = Execute
+sdlKeycode #{const SDLK_HELP} = Help
+sdlKeycode #{const SDLK_MENU} = Menu
+sdlKeycode #{const SDLK_SELECT} = Select
+sdlKeycode #{const SDLK_STOP} = Stop
+sdlKeycode #{const SDLK_AGAIN} = Again
+sdlKeycode #{const SDLK_UNDO} = Undo
+sdlKeycode #{const SDLK_CUT} = Cut
+sdlKeycode #{const SDLK_COPY} = Copy
+sdlKeycode #{const SDLK_PASTE} = Paste
+sdlKeycode #{const SDLK_FIND} = Find
+sdlKeycode #{const SDLK_MUTE} = Mute
+sdlKeycode #{const SDLK_VOLUMEUP} = VolumeUp
+sdlKeycode #{const SDLK_VOLUMEDOWN} = VolumeDown
+sdlKeycode #{const SDLK_KP_COMMA} = KeypadComma
+sdlKeycode #{const SDLK_KP_EQUALSAS400} = KeyPadEqualsAs400
+sdlKeycode #{const SDLK_ALTERASE} = AltErase
+sdlKeycode #{const SDLK_SYSREQ} = SysReq
+sdlKeycode #{const SDLK_CANCEL} = Cancel
+sdlKeycode #{const SDLK_CLEAR} = Clear
+sdlKeycode #{const SDLK_PRIOR} = Prior
+sdlKeycode #{const SDLK_RETURN2} = Return2
+sdlKeycode #{const SDLK_SEPARATOR} = Separator
+sdlKeycode #{const SDLK_OUT} = Out
+sdlKeycode #{const SDLK_OPER} = Oper
+sdlKeycode #{const SDLK_CLEARAGAIN} = ClearAgain
+sdlKeycode #{const SDLK_CRSEL} = CrSel
+sdlKeycode #{const SDLK_EXSEL} = ExSel
+sdlKeycode #{const SDLK_KP_00} = Keypad00
+sdlKeycode #{const SDLK_KP_000} = Keypad000
+sdlKeycode #{const SDLK_THOUSANDSSEPARATOR} = ThousandSeparator
+sdlKeycode #{const SDLK_DECIMALSEPARATOR} = DecimalSeparator
+sdlKeycode #{const SDLK_CURRENCYUNIT} = CurrencyUnit
+sdlKeycode #{const SDLK_CURRENCYSUBUNIT} = CurrencySubunit
+sdlKeycode #{const SDLK_KP_LEFTPAREN} = KeypadLeftParen
+sdlKeycode #{const SDLK_KP_RIGHTPAREN} = KeypadRightParen
+sdlKeycode #{const SDLK_KP_LEFTBRACE} = KeypadLeftBrace
+sdlKeycode #{const SDLK_KP_RIGHTBRACE} = KeypadRightBrace
+sdlKeycode #{const SDLK_KP_TAB} = KeypadTab
+sdlKeycode #{const SDLK_KP_BACKSPACE} = KeypadBackspace
+sdlKeycode #{const SDLK_KP_A} = KeypadA
+sdlKeycode #{const SDLK_KP_B} = KeypadB
+sdlKeycode #{const SDLK_KP_C} = KeypadC
+sdlKeycode #{const SDLK_KP_D} = KeypadD
+sdlKeycode #{const SDLK_KP_E} = KeypadE
+sdlKeycode #{const SDLK_KP_F} = KeypadF
+sdlKeycode #{const SDLK_KP_XOR} = KeypadXOR
+sdlKeycode #{const SDLK_KP_POWER} = KeypadPower
+sdlKeycode #{const SDLK_KP_PERCENT} = KeypadPercent
+sdlKeycode #{const SDLK_KP_LESS} = KeypadLess
+sdlKeycode #{const SDLK_KP_GREATER} = KeypadGreater
+sdlKeycode #{const SDLK_KP_AMPERSAND} = KeypadAmpersand
+sdlKeycode #{const SDLK_KP_DBLAMPERSAND} = KeypadDoubleAmpersand
+sdlKeycode #{const SDLK_KP_VERTICALBAR} = KeypadVerticalBar
+sdlKeycode #{const SDLK_KP_DBLVERTICALBAR} = KeypadDoubleVerticalBar
+sdlKeycode #{const SDLK_KP_COLON} = KeypadColon
+sdlKeycode #{const SDLK_KP_HASH} = KeypadHash
+sdlKeycode #{const SDLK_KP_SPACE} = KeypadSpace
+sdlKeycode #{const SDLK_KP_AT} = KeypadAt
+sdlKeycode #{const SDLK_KP_EXCLAM} = KeypadExclamation
+sdlKeycode #{const SDLK_KP_MEMSTORE} = KeypadMemStore
+sdlKeycode #{const SDLK_KP_MEMRECALL} = KeypadMemRecall
+sdlKeycode #{const SDLK_KP_MEMCLEAR} = KeypadMemClear
+sdlKeycode #{const SDLK_KP_MEMADD} = KeypadMemAdd
+sdlKeycode #{const SDLK_KP_MEMSUBTRACT} = KeypadMemSubstract
+sdlKeycode #{const SDLK_KP_MEMMULTIPLY} = KeypadMemMultiply
+sdlKeycode #{const SDLK_KP_MEMDIVIDE} = KeypadMemDivide
+sdlKeycode #{const SDLK_KP_PLUSMINUS} = KeypadPlusMinus
+sdlKeycode #{const SDLK_KP_CLEAR} = KeypadClear
+sdlKeycode #{const SDLK_KP_CLEARENTRY} = KeypadClearEntry
+sdlKeycode #{const SDLK_KP_BINARY} = KeypadBinary
+sdlKeycode #{const SDLK_KP_OCTAL} = KeypadOctal
+sdlKeycode #{const SDLK_KP_DECIMAL} = KeypadDecimal
+sdlKeycode #{const SDLK_KP_HEXADECIMAL} = KeypadHexadecimal
+sdlKeycode #{const SDLK_LCTRL} = LeftControl
+sdlKeycode #{const SDLK_LSHIFT} = LeftShift
+sdlKeycode #{const SDLK_LALT} = LeftAlt
+sdlKeycode #{const SDLK_LGUI} = LeftGUI
+sdlKeycode #{const SDLK_RCTRL} = RightControl
+sdlKeycode #{const SDLK_RSHIFT} = RightShift
+sdlKeycode #{const SDLK_RALT} = RightAlt
+sdlKeycode #{const SDLK_RGUI} = RightGUI
+sdlKeycode #{const SDLK_MODE} = Mode
+sdlKeycode #{const SDLK_AUDIONEXT} = AudioNext
+sdlKeycode #{const SDLK_AUDIOPREV} = AudioPrevious
+sdlKeycode #{const SDLK_AUDIOSTOP} = AudioStop
+sdlKeycode #{const SDLK_AUDIOPLAY} = AudioPlay
+sdlKeycode #{const SDLK_AUDIOMUTE} = AudioMute
+sdlKeycode #{const SDLK_MEDIASELECT} = MediaSelect
+sdlKeycode #{const SDLK_WWW} = WWW
+sdlKeycode #{const SDLK_MAIL} = Mail
+sdlKeycode #{const SDLK_CALCULATOR} = Calculator
+sdlKeycode #{const SDLK_COMPUTER} = Computer
+sdlKeycode #{const SDLK_AC_SEARCH} = ACSearch
+sdlKeycode #{const SDLK_AC_HOME} = ACHome
+sdlKeycode #{const SDLK_AC_BACK} = ACBack
+sdlKeycode #{const SDLK_AC_FORWARD} = ACForward
+sdlKeycode #{const SDLK_AC_STOP} = ACStop
+sdlKeycode #{const SDLK_AC_REFRESH} = ACRefresh
+sdlKeycode #{const SDLK_AC_BOOKMARKS} = ACBookmarks
+sdlKeycode #{const SDLK_BRIGHTNESSDOWN} = BrightnessDown
+sdlKeycode #{const SDLK_BRIGHTNESSUP} = BrightnessUp
+sdlKeycode #{const SDLK_DISPLAYSWITCH} = DisplaySwitch
+sdlKeycode #{const SDLK_KBDILLUMTOGGLE} = KBIllumToggle
+sdlKeycode #{const SDLK_KBDILLUMDOWN} = KBIllumDown
+sdlKeycode #{const SDLK_KBDILLUMUP} = KBIllumUp
+sdlKeycode #{const SDLK_EJECT} = Eject
+sdlKeycode #{const SDLK_SLEEP} = Sleep
+sdlKeycode #{const SDLK_AMPERSAND} = Ampersand
+sdlKeycode #{const SDLK_ASTERISK} = Asterisk
+sdlKeycode #{const SDLK_AT} = At
+sdlKeycode #{const SDLK_CARET} = Caret
+sdlKeycode #{const SDLK_COLON} = Colon
+sdlKeycode #{const SDLK_DOLLAR} = Dollar
+sdlKeycode #{const SDLK_EXCLAIM} = Exclaim
+sdlKeycode #{const SDLK_GREATER} = Greater
+sdlKeycode #{const SDLK_HASH} = Hash
+sdlKeycode #{const SDLK_LEFTPAREN} = LeftParen
+sdlKeycode #{const SDLK_LESS} = Less
+sdlKeycode #{const SDLK_PERCENT} = Percent
+sdlKeycode #{const SDLK_PLUS} = Plus
+sdlKeycode #{const SDLK_QUESTION} = Question
+sdlKeycode #{const SDLK_QUOTEDBL} = DoubleQuote
+sdlKeycode #{const SDLK_RIGHTPAREN} = RightParen
+sdlKeycode #{const SDLK_UNDERSCORE} = Underscore
View
8 Graphics/UI/SDL/Keysym.hsc
@@ -16,6 +16,7 @@ module Graphics.UI.SDL.Keysym where
import Prelude hiding (Either(Left, Right))
import Control.Applicative
import Foreign
+import Graphics.UI.SDL.Keycode (Keycode, sdlKeycode)
data Keysym = Keysym { keyScancode :: Scancode
, keyKeycode :: Keycode
@@ -23,9 +24,6 @@ data Keysym = Keysym { keyScancode :: Scancode
}
deriving (Eq, Show)
--- TODO Expand these into their sums
-newtype Keycode = Keycode (Word32) deriving (Eq, Show, Storable)
-
instance Storable Keysym where
sizeOf = const #{size SDL_Keysym}
@@ -34,12 +32,12 @@ instance Storable Keysym where
poke ptr (Keysym s k m) = do
-- TODO? Do we care about poking keysyms?
-- #{poke SDL_Keysym, scancode} ptr s
- #{poke SDL_Keysym, sym} ptr k
+ -- #{poke SDL_Keysym, sym} ptr k
#{poke SDL_Keysym, mod} ptr m
#{poke SDL_Keysym, unused} ptr (0 :: Word32)
peek ptr = Keysym <$> (sdlScanCode <$> #{peek SDL_Keysym, scancode} ptr)
- <*> (Keycode <$> #{peek SDL_Keysym, sym} ptr)
+ <*> (sdlKeycode <$> #{peek SDL_Keysym, sym} ptr)
<*> #{peek SDL_Keysym, mod} ptr
data Scancode
View
27 Graphics/UI/SDL/Video.hsc
@@ -73,6 +73,7 @@ module Graphics.UI.SDL.Video
-- ** Textures
, createTextureFromSurface
+ , queryTextureSize
-- * OpenGL
, withOpenGL
@@ -92,6 +93,9 @@ module Graphics.UI.SDL.Video
, getClipboardText
, setClipboardText
, hasClipboardText
+
+ -- * Misc
+ , mkFinalizedSurface
) where
import Control.Applicative
@@ -382,6 +386,23 @@ createTextureFromSurface renderer surface =
foreign import ccall unsafe "&SDL_DestroyTexture"
sdlDestroyTexture_finalizer :: FunPtr (Ptr TextureStruct -> IO ())
+-- int SDL_QueryTexture(SDL_Texture* texture,
+-- Uint32* format,
+-- int* access,
+-- int* w,
+-- int* h)
+foreign import ccall unsafe "SDL_QueryTexture"
+ sdlQueryTexture :: Ptr TextureStruct -> Ptr CUInt -> Ptr CInt -> Ptr CInt -> Ptr CInt -> IO ()
+
+-- | Use this function to query the size of a texture.
+queryTextureSize :: Texture -> IO Size
+queryTextureSize texture =
+ withForeignPtr texture $ \ct ->
+ alloca $ \widthPtr ->
+ alloca $ \heightPtr -> do
+ sdlQueryTexture ct nullPtr nullPtr widthPtr heightPtr
+ mkSize <$> peek widthPtr <*> peek heightPtr
+
--------------------------------------------------------------------------------
foreign import ccall unsafe "SDL_GL_CreateContext"
sdlGlCreateContext :: Ptr WindowStruct -> IO (Ptr GLContextStruct)
@@ -638,7 +659,7 @@ loadBMP path =
bmp <- sdlLoadBMP crwops 0
if bmp == nullPtr
then error "loadBMP: failed to load BMP"
- else newForeignPtr sdlFreeSurface_finalizer bmp
+ else mkFinalizedSurface bmp
foreign import ccall unsafe "&SDL_FreeSurface"
sdlFreeSurface_finalizer :: FunPtr (Ptr SurfaceStruct -> IO ())
@@ -652,3 +673,7 @@ freeSurface = finalizeForeignPtr
foreign import ccall unsafe "SDL_free"
sdlFree :: Ptr a -> IO ()
+
+mkFinalizedSurface :: Ptr SurfaceStruct -> IO Surface
+mkFinalizedSurface = newForeignPtr sdlFreeSurface_finalizer
+
View
2  README
@@ -1,5 +1,5 @@
This package contains Haskell bindings to libSDL >= 2.0.0.
-
+[![Build Status](https://travis-ci.org/pradeepcodes/hsSDL2.png)](https://travis-ci.org/pradeepcodes/hsSDL2)
TODO:
- Surface creation and drawing.[1]
View
1  SDL.cabal
@@ -33,6 +33,7 @@ Library
Graphics.UI.SDL.Events,
Graphics.UI.SDL.Time,
Graphics.UI.SDL.Keysym,
+ Graphics.UI.SDL.Keycode,
Graphics.UI.SDL.Color,
Graphics.UI.SDL.RWOps,
Graphics.UI.SDL.Types,
View
96 hsSDL-image/Graphics/UI/SDL/Image.hsc
@@ -0,0 +1,96 @@
+#include "SDL_image.h"
+module Graphics.UI.SDL.Image
+ ( -- * Library initialization.
+ ImageFlag(..)
+ , withInit
+ , init
+ , quit
+ -- * Image loading.
+ , load
+ ) where
+
+import Foreign
+import Foreign.C
+import Control.Monad
+import Control.Exception
+import Prelude hiding (init)
+
+import Graphics.UI.SDL ( failWithError )
+import Graphics.UI.SDL.Video
+import Graphics.UI.SDL.Types
+import Graphics.UI.SDL.Utilities
+
+data ImageFlag
+ = InitJPG
+ | InitPNG
+ | InitTIF
+ deriving ( Eq, Ord, Show, Read, Bounded, Enum )
+
+imageFlagToC :: ImageFlag -> CInt
+imageFlagToC InitJPG = #{const IMG_INIT_JPG}
+imageFlagToC InitPNG = #{const IMG_INIT_PNG}
+imageFlagToC InitTIF = #{const IMG_INIT_TIF}
+
+{-
+int IMG_Init(int flags)
+
+flags
+bitwise OR'd set of image formats to support by loading a library now. The values you may OR together to pass in are:
+IMG_INIT_JPG
+IMG_INIT_PNG
+IMG_INIT_TIF
+Initialize by loading support as indicated by the flags, or at least return success if support is already loaded. You may call this multiple times, which will actually require you to call IMG_Quit just once to clean up. You may call this function with a 0 to retrieve whether support was built-in or not loaded yet.
+Note: to load JPG, PNG, and/or TIF images you can call IMG_Init with the right IMG_INIT_* flags OR'd together before you program gets busy, to prevent a later hiccup while it loads the library, and to check that you do have the support that you need before you try and use it.
+Note: No initialization is needed nor performed when using the IMG_isJPG, IMG_isPNG, and IMG_isTIF functions.
+Note: this function does not always set the error string, so do not depend on IMG_GetError being meaningful all the time.
+-}
+
+foreign import ccall unsafe "IMG_Init"
+ imgInit :: CInt -> IO CInt
+
+init :: [ImageFlag] -> IO ()
+init flags = do
+ ret <- imgInit (toBitmask imageFlagToC flags)
+ when (ret == (-1)) (failWithError "IMG_Init")
+
+withInit :: [ImageFlag] -> IO a -> IO a
+withInit flags = bracket_ (init flags) quit
+
+{-
+void IMG_Quit()
+
+This function cleans up all dynamically loaded library handles, freeing memory. If support is
+required again it will be initialized again, either by IMG_Init or loading an image with
+dynamic support required. You may call this function when IMG_Load functions are no longer
+needed for the JPG, PNG, and TIF image formats. You only need to call this function once, no
+matter how many times IMG_Init was called.
+-}
+foreign import ccall unsafe "IMG_Quit" quit :: IO ()
+
+
+
+
+{-
+SDL_Surface *IMG_Load(const char *file)
+
+file
+Image file name to load a surface from.
+Load file for use as an image in a new surface. This actually calls IMG_LoadTyped_RW, with the file extension used as the type string. This can load all supported image files, including TGA as long as the filename ends with ".tga". It is best to call this outside of event loops, and rather keep the loaded images around until you are really done with them, as disk speed and image conversion to a surface is not that speedy. Don't forget to SDL_FreeSurface the returned surface pointer when you are through with it.
+Note: If the image format loader requires initialization, it will attempt to do that the first time it is needed if you have not already called IMG_Init to load support for your image format.
+Note: If the image format supports a transparent pixel, SDL_image will set the colorkey for the surface. You can enable RLE acceleration on the surface afterwards by calling:
+SDL_SetColorKey(image, SDL_RLEACCEL, image->format->colorkey);
+
+Returns: a pointer to the image as a new SDL_Surface. NULL is returned on errors, such as no support built for the image, or a file reading error.
+-}
+foreign import ccall unsafe "IMG_Load"
+ imgLoad :: CString -> IO (Ptr SurfaceStruct)
+
+-- FIXME: Error handling
+load :: FilePath -> IO Surface
+load filepath =
+ withCString filepath $ \cPath -> do
+ surface <- imgLoad cPath
+ mkFinalizedSurface surface
+
+
+
View
1  hsSDL-image/LICENSE
@@ -0,0 +1 @@
+Public Domain
View
0  hsSDL-image/README.md
No changes.
View
2  hsSDL-image/SDL-image.buildinfo.in
@@ -0,0 +1,2 @@
+cc-options: @SDL_CFLAGS@
+ld-options: @SDL_LIBS@
View
30 hsSDL-image/SDL-image.cabal
@@ -0,0 +1,30 @@
+Cabal-Version: >= 1.6
+Name: SDL2-image
+Version: 0.1.0
+Maintainer: Lemmih (lemmih@gmail.com)
+Author: Lemmih (lemmih@gmail.com)
+Copyright: 2004-2010, Lemmih
+License-File: LICENSE
+License: PublicDomain
+Build-Type: Custom
+Category: Foreign binding
+Synopsis: Binding to libSDL_image
+Description:
+ SDL_image is an image file loading library.
+ It loads images as SDL surfaces, and supports the
+ following formats: BMP, GIF, JPEG, LBM, PCX, PNG,
+ PNM, TGA, TIFF, XCF, XPM, XV.
+Extra-Source-Files: configure, includes/HsSDLConfig.h.in, SDL-image.buildinfo.in, config.mk.in
+Data-Files: README.md
+
+Library
+ Extensions: ForeignFunctionInterface
+ Build-Depends: base >= 3 && < 5, SDL2
+ Exposed-Modules:
+ Graphics.UI.SDL.Image
+ Includes: SDL.h SDL_image.h
+ GHC-Options: -Wall
+
+source-repository head
+ type: darcs
+ location: http://mirror.seize.it/hsSDL/hssdl-image/
View
5 hsSDL-image/Setup.lhs
@@ -0,0 +1,5 @@
+#!/usr/bin/env runhaskell
+> module Main where
+> import Distribution.Simple
+> main :: IO ()
+> main = defaultMainWithHooks autoconfUserHooks
View
5 hsSDL-image/config.mk.in
@@ -0,0 +1,5 @@
+SDL_CFLAGS=@SDL_CFLAGS@
+SDL_LIBS=@SDL_LIBS@
+PACKAGE=@PACKAGE_TARNAME@
+VERSION=@PACKAGE_VERSION@
+MAINTAINER=@PACKAGE_BUGREPORT@
View
3,970 hsSDL-image/configure
3,970 additions, 0 deletions not shown
View
41 hsSDL-image/configure.ac
@@ -0,0 +1,41 @@
+AC_INIT([Haskell SDL package], [0.5.2], [lemmih@gmail.com], [SDL2-image])
+
+# Safety check: Ensure that we are in the correct source directory.
+AC_CONFIG_SRCDIR([includes/HsSDLConfig.h.in])
+
+# Header file to place defines in
+AC_CONFIG_HEADERS([includes/HsSDLConfig.h])
+
+AC_PATH_PROGS([SDL_CONFIG], [sdl2-config sdl20-config], [none])
+
+if test "x$SDL_CONFIG" = "xnone"; then
+
+ AC_MSG_ERROR([*** SDL not found! Get SDL from www.libsdl.org.
+If you already installed it, check it's in the path. If problem remains,
+please send a mail to the address that appears in ./configure --version
+indicating your platform, the version of configure script and the problem.])
+
+fi
+
+SDL_LIBS="-L`$SDL_CONFIG --prefix`/lib -lSDL2_image"
+
+LDFLAGS=$SDL_LIBS
+AC_CHECK_LIB([SDL2_image],
+ [IMG_Load],
+ ,
+ [AC_MSG_ERROR([*** SDL2_image lib not found! Get SDL2_image from
+http://www.libsdl.org/projects/SDL_image/index.html])])
+LDFLAGS=
+
+if test x`uname` = "xDarwin"; then
+ #SDL_LIBS="`$SDL_CONFIG --prefix`/lib/libSDLmain.a `$SDL_CONFIG --prefix`/lib/libSDL.dylib -Wl,-framework,Cocoa"
+ SDL_LIBS="$SDL_LIBS `$SDL_CONFIG --prefix`/lib/libSDL2_image.dylib -Wl,-framework,Cocoa"
+fi
+
+SDL_CFLAGS=`$SDL_CONFIG --cflags`
+
+AC_SUBST([SDL_CFLAGS])
+AC_SUBST([SDL_LIBS])
+
+AC_CONFIG_FILES([config.mk SDL-image.buildinfo])
+AC_OUTPUT
View
22 hsSDL-image/includes/HsSDLConfig.h.in
@@ -0,0 +1,22 @@
+/* includes/HsSDLConfig.h.in. Generated from configure.ac by autoheader. */
+
+/* Define to 1 if you have the `SDL2_image' library (-lSDL2_image). */
+#undef HAVE_LIBSDL2_IMAGE
+
+/* Define to the address where bug reports for this package should be sent. */
+#undef PACKAGE_BUGREPORT
+
+/* Define to the full name of this package. */
+#undef PACKAGE_NAME
+
+/* Define to the full name and version of this package. */
+#undef PACKAGE_STRING
+
+/* Define to the one symbol short name of this package. */
+#undef PACKAGE_TARNAME
+
+/* Define to the home page for this package. */
+#undef PACKAGE_URL
+
+/* Define to the version of this package. */
+#undef PACKAGE_VERSION

No commit comments for this range

Something went wrong with that request. Please try again.