packages feed

reflex-gloss (empty) → 0.1

raw patch · 4 files changed

+119/−0 lines, 4 filesdep +basedep +dependent-sumdep +glosssetup-changed

Dependencies added: base, dependent-sum, gloss, reflex, transformers

Files

+ LICENSE view
@@ -0,0 +1,30 @@+Copyright (c) 2015, Jeffrey Rosenbluth++All rights reserved.++Redistribution and use in source and binary forms, with or without+modification, are permitted provided that the following conditions are met:++    * Redistributions of source code must retain the above copyright+      notice, this list of conditions and the following disclaimer.++    * Redistributions in binary form must reproduce the above+      copyright notice, this list of conditions and the following+      disclaimer in the documentation and/or other materials provided+      with the distribution.++    * Neither the name of Jeffrey Rosenbluth nor the names of other+      contributors may be used to endorse or promote products derived+      from this software without specific prior written permission.++THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS+"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT+LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR+A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT+OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,+SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT+LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,+DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY+THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT+(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE+OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ Setup.hs view
@@ -0,0 +1,2 @@+import Distribution.Simple+main = defaultMain
+ reflex-gloss.cabal view
@@ -0,0 +1,31 @@+name:                reflex-gloss+version:             0.1+synopsis:            An reflex interface for gloss.+description:         This package exports a simple wrapper, in terms of+                     Graphics.Gloss.Interface.IO.Game, that allows full+                     control of the picture generated by Gloss as a+                     Behavior, as well as providing access to+                     Gloss' clock and input-handling functionality as+                     Events.++homepage:            https://github.com/reflex-frp/reflex-gloss+bug-reports:         https://github.com/reflex-frp/reflex-gloss/issues+license:             BSD3+license-file:        LICENSE++author:              Jeffrey Rosenbluth+maintainer:          jeffrey.rosenbluth@gmail.com+copyright:           2015 Jeffrey Rosenbluth+category:            Graphics+build-type:          Simple+cabal-version:       >=1.10++library+  exposed-modules:     Reflex.Gloss+  build-depends:       base >=4.6 && <4.9,+                       gloss >= 1.9.2.1 && < 1.10,+                       reflex >=0.2 && <0.4,+                       dependent-sum >= 0.2.1 && < 0.3,+                       transformers >= 0.4.2 && < 0.5+  hs-source-dirs:      src+  default-language:    Haskell2010
+ src/Reflex/Gloss.hs view
@@ -0,0 +1,56 @@+{-# LANGUAGE FlexibleContexts #-}+{-# LANGUAGE RankNTypes       #-}+++module Reflex.Gloss+  ( playReflex+  , InputEvent )+  where++import           Control.Monad.Fix      (MonadFix)+import           Control.Monad.IO.Class (liftIO)+import           Data.Dependent.Sum (DSum ((:=>)))+import           Data.IORef             (readIORef)+++import           Graphics.Gloss                   (Color, Display, Picture)+import           Graphics.Gloss.Interface.IO.Game (playIO)+import qualified Graphics.Gloss.Interface.IO.Game as G++import           Reflex+import           Reflex.Host.Class (newEventWithTriggerRef, runHostFrame, fireEvents)++type InputEvent = G.Event++type GlossApp t m = (Reflex t, MonadHold t m, MonadFix m)+                  => Event t Float+                  -> Event t InputEvent+                  -> m (Behavior t Picture)++playReflex+  :: Display+  -> Color+  -> Int+  -> (forall t m. GlossApp t m)+  -> IO ()+playReflex display color frequency network =+  runSpiderHost $ do+    (tickEvent,  tickTriggerRef)  <- newEventWithTriggerRef+    (inputEvent, inputTriggerRef) <- newEventWithTriggerRef++    picture <- runHostFrame $ network tickEvent inputEvent++    liftIO $ playIO display+           color+           frequency+           ()+           (\_    -> runSpiderHost $ runHostFrame (sample picture))+           (\ge _ -> runSpiderHost $ handleTrigger ge inputTriggerRef)+           (\fl _ -> runSpiderHost $ handleTrigger fl tickTriggerRef)++  where+    handleTrigger e trigger = do+      mETrigger <- liftIO $ readIORef trigger+      case mETrigger of+        Nothing       -> return ()+        Just eTrigger -> fireEvents [eTrigger :=> e]