var x=document.getElementById("canvas"); var ctx=x.getContext("2d"); var path1 = new Path2D(); path1.rect(20,20,150,100); // add rect to path object ctx.stroke(path1); x.addEventListener("click", function(e) { var r = this.getBoundingClientRect(), x = e.clientX - r.left, y = e.clientY - r.top; // normally you would loop through your paths objects: if (ctx.isPointInPath(path1, x, y)) alert("Hit!"); })
public final PathPartList close() { m_fin = true; m_mov = false; if (null != m_p2d) { m_p2d.setClosed(true); } return this; }
if (Path2D.isSupported()) partlist.setPath2D(new Path2D(path));
public void clip(final Path2D path) { m_jso.clip(path.getNativePath2D()); }
if (path.isClosed())
if (Path2D.isSupported()) partlist.setPath2D(new Path2D(path));
public void fill(final Path2D path) { m_jso.fill(path.getNativePath2D()); }
if (path.isClosed())
function draw() { ctx.save(); // save the state circle = new Path2D(); circle.arc(currX,currY,16,0,2*Math.PI); ctx.clip(circle); ctx.clearRect(0, 0, w, h); ctx.restore(); // restore the state }
if (Path2D.isSupported()) partlist.setPath2D(new Path2D(path));
public void fill(final Path2D path) { m_jso.fill(path.getNativePath2D()); }
public final PathPartList close() { m_fin = true; m_mov = false; if (null != m_p2d) { m_p2d.setClosed(true); } return this; }
if (path.isClosed())
var p = new Path2D(); p.moveTo(10, 10); p.lineTo(100,50); p.lineTo(100, 100); p.lineTo(200, 150); p.lineTo(10, 150); p.closePath();
public Path2D(final Path2D path) { this(NativePath2D.make(Objects.requireNonNull(path).getNativePath2D())); }
public final PathPartList close() { m_fin = true; m_mov = false; if (null != m_p2d) { m_p2d.setClosed(true); } return this; }
var path1 = new Path2D(); path1.rect(x1, y1, w, h); // add sub-path to Path2D object var path2 = new Path2D(); path2.rect(x2, y2, w, h); // add sub-path to Path2D object // now we can iterate through the objects to check which path we // clicked without the need to rebuild each path as we did in the past if (ctx.isPointInPath(path1, x, y)) { ... }
public void stroke(final Path2D path) { m_jso.stroke(path.getNativePath2D()); }
public Path2D closePath() { if (null != m_path) { m_path.closePath(); } return setClosed(true); }
var path = new Path2D(); ... path.moveTo(.. , ..); path.lineTo(.. , ..); etc.