Beispiel #1
0
        /// <summary>
        /// Create a fill brush using current properties.  This method will construct a brush based on the
        /// settings of <see cref="ZedGraph.Fill.Type"/>, <see cref="ZedGraph.Fill.Color"/>
        /// and <see cref="ZedGraph.Fill.Brush"/>.  If
        /// <see cref="ZedGraph.Fill.Type"/> is set to <see cref="ZedGraph.FillType.Brush"/> and
        /// <see cref="ZedGraph.Fill.Brush"/>
        /// is null, then a <see cref="LinearGradientBrush"/> will be created between the colors of
        /// <see cref="System.Drawing.Color.White"/> and <see cref="ZedGraph.Fill.Color"/>.
        /// </summary>
        /// <param name="rect">A rectangle that bounds the object to be filled.  This determines
        /// the start and end of the gradient fill.</param>
        /// <param name="dataValue">The data value to be used for a value-based
        /// color gradient.  This is only applicable for <see cref="FillType.GradientByX"/>,
        /// <see cref="FillType.GradientByY"/> or <see cref="FillType.GradientByZ"/>.</param>
        /// <returns>A <see cref="System.Drawing.Brush"/> class representing the fill brush</returns>
        public Brush MakeBrush( RectangleF rect, PointPair dataValue )
        {
            // get a brush
            if ( this.IsVisible && ( !_color.IsEmpty || _brush != null ) )
            {
                if ( rect.Height < 1.0F )
                    rect.Height = 1.0F;
                if ( rect.Width < 1.0F )
                    rect.Width = 1.0F;

                //Brush	brush;
                if ( _type == FillType.Brush )
                {
                    return ScaleBrush( rect, _brush, _isScaled );
                }
                else if ( IsGradientValueType )
                {
                    if ( dataValue != null )
                    {
                        if ( !_secondaryValueGradientColor.IsEmpty )
                        {
                            // Go ahead and create a new Fill so we can do all the scaling, etc.,
                            // that is associated with a gradient
                            Fill tmpFill = new Fill( _secondaryValueGradientColor,
                                    GetGradientColor( dataValue ), _angle );
                            return tmpFill.MakeBrush( rect );
                        }
                        else
                            return new SolidBrush( GetGradientColor( dataValue ) );
                    }
                    else if ( _rangeDefault != double.MaxValue )
                    {
                        if ( !_secondaryValueGradientColor.IsEmpty )
                        {
                            // Go ahead and create a new Fill so we can do all the scaling, etc.,
                            // that is associated with a gradient
                            Fill tmpFill = new Fill( _secondaryValueGradientColor,
                                    GetGradientColor( _rangeDefault ), _angle );
                            return tmpFill.MakeBrush( rect );
                        }
                        else
                            return new SolidBrush( GetGradientColor( _rangeDefault ) );
                    }
                    else
                        return ScaleBrush( rect, _brush, true );
                }
                else
                    return new SolidBrush( _color );
            }

            // Always return a suitable default
            return new SolidBrush( Color.White );
        }
Beispiel #2
0
        /// <summary>
        /// Do all rendering associated with this <see cref="GasGaugeNeedle"/> item to the specified
        /// <see cref="Graphics"/> device. This method is normally only
        /// called by the Draw method of the parent <see cref="ZedGraph.CurveList"/>
        /// collection object.
        /// </summary>
        /// <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="ZedGraph.GraphPane"/> object that is the parent or
        /// owner of this object.
        /// </param>
        /// <param name="pos">Not used for rendering GasGaugeNeedle</param>
        /// <param name="scaleFactor">Not used for rendering GasGaugeNeedle</param>
        public override void Draw( Graphics g, GraphPane pane, int pos, float scaleFactor )
        {
            if ( pane.Chart._rect.Width <= 0 && pane.Chart._rect.Height <= 0 )
            {
                _slicePath = null;
            }
            else
            {
                CalcRectangle( g, pane, scaleFactor, pane.Chart._rect );

                _slicePath = new GraphicsPath();

                if ( !_isVisible )
                    return;

                RectangleF tRect = _boundingRectangle;

                if ( tRect.Width >= 1 && tRect.Height >= 1 )
                {
                    SmoothingMode sMode = g.SmoothingMode;
                    g.SmoothingMode = SmoothingMode.AntiAlias;

                    Matrix matrix = new Matrix();

                    matrix.Translate( tRect.X + ( tRect.Width / 2 ), tRect.Y + ( tRect.Height / 2 ), MatrixOrder.Prepend );

                    PointF[] pts = new PointF[2];
                    pts[0] = new PointF( ( ( tRect.Height * .10f ) / 2.0f ) * (float)Math.Cos( -SweepAngle * Math.PI / 180.0f ),
                    ( ( tRect.Height * .10f ) / 2.0f ) * (float)Math.Sin( -SweepAngle * Math.PI / 180.0f ) );
                    pts[1] = new PointF( ( tRect.Width / 2.0f ) * (float)Math.Cos( -SweepAngle * Math.PI / 180.0f ),
                    ( tRect.Width / 2.0f ) * (float)Math.Sin( -SweepAngle * Math.PI / 180.0f ) );

                    matrix.TransformPoints( pts );

                    Pen p = new Pen( NeedleColor, ( ( tRect.Height * .10f ) / 2.0f ) );
                    p.EndCap = LineCap.ArrowAnchor;
                    g.DrawLine( p, pts[0].X, pts[0].Y, pts[1].X, pts[1].Y );

                    //Fill center 10% with Black dot;
                    Fill f = new Fill( Color.Black );
                    RectangleF r = new RectangleF( ( tRect.X + ( tRect.Width / 2 ) ) - 1.0f, ( tRect.Y + ( tRect.Height / 2 ) ) - 1.0f, 1.0f, 1.0f );
                    r.Inflate( ( tRect.Height * .10f ), ( tRect.Height * .10f ) );
                    Brush b = f.MakeBrush( r );
                    g.FillPie( b, r.X, r.Y, r.Width, r.Height, 0.0f, -180.0f );

                    Pen borderPen = new Pen( Color.White, 2.0f );
                    g.DrawPie( borderPen, r.X, r.Y, r.Width, r.Height, 0.0f, -180.0f );

                    g.SmoothingMode = sMode;
                }
            }
        }