These forums are currently read-only due to receiving more spam than actual discussion. Sorry.

It is currently Sat Dec 02, 2017 4:16 pm Advanced search

<canvas> element "selection buffer"

Do you think the HTML spec should do something differently? You can discuss spec feedback here, but you should send it to the WHATWG mailing list or file a bug in the W3C bugzilla for it to be considered.

<canvas> element "selection buffer"

Postby pekarna » Wed Jun 11, 2008 11:51 am

I've been looking for something similar to OpenGL's selection buffer - that is, you can get some object ID for the given coordinates.

E.g., Jacob Seidelin's chess game http://blog.nihilogic.dk/search/label/chess could use it, but instead, keyboard control had to be used.

isPointInPath() does not solve the problem effectively if the path would be too complex - e.g. pixel-based sprites in several layers.

For an example of graphics too complex for creating paths, see e.g.
http://www.openttd.org/screens.php?imag ... 3_aug_1984 .
Mathematical computation of the object is principially impossible (or too complex in best case).


So, my suggestion is to add functionality similar to OpenGL's selection buffer:
The canvas element would keep a 2D array with an integer ID for each pixel actually drawn on the screen (thus, we are talking about real pixels). When turned on, these values would be set by every operation that changes the pixel, seting it to the current context's value. Pseudo-code example:

Code: Select all
function DrawCell( iCellId ){

  canvas.selectionBuffer.trackChanges( ON );
  canvas.selectionBuffer.setFillValue( iCellId );

  canvas.drawRasterImage( ..., cellImage );

  canvas.selectionBuffer.trackChanges( OFF );

}


Then, upon user's mouse click on the canvas, you could determine which object was clicked:

Code: Select all
canvas.onclick = function( e ){
  id = canvas.selectionBuffer.getIdAt( e.x, e.y );
  // eventually:
  id = e.selectionBufferID;
}


Such feature would allow interactive application with isometric or 3D graphic.
Is something like this planned or already suggested? I haven't found.

Regards,
Ondra Zizka
pekarna
<h6>
 
Posts: 1
Joined: Wed Jun 11, 2008 11:40 am

Postby zcorpan » Wed May 27, 2009 5:52 pm

You can use SVG instead of canvas if you want to easily determine which object was clicked.
zcorpan
<article>
 
Posts: 807
Joined: Tue Feb 06, 2007 8:29 pm
Location: Sweden


Return to Feedback on the Specs

Who is online

Users browsing this forum: No registered users and 0 guests