IntersectsWith() public method

Returns true if the specified range intersects (one or more cells) with the current range. If one of the range is empty then the return is false.
public IntersectsWith ( Range p_Range ) : bool
p_Range Range
return bool
Beispiel #1
0
        /// <summary>
        /// Draw the highlighted cells.
        /// </summary>
        /// <param name="panel"></param>
        /// <param name="graphics"></param>
        /// <param name="pRangeToRedraw">The range of cells that must be redrawed. Consider that can contains also not selected cells.</param>
        public virtual void DrawHighlight(GridSubPanel panel, DevAge.Drawing.GraphicsCache graphics, Range pRangeToRedraw)
        {
            if (mRange.IsEmpty() == false &&
                pRangeToRedraw.IntersectsWith(mRange))
            {
                System.Drawing.Rectangle rect = GetDrawingRectangle();
                if (rect != System.Drawing.Rectangle.Empty)
                {
                    System.Drawing.Rectangle rectangleToDraw = panel.RectangleGridToPanel(rect);

                    Border.DrawBorder(graphics, rectangleToDraw);
                }
            }
        }
Beispiel #2
0
		/// <summary>
		/// Query the QuadTree for items that are in the given area
		/// </summary>
		/// <returns></returns>
		public List<Range> QueryInternal(Range queryArea, bool stopOnFirst)
		{
			// create a list of the items that are found
			List<Range> results = new List<Range>();

			// this quad contains items that are not entirely contained by
			// it's four sub-quads. Iterate through the items in this quad
			// to see if they intersect.
			foreach (var item in this.Contents)
			{
				if (queryArea.IntersectsWith(item))
				{
					results.Add(item);
					if (stopOnFirst == true)
						return results;
				}
			}

			foreach (QuadTreeNode node in m_nodes)
			{
				if (node.IsEmpty)
					continue;

				// Case 1: search area completely contained by sub-quad
				// if a node completely contains the query area, go down that branch
				// and skip the remaining nodes (break this loop)
				if (node.Bounds.Contains(queryArea))
				{
					results.AddRange(node.QueryInternal(queryArea, stopOnFirst));
					break;
				}

				// Case 2: Sub-quad completely contained by search area
				// if the query area completely contains a sub-quad,
				// just add all the contents of that quad and it's children
				// to the result set. You need to continue the loop to test
				// the other quads
				if (queryArea.Contains(node.Bounds))
				{
					results.AddRange(node.SubTreeContents);
					continue;
				}

				// Case 3: search area intersects with sub-quad
				// traverse into this quad, continue the loop to search other
				// quads
				if (node.Bounds.IntersectsWith(queryArea))
				{
					results.AddRange(node.QueryInternal(queryArea, stopOnFirst));
				}
			}


			return results;
		}
Beispiel #3
0
        /// <summary>
        /// Draw the selection using the SelectionColor property over the selected cells. Draw a Border around the selection using Border and BorderMode properties.
        /// </summary>
        /// <param name="p_Panel"></param>
        /// <param name="graphics"></param>
        /// <param name="pRangeToRedraw">The range of cells that must be redrawed. Consider that can contains also not selected cells.</param>
        public virtual void DrawSelectionMask(GridSubPanel p_Panel, DevAge.Drawing.GraphicsCache graphics, Range pRangeToRedraw)
        {
            if (IsEmpty())
            {
                return;
            }

            Region     oldClip       = graphics.Graphics.Clip;
            SolidBrush brushFillMask = graphics.BrushsCache.GetBrush(BackColor);

            try
            {
                graphics.Graphics.Clip = new Region(graphics.ClipRectangle);

                Range     rangeFocus = Range.Empty;
                Rectangle rectFocus  = Rectangle.Empty;
                if (m_ActivePosition.IsEmpty() == false && pRangeToRedraw.Contains(m_ActivePosition))
                {
                    rectFocus  = p_Panel.RectangleGridToPanel(Grid.PositionToRectangle(m_ActivePosition));
                    rangeFocus = Grid.PositionToCellRange(m_ActivePosition);
                }
                Cells.ICellVirtual cellFocus = Grid.GetCell(m_ActivePosition);

                //Draw selection mask and border
                //Draw each cell separately
                if ((m_MaskStyle & SelectionMaskStyle.DrawOnlyInitializedCells) == SelectionMaskStyle.DrawOnlyInitializedCells &&
                    (MaskStyle & SelectionMaskStyle.DrawSeletionOverCells) == SelectionMaskStyle.DrawSeletionOverCells)                      //Draw Over cells enabled?
                {
                    PositionCollection selectedCells = GetCellsPositions();
                    for (int i = 0; i < selectedCells.Count; i++)
                    {
                        //if must be redrawed, is is not the cell with the focus and contains a cell
                        if (pRangeToRedraw.Contains(selectedCells[i]) && rangeFocus.Contains(selectedCells[i]) == false &&
                            Grid.GetCell(selectedCells[i]) != null)
                        {
                            Rectangle rect = p_Panel.RectangleGridToPanel(Grid.PositionToRectangle(selectedCells[i]));
                            graphics.Graphics.FillRectangle(brushFillMask, rect);
                        }
                    }
                }
                //draw all the selected ranges (Default) //Draw Over cells enabled?
                else if ((MaskStyle & SelectionMaskStyle.DrawSeletionOverCells) == SelectionMaskStyle.DrawSeletionOverCells)
                {
                    RangeCollection selectedRanges = GetRanges();
                    for (int i = 0; i < selectedRanges.Count; i++)
                    {
                        Range range = selectedRanges[i];
                        if (range.IntersectsWith(pRangeToRedraw))
                        {
                            Rectangle rect = p_Panel.RectangleGridToPanel(Grid.RangeToRectangle(range));

                            if (range.Contains(m_ActivePosition))
                            {
                                Region region = new Region(rect);
                                region.Exclude(rectFocus);
                                graphics.Graphics.FillRegion(brushFillMask, region);
                            }
                            else
                            {
                                graphics.Graphics.FillRectangle(brushFillMask, rect);
                            }
                        }
                    }
                }

                //Draw focus mask and focus border (only if there is a fucus cell and is not in editng mode)
                CellContext focusCellContext = new CellContext(Grid, m_ActivePosition, cellFocus);
                if (cellFocus != null && focusCellContext.IsEditing() == false &&
                    pRangeToRedraw.Contains(m_ActivePosition))
                {
                    //Draw Over cells enabled?
                    if ((MaskStyle & SelectionMaskStyle.DrawSeletionOverCells) == SelectionMaskStyle.DrawSeletionOverCells)
                    {
                        if (m_FocusBackColor != Color.Transparent)
                        {
                            Brush focusBrush = graphics.BrushsCache.GetBrush(m_FocusBackColor);
                            graphics.Graphics.FillRectangle(focusBrush, rectFocus);
                        }
                    }
                }

                if (focusCellContext.IsEditing() == false)
                {
                    mRangeHighlight.DrawHighlight(p_Panel, graphics, pRangeToRedraw);
                }
            }
            finally
            {
                graphics.Graphics.Clip = oldClip;
            }
        }