packages feed

free-game 0.9.2 → 0.9.3

raw patch · 9 files changed

+45/−12 lines, 9 filesdep ~GLFW-b

Dependency ranges changed: GLFW-b

Files

Graphics/UI/FreeGame.hs view
@@ -26,7 +26,7 @@ ) where
 
 import Graphics.UI.FreeGame.Base
-import Graphics.UI.FreeGame.GUI (GUI, GUIParam(..), Picture)
+import Graphics.UI.FreeGame.GUI (GUI, GUIParam(..))
 import Graphics.UI.FreeGame.Util
 import Graphics.UI.FreeGame.Types
 import Graphics.UI.FreeGame.Text
Graphics/UI/FreeGame/Base.hs view
@@ -30,6 +30,7 @@     ,_LiftUI     -- * Classes     ,Picture2D(..)+    ,rotate     ,Figure2D(..)     ,Keyboard(..)     ,Mouse(..)@@ -134,12 +135,23 @@ class Picture2D p where     -- | Construct a 'Picture2D' from a 'Bitmap'.     fromBitmap :: Bitmap -> p ()-    -- | Counterclockwise, degrees-    rotate :: Float -> p a -> p a+    -- | (radians)+    rotateR :: Float -> p a -> p a+    -- | (degrees)+    rotateD :: Float -> p a -> p a     scale :: V2 Float -> p a -> p a     translate :: V2 Float -> p a -> p a     colored :: Color -> p a -> p a +    rotateR = rotateD . (* 180) . (/ pi)+    rotateD = rotateR . (/ 180) . (* pi)++-- | Deprecated synonym for 'rotateD'.+rotate :: Picture2D p => Float -> p a -> p a+rotate = rotateD++{-# DEPRECATED rotate "Use rotateD instead" #-} + class Picture2D p => Figure2D p where     line :: [V2 Float] -> p ()     polygon :: [V2 Float] -> p ()@@ -223,7 +235,8 @@  #define MK_PICTURE_2D(cxt, ty, l, t) instance (Picture2D m cxt) => Picture2D (ty) where { \     fromBitmap = (l) . fromBitmap; \-    rotate = (t) . rotate; \+    rotateD = (t) . rotateD; \+    rotateR = (t) . rotateR; \     translate = (t) . translate; \     scale = (t) . scale; \     colored = (t) . colored }
Graphics/UI/FreeGame/Data/Font.hs view
@@ -66,9 +66,11 @@ metricsAscent :: Font -> Float
 metricsAscent (Font _ (a, _) _ _) = a
 
+-- | Get the font's metrics.
 metricsDescent :: Font -> Float
 metricsDescent (Font _ (_, d) _ _) = d
 
+-- | Get the font's boundingbox.
 fontBoundingBox :: Font -> BoundingBox Float
 fontBoundingBox (Font _ _ b _) = b
 
Graphics/UI/FreeGame/GUI.hs view
@@ -33,6 +33,7 @@ -- | A 'Functor' which represents graphical user interfaces.
 type GUI = UI GUIBase
 
+-- | The base of 'GUI'.
 data GUIBase a = Input (Ap GUIInput a) | Draw (Picture a) deriving Functor
 
 -- | _Draw :: Traversal' (GUIBase a) (Picture a)
@@ -47,7 +48,7 @@ 
 instance Picture2D GUIBase where
     fromBitmap = Draw . fromBitmap
-    rotate = over _Draw . rotate
+    rotateD = over _Draw . rotateD
     scale = over _Draw . scale
     translate = over _Draw . translate
     colored = over _Draw . colored
@@ -74,6 +75,7 @@ instance FromFinalizer GUIBase where
     fromFinalizer = Draw . fromFinalizer
 
+-- | A free structure that represents inputs.
 data GUIInput a = 
       ICharKey Char (Bool -> a)
     | ISpecialKey SpecialKey (Bool -> a)
@@ -84,10 +86,11 @@     | IMouseButtonR (Bool -> a)
     deriving Functor
 
+-- | A free structure that represents pictures.
 data Picture a
     = LiftBitmap Bitmap a
     | PictureWithFinalizer (FinalizerT IO a)
-    | Rotate Float (Picture a)
+    | RotateD Float (Picture a)
     | Scale (V2 Float) (Picture a)
     | Translate (V2 Float) (Picture a)
     | Colored Color (Picture a)
@@ -102,7 +105,7 @@ 
 instance Picture2D Picture where
     fromBitmap = flip LiftBitmap ()
-    rotate = Rotate
+    rotateD = RotateD
     scale = Scale
     translate = Translate
     colored = Colored
@@ -129,6 +132,7 @@     mouseButtonR = IMouseButtonR id
     mouseButtonM = IMouseButtonM id
 
+-- | Parameters of the application.
 data GUIParam = GUIParam
     { _framePerSecond :: Int
     , _windowSize :: V2 Int
Graphics/UI/FreeGame/GUI/GLFW.hs view
@@ -148,7 +148,7 @@ runPicture _ (LiftBitmap bmp@(BitmapData _ Nothing) r) = do
     liftIO $ runFinalizerT $ installTexture bmp >>= liftIO . drawTexture
     return r
-runPicture sc (Rotate theta cont) = preservingMatrix' $ do
+runPicture sc (RotateD theta cont) = preservingMatrix' $ do
     liftIO $ GL.rotate (gf (-theta)) (GL.Vector3 0 0 1)
     runPicture sc cont
 runPicture sc (Scale (V2 sx sy) cont) = preservingMatrix' $ do
Graphics/UI/FreeGame/Text.hs view
@@ -18,6 +18,7 @@ instance Monad m => IsString (TextT m ()) where
     fromString str = mapM_ (\c -> liftF (TypeChar c ())) str
 
+-- | Render a 'TextT'.
 runTextT :: (FromFinalizer m, Monad m, Picture2D m) => Maybe (BoundingBox Float) -> Font -> Float -> TextT m a -> m a
 runTextT bbox font size = flip evalStateT (V2 x0 y0) . go where
     go m = lift (runFreeT m) >>= \r -> case r of
@@ -39,5 +40,6 @@     advV = size * (metricsAscent font - metricsDescent font) * 1.1
     (V2 x0 y0, cond) = maybe (zero, const True) (\b -> (view _TopLeft b, flip inBoundingBox b)) bbox
 
+-- | Render a 'String'.
 text :: (FromFinalizer m, Monad m, Picture2D m) => Font -> Float -> String -> m ()
 text font size str = runTextT Nothing font size (fromString str)
Graphics/UI/FreeGame/Types.hs view
@@ -24,6 +24,7 @@ -- | 2D bounding box.
 data BoundingBox a = BoundingBox a a a a deriving (Show, Eq, Ord, Functor, Read)
 
+-- | Determine whether the given point is in the 'BoundingBox'.
 inBoundingBox :: Ord a => V2 a -> BoundingBox a -> Bool
 inBoundingBox (V2 x y) (BoundingBox x0 y0 x1 y1) = x0 <= x && x <= x1 && y0 <= y && y <= y1
 
Graphics/UI/FreeGame/Util.hs view
@@ -24,6 +24,8 @@     -- * Helper
     degrees,
     radians,
+    unitV2,
+    angleV2,
     sinCos,
     -- * Loading
     loadPictureFromFile,
@@ -56,9 +58,18 @@ (<||>) :: Applicative f => f Bool -> f Bool -> f Bool
 (<||>) = liftA2 (||)
 
--- | Create a unit vector from a direction.
+-- | A unit vector with given angle.
+unitV2 :: Floating a => a -> V2 a
+unitV2 t = V2 (cos t) (sin t)
+
+-- | An angle of given vector.
+angleV2 :: RealFloat a => V2 a -> a
+angleV2 (V2 a b) = atan2 b a
+
+-- | Deprecated synonym for 'unitV2'.
 sinCos :: Floating a => a -> V2 a
-sinCos t = V2 (cos t) (sin t)
+sinCos = unitV2
+{-# DEPRECATED sinCos "Use unitV2 instead" #-} 
 
 -- | Extract the next frame of the action.
 untick :: (Functor n, MonadFree (UI n) m) => Free (UI n) a -> m (Either (Free (UI n) a) a)
free-game.cabal view
@@ -1,5 +1,5 @@ name:                free-game
-version:             0.9.2
+version:             0.9.3
 synopsis:            Create graphical applications for free
 description:         Cross-platform GUI library based on free monads
 homepage:            https://github.com/fumieval/free-game
@@ -46,7 +46,7 @@     free == 3.*,
     repa,
     freetype2 >= 0.1,
-    GLFW-b >= 0.1.0.3,
+    GLFW-b >= 0.1.0.5,
     hashable >= 1.2,
     mtl >= 2.1,
     OpenGL == 2.8.*,