free-game 0.3.2.0 → 0.3.2.1
raw patch · 6 files changed
+98/−83 lines, 6 filesPVP: major bump suggested
API removals or changes: PVP suggests a major version bump
API changes (from Hackage documentation)
- Graphics.FreeGame.Base: AskInput :: Key -> (Bool -> a) -> GameAction a
- Graphics.FreeGame.Base: loadPicture :: MonadFree GameAction m => Bitmap -> m Picture
- Graphics.FreeGame.Input: data Key
- Graphics.FreeGame.Input: instance Eq Key
- Graphics.FreeGame.Input: instance Ord Key
- Graphics.FreeGame.Input: instance Show Key
+ Graphics.FreeGame.Base: GetButtonState :: Button -> (Bool -> a) -> GameAction a
+ Graphics.FreeGame.Base: getButtonState :: MonadFree GameAction m => Button -> m Bool
+ Graphics.FreeGame.Base: windowOrigin :: GameParam -> Vec2
+ Graphics.FreeGame.Data.Font: RenderedChar :: Bitmap -> Vec2 -> Float -> RenderedChar
+ Graphics.FreeGame.Data.Font: charAdvance :: RenderedChar -> Float
+ Graphics.FreeGame.Data.Font: charBitmap :: RenderedChar -> Bitmap
+ Graphics.FreeGame.Data.Font: charOffset :: RenderedChar -> Vec2
+ Graphics.FreeGame.Data.Font: charToBitmap :: Font -> Float -> Char -> IO RenderedChar
+ Graphics.FreeGame.Data.Font: data RenderedChar
+ Graphics.FreeGame.Input: data Button
+ Graphics.FreeGame.Input: instance Eq Button
+ Graphics.FreeGame.Input: instance Ord Button
+ Graphics.FreeGame.Input: instance Show Button
+ Graphics.FreeGame.Input: type Key = Button
- Graphics.FreeGame.Base: GameParam :: Int -> (Int, Int) -> String -> Bool -> Bool -> Color -> GameParam
+ Graphics.FreeGame.Base: GameParam :: Int -> (Int, Int) -> String -> Bool -> Bool -> Color -> Vec2 -> GameParam
- Graphics.FreeGame.Base: askInput :: MonadFree GameAction m => Key -> m Bool
+ Graphics.FreeGame.Base: askInput :: MonadFree GameAction m => Button -> m Bool
- Graphics.FreeGame.Input: KeyBackspace :: Key
+ Graphics.FreeGame.Input: KeyBackspace :: Button
- Graphics.FreeGame.Input: KeyChar :: Char -> Key
+ Graphics.FreeGame.Input: KeyChar :: Char -> Button
- Graphics.FreeGame.Input: KeyDelete :: Key
+ Graphics.FreeGame.Input: KeyDelete :: Button
- Graphics.FreeGame.Input: KeyDown :: Key
+ Graphics.FreeGame.Input: KeyDown :: Button
- Graphics.FreeGame.Input: KeyEnd :: Key
+ Graphics.FreeGame.Input: KeyEnd :: Button
- Graphics.FreeGame.Input: KeyEnter :: Key
+ Graphics.FreeGame.Input: KeyEnter :: Button
- Graphics.FreeGame.Input: KeyEsc :: Key
+ Graphics.FreeGame.Input: KeyEsc :: Button
- Graphics.FreeGame.Input: KeyF1 :: Key
+ Graphics.FreeGame.Input: KeyF1 :: Button
- Graphics.FreeGame.Input: KeyF10 :: Key
+ Graphics.FreeGame.Input: KeyF10 :: Button
- Graphics.FreeGame.Input: KeyF11 :: Key
+ Graphics.FreeGame.Input: KeyF11 :: Button
- Graphics.FreeGame.Input: KeyF12 :: Key
+ Graphics.FreeGame.Input: KeyF12 :: Button
- Graphics.FreeGame.Input: KeyF2 :: Key
+ Graphics.FreeGame.Input: KeyF2 :: Button
- Graphics.FreeGame.Input: KeyF3 :: Key
+ Graphics.FreeGame.Input: KeyF3 :: Button
- Graphics.FreeGame.Input: KeyF4 :: Key
+ Graphics.FreeGame.Input: KeyF4 :: Button
- Graphics.FreeGame.Input: KeyF5 :: Key
+ Graphics.FreeGame.Input: KeyF5 :: Button
- Graphics.FreeGame.Input: KeyF6 :: Key
+ Graphics.FreeGame.Input: KeyF6 :: Button
- Graphics.FreeGame.Input: KeyF7 :: Key
+ Graphics.FreeGame.Input: KeyF7 :: Button
- Graphics.FreeGame.Input: KeyF8 :: Key
+ Graphics.FreeGame.Input: KeyF8 :: Button
- Graphics.FreeGame.Input: KeyF9 :: Key
+ Graphics.FreeGame.Input: KeyF9 :: Button
- Graphics.FreeGame.Input: KeyHome :: Key
+ Graphics.FreeGame.Input: KeyHome :: Button
- Graphics.FreeGame.Input: KeyInsert :: Key
+ Graphics.FreeGame.Input: KeyInsert :: Button
- Graphics.FreeGame.Input: KeyLeft :: Key
+ Graphics.FreeGame.Input: KeyLeft :: Button
- Graphics.FreeGame.Input: KeyLeftControl :: Key
+ Graphics.FreeGame.Input: KeyLeftControl :: Button
- Graphics.FreeGame.Input: KeyLeftShift :: Key
+ Graphics.FreeGame.Input: KeyLeftShift :: Button
- Graphics.FreeGame.Input: KeyPad0 :: Key
+ Graphics.FreeGame.Input: KeyPad0 :: Button
- Graphics.FreeGame.Input: KeyPad1 :: Key
+ Graphics.FreeGame.Input: KeyPad1 :: Button
- Graphics.FreeGame.Input: KeyPad2 :: Key
+ Graphics.FreeGame.Input: KeyPad2 :: Button
- Graphics.FreeGame.Input: KeyPad3 :: Key
+ Graphics.FreeGame.Input: KeyPad3 :: Button
- Graphics.FreeGame.Input: KeyPad4 :: Key
+ Graphics.FreeGame.Input: KeyPad4 :: Button
- Graphics.FreeGame.Input: KeyPad5 :: Key
+ Graphics.FreeGame.Input: KeyPad5 :: Button
- Graphics.FreeGame.Input: KeyPad6 :: Key
+ Graphics.FreeGame.Input: KeyPad6 :: Button
- Graphics.FreeGame.Input: KeyPad7 :: Key
+ Graphics.FreeGame.Input: KeyPad7 :: Button
- Graphics.FreeGame.Input: KeyPad8 :: Key
+ Graphics.FreeGame.Input: KeyPad8 :: Button
- Graphics.FreeGame.Input: KeyPad9 :: Key
+ Graphics.FreeGame.Input: KeyPad9 :: Button
- Graphics.FreeGame.Input: KeyPadAdd :: Key
+ Graphics.FreeGame.Input: KeyPadAdd :: Button
- Graphics.FreeGame.Input: KeyPadDecimal :: Key
+ Graphics.FreeGame.Input: KeyPadDecimal :: Button
- Graphics.FreeGame.Input: KeyPadDivide :: Key
+ Graphics.FreeGame.Input: KeyPadDivide :: Button
- Graphics.FreeGame.Input: KeyPadEnter :: Key
+ Graphics.FreeGame.Input: KeyPadEnter :: Button
- Graphics.FreeGame.Input: KeyPadEqual :: Key
+ Graphics.FreeGame.Input: KeyPadEqual :: Button
- Graphics.FreeGame.Input: KeyPadMultiply :: Key
+ Graphics.FreeGame.Input: KeyPadMultiply :: Button
- Graphics.FreeGame.Input: KeyPadSubtract :: Key
+ Graphics.FreeGame.Input: KeyPadSubtract :: Button
- Graphics.FreeGame.Input: KeyPageDown :: Key
+ Graphics.FreeGame.Input: KeyPageDown :: Button
- Graphics.FreeGame.Input: KeyPageUp :: Key
+ Graphics.FreeGame.Input: KeyPageUp :: Button
- Graphics.FreeGame.Input: KeyRight :: Key
+ Graphics.FreeGame.Input: KeyRight :: Button
- Graphics.FreeGame.Input: KeyRightControl :: Key
+ Graphics.FreeGame.Input: KeyRightControl :: Button
- Graphics.FreeGame.Input: KeyRightShift :: Key
+ Graphics.FreeGame.Input: KeyRightShift :: Button
- Graphics.FreeGame.Input: KeySpace :: Key
+ Graphics.FreeGame.Input: KeySpace :: Button
- Graphics.FreeGame.Input: KeyTab :: Key
+ Graphics.FreeGame.Input: KeyTab :: Button
- Graphics.FreeGame.Input: KeyUp :: Key
+ Graphics.FreeGame.Input: KeyUp :: Button
- Graphics.FreeGame.Input: MouseLeft :: Key
+ Graphics.FreeGame.Input: MouseLeft :: Button
- Graphics.FreeGame.Input: MouseMiddle :: Key
+ Graphics.FreeGame.Input: MouseMiddle :: Button
- Graphics.FreeGame.Input: MouseRight :: Key
+ Graphics.FreeGame.Input: MouseRight :: Button
- Graphics.FreeGame.Simple: askInput :: MonadFree GameAction m => Key -> m Bool
+ Graphics.FreeGame.Simple: askInput :: MonadFree GameAction m => Button -> m Bool
Files
- Graphics/FreeGame/Backends/GLFW.hs +12/−9
- Graphics/FreeGame/Base.hs +17/−15
- Graphics/FreeGame/Data/Font.hs +2/−0
- Graphics/FreeGame/Input.hs +66/−57
- Graphics/FreeGame/Simple.hs +0/−1
- free-game.cabal +1/−1
Graphics/FreeGame/Backends/GLFW.hs view
@@ -15,7 +15,6 @@ import qualified Graphics.Rendering.OpenGL.GL as GL import Graphics.FreeGame.Base import Graphics.FreeGame.Data.Bitmap -import Graphics.FreeGame.Data.Color import qualified Graphics.FreeGame.Input as I import Control.Applicative import Control.Monad.Free @@ -85,7 +84,7 @@ GL.currentColor $= oldColor return xs -run :: (?windowWidth :: Int, ?windowHeight :: Int +run :: (?windowT :: GL.GLdouble, ?windowB :: GL.GLdouble, ?windowL :: GL.GLdouble, ?windowR :: GL.GLdouble , ?refTextures :: IORef (IM.IntMap Texture) , ?refFrame :: IORef Int , ?frameTime :: Double @@ -117,11 +116,11 @@ GL.preservingMatrix $ do GL.loadIdentity GL.scale (gf 1) (-1) 1 - GL.ortho 0 (fromIntegral ?windowWidth) 0 (fromIntegral ?windowHeight) 0 (-100) + GL.ortho ?windowL ?windowR ?windowT ?windowB 0 (-100) GL.matrixMode $= GL.Modelview 0 run is cont else return Nothing - AskInput key fcont -> either keyIsPressed mouseButtonIsPressed (mapKey key) >>= run is . fcont + GetButtonState key fcont -> either keyIsPressed mouseButtonIsPressed (mapKey key) >>= run is . fcont GetMousePosition fcont -> do (x, y) <- GLFW.getMousePosition run is $ fcont $ Vec2 (fromIntegral x) (fromIntegral y) @@ -138,6 +137,7 @@ (realToFrac g) (realToFrac b) (realToFrac a) + , windowOrigin = Vec2 (realToFrac ?windowL) (realToFrac ?windowT) } QuitGame -> return Nothing run is (Pure x) = do @@ -151,14 +151,17 @@ runGame param game = do True <- initialize pf <- openGLProfile - let ?windowWidth = fst $ windowSize param - ?windowHeight = snd $ windowSize param + let Vec2 ox oy = windowOrigin param + let ?windowL = realToFrac ox + ?windowR = realToFrac ox + fromIntegral (fst $ windowSize param) + ?windowT = realToFrac oy + ?windowB = realToFrac oy + fromIntegral (snd $ windowSize param) ?windowTitle = windowTitle param ?windowMode = windowed param ?cursorVisible = cursorVisible param True <- openWindow $ defaultDisplayOptions { - displayOptions_width = fromIntegral ?windowWidth - ,displayOptions_height = fromIntegral ?windowHeight + displayOptions_width = fromIntegral $ fst $ windowSize param + ,displayOptions_height = fromIntegral $ snd $ windowSize param ,displayOptions_displayMode = if ?windowMode then Window else Fullscreen ,displayOptions_windowIsResizable = False ,displayOptions_openGLProfile = pf @@ -189,7 +192,7 @@ terminate return r -mapKey :: I.Key -> Either Key MouseButton +mapKey :: I.Button -> Either Key MouseButton mapKey k = case k of I.KeyChar c -> Left $ CharKey c I.KeySpace -> Left KeySpace
Graphics/FreeGame/Base.hs view
@@ -31,10 +31,9 @@ ,drawPicture -- * Inputs - ,askInput + ,getButtonState ,getMousePosition ,getMouseWheel - ,getMouseState -- * Settings ,GameParam(..) @@ -42,7 +41,8 @@ ,getCurrentGameParam -- * Deprecated - ,loadPicture + ,askInput + ,getMouseState ) where import Control.Monad.Free @@ -66,7 +66,7 @@ | EmbedIO (IO a) | Bracket (Game a) | DrawPicture Picture a - | AskInput Key (Bool -> a) + | GetButtonState Button (Bool -> a) | GetMousePosition (Vec2 -> a) | GetMouseWheel (Int -> a) | GetGameParam (GameParam -> a) @@ -93,9 +93,9 @@ drawPicture :: MonadFree GameAction m => Picture -> m () drawPicture pic = wrap $ DrawPicture pic (return ()) --- | Is the specified 'Key' is pressed? -askInput :: MonadFree GameAction m => Key -> m Bool -askInput key = wrap $ AskInput key return +-- | Is the specified 'Button' is pressed? +getButtonState :: MonadFree GameAction m => Button -> m Bool +getButtonState key = wrap $ GetButtonState key return getMouseWheel :: MonadFree GameAction m => m Int getMouseWheel = wrap $ GetMouseWheel return @@ -130,20 +130,21 @@ | Colored Color Picture -- | Parameters of the application. -data GameParam = GameParam { - framePerSecond :: Int +data GameParam = GameParam + { framePerSecond :: Int ,windowSize :: (Int, Int) ,windowTitle :: String ,windowed :: Bool ,cursorVisible :: Bool ,clearColor :: Color + ,windowOrigin :: Vec2 } deriving Show -- | 640*480(windowed), 60fps defaultGameParam :: GameParam -defaultGameParam = GameParam 60 (640,480) "free-game" True True white +defaultGameParam = GameParam 60 (640,480) "free-game" True True white (Vec2 0 0) --- | Get the mouse's state. +-- | Deprecated synonym for 'getMouseState'. getMouseState :: MonadFree GameAction m => m MouseState getMouseState = MouseState `liftM` getMousePosition @@ -151,8 +152,9 @@ `ap` askInput MouseMiddle `ap` askInput MouseRight `ap` getMouseWheel +{-# DEPRECATED getMouseState "use getMousePosition and getMouseWheel instead." #-} -{-# DEPRECATED loadPicture "No longer needed; use BitmapPicture instead" #-} --- | Create a 'Picture' from 'Bitmap'. -loadPicture :: MonadFree GameAction m => Bitmap -> m Picture -loadPicture = return . BitmapPicture +-- | Deprecated synonym for 'getButtonState'. +askInput :: MonadFree GameAction m => Button -> m Bool +askInput = getButtonState +{-# DEPRECATED askInput "use getButtonState instead." #-}
Graphics/FreeGame/Data/Font.hs view
@@ -17,6 +17,8 @@ , Metrics(..) , Graphics.FreeGame.Data.Font.metrics , fontBoundingBox + , charToBitmap + , RenderedChar(..) , text , renderCharacters ) where
Graphics/FreeGame/Input.hs view
@@ -9,11 +9,72 @@ -- Portability : non-portable -- ---------------------------------------------------------------------------- -module Graphics.FreeGame.Input where +module Graphics.FreeGame.Input ( + Button(..) + -- * Deprecated + , Key + , MouseState(..) + ) where import Data.Vect --- | The state of the mouse. +-- | Buttons. +data Button + = KeyChar Char + | KeySpace + | KeyEsc + | KeyF1 + | KeyF2 + | KeyF3 + | KeyF4 + | KeyF5 + | KeyF6 + | KeyF7 + | KeyF8 + | KeyF9 + | KeyF10 + | KeyF11 + | KeyF12 + | KeyLeftShift + | KeyRightShift + | KeyLeftControl + | KeyRightControl + | KeyUp + | KeyDown + | KeyLeft + | KeyRight + | KeyTab + | KeyEnter + | KeyBackspace + | KeyInsert + | KeyDelete + | KeyPageUp + | KeyPageDown + | KeyHome + | KeyEnd + | KeyPad0 + | KeyPad1 + | KeyPad2 + | KeyPad3 + | KeyPad4 + | KeyPad5 + | KeyPad6 + | KeyPad7 + | KeyPad8 + | KeyPad9 + | KeyPadDivide + | KeyPadMultiply + | KeyPadSubtract + | KeyPadAdd + | KeyPadDecimal + | KeyPadEqual + | KeyPadEnter + | MouseLeft + | MouseRight + | MouseMiddle + deriving (Show, Eq, Ord) + +{-# DEPRECATED MouseState "no longer needed" #-} data MouseState = MouseState { mousePosition :: Vec2 , leftButton :: Bool @@ -22,58 +83,6 @@ , mouseWheel :: Int } deriving Show --- | Keys. -data Key - = KeyChar Char - | KeySpace - | KeyEsc - | KeyF1 - | KeyF2 - | KeyF3 - | KeyF4 - | KeyF5 - | KeyF6 - | KeyF7 - | KeyF8 - | KeyF9 - | KeyF10 - | KeyF11 - | KeyF12 - | KeyLeftShift - | KeyRightShift - | KeyLeftControl - | KeyRightControl - | KeyUp - | KeyDown - | KeyLeft - | KeyRight - | KeyTab - | KeyEnter - | KeyBackspace - | KeyInsert - | KeyDelete - | KeyPageUp - | KeyPageDown - | KeyHome - | KeyEnd - | KeyPad0 - | KeyPad1 - | KeyPad2 - | KeyPad3 - | KeyPad4 - | KeyPad5 - | KeyPad6 - | KeyPad7 - | KeyPad8 - | KeyPad9 - | KeyPadDivide - | KeyPadMultiply - | KeyPadSubtract - | KeyPadAdd - | KeyPadDecimal - | KeyPadEqual - | KeyPadEnter - | MouseLeft - | MouseRight - | MouseMiddle - deriving (Show, Eq, Ord) +{-# DEPRECATED Key "use Button instead" #-} +-- Deprecated synonym for 'Button'. +type Key = Button
Graphics/FreeGame/Simple.hs view
@@ -52,7 +52,6 @@ import Graphics.FreeGame import Graphics.FreeGame.Data.Color -import Graphics.FreeGame.Data.Font import Graphics.FreeGame.Input import Control.Monad
free-game.cabal view
@@ -1,5 +1,5 @@ name: free-game -version: 0.3.2.0 +version: 0.3.2.1 synopsis: Create graphical applications for free. description: Cross-platform GUI library based on free monads homepage: https://github.com/fumieval/free-game