void drawTo(Graphics g) { // Background // Brush brushBackground = new SolidBrush(BackColor); // g.FillRectangle(brushBackground, this.ClientRectangle); Vector center = Vector.Zero; Vector size = Vector.Zero; GraphicsUtil.TextPosition titlePosition = null; getWfCoords(ref center, ref size, ref titlePosition); if (titlePosition != null) { Brush titleBrush = new SolidBrush(_titleColor); titlePosition.drawText(g, _titleFont, titleBrush, _title); } Rectangle fr = VectorRect.FromCenterSize(center, size).rectangle; g.DrawRectangle(framePen, fr.Left - 1, fr.Top - 1, fr.Width + 2, fr.Height + 2); buildMap(); updateBitmap(); InterpolationMode imode = g.InterpolationMode; PixelOffsetMode pmode = g.PixelOffsetMode; g.InterpolationMode = InterpolationMode.NearestNeighbor; g.PixelOffsetMode = PixelOffsetMode.Half; g.DrawImage(bmap, fr, 0, 0, bmap.Width, bmap.Height, GraphicsUnit.Pixel); g.InterpolationMode = imode; g.PixelOffsetMode = pmode; // needsRedraw = false; }
protected override void OnMouseUp(MouseEventArgs e) { base.OnMouseUp(e); if (dragMode == DragMode.Dial) { 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); // Hit in Dial Region double n = 0; if (_slideDirection == SlideDirection.Horizontal) { n = (e.X - vlow.x) / (vhigh.x - vlow.x); } else { n = (e.Y - vlow.y) / (vhigh.y - vlow.y); } if (n < 0) { n = 0; } if (n > 1.0) { n = 1; } if (logScale) { if ((_minVal <= 0) || (_maxVal <= 0) || (_minVal == _maxVal)) { _val = _minVal; } else { _val = Math.Exp(n * (Math.Log(_maxVal) - Math.Log(_minVal)) + Math.Log(_minVal)); } } else { _val = n * (_maxVal - _minVal) + _minVal; } newValue(); Invalidate(); dragMode = DragMode.Idle; } else { forwardOnMouseUp(e); } }
void drawTo(Graphics g) { // Background //Brush brushBackground = new SolidBrush(BackColor); //g.FillRectangle(brushBackground, this.ClientRectangle); Vector valueCenter = Vector.V(0, 0); GraphicsUtil.TextPosition tpos = new GraphicsUtil.TextPosition(); GraphicsUtil.dualSplit(ClientSize, _valueSize, scale, ref valueCenter, ref tpos, _titlePos); if (_titlePos != GraphicsUtil.TextAlignment.off) { Brush titleBrush = new SolidBrush(_titleColor); tpos.drawText(g, _titleFont, titleBrush, _title); } Rectangle valueR = VectorRect.FromCenterSize(valueCenter, Vector.V(_valueSize) * scale).rectangle; // Frame if (_drawFrame) { Pen framePen = new Pen(_frameColor); g.DrawRectangle(framePen, valueR); valueR.Inflate(-1, -1); g.SetClip(valueR); } // Value Brush textBrush = new SolidBrush(_valueColor); String s = ""; switch (_inputType) { case RTFlexInputType.String: s = _stringVal; break; case RTFlexInputType.Float: s = String.Format(getFormat(), _floatVal); if ((unit != null) && (unit.Length > 0)) { s = s + " " + unit; } break; case RTFlexInputType.Integer: s = String.Format("{0}", _intVal); if ((unit != null) && (unit.Length > 0)) { s = s + " " + unit; } break; } GraphicsUtil.drawText(g, valueCenter, _valueFont, scale, s, 0, 2, 0, 0, Vector.X, textBrush); }
void getShapeCoords(ref Rectangle r, ref GraphicsUtil.TextPosition textpos) { r = getShapeRect(); Vector tl = Vector.V(r.Location); Vector tr = Vector.V(r.Location.X + r.Width - 1, r.Location.Y + r.Height - 1); switch (_titlePos) { case RTTitlePos.TopLeft: textpos = new GraphicsUtil.TextPosition(tl, scale, -1, -1); break; case RTTitlePos.TopCenter: textpos = new GraphicsUtil.TextPosition(Vector.V((tl.x + tr.x) / 2, tl.y), scale, 0, -1); break; case RTTitlePos.TopRight: textpos = new GraphicsUtil.TextPosition(Vector.V(tr.x, tl.y), scale, 1, -1); break; case RTTitlePos.BottomLeft: if (_showXScale) { textpos = new GraphicsUtil.TextPosition(Vector.V(tl.x, Height - 1), scale, -1, -1); } else { textpos = new GraphicsUtil.TextPosition(Vector.V(tl.x, tr.y), scale, -1, 1); } break; case RTTitlePos.BottomCenter: if (_showXScale) { textpos = new GraphicsUtil.TextPosition(Vector.V((tl.x + tr.x) / 2, Height - 1), scale, 0, -1); } else { textpos = new GraphicsUtil.TextPosition(Vector.V((tl.x + tr.x) / 2, tr.y), scale, 0, 1); } break; case RTTitlePos.BottomRight: if (_showXScale) { textpos = new GraphicsUtil.TextPosition(Vector.V(tr.x, Height - 1), scale, 1, -1); } else { textpos = new GraphicsUtil.TextPosition(tr, scale, 1, -1); } break; } }
void getWfCoords(ref Vector wfCenter, ref Vector wfSize, ref GraphicsUtil.TextPosition titlePosition) { GraphicsUtil.TextAlignment ta = _titlePos; if ((_title == null) || (_title.Length < 1)) { ta = GraphicsUtil.TextAlignment.off; } Size sz = new Size(_displaySize.Width + 4, _displaySize.Height + 4); wfSize = Vector.V(_displaySize) * scale; GraphicsUtil.dualSplit(ClientSize, sz, scale, ref wfCenter, ref titlePosition, _titlePos); }
void drawTo(Graphics g) { Vector center = Vector.Zero; Vector dim = Vector.Zero; GraphicsUtil.TextPosition titlePosition = null; GraphicsUtil.TextPosition valuePosition = null; getLevelCoords(ref center, ref titlePosition, ref valuePosition, ref dim); if (titlePosition != null) { titlePosition.drawText(g, _titleFont, titleBrush, _title); } if (valuePosition != null) { string vs = getValueString(); valuePosition.drawText(g, _valueFont, valueBrush, vs); } double v = 0; try { if (_logScale) { v = (Math.Log(_value) - Math.Log(_min)) / (Math.Log(_max) - Math.Log(_min)); } else { v = (_value - _min) / (_max - _min); } } catch (Exception e) { v = 0; } switch (_levelType) { case RTLevelType.LinearH: GraphicsUtil.drawHBar(g, center, dim, v, framePen, fillBrush); break; case RTLevelType.LinearV: GraphicsUtil.drawVBar(g, center, dim, v, framePen, fillBrush); break; case RTLevelType.Rotary: GraphicsUtil.drawRotor(g, _openAngle, center, dim, v, gridCalculator, framePen, pointPen); break; } }
void drawTo(Graphics g) { // Background // Brush brushBackground = new SolidBrush(BackColor); // g.FillRectangle(brushBackground, this.ClientRectangle); Vector center = Vector.Zero; Vector size = Vector.Zero; GraphicsUtil.TextPosition titlePosition = null; getWfCoords(ref center, ref size, ref titlePosition); if (titlePosition != null) { Brush titleBrush = new SolidBrush(_titleColor); titlePosition.drawText(g, _titleFont, titleBrush, _title); } Rectangle fr = VectorRect.FromCenterSize(center, size).rectangle; g.DrawRectangle(framePen, fr.Left - 1, fr.Top - 1, fr.Width + 2, fr.Height + 2); if ((bmap == null) || (data.Length != bmap.Height * bmap.Width * 4)) { bmap = new Bitmap(_timeSteps, _ySteps, PixelFormat.Format32bppRgb); } BitmapData bmd = bmap.LockBits(new Rectangle(0, 0, bmap.Width, bmap.Height), ImageLockMode.WriteOnly, PixelFormat.Format32bppRgb); Marshal.Copy(data, 0, bmd.Scan0, bmap.Width * bmap.Height * 4); bmap.UnlockBits(bmd); InterpolationMode imode = g.InterpolationMode; PixelOffsetMode pmode = g.PixelOffsetMode; g.InterpolationMode = InterpolationMode.NearestNeighbor; g.PixelOffsetMode = PixelOffsetMode.Half; g.DrawImage(bmap, fr, 0, 0, bmap.Width, bmap.Height, GraphicsUnit.Pixel); g.InterpolationMode = imode; g.PixelOffsetMode = pmode; // needsRedraw = false; }
void getLevelCoords(ref Vector levelCenter, ref GraphicsUtil.TextPosition titlePosition, ref GraphicsUtil.TextPosition valuePosition, ref Vector dim) { switch (_levelType) { case RTLevelType.Off: dim = Vector.Zero; break; case RTLevelType.LinearH: case RTLevelType.LinearV: case RTLevelType.Rotary: dim = Vector.V(displaySize) * scale; break; } GraphicsUtil.TextAlignment ta = _titlePos; if ((_title == null) || (_title.Length < 1)) { ta = GraphicsUtil.TextAlignment.off; } GraphicsUtil.tripleSplit(ClientSize, _displaySize, scale, ref levelCenter, ref titlePosition, ta, ref valuePosition, _valuePos); }
protected override void OnMouseWheel(MouseEventArgs e) { base.OnMouseWheel(e); 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); VectorRect vr = VectorRect.containingRects(bar, handle); if (vr.inside(e.X, e.Y)) { ((HandledMouseEventArgs)e).Handled = true; if (_logScale) { if ((_minVal <= 0) || (_maxVal <= 0) || (_maxVal == _minVal)) { return; } if (_val <= 0) { return; } double v = Math.Log(_val) + (double)e.Delta / 2000 * (Math.Log(_maxVal) - Math.Log(_minVal)); if (v < Math.Log(_minVal)) { v = Math.Log(_minVal); } if (v > Math.Log(_maxVal)) { v = Math.Log(_maxVal); } _val = Math.Exp(v); Invalidate(); newValue(); } else { if (_minVal >= _maxVal) { return; } double v = _val + (double)e.Delta / 2000 * (_maxVal - _minVal); if (v < _minVal) { v = _minVal; } if (v > _maxVal) { v = _maxVal; } _val = v; Invalidate(); newValue(); } } else { forwardOnMouseWheel(e); } }
// private static double sqr(double s) { return s * s; } protected override void OnMouseDown(MouseEventArgs e) { base.OnMouseDown(e); if (e.Button != MouseButtons.Left) { return; } double scl = scale; if ((e.X < 0) || (e.X >= Width) || (e.Y < 0) || (e.Y >= Height)) { return; } if (_showValue && e.Y >= Height - 1 - valueFont.Height * scale) { // Hit in Value // Show Value Selector Window NumericInputWin dw = new NumericInputWin(this, ((_title != null) && (_title.Length > 0)) ? _title : null, ((_unit != null) && (_unit.Length > 0)) ? _unit : null, getFormat(), true, _minVal, _val, _maxVal, _logScale); dw.StartPosition = FormStartPosition.Manual; dw.Location = PointToScreen(e.Location); dw.ShowDialog(); _val = dw.value; newValue(); Invalidate(); return; } 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); VectorRect vr = VectorRect.containingRects(bar, handle); if (vr.inside(e.X, e.Y)) { // Hit in Dial Region double n = 0; if (_slideDirection == SlideDirection.Horizontal) { n = (e.X - vlow.x) / (vhigh.x - vlow.x); } else { n = (e.Y - vlow.y) / (vhigh.y - vlow.y); } if (n < 0) { n = 0; } if (n > 1.0) { n = 1; } if (logScale) { if ((_minVal <= 0) || (_maxVal <= 0) || (_minVal == _maxVal)) { _val = _minVal; } else { _val = Math.Exp(n * (Math.Log(_maxVal) - Math.Log(_minVal)) + Math.Log(_minVal)); } } else { _val = n * (_maxVal - _minVal) + _minVal; } newValue(); Invalidate(); dragMode = DragMode.Dial; dragStart = e.Location; } else { forwardOnMouseDown(e); } }
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); } } } } }
void getPositions(ref GraphicsUtil.TextPosition titlePos, ref GraphicsUtil.TextPosition valuePos, ref VectorRect bar, ref VectorRect handle, ref Vector vlow, ref Vector vhigh) { double y0 = 0; double y1 = Height - 1; if (_showTitle) { titlePos = new GraphicsUtil.TextPosition(Vector.V(Width / 2, 0), 0, 1); titlePos.scale = scale; y0 += scale * _titleFont.Height * 1.5; } else { titlePos = null; } if (_showValue) { valuePos = new GraphicsUtil.TextPosition(Vector.V(Width / 2, Height - 1), 0, -1); valuePos.scale = scale; y1 -= scale * _valueFont.Height * 1.5; } else { valuePos = null; } // Calculate the required space for the slider, the scale and the scale values double w = _slideKnob; if (_showScale) { w += _slideScaleDist; w += _slideScaleWidth; if (_showScaleValues) { if (_slideDirection == SlideDirection.Horizontal) { w += _scaleFont.Height; } else { w += _scaleFont.Height * _lableLength; } } } w *= scale; double start = 0; if (_slideDirection == SlideDirection.Horizontal) { start = (y1 + y0) / 2 - w / 2 + _slideKnob / 2 * scale; double wbar = Width - 3 * _slideWidth * scale; bar = VectorRect.FromCenterSize(Vector.V(Width / 2, start), Vector.V(Width - 2, _slideWidth * scale)); double sp = (Width / 2 - wbar / 2) + slidePos() * wbar; handle = VectorRect.FromCenterSize(Vector.V(sp, start), Vector.V(_slideWidth * scale, _slideKnob * scale)); if (_showScale) { start += _slideKnob / 2 * scale + _slideScaleDist * scale; } vlow = Vector.V(Width / 2 - wbar / 2, start); vhigh = Vector.V(Width / 2 + wbar / 2, start); } else { start = Width / 2 - w / 2 + _slideKnob / 2 * scale; double wbar = y1 - y0 - 3 * _slideWidth * scale; bar = VectorRect.FromCenterSize(Vector.V(start, (y1 + y0) / 2), Vector.V(_slideWidth * scale, y0 - y1 - 2)); double sp = (y1 + y0) / 2 + wbar / 2 - slidePos() * wbar; handle = VectorRect.FromCenterSize(Vector.V(start, sp), Vector.V(_slideKnob * scale, _slideWidth * scale)); if (_showScale) { start += _slideKnob / 2 * scale + _slideScaleDist * scale; } vlow = Vector.V(start, (y1 + y0) / 2 + wbar / 2); vhigh = Vector.V(start, (y1 + y0) / 2 - wbar / 2); } }
void drawTo(Graphics g) { // Background //Brush brushBackground = new SolidBrush(BackColor); //g.FillRectangle(brushBackground, this.ClientRectangle); Rectangle shape = new Rectangle(); GraphicsUtil.TextPosition tp = new GraphicsUtil.TextPosition(); getShapeCoords(ref shape, ref tp); if ((_titlePos != RTTitlePos.Off) && (_title != null) && (_title.Length > 0)) { Brush titleBrush = new SolidBrush(_titleColor); tp.drawText(g, _titleFont, titleBrush, _title); } Pen framePen = new Pen(_frameColor); Rectangle oshape = shape; shape.Inflate(-1, -1); double ymin = 0, ymax = 0; Vector[] l = getShape(shape, ref ymin, ref ymax); Brush scaleBrush = new SolidBrush(_scaleColor); Pen majorGridPen = new Pen(_majorGridColor); Pen minorGridPen = new Pen(_minorGridColor); for (int i = 0; i < gridY.gridLength; i++) { double y = shape.Bottom - gridY.grid[i].screen; string s = gridY.grid[i].name; if (gridY.grid[i].isMajor && _showYScale) { GraphicsUtil.drawText(g, Vector.V(shape.Left, y), _scaleFont, scale, s, 0, 2, 1, 0, Vector.X, scaleBrush); } if (gridY.grid[i].isMajor && _showMajorYGrid) { GraphicsUtil.drawLine(g, Vector.V(shape.Left, y), Vector.V(shape.Right, y), majorGridPen); } if (!gridY.grid[i].isMajor && _showMinorYGrid) { GraphicsUtil.drawLine(g, Vector.V(shape.Left, y), Vector.V(shape.Right, y), minorGridPen); } } for (int i = 0; i < gridX.gridLength; i++) { double x = shape.Left + gridX.grid[i].screen; string s = gridX.grid[i].name; if (gridX.grid[i].isMajor && showXScale) { GraphicsUtil.drawText(g, Vector.V(x, shape.Bottom), _scaleFont, scale, s, 0, 2, -1, 0, Vector.Y, scaleBrush); } if (gridX.grid[i].isMajor && _showMajorXGrid) { GraphicsUtil.drawLine(g, Vector.V(x, shape.Bottom), Vector.V(x, shape.Top), majorGridPen); } if (!gridX.grid[i].isMajor && _showMinorXGrid) { GraphicsUtil.drawLine(g, Vector.V(x, shape.Bottom), Vector.V(x, shape.Top), minorGridPen); } } g.DrawRectangle(framePen, oshape); Pen anchorPen = new Pen(_anchorColor); Brush selBrush = null; if (dragMode == DragMode.Holding) { selBrush = new SolidBrush(Color.Red); } Point[] p = new Point[l.Length]; g.SetClip(shape); for (int i = 0; i < l.Length; i++) { p[i] = l[i].Point; if (i > 0) { Rectangle A = new Rectangle(p[i].X - _anchorSize / 2, p[i].Y - _anchorSize / 2, _anchorSize, _anchorSize); if ((dragMode == DragMode.Holding) && (dragSelect == i)) { g.FillRectangle(selBrush, A); } else { g.DrawRectangle(anchorPen, A); } } } Pen shapePen = new Pen(_shapeColor); g.DrawLines(shapePen, p); }
protected override void OnMouseDown(MouseEventArgs e) { base.OnMouseDown(e); if (e.Button != MouseButtons.Left) { return; } Vector valueCenter = Vector.V(0, 0); GraphicsUtil.TextPosition tpos = new GraphicsUtil.TextPosition(); GraphicsUtil.dualSplit(ClientSize, _valueSize, scale, ref valueCenter, ref tpos, _titlePos); Rectangle valueR = VectorRect.FromCenterSize(valueCenter, Vector.V(_valueSize)).rectangle; if (valueR.Contains(e.Location)) { // Hit in Value // Show Value Selector Window FlexibleInputWin dw; switch (_inputType) { case RTFlexInputType.String: dw = new FlexibleInputWin(_title, _stringVal); dw.StartPosition = FormStartPosition.Manual; dw.Location = PointToScreen(new Point(0, 0)); dw.ShowDialog(); _stringVal = dw.stringValue; break; case RTFlexInputType.Integer: if (_minVal < _maxVal) { dw = new FlexibleInputWin(_title, ((_unit != null) && (_unit.Length > 0))?_unit:null, (int)_minVal, (int)_maxVal, _intVal); } else { dw = new FlexibleInputWin(_title, ((_unit != null) && (_unit.Length > 0)) ? _unit : null, _intVal); } dw.StartPosition = FormStartPosition.Manual; dw.Location = PointToScreen(new Point(0, 0)); dw.ShowDialog(); _intVal = dw.intValue; break; case RTFlexInputType.Float: if (_minVal < _maxVal) { dw = new FlexibleInputWin(_title, ((_unit != null) && (_unit.Length > 0)) ? _unit : null, _minVal, _maxVal, _floatVal, _format); } else { dw = new FlexibleInputWin(_title, ((_unit != null) && (_unit.Length > 0)) ? _unit : null, _floatVal, _format); } dw.StartPosition = FormStartPosition.Manual; dw.Location = PointToScreen(new Point(0, 0)); dw.ShowDialog(); _floatVal = dw.floatValue; break; } newValue(); Invalidate(); } }