Skip to content

Commit

Permalink
Visual and init-click bug fixes
Browse files Browse the repository at this point in the history
- Fix YDetectControlReset drawing wrong control bulb
- Fix wire initial states highlighting and toggling when dragging gates near them and releasing
  • Loading branch information
Strilanc committed Jun 8, 2018
1 parent 57ce05d commit b40b950
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 8 deletions.
2 changes: 1 addition & 1 deletion src/gates/Detector.js
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down
9 changes: 4 additions & 5 deletions src/ui/DisplayedCircuit.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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;
Expand All @@ -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))
}
Expand Down
11 changes: 9 additions & 2 deletions src/ui/DisplayedInspector.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

/**
Expand Down

0 comments on commit b40b950

Please sign in to comment.