Skip to content

add Path2D and related methods #769

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Apr 3, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions api-reports/2_12.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1089,6 +1089,9 @@ CanvasRenderingContext2D[JC] def createRadialGradient(x0: Double, y0: Double, r0
CanvasRenderingContext2D[JC] def drawImage(image: HTMLElement, offsetX: Double, offsetY: Double, width: Double?, height: Double?, canvasOffsetX: Double?, canvasOffsetY: Double?, canvasImageWidth: Double?, canvasImageHeight: Double?): Unit
CanvasRenderingContext2D[JC] def ellipse(x: Double, y: Double, radiusX: Double, radiusY: Double, rotation: Double, startAngle: Double, endAngle: Double, anticlockwise: Boolean?): Unit
CanvasRenderingContext2D[JC] def fill(): Unit
CanvasRenderingContext2D[JC] def fill(fillRule: String): Unit
CanvasRenderingContext2D[JC] def fill(path: Path2D): Unit
CanvasRenderingContext2D[JC] def fill(path: Path2D, fillRule: String): Unit
CanvasRenderingContext2D[JC] def fillRect(x: Double, y: Double, w: Double, h: Double): Unit
CanvasRenderingContext2D[JC] var fillStyle: js.Any
CanvasRenderingContext2D[JC] def fillText(text: String, x: Double, y: Double, maxWidth: Double?): Unit
Expand Down Expand Up @@ -1122,6 +1125,7 @@ CanvasRenderingContext2D[JC] var shadowColor: String
CanvasRenderingContext2D[JC] var shadowOffsetX: Double
CanvasRenderingContext2D[JC] var shadowOffsetY: Double
CanvasRenderingContext2D[JC] def stroke(): Unit
CanvasRenderingContext2D[JC] def stroke(path: Path2D): Unit
CanvasRenderingContext2D[JC] def strokeRect(x: Double, y: Double, w: Double, h: Double): Unit
CanvasRenderingContext2D[JC] var strokeStyle: js.Any
CanvasRenderingContext2D[JC] def strokeText(text: String, x: Double, y: Double, maxWidth: Double?): Unit
Expand Down Expand Up @@ -16627,6 +16631,17 @@ ParentNode[JT] def children: HTMLCollection[Element]
ParentNode[JT] def firstElementChild: Element
ParentNode[JT] def lastElementChild: Element
ParentNode[JT] def replaceChildren(nodes: Node | String*): Unit
Path2D[JC] def addPath(path: Path2D): Unit
Path2D[JC] def arc(x: Double, y: Double, radius: Double, startAngle: Double, endAngle: Double): Unit
Path2D[JC] def arc(x: Double, y: Double, radius: Double, startAngle: Double, endAngle: Double, anticlockwise: Boolean): Unit
Path2D[JC] def arcTo(x1: Double, y1: Double, x2: Double, y2: Double, radius: Double): Unit
Path2D[JC] def bezierCurveTo(cp1x: Double, cp1y: Double, cp2x: Double, cp2y: Double, x: Double, y: Double): Unit
Path2D[JC] def closePath(): Unit
Path2D[JC] def ellipse(x: Double, y: Double, radiusX: Double, radiusY: Double, rotation: Double, startAngle: Double, endAngle: Double, anticlockwise: Boolean?): Unit
Path2D[JC] def lineTo(x: Double, y: Double): Unit
Path2D[JC] def moveTo(x: Double, y: Double): Unit
Path2D[JC] def quadraticCurveTo(cpx: Double, cpy: Double, x: Double, y: Double): Unit
Path2D[JC] def rect(x: Double, y: Double, w: Double, h: Double): Unit
Pbkdf2Params[JT] val hash: HashAlgorithmIdentifier
Pbkdf2Params[JT] val iterations: Double
Pbkdf2Params[JT] val name: String
Expand Down
15 changes: 15 additions & 0 deletions api-reports/2_13.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1089,6 +1089,9 @@ CanvasRenderingContext2D[JC] def createRadialGradient(x0: Double, y0: Double, r0
CanvasRenderingContext2D[JC] def drawImage(image: HTMLElement, offsetX: Double, offsetY: Double, width: Double?, height: Double?, canvasOffsetX: Double?, canvasOffsetY: Double?, canvasImageWidth: Double?, canvasImageHeight: Double?): Unit
CanvasRenderingContext2D[JC] def ellipse(x: Double, y: Double, radiusX: Double, radiusY: Double, rotation: Double, startAngle: Double, endAngle: Double, anticlockwise: Boolean?): Unit
CanvasRenderingContext2D[JC] def fill(): Unit
CanvasRenderingContext2D[JC] def fill(fillRule: String): Unit
CanvasRenderingContext2D[JC] def fill(path: Path2D): Unit
CanvasRenderingContext2D[JC] def fill(path: Path2D, fillRule: String): Unit
CanvasRenderingContext2D[JC] def fillRect(x: Double, y: Double, w: Double, h: Double): Unit
CanvasRenderingContext2D[JC] var fillStyle: js.Any
CanvasRenderingContext2D[JC] def fillText(text: String, x: Double, y: Double, maxWidth: Double?): Unit
Expand Down Expand Up @@ -1122,6 +1125,7 @@ CanvasRenderingContext2D[JC] var shadowColor: String
CanvasRenderingContext2D[JC] var shadowOffsetX: Double
CanvasRenderingContext2D[JC] var shadowOffsetY: Double
CanvasRenderingContext2D[JC] def stroke(): Unit
CanvasRenderingContext2D[JC] def stroke(path: Path2D): Unit
CanvasRenderingContext2D[JC] def strokeRect(x: Double, y: Double, w: Double, h: Double): Unit
CanvasRenderingContext2D[JC] var strokeStyle: js.Any
CanvasRenderingContext2D[JC] def strokeText(text: String, x: Double, y: Double, maxWidth: Double?): Unit
Expand Down Expand Up @@ -16627,6 +16631,17 @@ ParentNode[JT] def children: HTMLCollection[Element]
ParentNode[JT] def firstElementChild: Element
ParentNode[JT] def lastElementChild: Element
ParentNode[JT] def replaceChildren(nodes: Node | String*): Unit
Path2D[JC] def addPath(path: Path2D): Unit
Path2D[JC] def arc(x: Double, y: Double, radius: Double, startAngle: Double, endAngle: Double): Unit
Path2D[JC] def arc(x: Double, y: Double, radius: Double, startAngle: Double, endAngle: Double, anticlockwise: Boolean): Unit
Path2D[JC] def arcTo(x1: Double, y1: Double, x2: Double, y2: Double, radius: Double): Unit
Path2D[JC] def bezierCurveTo(cp1x: Double, cp1y: Double, cp2x: Double, cp2y: Double, x: Double, y: Double): Unit
Path2D[JC] def closePath(): Unit
Path2D[JC] def ellipse(x: Double, y: Double, radiusX: Double, radiusY: Double, rotation: Double, startAngle: Double, endAngle: Double, anticlockwise: Boolean?): Unit
Path2D[JC] def lineTo(x: Double, y: Double): Unit
Path2D[JC] def moveTo(x: Double, y: Double): Unit
Path2D[JC] def quadraticCurveTo(cpx: Double, cpy: Double, x: Double, y: Double): Unit
Path2D[JC] def rect(x: Double, y: Double, w: Double, h: Double): Unit
Pbkdf2Params[JT] val hash: HashAlgorithmIdentifier
Pbkdf2Params[JT] val iterations: Double
Pbkdf2Params[JT] val name: String
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,12 @@ class CanvasRenderingContext2D extends js.Object {
/** Fills the subpaths with the current fill style. */
def fill(): Unit = js.native

def fill(path: Path2D): Unit = js.native

def fill(fillRule: String): Unit = js.native
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, this is neat!


def fill(path: Path2D, fillRule: String): Unit = js.native

/** Creates a new, blank ImageData object with the specified dimensions. All of the pixels in the new object are
* transparent black.
*/
Expand Down Expand Up @@ -172,6 +178,8 @@ class CanvasRenderingContext2D extends js.Object {
/** Strokes the subpaths with the current stroke style. */
def stroke(): Unit = js.native

def stroke(path: Path2D): Unit = js.native

/** Paints a rectangle which has a starting point at (x, y) and has a w width and an h height onto the canvas, using
* the current stroke style.
*/
Expand Down
34 changes: 34 additions & 0 deletions dom/src/main/scala/org/scalajs/dom/Path2D.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package org.scalajs.dom

import scala.scalajs.js
import scala.scalajs.js.annotation.JSGlobal

@js.native
@JSGlobal
class Path2D extends js.Object {
Comment on lines +10 to +12
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The [[Path2D]] interface of the Canvas 2D API is used to declare a path that can then be used on a [[CanvasRenderingContext2D]] object.


def addPath(path: Path2D): Unit = js.native

def closePath(): Unit = js.native

def moveTo(x: Double, y: Double): Unit = js.native

def lineTo(x: Double, y: Double): Unit = js.native

def bezierCurveTo(cp1x: Double, cp1y: Double, cp2x: Double, cp2y: Double, x: Double, y: Double): Unit = js.native

def quadraticCurveTo(cpx: Double, cpy: Double, x: Double, y: Double): Unit = js.native

def arcTo(x1: Double, y1: Double, x2: Double, y2: Double, radius: Double): Unit = js.native

def arc(x: Double, y: Double, radius: Double, startAngle: Double, endAngle: Double,
anticlockwise: Boolean): Unit = js.native
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
def arc(x: Double, y: Double, radius: Double, startAngle: Double, endAngle: Double,
anticlockwise: Boolean): Unit = js.native
def arc(x: Double, y: Double, radius: Double, startAngle: Double, endAngle: Double,
counterclockwise: Boolean): Unit = js.native


def arc(x: Double, y: Double, radius: Double, startAngle: Double, endAngle: Double): Unit = js.native

def ellipse(x: Double, y: Double, radiusX: Double, radiusY: Double, rotation: Double, startAngle: Double,
endAngle: Double, anticlockwise: Boolean = js.native): Unit = js.native
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems to be called counterclockwise in the spec.

Suggested change
endAngle: Double, anticlockwise: Boolean = js.native): Unit = js.native
endAngle: Double, counterclockwise: Boolean = js.native): Unit = js.native


def rect(x: Double, y: Double, w: Double, h: Double): Unit = js.native

}