Thanks to visit codestin.com
Credit goes to github.com

Skip to content
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
Prev Previous commit
Next Next commit
add CanvasFillRule enum
  • Loading branch information
buntec committed Mar 29, 2023
commit 17abf368db22e67a6d0af2700b43a7596475b7ec
14 changes: 14 additions & 0 deletions dom/src/main/scala-2/org/scalajs/dom/CanvasFillRule.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package org.scalajs.dom

import scala.scalajs.js

@js.native
sealed trait CanvasFillRule extends js.Any

object CanvasFillRule {

val nonzero: CanvasFillRule = "nonzero".asInstanceOf[CanvasFillRule]

val evenodd: CanvasFillRule = "evenodd".asInstanceOf[CanvasFillRule]

}
13 changes: 13 additions & 0 deletions dom/src/main/scala-3/org/scalajs/dom/CanvasFillRule.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package org.scalajs.dom

import scala.scalajs.js

opaque type CanvasFillRule <: String = String

object CanvasFillRule {

val nonzero: CanvasFillRule = "nonzero"

val evenodd: CanvasFillRule = "evenodd"

}
41 changes: 27 additions & 14 deletions dom/src/main/scala/org/scalajs/dom/CanvasRenderingContext2D.scala
Original file line number Diff line number Diff line change
Expand Up @@ -86,25 +86,28 @@ class CanvasRenderingContext2D extends js.Object {
*/
def save(): Unit = js.native

/** Adds an arc to the path which is centered at (x, y) position with radius r starting at startAngle and ending at
* endAngle going in the given direction by anticlockwise (defaulting to clockwise).
/** The arc() method creates a circular arc centered at (x, y) with a radius of radius. The path starts at startAngle,
* ends at endAngle, and travels in the direction given by counterclockwise (defaulting to clockwise).
*/
def arc(x: Double, y: Double, radius: Double, startAngle: Double, endAngle: Double,
anticlockwise: Boolean): Unit = js.native
counterclockwise: Boolean): Unit = js.native

/** Adds an arc to the path which is centered at (x, y) position with radius r starting at startAngle and ending at
* endAngle going in the given direction by anticlockwise (defaulting to clockwise).
/** The arc() method creates a circular arc centered at (x, y) with a radius of radius. The path starts at startAngle,
* ends at endAngle, and travels in the direction given by counterclockwise (defaulting to clockwise).
*/
def arc(x: Double, y: Double, radius: Double, startAngle: Double, endAngle: Double): Unit = js.native

/** Returns a TextMetrics object. */
def measureText(text: String): TextMetrics = js.native

/** Reports whether or not the specified point is contained in the current path. */
def isPointInPath(x: Double, y: Double, fillRule: String): Boolean = js.native
def isPointInPath(x: Double, y: Double, fillRule: CanvasFillRule = js.native): Boolean = js.native

/** Reports whether or not the specified point is contained in the current path. */
def isPointInPath(x: Double, y: Double): Boolean = js.native
def isPointInPath(path: Path2D, x: Double, y: Double): Boolean = js.native

/** Reports whether or not the specified point is contained in the current path. */
def isPointInPath(path: Path2D, x: Double, y: Double, fillRule: CanvasFillRule): Boolean = js.native

/** Adds a quadratic Bézier curve to the current path. */
def quadraticCurveTo(cpx: Double, cpy: Double, x: Double, y: Double): Unit = js.native
Expand Down Expand Up @@ -140,13 +143,13 @@ class CanvasRenderingContext2D extends js.Object {
def getLineDash(): js.Array[Double] = js.native

/** Fills the subpaths with the current fill style. */
def fill(): Unit = js.native
def fill(fillRule: CanvasFillRule = js.native): Unit = js.native

/** Fills the subpaths with the current fill style. */
def fill(path: Path2D): Unit = js.native

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

def fill(path: Path2D, fillRule: String): Unit = js.native
/** Fills the subpaths with the current fill style. */
def fill(path: Path2D, fillRule: CanvasFillRule): 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 All @@ -169,7 +172,17 @@ class CanvasRenderingContext2D extends js.Object {
/** Creates a clipping path from the current sub-paths. Everything drawn after clip() is called appears inside the
* clipping path only. For an example, see Clipping paths in the Canvas tutorial.
*/
def clip(fillRule: String = js.native): Unit = js.native
def clip(fillRule: CanvasFillRule = js.native): Unit = js.native

/** Creates a clipping path from the current sub-paths. Everything drawn after clip() is called appears inside the
* clipping path only. For an example, see Clipping paths in the Canvas tutorial.
*/
def clip(path: Path2D): Unit = js.native

/** Creates a clipping path from the current sub-paths. Everything drawn after clip() is called appears inside the
* clipping path only. For an example, see Clipping paths in the Canvas tutorial.
*/
def clip(path: Path2D, fillRule: CanvasFillRule): Unit = js.native

/** Sets all pixels in the rectangle defined by starting point (x, y) and size (width, height) to transparent black.
*/
Expand Down Expand Up @@ -225,9 +238,9 @@ class CanvasRenderingContext2D extends js.Object {
def createLinearGradient(x0: Double, y0: Double, x1: Double, y1: Double): CanvasGradient = js.native

/** The ellipse() method creates an elliptical arc centered at (x, y) with the radii radiusX and radiusY. The path
* starts at startAngle and ends at endAngle, and travels in the direction given by anticlockwise (defaulting to
* starts at startAngle and ends at endAngle, and travels in the direction given by counterclockwise (defaulting to
* clockwise).
*/
def ellipse(x: Double, y: Double, radiusX: Double, radiusY: Double, rotation: Double, startAngle: Double,
endAngle: Double, anticlockwise: Boolean = js.native): Unit = js.native
endAngle: Double, counterclockwise: Boolean = js.native): Unit = js.native
}
19 changes: 13 additions & 6 deletions dom/src/main/scala/org/scalajs/dom/Path2D.scala
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@ package org.scalajs.dom
import scala.scalajs.js
import scala.scalajs.js.annotation.JSGlobal

/** The [[Path2D]] interface of the Canvas 2D API is used to declare a path that can then be used on a
* [[CanvasRenderingContext2D]] object. The path methods of the [[CanvasRenderingContext2D]] interface are also present
* on this interface, which gives you the convenience of being able to retain and replay your path whenever desired.
*/
@js.native
@JSGlobal
class Path2D extends js.Object {
Expand Down Expand Up @@ -36,20 +40,23 @@ class Path2D extends js.Object {
*/
def arcTo(x1: Double, y1: Double, x2: Double, y2: Double, radius: Double): Unit = js.native

/** Adds an arc to the path which is centered at (x, y) position with radius r starting at startAngle and ending at
* endAngle going in the given direction by counterclockwise (defaulting to clockwise).
/** The arc() method creates a circular arc centered at (x, y) with a radius of radius. The path starts at startAngle,
* ends at endAngle, and travels in the direction given by counterclockwise (defaulting to clockwise).
*/
def arc(x: Double, y: Double, radius: Double, startAngle: Double, endAngle: Double,
anticlockwise: Boolean): Unit = js.native
counterclockwise: Boolean): Unit = js.native

/** The arc() method creates a circular arc centered at (x, y) with a radius of radius. The path starts at startAngle,
* ends at endAngle, and travels in the direction given by counterclockwise (defaulting to clockwise).
*/
def arc(x: Double, y: Double, radius: Double, startAngle: Double, endAngle: Double): Unit = js.native

/** Adds an elliptical arc to the path which is centered at (x, y) position with the radii radiusX and radiusY
* starting at startAngle and ending at endAngle going in the given direction by counterclockwise (defaulting to
/** The ellipse() method creates an elliptical arc centered at (x, y) with the radii radiusX and radiusY. The path
* starts at startAngle and ends at endAngle, and travels in the direction given by counterclockwise (defaulting to
* clockwise).
*/
def ellipse(x: Double, y: Double, radiusX: Double, radiusY: Double, rotation: Double, startAngle: Double,
endAngle: Double, anticlockwise: Boolean = js.native): Unit = js.native
endAngle: Double, counterclockwise: Boolean = js.native): Unit = js.native

/** Creates a path for a rectangle at position (x, y) with a size that is determined by width and height. */
def rect(x: Double, y: Double, w: Double, h: Double): Unit = js.native
Expand Down