packages feed

SDL 0.4.0 → 0.5.0

raw patch · 7 files changed

+199/−5 lines, 7 files

Files

Graphics/UI/SDL/Events.hsc view
@@ -129,7 +129,7 @@     | LostFocus [Focus]     | KeyDown !Keysym     | KeyUp !Keysym-    | MouseMotion !Word16 !Word16 !Word16 !Word16+    | MouseMotion !Word16 !Word16 !Int16 !Int16     | MouseButtonDown !Word16                       !Word16                       !MouseButton@@ -365,7 +365,7 @@     = do #{poke SDL_KeyboardEvent, state} ptr state          #{poke SDL_KeyboardEvent, keysym} ptr keysym -pokeMouseMotion :: Ptr Event -> Word16 -> Word16 -> Word16 -> Word16 -> IO ()+pokeMouseMotion :: Ptr Event -> Word16 -> Word16 -> Int16 -> Int16 -> IO () pokeMouseMotion ptr x y xrel yrel     = do #{poke SDL_MouseMotionEvent, x} ptr x          #{poke SDL_MouseMotionEvent, y} ptr y
Graphics/UI/SDL/Types.hsc view
@@ -34,6 +34,8 @@     , pixelFormatGetColorKey     , pixelFormatGetBitsPerPixel     , pixelFormatGetBytesPerPixel+    , videoInfoWidth+    , videoInfoHeight     ) where  import Foreign (Word8, Word16, Word32, Ptr, Storable(peekByteOff),@@ -271,4 +273,16 @@ surfaceGetPixels surface     = withForeignPtr surface $       #peek SDL_Surface, pixels++videoInfoWidth :: VideoInfo -> Int+videoInfoWidth vi+    = unsafePerformIO $+      withForeignPtr vi $+      #peek SDL_VideoInfo, current_w++videoInfoHeight :: VideoInfo -> Int+videoInfoHeight vi+    = unsafePerformIO $+      withForeignPtr vi $+      #peek SDL_VideoInfo, current_h 
Graphics/UI/SDL/Video.hsc view
@@ -612,7 +612,7 @@  -- | Converts a surface to the display format. Throws an exception on error. displayFormatAlpha :: Surface -> IO Surface-displayFormatAlpha = unwrapMaybe "SDL_DisplayFormatAlpha" . tryDisplayFormat+displayFormatAlpha = unwrapMaybe "SDL_DisplayFormatAlpha" . tryDisplayFormatAlpha  -- void SDL_WarpMouse(Uint16 x, Uint16 y); foreign import ccall unsafe "SDL_WarpMouse" sdlWarpMouse :: Word16 -> Word16 -> IO ()
+ MACOSX view
@@ -0,0 +1,72 @@+hsSDL on Mac OS X as of February 26, 2006.+------------------------------------------++Developing software with SDL and hsSDL on Mac OS X can be a bit painful.  There are at least three problems, two of which are essentially solved at this time.++Building hsSDL on Mac OS X+--------------------------++We need to give options to hsc2hs to play nicely with SDL, but there is a problem with hsc2hs options on Mac; dons explained it to me on #haskell but I can't remember the details.  (I think the --ld=gcc is the crucial option.)  I don't think there's anyway to give hsc2hs arguments on the cabal Setup.lhs command line, or in the .cabal file.  Here's one way to fix it:++Create your own hsc2hs wrapper that has the arguments.  Let's call it+myhsc2hs:++#!/bin/sh+echo "/usr/local/bin/hsc2hs -v --cc=gcc --ld=gcc --lflag="-L/sw/lib -lSDLmain -framework AppKit -framework SDL" $@"+/usr/local/bin/hsc2hs -v --cc=gcc --ld=gcc --lflag="-L/sw/lib" --lflag="-lSDLmain" --lflag="-framework" --lflag="AppKit" --lflag="-framework" --lflag="SDL" "$@"++Run cabal configure with your own hsc2hs:++$ runhaskell ./Setup.lhs configure --with-hsc2hs ~/bin/myhsc2hs+Configuring SDL-0.3.0...+configure: Using install prefix: /usr/local+configure: Using compiler: /usr/local/bin/ghc+configure: Compiler flavor: GHC+configure: Compiler version: 6.4.1+configure: Using package tool: /usr/local/bin/ghc-pkg+configure: No haddock found+configure: Using happy: /usr/local/bin/happy+configure: Using alex: /usr/local/bin/alex+configure: Using hsc2hs: /Users/nalexand/bin/myhsc2hs+configure: No c2hs found+configure: No cpphs found+configure: No greencard found+configure: Dependency base-any: using base-1.0++Run cabal build (verbosely to see if your hsc2hs is being used):++$ runhaskell ./Setup.lhs build -v+Preprocessing library SDL-0.2.0...+/Users/nalexand/bin/myhsc2hs -D__GLASGOW_HASKELL__=604 -I/usr/local/+lib/ghc-6.4.1/include -I/sw/include/SDL -o Graphics/UI/SDL/General.hs+Graphics/UI/SDL/General.hsc+/usr/local/bin/hsc2hs -v --cc=gcc --ld=gcc --lflag=-L/sw/lib -+lSDLmain -framework AppKit -framework SDL -D__GLASGOW_HASKELL__=604 -+I/usr/local/lib/ghc-6.4.1/include -I/sw/include/SDL -o Graphics/UI/+SDL/General.hs Graphics/UI/SDL/General.hsc+Executing: gcc -c -I/usr/local/lib/ghc-6.4.1/include -I/sw/include/+SDL Graphics/UI/SDL/General_hsc_make.c -o Graphics/UI/SDL/+General_hsc_make.o+...++Running programs built with hsSDL on Mac OS X+---------------------------------------------++All our troubles stem from SDL's startup procedure on Mac OS X.  The fundamental problem is that SDL uses Objective-C and Cocoa to open a UI window; this means that Cocoa must be initialized, and in particular, an NSAutoReleasePool be in place.  This initialization is done in libSDLmain.  For C/C++/Objective-C programs, libSDLmain #defines the developer's main to be SDL_main and piggy backs SDL_main onto it's own Cocoa main, using the C preprocessor and abusing the linker.  Of course, this technique will never work for Haskell: there is no clean entry point to a Haskell runtime in this fashion.++But we can fake it.  In Core/Examples/MacOSX, I've included the Core/Examples/Test.hs example and a small Cabal definition to build it.  Our actual 'main' is Test.sdl_main.  We provide a Main.main, 'foreign export'ed as 'hs_main', which we will call from C.  (We indirect so that the file Main_stub.o need not be rebuilt every time we modify module Test.)  We provide our own 'SDL_main' in c_main.c, which initializes the Haskell runtime and calls 'hs_main', running Test.main in an environment with SDL available.  Finally, libSDLmain will find our C 'SDL_main' and call it, starting the whole process.++I recommend modifying this example when starting new projects.++GHCi and hsSDL on Mac OS X+--------------------------++At the moment, hsSDL can be loaded in GHCi.  Unfortunately, no programs will run correctly.  The startup procedure described above has not been implemented in GHCi, although there is no deep problem (that I can see) preventing a customized GHCi that starts SDL first from being built.  I, for one, would truly appreciate an implementation.++Contact information+-------------------++All Mac OS X patches should be routed to Lemmih (lemmih@gmail.com).  Any Mac OS X specific questions/comments could be forwarded to me, Nick Alexander (ncalexan@uci.edu).++Best of luck,+Nick
+ README view
@@ -0,0 +1,11 @@+This package contains Haskell bindings to libSDL >= 1.2.8.++Global installation:+  runhaskell Setup.lhs configure+  runhaskell Setup.lhs build+  runhaskell Setup.lhs install # as root++Local installation:+  runhaskell Setup.lhs configure --prefix=[HOME]/usr --user+  runhaskell Setup.lhs build+  runhaskell Setup.lhs install --user # not as root
SDL.cabal view
@@ -1,5 +1,5 @@ Name: SDL-Version: 0.4.0+Version: 0.5.0 Maintainer: Lemmih (lemmih@gmail.com) Author: Lemmih (lemmih@gmail.com) Copyright: 2004-2005, Lemmih@@ -8,7 +8,7 @@ Build-Depends: base Category: Foreign binding Synopsis: Binding to libSDL-Tested-with: GHC ==6.4, Hugs ==20050308+Tested-with: GHC ==6.6, GHC ==6.8, Hugs ==20050308 Extensions: CPP, ForeignFunctionInterface, MultiParamTypeClasses, FunctionalDependencies Exposed-Modules:   Graphics.UI.SDL,@@ -32,3 +32,4 @@ Extra-Libraries: SDL Frameworks: AppKit GHC-Options: -fglasgow-exts -Wall -Werror+Data-files: README, MACOSX, WIN32
+ WIN32 view
@@ -0,0 +1,96 @@+Building hsSDL on Win32+-----------------------+Bit Connor <bit@mutantlemon.com>+++This is how I managed to get hsSDL working on Windows XP.+I used GHC version 6.6.1+++1. Download the SDL mingw development package from the SDL website+   http://www.libsdl.org++   The file I used was SDL-devel-1.2.12-mingw32.tar.gz++2. Extract it somewhere. You will get a directory called SDL-1.2.12++   I used C:\SDL-1.2.12++3. Modify SDL.cabal file from hsSDL distribution.++   A. There is a line:++          Extra-Libraries: SDL++      Change it to:++          Extra-Libraries: SDL.dll SDLmain++   B. Add two new lines to the end of the file:++          Include-Dirs: C:\SDL-1.2.12\include+          Extra-Lib-Dirs: C:\SDL-1.2.12\lib++4. Modify C:\SDL-1.2.12\include\SDL.h++   Line 28 there is a line:++       #include "SDL_main.h"++   Comment this out by changing it to:++       /* #include "SDL_main.h" */++   (This step is needed so that hsc2hs will later work correctly. hsc2hs works+   by generating a C program that generates a haskell program when run.+   SDL_main.h uses a preprocessor macro to mangle the program's main function.+   This causes hsc2hs to fail)++5. Open a Windows Command Prompt (Start -> Run -> "cmd.exe")+   cd into the hsSDL distribution directory and run:++       runghc Setup.lhs configure++   I got an error at the end, about a missing sh:++       ...+       configure: Using hsc2hs: C:\ghc\ghc-6.6.1\bin\hsc2hs.exe+       configure: No c2hs found+       configure: No cpphs found+       configure: No greencard found+       Setup.lhs: Cannot find: sh++   I ignored the error, and didn't have any problems.++   Next run:++       runghc Setup.lhs build++   Finally, run:++       runghc Setup.lhs install++6. Compile the example program. Run:++       cd Examples+       ghc --make Test.hs++   You should get a Test.exe file.+   Before running it, copy the SDL.dll file into the directory. You can find+   it here:++       C:\SDL-1.2.12\bin\SDL.dll++   Now run Test.exe, press spacebar a few times to watch the smiley face jump+   around, and finally press Q to quit.++7. Using SDL from GHCi does not seem to work. This is the error I get trying to+   run Test.hs from GHCi:++       Prelude Main> main+       Loading package SDL-0.4.0 ... can't load .so/.DLL for: SDLmain (addDLL: unknown+       error)++Peace,+Bit Connor <bit@mutantlemon.com>+