Пример #1
0
        /// <summary>
        /// Distributes the TextIcons, when they are overlapping
        /// </summary>
        public void TextIconsDistribute()
        {
            List <Rectangle>      occupiedPosition = new List <Rectangle>();
            IComparer <Rectangle> byViewPos        = new ByViewPosition();

            foreach (var item in TextIconList)
            {
                item.ViewOffset = item.DefaultViewOffset;
            }

            //Consolidate TextIcons that share the same position and name
            TextIconList.Sort();
            int ListLength       = TextIconList.Count;
            int TextIconQuantity = 1;

            for (int i = 1; i < ListLength; i++)
            {
                if (TextIconList[i - 1].CompareTo(TextIconList[i]) == 0)
                {
                    TextIconQuantity++;
                    TextIconList.RemoveAt(i);
                    i--;
                    ListLength--;
                }
                else if (TextIconQuantity > 1)
                {
                    TextIconList[i - 1].name += " x" + TextIconQuantity;
                    TextIconQuantity          = 1;
                }
            }

            //Placement happens bottom to top, left to right
            //Each newly placed Texticon is compared to only the Texticons that are placed above its position
            //Therefore a sorted list of the occupied Positions is maintained
            occupiedPosition.Add(TextIconList[0].ViewDisplayRect);
            for (int i = 1; i < TextIconList.Count; i++)
            {
                var lowestPosIndex = occupiedPosition.BinarySearch(TextIconList[i].ViewDisplayRect + new Point(0, (int)TextIconList[i].ViewNameSize.Height), byViewPos);
                if (lowestPosIndex < 0)
                {
                    lowestPosIndex = ~lowestPosIndex;
                }

                for (int j = lowestPosIndex; j < occupiedPosition.Count; j++)
                {
                    if (TextIconList[i].ViewDisplayRect.Intersects(occupiedPosition[j]))
                    {
                        TextIconList[i].ViewOffset -= new PointF(0, TextIconList[i].ViewDisplayRect.Bottom - occupiedPosition[j].Top);
                    }
                }
                //Inserts the new label sorted
                var InsertIndex = occupiedPosition.BinarySearch(TextIconList[i].ViewDisplayRect, byViewPos);
                if (InsertIndex < 0)
                {
                    InsertIndex = ~InsertIndex;
                }
                occupiedPosition.Insert(InsertIndex, TextIconList[i].ViewDisplayRect);
            }
        }
Пример #2
0
        /// <summary>
        /// Distributes the TextIcons, when they are overlapping
        /// </summary>
        public void TextIconsDistribute()
        {
            if (TextIconList.Count == 0)
            {
                return;
            }
            var occupiedPosition            = new List <Rectangle>();
            IComparer <Rectangle> byViewPos = new ByViewPosition();
            var textIconList = new List <TextIcon>(TextIconList.Values);

            foreach (var item in TextIconList.Values)
            {
                item.ViewOffset = item.DefaultViewOffset;
            }

            //Consolidate TextIcons that share the same position and name
            textIconList.Sort();
            int listLength       = textIconList.Count;
            int textIconQuantity = 1;

            for (int i = 1; i < listLength; i++)
            {
                if (textIconList[i - 1].CompareTo(textIconList[i]) == 0)
                {
                    textIconQuantity++;
                    textIconList.RemoveAt(i);
                    i--;
                    listLength--;
                }
                else if (textIconQuantity > 1)
                {
                    textIconList[i - 1].name += " x" + textIconQuantity;
                    textIconQuantity          = 1;
                }
            }

            //Placement happens bottom to top, left to right
            //Each newly placed Texticon is compared to only the Texticons that are placed above its position
            //Therefore a sorted list of the occupied Positions is maintained
            occupiedPosition.Add(textIconList[0].ViewDisplayRect);


            List <TextIcon> texiconsCopy = TextIconList.Values.ToList();
            int             numTextIcons = texiconsCopy.Count;

            for (int i = 1; i < numTextIcons; i++)
            {
                var item           = texiconsCopy[i];
                int lowestPosIndex = occupiedPosition.BinarySearch(item.ViewDisplayRect + new Point(0, (int)item.ViewNameSize.Height), byViewPos);
                int lpi            = lowestPosIndex;
                if (lowestPosIndex < 0)
                {
                    lpi = ~lowestPosIndex;
                }

                for (int j = lpi; j < occupiedPosition.Count; j++)
                {
                    if (item.ViewDisplayRect.Intersects(occupiedPosition[j]))
                    {
                        item.ViewOffset -= new PointF(0, item.ViewDisplayRect.Bottom - occupiedPosition[j].Top);
                    }
                }
                //Inserts the new label sorted
                int insertIndex = occupiedPosition.BinarySearch(item.ViewDisplayRect, byViewPos);
                if (insertIndex < 0)
                {
                    insertIndex = ~insertIndex;
                }
                occupiedPosition.Insert(insertIndex, item.ViewDisplayRect);
            }
        }