free-game 0.9.3 → 0.9.3.1
raw patch · 10 files changed
+57/−11 lines, 10 files
Files
- Graphics/UI/FreeGame.hs +6/−2
- Graphics/UI/FreeGame/Base.hs +1/−1
- Graphics/UI/FreeGame/Data/Bitmap.hs +1/−1
- Graphics/UI/FreeGame/Data/Color.hs +43/−1
- Graphics/UI/FreeGame/Data/Font.hs +1/−1
- Graphics/UI/FreeGame/GUI.hs +1/−1
- Graphics/UI/FreeGame/GUI/GLFW.hs +1/−1
- Graphics/UI/FreeGame/Types.hs +1/−1
- Graphics/UI/FreeGame/Util.hs +1/−1
- free-game.cabal +1/−1
Graphics/UI/FreeGame.hs view
@@ -2,7 +2,7 @@ Module : Graphics.UI.FreeGame Copyright : (C) 2013 Fumiaki Kinoshita License : BSD-style (see the file LICENSE) -Maintainer : Fumiaki Kinsohita <fumiexcel@gmail.com> +Maintainer : Fumiaki Kinoshita <fumiexcel@gmail.com> free-game is a library that abstracts and purifies GUI applications with simple interfaces. -} @@ -22,7 +22,9 @@ module Graphics.UI.FreeGame.Util, module Graphics.UI.FreeGame.Text, module Graphics.UI.FreeGame.Types, - module Linear + module Linear, + module Control.Monad, + module Control.Applicative ) where import Graphics.UI.FreeGame.Base @@ -36,6 +38,8 @@ import qualified Graphics.UI.FreeGame.GUI.GLFW as GLFW import Control.Monad.Free.Church import Data.Default +import Control.Monad +import Control.Applicative import Linear hiding (rotate) -- | 'Game' is a "free" monad which describes GUIs.
Graphics/UI/FreeGame/Base.hs view
@@ -8,7 +8,7 @@ -- Copyright : (C) 2012-2013 Fumiaki Kinoshita -- License : BSD-style (see the file LICENSE) ----- Maintainer : Fumiaki Kinsohita <fumiexcel@gmail.com>+-- Maintainer : Fumiaki Kinoshita <fumiexcel@gmail.com> -- Stability : experimental -- Portability : non-portable --
Graphics/UI/FreeGame/Data/Bitmap.hs view
@@ -4,7 +4,7 @@ -- Copyright : (C) 2013 Fumiaki Kinoshita -- License : BSD-style (see the file LICENSE) -- --- Maintainer : Fumiaki Kinsohita <fumiexcel@gmail.com> +-- Maintainer : Fumiaki Kinoshita <fumiexcel@gmail.com> -- Stability : experimental -- Portability : non-portable --
Graphics/UI/FreeGame/Data/Color.hs view
@@ -5,7 +5,7 @@ -- Copyright : (C) 2013 Fumiaki Kinoshita -- License : BSD-style (see the file LICENSE) -- --- Maintainer : Fumiaki Kinsohita <fumiexcel@gmail.com> +-- Maintainer : Fumiaki Kinoshita <fumiexcel@gmail.com> -- Stability : provisional -- Portability : non-portable -- @@ -18,6 +18,7 @@ , blend -- * Lenses , _Red, _Green, _Blue, _Alpha, _8Bit + , _Hue, _Saturation, _Brightness -- * Basic colors , white, black, red, green, blue, yellow, cyan, magenta ) where @@ -49,6 +50,47 @@ -- | @'_Alpha' :: Lens' 'Color' 'Float'@ _Alpha :: Functor f => (Float -> f Float) -> Color -> f Color _Alpha f (Color r g b a) = fmap (\a' -> Color r g b a') (f a) + +argb :: Float -> Float -> Float -> Float -> Color +argb a r g b = Color r g b a + +-- | @'_Hue' :: Lens' 'Color' 'Float'@ +_Hue :: Functor f => (Float -> f Float) -> Color -> f Color +_Hue f (Color r g b a) = rgb_hsv r g b $ \h s v -> fmap (\h' -> hsv_rgb h' s v (argb a)) (f h) + +-- | @'_Saturation' :: Lens' 'Color' 'Float'@ +_Saturation :: Functor f => (Float -> f Float) -> Color -> f Color +_Saturation f (Color r g b a) = rgb_hsv r g b $ \h s v -> fmap (\s' -> hsv_rgb h s' v (argb a)) (f s) + +-- | @'_Brightness' :: Lens' 'Color' 'Float'@ +_Brightness :: Functor f => (Float -> f Float) -> Color -> f Color +_Brightness f (Color r g b a) = rgb_hsv r g b $ \h s v -> fmap (\v' -> hsv_rgb h s v' (argb a)) (f v) + +rgb_hsv :: Float -> Float -> Float -> (Float -> Float -> Float -> a) -> a +rgb_hsv r g b f = f h (s / maxC) maxC where + maxC = r `max` g `max` b + minC = r `min` g `min` b + s = maxC - minC + h | maxC == r = (g - b) / s * 60 + | maxC == g = (b - r) / s * 60 + 120 + | maxC == b = (r - g) / s * 60 + 240 + | otherwise = undefined + +hsv_rgb :: Float -> Float -> Float -> (Float -> Float -> Float -> a) -> a +hsv_rgb h s v r + | h' == 0 = r v t p + | h' == 1 = r q v p + | h' == 2 = r p v t + | h' == 3 = r p q v + | h' == 4 = r t p v + | h' == 5 = r v p q + | otherwise = undefined + where + h' = floor (h / 60) `mod` 6 :: Int + f = h / 60 - fromIntegral h' + p = v * (1 - s) + q = v * (1 - f * s) + t = v * (1 - (1 - f) * s) hf :: Char -> Float hf x = fromIntegral (digitToInt x) / 15
Graphics/UI/FreeGame/Data/Font.hs view
@@ -4,7 +4,7 @@ -- Copyright : (C) 2013 Fumiaki Kinoshita -- License : BSD-style (see the file LICENSE) -- --- Maintainer : Fumiaki Kinsohita <fumiexcel@gmail.com> +-- Maintainer : Fumiaki Kinoshita <fumiexcel@gmail.com> -- Stability : provisional -- Portability : non-portable --
Graphics/UI/FreeGame/GUI.hs view
@@ -5,7 +5,7 @@ -- Copyright : (C) 2013 Fumiaki Kinoshita -- License : BSD-style (see the file LICENSE) -- --- Maintainer : Fumiaki Kinsohita <fumiexcel@gmail.com> +-- Maintainer : Fumiaki Kinoshita <fumiexcel@gmail.com> -- Stability : provisional -- Portability : non-portable -- Provides the "free" embodiment.
Graphics/UI/FreeGame/GUI/GLFW.hs view
@@ -5,7 +5,7 @@ -- Copyright : (C) 2013 Fumiaki Kinoshita -- License : BSD-style (see the file LICENSE) -- --- Maintainer : Fumiaki Kinsohita <fumiexcel@gmail.com> +-- Maintainer : Fumiaki Kinoshita <fumiexcel@gmail.com> -- Stability : experimental -- Portability : non-portable --
Graphics/UI/FreeGame/Types.hs view
@@ -5,7 +5,7 @@ -- Copyright : (C) 2013 Fumiaki Kinoshita -- License : BSD-style (see the file LICENSE) -- --- Maintainer : Fumiaki Kinsohita <fumiexcel@gmail.com> +-- Maintainer : Fumiaki Kinoshita <fumiexcel@gmail.com> -- Stability : provisional -- Portability : non-portable --
Graphics/UI/FreeGame/Util.hs view
@@ -5,7 +5,7 @@ -- Copyright : (C) 2013 Fumiaki Kinoshita -- License : BSD-style (see the file LICENSE) -- --- Maintainer : Fumiaki Kinsohita <fumiexcel@gmail.com> +-- Maintainer : Fumiaki Kinoshita <fumiexcel@gmail.com> -- Stability : experimental -- Portability : non-portable --
free-game.cabal view
@@ -1,5 +1,5 @@ name: free-game -version: 0.9.3 +version: 0.9.3.1 synopsis: Create graphical applications for free description: Cross-platform GUI library based on free monads homepage: https://github.com/fumieval/free-game