Example #1
0
        // Rotates a block's orientation through the progression of LineOrientations
        // Returns true if rotation succeeds. Returns false if all orientations have been
        // performed and no more remain.
        public bool RotateBlockLine()
        {
            // Rotate one position over!
            this.Orientation = this.Orientation == LineOrientation.Left ? LineOrientation.Right :
                               this.Orientation == LineOrientation.Right ? LineOrientation.Up :
                               this.Orientation == LineOrientation.Up ? LineOrientation.Down :
                               this.Orientation == LineOrientation.Down ? LineOrientation.Front :
                               this.Orientation == LineOrientation.Front ? LineOrientation.Back :
                               LineOrientation.NoOrientation;  // If none of those, you're Back or NoOrientation - go to NoOrientation.

            // Remember, all rotations are at 90deg from the last blockline. If you're not 90deg, correct it.
            if ((this.Orientation == LineOrientation.Left || this.Orientation == LineOrientation.Right) &&
                (this.LastLineOrientation == LineOrientation.Left || this.LastLineOrientation == LineOrientation.Right))
            {
                this.Orientation = LineOrientation.Up;
            }

            else if ((this.Orientation == LineOrientation.Up || this.Orientation == LineOrientation.Down) &&
                     (this.LastLineOrientation == LineOrientation.Up || this.LastLineOrientation == LineOrientation.Down))
            {
                this.Orientation = LineOrientation.Front;
            }

            else if ((this.Orientation == LineOrientation.Front || this.Orientation == LineOrientation.Back) &&
                     (this.LastLineOrientation == LineOrientation.Front || this.LastLineOrientation == LineOrientation.Back))
            {
                this.Orientation = LineOrientation.NoOrientation; // You're done. No more options!
            }
            // Return true if we're not out of orientations (ie, it's not NoOrientation)
            return(this.Orientation != LineOrientation.NoOrientation);
        }
    /// <summary> Trim points according to 'completion' then Scales them </summary>
    /// <param name="points"></param>
    /// <param name="completion"></param>
    /// <param name="fillMode"></param>
    /// <returns> Adjusted Points </returns>
    public static Vector3[] AdjustPoints(this Vector3[] points, float completion,
                                         LineOrientation fillMode, float xScale, float yScale, bool showDebug)
    {
        var changedScale = !(Mathf.Approximately(xScale, 1f) && Mathf.Approximately(yScale, 1f));
        var complete     = Mathf.Approximately(completion, 1f);

        if (complete && !changedScale)
        {
            return(points);
        }
        // Make a flat clone of the original array
        var adjPoints = Enumerable.Repeat(Vector3.zero, points.Length).ToArray();

        Array.Copy(points, adjPoints, points.Length);
        if (!complete)
        {
            adjPoints = AdjustCompletion(points, adjPoints, completion, fillMode,
                                         showDebug, xScale, yScale);
        }
        if (changedScale)
        {
            for (int i = 0; i < adjPoints.Length; i++)
            {
                adjPoints[i].Set(adjPoints[i].x * xScale,
                                 adjPoints[i].y * yScale,
                                 adjPoints[i].z);
            }
        }
        return(adjPoints);
    }
Example #3
0
        /// <summary>
        /// Returns an oriented line geometry
        /// </summary>
        /// <param name="thickness">The thickness of the line</param>
        /// <param name="orientation">The orientation of the line</param>
        /// <param name="lineDimension">The size of the line</param>
        /// <param name="containerSize">The size where the line is drawn. If the orientation is vertical, containerSize must be the available width to draw the line otherwise the available height.</param>
        /// <returns>Oriented line geometry</returns>
        public static Geometry GetOrientedLine(double thickness, LineOrientation orientation, double lineDimension, double containerSize)
        {
            var geometry = new PathGeometry();

            var pathFigure = new PathFigure();

            pathFigure.IsClosed = false;
            geometry.Figures.Add(pathFigure);

            var halfStroke      = thickness / 2d;
            var middleContainer = containerSize / 2d;

            if (orientation == LineOrientation.Vertical)
            {
                pathFigure.StartPoint = new Point(middleContainer - halfStroke, 0);
                pathFigure.Segments.Add(new LineSegment {
                    Point = new Point(middleContainer - halfStroke, lineDimension)
                });
            }
            else
            {
                pathFigure.StartPoint = new Point(0, middleContainer - halfStroke);
                pathFigure.Segments.Add(new LineSegment {
                    Point = new Point(lineDimension, middleContainer - halfStroke)
                });
            }

            return(geometry);
        }
Example #4
0
    public Line(Block[] blocks, LineOrientation orientation)
    {
        Orientation  = orientation;
        SubLines     = new List <Line>();
        BlocksInLine = new List <Block>();
        BlocksInLine.AddRange(blocks);

        SubLines.Add(this);
    }
Example #5
0
 /// <summary>
 /// Constructor used to initialize the <see cref="Line">Line</see> object with
 /// initial values for orientation, colour and location.
 /// </summary>
 /// <param name="orientation">Whether the line runs vertically or horizontally.</param>
 /// <param name="colour">The colour of the line.</param>
 /// <param name="location">The starting x and y coordinates of the line origin.</param>
 /// <param name="length">The length of the line, either horizontally or 
 /// vertically, from the location.</param>
 public      Line
            (LineOrientation orientation, 
             ConsoleColor    colour, 
             Point           location, 
             Int32           length) : this() {
     _orientation = orientation;
     _colour = colour;
     _location = location;
     _length = length;
 }
 public static void ModifyWithLine(Entity cellEntity, LineOrientation orientation)
 {
     if (orientation == LineOrientation.Horizontal)
     {
         ModifyWithLine(cellEntity, Direction.Left, Direction.Right, "LineHorizontal");
     }
     else
     {
         ModifyWithLine(cellEntity, Direction.Up, Direction.Down, "LineVertical");
     }
 }
Example #7
0
 /// <summary>
 /// Constructor used to initialize the <see cref="Line">Line</see> object with
 /// initial values for orientation, colour and location.
 /// </summary>
 /// <param name="orientation">Whether the line runs vertically or horizontally.</param>
 /// <param name="colour">The colour of the line.</param>
 /// <param name="location">The starting x and y coordinates of the line origin.</param>
 /// <param name="length">The length of the line, either horizontally or
 /// vertically, from the location.</param>
 public Line
     (LineOrientation orientation,
     ConsoleColor colour,
     Point location,
     int length) : this()
 {
     _orientation = orientation;
     _colour      = colour;
     _location    = location;
     _length      = length;
 }
Example #8
0
    protected virtual void CheckValid(List <Block> validBlocks, LineOrientation orientation)
    {
        if (validBlocks.Count >= 3)
        {
            Line newLine = new Line(validBlocks.ToArray(), orientation);

            if (!TryConcatLines(newLine))
            {
                lines.Add(newLine);
            }
        }
    }
Example #9
0
 ///<summary>Creates a LineObject with the specified name, section, color, line thickness, line orientation, line position and percent.  Orientation determines whether the line is horizontal or vertical.  Position determines which side of the section the line draws on.  Percent determines how much of available space the line will take up.  The line will be offset of its position in pixels according to the given X/Y values.</summary>
 public ReportObject(string name, AreaSectionType sectionType, Color color, float lineThickness, LineOrientation lineOrientation, LinePosition linePosition, int linePercent, int offSetX, int offSetY)
 {
     _name               = name;
     _sectionType        = sectionType;
     _foreColor          = color;
     _floatLineThickness = lineThickness;
     _lineOrientation    = lineOrientation;
     _linePosition       = linePosition;
     _intLinePercent     = linePercent;
     _offSetX            = offSetX;
     _offSetY            = offSetY;
     _reportObjectType   = ReportObjectType.LineObject;
 }
Example #10
0
        public LineShape(Point p1, Point p2, Canvas canvas)
        {
            P1     = p1;
            P2     = p2;
            Canvas = canvas;

            if (P1.X == P2.X)
            {
                Orientation = LineOrientation.Vertical;
            }
            else if (P1.Y == P2.Y)
            {
                Orientation = LineOrientation.Horizontal;
            }
            else
            {
                Orientation = LineOrientation.Unknown;
            }
        }
	/// <summary> Trim points according to 'completion' then Scales them </summary>
	/// <param name="points"></param>
	/// <param name="completion"></param>
	/// <param name="fillMode"></param>
	/// <returns> Adjusted Points </returns>
	public static Vector3[] AdjustPoints (this Vector3[] points, float completion, 
		LineOrientation fillMode, float xScale, float yScale, bool showDebug)
	{
		var changedScale = !(Mathf.Approximately (xScale, 1f) && Mathf.Approximately (yScale, 1f));
		var complete = Mathf.Approximately(completion, 1f);
		if (complete && !changedScale)
			return points;
		// Make a flat clone of the original array
		var adjPoints = Enumerable.Repeat (Vector3.zero, points.Length).ToArray ();
		Array.Copy (points, adjPoints, points.Length);
		if (!complete) {
			adjPoints = AdjustCompletion (points, adjPoints, completion, fillMode, 
				showDebug, xScale, yScale);
		}
		if (changedScale) {
			for (int i = 0; i < adjPoints.Length; i++) {
				adjPoints[i].Set (adjPoints[i].x * xScale,
					adjPoints[i].y * yScale,
					adjPoints[i].z);
			}
		}
		return adjPoints;
	}
Example #12
0
        /// <summary>
        /// Reads Xml when the <see cref="Line">Line</see> is to be deserialized
        /// from a stream.</summary>
        /// <param name="reader">The stream from which the object will be deserialized.</param>
        void System.Xml.Serialization.IXmlSerializable.ReadXml(System.Xml.XmlReader reader)
        {
            _orientation = (LineOrientation)Enum.Parse(_orientation.GetType(),
                                                       reader.GetAttribute("Orientation"));
            _length = int.Parse(reader.GetAttribute("Length"));

            string colour = reader.GetAttribute("Colour");

            if (colour != null && colour.Length > 0)
            {
                _colour = (ConsoleColor)Enum.Parse(typeof(ConsoleColor), colour);
            }

            reader.Read();

            if (reader.Name == "Location")
            {
                ((IXmlSerializable)_location).ReadXml(reader);
            }
            else
            {
                throw new InvalidOperationException("<Location> node missing from <Line> node.");
            }
        }
Example #13
0
		private void RecalculateOrientations()
		{
			if (!FirstBendPoint.AutoPosition)
			{
				if (FirstBendPoint.X >= startShape.Left && FirstBendPoint.X <= startShape.Right)
				{
					startOrientation = LineOrientation.Vertical;
				}
				else if (FirstBendPoint.Y >= startShape.Top && FirstBendPoint.Y <= startShape.Bottom)
				{
					startOrientation = LineOrientation.Horizontal;
				}
			}
			if (!LastBendPoint.AutoPosition)
			{
				if (LastBendPoint.X >= endShape.Left && LastBendPoint.X <= endShape.Right)
				{
					endOrientation = LineOrientation.Vertical;
				}
				else if (LastBendPoint.Y >= endShape.Top && LastBendPoint.Y <= endShape.Bottom)
				{
					endOrientation = LineOrientation.Horizontal;
				}
			}
		}
Example #14
0
		protected void Reverse()
		{
			Shape shape = startShape;
			startShape = endShape;
			endShape = shape;

			LineOrientation orientation = startOrientation;
			startOrientation = endOrientation;
			endOrientation = orientation;

			bendPoints.Reverse();
			RouteCache.Reverse();
			foreach (BendPoint point in BendPoints)
			{
				point.RelativeToStartShape = !point.RelativeToStartShape;
			}

			NeedsRedraw = true;
		}
Example #15
0
        protected override void Deserialize(XmlElement e)
        {
            // New file format
            XmlElement startNode = e["StartOrientation"];
            if (startNode != null)
            {
                if (startNode.InnerText == "Horizontal")
                    startOrientation = LineOrientation.Horizontal;
                else
                    startOrientation = LineOrientation.Vertical;
            }
            XmlElement endNode = e["EndOrientation"];
            if (endNode != null)
            {
                if (endNode.InnerText == "Horizontal")
                    endOrientation = LineOrientation.Horizontal;
                else
                    endOrientation = LineOrientation.Vertical;
            }

            if (startNode != null && endNode != null) // To be sure it's the new file format
            {
                bendPoints.Clear();

                XmlNodeList nodes = e.SelectNodes("child::BendPoint");
                foreach (XmlElement node in nodes)
                {
                    bool relativeToStartShape;
                    bool.TryParse(node.GetAttribute("relativeToStartShape"), out relativeToStartShape);
                    Shape relativeShape = relativeToStartShape ? startShape : endShape;

                    BendPoint point = new BendPoint(relativeShape, relativeToStartShape, false);
                    point.Deserialize(node);
                    bendPoints.Add(point);
                }
                if (bendPoints.Count == 0 || !FirstBendPoint.RelativeToStartShape)
                    bendPoints.AddFirst(new BendPoint(startShape, true));
                if (LastBendPoint.RelativeToStartShape)
                    bendPoints.Add(new BendPoint(endShape, false));
            }
            Reroute();
        }
Example #16
0
		public void InitOrientations()
		{
			if (startShape == endShape)
			{
				startOrientation = LineOrientation.Horizontal;
				endOrientation = LineOrientation.Vertical;
			}
			else
			{
				int hDiff = Math.Max(startShape.Left - endShape.Right, endShape.Left - startShape.Right);
				int vDiff = Math.Max(startShape.Top - endShape.Bottom, endShape.Top - startShape.Bottom);

				if (vDiff >= Spacing * 2)
				{
					startOrientation = LineOrientation.Vertical;
					endOrientation = LineOrientation.Vertical;
				}
				else if (hDiff >= Spacing * 2)
				{
					startOrientation = LineOrientation.Horizontal;
					endOrientation = LineOrientation.Horizontal;
				}
				else
				{
					startOrientation = LineOrientation.Vertical;
					endOrientation = LineOrientation.Horizontal;
				}
			}
		}
    private static Vector3[] AdjustCompletion(this Vector3[] points, Vector3[] adjPoints,
                                              float completion, LineOrientation fillMode, bool showDebug, float xScale, float yScale)
    {
        var first = adjPoints[0];
        var last  = adjPoints[adjPoints.Length - 1];

        switch (fillMode)
        {
        case LineOrientation.Free:
            break;

        case LineOrientation.Horizontal:
            first = new Vector3(first.x, 0f);
            last  = new Vector3(last.x, 0f);
            break;

        case LineOrientation.Vertical:
            first = new Vector3(0, first.y);
            last  = new Vector3(0, last.y);
            break;
        }

        // Proportional point in an imaginary line connecting the first and last point
        var limitPoint         = Vector3.Lerp(first, last, completion);
        var limitPointDistance = Vector3.Distance(limitPoint, last);

        int  capIdx           = 0;                                                      // Last 'valid' Idx before the limitPoint
        bool lastPointIsExact = (limitPoint == last);

        // If last point to show == last point in the list, just assign it
        if (lastPointIsExact)
        {
            capIdx = adjPoints.Length;
        }
        else
        {
            for (int i = 0; i < adjPoints.Length; i++)
            {
                var projPoint = ProjectedPoint(adjPoints[i], first, last);
                if (showDebug)
                {
                    DebugDrawLineScaled(adjPoints[i], projPoint, 8f, xScale, yScale);
                }
                var currPointDistance = Vector3.Distance(projPoint, last);
                if (currPointDistance < limitPointDistance)
                {
                    capIdx = Mathf.Max(0, i - 1);                       // Assures capIdx is never negative
                    break;
                }
            }
        }

        // Remove remaining points, leaving room for the end cap
        // Only leaves room when the last x is not exactly the last valid x
        int trailPoints = lastPointIsExact ? 0 : 1;

        adjPoints = Enumerable.Repeat(Vector3.zero, capIdx + trailPoints + 1).ToArray();

        // First copy all original points in range, then add the trail point if needed
        try {
            //TODO: Fix the first case, shouldn't leave a trailing Vector3.zero..
            Array.Copy(points, adjPoints, Mathf.Min(points.Length, capIdx + 1));
        } catch (System.Exception) {
            Debug.Log(" Broken capIdx: " + capIdx + " points: " + points.Length + " adjPoints: " + adjPoints.Length);
            throw;
        }

        if (!lastPointIsExact)
        {
            adjPoints = AddTrailPoint(adjPoints, points[capIdx], points[capIdx + 1], limitPoint, first, last);
        }

        return(adjPoints);
    }
Example #18
0
    protected virtual void CheckWay(int x, int y, int directionX, int directionY, ColorId myColor, Block[,] gridArray, ref List <Block> validBlocks, LineOrientation orientation)
    {
        validBlocks.Clear();
        validBlocks.Add(gridArray[x, y]);

        Check(x, y, directionX, directionY, myColor, gridArray, ref validBlocks);
        Check(x, y, -directionX, -directionY, myColor, gridArray, ref validBlocks);

        CheckValid(validBlocks, orientation);
    }
Example #19
0
        /// <summary>
        /// Submits the mesh for rendering
        /// <summary>
        public override void Draw(Matrix4x4 transform, Material material)
        {
            if (_mesh == null ||
                _geometryDirty ||
                _prevLineCount != _lineCount ||
                _prevLineDensity != _lineDensity ||
                _prevOrientation != _orientation)
            {
                BuildMesh();
                _geometryDirty   = false;
                _prevLineCount   = _lineCount;
                _prevLineDensity = _lineDensity;
                _prevOrientation = _orientation;
            }

            //Can't set stride variables without parent texture
            if (ParentRenderer.Texture == null)
            {
                return;
            }

            if (isActiveAndEnabled && _opacity > 0.0f)
            {
                // push all the items into material property block
                // we use this technique in order to the share the material between all the different layers
                if (_materialBlock == null)
                {
                    _materialBlock = new MaterialPropertyBlock();
                }
                else
                {
                    _materialBlock.Clear();
                }

                //For the line layer, the sampling schema for recovery of nil depth values from neighbors needs
                //to match the strides of the lines (density and count) and is swapped dependening on the orientation.
                if (_orientation == LineOrientation.Horizontal)
                {
                    _materialBlock.SetVector("_MeshScalar", new Vector4((float)ParentRenderer.Texture.width / (int)_lineDensity, 0.0f, 0.0f, 0.0f));
                }
                else
                {
                    _materialBlock.SetVector("_MeshScalar", new Vector4(0.0f, ((float)ParentRenderer.Texture.height * .5f) / (int)_lineDensity, 0.0f, 0.0f));
                }

                if (_lineSprite != null)
                {
                    _materialBlock.SetTexture("_Sprite", _lineSprite);
                    _materialBlock.SetFloat("_UseSprite", 1.0f);
                }
                else
                {
                    _materialBlock.SetFloat("_UseSprite", 0.0f);
                }

                //Apply exponential curve
                float lineWidth = _width / LINE_WIDTH_MAX;
                lineWidth  = Mathf.Pow(lineWidth, 2.0f);
                lineWidth *= LINE_WIDTH_MAX;

                //lines need to scale with the object based on their orientation.
                float scaledWidth = lineWidth / LINE_MM_TO_METERS * (_orientation == LineOrientation.Horizontal ? gameObject.transform.localScale.y : gameObject.transform.localScale.x);
                _materialBlock.SetFloat("_Width", scaledWidth);
                _materialBlock.SetFloat("_Opacity", _opacity);
                _materialBlock.SetFloat("_LineOrientation", (float)_orientation);

                Graphics.DrawMesh(_mesh, transform, material, 0, null, 0, _materialBlock);
            }
        }
	private static Vector3[] AdjustCompletion (this Vector3[] points, Vector3[] adjPoints, 
		float completion, LineOrientation fillMode, bool showDebug, float xScale, float yScale)
	{
		var first = adjPoints[0];
		var last = adjPoints[adjPoints.Length - 1];

		switch (fillMode) {
			case LineOrientation.Free:
				break;
			case LineOrientation.Horizontal:
				first = new Vector3 (first.x, 0f);
				last = new Vector3 (last.x, 0f);
				break;
			case LineOrientation.Vertical:
				first = new Vector3 (0, first.y);
				last = new Vector3 (0, last.y);
				break;
		}

		// Proportional point in an imaginary line connecting the first and last point
		var limitPoint = Vector3.Lerp (first, last, completion);
		var limitPointDistance = Vector3.Distance (limitPoint, last);

		int capIdx = 0;								// Last 'valid' Idx before the limitPoint
		bool lastPointIsExact = (limitPoint == last);

		// If last point to show == last point in the list, just assign it
		if (lastPointIsExact) {
			capIdx = adjPoints.Length;
		} else {
			for (int i = 0; i < adjPoints.Length; i++) {
				var projPoint = ProjectedPoint (adjPoints[i], first, last);
				if (showDebug)
					DebugDrawLineScaled (adjPoints[i], projPoint, 8f, xScale, yScale);
				var currPointDistance = Vector3.Distance (projPoint, last);
				if (currPointDistance < limitPointDistance) {
					capIdx = Mathf.Max (0, i - 1);	// Assures capIdx is never negative
					break;
				}
			}
		}

		// Remove remaining points, leaving room for the end cap
		// Only leaves room when the last x is not exactly the last valid x
		int trailPoints = lastPointIsExact ? 0 : 1;
		adjPoints = Enumerable.Repeat (Vector3.zero, capIdx + trailPoints + 1).ToArray ();

		// First copy all original points in range, then add the trail point if needed
		try {
			//TODO: Fix the first case, shouldn't leave a trailing Vector3.zero..
			Array.Copy (points, adjPoints, Mathf.Min (points.Length, capIdx + 1));
		} catch (System.Exception) {
			Debug.Log (" Broken capIdx: " + capIdx + " points: " + points.Length + " adjPoints: " + adjPoints.Length);
			throw;
		}

		if (!lastPointIsExact) {
			adjPoints = AddTrailPoint (adjPoints, points[capIdx], points[capIdx + 1], limitPoint, first, last);
		}

		return adjPoints;
	}
Example #21
0
		protected virtual void OnDeserializing(SerializeEventArgs e)
		{
			// Old file format
			XmlElement oldStartNode = e.Node["StartNode"];
			XmlElement oldEndNode = e.Node["EndNode"];
			if (oldStartNode != null && oldEndNode != null)
			{
				bool isHorizontal;
				bool.TryParse(oldStartNode.GetAttribute("isHorizontal"), out isHorizontal);
				startOrientation = (isHorizontal) ? LineOrientation.Horizontal : LineOrientation.Vertical;
				bool.TryParse(oldEndNode.GetAttribute("isHorizontal"), out isHorizontal);
				endOrientation = (isHorizontal) ? LineOrientation.Horizontal : LineOrientation.Vertical;

				int startLocation, endLocation;
				int.TryParse(oldStartNode.GetAttribute("location"), out startLocation);
				int.TryParse(oldEndNode.GetAttribute("location"), out endLocation);

				Reroute();
				if (startOrientation == LineOrientation.Vertical)
					FirstBendPoint.X = startShape.Left + startLocation;
				else
					FirstBendPoint.Y = startShape.Top + startLocation;

				if (endOrientation == LineOrientation.Vertical)
					LastBendPoint.X = endShape.Left + endLocation;
				else
					LastBendPoint.Y = endShape.Top + endLocation;

				FirstBendPoint.AutoPosition = false;
				LastBendPoint.AutoPosition = false;
				Reroute();
			}
			else
			{
				// New file format
				XmlElement startNode = e.Node["StartOrientation"];
				if (startNode != null)
				{
					if (startNode.InnerText == "Horizontal")
						startOrientation = LineOrientation.Horizontal;
					else
						startOrientation = LineOrientation.Vertical;
				}
				XmlElement endNode = e.Node["EndOrientation"];
				if (endNode != null)
				{
					if (endNode.InnerText == "Horizontal")
						endOrientation = LineOrientation.Horizontal;
					else
						endOrientation = LineOrientation.Vertical;
				}

				if (startNode != null && endNode != null) // To be sure it's the new file format
				{
					bendPoints.Clear();

					XmlNodeList nodes = e.Node.SelectNodes("child::BendPoint");
					foreach (XmlElement node in nodes)
					{
						bool relativeToStartShape;
						bool.TryParse(node.GetAttribute("relativeToStartShape"), out relativeToStartShape);
						Shape relativeShape = relativeToStartShape ? startShape : endShape;

						BendPoint point = new BendPoint(relativeShape, relativeToStartShape, false);
						point.Deserialize(node);
						bendPoints.Add(point);
					}
					if (bendPoints.Count == 0 || !FirstBendPoint.RelativeToStartShape)
						bendPoints.AddFirst(new BendPoint(startShape, true));
					if (LastBendPoint.RelativeToStartShape)
						bendPoints.Add(new BendPoint(endShape, false));
				}
				Reroute();
			}
		}
Example #22
0
		/// <summary>Line is drawn in 50% of the available space.</summary>
		public void AddLine(string name,string sectionName,Color color,float floatLineThickness,LineOrientation lineOrientation,LinePosition linePosition) {
			AddLine(name,sectionName,color,floatLineThickness,lineOrientation,linePosition,50,0,0);
		}
 public override int CheckForLine(int x, int y, LineOrientation orientation, bool includeMovingItemsInLine = true)
 {
     var count = 1;
     if (Items[x][y] == null || Items[x][y] == DisabledItem) return count;
     switch (orientation)
     {
         // ->\\     |
         //  ->\\    V
         //   ->\\
         case LineOrientation.Vertical:
             for (var i = 1; x + i < FieldSize && y + i < FieldSize; i++)
             {
                 if (Items[x + i][y + i] == null || Items[x + i][y + i] == DisabledItem) break;
                 if (includeMovingItemsInLine)
                 {
                     var goItem = (Items[x + i][y + i] as GameObject);
                     if (goItem != null && ((goItem.GetComponent<GameItemMovingScript>().IsMoving && !goItem.GetComponent<GameItem>().IsDraggableWhileMoving)
                     || goItem.GetComponent<GameItemScalingScript>().isScaling)) return 1;
                 }
                 var gobj1 = Items[x][y] as GameObject;
                 if (gobj1 != null)
                 {
                     var gi1 = gobj1.GetComponent<GameItem>();
                     var gobj2 = Items[x + i][y + i] as GameObject;
                     if (gobj2 != null)
                     {
                         var gi2 = gobj2.GetComponent<GameItem>();
                         if (gi1.Type != gi2.Type)
                             break;
                     }
                 }
                 count++;
             }
             break;
         // ->  //
         // -> //   ^
         // ->//    |
         case LineOrientation.Horizontal:
             for (var i = 1; x + i < FieldSize && y - i >= 0; i++)
             {
                 if (Items[x + i][y - i] == null || Items[x + i][y - i] == DisabledItem) break;
                 if (includeMovingItemsInLine)
                 {
                     var goItem = (Items[x + i][y - i] as GameObject);
                     if (goItem != null && ((goItem.GetComponent<GameItemMovingScript>().IsMoving && !goItem.GetComponent<GameItem>().IsDraggableWhileMoving)
                     || goItem.GetComponent<GameItemScalingScript>().isScaling)) return 1;
                 }
                 var gobj1 = Items[x][y] as GameObject;
                 if (gobj1 != null)
                 {
                     var gi1 = gobj1.GetComponent<GameItem>();
                     var gobj2 = Items[x + i][y - i] as GameObject;
                     if (gobj2 != null)
                     {
                         var gi2 = gobj2.GetComponent<GameItem>();
                         if (gi1.Type != gi2.Type)
                             break;
                     }
                 }
                 count++;
             }
             break;
     }
     return count;
 }
Example #24
0
		private void RelocateAutoBendPoints()
		{
			if (FirstBendPoint.AutoPosition && LastBendPoint.AutoPosition)
			{
				if (startOrientation == endOrientation && startShape == endShape)
				{
					startOrientation = LineOrientation.Horizontal;
					endOrientation = LineOrientation.Vertical;
				}

				if (startOrientation == LineOrientation.Horizontal &&
					endOrientation == LineOrientation.Horizontal)
				{
					if (startShape.Right <= endShape.Left - 2 * Spacing)
					{
						FirstBendPoint.X = startShape.Right + Spacing;
						LastBendPoint.X = endShape.Left - Spacing;
					}
					else if (startShape.Left >= endShape.Right + 2 * Spacing)
					{
						FirstBendPoint.X = startShape.Left - Spacing;
						LastBendPoint.X = endShape.Right + Spacing;
					}
					else
					{
						if (Math.Abs(startShape.Left - endShape.Left) <
							Math.Abs(startShape.Right - endShape.Right))
						{
							FirstBendPoint.X = startShape.Left - Spacing;
							LastBendPoint.X = endShape.Left - Spacing;
						}
						else
						{
							FirstBendPoint.X = startShape.Right + Spacing;
							LastBendPoint.X = endShape.Right + Spacing;
						}
					}

					Shape smallerShape, biggerShape;
					if (startShape.Height < endShape.Height)
					{
						smallerShape = startShape;
						biggerShape = endShape;
					}
					else
					{
						smallerShape = endShape;
						biggerShape = startShape;
					}

					if (biggerShape.Top <= smallerShape.VerticalCenter &&
						biggerShape.Bottom >= smallerShape.VerticalCenter)
					{
						int center = (
							Math.Max(startShape.Top, endShape.Top) +
							Math.Min(startShape.Bottom, endShape.Bottom)) / 2;

						FirstBendPoint.Y = center;
						LastBendPoint.Y = center;
					}
					else
					{
						FirstBendPoint.Y = startShape.VerticalCenter;
						LastBendPoint.Y = endShape.VerticalCenter;
					}
				}
				else if (startOrientation == LineOrientation.Vertical &&
					endOrientation == LineOrientation.Vertical)
				{
					if (startShape.Bottom <= endShape.Top - 2 * Spacing)
					{
						FirstBendPoint.Y = startShape.Bottom + Spacing;
						LastBendPoint.Y = endShape.Top - Spacing;
					}
					else if (startShape.Top >= endShape.Bottom + 2 * Spacing)
					{
						FirstBendPoint.Y = startShape.Top - Spacing;
						LastBendPoint.Y = endShape.Bottom + Spacing;
					}
					else
					{
						if (Math.Abs(startShape.Top - endShape.Top) <
							Math.Abs(startShape.Bottom - endShape.Bottom))
						{
							FirstBendPoint.Y = startShape.Top - Spacing;
							LastBendPoint.Y = endShape.Top - Spacing;
						}
						else
						{
							FirstBendPoint.Y = startShape.Bottom + Spacing;
							LastBendPoint.Y = endShape.Bottom + Spacing;
						}
					}

					Shape smallerShape, biggerShape;
					if (startShape.Width < endShape.Width)
					{
						smallerShape = startShape;
						biggerShape = endShape;
					}
					else
					{
						smallerShape = endShape;
						biggerShape = startShape;
					}

					if (biggerShape.Left <= smallerShape.HorizontalCenter &&
						biggerShape.Right >= smallerShape.HorizontalCenter)
					{
						int center = (
							Math.Max(startShape.Left, endShape.Left) +
							Math.Min(startShape.Right, endShape.Right)) / 2;

						FirstBendPoint.X = center;
						LastBendPoint.X = center;
					}
					else
					{
						FirstBendPoint.X = startShape.HorizontalCenter;
						LastBendPoint.X = endShape.HorizontalCenter;
					}
				}
				else
				{
					if (startOrientation == LineOrientation.Horizontal)
					{
						FirstBendPoint.Y = startShape.VerticalCenter;
						LastBendPoint.X = endShape.HorizontalCenter;

						if (LastBendPoint.X >= startShape.HorizontalCenter)
							FirstBendPoint.X = startShape.Right + Spacing;
						else
							FirstBendPoint.X = startShape.Left - Spacing;

						if (FirstBendPoint.Y >= endShape.VerticalCenter)
							LastBendPoint.Y = endShape.Bottom + Spacing;
						else
							LastBendPoint.Y = endShape.Top - Spacing;
					}
					else
					{
						FirstBendPoint.X = startShape.HorizontalCenter;
						LastBendPoint.Y = endShape.VerticalCenter;

						if (LastBendPoint.Y >= startShape.VerticalCenter)
							FirstBendPoint.Y = startShape.Bottom + Spacing;
						else
							FirstBendPoint.Y = startShape.Top - Spacing;

						if (FirstBendPoint.X >= endShape.HorizontalCenter)
							LastBendPoint.X = endShape.Right + Spacing;
						else
							LastBendPoint.X = endShape.Left - Spacing;
					}
				}
			}
			else if (FirstBendPoint.AutoPosition)
			{
				if (startOrientation == LineOrientation.Horizontal)
				{
					if (bendPoints.SecondValue.X < startShape.HorizontalCenter)
						FirstBendPoint.X = startShape.Left - Spacing;
					else
						FirstBendPoint.X = startShape.Right + Spacing;

					if (bendPoints.SecondValue.Y >= startShape.Top &&
					    bendPoints.SecondValue.Y <= startShape.Bottom)
					{
						FirstBendPoint.Y = bendPoints.SecondValue.Y;
					}
					else
					{
						FirstBendPoint.Y = startShape.VerticalCenter;
					}
				}
				else
				{
					if (bendPoints.SecondValue.Y < startShape.VerticalCenter)
						FirstBendPoint.Y = startShape.Top - Spacing;
					else
						FirstBendPoint.Y = startShape.Bottom + Spacing;

					if (bendPoints.SecondValue.X >= startShape.Left &&
						bendPoints.SecondValue.X <= startShape.Right)
					{
						FirstBendPoint.X = bendPoints.SecondValue.X;
					}
					else
					{
						FirstBendPoint.X = startShape.HorizontalCenter;
					}
				}
			}
			else if (LastBendPoint.AutoPosition)
			{
				if (endOrientation == LineOrientation.Horizontal)
				{
					if (bendPoints.SecondLastValue.X < endShape.HorizontalCenter)
						LastBendPoint.X = endShape.Left - Spacing;
					else
						LastBendPoint.X = endShape.Right + Spacing;

					if (bendPoints.SecondLastValue.Y >= endShape.Top &&
						bendPoints.SecondLastValue.Y <= endShape.Bottom)
					{
						LastBendPoint.Y = bendPoints.SecondLastValue.Y;
					}
					else
					{
						LastBendPoint.Y = endShape.VerticalCenter;
					}
				}
				else
				{
					if (bendPoints.SecondLastValue.Y < endShape.VerticalCenter)
						LastBendPoint.Y = endShape.Top - Spacing;
					else
						LastBendPoint.Y = endShape.Bottom + Spacing;

					if (bendPoints.SecondLastValue.X >= endShape.Left &&
						bendPoints.SecondLastValue.X <= endShape.Right)
					{
						LastBendPoint.X = bendPoints.SecondLastValue.X;
					}
					else
					{
						LastBendPoint.X = endShape.HorizontalCenter;
					}
				}
			}
		}
Example #25
0
 // Reset orientation to the first valid orientation (which will be left unless it's not valid)
 // Takes in the last blockline's orientation
 public void ZeroOrientation()
 {
     // Start with a Left line orientation, unless the last block was left or right (block lines must be 90deg from the last block line)
     this.Orientation = ((this.LastLineOrientation != LineOrientation.Left) && (this.LastLineOrientation != LineOrientation.Right)) ?
                        LineOrientation.Left : LineOrientation.Up;
 }
Example #26
0
 ///<summary>Creates a LineObject with the specified name, section, color, line thickness, line orientation, line position and percent.  Orientation determines whether the line is horizontal or vertical.  Position determines which side of the section the line draws on.  Percent determines how much of available space the line will take up.</summary>
 public ReportObject(string name, AreaSectionType sectionType, Color color, float lineThickness, LineOrientation lineOrientation, LinePosition linePosition, int linePercent)
     : this(name, sectionType, color, lineThickness, lineOrientation, linePosition, linePercent, 0, 0)
 {
 }
Example #27
0
		///<summary>Overload for LineObject.</summary>
		public ReportObject(string name,string sectionName,Color color,float lineThickness,LineOrientation lineOrientation,LinePosition linePosition,int linePercent,int offSetX,int offSetY) {
			_name=name;
			_sectionName=sectionName;
			_foreColor=color;
			_floatLineThickness=lineThickness;
			_lineOrientation=lineOrientation;
			_linePosition=linePosition;
			_intLinePercent=linePercent;
			_offSetX=offSetX;
			_offSetY=offSetY;
			_reportObjectKind=ReportObjectKind.LineObject;
		}
Example #28
0
 /// <summary></summary>
 public void AddLine(string name, AreaSectionType sectionType, Color color, float lineThickness, LineOrientation lineOrientation, LinePosition linePosition, int linePercent, int offSetX, int offSetY)
 {
     _reportObjects.Add(new ReportObject(name, sectionType, color, lineThickness, lineOrientation, linePosition, linePercent, offSetX, offSetY));
 }
Example #29
0
		/// <summary>Adds a line to a section.</summary>
		public void AddLine(string name,string sectionName,Color color,float floatLineThickness,LineOrientation lineOrientation,LinePosition linePosition,int linePercentValue,int offSetX,int offSetY) {
			_reportObjects.Add(new ReportObject(name,sectionName,color,floatLineThickness,lineOrientation,linePosition,linePercentValue,offSetX,offSetY));
		}
Example #30
0
        /// <summary>
        /// Reads Xml when the <see cref="Line">Line</see> is to be deserialized 
        /// from a stream.</summary>
        /// <param name="reader">The stream from which the object will be deserialized.</param>
        void System.Xml.Serialization.IXmlSerializable.ReadXml(System.Xml.XmlReader reader) {
            _orientation = (LineOrientation)Enum.Parse(_orientation.GetType(), 
                                                       reader.GetAttribute("Orientation"));
            _length = Int32.Parse(reader.GetAttribute("Length"));

            string colour = reader.GetAttribute("Colour");
            if (colour != null && colour.Length > 0)
                _colour = (ConsoleColor)Enum.Parse(typeof(ConsoleColor), colour);

            reader.Read();

            if (reader.Name == "Location") 
                ((IXmlSerializable)_location).ReadXml(reader);
            else
                throw new InvalidOperationException("<Location> node missing from <Line> node.");
        }
Example #31
0
		/// <summary>Line is drawn in 50% of the available space, black in color and in 2pt size.</summary>
		public void AddLine(string name,string sectionName,LineOrientation lineOrientation,LinePosition linePosition) {
			AddLine(name,sectionName,Color.Black,2,lineOrientation,linePosition,50,0,0);
		}
Example #32
0
 public Line()
 {
     m_orientation = LineOrientation.Horizontal;
     m_style       = LineStyle.Etched;
 }