示例#1
0
        public YSolidGauge(PictureBox ChartContainer, DisplayMode mode, logFct logFunction) : base(ChartContainer, logFunction)
        {
            this._minMaxFont = new YFontParams(this, this, Math.Min(ChartContainer.Width, ChartContainer.Height) / 15, FontsizeChange);
            _displayMode     = mode;
            this._font       = new YFontParams(this, this, Math.Min(ChartContainer.Width, ChartContainer.Height) / 5, null);


            YGraphics     g = new YGraphics(ChartContainer);
            DrawPrameters p = ComputeDrawParameters(g, UIContainer.Size.Width, UIContainer.Size.Height, mainViewPort);

            g.Dispose();

            AllowRedraw();
            Draw();
        }
示例#2
0
        protected override int Render(YGraphics g, int w, int h)
        {
            mainViewPort = new ViewPortSettings()
            {
                IRLx = 0, IRLy = 0, zoomx = 1.0, zoomy = 1.0, Lmargin = 0, Rmargin = 0, Tmargin = 0, Bmargin = 0, Capture = false
            };

            g.SmoothingMode     = SmoothingMode.HighQuality;
            g.TextRenderingHint = System.Drawing.Text.TextRenderingHint.AntiAlias;

            drawAnnotationPanels(g, _annotationPanels, w, h, false, ref mainViewPort);

            DrawPrameters p = ComputeDrawParameters(g, w, h, mainViewPort);


            if (_path == null)
            {
                double outterlength = (2 * p.outerRadius * Math.PI) * (p.angleEnd - p.angleStart) / (2 * Math.PI);
                int    stepCount    = (int)(outterlength / SegmentMaxLength);
                double stepsize     = (p.angleEnd - p.angleStart) / stepCount;
                _path = new PointF[2 * (stepCount + 1)];
                int n = 0;
                for (int i = 0; i <= stepCount; i++)
                {
                    double a = p.angleStart + i * stepsize;
                    _path[n++] = new PointF((Single)(p.xcenter + p.outerRadius * Math.Cos(a)), (Single)(p.ycenter - p.outerRadius * Math.Sin(a)));
                }
                for (int i = stepCount; i >= 0; i--)
                {
                    double a = p.angleStart + i * stepsize;
                    _path[n++] = new PointF((Single)(p.xcenter + p.innerRadius * Math.Cos(a)), (Single)(p.ycenter - p.innerRadius * Math.Sin(a)));
                }
            }

            if (_bgBrush == null)
            {
                _bgBrush = new LinearGradientBrush(new Point(0, (int)(p.ycenter - p.heightTop)),
                                                   new Point(0, (int)(p.ycenter + p.heightBottom)), _backgroundColor1, _backgroundColor2);
            }



            if (_borderpen == null)
            {
                _borderpen          = new Pen(_borderColor, (float)_borderThickness);
                _borderpen.LineJoin = LineJoin.Round;
            }

            g.FillPolygon(_bgBrush, _path);


            if (_shownValue != _value)
            {
                double step = _maxSpeed * (_max - _min) / 100;
                if (Math.Abs(_value - _shownValue) < step)
                {
                    _shownValue = _value;
                }
                else if (_shownValue < _value)
                {
                    _shownValue += step;
                }
                else
                {
                    _shownValue -= step;
                }
            }



            double v = _shownValue;

            if (v >= _min)
            {
                if (v > _max)
                {
                    v = _max;
                }
                double   valueFactor  = (v - _min) / (_max - min);
                double   angleValue   = p.angleStart + (p.angleEnd - p.angleStart) * valueFactor;
                double   outterlength = (2 * p.outerRadius * Math.PI) * (angleValue - p.angleStart) / (2 * Math.PI);
                int      stepCount    = (int)(outterlength / SegmentMaxLength);
                double   stepsize     = (angleValue - p.angleStart) / stepCount;
                PointF[] pt           = new PointF[2 * (stepCount + 1)];
                int      n            = 0;
                for (int i = 0; i <= stepCount; i++)
                {
                    double a = p.angleEnd - i * stepsize;
                    pt[n++] = new PointF((Single)(p.xcenter + p.outerRadius * Math.Cos(a)), (Single)(p.ycenter - p.outerRadius * Math.Sin(a)));
                }
                for (int i = stepCount; i >= 0; i--)
                {
                    double a = p.angleEnd - i * stepsize;
                    pt[n++] = new PointF((Single)(p.xcenter + p.innerRadius * Math.Cos(a)), (Single)(p.ycenter - p.innerRadius * Math.Sin(a)));
                }
                Brush b;
                if (_color1 == _color2)
                {
                    b = new SolidBrush(_color1);
                }
                else
                {
                    int    A1 = (_color1.ToArgb() >> 24) & 0xFF;
                    double H1 = _color1.GetHue();
                    double S1 = _color1.GetSaturation();
                    double L1 = _color1.GetBrightness();
                    int    A2 = (_color2.ToArgb() >> 24) & 0xFF;
                    double H2 = _color2.GetHue();
                    double S2 = _color2.GetSaturation();
                    double L2 = _color2.GetBrightness();
                    int    A  = ((int)Math.Round(A1 + (double)(A2 - A1) * valueFactor)) & 0xff;

                    double H;
                    if (Math.Abs(H2 - H1) <= 180)
                    {
                        H = H1 + (double)(H2 - H1) * valueFactor;
                    }
                    else
                    {
                        H = H1 + 360 + (double)(H2 - H1 + 360) * valueFactor;
                        if (H > 360)
                        {
                            H -= 360;
                        }
                    }
                    double S = S1 + (double)(S2 - S1) * valueFactor;
                    double L = L1 + (double)(L2 - L1) * valueFactor;
                    b = new SolidBrush(Color.FromArgb(A1, Ycolor.hsl2rgb((int)((255 * H) / 360), (int)(255 * S), (int)(255 * L))));
                }
                g.FillPolygon(b, pt);
            }

            if (_borderThickness > 0)
            {
                g.DrawPolygon(_borderpen, _path);
            }

            g.DrawString(lastDrawParameters.value, _font.fontObject, _font.brushObject, p.valueRectangle, p.valueFormat);

            if (_showMinMax)
            {
                //Pen pn = new Pen(Color.Red);
                //g.DrawRectangle(pn,lastDrawParameters.minValueRectangle);
                //g.DrawRectangle(pn, lastDrawParameters.maxValueRectangle);

                g.DrawString(lastDrawParameters.minValue, _minMaxFont.fontObject, _minMaxFont.brushObject, lastDrawParameters.minValueRectangle, lastDrawParameters.minValueFormat);
                g.DrawString(lastDrawParameters.maxValue, _minMaxFont.fontObject, _minMaxFont.brushObject, lastDrawParameters.maxValueRectangle, lastDrawParameters.maxValueFormat);
            }
            drawAnnotationPanels(g, _annotationPanels, w, h, true, ref mainViewPort);
            DrawMessagePanels(g, w, h);



            return(0);
        }