Ejemplo n.º 1
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="e"></param>
        protected virtual PointF OnInitializeItem(DrawLegendItemArgs e)
        {
            if (e.Item.LegendItemVisible == false) return e.TopLeft;
            PointF topLeft = e.TopLeft;
            PointF tempTopLeft = topLeft;
            if (topLeft.Y > ControlRectangle.Bottom)
            {
                return topLeft; // drawing would be below the screen
            }
            if (topLeft.Y > ControlRectangle.Top - ItemHeight)
            {
                // Draw the item itself
                // Point tl = new Point((int)topLeft.X, (int)topLeft.Y);
                LegendBox itemBox = new LegendBox();
                _legendBoxes.Add(itemBox);
                itemBox.Item = e.Item;
                itemBox.Bounds = new Rectangle(0, (int)topLeft.Y, Width, ItemHeight);
                itemBox.Indent = (int)topLeft.X / _indentation;

                DrawPlusMinus(e.Graphics, ref tempTopLeft, itemBox);

                int ih = ItemHeight;

                if (e.Item.LegendSymbolMode == SymbolMode.Symbol)
                {
                    Size s = e.Item.GetLegendSymbolSize();
                    if (s.Height > ih) tempTopLeft.Y += 3;
                }
                if (e.Item.LegendSymbolMode == SymbolMode.Symbol || e.Item.LegendSymbolMode == SymbolMode.GroupSymbol)
                {
                    DrawSymbol(e.Graphics, ref tempTopLeft, itemBox);
                }

                if (e.Item.LegendSymbolMode == SymbolMode.Checkbox)
                {
                    DrawCheckBoxes(e.Graphics, ref tempTopLeft, itemBox);
                }

                int width = (int)e.Graphics.MeasureString(e.Item.LegendText, Font).Width;
                int dY = 0;
                if (e.Item.LegendSymbolMode == SymbolMode.Symbol)
                {
                    Size s = e.Item.GetLegendSymbolSize();
                    if (s.Height > ih) dY = (s.Height - ih) / 2;
                    tempTopLeft.Y += dY;
                }
                tempTopLeft.Y += (ih - Font.Height) / (float)2;

                itemBox.Textbox = new Rectangle((int)tempTopLeft.X, (int)topLeft.Y + dY, width, ItemHeight);
                if (itemBox.Item.IsSelected)
                {
                    if (_selection.Contains(itemBox) == false) _selection.Add(itemBox);
                    Rectangle innerBox = itemBox.Textbox;
                    innerBox.Inflate(-1, -1);
                    Brush b = HighlightBrush(innerBox);
                    e.Graphics.FillRectangle(b, innerBox);
                    b.Dispose();

                    SymbologyGlobal.DrawRoundedRectangle(e.Graphics, _highlightBorderPen, itemBox.Textbox);

                    e.Graphics.DrawString(e.Item.LegendText, Font, _selectionFontBrush, tempTopLeft);
                }
                else
                {
                    e.Graphics.DrawString(e.Item.LegendText, Font, Brushes.Black, tempTopLeft);
                }
            }
            int h = ItemHeight;
            if (e.Item.LegendSymbolMode == SymbolMode.Symbol)
            {
                Size s = e.Item.GetLegendSymbolSize();
                if (s.Height > h) h = s.Height + 6;
            }
            topLeft.Y += h;

            if (e.Item.IsExpanded)
            {
                topLeft.X += _indentation;
                if (e.Item.LegendItems != null)
                {
                    List<ILegendItem> items = e.Item.LegendItems.ToList();
                    if (e.Item is IGroup) items.Reverse(); // reverse layers because of drawing order, don't bother reversing categories.
                    foreach (ILegendItem item in items)
                    {
                        DrawLegendItemArgs args = new DrawLegendItemArgs(e.Graphics, item, e.ClipRectangle, topLeft);
                        topLeft = OnInitializeItem(args);
                        if (topLeft.Y > ControlRectangle.Bottom) break;
                    }
                }
                topLeft.X -= _indentation;
            }
            return topLeft;
        }
Ejemplo n.º 2
0
 /// <summary>
 /// Extends initialize to draw "non-selected" elements.
 /// </summary>
 /// <param name="e"></param>
 protected override void OnInitialize(PaintEventArgs e)
 {
     // draw standard background image to buffer
     base.OnInitialize(e);
     PointF topLeft = new Point(0, 0);
     if (_rootNodes == null || _rootNodes.Count == 0) return;
     _legendBoxes = new List<LegendBox>();
     foreach (ILegendItem item in _rootNodes)
     {
         DrawLegendItemArgs args = new DrawLegendItemArgs(e.Graphics, item, ClientRectangle, topLeft);
         OnInitializeItem(args);
         topLeft.Y += SizeItem((int)topLeft.X, item, e.Graphics).Height;
     }
 }