[whatwg] Fwd: windowToCanvas()

David Geary david.mark.geary at gmail.com
Wed Aug 31 10:55:30 PDT 2011


Forgive me if this shows up twice on the list. I’m new at this, and I
believe I sent the original to the wrong address.

---------- Forwarded message ----------
From: David Geary <david.mark.geary at gmail.com>
Date: Wed, Aug 31, 2011 at 11:52 AM
Subject: windowToCanvas()
To: whatwg at whatwg.org

In a previous email titled ‘Should Paths be First Class Citizens’, I briefly
discussed this code snippet:

context.canvas.onmousedown = function (e) {
   var loc = windowToCanvas(context.canvas, e);

   polygons.forEach( function (polygon) {  // polygons is an array of
polygon objects
      polygon.createPath();  // my polygons have a createPath() method

      if (context.isPointInPath(loc.x, loc.y)) {
         alert('mouse clicked in polygon');
      }
   });
}

I implemented the windowToCanvas() myself. That methods’s not too difficult
to implement after you know how to do it properly, but it’s not very
straightforward to implement if you are new to web development.

Would it make sense to add such a method to the Canvas specification?


David
Author of Core HTML5 Canvas (corehtml5canvas.com)



More information about the whatwg mailing list