From efe1a823522c64335ba149108083f46d1522b89a Mon Sep 17 00:00:00 2001 From: Devine Lu Linvega Date: Sun, 28 Jul 2019 09:00:09 +0900 Subject: [PATCH] Can import image with $circle shape, fixes #84 --- desktop/sources/scripts/ronin.js | 3 ++- desktop/sources/scripts/surface.js | 14 ++++++++++++-- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/desktop/sources/scripts/ronin.js b/desktop/sources/scripts/ronin.js index 082a88c..446acc3 100644 --- a/desktop/sources/scripts/ronin.js +++ b/desktop/sources/scripts/ronin.js @@ -141,7 +141,8 @@ function Ronin () { const circle = { cx: this.mouseOrigin.x, cy: this.mouseOrigin.y, - r: d + r: d, + edge: { x: rect.x - rect.w, y: rect.y - rect.h, w: rect.w * 2, h: rect.h * 2 } } return { x, y, d, line, rect, pos, circle, type, 'is-down': type !== 'mouse-up' ? true : null } } diff --git a/desktop/sources/scripts/surface.js b/desktop/sources/scripts/surface.js index 661b693..9f19196 100644 --- a/desktop/sources/scripts/surface.js +++ b/desktop/sources/scripts/surface.js @@ -154,6 +154,11 @@ function Surface (ronin) { } else if (isRect(shape)) { const fit = fitRect({ w: img.width, h: img.height }, { w: shape.w, h: shape.h }) this.context.drawImage(img, shape.x, shape.y, fit.w, fit.h) + } else if (isCircle(shape)) { + const side = Math.sqrt(Math.pow(shape.r, 2) / 2) + const rect = { x: shape.cx - (side), y: shape.cy - (side), w: side * 2, h: side * 2 } + const fit = fitRect({ w: img.width, h: img.height }, { w: rect.w, h: rect.h }) + this.context.drawImage(img, rect.x, rect.y, fit.w, fit.h) } else { this.context.drawImage(img, shape.x, shape.y, img.width, img.height) } @@ -182,11 +187,16 @@ function Surface (ronin) { this.stroke(shape.rect || shape, 'black', 4, context) if (shape.pos) { this.stroke(shape.pos, 'black', 4, context) } if (shape.line) { this.stroke(shape.line, 'black', 4, context) } - if (shape.circle) { this.stroke(shape.circle, 'black', 4, context) } + if (shape.circle) { + this.stroke(shape.circle, 'black', 4, context) + } + this.stroke(shape.rect || shape, color, 1.5, context) if (shape.pos) { this.stroke(shape.pos, color, 1.5, context) } if (shape.line) { this.stroke(shape.line, color, 1.5, context) } - if (shape.circle) { this.stroke(shape.circle, color, 1.5, context) } + if (shape.circle) { + this.stroke(shape.circle, color, 1.5, context) + } } this.clone = function (a, b) {