Only in reactive-glut-0.2.0/: dist
diff -ur reactive-glut-0.1.6/reactive-glut.cabal reactive-glut-0.2.0/reactive-glut.cabal
|
old
|
new
|
|
| 1 | 1 | Name: reactive-glut |
| 2 | | Version: 0.1.6 |
| | 2 | Version: 0.2.0 |
| 3 | 3 | Cabal-Version: >= 1.2 |
| 4 | 4 | Synopsis: Connects Reactive and GLUT |
| 5 | 5 | Category: FRP, graphics |
| … |
… |
|
| 26 | 26 | Library |
| 27 | 27 | hs-Source-Dirs: src |
| 28 | 28 | Extensions: |
| 29 | | Build-Depends: base, old-time, OpenGL, GLUT, vector-space, reactive >= 0.10.5 |
| | 29 | Build-Depends: base, containers, old-time, OpenGL, GLUT, vector-space, reactive >= 0.10.5 |
| 30 | 30 | Exposed-Modules: |
| 31 | 31 | FRP.Reactive.GLUT.Adapter |
| 32 | 32 | Other-Modules: |
diff -ur reactive-glut-0.1.6/src/FRP/Reactive/GLUT/Adapter.hs reactive-glut-0.2.0/src/FRP/Reactive/GLUT/Adapter.hs
|
old
|
new
|
|
| 22 | 22 | |
| 23 | 23 | import qualified Graphics.UI.GLUT as G |
| 24 | 24 | |
| 25 | | import FRP.Reactive (Behavior,stepper) |
| | 25 | import FRP.Reactive (Behavior,stepper,flipFlop,accumB) |
| 26 | 26 | import FRP.Reactive.LegacyAdapters |
| 27 | 27 | |
| 28 | 28 | import FRP.Reactive.GLUT.UI |
| 29 | 29 | import FRP.Reactive.GLUT.SimpleGL |
| 30 | 30 | |
| | 31 | import qualified Data.Set as Set |
| | 32 | |
| 31 | 33 | -- | Adapter to connect @FRP.Reactive@ with @GLUT@. Uses given window |
| 32 | 34 | -- title and a simple canned initialization. Or do your own |
| 33 | 35 | -- initialization and then invoke 'adapt'. |
| … |
… |
|
| 42 | 44 | let mkE = makeEvent clock |
| 43 | 45 | (mousePosSink , mousePosE ) <- mkE |
| 44 | 46 | (leftDownSink , leftDown ) <- mkE |
| | 47 | (leftUpSink , leftUp ) <- mkE |
| 45 | 48 | (rightDownSink, rightDown ) <- mkE |
| | 49 | (rightUpSink , rightUp ) <- mkE |
| 46 | 50 | (keyActionSink, keyActions) <- mkE |
| 47 | 51 | (tickSink , tick ) <- mkE |
| | 52 | |
| 48 | 53 | -- TODO: let the initial mouse position be its actual position |
| 49 | 54 | let windowPoint' p = do -- putStrLn $ "window point " ++ show p |
| 50 | 55 | windowPoint p |
| … |
… |
|
| 60 | 65 | G.keyboardMouseCallback G.$= Just (\k ks _ _ -> |
| 61 | 66 | case (k,ks) of |
| 62 | 67 | (G.MouseButton G.LeftButton ,G.Down) -> leftDownSink () |
| | 68 | (G.MouseButton G.LeftButton ,G.Up) -> leftUpSink () |
| 63 | 69 | (G.MouseButton G.RightButton,G.Down) -> rightDownSink () |
| | 70 | (G.MouseButton G.RightButton,G.Up) -> rightUpSink () |
| 64 | 71 | (G.Char c ,G.Down) -> keyActionSink (Down, Char c) |
| 65 | 72 | (G.SpecialKey s,G.Down) -> keyActionSink (Down, SpecialKey s) |
| 66 | 73 | (G.Char c ,G.Up) -> keyActionSink (Up , Char c) |
| 67 | 74 | (G.SpecialKey s,G.Up) -> keyActionSink (Up , SpecialKey s) |
| 68 | 75 | _ -> return () |
| 69 | 76 | ) |
| | 77 | -- Convenient summary behaviors |
| | 78 | let leftButtonB = flipFlop leftDown leftUp |
| | 79 | rightButtonB = flipFlop rightDown rightUp |
| | 80 | keyboardB = accumB Set.empty (uncurry setAction <$> keyActions) |
| | 81 | where |
| | 82 | setAction Down = Set.insert |
| | 83 | setAction Up = Set.delete |
| | 84 | -- |
| 70 | 85 | updater <- mkUpdater |
| 71 | 86 | (cGetTime clock) |
| 72 | | (glwrap <$> f (UI mousePos leftDown rightDown keyActions tick)) |
| | 87 | (glwrap <$> f (UI mousePos leftDown leftUp leftButtonB rightDown rightUp rightButtonB keyActions keyboardB tick)) |
| 73 | 88 | schedule (updater >> tickSink ()) |
| 74 | 89 | -- putStrLn "mainLoop" |
| 75 | 90 | G.mainLoop |
diff -ur reactive-glut-0.1.6/src/FRP/Reactive/GLUT/UI.hs reactive-glut-0.2.0/src/FRP/Reactive/GLUT/UI.hs
|
old
|
new
|
|
| 23 | 23 | |
| 24 | 24 | import Control.Applicative (liftA2) |
| 25 | 25 | import qualified Graphics.UI.GLUT as G |
| | 26 | import Data.Map(Map) |
| | 27 | import Data.Set(Set) |
| 26 | 28 | |
| 27 | 29 | import Data.VectorSpace |
| 28 | 30 | import FRP.Reactive |
| 29 | 31 | |
| 30 | 32 | -- | Simple UI type. |
| 31 | 33 | data UI = UI { |
| 32 | | mousePosition :: Behavior (Double,Double), |
| 33 | | leftButtonPressed :: Event (), |
| 34 | | rightButtonPressed :: Event (), |
| 35 | | keyAction :: Event (KeyState, Key), |
| 36 | | framePass :: Event () |
| | 34 | mousePosition :: Behavior (Double,Double), |
| | 35 | leftButtonPressed :: Event (), |
| | 36 | leftButtonReleased :: Event (), |
| | 37 | leftButton :: Behavior Bool, |
| | 38 | rightButtonPressed :: Event (), |
| | 39 | rightButtonReleased :: Event (), |
| | 40 | rightButton :: Behavior Bool, |
| | 41 | keyAction :: Event (KeyState, Key), |
| | 42 | keyboard :: Behavior (Set Key), |
| | 43 | framePass :: Event () |
| 37 | 44 | } |
| 38 | 45 | |
| 39 | 46 | -- TODO: make button and key interfaces alike |