diff options
Diffstat (limited to 'tools/mq_editor/editor.js')
| -rw-r--r-- | tools/mq_editor/editor.js | 15 |
1 files changed, 13 insertions, 2 deletions
diff --git a/tools/mq_editor/editor.js b/tools/mq_editor/editor.js index 301dcc5..868d3d5 100644 --- a/tools/mq_editor/editor.js +++ b/tools/mq_editor/editor.js @@ -23,7 +23,8 @@ class PartialEditor { // Private state this._selectedIndex = -1; - this._dragPointIndex = -1; + this._dragPointIndex = -1; + this._dragCompanionOff = null; // {dt, dv} offset of companion handle relative to anchor this._amp = { tMin: 0, tMax: 1, ampTop: 1 }; this._setupButtons(); @@ -489,7 +490,12 @@ class PartialEditor { const curve = partial.ampCurve; for (let i = 0; i < 4; ++i) { if (Math.hypot(this._tToX(curve['t' + i]) - x, this._ampToY(curve['v' + i]) - y) <= 8) { - this._dragPointIndex = i; + this._dragPointIndex = i; + this._dragCompanionOff = null; + if (i === 0) + this._dragCompanionOff = { dt: curve.t1 - curve.t0, dv: curve.v1 - curve.v0 }; + else if (i === 3) + this._dragCompanionOff = { dt: curve.t2 - curve.t3, dv: curve.v2 - curve.v3 }; canvas.style.cursor = 'grabbing'; e.preventDefault(); return; @@ -505,6 +511,11 @@ class PartialEditor { const i = this._dragPointIndex; curve['t' + i] = Math.max(0, Math.min(this.viewer ? this.viewer.t_max : 1e6, this._xToT(x))); curve['v' + i] = Math.max(0, this._yToAmp(y)); + if (this._dragCompanionOff) { + const off = this._dragCompanionOff; + if (i === 0) { curve.t1 = curve.t0 + off.dt; curve.v1 = curve.v0 + off.dv; } + else { curve.t2 = curve.t3 + off.dt; curve.v2 = curve.v3 + off.dv; } + } this._renderAmpEditor(); if (this.viewer) this.viewer.render(); e.preventDefault(); |
