-
Notifications
You must be signed in to change notification settings - Fork 162
/
package.scala
76 lines (57 loc) · 2.06 KB
/
package.scala
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
package org.scalajs.dom
import scala.language.implicitConversions
package object ext {
implicit class PimpedNodeList(nodes: NodeList)
extends EasySeq[Node](nodes.length, nodes.apply)
implicit class PimpedTouchList(nodes: TouchList)
extends EasySeq[Touch](nodes.length, nodes.apply)
implicit class PimpedHtmlCollection(coll: html.Collection)
extends EasySeq[Element](coll.length, coll.apply)
implicit class PimpedSVGTransformList(coll: svg.TransformList)
extends EasySeq[svg.Transform](coll.numberOfItems, coll.getItem)
implicit class Castable(x: Any) {
def cast[T] = x.asInstanceOf[T]
}
implicit def pimpAnimatedNumber(x: svg.AnimatedNumber) = x.baseVal
implicit def pimpRichAnimatedNumber(x: svg.AnimatedNumber) =
x.baseVal: runtime.RichDouble
implicit def pimpAnimatedLength(x: svg.AnimatedLength) = x.baseVal.value
implicit def pimpRichAnimatedLength(x: svg.AnimatedLength) =
x.baseVal.value: runtime.RichDouble
implicit def color2String(c: Color) = c.toString
implicit class pimpedContext(val ctx: CanvasRenderingContext2D) {
def prepCircle(x: Double, y: Double, r: Double) = {
ctx.beginPath()
ctx.arc(x, y, r, 0, math.Pi * 2)
}
def fillCircle(x: Double, y: Double, r: Double) = {
prepCircle(x, y, r)
ctx.fill()
}
def strokeCircle(x: Double, y: Double, r: Double) = {
prepCircle(x, y, r)
ctx.stroke()
}
def prepPath(points: Seq[(Double, Double)], closed: Boolean = true) = {
ctx.beginPath()
if (closed) ctx.moveTo(points.last._1, points.last._2)
for (p <- points) {
ctx.lineTo(p._1, p._2)
}
}
def fillPath(points: (Double, Double)*) = {
prepPath(points)
ctx.fill()
}
def strokePath(points: (Double, Double)*) = {
prepPath(points)
ctx.stroke()
}
def strokePathOpen(points: (Double, Double)*) = {
prepPath(points, closed = false)
ctx.stroke()
}
}
implicit def pimpNamedNodeMap(namedNodeMap: NamedNodeMap): NamedNodeMapMap =
new NamedNodeMapMap(namedNodeMap)
}