Fixed issue with mouse click erasing main canvas
This commit is contained in:
parent
51c40b822f
commit
e3f1e72e96
@ -105,37 +105,43 @@ function Commander (ronin) {
|
|||||||
|
|
||||||
this.onMouseDown = (e) => {
|
this.onMouseDown = (e) => {
|
||||||
this.mouseDown = true
|
this.mouseDown = true
|
||||||
this.mouseRect.x = e.offsetX
|
const offset = this.makeMouseOffset({ x: e.offsetX, y: e.offsetY })
|
||||||
this.mouseRect.y = e.offsetY
|
this.mouseRect.x = offset.x
|
||||||
this.mouseRect.a.x = e.offsetX
|
this.mouseRect.y = offset.y
|
||||||
this.mouseRect.a.y = e.offsetY
|
this.mouseRect.a.x = offset.x
|
||||||
|
this.mouseRect.a.y = offset.y
|
||||||
this.mouseRect.t = 'pos'
|
this.mouseRect.t = 'pos'
|
||||||
this.capture()
|
this.capture()
|
||||||
this.show()
|
this.show()
|
||||||
}
|
}
|
||||||
|
|
||||||
this.onMouseMove = (e) => {
|
this.onMouseMove = (e) => {
|
||||||
if (this.mouseDown === true) {
|
if (this.mouseDown !== true) { return }
|
||||||
this.mouseRect.w = e.offsetX - this.mouseRect.x
|
const offset = this.makeMouseOffset({ x: e.offsetX, y: e.offsetY })
|
||||||
this.mouseRect.h = e.offsetY - this.mouseRect.y
|
this.mouseRect.w = offset.x - this.mouseRect.x
|
||||||
this.mouseRect.b.x = e.offsetX
|
this.mouseRect.h = offset.y - this.mouseRect.y
|
||||||
this.mouseRect.b.y = e.offsetY
|
this.mouseRect.b.x = offset.x
|
||||||
this.commit()
|
this.mouseRect.b.y = offset.y
|
||||||
}
|
this.commit()
|
||||||
}
|
}
|
||||||
|
|
||||||
this.onMouseUp = (e) => {
|
this.onMouseUp = (e) => {
|
||||||
this.mouseDown = false
|
this.mouseDown = false
|
||||||
this.mouseRect.w = e.offsetX - this.mouseRect.x
|
const offset = this.makeMouseOffset({ x: e.offsetX, y: e.offsetY })
|
||||||
this.mouseRect.h = e.offsetY - this.mouseRect.y
|
this.mouseRect.w = offset.x - this.mouseRect.x
|
||||||
this.mouseRect.b.x = e.offsetX
|
this.mouseRect.h = offset.y - this.mouseRect.y
|
||||||
this.mouseRect.b.y = e.offsetY
|
this.mouseRect.b.x = offset.x
|
||||||
|
this.mouseRect.b.y = offset.y
|
||||||
this.mouseRect.t = ''
|
this.mouseRect.t = ''
|
||||||
this.commit()
|
this.commit()
|
||||||
this._input.focus()
|
this._input.focus()
|
||||||
ronin.surface.clearGuide()
|
ronin.surface.clearGuide()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
this.makeMouseOffset = (pos) => {
|
||||||
|
return { x: pos.x * ronin.surface.ratio, y: pos.y * ronin.surface.ratio }
|
||||||
|
}
|
||||||
|
|
||||||
// Injection
|
// Injection
|
||||||
|
|
||||||
this.cache = ''
|
this.cache = ''
|
||||||
|
@ -6,7 +6,7 @@ function Surface (ronin) {
|
|||||||
this.ratio = window.devicePixelRatio
|
this.ratio = window.devicePixelRatio
|
||||||
// Contexts
|
// Contexts
|
||||||
this.context = this.el.getContext('2d')
|
this.context = this.el.getContext('2d')
|
||||||
this.guide = this.el.getContext('2d')
|
this.guide = this._guide.getContext('2d')
|
||||||
|
|
||||||
this.install = function (host) {
|
this.install = function (host) {
|
||||||
host.appendChild(this.el)
|
host.appendChild(this.el)
|
||||||
@ -15,9 +15,6 @@ function Surface (ronin) {
|
|||||||
this._guide.addEventListener('mousedown', ronin.commander.onMouseDown, false)
|
this._guide.addEventListener('mousedown', ronin.commander.onMouseDown, false)
|
||||||
this._guide.addEventListener('mousemove', ronin.commander.onMouseMove, false)
|
this._guide.addEventListener('mousemove', ronin.commander.onMouseMove, false)
|
||||||
this._guide.addEventListener('mouseup', ronin.commander.onMouseUp, false)
|
this._guide.addEventListener('mouseup', ronin.commander.onMouseUp, false)
|
||||||
// this.context.imageSmoothingEnabled = false
|
|
||||||
this.context.scale(this.ratio, this.ratio)
|
|
||||||
this.guide.scale(this.ratio, this.ratio)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
this.start = function () {
|
this.start = function () {
|
||||||
@ -151,8 +148,8 @@ function Surface (ronin) {
|
|||||||
context.clearRect(rect.x, rect.y, rect.w, rect.h)
|
context.clearRect(rect.x, rect.y, rect.w, rect.h)
|
||||||
}
|
}
|
||||||
|
|
||||||
this.clearGuide = function () {
|
this.clearGuide = function (rect = this.getFrame(), context = this.guide) {
|
||||||
this.clear(ronin.surface.getFrame(), ronin.surface.guide)
|
context.clearRect(rect.x, rect.y, rect.w, rect.h)
|
||||||
}
|
}
|
||||||
|
|
||||||
this.clone = function (a, b) {
|
this.clone = function (a, b) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user