Skip to content

Commit

Permalink
All hints hide when circuit contains any gates
Browse files Browse the repository at this point in the history
  • Loading branch information
Strilanc committed Sep 9, 2019
1 parent 4f54538 commit 7f461a9
Showing 1 changed file with 13 additions and 61 deletions.
74 changes: 13 additions & 61 deletions src/ui/DisplayedInspector.js
Original file line number Diff line number Diff line change
Expand Up @@ -321,33 +321,12 @@ class DisplayedInspector {
this._drawHint_useControls(painter);
}

/**
* @returns {!number}
* @private
*/
_watchOutputsChangeVisibility() {
if (this.displayedCircuit.circuitDefinition.customInitialValues.size > 0) {
return 0;
}

let gatesInCircuit = this.displayedCircuit.circuitDefinition.countGatesUpTo(2);
let gatesInPlay = gatesInCircuit + (this.hand.isBusy() ? 1 : 0);
if (gatesInCircuit >= 2 || gatesInPlay === 0) {
return 0;
}

let handPosY = this.hand.pos === undefined ? Infinity : this.hand.pos.y;
return gatesInCircuit === 0 ? (handPosY - 125)/25 :
gatesInPlay === 2 ? (150 - handPosY)/25 :
1.0;
}

/**
* @param {!Painter} painter
* @private
*/
_drawHint_watchOutputsChange(painter) {
let visibilityFactor = this._watchOutputsChangeVisibility();
let visibilityFactor = this._hintVisibility();
if (visibilityFactor <= 0) {
return;
}
Expand Down Expand Up @@ -382,20 +361,22 @@ class DisplayedInspector {
painter.ctx.restore();
}

_hintVisibility() {
if (this.displayedCircuit.circuitDefinition.columns.length > 0) {
return 0;
}
return this.hand.pos === undefined || !this.hand.isBusy() ? 1.0 :
this.hand.heldGate !== undefined && this.hand.heldGate.isControl() ? 1.0 :
(150-this.hand.pos.y)/50;
}


/**
* @param {!Painter} painter
* @private
*/
_drawHint_dragGatesOntoCircuit(painter) {
if (this.displayedCircuit.circuitDefinition.hasNonControlGates()) {
return;
}

let visibilityFactor =
this.hand.pos === undefined || !this.hand.isBusy() ? 1.0 :
this.hand.heldGate !== undefined && this.hand.heldGate.isControl() ? 1.0 :
(150-this.hand.pos.y)/50;
let visibilityFactor = this._hintVisibility();
if (visibilityFactor <= 0) {
return;
}
Expand All @@ -404,7 +385,7 @@ class DisplayedInspector {
painter.ctx.globalAlpha *= Math.min(1, visibilityFactor);

painter.ctx.save();
painter.ctx.translate(70, 190);
painter.ctx.translate(130, 195);
painter.ctx.rotate(Math.PI * 0.05);
painter.ctx.fillStyle = 'red';
painter.ctx.font = '16px sans-serif';
Expand All @@ -428,41 +409,12 @@ class DisplayedInspector {
painter.ctx.restore();
}

/**
* @returns {!number}
* @private
*/
_useControlsHintVisibility() {
let circ = this.displayedCircuit.circuitDefinition;
let gatesInCircuit = circ.countGatesUpTo(2);
let gatesInPlay = gatesInCircuit + (this.hand.heldGate !== undefined ? 1 : 0);

if (circ.customInitialValues.size > 0) {
return 0;
}

let gate = circ.gateInSlot(0, 0);
if (circ.hasControls() || !circ.hasNonControlGates() || (gate !== undefined && gate.height > 1)) {
return 0;
}

if (gatesInCircuit === 1 && gatesInPlay === 1 && !this.displayedCircuit.isBeingEdited()) {
return 1;
}

if (gatesInCircuit === 1 && gatesInPlay === 2 && this.displayedCircuit.isBeingEdited()) {
return (150-this.hand.pos.y)/50;
}

return 0;
}

/**
* @param {!Painter} painter
* @private
*/
_drawHint_useControls(painter) {
let visibilityFactor = this._useControlsHintVisibility();
let visibilityFactor = this._hintVisibility();
if (visibilityFactor <= 0) {
return;
}
Expand Down

0 comments on commit 7f461a9

Please sign in to comment.