0 | module Web.Canvas.Shape
  1 |
  2 | import Data.Linear.Token
  3 | import Web.Canvas.Angle
  4 | import Web.Canvas.Hints
  5 | import Web.Internal.HtmlPrim
  6 |
  7 | %default total
  8 |
  9 | parameters {auto cr : CanvasRect}
 10 |   export %inline
 11 |   clearRect : (x,y,width,height : Double) -> IO1 ()
 12 |   clearRect x y width height = ffi $ prim__clearRect cr x y width height
 13 |
 14 |   export %inline
 15 |   fillRect : (x,y,width,height : Double) -> IO1 ()
 16 |   fillRect x y width height = ffi $ prim__fillRect cr x y width height
 17 |
 18 |   export %inline
 19 |   strokeRect : (x,y,width,height : Double) -> IO1 ()
 20 |   strokeRect x y width height = ffi $ prim__strokeRect cr x y width height
 21 |
 22 | parameters {auto cp : CanvasPath}
 23 |
 24 |   export %inline
 25 |   arc :
 26 |        (x,y                            : Double)
 27 |     -> (radius                         : Double)
 28 |     -> (startAngle, endAngle           : Angle)
 29 |     -> {default false counterclockwise : Boolean}
 30 |     -> IO1 ()
 31 |   arc x y r sa ea =
 32 |     ffi $ prim__arc cp x y r sa.radians ea.radians (def counterclockwise)
 33 |
 34 |   export %inline
 35 |   arcTo : (x1,y1,x2,y2,radius : Double) -> IO1 ()
 36 |   arcTo x1 y1 x2 y2 r = ffi $ prim__arcTo cp x1 y1 x2 y2 r
 37 |
 38 |   export
 39 |   circle : (x,y,radius : Double) -> IO1 ()
 40 |   circle x y r = arc x y r (rad 0) (rad $ 2 * pi)
 41 |
 42 |   export %inline
 43 |   bezierCurveTo : (cp1x, cp1y, cp2x, cp2y, x, y : Double) -> IO1 ()
 44 |   bezierCurveTo cp1x cp1y cp2x cp2y x y =
 45 |     ffi $ prim__bezierCurveTo cp cp1x cp1y cp2x cp2y x y
 46 |
 47 |   export %inline
 48 |   closePath : IO1 ()
 49 |   closePath = ffi $ prim__closePath cp
 50 |
 51 |   export %inline
 52 |   ellipse :
 53 |        (x,y                  : Double)
 54 |     -> (radiusX, radiusY     : Double)
 55 |     -> (rotation             : Angle)
 56 |     -> (startAngle, endAngle : Angle)
 57 |     -> {default false counterclockwise : Boolean}
 58 |     -> IO1 ()
 59 |   ellipse x y rx ry rot sa ea =
 60 |     ffi $ prim__ellipse cp x y rx ry
 61 |       rot.radians sa.radians ea.radians
 62 |       (def counterclockwise)
 63 |
 64 |   export %inline
 65 |   lineTo : (x,y : Double) -> IO1 ()
 66 |   lineTo x y = ffi $ prim__lineTo cp x y
 67 |
 68 |   export %inline
 69 |   moveTo : (x,y : Double) -> IO1 ()
 70 |   moveTo x y = ffi $ prim__moveTo cp x y
 71 |
 72 |   export %inline
 73 |   rect : (x,y,width,height : Double) -> IO1 ()
 74 |   rect x y width height = ffi $ prim__rect cp x y width height
 75 |
 76 |   export %inline
 77 |   quadraticCurveTo : (cpx, cpy, x, y : Double) -> IO1 ()
 78 |   quadraticCurveTo cpx cpy x y =
 79 |     ffi $ prim__quadraticCurveTo cp cpx cpy x y
 80 |
 81 | parameters {auto cp : CanvasDrawPath}
 82 |
 83 |   export %inline
 84 |   beginPath : IO1 ()
 85 |   beginPath = ffi $ prim__beginPath cp
 86 |
 87 |   export %inline
 88 |   clip : IO1 ()
 89 |   clip = ffi $ prim__clip cp undef
 90 |
 91 |   export %inline
 92 |   fill : IO1 ()
 93 |   fill = ffi $ prim__fill cp undef
 94 |
 95 |   export %inline
 96 |   stroke : IO1 ()
 97 |   stroke = ffi $ prim__stroke cp
 98 |
 99 | parameters {auto cs : CanvasText}
100 |
101 |   export %inline
102 |   fillText :
103 |        (txt : String)
104 |     -> (x,y : Double)
105 |     -> {default undef maxWidth : UndefOr Double}
106 |     -> IO1 ()
107 |   fillText txt x y = ffi $ prim__fillText cs txt x y maxWidth
108 |
109 |   export %inline
110 |   strokeText :
111 |        (txt : String)
112 |     -> (x,y : Double)
113 |     -> {default undef maxWidth : UndefOr Double}
114 |     -> IO1 ()
115 |   strokeText txt x y = ffi $ prim__strokeText cs txt x y maxWidth
116 |