Exemple #1
0
 protected override void OnMouseUp(MouseEventArgs e)
 {
     base.OnMouseUp(e);
     try
     {
         Cursor = Cursors.Default;
         if (e.Button == MouseButtons.Right)
         {
             contextMenuStrip.Show(this, e.Location);
             return;
         }
         ILayerItem targetLayerItem = null;
         if (_isDraging && _dragLayerItem != null && Math.Abs(e.Location.Y - beginDrapPoint.Y) > 6)
         {
             FindFocusedLayer(e.Location, _provider);
             targetLayerItem = _focusedItem;
             if (targetLayerItem != null)
             {
                 ILayerItem parent     = FindLayerParent(targetLayerItem);
                 ILayerItem dragParent = FindLayerParent(_dragLayerItem);
                 if (parent == null)
                 {
                     return;
                 }
                 if (targetLayerItem.Equals(_dragLayerItem) || !parent.Equals(dragParent))
                 {
                     _provider.Group(_dragLayerItem, parent as ILayerItemGroup);
                     Update();
                     return;
                 }
                 int        idx          = -1;
                 ILayerItem desLayerItem = null;
                 idx          = (parent as ILayerItemGroup).Items.IndexOf(targetLayerItem);
                 desLayerItem = parent;
                 _provider.AdjustOrder(idx, _dragLayerItem);
                 Update();
             }
             return;
         }
         _dragLayerItem = null;
     }
     finally
     {
         beginDrapPoint = Point.Empty;
         _dragLayerItem = null;
         _isDraging     = false;
     }
 }
Exemple #2
0
 public ILayerItem FindParent(ILayerItem item)
 {
     foreach (ILayerItem layer in _items)
     {
         if (item.Equals(layer))
         {
             return(this);
         }
         if (layer is ILayerItemGroup)
         {
             ILayerItem parent = (layer as ILayerItemGroup).FindParent(item);
             if (parent != null)
             {
                 return(parent);
             }
         }
     }
     return(null);
 }
 public ILayerItem FindLayerParent(ILayerItem layer)
 {
     if (Items == null || Items.Count == 0)
     {
         return(null);
     }
     foreach (ILayerItem item in Items)
     {
         if (layer.Equals(item))
         {
             return(this);
         }
         if (item is ILayerItemGroup)
         {
             ILayerItem parent = (item as ILayerItemGroup).FindParent(layer);
             if (parent != null)
             {
                 return(parent);
             }
         }
     }
     return(null);
 }
Exemple #4
0
        private void DrawLayerItem(Graphics g, ILayerItem item, ref int x, ref int y, ref int maxWidth)
        {
            if (item == null)
            {
                return;
            }
            int offsetLeft = 0;

            if (item is ILayerItemGroup)
            {
                if (!_helpers.ContainsKey(item))
                {
                    _helpers.Add(item, new ItemDrawHelper());
                }
                ItemDrawHelper helper = _helpers[item];
                helper.Bounds = new Rectangle(0, y, Width, cstGroupBarHeight);
                g.FillRectangle(groupFillBrush, helper.Bounds);
                g.DrawRectangle(Pens.Gray, helper.Bounds);
                g.DrawLine(Pens.Gray, x + cstVisibleBarWidth, y, x + cstVisibleBarWidth, y + cstGroupBarHeight);
                ILayerItem itemParent = FindLayerParent(item);
                if (itemParent != null && !_provider.Equals(itemParent))
                {
                    offsetLeft = GetOffsetLeft(item);
                }
                else if (_provider.Equals(itemParent))
                {
                    offsetLeft = cstFistItemLeftBank;
                }
                helper.GroupCollpaseBounds        = new Rectangle();
                helper.GroupCollpaseBounds.X      = offsetLeft + cstVisibleBarWidth;
                helper.GroupCollpaseBounds.Y      = y + cstGroupImageTopRemainBank;
                helper.GroupCollpaseBounds.Width  = imageList.Images[cstUpIco].Width;
                helper.GroupCollpaseBounds.Height = imageList.Images[cstUpIco].Height;
                if (helper.IsCollpased)
                {
                    g.DrawImage(imageList.Images[cstUpIco], helper.GroupCollpaseBounds.X, helper.GroupCollpaseBounds.Y);
                }
                else
                {
                    g.DrawImage(imageList.Images[cstDownIco], helper.GroupCollpaseBounds.X, helper.GroupCollpaseBounds.Y);
                }
                g.DrawImage(_groupImage, offsetLeft + cstVisibleBarWidth + 22, y + cstGroupImageTopRemainBank);
                helper.VisibleBounds        = new Rectangle();
                helper.VisibleBounds.X      = 4;
                helper.VisibleBounds.Y      = y + 6;
                helper.VisibleBounds.Width  = imageList.Images[cstEyeIcoOpen].Width;
                helper.VisibleBounds.Height = imageList.Images[cstEyeIcoOpen].Height;
                if (item.IsVisible)
                {
                    g.DrawImage(imageList.Images[cstEyeIcoOpen], helper.VisibleBounds.X, helper.VisibleBounds.Y);
                }
                else
                {
                    g.DrawImage(imageList.Images[cstEyeIcoClose], helper.VisibleBounds.X, helper.VisibleBounds.Y);
                }
                int beginX = offsetLeft + cstVisibleBarWidth + 42;
                if (item.Equals(_currentLayerItem))
                {
                    g.DrawString(item.Name, Font, Brushes.Gray, offsetLeft + cstVisibleBarWidth + 42, y + cstRemainBank);
                    if (maxWidth < g.MeasureString(item.Name, Font).Width)
                    {
                        maxWidth = (int)g.MeasureString(item.Name, Font).Width + beginX;
                    }
                }
                else
                {
                    g.DrawString(item.Name, Font, Brushes.Black, offsetLeft + cstVisibleBarWidth + 42, y + cstRemainBank);
                    if (maxWidth < g.MeasureString(item.Name, Font).Width)
                    {
                        maxWidth = (int)g.MeasureString(item.Name, Font).Width + beginX;
                    }
                }
                y += cstGroupBarHeight;
                if (!helper.IsCollpased)
                {
                    foreach (ILayerItem child in (item as ILayerItemGroup).Items)
                    {
                        DrawLayerItem(g, child, ref x, ref y, ref maxWidth);
                    }
                }
            }
            else
            {
                ILayerItem itemParent = FindLayerParent(item);
                if (itemParent != null && !_provider.Equals(itemParent))
                {
                    offsetLeft = GetOffsetLeft(item);
                }
                else if (_provider.Equals(itemParent))
                {
                    offsetLeft = cstFistItemLeftBank;
                }
                if (!_helpers.ContainsKey(item))
                {
                    _helpers.Add(item, new ItemDrawHelper());
                }
                ItemDrawHelper helper = _helpers[item];
                helper.Bounds        = new Rectangle();
                helper.Bounds.X      = 0;
                helper.Bounds.Y      = y;
                helper.Bounds.Width  = Width;
                helper.Bounds.Height = cstLayerItemHeight;
                g.DrawRectangle(Pens.Gray, helper.Bounds);
                g.DrawLine(Pens.Gray, x + cstVisibleBarWidth, y, x + cstVisibleBarWidth, y + cstGroupBarHeight);
                g.DrawImage(GetImage(item), offsetLeft + cstVisibleBarWidth, y + cstRemainBank, 16, 16);
                helper.VisibleBounds        = new Rectangle();
                helper.VisibleBounds.X      = 4;
                helper.VisibleBounds.Y      = y + cstRemainBank;
                helper.VisibleBounds.Width  = imageList.Images[cstEyeIcoOpen].Width;
                helper.VisibleBounds.Height = imageList.Images[cstEyeIcoOpen].Height;
                helper.EditBounds           = new Rectangle(helper.VisibleBounds.Right + 2, helper.VisibleBounds.Y, helper.VisibleBounds.Width, helper.VisibleBounds.Height);
                if (item.IsVisible)
                {
                    g.DrawImage(imageList.Images[cstEyeIcoOpen], helper.VisibleBounds.X, helper.VisibleBounds.Y);
                }
                else
                {
                    g.DrawImage(imageList.Images[cstEyeIcoClose], helper.VisibleBounds.X, helper.VisibleBounds.Y);
                }
                //if (_editLayerItem != null && item.Equals(_editLayerItem))
                //{
                //    g.DrawImage(imageList.Images[cstEditIco], helper.EditBounds.X, helper.EditBounds.Y);
                //}
                if (item.IsSelected)
                {
                    g.DrawImage(imageList.Images[cstEditIco], helper.EditBounds.X, helper.EditBounds.Y);
                }
                int beginX = offsetLeft + cstVisibleBarWidth + imageList.ImageSize.Width + 8;
                if (item.Equals(_currentLayerItem))
                {
                    g.DrawString(item.Name, Font, Brushes.Gray, offsetLeft + cstVisibleBarWidth + imageList.ImageSize.Width + 8, y + cstRemainBank + 2);
                    if (maxWidth < g.MeasureString(item.Name, Font).Width)
                    {
                        maxWidth = (int)g.MeasureString(item.Name, Font).Width + beginX;
                    }
                }
                else
                {
                    g.DrawString(item.Name, Font, Brushes.Black, offsetLeft + cstVisibleBarWidth + imageList.ImageSize.Width + 8, y + cstRemainBank + 2);
                    if (maxWidth < g.MeasureString(item.Name, Font).Width)
                    {
                        maxWidth = (int)g.MeasureString(item.Name, Font).Width + beginX;
                    }
                }
                y         += cstLayerItemHeight;
                offsetLeft = 0;
            }
        }