Пример #1
0
        private void IoDescEditor2_MouseDown(object sender, MouseEventArgs e)
        {
            this.Focus();

            ItemRectContainer clickedRect = FindItemRectAtControlPos(new Point(e.X, e.Y));

            if (clickedRect == null)
            {
                return;
            }
            if (!this.ctrlPressed)
            {
                this.selectedItemRects.Clear();
                this.selectedItemRects.Add(clickedRect);
            }
            else if (this.selectedItemRects.Contains(clickedRect))
            {
                this.selectedItemRects.Remove(clickedRect);
            }
            else
            {
                this.selectedItemRects.Add(clickedRect);
            }

            this.selectedItemRects.Sort((cont1, cont2) => cont1.Index.CompareTo(cont2.Index));
            CreateIoDescBitmap();
            this.Invalidate();
        }
Пример #2
0
        private ItemRectContainer FindItemRectAtControlPos(Point pos)
        {
            if (this.itemRects.Count == 0)
            {
                return(null);
            }
            int worldMousePos      = (pos.Y + vScrollBar.Value * scrollDivisor);
            ItemRectContainer rect = null;

            for (int i = worldMousePos; i >= 0; i--)
            {
                if (itemRects.ContainsKey(i))
                {
                    if (itemRects[i].ItemRect.Bottom > worldMousePos &&
                        pos.X >= itemRects[i].ItemRect.Left &&
                        pos.X <= itemRects[i].ItemRect.Right)
                    {
                        rect = itemRects[i];
                    }
                    break;
                }
            }
            return(rect);
        }
Пример #3
0
        private SortedList <int, ItemRectContainer> CreateItemRectangles(IoDescription ioDesc)
        {
            lock (syncLock)
            {
                SortedList <int, ItemRectContainer> rectList = new SortedList <int, ItemRectContainer>();
                ItemRectContainer rectContainer;
                int size;

                if (ioDesc == null || ioDesc.Size <= 0)
                {
                    return(rectList);
                }

                for (int address = 0, index = 0; address < ioDesc.Size; address++, index++)
                {
                    IoDescriptionItem item = ioDesc.GetItemAtAddress(address);
                    if (item == null)
                    {
                        size = 1;
                    }
                    else
                    {
                        size = item.Size;
                    }

                    Rectangle rect = new Rectangle(
                        vericalSpacerSize,
                        (address * byteHeight) + (index) /*+ horizontalSpacerSize*/,
                        byteWidth,
                        (byteHeight * size));

                    rectContainer          = new ItemRectContainer();
                    rectContainer.Item     = item;
                    rectContainer.ItemRect = rect;
                    rectContainer.Index    = index;
                    rectContainer.Address  = address;

                    rectList.Add(rect.Top, rectContainer);
                    address += (size - 1);
                }
                ItemRectContainer sel = null;

                if (selectedItemRects.Count == 1)
                {
                    if (selectedItemRects[0].Item != null)
                    {
                        sel = rectList.Values.FirstOrDefault(x => x.Item == selectedItemRects[0].Item);
                    }
                    else
                    {
                        sel = rectList.Values.FirstOrDefault(x => x.Address == selectedItemRects[0].Address);
                    }
                }

                this.selectedItemRects.Clear();

                if (sel != null)
                {
                    this.selectedItemRects.Add(sel);
                }

                return(rectList);
            }
        }