コード例 #1
0
ファイル: IGProcess.cs プロジェクト: mbekle/InfoGraphic
        public void PrepareItems()
        {
            if (_items.Count == 0)
            {
                return;
            }

            foreach (IGProcessItemInner pi in _items)
            {
                if (pi.Width != 0)
                {
                    continue;
                }

                if (string.IsNullOrEmpty(pi.Text) || pi.TextFont == null)
                {
                    pi.Width = DefaultItemWidht;
                }
                else
                {
                    Size textSize = TextRenderer.MeasureText(pi.Text, pi.TextFont);
                    pi.Width = (_isVertical ? textSize.Height : textSize.Width) + (_itemTextLeftRightEmptyWidth * 2);
                }
            }

            int   itemsTotalWidth = GetItemsTotalWidth();
            float itemStartX_Y    = 0;
            int   w_h             = (_isVertical ? Height : Width);

            switch (_itemAlignment)
            {
            case StringAlignment.Center: itemStartX_Y = (w_h - itemsTotalWidth) / 2; break;

            case StringAlignment.Far: itemStartX_Y = w_h - itemsTotalWidth - DefaultNearFarEmptyWidth; break;

            case StringAlignment.Near: itemStartX_Y = DefaultNearFarEmptyWidth; break;
            }

            float  x        = (_isVertical ? (Width - _itemHeight) / 2 : itemStartX_Y);
            float  y        = (_isVertical ? itemStartX_Y : (Height - _itemHeight) / 2);
            PointF location = new PointF(x, y);

            for (int i = 0; i < _items.Count; ++i)
            {
                IGProcessItemInner pItem = _items[i];
                pItem.BoundRect = new RectangleF(location, new Size((_isVertical ? _itemHeight : pItem.Width), (_isVertical ? pItem.Width : _itemHeight)));
                pItem.Origin    = new PointF(pItem.BoundRect.X + pItem.BoundRect.Width / 2, pItem.BoundRect.Y + pItem.BoundRect.Height / 2);

                if (_isVertical)
                {
                    location.Y += pItem.Width + ItemSeperatorWidth;
                }
                else
                {
                    location.X += pItem.Width + ItemSeperatorWidth;
                }
            }

            PrepareItemsGraphicsPath();
        }
コード例 #2
0
ファイル: IGProcess.cs プロジェクト: mbekle/InfoGraphic
        public IGProcessItem AddItem(
            string text,
            int width,
            Font textFont,
            Color textColor,
            StringAlignment textAlignment,
            float textAngle,
            Color backColorFrom,
            Color backColorTo,
            LinearGradientMode backColorGradientMode,
            Color lineColor,
            float lineWidth,
            Image icon)
        {
            IGProcessItemInner item = new IGProcessItemInner()
            {
                Owner                 = this,
                Text                  = text,
                Width                 = width,
                TextFont              = textFont,
                TextColor             = textColor,
                TextAlignment         = textAlignment,
                TextAngle             = textAngle,
                BackColorFrom         = (backColorFrom == Color.Empty ? Color.Blue : backColorFrom),
                BackColorTo           = backColorTo,
                BackColorGradientMode = backColorGradientMode,
                LineColor             = lineColor,
                LineWidth             = lineWidth,
                Icon                  = icon
            };

            _items.Add(item);
            return(item);
        }
コード例 #3
0
ファイル: IGProcess.cs プロジェクト: mbekle/InfoGraphic
            public void Refresh()
            {
                IGProcessItemInner item = (IGProcessItemInner)this;

                using (Graphics gr = item.Owner.CreateGraphics())
                {
                    item.Owner.ConfigureGraphics(gr);
                    item.Draw(gr);
                }
            }
コード例 #4
0
ファイル: IGProcess.cs プロジェクト: mbekle/InfoGraphic
        private void PrepareItemsGraphicsPath()
        {
            for (int i = 0; i < _items.Count; ++i)
            {
                IGProcessItemInner pItem  = _items[i];
                RectangleF         rect   = pItem.BoundRect;
                GraphicsPath       grPath = new GraphicsPath();
                bool isFirst        = (i == 0);
                bool isLast         = (i == _items.Count - 1);
                int  itemRoundWidth = (_itemRoundingShape == ItemRoundingShapeType.Circular ? _itemRoundWidth : 0);

                PointF[] points = new PointF[isFirst || isLast ? 5 : 6];

                if (isLast)
                {
                    if (_isVertical)
                    {
                        points[0] = new PointF(rect.Right, rect.Bottom - itemRoundWidth);
                        points[1] = new PointF(rect.Right, rect.Y);
                        points[2] = new PointF(rect.X + rect.Width / 2, rect.Y + _itemTriangleWidth);
                        points[3] = new PointF(rect.X, rect.Y);
                        points[4] = new PointF(rect.X, rect.Bottom - itemRoundWidth);
                    }
                    else
                    {
                        points[0] = new PointF(rect.Right - itemRoundWidth, rect.Y);
                        points[1] = new PointF(rect.X, rect.Y);
                        points[2] = new PointF(rect.X + _itemTriangleWidth, rect.Y + rect.Height / 2);
                        points[3] = new PointF(rect.X, rect.Bottom);
                        points[4] = new PointF(rect.Right - itemRoundWidth, rect.Bottom);
                    }
                }
                else
                {
                    if (_isVertical)
                    {
                        points[0] = new PointF(rect.Right, rect.Y + (isFirst ? itemRoundWidth : 0));
                        points[1] = new PointF(rect.Right, rect.Bottom - _itemTriangleWidth);
                        points[2] = new PointF(rect.X + rect.Width / 2, rect.Y + rect.Height);
                        points[3] = new PointF(rect.X, rect.Bottom - _itemTriangleWidth);
                        points[4] = new PointF(rect.X, rect.Y + (isFirst ? itemRoundWidth : 0));
                    }
                    else
                    {
                        points[0] = new PointF(rect.X + (isFirst ? itemRoundWidth : 0), rect.Y);
                        points[1] = new PointF(rect.Right - _itemTriangleWidth, rect.Y);
                        points[2] = new PointF(rect.Right, rect.Y + rect.Height / 2);
                        points[3] = new PointF(rect.Right - _itemTriangleWidth, rect.Bottom);
                        points[4] = new PointF(rect.X + (isFirst ? itemRoundWidth : 0), rect.Bottom);
                    }
                }

                if (isFirst == false && isLast == false)
                {
                    if (_isVertical)
                    {
                        points[5] = new PointF(rect.X + rect.Width / 2, rect.Y + _itemTriangleWidth);
                    }
                    else
                    {
                        points[5] = new PointF(rect.X + _itemTriangleWidth, rect.Y + rect.Height / 2);
                    }
                }

                grPath.AddLines(points);

                if ((isFirst || isLast) && _itemRoundingShape == ItemRoundingShapeType.Circular)
                {
                    int roundRectWidth = 2 * _itemRoundWidth;

                    if (_isVertical)
                    {
                        RectangleF r = new RectangleF(rect.X, (isLast ? rect.Bottom - roundRectWidth : rect.Y), rect.Width, roundRectWidth);
                        grPath.AddArc(r, 180, (isLast ? -1 : 1) * 180);
                    }
                    else
                    {
                        RectangleF r = new RectangleF((isLast ? rect.Right - roundRectWidth : rect.X), rect.Y, roundRectWidth, rect.Height);
                        grPath.AddArc(r, 90, (isLast ? -1 : 1) * 180);
                    }
                }

                grPath.CloseFigure();

                if (pItem.GrPath != null)
                {
                    pItem.GrPath.Dispose();
                }

                pItem.GrPath = grPath;
            }
        }