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); }
protected override int Render(YGraphics g, int w, int h) { ViewPortSettings mainViewPort = new ViewPortSettings() { IRLx = 0, IRLy = 0, zoomx = 1.0, zoomy = 1.0, Lmargin = 0, Rmargin = 0, Tmargin = 0, Bmargin = 0, Capture = false }; mainViewPort.Lmargin = 0; mainViewPort.Rmargin = 0; mainViewPort.Tmargin = 0; mainViewPort.Bmargin = 0; g.SmoothingMode = SmoothingMode.HighQuality; g.TextRenderingHint = System.Drawing.Text.TextRenderingHint.AntiAlias; StringFormat stringFormat4Sizing = new StringFormat(StringFormatFlags.NoClip); StringFormat stringFormat = new StringFormat(StringFormatFlags.NoClip); stringFormat.Alignment = StringAlignment.Center; stringFormat.LineAlignment = StringAlignment.Center; drawAnnotationPanels(g, _annotationPanels, w, h, false, ref mainViewPort); g.TextRenderingHint = System.Drawing.Text.TextRenderingHint.AntiAlias; double xcenter = mainViewPort.Lmargin + (w - mainViewPort.Lmargin - mainViewPort.Rmargin) / 2; double ycenter = mainViewPort.Tmargin + (h - mainViewPort.Tmargin - mainViewPort.Bmargin) / 2; double radius = Math.Min((w - mainViewPort.Lmargin - mainViewPort.Rmargin) / 2, (h - mainViewPort.Tmargin - mainViewPort.Bmargin) / 2) - borderThickness; int circonference = (int)(2 * radius * 3.14); double AngleAperture = 4 * 2 * Math.PI / 5; if (_path == null) { double outterlength = (2 * radius * Math.PI); int stepCount = (int)(outterlength / SegmentMaxLength); double stepsize = (2 * Math.PI) / stepCount; _path = new PointF[stepCount]; int n = 0; for (int i = 0; i < stepCount; i++) { double a = (2 * i * Math.PI) / stepCount; _path[n++] = new PointF((Single)(xcenter + radius * Math.Cos(a)), (Single)(ycenter - radius * Math.Sin(a))); } } if (_bgBrush == null) { _bgBrush = new LinearGradientBrush(new Point(0, (int)(ycenter - radius)), new Point(0, (int)(ycenter + radius)), _backgroundColor1, _backgroundColor2); } if (_borderpen == null) { _borderpen = new Pen(_borderColor, (float)_borderThickness); _borderpen.LineJoin = LineJoin.Round; } if (_path.Length > 3) { g.FillPolygon(_bgBrush, _path); } if (_graduationPen == null) { _graduationPen = new Pen(_graduationColor, (float)_graduationThickness); } if (_subgraduationPen == null) { _subgraduationPen = new Pen(_subgraduationColor, (float)_subgraduationThickness); } // draw unit string unitDesc = ((_unitFactor != 1) ? "x" + _unitFactor.ToString() + " " : "") + _unit; SizeF size = g.MeasureString(unitDesc.ToString(), _unitFont.fontObject, 10000, stringFormat4Sizing); Rectangle unitPos = new Rectangle((int)(xcenter - size.Width / 2), (int)(ycenter + radius / 2 - size.Height / 2), (int)(size.Width + 1), (int)(size.Height + 1)); g.DrawString(unitDesc, _unitFont.fontObject, _unitFont.brushObject, unitPos, stringFormat); // draw status line if (_statusLine != "") { size = g.MeasureString(_statusLine, _statusFont.fontObject, 10000, stringFormat4Sizing); Rectangle statusPos = new Rectangle((int)(xcenter - size.Width / 2), (int)(ycenter - radius / 3 - size.Height / 2), (int)(size.Width + 1), (int)(size.Height + 1)); g.DrawString(_statusLine, _statusFont.fontObject, _statusFont.brushObject, statusPos, stringFormat); } double firstGraduation; int gratuationCount; double Angle, C, S, R1, R2; double outerCoef = _graduationOuterRadiusSize / 100; // draw zones for (int i = 0; i < _zones.Count; i++) { if (_zones[i].visible) { if (_zones[i].path == null) { double zmin = Math.Max(_min, Math.Min(_max, _zones[i].min)); double zmax = Math.Max(_min, Math.Min(_max, _zones[i].max)); if (zmax > zmin) { double zOuterCoef = _zones[i].outerRadius / 100; double Angle1 = ((Math.PI - AngleAperture) / 2) + AngleAperture * (zmin - _min) / (_max - _min); double Angle2 = ((Math.PI - AngleAperture) / 2) + AngleAperture * (zmax - _min) / (_max - _min); double outterlength = (Angle2 - Angle1) * radius; int stepCount = (int)(outterlength / SegmentMaxLength); if (stepCount < 2) { stepCount = 2; } _zones[i].setPathSize(2 * stepCount + 2); PointF[] Path = new PointF[2 * stepCount + 2]; for (int j = 0; j <= stepCount; j++) { double A = Angle1 + ((Angle2 - Angle1) * j) / stepCount; _zones[i].setPathPoint(j, new PointF((float)(xcenter - radius * zOuterCoef * Math.Cos(A)), (float)(ycenter - radius * zOuterCoef * Math.Sin(A)))); } double innerRadiusCoef = zOuterCoef - (_zones[i].width / 100); for (int j = stepCount; j >= 0; j--) { double A = Angle1 + ((Angle2 - Angle1) * j) / stepCount; _zones[i].setPathPoint(2 * stepCount + 1 - j, new PointF((float)(xcenter - radius * innerRadiusCoef * Math.Cos(A)), (float)(ycenter - radius * innerRadiusCoef * Math.Sin(A)))); } } } if (_zones[i].path != null) { g.FillPolygon(_zones[i].zoneBrush, _zones[i].path); } } } firstGraduation = _graduation * (int)(_min / _graduation); if (_min < 0) { firstGraduation -= _graduation; } while (firstGraduation < _min) { firstGraduation += _graduation; } gratuationCount = (int)((_max - _min) / _graduation) + 1; // draw sub graduations if ((_subgraduationCount > 0) && ((_subgraduationCount * gratuationCount) < circonference)) { double subgraduation = _graduation / _subgraduationCount; firstGraduation = subgraduation * (int)(_min / subgraduation); if (_min < 0) { firstGraduation -= subgraduation; } while (firstGraduation < _min) { firstGraduation += subgraduation; } gratuationCount = (int)((_max - _min) / subgraduation) + 1; for (int i = 0; i < gratuationCount; i++) { double value = firstGraduation + i * subgraduation; if (value <= _max) { Angle = ((Math.PI - AngleAperture) / 2) + AngleAperture * (value - _min) / (_max - _min); C = Math.Cos(Angle); S = Math.Sin(Angle); R1 = (outerCoef * (radius - _borderThickness / 2)); R2 = (100 - _subgraduationSize) * (outerCoef * (radius - _borderThickness / 2)) / 100; g.DrawLine(_subgraduationPen, (float)(xcenter - R1 * C), (float)(ycenter - R1 * S), (float)(xcenter - R2 * C), (float)(ycenter - R2 * S)); } } } // draw Main graduations if (gratuationCount < circonference) // stop drawing graduation if too many { for (int i = 0; i < gratuationCount; i++) { double gvalue = firstGraduation + i * _graduation; if (gvalue <= _max) { Angle = ((Math.PI - AngleAperture) / 2) + AngleAperture * (gvalue - _min) / (_max - _min); C = Math.Cos(Angle); S = Math.Sin(Angle); R1 = (outerCoef * (radius - _borderThickness / 2)); R2 = (100 - _graduationSize) * (outerCoef * (radius - _borderThickness / 2)) / 100; g.DrawLine(_graduationPen, (float)(xcenter - R1 * C), (float)(ycenter - R1 * S), (float)(xcenter - R2 * C), (float)(ycenter - R2 * S)); size = g.MeasureString(gvalue.ToString().Trim(), _graduationFont.fontObject, 1000, stringFormat4Sizing); double HalfDiagonal = 0.4 * Math.Sqrt(size.Width * size.Width + size.Height * size.Height); Rectangle position = new Rectangle((int)(xcenter - (R2 - HalfDiagonal) * C - (size.Width / 2)), (int)(ycenter - (R2 - HalfDiagonal) * S - (size.Height / 2)), (int)size.Width + 1, (int)size.Height); // g.DrawRectangle(new Pen(Color.Red, 1), position); g.DrawString(gvalue.ToString(), _graduationFont.fontObject, _graduationFont.brushObject, position, stringFormat); } } } // draw Border if ((_borderThickness > 0) && (_path.Length > 3)) { g.DrawPolygon(_borderpen, _path); } drawAnnotationPanels(g, _annotationPanels, w, h, true, ref mainViewPort); // draw Needle if (_showNeedle) { if (_needleValue != _value) { double step = _unitFactor * _needleMaxSpeed * (_max - _min) / 100; if (Math.Abs(_value - _needleValue) < step) { _needleValue = _value; } else if (_needleValue < value) { _needleValue += step; } else { _needleValue -= step; } } double needlevalue = _needleValue / _unitFactor; double allowedOverflow = (_max - min) * 0.05; if (needlevalue < _min - allowedOverflow) { needlevalue = _min - allowedOverflow; } if (needlevalue > _max + allowedOverflow) { needlevalue = _max + allowedOverflow; } Angle = ((Math.PI - AngleAperture) / 2) + AngleAperture * (needlevalue - _min) / (_max - _min); C = Math.Cos(Angle); S = Math.Sin(Angle); R1 = (radius * _needleLength1) / 100; R2 = (radius * _needleLength2) / 100; double R3 = (radius * _needleWidth) / 200; PointF[] needlepath = new PointF[4]; needlepath[0] = new PointF((float)(xcenter - R1 * C), (float)(ycenter - R1 * S)); needlepath[1] = new PointF((float)(xcenter + R3 * S), (float)(ycenter - R3 * C)); needlepath[2] = new PointF((float)(xcenter + R2 * C), (float)(ycenter + R2 * S)); needlepath[3] = new PointF((float)(xcenter - R3 * S), (float)(ycenter + R3 * C)); if (_needleBrush == null) { _needleBrush = new SolidBrush(_needleColor); } g.FillPolygon(_needleBrush, needlepath); if (_needleContourThickness > 0) { if (_needleContourPen == null) { _needleContourPen = new Pen(_needleContourColor, (float)_needleContourThickness); _needleContourPen.StartCap = LineCap.Round; _needleContourPen.EndCap = LineCap.Round; _needleContourPen.LineJoin = LineJoin.Round; } PointF[] needlepath2 = new PointF[5]; needlepath2[0] = needlepath[0]; needlepath2[1] = needlepath[1]; needlepath2[2] = needlepath[2]; needlepath2[3] = needlepath[3]; needlepath2[4] = needlepath[0]; g.DrawLines(_needleContourPen, needlepath2); } } DrawMessagePanels(g, w, h); return(0); }