English is not my strong suit, so please bear with me.
Let me outline the issue I'm currently grappling with.
I'm in the process of developing a function that allows users to draw a rectangle on a canvas using their mouse (specifically, using the strokeRect
function).
Everything works smoothly under normal circumstances. However, when the rotation button is clicked, an issue arises wherein the rectangle is not drawn at the mouse coordinates as expected.
To provide context, clicking the rotate button triggers a CSS rotation using transform = 'rotate(90deg)'
, and retrieves the canvas size within the calcCanvasRect
function utilizing the getBoundingClientRect
function.
I'm seeking advice on how to tackle this challenge. Help!
Here's the basic structure for reference:
<div class="myContainer">
<div class="rotation-wrapper">
<div id="canvasParent">
<canvas id="view_canvas"></canvas>
</div>
</div>
</div>
The complete source code is provided below:
// JavaScript functions and code snippets are available here...
I have experimented with the canvas translate and rotate features but haven't found a satisfactory solution yet. Is there a more efficient approach?
Could there be some aspect or technique that I am overlooking?