Exemplo n.º 1
0
 /// <summary>
 /// Constructor
 /// </summary>
 /// <param name="addedRange"></param>
 /// <param name="removedRange"></param>
 public RangeRegionChangedEventArgs(GridRange addedRange, GridRange removedRange)
 {
     if (addedRange.IsEmpty() == false)
     {
         this.addedRange = new RangeRegion(addedRange);
     }
     if (removedRange.IsEmpty() == false)
     {
         this.removedRange = new RangeRegion(removedRange);
     }
 }
Exemplo n.º 2
0
 /// <summary>
 /// Returns a range with the smaller Start and the bigger End. The Union of the 2 Range. If one of the range is empty then the return is the other range.
 /// </summary>
 /// <param name="p_Range1"></param>
 /// <param name="p_Range2"></param>
 /// <returns></returns>
 public static GridRange GetBounds(GridRange p_Range1, GridRange p_Range2)
 {
     if (p_Range1.IsEmpty())
     {
         return(p_Range2);
     }
     else if (p_Range2.IsEmpty())
     {
         return(p_Range1);
     }
     else
     {
         return(new GridRange(Position.Min(p_Range1.Start, p_Range2.Start),
                              Position.Max(p_Range1.End, p_Range2.End), false));
     }
 }
Exemplo n.º 3
0
        /// <summary>
        /// Returns the intersection between the 2 Range. If one of the range is empty then the return is empty.
        /// </summary>
        /// <param name="p_Range1"></param>
        /// <param name="p_Range2"></param>
        /// <returns></returns>
        public static GridRange Intersect(GridRange p_Range1, GridRange p_Range2)
        {
            if (p_Range1.IsEmpty() || p_Range2.IsEmpty())
            {
                return(GridRange.Empty);
            }

            Position startNew = Position.Max(p_Range1.Start, p_Range2.Start);
            Position endNew   = Position.Min(p_Range1.End, p_Range2.End);

            if (startNew.Column > endNew.Column ||
                startNew.Row > endNew.Row)
            {
                return(GridRange.Empty);
            }
            else
            {
                return(new GridRange(startNew, endNew, false));
            }
        }
Exemplo n.º 4
0
Arquivo: Grid.cs Projeto: alexfordc/Au
        /// <summary>
        /// This method converts a Position to the real range of the cell. This is usefull when RowSpan or ColumnSpan is greater than 1.
        /// </summary>
        /// <returns></returns>
        public override GridRange RangeToCellRange(GridRange range)
        {
            int x  = range.Start.Column;
            int x1 = range.End.Column;
            int y  = range.Start.Row;
            int y1 = range.End.Row;

            for (int x2 = range.Start.Column; x2 <= range.End.Column; x2++)
            {
                for (int y2 = range.Start.Row; y2 <= range.End.Row; y2++)
                {
                    var       p      = new Position(y2, x2);
                    GridRange range2 = PositionToCellRange(p);
                    if (range2.IsEmpty())
                    {
                        range2 = new GridRange(p, p);
                    }
                    if (range2.Start.Column < x)
                    {
                        x = range2.Start.Column;
                    }
                    if (range2.End.Column > x1)
                    {
                        x1 = range2.End.Column;
                    }

                    if (range2.Start.Row < y)
                    {
                        y = range2.Start.Row;
                    }
                    if (range2.End.Row > y1)
                    {
                        y1 = range2.End.Row;
                    }
                }
            }
            return(new GridRange(y, x, y1, x1));
        }
Exemplo n.º 5
0
        /// <summary>
        /// Return all the cells that don't intersect with the specified cells. (Remove the specified cells from the current cells ad returns the remaining cells)
        /// </summary>
        /// <param name="range"></param>
        /// <returns></returns>
        public RangeRegion Exclude(GridRange range)
        {
            RangeRegion excluded;

            GridRange intersection = Intersect(range);

            if (intersection.IsEmpty())
            {
                excluded = new RangeRegion(this);
            }
            else
            {
                excluded = new RangeRegion();

                //Top Left
                if (this.Start.Row < intersection.Start.Row &&
                    this.Start.Column < intersection.Start.Column)
                {
                    excluded.Add(new GridRange(this.Start.Row, this.Start.Column, intersection.Start.Row - 1, intersection.Start.Column - 1));
                }

                //Top
                if (this.Start.Row < intersection.Start.Row)
                {
                    excluded.Add(new GridRange(this.Start.Row, intersection.Start.Column, intersection.Start.Row - 1, intersection.End.Column));
                }

                //Top Right
                if (this.Start.Row < intersection.Start.Row &&
                    this.End.Column > intersection.End.Column)
                {
                    excluded.Add(new GridRange(this.Start.Row, intersection.End.Column + 1, intersection.Start.Row - 1, this.End.Column));
                }

                //----------

                //Left
                if (this.Start.Column < intersection.Start.Column)
                {
                    excluded.Add(new GridRange(intersection.Start.Row, this.Start.Column, intersection.End.Row, intersection.Start.Column - 1));
                }

                //Right
                if (this.End.Column > intersection.End.Column)
                {
                    excluded.Add(new GridRange(intersection.Start.Row, intersection.End.Column + 1, intersection.End.Row, this.End.Column));
                }

                //--------

                //Bottom Left
                if (this.End.Row > intersection.End.Row &&
                    this.Start.Column < intersection.Start.Column)
                {
                    excluded.Add(new GridRange(intersection.End.Row + 1, this.Start.Column, this.End.Row, intersection.Start.Column - 1));
                }

                //Bottom
                if (this.End.Row > intersection.End.Row)
                {
                    excluded.Add(new GridRange(intersection.End.Row + 1, intersection.Start.Column, this.End.Row, intersection.End.Column));
                }

                //Bottom Right
                if (this.End.Row > intersection.End.Row &&
                    this.End.Column > intersection.End.Column)
                {
                    excluded.Add(new GridRange(intersection.End.Row + 1, intersection.End.Column + 1, this.End.Row, this.End.Column));
                }
            }

            return(excluded);
        }