W3C home > Mailing lists > Public > whatwg@whatwg.org > August 2011

[whatwg] windowToCanvas()

From: Tab Atkins Jr. <jackalmage@gmail.com>
Date: Wed, 31 Aug 2011 14:12:00 -0700
Message-ID: <CAAWBYDDZo2J6Z+Q_5cSbvy1PcX4wWb0iRexgKJcws5j7vizLxw@mail.gmail.com>
On Wed, Aug 31, 2011 at 10:52 AM, David Geary
<david.mark.geary at gmail.com> wrote:
> 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?

I assume this just translates window-relative coordinates to
element-relative coordinates.  Yes, that sort of thing is useful, but
it's nothing to do with canvas specifically - it would be useful for
every element if it were easier to do that sort of thing.

~TJ
Received on Wednesday, 31 August 2011 14:12:00 UTC

This archive was generated by hypermail 2.4.0 : Wednesday, 22 January 2020 16:59:35 UTC