From b40b950ea05f7abd97930c6928095a361ed3ca41 Mon Sep 17 00:00:00 2001 From: Craig Gidney Date: Fri, 8 Jun 2018 12:55:28 -0300 Subject: [PATCH] Visual and init-click bug fixes - Fix YDetectControlReset drawing wrong control bulb - Fix wire initial states highlighting and toggling when dragging gates near them and releasing --- src/gates/Detector.js | 2 +- src/ui/DisplayedCircuit.js | 9 ++++----- src/ui/DisplayedInspector.js | 11 +++++++++-- 3 files changed, 14 insertions(+), 8 deletions(-) diff --git a/src/gates/Detector.js b/src/gates/Detector.js index 3d9a91fb..e28b973d 100644 --- a/src/gates/Detector.js +++ b/src/gates/Detector.js @@ -258,7 +258,7 @@ function drawControlBulb(args, axis) { args.painter.strokeCircle(p, 5); let r = 5*Math.sqrt(0.5)*1.1; args.painter.strokeLine(p.offsetBy(+r, -r), p.offsetBy(-r, +r)); - args.painter.strokeLine(p.offsetBy(-r, +r), p.offsetBy(+r, -r)); + args.painter.strokeLine(p.offsetBy(-r, -r), p.offsetBy(+r, +r)); break; case 'Z': args.painter.fillCircle(p, 5, "black"); diff --git a/src/ui/DisplayedCircuit.js b/src/ui/DisplayedCircuit.js index b4894b08..f640b263 100644 --- a/src/ui/DisplayedCircuit.js +++ b/src/ui/DisplayedCircuit.js @@ -374,7 +374,7 @@ class DisplayedCircuit { } let rect = this._wireInitialStateClickableRect(row); painter.noteTouchBlocker({rect, cursor: 'pointer'}); - if (hand.pos !== undefined && rect.containsPoint(hand.pos)) { + if (this._highlightedSlot === undefined && hand.pos !== undefined && rect.containsPoint(hand.pos)) { painter.fillRect(rect, Config.HIGHLIGHTED_GATE_FILL_COLOR); } painter.print(`|${v}⟩`, 20, y, 'right', 'middle', 'black', '14px sans-serif', 20, Config.WIRE_SPACING); @@ -948,9 +948,8 @@ class DisplayedCircuit { /** * @param {!Point} pt * @returns {undefined|!int} - * @private */ - _findWireWithInitialStateAreaContaining(pt) { + findWireWithInitialStateAreaContaining(pt) { // Is it in the right vertical band; the one at the start of the circuit? if (pt.x < 0 || pt.x > 30) { return undefined; @@ -977,11 +976,11 @@ class DisplayedCircuit { * @returns {undefined|!DisplayedCircuit} */ tryClick(hand) { - if (hand.pos === undefined) { + if (hand.pos === undefined || hand.heldGate !== undefined) { return undefined; } - let clickedInitialStateWire = this._findWireWithInitialStateAreaContaining(hand.pos); + let clickedInitialStateWire = this.findWireWithInitialStateAreaContaining(hand.pos); if (clickedInitialStateWire !== undefined) { return this.withCircuit(this.circuitDefinition.withSwitchedInitialStateOn(clickedInitialStateWire)) } diff --git a/src/ui/DisplayedInspector.js b/src/ui/DisplayedInspector.js index 9c7b2e5c..c244ed9d 100644 --- a/src/ui/DisplayedInspector.js +++ b/src/ui/DisplayedInspector.js @@ -131,8 +131,15 @@ class DisplayedInspector { if (this.hand.pos === undefined) { return undefined; } - let pos = this.displayedCircuit.findGateWithButtonContaining(this.hand.pos); - return pos === undefined ? undefined : pos.col + ':' + pos.row; + let butBos = this.displayedCircuit.findGateWithButtonContaining(this.hand.pos); + if (butBos !== undefined) { + return `gate-button-${butBos.col}:${butBos.row}`; + } + let initPos = this.displayedCircuit.findWireWithInitialStateAreaContaining(this.hand.pos); + if (initPos !== undefined) { + return `wire-init-${initPos}`; + } + return undefined; } /**