public RTLevel() { _title = "level"; _titlePos = GraphicsUtil.TextAlignment.left; _titleColor = Color.DimGray; titleBrush = new SolidBrush(_titleColor); _titleFont = new Font(FontFamily.GenericSansSerif, 8); _displaySize = new Size(50, 10); _valuePos = GraphicsUtil.TextAlignment.below; _valueFont = new Font(FontFamily.GenericSansSerif, 8); _valueColor = Color.DimGray; valueBrush = new SolidBrush(_valueColor); _format = "F2"; _unit = ""; _value = 0; _min = -1; _max = 1; _openAngle = 150; _frameColor = Color.DimGray; framePen = new Pen(_frameColor); _fillColor = Color.LimeGreen; fillBrush = new SolidBrush(_fillColor); _pointColor = Color.Red; pointPen = new Pen(_pointColor); _levelType = RTLevelType.LinearH; _logScale = false; gridCalculator = new GridCalculator(_min, _max, _logScale, 2 * Vector.V(displaySize).Len); gridCalculator.reScreen(-openAngle / 2, openAngle / 2); this.DoubleBuffered = true; }
void drawTo(Graphics g) { GraphicsUtil.TextPosition titlePos = new GraphicsUtil.TextPosition(); GraphicsUtil.TextPosition valuePos = new GraphicsUtil.TextPosition(); VectorRect bar = new VectorRect(); VectorRect handle = new VectorRect(); Vector vlow = Vector.Zero; Vector vhigh = Vector.Zero; getPositions(ref titlePos, ref valuePos, ref bar, ref handle, ref vlow, ref vhigh); double hlen = 0; if (_showScale) { if (_slideDirection == SlideDirection.Horizontal) { hlen = (vhigh.x - vlow.x) / scale; if (grid == null) { grid = new GridCalculator(_minVal, _maxVal, 1e-12, 1e-12, 1.1, _minVal, _maxVal, _logScale, 0, hlen, (double)_scaleFont.Height * _lableLength); } else if (grid.high != hlen) { grid.reScreen(0, hlen); } } else { hlen = (vlow.y - vhigh.y) / scale; if (grid == null) { grid = new GridCalculator(_minVal, _maxVal, 1e-12, 1e-12, 1.1, _minVal, _maxVal, _logScale, 0, hlen, (double)_scaleFont.Height); grid.showEndLables = true; } else if (grid.high != hlen) { grid.reScreen(0, hlen); } } } // Title if (_showTitle && (_title != null) && (_title.Length > 0)) { titlePos.drawText(g, _titleFont, titleBrush, _title); } // Value if (_showValue) { String s = String.Format(getFormat(), _val); if ((unit != null) && (unit.Length > 0)) { s = s + " " + unit; } valuePos.drawText(g, _valueFont, valueBrush, s); } g.DrawRectangle(penSlide, bar.rectangle); g.FillRectangle(brushSlideMark, handle.rectangle); g.DrawRectangle(penSlideMark, handle.rectangle); if (_showScale) { GraphicsUtil.drawLine(g, vlow, vhigh, scalePen); Vector vr = 0.5 * _slideScaleWidth * scale * ((vhigh - vlow).norm).vrot90(); Vector vtext = Vector.Zero; if (_slideDirection == SlideDirection.Horizontal) { vtext = Vector.V(0, _slideScaleWidth / 2 * scale); } else { vtext = Vector.V(_slideScaleWidth / 2 * scale, 0); } for (int i = 0; i < grid.gridLength; i++) { Vector vpos = vlow + (vhigh - vlow) * grid.grid[i].screen / hlen; if (grid.grid[i].isMajor) { GraphicsUtil.drawLine(g, vpos - vr, vpos + vr, scalePen); } else { GraphicsUtil.drawLine(g, vpos - vr / 2, vpos + vr / 2, scalePen); } if (_showScaleValues && grid.grid[i].show && (grid.grid[i].name.Length > 0)) { if (_slideDirection == SlideDirection.Horizontal) { GraphicsUtil.drawText(g, vpos + vtext, _scaleFont, scale, grid.grid[i].name, 0, 2, 0, 1, Vector.V(1, 0), scaleFontBrush); } else { GraphicsUtil.drawText(g, vpos + vtext, _scaleFont, scale, grid.grid[i].name, 0, 2, -1, 0, Vector.V(1, 0), scaleFontBrush); } } } } }