free-game 0.9.4 → 0.9.4.1
raw patch · 5 files changed
+29/−22 lines, 5 files
Files
- Graphics/UI/FreeGame.hs +15/−19
- Graphics/UI/FreeGame/GUI/GLFW.hs +1/−0
- Graphics/UI/FreeGame/Text.hs +5/−1
- Graphics/UI/FreeGame/Types.hs +7/−1
- free-game.cabal +1/−1
Graphics/UI/FreeGame.hs view
@@ -7,9 +7,7 @@ This module just re-exports other submodules. -} module Graphics.UI.FreeGame - ( -- * Examples - -- $example - -- * Main + ( -- * Main Game, runGame, def, @@ -47,27 +45,25 @@ import Linear hiding (rotate) -- | 'Game' is a "free" monad which describes GUIs. --- This monad is an instance of 'Picture2D' so you can create it using 'fromBitmap' and can be transformed with 'translate', 'scale', 'rotate', 'colored'. +-- This monad is an instance of 'Picture2D' so you can construct it using 'fromBitmap' and can be transformed with 'translate', 'scale', 'rotate', 'colored'. -- --- It is also an instance of 'Keyboard' and 'Mouse'. +-- It is also an instance of 'Keyboard' and 'Mouse'. Note that 'mousePosition' returns a relative position. For example: -- --- You have to call 'tick' at the end of the current frame. +-- > foo = foreverTick $ do +-- > p <- mousePosition +-- > translate p $ colored blue $ polygonOutline [V2 (-8) (-8), V2 8 (-8), V2 8 8, V2 (-8) 8] +-- +-- When we run @foo@ using 'runGame', a blue square follows the cursor. +-- And 'translate' (V2 240 240) @foo@, 'rotate' 45 @foo@, 'scale' 1.5 @foo@ also does in the same way. -- --- The only way to embody a 'Game' as a real thing is to apply 'runGame'. +-- You have to call 'tick' at the end of the frame. +-- +-- The only way to embody a 'Game' as a real stuff is to apply 'runGame'. +-- +-- for more examples, see <https://github.com/fumieval/free-game/tree/master/examples>. + type Game = F GUI -- | Run a 'Game'. runGame :: GUIParam -> Game a -> IO (Maybe a) runGame = GLFW.runGame - -{- $example - -> import Control.Monad -> import Graphics.UI.FreeGame -> main = runGame def $ forever tick - -shows a window and does nothing. - -for more examples, see <https://github.com/fumieval/free-game/tree/master/examples>. - --}
Graphics/UI/FreeGame/GUI/GLFW.hs view
@@ -267,6 +267,7 @@ mkVertex2 :: V2 Float -> GL.Vertex2 GL.GLfloat mkVertex2 = unsafeCoerce +{-# INLINE mkVertex2 #-} gf :: Float -> GL.GLfloat {-# INLINE gf #-}
Graphics/UI/FreeGame/Text.hs view
@@ -1,5 +1,5 @@ {-# LANGUAGE TypeSynonymInstances, FlexibleInstances, DeriveFunctor #-} -module Graphics.UI.FreeGame.Text (TextF(..), TextT, runTextT, text) where +module Graphics.UI.FreeGame.Text (TextF(..), TextT, runTextT, runTextT_, text) where import Data.String import Graphics.UI.FreeGame.Base @@ -39,6 +39,10 @@ go cont advV = size * (metricsAscent font - metricsDescent font) * 1.1 (V2 x0 y0, cond) = maybe (zero, const True) (\b -> (view _TopLeft b, flip inBoundingBox b)) bbox + +runTextT_ :: (FromFinalizer m, Monad m, Picture2D m) => Maybe (BoundingBox Float) -> Font -> Float -> TextT m () -> m () +runTextT_ = runTextT +{-# INLINE runTextT_ #-} -- | Render a 'String'. text :: (FromFinalizer m, Monad m, Picture2D m) => Font -> Float -> String -> m ()
Graphics/UI/FreeGame/Types.hs view
@@ -13,6 +13,7 @@ module Graphics.UI.FreeGame.Types ( BoundingBox(..), inBoundingBox, + _Corners, _TopLeft, _TopRight, _BottomLeft, @@ -20,6 +21,7 @@ ) where import Linear.V2 +import Control.Applicative -- | 2D bounding box (x0, y0, x1, y1) data BoundingBox a = BoundingBox a a a a deriving (Show, Eq, Ord, Functor, Read) @@ -28,6 +30,11 @@ 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 +-- | @'_Corners' :: Traversal' ('BoundingBox' a) ('V2' a)@ +_Corners :: Applicative f => (V2 a -> f (V2 a)) -> (BoundingBox a -> f (BoundingBox a)) +_Corners f (BoundingBox x0 y0 x1 y1) = go <$> f (V2 x0 y0) <*> f (V2 x1 y0) <*> f (V2 x1 y1) <*> f (V2 x0 y1) where + go (V2 x0' _) (V2 _ y1') (V2 x2' _) (V2 _ y3') = BoundingBox x0' y1' x2' y3' + -- | @'_TopLeft' :: Lens' ('BoundingBox' a) ('V2' a)@ _TopLeft :: Functor f => (V2 a -> f (V2 a)) -> (BoundingBox a -> f (BoundingBox a)) _TopLeft f (BoundingBox x0 y0 x1 y1) = fmap (\(V2 x0' y0') -> BoundingBox x0' y0' x1 y1) (f (V2 x0 y0)) @@ -43,4 +50,3 @@ -- | @'_BottomRight' :: Lens' ('BoundingBox' a) ('V2' a)@ _BottomRight :: Functor f => (V2 a -> f (V2 a)) -> (BoundingBox a -> f (BoundingBox a)) _BottomRight f (BoundingBox x0 y0 x1 y1) = fmap (\(V2 x1' y1') -> BoundingBox x0 y0 x1' y1') (f (V2 x1 y1)) -
free-game.cabal view
@@ -1,5 +1,5 @@ name: free-game -version: 0.9.4 +version: 0.9.4.1 synopsis: Cross-platform GUI library based on free monads description: free-game is a library that abstracts graphical applications with simple interfaces. Twitter: #hs_free_game homepage: https://github.com/fumieval/free-game/tree/maintainance0.9