Esempio n. 1
0
/*
 *              /// <summary>
 *              /// Move the position of the object at the specified index
 *              /// to the new relative position in the list.</summary>
 *              /// <remarks>For Graphic type objects, this method controls the
 *              /// Z-Order of the items.  Objects at the beginning of the list
 *              /// appear in front of objects at the end of the list.</remarks>
 *              /// <param name="index">The zero-based index of the object
 *              /// to be moved.</param>
 *              /// <param name="relativePos">The relative number of positions to move
 *              /// the object.  A value of -1 will move the
 *              /// object one position earlier in the list, a value
 *              /// of 1 will move it one position later.  To move an item to the
 *              /// beginning of the list, use a large negative value (such as -999).
 *              /// To move it to the end of the list, use a large positive value.
 *              /// </param>
 *              /// <returns>The new position for the object, or -1 if the object
 *              /// was not found.</returns>
 *              public int Move( int index, int relativePos )
 *              {
 *                      if ( index < 0 || index >= Count )
 *                              return -1;
 *
 *                      GraphObj graphObj = this[index];
 *                      this.RemoveAt( index );
 *
 *                      index += relativePos;
 *                      if ( index < 0 )
 *                              index = 0;
 *                      if ( index > Count )
 *                              index = Count;
 *
 *                      Insert( index, graphObj );
 *                      return index;
 *              }
 */
        #endregion

        #region Render Methods

        /// <summary>
        /// Render text to the specified <see cref="Graphics"/> device
        /// by calling the Draw method of each <see cref="GraphObj"/> object in
        /// the collection.
        /// </summary>
        /// <remarks>This method is normally only called by the Draw method
        /// of the parent <see cref="GraphPane"/> object.
        /// </remarks>
        /// <param name="g">
        /// A graphic device object to be drawn into.  This is normally e.Graphics from the
        /// PaintEventArgs argument to the Paint() method.
        /// </param>
        /// <param name="pane">
        /// A reference to the <see cref="PaneBase"/> object that is the parent or
        /// owner of this object.
        /// </param>
        /// <param name="scaleFactor">
        /// The scaling factor to be used for rendering objects.  This is calculated and
        /// passed down by the parent <see cref="GraphPane"/> object using the
        /// <see cref="PaneBase.CalcScaleFactor"/> method, and is used to proportionally adjust
        /// font sizes, etc. according to the actual size of the graph.
        /// </param>
        /// <param name="zOrder">A <see cref="ZOrder"/> enumeration that controls
        /// the placement of this <see cref="GraphObj"/> relative to other
        /// graphic objects.  The order of <see cref="GraphObj"/>'s with the
        /// same <see cref="ZOrder"/> value is control by their order in
        /// this <see cref="GraphObjList"/>.</param>
        public void Draw(Graphics g, PaneBase pane, float scaleFactor,
                         ZOrder zOrder)
        {
            // Draw the items in reverse order, so the last items in the
            // list appear behind the first items (consistent with
            // CurveList)
            for (int i = this.Count - 1; i >= 0; i--)
            {
                GraphObj item = this[i];
                if (item.ZOrder == zOrder && item.IsVisible)
                {
                    Region region = null;
                    if (item.IsClippedToChartRect && pane is GraphPane)
                    {
                        region = g.Clip.Clone();
                        g.SetClip(((GraphPane)pane).Chart._rect);
                    }

                    item.Draw(g, pane, scaleFactor);

                    if (item.IsClippedToChartRect && pane is GraphPane)
                    {
                        g.Clip = region;
                    }
                }
            }
        }
Esempio n. 2
0
        /// <summary>
        /// Render text to the specified <see cref="Graphics"/> device
        /// by calling the Draw method of each <see cref="GraphObj"/> object in
        /// the collection.
        /// </summary>
        /// <remarks>This method is normally only called by the Draw method
        /// of the parent <see cref="GraphPane"/> object.
        /// </remarks>
        /// <param name="g">
        /// A graphic device object to be drawn into.  This is normally e.Graphics from the
        /// PaintEventArgs argument to the Paint() method.
        /// </param>
        /// <param name="pane">
        /// A reference to the <see cref="PaneBase"/> object that is the parent or
        /// owner of this object.
        /// </param>
        /// <param name="scaleFactor">
        /// The scaling factor to be used for rendering objects.  This is calculated and
        /// passed down by the parent <see cref="GraphPane"/> object using the
        /// <see cref="PaneBase.CalcScaleFactor"/> method, and is used to proportionally adjust
        /// font sizes, etc. according to the actual size of the graph.
        /// </param>
        /// <param name="zOrder">A <see cref="ZOrder"/> enumeration that controls
        /// the placement of this <see cref="GraphObj"/> relative to other
        /// graphic objects.  The order of <see cref="GraphObj"/>'s with the
        /// same <see cref="ZOrder"/> value is control by their order in
        /// this <see cref="GraphObjList"/>.</param>
        public void Draw(Graphics g, PaneBase pane, float scaleFactor,
                         ZOrder zOrder)
        {
            GraphPane graphPane = pane as GraphPane;
            int       minX      = int.MinValue;
            int       maxX      = int.MaxValue;
            int       minY      = int.MinValue;
            int       maxY      = int.MaxValue;
            bool      isOptDraw = false;

            if (graphPane != null)
            {
                isOptDraw = true;
                minX      = (int)graphPane.Chart.Rect.Left;
                maxX      = (int)graphPane.Chart.Rect.Right;
                minY      = (int)graphPane.Chart.Rect.Top;
                maxY      = (int)graphPane.Chart.Rect.Bottom;
                if (isOptDraw)
                {
                    if (isPixelDrawn == null)
                    {
                        isPixelDrawn = new MultiDimBitArray(maxX, maxY);
                    }
                    else
                    {
                        isPixelDrawn.TryResize(maxX, maxY);
                    }
                }
            }



            // Draw the items in reverse order, so the last items in the
            // list appear behind the first items (consistent with
            // CurveList)
            List <GraphObj> graphObjs = zOrderList[(int)zOrder];

            for (int i = graphObjs.Count - 1; i >= 0; i--)
            {
                GraphObj item = graphObjs[i];
                PointF   pix  = item.Location.Transform(pane);
                if (item.ZOrder == zOrder && item.IsVisible &&
                    pix.X >= minX && pix.X <= maxX &&
                    pix.Y >= minY && pix.Y <= maxY)
                {
                    // Don't try to draw where we already drew.
                    // This is a huge optimization when there are
                    // many more draw items than pixels in the rectangle.
                    if (isPixelDrawn[(int)pix.X, (int)pix.Y])
                    {
                        continue;
                    }
                    isPixelDrawn[(int)pix.X, (int)pix.Y] = true;

                    Region region = null;
                    if (item.IsClippedToChartRect && pane is GraphPane)
                    {
                        region = g.Clip.Clone();
                        g.SetClip(((GraphPane)pane).Chart._rect);
                    }

                    item.Draw(g, pane, scaleFactor);

                    if (item.IsClippedToChartRect && pane is GraphPane)
                    {
                        g.Clip = region;
                    }
                }
            }
        }