text: import { __extends } from "tslib";
  import { Vector3, Matrix } from "@babylonjs/core/Maths/math.vector";
  import { Tools } from "@babylonjs/core/Misc/tools";
  import { Control } from "./control";
  import { ValueAndUnit } from "../valueAndUnit";
  import { _TypeStore } from '@babylonjs/core/Misc/typeStore';
  /** Class used to render 2D lines */
  var Line = /** @class */ (function (_super) {
      __extends(Line, _super);
      /**
       * Creates a new Line
       * @param name defines the control name
       */
      function Line(name) {
          var _this = _super.call(this, name) || this;
          _this.name = name;
          _this._lineWidth = 1;
          _this._x1 = new ValueAndUnit(0);
          _this._y1 = new ValueAndUnit(0);
          _this._x2 = new ValueAndUnit(0);
          _this._y2 = new ValueAndUnit(0);
          _this._dash = new Array();
          _this._automaticSize = true;
          _this.isHitTestVisible = false;
          _this._horizontalAlignment = Control.HORIZONTAL_ALIGNMENT_LEFT;
          _this._verticalAlignment = Control.VERTICAL_ALIGNMENT_TOP;
          return _this;
      }
      Object.defineProperty(Line.prototype, "dash", {
          /** Gets or sets the dash pattern */
          get: function () {
              return this._dash;
          },
          set: function (value) {
              if (this._dash === value) {
                  return;
              }
              this._dash = value;
              this._markAsDirty();
          },
          enumerable: false,
          configurable: true
      });
      Object.defineProperty(Line.prototype, "connectedControl", {
          /** Gets or sets the control connected with the line end */
          get: function () {
              return this._connectedControl;
          },
          set: function (value) {
              var _this = this;
              if (this._connectedControl === value) {
                  return;
              }
              if (this._connectedControlDirtyObserver && this._connectedControl) {
                  this._connectedControl.onDirtyObservable.remove(this._connectedControlDirtyObserver);
                  this._connectedControlDirtyObserver = null;
              }
              if (value) {
                  this._connectedControlDirtyObserver = value.onDirtyObservable.add(function () { return _this._markAsDirty(); });
              }
              this._connectedControl = value;
              this._markAsDirty();
          },
          enumerable: false,
          configurable: true
      });
      Object.defineProperty(Line.prototype, "x1", {
          /** Gets or sets start coordinates on X axis */
          get: function () {
              return this._x1.toString(this._host);
          },
          set: function (value) {
              if (this._x1.toString(this._host) === value) {
                  return;
              }
              if (this._x1.fromString(value)) {
                  this._markAsDirty();
              }
          },
          enumerable: false,
          configurable: true
      });
      Object.defineProperty(Line.prototype, "y1", {
          /** Gets or sets start coordinates on Y axis */
          get: function () {
              return this._y1.toString(this._host);
          },
          set: function (value) {
              if (this._y1.toString(this._host) === value) {
                  return;
              }
              if (this._y1.fromString(value)) {
                  this._markAsDirty();
              }
          },
          enumerable: false,
          configurable: true
      });
      Object.defineProperty(Line.prototype, "x2", {
          /** Gets or sets end coordinates on X axis */
          get: function () {
              return this._x2.toString(this._host);
          },
          set: function (value) {
              if (this._x2.toString(this._host) === value) {
                  return;
              }
              if (this._x2.fromString(value)) {
                  this._markAsDirty();
              }
          },
          enumerable: false,
          configurable: true
      });
      Object.defineProperty(Line.prototype, "y2", {
          /** Gets or sets end coordinates on Y axis */
          get: function () {
              return this._y2.toString(this._host);
          },
          set: function (value) {
              if (this._y2.toString(this._host) === value) {
                  return;
              }
              if (this._y2.fromString(value)) {
                  this._markAsDirty();
              }
          },
          enumerable: false,
          configurable: true
      });
      Object.defineProperty(Line.prototype, "lineWidth", {
          /** Gets or sets line width */
          get: function () {
              return this._lineWidth;
          },
          set: function (value) {
              if (this._lineWidth === value) {
                  return;
              }
              this._lineWidth = value;
              this._markAsDirty();
          },
          enumerable: false,
          configurable: true
      });
      Object.defineProperty(Line.prototype, "horizontalAlignment", {
          /** Gets or sets horizontal alignment */
          set: function (value) {
              return;
          },
          enumerable: false,
          configurable: true
      });
      Object.defineProperty(Line.prototype, "verticalAlignment", {
          /** Gets or sets vertical alignment */
          set: function (value) {
              return;
          },
          enumerable: false,
          configurable: true
      });
      Object.defineProperty(Line.prototype, "_effectiveX2", {
          get: function () {
              return (this._connectedControl ? this._connectedControl.centerX : 0) + this._x2.getValue(this._host);
          },
          enumerable: false,
          configurable: true
      });
      Object.defineProperty(Line.prototype, "_effectiveY2", {
          get: function () {
              return (this._connectedControl ? this._connectedControl.centerY : 0) + this._y2.getValue(this._host);
          },
          enumerable: false,
          configurable: true
      });
      Line.prototype._getTypeName = function () {
          return "Line";
      };
      Line.prototype._draw = function (context) {
          context.save();
          if (this.shadowBlur || this.shadowOffsetX || this.shadowOffsetY) {
              context.shadowColor = this.shadowColor;
              context.shadowBlur = this.shadowBlur;
              context.shadowOffsetX = this.shadowOffsetX;
              context.shadowOffsetY = this.shadowOffsetY;
          }
          this._applyStates(context);
          context.strokeStyle = this.color;
          context.lineWidth = this._lineWidth;
          context.setLineDash(this._dash);
          context.beginPath();
          context.moveTo(this._cachedParentMeasure.left + this._x1.getValue(this._host), this._cachedParentMeasure.top + this._y1.getValue(this._host));
          context.lineTo(this._cachedParentMeasure.left + this._effectiveX2, this._cachedParentMeasure.top + this._effectiveY2);
          context.stroke();
          context.restore();
      };
      Line.prototype._measure = function () {
          // Width / Height
          this._currentMeasure.width = Math.abs(this._x1.getValue(this._host) - this._effectiveX2) + this._lineWidth;
          this._currentMeasure.height = Math.abs(this._y1.getValue(this._host) - this._effectiveY2) + this._lineWidth;
      };
      Line.prototype._computeAlignment = function (parentMeasure, context) {
          this._currentMeasure.left = parentMeasure.left + Math.min(this._x1.getValue(this._host), this._effectiveX2) - this._lineWidth / 2;
          this._currentMeasure.top = parentMeasure.top + Math.min(this._y1.getValue(this._host), this._effectiveY2) - this._lineWidth / 2;
      };
      /**
       * Move one end of the line given 3D cartesian coordinates.
       * @param position Targeted world position
       * @param scene Scene
       * @param end (opt) Set to true to assign x2 and y2 coordinates of the line. Default assign to x1 and y1.
       */
      Line.prototype.moveToVector3 = function (position, scene, end) {
          if (end === void 0) { end = false; }
          if (!this._host || this.parent !== this._host._rootContainer) {
              Tools.Error("Cannot move a control to a vector3 if the control is not at root level");
              return;
          }
          var globalViewport = this._host._getGlobalViewport(scene);
          var projectedPosition = Vector3.Project(position, Matrix.Identity(), scene.getTransformMatrix(), globalViewport);
          this._moveToProjectedPosition(projectedPosition, end);
          if (projectedPosition.z < 0 || projectedPosition.z > 1) {
              this.notRenderable = true;
              return;
          }
          this.notRenderable = false;
      };
      /**
       * Move one end of the line to a position in screen absolute space.
       * @param projectedPosition Position in screen absolute space (X, Y)
       * @param end (opt) Set to true to assign x2 and y2 coordinates of the line. Default assign to x1 and y1.
       */
      Line.prototype._moveToProjectedPosition = function (projectedPosition, end) {
          if (end === void 0) { end = false; }
          var x = (projectedPosition.x + this._linkOffsetX.getValue(this._host)) + "px";
          var y = (projectedPosition.y + this._linkOffsetY.getValue(this._host)) + "px";
          if (end) {
              this.x2 = x;
              this.y2 = y;
              this._x2.ignoreAdaptiveScaling = true;
              this._y2.ignoreAdaptiveScaling = true;
          }
          else {
              this.x1 = x;
              this.y1 = y;
              this._x1.ignoreAdaptiveScaling = true;
              this._y1.ignoreAdaptiveScaling = true;
          }
      };
      return Line;
  }(Control));
  export { Line };
  _TypeStore.RegisteredTypes["BABYLON.GUI.Line"] = Line;
  //# sourceMappingURL=line.js.map