0 | module Rhone.Canvas.Scene
 1 |
 2 | import Control.Monad.Either.Extra
 3 | import JS
 4 | import Rhone.Canvas.Shape
 5 | import Rhone.Canvas.Style
 6 | import Rhone.Canvas.Transformation
 7 | import Rhone.JS.Reactimate
 8 | import Web.Html
 9 |
10 | %default total
11 |
12 | public export
13 | data Scene : Type where
14 |   S1 : (fs : List Style) -> (tr : Transformation) -> (shape : Shape) -> Scene
15 |   SM : (fs : List Style) -> (tr : Transformation) -> List Scene -> Scene
16 |
17 | --------------------------------------------------------------------------------
18 | --          IO
19 | --------------------------------------------------------------------------------
20 |
21 | mutual
22 |   export
23 |   applyAll : CanvasRenderingContext2D -> List Scene -> JSIO ()
24 |   applyAll ctxt = assert_total $ traverseList_ (apply ctxt)
25 |
26 |   export
27 |   apply : CanvasRenderingContext2D -> Scene -> JSIO ()
28 |   apply ctxt (S1 fs tr shape) = do
29 |     save    ctxt
30 |     traverseList_ (apply ctxt) fs
31 |     apply   ctxt tr
32 |     apply   ctxt shape
33 |     restore ctxt
34 |
35 |   apply ctxt (SM fs tr xs) = do
36 |     save     ctxt
37 |     traverseList_ (apply ctxt) fs
38 |     apply    ctxt tr
39 |     applyAll ctxt xs
40 |     restore  ctxt
41 |