├── .gitignore ├── README.md ├── build.sbt ├── project ├── build.properties └── plugins.sbt └── src └── main └── scala └── paperjs ├── Basic ├── Matrix.scala ├── Point.scala ├── Rectangle.scala ├── Size.scala └── package.scala ├── Items ├── Group.scala ├── Item.scala ├── Layer.scala ├── PlacedSymbol.scala ├── Raster.scala └── Shape.scala ├── Paths ├── CompoundPath.scala ├── Curve.scala ├── Path.scala ├── PathItem.scala ├── Segment.scala └── package.scala ├── Projects ├── Project.scala ├── Symbol.scala ├── View.scala └── package.scala ├── Styling ├── Color.scala └── Style.scala ├── Tools ├── Key.scala ├── Tool.scala └── ToolEvent.scala ├── Typography ├── PointText.scala └── TextItem.scala └── package.scala /.gitignore: -------------------------------------------------------------------------------- 1 | # paper-scala-js 2 | /.idea/ 3 | /target/ 4 | /project/project 5 | /project/target -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Paper-Scala-js 2 | ## A Scala.js binding for Paper.js 3 | 4 | [Paper.js](http://paperjs.org/) is best described in their own words. So this description is an extract from their website. Paper.js — The Swiss Army Knife of Vector Graphics Scripting. It is an open source vector graphics scripting framework that runs on top of the HTML5 Canvas. It offers a clean Scene Graph / Document Object Model and a lot of powerful functionality to create and work with vector graphics and bezier curves, all neatly wrapped up in a well designed, consistent and clean programming interface. 5 | 6 | To find out more about [Paper.js](http://paperjs.org/) please visit their webite. Paper-Scala-js aim to make available all of Paper.js functionality from within a Scala.js application, and therefore in Scala, to its users. Undoubtedly we will fall short at times, primarily because in the JavaScript everything is possible, and if you spot where we haven’t yet deliver on our promises let us know and open an issue. 7 | 8 | ## Installing Paper-Scala-js 9 | 10 | Paper-scala-js is published as a SNAPSHOT with Sonatype snapshots repository so add the following lines to build.sbt to add it to your project. Note that you don't need to add the Scala.js dom dependency, Paper-Scala-js will do that for you. 11 | 12 | ``` 13 | enablePlugins(ScalaJSPlugin) 14 | 15 | resolvers += "Sonatype snapshots" at "https://oss.sonatype.org/content/repositories/snapshots/" 16 | 17 | libraryDependencies ++= Seq( 18 | "com.github.yoeluk" %%% "paper-scala-js" % "0.5-SNAPSHOT", 19 | "com.lihaoyi" %%% "scalarx" % "0.2.8" 20 | ) 21 | 22 | persistLauncher in Compile := false 23 | 24 | persistLauncher in Test := false 25 | 26 | skip in packageJSDependencies := false 27 | ``` 28 | 29 | Add the following line to the plugins.sbt file under the Project/ directory to get the Scala.js plugin. 30 | 31 | ``` 32 | addSbtPlugin("org.scala-js" % "sbt-scalajs" % "0.6.5") 33 | ``` 34 | 35 | Please note that Paper.js requieres setup and you can do that from withing Paper-Scala-js. See an example of an entry method below. 36 | 37 | ## Sketcher App 38 | 39 | The example entry method below ilustrates what it feels like drawing and adding mouse events with Paper-Scala-js. 40 | 41 | ```scala 42 | package sketcher 43 | 44 | import org.scalajs.dom.html 45 | import paperjs.Projects.{View, FrameEvent} 46 | import scala.scalajs.js 47 | import scala.scalajs.js.annotation.JSExport 48 | import paperjs._ 49 | import rx._ 50 | import Basic._,Paths._,Styling._,Tools._ 51 | 52 | @JSExport 53 | object Sketcher { 54 | @JSExport 55 | def main(canvas: html.Canvas): Unit = { 56 | 57 | Paper.setup(canvas) 58 | val tool = Tool() 59 | 60 | val width, height = Var(0.0) 61 | val center = Paper.view.center 62 | val points = 10 63 | val smooth = Var(true) 64 | val path = Path() 65 | 66 | val mousePos = Var(Paper.view.center / 2) 67 | val heightBuff = Var(center.y) 68 | val pathHeight = Rx { 69 | heightBuff() + (center.y - mousePos().y - heightBuff()) / 10 70 | } 71 | val eventCount = Var(0) 72 | 73 | path.fillColor = Color("black") 74 | 75 | initializePath() 76 | 77 | def initializePath() = { 78 | width() = Paper.view.size.width 79 | height() = Paper.view.size.height / 2 80 | path.segments = js.Array[Segment]() 81 | path.add(Paper.view.bounds.bottomLeft) 82 | for (i <- 1 to points - 1) { 83 | val point = Point(width() / points * i, center.y) 84 | path.add(point) 85 | } 86 | path.add(Paper.view.bounds.bottomRight) 87 | path.fullySelected = true 88 | } 89 | 90 | Obs(eventCount) { 91 | val pH = pathHeight() 92 | heightBuff() = pH 93 | for (i <- 1 to points - 1) { 94 | val sinSeed = eventCount() + i * 200 95 | val sinHeight = js.Math.sin(sinSeed / 200) * pathHeight() 96 | val yPos = js.Math.sin(sinSeed / 100) * sinHeight + height() 97 | path.segments(i).point.y = yPos 98 | } 99 | if (smooth()) path.smooth() 100 | } 101 | 102 | Obs(smooth) { 103 | if (!smooth()) { 104 | for (i <- 0 to path.segments.length - 1) { 105 | val segment = path.segments(i) 106 | segment.handleIn = Point.nullPoint 107 | segment.handleOut = Point.nullPoint 108 | } 109 | } 110 | } 111 | 112 | Paper.view.onFrame = (view: View, event: FrameEvent) => { 113 | println(event) 114 | eventCount() = event.count 115 | } 116 | 117 | tool.onMouseMove = (event: ToolEvent) => { 118 | mousePos() = event.point 119 | } 120 | 121 | tool.onMouseDown = (event: ToolEvent) => { 122 | val sm = smooth() 123 | smooth() = !sm 124 | } 125 | 126 | Paper.view.onResize = (view: View, event: FrameEvent) => { 127 | initializePath() 128 | } 129 | } 130 | } 131 | ``` 132 | 133 | This example is part of a provisional demo project that you can find [here](https://github.com/yoeluk/sketch-app). 134 | 135 | License 136 | === 137 | The code is available under [Apache 2](http://www.apache.org/licenses/LICENSE-2.0.txt) license. Feel free to contribute to it or to fork it. 138 | -------------------------------------------------------------------------------- /build.sbt: -------------------------------------------------------------------------------- 1 | sonatypeSettings 2 | name := "paper-scala-js" 3 | version := "0.5-SNAPSHOT" 4 | scalaVersion := "2.11.7" 5 | organization := "com.github.yoeluk" 6 | 7 | enablePlugins(ScalaJSPlugin) 8 | 9 | scalacOptions ++= Seq( 10 | "-feature", 11 | "-deprecation", 12 | "-encoding", "UTF-8", 13 | "-language:implicitConversions", 14 | "-language:reflectiveCalls" 15 | ) 16 | libraryDependencies += "org.scala-js" %%% "scalajs-dom" % "0.8.1" 17 | jsDependencies += "org.webjars" % "paperjs" % "0.9.22" / "paper-full.min.js" commonJSName "paper" 18 | 19 | publishMavenStyle := true 20 | publishArtifact in Test := false 21 | pomIncludeRepository := { _ => false } 22 | 23 | publishTo <<= version { v: String => 24 | val nexus = "https://oss.sonatype.org/" 25 | if (v.trim.endsWith("SNAPSHOT")) 26 | Some("snapshots" at nexus + "content/repositories/snapshots") 27 | else 28 | Some("releases" at nexus + "service/local/staging/deploy/maven2") 29 | } 30 | 31 | pomExtra := { 32 | https://github.com/yoeluk/paper-scala-js 33 | 34 | 35 | Apache 2 36 | http://www.apache.org/licenses/LICENSE-2.0.txt 37 | 38 | 39 | 40 | https://github.com/yoeluk/paper-scala-js.git 41 | scm:git:git@github.com:yoeluk/paper-scala-js.git 42 | github.com/yoeluk/paper-scala-js 43 | 44 | 45 | 46 | yoeluk 47 | Yoel RGD 48 | https://github.com/yoeluk/ 49 | 50 | 51 | } -------------------------------------------------------------------------------- /project/build.properties: -------------------------------------------------------------------------------- 1 | sbt.version = 0.13.8 -------------------------------------------------------------------------------- /project/plugins.sbt: -------------------------------------------------------------------------------- 1 | logLevel := Level.Warn 2 | resolvers += Classpaths.typesafeReleases 3 | addSbtPlugin("org.scala-js" % "sbt-scalajs" % "0.6.5") 4 | addSbtPlugin("org.xerial.sbt" % "sbt-sonatype" % "0.2.2") 5 | addSbtPlugin("com.jsuereth" % "sbt-pgp" % "1.0.0") -------------------------------------------------------------------------------- /src/main/scala/paperjs/Basic/Matrix.scala: -------------------------------------------------------------------------------- 1 | package paperjs 2 | package Basic 3 | 4 | import scala.scalajs.js 5 | import scala.scalajs.js.annotation.JSName 6 | 7 | /** 8 | * Created by yoelusa on 25/04/15. 9 | */ 10 | 11 | @js.native 12 | trait MatrixProps extends js.Object { 13 | var a: Double = js.native 14 | var b: Double = js.native 15 | var c: Double = js.native 16 | var d: Double = js.native 17 | var tx: Double = js.native 18 | var ty: Double = js.native 19 | def values: js.Array[Double] = js.native 20 | def translation: Point = js.native 21 | def scaling: Point = js.native 22 | def rotation: Double = js.native 23 | } 24 | 25 | @js.native 26 | @JSName("paper.Matrix") 27 | class Matrix(a: Double, b: Double, c: Double, d: Double, 28 | tx: Double, ty: Double) extends MatrixProps { 29 | def set(a1: Double, b1: Double, c1: Double, d1: Double, 30 | tx1: Double, ty1: Double): Matrix = js.native 31 | def equals(matrix: Matrix): Boolean = js.native 32 | @JSName("equals") 33 | def ==(matrix: Matrix): Boolean = js.native 34 | override def toString: String = js.native 35 | def reset(): Unit = js.native 36 | def apply(recursively: Boolean): Boolean = js.native 37 | def translate(point: Point): Matrix = js.native 38 | def translate(dx: Double, dy: Double): Matrix = js.native 39 | //def scale(scale: Double, center: Point = Point(0,0)): Matrix = js.native 40 | def scale(hor: Double, ver: Double, center: Point = Point(0,0)): Matrix = 41 | js.native 42 | def rotate(angle: Double, center: Point): Matrix = js.native 43 | def rotate(angle: Double, x: Double, y: Double): Matrix = js.native 44 | def shear(hor: Double, ver: Double, center: Point = Point(0,0)): Matrix = 45 | js.native 46 | def skew(hor: Double, ver: Double, center: Point = Point(0,0)): Matrix = 47 | js.native 48 | def concatenate(mx: Matrix): Matrix = js.native 49 | def preConcatenate(mx: Matrix): Matrix = js.native 50 | def chain(mx: Matrix): Matrix = js.native 51 | def isIdentity: Boolean = js.native 52 | def isInvertible: Boolean = js.native 53 | def isSingular: Boolean = js.native 54 | def transform(point: Point): Point = js.native 55 | def transform(src: Double, dst: Double, count: Double): Double = js.native 56 | def inverseTransform(point: Point): Point = js.native 57 | //def decompose(): Dynamic = js.native 58 | def inverted(): Matrix = js.native 59 | //def applyToContext(ctx: dom.CanvasRenderingContext2D) 60 | } 61 | -------------------------------------------------------------------------------- /src/main/scala/paperjs/Basic/Point.scala: -------------------------------------------------------------------------------- 1 | package paperjs 2 | package Basic 3 | 4 | import scala.scalajs.js 5 | import scala.scalajs.js.annotation.JSName 6 | 7 | /** 8 | * Created by yoelusa on 23/04/15. 9 | */ 10 | 11 | @js.native 12 | trait PointProps extends js.Object { 13 | var angleInRadians: Double = js.native 14 | def quadrant: Double = js.native 15 | var selected: Boolean = js.native 16 | var x: Double = js.native 17 | var y: Double = js.native 18 | } 19 | 20 | @js.native 21 | trait Vect extends PointProps { 22 | var angle: Double = js.native 23 | var length: Double = js.native 24 | } 25 | 26 | object Vect { 27 | def apply(angle: Double, length: Double): Vect = 28 | js.Dynamic.literal( 29 | angle = angle, 30 | length = length 31 | ).asInstanceOf[Vect] 32 | } 33 | 34 | @js.native 35 | @JSName("paper.Point") 36 | class Point(x: Double, y: Double) extends PointProps with Vect { 37 | def this(x: Double) = this(0,0) 38 | def this(props: PointProps) = this(0,0) 39 | def add(d: Double): Point = js.native 40 | def add(p: Point): Point = js.native 41 | def subtract(d: Double): Point = js.native 42 | def subtract(p: Point): Point = js.native 43 | def multiply(d: Double): Point = js.native 44 | def multiply(p: Point): Point = js.native 45 | def divide(d: Double): Point = js.native 46 | def divide(p: Point): Point = js.native 47 | def modulo(i: Int): Point = js.native 48 | def modulo(p: Point): Point = js.native 49 | override def toString(): String = js.native 50 | def equals(point: Point): Boolean = js.native 51 | @JSName("equals") 52 | def ==(point: Point): Boolean = js.native 53 | def getAngle(point: Point): Double = js.native 54 | def getAngleInRadians(point: Point): Double = js.native 55 | def getDistance(point: Point, squared: Boolean = false): Double = js.native 56 | def normalize(length: Double = 1.0): Point = js.native 57 | def rotate(angle: Double, center: Point = this): Point = js.native 58 | def transform(matrix: Matrix): Point = js.native 59 | def isInside(rect: Rect): Boolean = js.native 60 | def isClose(point: Point, tolerance: Double): Boolean = js.native 61 | def isColinear(point: Point): Boolean = js.native 62 | def isOrthogonal(point: Point): Boolean = js.native 63 | def isZero: Boolean = js.native 64 | def isNaN: Boolean = js.native 65 | def dot(point: Point): Double = js.native 66 | def cross(point: Point): Double = js.native 67 | def project(point: Point): Point = js.native 68 | def round(): Point = js.native 69 | def ceil(): Point = js.native 70 | def floor(): Point = js.native 71 | def abs(): Point = js.native 72 | } 73 | 74 | @js.native 75 | @JSName("paper.Point") 76 | object Point extends js.Object { 77 | def min(point1: Point, point2: Point): Point = js.native 78 | def max(point1: Point, point2: Point): Point = js.native 79 | def random(): Point = js.native 80 | def nullPoint: Point = js.native 81 | } -------------------------------------------------------------------------------- /src/main/scala/paperjs/Basic/Rectangle.scala: -------------------------------------------------------------------------------- 1 | package paperjs 2 | package Basic 3 | 4 | import scala.scalajs.js 5 | import scala.scalajs.js.annotation.JSName 6 | 7 | /** 8 | * Created by yoelusa on 24/04/15. 9 | */ 10 | 11 | @js.native 12 | trait RectProps extends js.Object { 13 | var x: Double = js.native 14 | var y: Double = js.native 15 | var width: Double = js.native 16 | var height: Double = js.native 17 | var point: Point = js.native 18 | var size: Size = js.native 19 | var left: Double = js.native 20 | var top: Double = js.native 21 | var right: Double = js.native 22 | var bottom: Double = js.native 23 | var center: Point = js.native 24 | var topLeft: Point = js.native 25 | var topRight: Point = js.native 26 | var bottomLeft: Point = js.native 27 | var bottomRight: Point = js.native 28 | var leftCenter: Point = js.native 29 | var topCenter: Point = js.native 30 | var rightCenter: Point = js.native 31 | var bottomCenter: Point = js.native 32 | def area: Double = js.native 33 | var selected: Boolean = js.native 34 | } 35 | 36 | object RectDims { 37 | def apply(x: Double, y: Double, width: Double, height: Double): RectProps = 38 | js.Dynamic.literal( 39 | "x" -> x, 40 | "y" -> y, 41 | "width" -> width, 42 | "height" ->height 43 | ).asInstanceOf[RectProps] 44 | } 45 | 46 | @js.native 47 | @JSName("paper.Rectangle") 48 | class Rect(x: Double, y: Double, width: Double, height: Double) extends RectProps { 49 | def this(p: Point, s: Size) = this(0,0,0,0) 50 | def this(props: RectProps) = this(0,0,0,0) 51 | def this(from: Point, to: Point) = this(0,0,0,0) 52 | def equals(rect: Rect): Boolean = js.native 53 | @JSName("equals") 54 | def ==(r: Rect): Boolean = js.native 55 | override def toString: String = js.native 56 | def isEmpty: Boolean = js.native 57 | def contains(point: Point): Boolean = js.native 58 | def contains(rect: Rect): Boolean = js.native 59 | def intersects(rect: Rect): Boolean = js.native 60 | def intersect(rect: Rect): Rect = js.native 61 | def unite(rect: Rect): Rect = js.native 62 | def include(point: Point): Unit = js.native 63 | def expand(amount: Double): Unit = js.native 64 | def expand(amount: Point): Unit = js.native 65 | def expand(amount: Size): Unit = js.native 66 | def expand(hor: Double, ver: Double): Unit = js.native 67 | def scale(amount: Double): Unit = js.native 68 | def scale(hor: Double, ver: Double): Unit = js.native 69 | } 70 | 71 | object Rect { 72 | def apply(x: Double, y: Double, width: Double, height: Double): Rect = 73 | new Rect(x, y, width, height) 74 | def apply(p: Point, s: Size): Rect = new Rect(p, s) 75 | def apply(props: RectProps): Rect = new Rect(props) 76 | def apply(from: Point, to: Point): Rect = new Rect(from,to) 77 | } 78 | -------------------------------------------------------------------------------- /src/main/scala/paperjs/Basic/Size.scala: -------------------------------------------------------------------------------- 1 | package paperjs 2 | package Basic 3 | 4 | import scala.scalajs.js 5 | import scala.scalajs.js.annotation.JSName 6 | 7 | /** 8 | * Created by yoelusa on 24/04/15. 9 | */ 10 | 11 | @js.native 12 | trait SizeProps extends js.Object { 13 | var width: Double = js.native 14 | var height: Double = js.native 15 | } 16 | 17 | @js.native 18 | @JSName("paper.Size") 19 | class Size(width: Double, height: Double) extends SizeProps { 20 | def this(width: Double) = this(0,0) 21 | def this(point: Point) = this(0,0) 22 | def this(size: Size) = this(0,0) 23 | def this(props: SizeProps) = this(0,0) 24 | def add(d: Double): Size = js.native 25 | def add(s: Size): Size = js.native 26 | def subtract(d: Double): Size = js.native 27 | def subtract(s: Size): Size = js.native 28 | def multiply(d: Double): Size = js.native 29 | def multiply(s: Size): Size = js.native 30 | def divide(d: Double): Size = js.native 31 | def divide(s: Size): Size = js.native 32 | def modulo(i: Int): Size = js.native 33 | def modulo(s: Size): Size = js.native 34 | def equals(s: Size): Boolean = js.native 35 | @JSName("equals") 36 | def ==(s: Size): Boolean = js.native 37 | def isZero: Boolean = js.native 38 | def isNaN: Boolean = js.native 39 | def round(): Size = js.native 40 | def ceil(): Size = js.native 41 | def floor(): Size = js.native 42 | def abs(): Size = js.native 43 | } 44 | 45 | @js.native 46 | @JSName("paper.Point") 47 | object Size extends js.Object { 48 | def min(size1: Size, size2: Size): Size = js.native 49 | def max(size1: Size, size2: Size): Size = js.native 50 | def random(): Size = js.native 51 | } 52 | -------------------------------------------------------------------------------- /src/main/scala/paperjs/Basic/package.scala: -------------------------------------------------------------------------------- 1 | package paperjs 2 | 3 | /** 4 | * Created by yoelusa on 24/04/15. 5 | */ 6 | 7 | package object Basic { 8 | implicit class PointCompanionOps(val self: Point.type) extends AnyVal { 9 | def apply(x: Double, y: Double): Point = new Point(x, y) 10 | def apply(x: Double): Point = new Point(x) 11 | def apply(props: PointProps): Point = new Point(props) 12 | } 13 | implicit class SizeCompanionOps(val self: Size.type) extends AnyVal { 14 | def apply(width: Double, height: Double): Size = new Size(width, height) 15 | def apply(p: Point): Size = new Size(p) 16 | def apply(props: SizeProps): Size = new Size(props) 17 | } 18 | implicit def toPointOps(p: Point): PointOps = new PointOps(p) 19 | class PointOps(p: Point) { 20 | def *(p1: Point): Point = p multiply p1 21 | def *(d: Double): Point = p multiply d 22 | def /(p1: Point): Point = p divide p1 23 | def /(d: Double): Point = p divide d 24 | def +(p1: Point): Point = p add p1 25 | def +(d: Double): Point = p add d 26 | def -(p1: Point): Point = p subtract p1 27 | def -(d: Double): Point = p subtract d 28 | def %(i: Int): Point = p modulo i 29 | def %(i: Point): Point = p modulo i 30 | } 31 | implicit def toSizeOps(s: Size): SizeOps = new SizeOps(s) 32 | class SizeOps(s: Size) { 33 | def *(s1: Size): Size = s multiply s1 34 | def *(d: Double): Size = s multiply d 35 | def /(s1: Size): Size = s divide s1 36 | def /(d: Double): Size = s divide d 37 | def +(s1: Size): Size = s add s1 38 | def +(d: Double): Size = s add d 39 | def -(s1: Size): Size = s subtract s1 40 | def -(d: Double): Size = s subtract d 41 | def %(i: Int): Size = s modulo i 42 | def %(i: Size): Size = s modulo i 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /src/main/scala/paperjs/Items/Group.scala: -------------------------------------------------------------------------------- 1 | package paperjs 2 | package Items 3 | 4 | import scala.scalajs.js 5 | import scala.scalajs.js.annotation.JSName 6 | 7 | /** 8 | * Created by yoelusa on 26/04/15. 9 | */ 10 | 11 | @js.native 12 | trait GroupNative extends Item { 13 | var clipped: Boolean = js.native 14 | } 15 | 16 | @js.native 17 | @JSName("paper.Group") 18 | class Group(children: js.Array[Item]) extends GroupNative { 19 | def this(obj: js.Dynamic) = this(js.Array[Item]()) 20 | } 21 | 22 | object Group { 23 | def apply(children: js.Array[Item]): Group = new Group(children) 24 | } 25 | -------------------------------------------------------------------------------- /src/main/scala/paperjs/Items/Item.scala: -------------------------------------------------------------------------------- 1 | package paperjs 2 | package Items 3 | 4 | import org.scalajs.dom 5 | import org.scalajs.dom.raw.SVGElement 6 | 7 | import scala.scalajs.js 8 | import Basic._, Styling._,Projects._,Tools.ToolEvent 9 | 10 | import scala.scalajs.js.annotation.JSName 11 | 12 | /** 13 | * Created by yoelusa on 25/04/15. 14 | */ 15 | 16 | @js.native 17 | trait Item extends EventHandling[Item] with MouseHandler { 18 | 19 | // Properties 20 | 21 | var tangent: Point = js.native 22 | var normal: Point = js.native 23 | var curvature: Double = js.native 24 | val id: Int = js.native 25 | val className: String = js.native 26 | var name: String = js.native 27 | var style: Style = js.native 28 | var visible: Boolean = js.native 29 | var blendMode: String = js.native 30 | var opacity: Double = js.native 31 | var selected: Boolean = js.native 32 | var clipMask: Boolean = js.native 33 | var data: js.Dynamic = js.native 34 | 35 | // Position and Bounding Boxes 36 | 37 | var position: Point = js.native 38 | var pivot: Point = js.native 39 | var bounds: Rect = js.native 40 | var strokeBounds: Rect = js.native 41 | var handleBounds: Rect = js.native 42 | var rotation: Double = js.native 43 | var scaling: Double = js.native 44 | var matrix: Matrix = js.native 45 | var globalMatrix: Matrix = js.native 46 | var applyMatrix: Matrix = js.native 47 | 48 | // Project Hierarchy 49 | 50 | val project: Project = js.native 51 | val view: View = js.native 52 | val layer: Layer = js.native 53 | val parent: Item = js.native 54 | def children: js.Array[Item] = js.native 55 | def firstChild: Item = js.native 56 | def lastChild: Item = js.native 57 | def nextSibling: Item = js.native 58 | def previousSibling: Item = js.native 59 | def index: Int = js.native 60 | 61 | // Stroke Style 62 | 63 | var strokeColor: Color = js.native 64 | var strokeWidth: Double = js.native 65 | var strokeCap: String = js.native 66 | var strokeJoin: String = js.native 67 | var dashOffset: Double = js.native 68 | var strokeScaling: Boolean = js.native 69 | var dashArray: js.Array[Double] = js.native 70 | var miterLimit: Double = js.native 71 | var windingRule: String = js.native 72 | 73 | // Fill Style 74 | 75 | var fillColor: Color = js.native 76 | var selectedColor: Color = js.native 77 | var onFrame: js.Function1[dom.Event, Unit] => Unit = js.native 78 | var onClick: js.ThisFunction1[Item, ToolEvent, Unit] = js.native 79 | var onDoubleClick: js.ThisFunction1[Item, ToolEvent, Unit] = js.native 80 | var onMouseEnter: js.ThisFunction1[Item, ToolEvent, Unit] = js.native 81 | var onMouseLeave: js.ThisFunction1[Item, ToolEvent, Unit] = js.native 82 | 83 | // Methods 84 | 85 | def set(props: js.Dynamic): Item = js.native 86 | def clone(insert: Boolean = true): Item = js.native 87 | @JSName("copyTo") 88 | def copyToProj(proj: Project): Item = js.native 89 | @JSName("copyTo") 90 | def copyToLayer(layer: Layer): Item = js.native 91 | //def copyToGroup(group: Project): Item = js.native 92 | //def copyToCompPath(compPath: Project): Item = js.native 93 | def rasterize(resolution: Double = 1.0): Raster = js.native 94 | def contains(point: Point): Boolean = js.native 95 | def isInside(rect: Rect): Boolean = js.native 96 | def intersects(item: Item): Boolean = js.native 97 | def hitTest(point: Point, options: js.Dynamic): HitResult = js.native 98 | 99 | // Fetching and matching items 100 | 101 | def matches(matching: js.Dynamic): Boolean = js.native 102 | def matches(name: String, compare: js.Any): Boolean = js.native 103 | def getItems(matching: js.Dynamic = js.Dynamic.literal()): js.Array[Item] = 104 | js.native 105 | def getItem(matching: js.Dynamic = js.Dynamic.literal()): Item = js.native 106 | 107 | // Import / Export JSON and SVG 108 | 109 | def exportJSON(options: js.Dynamic = js.Dynamic.literal()): String = 110 | js.native 111 | def importJSON(json: String): Unit = js.native 112 | 113 | @JSName("exportSVG") 114 | def exportSVGAsString(options: js.Dynamic = js.Dynamic.literal(asString = true)): String = 115 | js.native 116 | @JSName("exportSVG") 117 | def exportSVG(options: js.Dynamic = js.Dynamic.literal()): SVGElement = 118 | js.native 119 | def importSVG(svg: String, options: js.Dynamic = js.Dynamic.literal()): Item = 120 | js.native 121 | 122 | // Hierarchy Operations 123 | 124 | def addChild(item: Item): Item = js.native 125 | def insertChildren(index: Int, item: Item): Item = js.native 126 | def addChildren(items: js.Array[Item]): js.Array[Item] = js.native 127 | def insertChildren(index: Int, items: js.Array[Item]): js.Array[Item] = js.native 128 | def insertAbove(item: Item): Item = js.native 129 | def insertBelow(item: Item): Item = js.native 130 | def sendToBack(): Unit = js.native 131 | def reduce(): Unit = js.native 132 | def replaceWith(item: Item): Boolean = js.native 133 | def remove(): Unit = js.native 134 | def removeChildren(): js.Array[Item] =js.native 135 | def removeChildren(from: Int, to: Int = 0): js.Array[Item] = js.native 136 | def reverseChildren(): Unit = js.native 137 | 138 | // Tests 139 | 140 | def isEmpty(): Boolean = js.native 141 | 142 | // Style Tests 143 | 144 | def hasFill(): Boolean = js.native 145 | def hasStroke(): Boolean = js.native 146 | def hasShadow(): Boolean = js.native 147 | 148 | // Hierarchy Tests 149 | 150 | def hasChildren(): Boolean = js.native 151 | def isInserted(): Boolean = js.native 152 | def isAbove(): Boolean = js.native 153 | def isBelow(item: Item): Boolean = js.native 154 | def isParent(item: Item): Boolean = js.native 155 | def isChild(item: Item): Boolean = js.native 156 | def isDescendant(item: Item): Boolean = js.native 157 | def isAncestor(item: Item): Boolean = js.native 158 | def isGroupedWith(item: Item): Boolean = js.native 159 | 160 | // Transform Functions 161 | 162 | def bringToFront(): Unit = js.native 163 | def translate(delta: Point): Unit = js.native 164 | def rotate(angle: Double, center: Point = Point(0,0)): Unit = js.native 165 | @JSName("scale") 166 | def scaleAll(scale: Double, center: Point = Point(0,0)): Unit = js.native 167 | def scale(hor: Double, ver: Double, center: Point = Point(0,0)): Unit = js.native 168 | @JSName("shear") 169 | def shearAll(shear: Double, center: Point = Point(0,0)): Unit = js.native 170 | def shear(hor: Double, ver: Double, center: Point = Point(0,0)): Unit = js.native 171 | @JSName("skew") 172 | def skewAll(skew: Double, center: Point = Point(0,0)): Unit = js.native 173 | def skew(hor: Double, ver: Double, center: Point = Point(0,0)): Unit = js.native 174 | def transform(matrix: Matrix): Unit = js.native 175 | def globalToLocal(point: Point): Point = js.native 176 | def localToGlobal(point: Point): Point = js.native 177 | def parentToLocal(point: Point): Point = js.native 178 | def localToParent(point: Point): Point = js.native 179 | def fitBounds(rectangle: Rect, fill: Boolean = false): Unit = js.native 180 | 181 | // Remove On Event 182 | 183 | def removeOn(params: js.Dynamic): Unit = js.native 184 | def removeOnMove(): Unit = js.native 185 | def removeOnDown(): Unit = js.native 186 | def removeOnDrag(): Unit = js.native 187 | def removeOnUp(): Unit = js.native 188 | } -------------------------------------------------------------------------------- /src/main/scala/paperjs/Items/Layer.scala: -------------------------------------------------------------------------------- 1 | package paperjs 2 | package Items 3 | 4 | import scala.scalajs.js 5 | import scala.scalajs.js.annotation.JSName 6 | 7 | /** 8 | * Created by yoelusa on 25/04/15. 9 | */ 10 | 11 | @js.native 12 | @JSName("paper.Layer") 13 | class Layer(children: js.Array[Item]) extends Item with GroupNative { 14 | def this(obj: js.Dynamic) = this(js.Array[Item]()) 15 | def activate(): Unit = js.native 16 | } 17 | 18 | object Layer { 19 | def apply(children: js.Array[Item]): Layer = new Layer(children) 20 | } 21 | -------------------------------------------------------------------------------- /src/main/scala/paperjs/Items/PlacedSymbol.scala: -------------------------------------------------------------------------------- 1 | package paperjs 2 | package Items 3 | 4 | import scala.scalajs.js 5 | import scala.scalajs.js.annotation.JSName 6 | import Basic._ 7 | 8 | /** 9 | * Created by yoelusa on 26/04/15. 10 | */ 11 | 12 | @js.native 13 | @JSName("paper.PlacedSymbol") 14 | class PlacedSymbol(symbol: Symbol, var point: Point = Point(0,0)) extends Item 15 | -------------------------------------------------------------------------------- /src/main/scala/paperjs/Items/Raster.scala: -------------------------------------------------------------------------------- 1 | package paperjs.Items 2 | 3 | import scala.scalajs.js 4 | import paperjs._ 5 | import Basic._,Styling._ 6 | 7 | import scala.scalajs.js.annotation.JSName 8 | import org.scalajs.dom._ 9 | 10 | /** 11 | * Created by yoelusa on 26/04/15. 12 | */ 13 | 14 | @js.native 15 | @JSName("paper.Raster") 16 | class Raster(var source: String, position: Point = Point(0,0)) extends Item { 17 | def this(source: raw.HTMLImageElement, position: Point) = this("", position) 18 | def this(source: raw.HTMLCanvasElement, position: Point) = this("", position) 19 | def this(obj: js.Dynamic) = this("", Point(0,0)) 20 | var size: Size = js.native 21 | var width: Double = js.native 22 | var height: Double = js.native 23 | def resolution: Size = js.native 24 | def image: raw.HTMLImageElement = js.native 25 | @JSName("image") 26 | def imageCanvas: html.Canvas = js.native 27 | def canvas: html.Canvas = js.native 28 | def context: CanvasRenderingContext2D = js.native 29 | 30 | // Methods 31 | 32 | def getSubCanvas(rect: Rect): html.Canvas = js.native 33 | def getSubRaster(rect: Rect): Raster = js.native 34 | def toDataURL: String = js.native 35 | def drawImage(image: raw.HTMLImageElement, point: Point): Unit = js.native 36 | @JSName("drawImage") 37 | def drawCanvas(canvas: html.Canvas, point: Point): Unit = js.native 38 | def getAverageColor(obj: js.Dynamic): Color = js.native 39 | 40 | // Pixel 41 | 42 | def getPixel(x: Double, y: Double): Color = js.native 43 | @JSName("getPixel") 44 | def getPointWithPoint(point: Point): Color = js.native 45 | def setPixel(x: Double, y: Double, color: Color): Unit =js.native 46 | @JSName("setPoint") 47 | def setPixelWithPoint(x: Double, y: Double, color: Color): Unit =js.native 48 | 49 | // Image Data 50 | 51 | def createImageData(size: Size): Unit = js.native 52 | def getImageData(rect: Rect): raw.ImageData = js.native 53 | def setImageData(data: raw.ImageData, point: Point): Unit = js.native 54 | } 55 | -------------------------------------------------------------------------------- /src/main/scala/paperjs/Items/Shape.scala: -------------------------------------------------------------------------------- 1 | package paperjs 2 | package Items 3 | 4 | import scala.scalajs.js 5 | import scala.scalajs.js.annotation.JSName 6 | import Basic._ 7 | 8 | /** 9 | * Created by yoelusa on 26/04/15. 10 | */ 11 | 12 | @js.native 13 | @JSName("paper.Shape") 14 | trait Shape extends Item { 15 | @JSName("type") 16 | def typeName: String =js.native 17 | def size: Size = js.native 18 | def radius: Double = js.native 19 | } 20 | 21 | @js.native 22 | @JSName("paper.Shape") 23 | object Shape extends js.Object { 24 | def Circle(center: Point, radius: Double): Shape = js.native 25 | def Circle(obj: js.Dynamic): Shape = js.native 26 | def Rectangle(rectangle: Rect, radius: Double = 1.0): Shape = js.native 27 | def Rectangle(point: Point, size: Size): Shape = js.native 28 | def Rectangle(obj: js.Dynamic): Shape = js.native 29 | def Ellipse(rectangle: Rect): Shape = js.native 30 | def Ellipse(obj: js.Dynamic): Shape = js.native 31 | } 32 | -------------------------------------------------------------------------------- /src/main/scala/paperjs/Paths/CompoundPath.scala: -------------------------------------------------------------------------------- 1 | package paperjs 2 | package Paths 3 | 4 | import Items._ 5 | 6 | import scala.scalajs.js 7 | 8 | /** 9 | * Created by yoelusa on 27/04/15. 10 | */ 11 | 12 | @js.native 13 | class CompoundPath(pathData: String) extends Item with PathItem{ 14 | def this(obj: js.Dynamic) = this("") 15 | 16 | // Properties 17 | 18 | var clockwise: Boolean = js.native 19 | def firstSegment: Segment = js.native 20 | def lastSegment: Segment = js.native 21 | def curves: js.Array[Curve] = js.native 22 | def firstCurve: Curve = js.native 23 | def lastCurve: Curve = js.native 24 | def area: Double = js.native 25 | 26 | // Methods 27 | 28 | def reverse(): Unit = js.native 29 | } 30 | -------------------------------------------------------------------------------- /src/main/scala/paperjs/Paths/Curve.scala: -------------------------------------------------------------------------------- 1 | package paperjs 2 | package Paths 3 | 4 | import scala.scalajs.js 5 | import scala.scalajs.js.annotation.JSName 6 | 7 | import Basic._ 8 | 9 | /** 10 | * Created by yoelusa on 25/04/15. 11 | */ 12 | 13 | @js.native 14 | @JSName("paper.Curve") 15 | class Curve(var segment1: Segment, var segment2: Segment) extends js.Object { 16 | def this(point1: Point, handle1: Point, handle2: Point, point2: Point) = 17 | this(Segment(Point(0,0)),Segment(Point(0,0))) 18 | 19 | // Properties 20 | 21 | def path: Path = js.native 22 | def index: Int = js.native 23 | def next: Curve = js.native 24 | def previous: Curve = js.native 25 | var selected: Boolean = js.native 26 | def length: Double = js.native 27 | var bounds: Rect = js.native 28 | var strokeBounds: Rect = js.native 29 | var handleBounds: Rect = js.native 30 | 31 | // Methods 32 | 33 | def isLinear: Boolean = js.native 34 | def divide(offset: Double = 0.5, isParameter: Boolean): Curve = js.native 35 | def split(offset: Double, isParameter: Boolean = false): Path = js.native 36 | def reverse(): Curve = js.native 37 | def remove(): Boolean = js.native 38 | override def clone(): Curve = js.native 39 | override def toString: String = js.native 40 | def getParameterAt(offset: Double, start: Double = 1.0): Double = js.native 41 | def getParameterOf(point: Point): Double = js.native 42 | def getLocationAt(offset: Double, isParameter: Boolean = false): CurveLocation = js.native 43 | def getLocationOf(point: Point): CurveLocation = js.native 44 | def getPointAt(offset: Double, isParameter: Boolean = false): Point = js.native 45 | def getTangentAt(offset: Double, isParameter: Boolean = false): Point = js.native 46 | def getNormalAt(offset: Double, isParameter: Boolean = false): Point = js.native 47 | def getCurvatureAt(offset: Double, isParameter: Boolean = false): Point = js.native 48 | } 49 | -------------------------------------------------------------------------------- /src/main/scala/paperjs/Paths/Path.scala: -------------------------------------------------------------------------------- 1 | package paperjs 2 | package Paths 3 | 4 | import scala.scalajs.js 5 | import scala.scalajs.js.annotation.JSName 6 | 7 | import Basic._,Items._ 8 | 9 | /** 10 | * Created by yoelusa on 25/04/15. 11 | */ 12 | 13 | @js.native 14 | @JSName("paper.Path") 15 | class Path(var segments: js.Array[Segment] = js.Array[Segment]()) extends Item with PathItem { 16 | def this(obj: js.Dynamic) = this() 17 | def this(pathData: String) = this() 18 | 19 | // Properties 20 | 21 | def firstSegment: Segment = js.native 22 | def lastSegment: Segment = js.native 23 | def curves: Curve = js.native 24 | def firstCurve: Curve = js.native 25 | def lastCurve: Curve = js.native 26 | var closed: Boolean = js.native 27 | var length: Double = js.native 28 | def area: Double = js.native 29 | var fullySelected: Boolean = js.native 30 | var clockwise: Boolean = js.native 31 | def interiorPoint: Point = js.native 32 | 33 | // Methods 34 | 35 | def add(segment: Segment): Segment = js.native 36 | def add(point: Point): Point = js.native 37 | def insert(index: Int, segment: Segment): Segment = js.native 38 | def addSegments(segments: js.Array[Segment]): js.Array[Segment] = js.native 39 | def insertSegments(index: Int, segments: js.Array[Segment]): js.Array[Segment] = js.native 40 | def removeSegment(index: Int): Segment = js.native 41 | def removeSegments(from: Int, to: Int = 0): js.Array[Segment] = js.native 42 | def flatten(maxDistance: Double): Unit = js.native 43 | override def reduce(): Unit = js.native 44 | def simplify(tolerance: Double = 2.5): Unit = js.native 45 | def split(offset: Double): Path = js.native 46 | def split(location: CurveLocation): Path = js.native 47 | def split(index: Int, parameter: Double): Path = js.native 48 | def reverse(): Unit = js.native 49 | def join(path: Path): Path = js.native 50 | 51 | // Positions on Paths and Curves 52 | 53 | def getLocationOf(point: Point): CurveLocation = js.native 54 | def getOffsetOf(point: Point): Double = js.native 55 | def getLocationAt(offset: Double, isParameter: Boolean = false): CurveLocation = js.native 56 | def getPointAt(offset: Double, isParameter: Boolean): Point = js.native 57 | def getTangentAt(offset: Double, isParameter: Boolean): Point = js.native 58 | def getNormalAt(offset: Double, isParameter: Boolean): Point = js.native 59 | def getCurvatureAt(offset: Double, point: Point): Double = js.native 60 | def getNearestPoint(point: Point): Point = js.native 61 | } 62 | 63 | @js.native 64 | @JSName("paper.Path") 65 | object Path extends js.Object { 66 | def Line(from: Point, to: Point): Path = js.native 67 | def Line(obj: js.Dynamic): Path = js.native 68 | def Circle(center: Point, radius: Double): Path = js.native 69 | def Circle(obj: js.Dynamic): Path = js.native 70 | def Rectangle(rectangle: Rect, radius: Double = 1.0): Path = js.native 71 | def Rectangle(point: Point, size: Size): Path = js.native 72 | def Rectangle(obj: js.Dynamic): Path = js.native 73 | def Ellipse(rectangle: Rect): Path = js.native 74 | def Ellipse(obj: js.Dynamic): Path = js.native 75 | def Arc(from: Point, through: Point, to: Point): Path = js.native 76 | def Arc(obj: js.Dynamic): Path = js.native 77 | def RegularPolygon(center: Point, sides: Int, radius: Double): Path = js.native 78 | def RegularPolygon(obj: js.Dynamic): Path = js.native 79 | def Star(center: Point, points: Int, radius1: Double, radius2: Double): Path = js.native 80 | def Star(obj: js.Dynamic): Path = js.native 81 | } -------------------------------------------------------------------------------- /src/main/scala/paperjs/Paths/PathItem.scala: -------------------------------------------------------------------------------- 1 | package paperjs 2 | package Paths 3 | 4 | import Items._,Basic._ 5 | 6 | import scala.scalajs.js 7 | 8 | /** 9 | * Created by yoelusa on 27/04/15. 10 | */ 11 | 12 | @js.native 13 | trait PathItem extends Item { 14 | 15 | //Properties 16 | 17 | def pathData: String = js.native 18 | 19 | // Methods 20 | 21 | def getIntersections(path: PathItem, sorted: Boolean = false): js.Array[CurveLocation] = 22 | js.native 23 | def smooth(): Unit = js.native 24 | 25 | // Postscript Style Drawing Commands 26 | 27 | def moveTo(point: Point): Unit = js.native 28 | def lineTo(point: Point): Unit = js.native 29 | def cubicCurveTo(handle1: Point, handle2: Point, to: Point): Unit = js.native 30 | def quadraticCurveTo(handle: Point, to: Point): Unit = js.native 31 | def curveTo(through: Point, to: Point, parameter: Double = 0.5): Unit = js.native 32 | def arcTo(through: Point, to: Point): Unit = js.native 33 | def closePath(join: Boolean): Unit = js.native 34 | 35 | // Relative Drawing Commands 36 | 37 | def moveBy(to: Point): Unit = js.native 38 | def lineBy(to: Point): Unit = js.native 39 | def curveBy(through: Point, to: Point, parameter: Double = 0.5): Unit = js.native 40 | def cubicCurveBy(handle1: Point, handle2: Point, to: Point): Unit = js.native 41 | def quadraticCurveBy(handle: Point, to: Point): Unit = js.native 42 | def arcBy(through: Point, to: Point): Unit = js.native 43 | def arcBy(to: Point, clockwise: Boolean = true): Unit = js.native 44 | 45 | // Boolean Path Operations 46 | 47 | def unite(path: PathItem): PathItem = js.native 48 | def intersect(path: PathItem): PathItem = js.native 49 | def subtract(path: PathItem): PathItem = js.native 50 | def exclude(path: PathItem): Group = js.native 51 | def divide(path: PathItem): Group =js.native 52 | } 53 | -------------------------------------------------------------------------------- /src/main/scala/paperjs/Paths/Segment.scala: -------------------------------------------------------------------------------- 1 | package paperjs 2 | package Paths 3 | 4 | import scala.scalajs.js 5 | import Basic._ 6 | 7 | import scala.scalajs.js.annotation.JSName 8 | 9 | /** 10 | * Created by yoelusa on 25/04/15. 11 | */ 12 | 13 | @js.native 14 | @JSName("paper.Segment") 15 | class Segment(var point: Point, var handleIn: Point = Point(0,0), 16 | var handleOut: Point = Point(0,0)) extends js.Object { 17 | def this(obj: js.Dynamic) = this(Point(0,0)) 18 | 19 | // Properties 20 | 21 | var linear: Boolean = js.native 22 | var selected: Boolean = js.native 23 | 24 | // Hierarchy 25 | 26 | def index: Int = js.native 27 | def path: Path = js.native 28 | def curve: Curve = js.native 29 | def location: CurveLocation = js.native 30 | 31 | // Sibling Segments 32 | 33 | def next: Segment = js.native 34 | def previous: Segment = js.native 35 | 36 | // Methods 37 | 38 | def isColinear(segment: Segment): Boolean = js.native 39 | def isArc: Boolean = js.native 40 | def reverse(): Segment = js.native 41 | def remove(): Boolean = js.native 42 | override def toString: String = js.native 43 | def transform(matrix: Matrix): Unit = js.native 44 | } 45 | 46 | object Segment { 47 | def apply(point: Point, handleIn: Point = Point(0,0), handleOut: Point = Point(0,0)): Segment = 48 | new Segment(point, handleIn, handleOut) 49 | } 50 | -------------------------------------------------------------------------------- /src/main/scala/paperjs/Paths/package.scala: -------------------------------------------------------------------------------- 1 | package paperjs 2 | 3 | import scala.scalajs.js 4 | 5 | /** 6 | * Created by yoelusa on 27/04/15. 7 | */ 8 | package object Paths { 9 | implicit class PathCompanionOps(val self: Path.type) extends AnyVal { 10 | def apply(segments: js.Array[Segment] = js.Array[Segment]()): Path = new Path(segments) 11 | def apply(obj: js.Dynamic): Path = new Path(obj) 12 | def apply(pathData: String): Path = new Path(pathData) 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /src/main/scala/paperjs/Projects/Project.scala: -------------------------------------------------------------------------------- 1 | package paperjs 2 | package Projects 3 | 4 | import org.scalajs.dom.raw.HTMLCanvasElement 5 | 6 | import scala.scalajs.js 7 | import scala.scalajs.js.annotation.JSName 8 | import Styling._,Items._,Basic._ 9 | 10 | /** 11 | * Created by yoelusa on 25/04/15. 12 | */ 13 | 14 | @js.native 15 | @JSName("paper.Project") 16 | class Project(element: String) extends js.Object { 17 | def this(elem: HTMLCanvasElement) = this("") 18 | def view: View = js.native 19 | var currentStyle: Style = js.native 20 | def index: Int = js.native 21 | var layers: js.Array[Layer] = js.native 22 | def activeLayer: Layer = js.native 23 | def symbols: Symbol = js.native 24 | def selectedItems: js.Array[Item] = js.native 25 | def activate(): Unit = js.native 26 | def clear(): Unit = js.native 27 | def isEmpty: Boolean = js.native 28 | def remove(): Unit = js.native 29 | def selectAll(): Unit = js.native 30 | def deselectAll(): Unit = js.native 31 | def hitTest(point: Point, options: js.Dynamic = 32 | js.Dynamic.literal()): HitResult = js.native 33 | def getItems(matching: js.Dynamic = js.Dynamic.literal()): js.Array[Item] = 34 | js.native 35 | def getItem(matching: js.Dynamic = js.Dynamic.literal()): Item = js.native 36 | def exportJSON(options: js.Dynamic = js.Dynamic.literal()): String = 37 | js.native 38 | def importJSON(json: String): Unit = js.native 39 | def exportSVG(options: js.Dynamic = js.Dynamic.literal()): String = 40 | js.native 41 | def importSVG(svg: String, options: js.Dynamic = js.Dynamic.literal()): Item = 42 | js.native 43 | } 44 | 45 | object Project { 46 | def apply(element: String): Project = new Project(element) 47 | def apply(element: HTMLCanvasElement): Project = new Project(element) 48 | } 49 | -------------------------------------------------------------------------------- /src/main/scala/paperjs/Projects/Symbol.scala: -------------------------------------------------------------------------------- 1 | package paperjs 2 | package Projects 3 | 4 | import scala.scalajs.js 5 | import Items._,Basic._ 6 | 7 | import scala.scalajs.js.annotation.JSName 8 | 9 | /** 10 | * Created by yoelusa on 25/04/15. 11 | */ 12 | 13 | @js.native 14 | @JSName("paper.Symbol") 15 | class Symbol(item: Item, dontCenter: Boolean = false) extends js.Object { 16 | val project: Project = js.native 17 | var definition: Item = js.native 18 | def place(position: Point = Point(0,0)): PlacedSymbol = js.native 19 | override def clone(): Symbol = js.native 20 | def equals(symbol: Symbol): Boolean = js.native 21 | } 22 | 23 | object Symbol { 24 | def apply(item: Item, dontCenter: Boolean = false) = new Symbol(item,dontCenter) 25 | } 26 | -------------------------------------------------------------------------------- /src/main/scala/paperjs/Projects/View.scala: -------------------------------------------------------------------------------- 1 | package paperjs 2 | package Projects 3 | 4 | import Basic._ 5 | import org.scalajs.dom 6 | 7 | import scala.scalajs.js 8 | import scala.scalajs.js.annotation.JSName 9 | import org.scalajs.dom._ 10 | 11 | /** 12 | * Created by yoelusa on 25/04/15. 13 | */ 14 | 15 | @js.native 16 | @JSName("paper.View") 17 | trait View extends EventHandling[View] { 18 | val element: raw.HTMLCanvasElement = js.native 19 | val pixelRatio: Double = js.native 20 | val resolution: Double = js.native 21 | var viewSize: Size = js.native 22 | def bounds: Rect = js.native 23 | def size: Size = js.native 24 | var center: Point = js.native 25 | var zoom: Double = js.native 26 | 27 | // Event Handlers 28 | 29 | var onFrame: js.ThisFunction1[View, FrameEvent, Unit] = js.native 30 | var onResize: js.ThisFunction1[View, FrameEvent, Unit] = js.native 31 | 32 | // Methods 33 | 34 | def draw(): Unit = js.native 35 | def remove(): Unit = js.native 36 | def isVisible: Boolean = js.native 37 | def scrollBy(point: Point): Unit = js.native 38 | def play(): Unit = js.native 39 | def update(): Unit =js.native 40 | def projectToView(point: Point): Point = js.native 41 | def viewToProject(point: Point): Point = js.native 42 | } 43 | -------------------------------------------------------------------------------- /src/main/scala/paperjs/Projects/package.scala: -------------------------------------------------------------------------------- 1 | package paperjs 2 | 3 | import scala.scalajs.js 4 | 5 | /** 6 | * Created by yoelusa on 17/09/2015. 7 | */ 8 | package object Projects { 9 | @js.native 10 | trait FrameEvent extends js.Object { 11 | val delta: Double = js.native 12 | val time: Double = js.native 13 | val count: Int = js.native 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /src/main/scala/paperjs/Styling/Color.scala: -------------------------------------------------------------------------------- 1 | package paperjs 2 | package Styling 3 | 4 | import scala.scalajs.js 5 | import Basic._ 6 | 7 | import scala.scalajs.js.annotation.JSName 8 | 9 | /** 10 | * Created by yoelusa on 25/04/15. 11 | */ 12 | 13 | @js.native 14 | @JSName("paper.GradientStops") 15 | class GradientStops(color: String, rampPoint: Double) extends js.Object { 16 | def this(color: Color, rampPoint: Double) = this("",0) 17 | override def clone(): GradientStops = js.native 18 | } 19 | 20 | @js.native 21 | trait Gradient extends js.Object { 22 | var stops: js.Array[Double] = js.native 23 | var radial: Boolean = js.native 24 | override def clone(): Gradient = js.native 25 | def equals(): Boolean = js.native 26 | } 27 | 28 | @js.native 29 | @JSName("paper.Color") 30 | class Color(red: Double, green: Double, blue: Double, alpha: Double) extends js.Object { 31 | def this(gray: Double, alpha: Double) = this(0,0,0,0) 32 | def this(gradient: Gradient, origin: Point, destination: Point, 33 | highlight: Point = Point(0,0)) = this(0,0,0,0) 34 | def this(obj: js.Dynamic) = this(0,0,0,0) 35 | def this(color: String) = this(0,0,0,0) 36 | def +(d: Double): Color = js.native 37 | def +(c: Color): Color = js.native 38 | def -(d: Double): Color = js.native 39 | def -(c: Color): Color = js.native 40 | def *(d: Double): Color = js.native 41 | def *(c: Color): Color = js.native 42 | def /(d: Double): Color = js.native 43 | def /(c: Color): Color = js.native 44 | val `type`: String = js.native 45 | def components: js.Array[Double] = js.native 46 | def hue: Double = js.native 47 | def saturation: Double = js.native 48 | def brightness: Double = js.native 49 | def lightness: Double = js.native 50 | def gradient: Gradient = js.native 51 | def highlight: Point = js.native 52 | def convert(`type`: String): Color = js.native 53 | def hasAlpha: Boolean = js.native 54 | def equals(color: Color): Boolean = js.native 55 | def equals(color: String): Boolean = js.native 56 | override def clone(): Color = js.native 57 | override def toString: String = js.native 58 | def toCSS(hex: Boolean): String = js.native 59 | def transform(matrix: Matrix): Unit = js.native 60 | } 61 | 62 | object Color { 63 | def apply(red: Double, green: Double, blue: Double, alpha: Double): Color = 64 | new Color(red,green,blue,alpha) 65 | def apply(gradient: Gradient, origin: Point, destination: Point, 66 | highlight: Point = Point(0,0)): Color = 67 | new Color(gradient,origin,destination,highlight) 68 | def apply(gray: Double, alpha: Double): Color = new Color(gray,alpha) 69 | def apply(obj: js.Dynamic): Color = new Color(obj) 70 | def apply(color: String): Color = new Color(color) 71 | } 72 | -------------------------------------------------------------------------------- /src/main/scala/paperjs/Styling/Style.scala: -------------------------------------------------------------------------------- 1 | package paperjs 2 | package Styling 3 | 4 | import scala.scalajs.js 5 | import Projects._ 6 | 7 | import scala.scalajs.js.annotation.JSName 8 | 9 | /** 10 | * Created by yoelusa on 25/04/15. 11 | */ 12 | 13 | @js.native 14 | trait Style extends FontStyle { 15 | 16 | // Properties 17 | 18 | def view: View = js.native 19 | 20 | // Stroke Style 21 | 22 | var StrokeColor: Color = js.native 23 | @JSName("strokeColor") 24 | var StrokeColorStr: String = js.native 25 | var strokeWidth: Double = js.native 26 | var strokeCap: String = js.native 27 | var strokeJoin: String = js.native 28 | var strokeScaling: Boolean = js.native 29 | var dashOffset: Double = js.native 30 | var dashArray: js.Array[Int] = js.native 31 | var miterLimit: Double = js.native 32 | 33 | // Fill Style 34 | 35 | var fillColor: Color = js.native 36 | @JSName("fillColor") 37 | var fillColorStr: String = js.native 38 | 39 | 40 | // Shadow Style 41 | 42 | var shadowColor: Color = js.native 43 | @JSName("shadowColor") 44 | var shadowColorStr: String = js.native 45 | var shadowBlur: Double = js.native 46 | var shadowOffset: Double = js.native 47 | 48 | // Selection Style 49 | 50 | var selectedColor: Color = js.native 51 | @JSName("selectedColor") 52 | var selectedColorStr: String = js.native 53 | } -------------------------------------------------------------------------------- /src/main/scala/paperjs/Tools/Key.scala: -------------------------------------------------------------------------------- 1 | package paperjs.Tools 2 | 3 | import scala.scalajs.js 4 | 5 | /** 6 | * Created by yoelusa on 27/04/15. 7 | */ 8 | 9 | @js.native 10 | trait Key extends js.Object 11 | 12 | @js.native 13 | object Key extends js.Object { 14 | def isDown(key: String): Boolean = js.native 15 | } 16 | 17 | @js.native 18 | trait KeyEvent extends js.Object { 19 | val `type`: String = js.native 20 | val character: String = js.native 21 | val key: String = js.native 22 | override def toString: String = js.native 23 | def modifiers: js.Dynamic = js.native 24 | } 25 | -------------------------------------------------------------------------------- /src/main/scala/paperjs/Tools/Tool.scala: -------------------------------------------------------------------------------- 1 | package paperjs 2 | package Tools 3 | 4 | import scala.scalajs.js 5 | import scala.scalajs.js.annotation.JSName 6 | 7 | /** 8 | * Created by yoelusa on 27/04/15. 9 | */ 10 | 11 | @js.native 12 | @JSName("paper.Tool") 13 | class Tool extends EventHandling[Tool] { 14 | var minDistance: Double = js.native 15 | var maxDistance: Double = js.native 16 | var fixedDistance: Double = js.native 17 | var onMouseDown: js.Function1[ToolEvent, Unit] = js.native 18 | var onMouseUp: js.Function1[ToolEvent, Unit] = js.native 19 | var onMouseMove: js.Function1[ToolEvent, Unit] = js.native 20 | var onMouseDrag: js.Function1[ToolEvent, Unit] = js.native 21 | var onKeyDown: js.Function1[ToolEvent, Unit] = js.native 22 | var onKeyUp: js.Function1[ToolEvent, Unit] = js.native 23 | def activate(): Unit = js.native 24 | def remove(): Unit = js.native 25 | } 26 | 27 | object Tool { 28 | def apply(): Tool = new Tool() 29 | } 30 | -------------------------------------------------------------------------------- /src/main/scala/paperjs/Tools/ToolEvent.scala: -------------------------------------------------------------------------------- 1 | package paperjs 2 | package Tools 3 | 4 | import scala.scalajs.js 5 | import Basic._,Items._ 6 | 7 | /** 8 | * Created by yoelusa on 27/04/15. 9 | */ 10 | 11 | @js.native 12 | trait ToolEvent extends js.Object { 13 | val `type`: String = js.native 14 | val point: Point = js.native 15 | val lastPoint: Point = js.native 16 | val downPoint: Point = js.native 17 | val middlePoint: Point = js.native 18 | val delta: Point = js.native 19 | val count: Int = js.native 20 | val item: Item = js.native 21 | override def toString(): String = js.native 22 | val modifiers: js.Dynamic = js.native 23 | } 24 | -------------------------------------------------------------------------------- /src/main/scala/paperjs/Typography/PointText.scala: -------------------------------------------------------------------------------- 1 | package paperjs 2 | package Typography 3 | 4 | import Basic._,Items._ 5 | 6 | import scala.scalajs.js 7 | import scala.scalajs.js.annotation.JSName 8 | 9 | /** 10 | * Created by yoelusa on 27/04/15. 11 | */ 12 | 13 | @js.native 14 | @JSName("paper.PointText") 15 | class PointText(point: Point) extends Item with TextItem { 16 | def this(obj: js.Dynamic) = this(Point(0,0)) 17 | } 18 | -------------------------------------------------------------------------------- /src/main/scala/paperjs/Typography/TextItem.scala: -------------------------------------------------------------------------------- 1 | package paperjs 2 | package Typography 3 | 4 | import scala.scalajs.js 5 | 6 | import Items._ 7 | 8 | /** 9 | * Created by yoelusa on 27/04/15. 10 | */ 11 | 12 | @js.native 13 | trait TextItem extends Item with FontStyle { 14 | var content: String = js.native 15 | } 16 | -------------------------------------------------------------------------------- /src/main/scala/paperjs/package.scala: -------------------------------------------------------------------------------- 1 | import org.scalajs.dom 2 | import org.scalajs.dom.html 3 | 4 | import scala.scalajs.js 5 | import scala.scalajs.js.annotation.JSName 6 | 7 | /** 8 | * Created by yoelusa on 27/04/15. 9 | */ 10 | 11 | package object paperjs { 12 | import Items._,Basic._,Paths._,Styling.Color,Projects._,Tools._ 13 | @js.native 14 | trait HitResult extends js.Object { 15 | @JSName("type") 16 | val hitType: String = js.native 17 | val name: String = js.native 18 | val item: Item = js.native 19 | val location: CurveLocation = js.native 20 | val color: Color = js.native 21 | val segment: Segment = js.native 22 | val point: Point = js.native 23 | } 24 | @js.native 25 | @JSName("paper.CurveLocation") 26 | class CurveLocation(curve: Curve, parameter: Double, point: Point) 27 | extends js.Object { 28 | val segment: Segment = js.native 29 | val intersection: CurveLocation = js.native 30 | val path: Item = js.native 31 | val index: Int = js.native 32 | val offset: Double = js.native 33 | val curveOffset: Double = js.native 34 | val distance: Double = js.native 35 | def equals(location: CurveLocation): Boolean = js.native 36 | override def toString: String = js.native 37 | } 38 | @js.native 39 | trait FontStyle extends js.Object { 40 | 41 | // Character Style 42 | 43 | var fontFamily: String = js.native 44 | var fontWeight: Int = js.native 45 | @JSName("fontWeight") 46 | var fontWeightStr: String = js.native 47 | var fontSize: Double = js.native 48 | var leading: Double = js.native 49 | @JSName("leading") 50 | var leadingStr: String = js.native 51 | 52 | // Paragraph Style 53 | 54 | var justification: String = js.native 55 | } 56 | @js.native 57 | trait EventHandling[T] extends js.Object { 58 | def on(event: String, function: js.ThisFunction1[View, dom.Event, Unit]): T = js.native 59 | @JSName("on") 60 | def bind(param: js.Dynamic): Unit = js.native 61 | def off(event: String, function: js.ThisFunction1[View, dom.Event, Unit]): T = js.native 62 | @JSName("off") 63 | def unbind(param: js.Dynamic): Unit = js.native 64 | def emit(event: String, eventProps: js.Dynamic): Boolean = js.native 65 | def responds(event: String): Boolean = js.native 66 | } 67 | @js.native 68 | trait MouseHandler extends js.Object { 69 | var onMouseDown: js.ThisFunction1[Item, ToolEvent, Unit] = js.native 70 | var onMouseUp: js.ThisFunction1[Item, ToolEvent, Unit] = js.native 71 | var onMouseMove: js.ThisFunction1[Item, ToolEvent, Unit] = js.native 72 | } 73 | implicit class PaperCompanionOps(val self: PaperScope.type) extends AnyVal { 74 | def apply(): PaperScope = new PaperScope() 75 | } 76 | @js.native 77 | @JSName("PaperScope") 78 | class PaperScope extends js.Object { 79 | def setup(canvas: html.Canvas): Unit = js.native 80 | def activate(): Unit = js.native 81 | def view: View = js.native 82 | def version: String = js.native 83 | var settings: js.Dynamic = js.native 84 | def project: Project = js.native 85 | def projects: js.Array[Project] = js.native 86 | def tool: Tool = js.native 87 | def tools: js.Array[Tool] = js.native 88 | } 89 | @js.native 90 | @JSName("PaperScope") 91 | object PaperScope extends js.Object { 92 | def get(id: Int): PaperScope = js.native 93 | } 94 | @js.native 95 | @JSName("paper") 96 | object Paper extends PaperScope 97 | } --------------------------------------------------------------------------------