packages feed

spice 0.1.1.0 → 0.1.2.1

raw patch · 8 files changed

+199/−10 lines, 8 filesPVP ok

version bump matches the API change (PVP)

API changes (from Hackage documentation)

+ FRP.Spice.Graphics.Color: Color :: Float -> Float -> Float -> Float -> Color
+ FRP.Spice.Graphics.Color: bindColor :: Color -> IO ()
+ FRP.Spice.Graphics.Color: black :: Color
+ FRP.Spice.Graphics.Color: blue :: Color
+ FRP.Spice.Graphics.Color: color3f :: Float -> Float -> Float -> Color
+ FRP.Spice.Graphics.Color: color3i :: Int -> Int -> Int -> Color
+ FRP.Spice.Graphics.Color: color4f :: Float -> Float -> Float -> Float -> Color
+ FRP.Spice.Graphics.Color: color4i :: Int -> Int -> Int -> Int -> Color
+ FRP.Spice.Graphics.Color: data Color
+ FRP.Spice.Graphics.Color: getAlpha :: Color -> Float
+ FRP.Spice.Graphics.Color: getBlue :: Color -> Float
+ FRP.Spice.Graphics.Color: getGreen :: Color -> Float
+ FRP.Spice.Graphics.Color: getRed :: Color -> Float
+ FRP.Spice.Graphics.Color: green :: Color
+ FRP.Spice.Graphics.Color: instance Eq Color
+ FRP.Spice.Graphics.Color: instance Read Color
+ FRP.Spice.Graphics.Color: instance Show Color
+ FRP.Spice.Graphics.Color: red :: Color
+ FRP.Spice.Graphics.Color: white :: Color
+ FRP.Spice.Graphics.Geometry: renderPoint :: Vector Float -> IO ()
+ FRP.Spice.Graphics.Geometry: renderRectangle :: Vector Float -> Vector Float -> IO ()
+ FRP.Spice.Graphics.Geometry: renderSquare :: Vector Float -> Float -> IO ()
+ FRP.Spice.Graphics.Utils: togl :: Float -> GLfloat

Files

spice.cabal view
@@ -1,5 +1,5 @@ name:                spice-version:             0.1.1.0+version:             0.1.2.1 synopsis:            An FRP-based game engine written in Haskell. description:         An FRP-based game engine written in Haskell. - See the homepage for more information. homepage:            http://github.com/crockeo/spice@@ -21,6 +21,10 @@                        FRP.Spice.Engine.RenderWrapper                        FRP.Spice.Engine.RunInput                        FRP.Spice.Game+                       FRP.Spice.Graphics+                       FRP.Spice.Graphics.Color+                       FRP.Spice.Graphics.Geometry+                       FRP.Spice.Graphics.Utils                        FRP.Spice.Input                        FRP.Spice.Input.Keyboard                        FRP.Spice.Input.Mouse
+ src/FRP/Spice/Graphics.hs view
@@ -0,0 +1,13 @@+{-|+  This module re-exports a number of modules having to do with graphics.+-}+module FRP.Spice.Graphics ( module FRP.Spice.Graphics.Geometry+                          , module FRP.Spice.Graphics.Color+                          , module FRP.Spice.Graphics.Utils+                          ) where++-----------------------+-- Rexported Imports --+import FRP.Spice.Graphics.Geometry+import FRP.Spice.Graphics.Color+import FRP.Spice.Graphics.Utils
+ src/FRP/Spice/Graphics/Color.hs view
@@ -0,0 +1,97 @@+{-|+  This module provides an abstraction over the default representations of color+  in the Haskell OpenGL bindings.+-}+module FRP.Spice.Graphics.Color where++--------------------+-- Global Imports --+import Graphics.Rendering.OpenGL (Color4 (..), GLfloat, color)++-------------------+-- Local Imports --+import FRP.Spice.Graphics.Utils++----------+-- Code --++{-|+  Representing a Color using four @'Float'@ representing reg, green, blue, and+  the alpha mask respectively. The @'Float'@s are in a range from 0-1,+  representing @'Int'@s from 0-255.+-}+data Color = Color { getRed   :: Float+                   , getGreen :: Float+                   , getBlue  :: Float+                   , getAlpha :: Float+                   }+  deriving (Eq, Show, Read)++{-|+  Changes the current OpenGL context's rendering color to the @'Color'@+  specified.+-}+bindColor :: Color -> IO ()+bindColor (Color r g b a) =+  color $ Color4 (togl r) (togl g) (togl b) (togl a)++{-|+  A synonym for the @'Color'@ constructor.+-}+color4f :: Float -> Float -> Float -> Float -> Color+color4f = Color++{-|+  Constructing a @'Color'@ from 3 @'Float'@s, defaulting the alpha mask to 1.0.+-}+color3f :: Float -> Float -> Float -> Color+color3f r g b = color4f r g b 1.0++{-|+  Creating a @'Color'@ from 4 @'Int'@s. The ints, similarly to @'color4f'@+  represent red, green, blue, and the alpha mask respectively. The ints should+  be in the range of 0-255. (Note: @'color4i'@ is functionally equivalent (and+  also equivalent in source code) to calling color4f with each of its arguments+  divided by 255.)+-}+color4i :: Int -> Int -> Int -> Int -> Color+color4i r g b a = color4f (fromIntegral r / 255)+                          (fromIntegral g / 255)+                          (fromIntegral b / 255)+                          (fromIntegral a / 255)++{-|+  Constructing a @'Color'@ from 3 @'Int'@s, defaulting the alpha mask to 255.+-}+color3i :: Int -> Int -> Int -> Color+color3i r g b = color4i r g b 255++{-|+  The color black.+-}+black :: Color+black = color3i 0 0 0++{-|+  The color white.+-}+white :: Color+white = color3i 255 255 255++{-|+  The color red.+-}+red :: Color+red = color3i 255 0 0++{-|+  The color green.+-}+green :: Color+green = color3i 0 255 0++{-|+  The color blue.+-}+blue :: Color+blue = color3i 0 0 255
+ src/FRP/Spice/Graphics/Geometry.hs view
@@ -0,0 +1,42 @@+{-|+  This module provides a cleaner API to render a number of shapes in the+  current OpenGL context.+-}+module FRP.Spice.Graphics.Geometry where++--------------------+-- Global Imports --+import Graphics.Rendering.OpenGL++-------------------+-- Local Imports --+import FRP.Spice.Graphics.Utils+import FRP.Spice.Math.Vector++----------+-- Code --++{-|+  Rendering a point.+-}+renderPoint :: Vector Float -> IO ()+renderPoint (Vector x y) = do+  renderPrimitive Points $+    vertex $ Vertex2 (togl x) (togl y)++{-|+  Rendering a rectangle.+-}+renderRectangle :: Vector Float -> Vector Float -> IO ()+renderRectangle (Vector x y) (Vector w h) = do+  renderPrimitive Quads $ do+    vertex $ Vertex2 (togl (x    )) (togl (y    ))+    vertex $ Vertex2 (togl (x + w)) (togl (y    ))+    vertex $ Vertex2 (togl (x + w)) (togl (y + h))+    vertex $ Vertex2 (togl (x    )) (togl (y + h))++{-|+  Rendering a square.+-}+renderSquare :: Vector Float -> Float -> IO ()+renderSquare pos size = renderRectangle pos $ Vector size size
+ src/FRP/Spice/Graphics/Utils.hs view
@@ -0,0 +1,18 @@+{-|+  This module provides a set of utilities to ease the burden of writing OpenGL+  rendering functions.+-}+module FRP.Spice.Graphics.Utils where++--------------------+-- Global Imports --+import Graphics.Rendering.OpenGL++----------+-- Code --++{-|+  Converting a @'Float'@ to a @'GLfloat'@+-}+togl :: Float -> GLfloat+togl = realToFrac
src/FRP/Spice/Input/Keyboard.hs view
@@ -21,8 +21,7 @@ keys = map toEnum [0 .. 318]  {-|-  A Map from @'Key'@ to the externals created for every single-  key.+  A Map from @'Key'@ to the externals created for every single key. -} externals :: IO (Map Key (Signal Bool, Bool -> IO ())) externals = liftM fromList $ mapM (\k -> liftM ((,) k) $ external False) keys
src/FRP/Spice/Input/Mouse.hs view
@@ -24,7 +24,9 @@ instance Ord MouseButton where   mb1 <= mb2 = fromEnum mb1 < fromEnum mb2 --- A set of all mouse buttons available via GLFW+{-|+  A list of all mouse buttons available via the GLFW api.+-} buttons :: [MouseButton] buttons = [ ButtonLeft           , ButtonRight@@ -33,14 +35,22 @@           ++           map ButtonNo [0 .. 7] --- Getting externals for all of the buttons+{-|+  A map from @'MouseButton'@ to externals created for every button.+-} externals :: IO (Map MouseButton (Signal Bool, Bool -> IO ())) externals = liftM fromList $ mapM (\b -> liftM ((,) b) $ external False) buttons --- Getting the signals from the externals+{-|+  Creating the @'Signal'@ of a @'Map'@ from @'MouseButton'@ to @'Bool'@ from a+  @'Map'@ of @'externals'@.+-} signals :: Map MouseButton (Signal Bool, Bool -> IO ()) -> Signal (Map MouseButton Bool) signals = T.sequence . fmap fst --- Getting the sinks from the externals+{-|+  Making a @'Map'@ from @'MouseButton'@ to sink from a @'Map'@ of+  @'externals'@.+-} sinks :: Map MouseButton (Signal Bool, Bool -> IO ()) -> Map MouseButton (Bool -> IO ()) sinks = fmap snd
src/FRP/Spice/Input/MousePosition.hs view
@@ -14,14 +14,20 @@ -- Local Imports -- import FRP.Spice.Math.Vector --- Getting the external for the mouse position+{-|+  Creating the external for the mouse position.+-} externals :: IO (Signal (Vector Float), Vector Float -> IO ()) externals = external def --- Getting the signal from the external+{-|+  Getting the signal from the mouse position external.+-} signals :: (Signal (Vector Float), Vector Float -> IO ()) -> Signal (Vector Float) signals = fst --- Getting the signal from the external+{-|+  Getting the sink from the mouse position external.+-} sinks :: (Signal (Vector Float), Vector Float -> IO ()) -> Vector Float -> IO () sinks = snd