Copyright | (c) Francesco Gazzetta, 2016 |
---|---|
License | MIT |
Maintainer | francygazz@gmail.com |
Stability | experimental |
Safe Haskell | None |
Language | Haskell98 |
This package lets you interact with the screen Elm-style. This is especially useful for small games or visualizations. You can get something on the screen quickly using the Vars provided below.
Try to run this:
import Graphics.Shine.FRP.Varying import Graphics.Shine import Graphics.Shine.Picture import Graphics.Shine.Image import GHCJS.DOM (webViewGetDomDocument, runWebGUI) resizeImage img (x',y') = Translate (x/2) (y/2) -- Pictures are centered on (0,0), so we need to move it $ Image (Stretched x y) img -- Scale de picture to the given position where x = fromIntegral x' -- mousePosition is Integral y = fromIntegral y' main :: IO () main = runWebGUI $ \ webView -> do ctx <- fixedSizeCanvas webView 1024 768 Just doc <- webViewGetDomDocument webView narwhal <- makeImage "https://wiki.haskell.org/wikiupload/8/85/NarleyYeeaaahh.jpg" let resizedNarwhal = resizeImage narwhal <$> mousePosition playVarying ctx doc 30 resizedNarwhal
- data ShineInput
- playVarying :: (IsEventTarget eventElement, IsDocument eventElement) => CanvasRenderingContext2D -> eventElement -> Float -> Var ShineInput Picture -> IO ()
- playVaryingIO :: (IsEventTarget eventElement, IsDocument eventElement) => CanvasRenderingContext2D -> eventElement -> Float -> VarT IO ShineInput Picture -> IO ()
- timeDeltaNumeric :: Monad m => VarT m ShineInput Float
- timeDeltaEvent :: Monad m => VarT m ShineInput (Event Float)
- time :: Monad m => VarT m ShineInput Float
- isDownButton :: Monad m => MouseBtn -> VarT m ShineInput Bool
- isDownKey :: Monad m => Key -> VarT m ShineInput Bool
- mousePosition :: Monad m => VarT m ShineInput (Int, Int)
- mouseButtonsDown :: Monad m => VarT m ShineInput [MouseBtn]
- keysDown :: Monad m => VarT m ShineInput [Key]
Documentation
data ShineInput Source
Datatype representing all possible inputs coming from shine's main loop
Running the Var
:: (IsEventTarget eventElement, IsDocument eventElement) | |
=> CanvasRenderingContext2D | The context to draw on |
-> eventElement | the element used to catch events |
-> Float | FPS |
-> Var ShineInput Picture | A |
-> IO () |
Feed the input to the Var and draw the result
:: (IsEventTarget eventElement, IsDocument eventElement) | |
=> CanvasRenderingContext2D | The context to draw on |
-> eventElement | the element used to catch events |
-> Float | FPS |
-> VarT IO ShineInput Picture | An effectful |
-> IO () |
Feed the input to the VarT IO and draw the result
Useful Vars
timeDeltaNumeric :: Monad m => VarT m ShineInput Float Source
Time delta. On non-time inputs the value is 0.
timeDeltaEvent :: Monad m => VarT m ShineInput (Event Float) Source
Time delta. On non-time inputs the value is NoEvent.
time :: Monad m => VarT m ShineInput Float Source
Time since beginning.
isDownButton :: Monad m => MouseBtn -> VarT m ShineInput Bool Source
Whether a mouse button is pressed.
mousePosition :: Monad m => VarT m ShineInput (Int, Int) Source
The pointer's position, relative to the canvas. The top-left corner is the origin.
mouseButtonsDown :: Monad m => VarT m ShineInput [MouseBtn] Source
A list of mouse buttons that are currently being pressed.
keysDown :: Monad m => VarT m ShineInput [Key] Source
A list of keys that are currently being pressed.