Show accurate preview rect near bounds of canvas

main
Isaiah Odhner 2019-10-26 14:50:24 -04:00
parent e6350ff7f7
commit 455051d91c
1 changed files with 10 additions and 3 deletions

View File

@ -344,10 +344,17 @@ tools = [{
var rect_x1 = ~~(x - w/2);
var rect_y1 = ~~(y - h/2);
var rect_x2 = ~~(x + w/2);
var rect_y2 = ~~(y + h/2);
// TODO: clamp rect while maintaining width & height before clamping to squish it
// try to move rect into bounds without squishing
rect_x1 = Math.max(0, rect_x1);
rect_y1 = Math.max(0, rect_y1);
rect_x1 = Math.min(canvas.width - w, rect_x1);
rect_y1 = Math.min(canvas.height - h, rect_y1);
var rect_x2 = rect_x1 + w;
var rect_y2 = rect_y1 + h;
// clamp rect to bounds (with squishing)
rect_x1 = Math.max(0, rect_x1);
rect_y1 = Math.max(0, rect_y1);
rect_x2 = Math.min(canvas.width, rect_x2);