Can import image with $circle shape, fixes #84

This commit is contained in:
Devine Lu Linvega 2019-07-28 09:00:09 +09:00
parent 9f15dae5b2
commit efe1a82352
2 changed files with 14 additions and 3 deletions

View File

@ -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 }
}

View File

@ -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) {