// 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); } }
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; } Vector center = Vector.V(Width / 2, Height / 2); if (_showValue && e.Y >= center.y + _dialDiameter * scl / 2) { // 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(); } else if (Math.Sqrt(sqr(e.X - center.x) + sqr(e.Y - center.y)) < _dialDiameter * scl / 2) { // Hit in Dial Region Vector dist = Vector.V(e.Location) - Vector.V(Width / 2, Height / 2); double phit = (-dist).Phi; if (phit < -Math.PI / 2) { phit += 2.0 * Math.PI; } double n = (phit + Math.PI / 4) / (1.5 * Math.PI); if (n < 0) { n = 0; } if (n > 1) { 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); } }