Hi Brian,
I think about coordinate problems in terms of the following:
1. Screen coordinates--I usually think of them in client coordinates. Specifically, the offset to the top left of the injection div. These are in pixels.
2. Workspace coordinates. Where blocks are on the workspace. You can call block.getRelativeToSurfaceXY() to get the position of a block in workspace coordinates.
- Workspace units may be different from pixels if the workspace is scaled
- The workspace coordinate system has an origin that is originally at the top left corner of the workspace. This origin moves relative to the injection div as you scale and scroll the workspace.
3. Workspace offset. The offset from the origin of the workspace to the top left corner of the injection div in pixels.
-
Here's a helper function to get that offset. I'm adding it to Blockly as well, but it isn't in yet.
4. MouseEvent coordinates. I usually use clientX and clientY, which are in pixels.
Hope that helps,
Rachel