Пример #1
0
        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);
            }
        }
Пример #2
0
        // 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);
            }
        }