Exemplo n.º 1
0
        private void DrawCursor()
        {
            _lower = 0f;
            float bandpassOffset;
            var   bandpassWidth = 0f;
            var   cursorWidth   = Math.Max((_filterBandwidth + _filterOffset) * _xIncrement, 2);
            var   xCarrier      = (float)ClientRectangle.Width / 2 + (_frequency - _displayCenterFrequency) * _xIncrement;

            switch (_bandType)
            {
            case BandType.Upper:
                bandpassOffset = _filterOffset * _xIncrement;
                bandpassWidth  = cursorWidth - bandpassOffset;
                _lower         = xCarrier + bandpassOffset;
                break;

            case BandType.Lower:
                bandpassOffset = _filterOffset * _xIncrement;
                bandpassWidth  = cursorWidth - bandpassOffset;
                _lower         = xCarrier - bandpassOffset - bandpassWidth;
                break;

            case BandType.Center:
                _lower        = xCarrier - cursorWidth / 2;
                bandpassWidth = cursorWidth;
                break;
            }
            _upper = _lower + bandpassWidth;

            using (var transparentBrush = new SolidBrush(Color.FromArgb(80, Color.DarkGray)))
                using (var hotTrackPen = new Pen(Color.Red))
                    using (var carrierPen = new Pen(Color.Red))
                        using (var fontFamily = new FontFamily("Arial"))
                            using (var path = new GraphicsPath())
                                using (var outlinePen = new Pen(Color.Black))
                                {
                                    carrierPen.Width = CarrierPenWidth;
                                    if (cursorWidth < ClientRectangle.Width)
                                    {
                                        _graphics2.FillRectangle(transparentBrush, (int)_lower + 1, 0, (int)bandpassWidth, ClientRectangle.Height);
                                        if (xCarrier >= AxisMargin && xCarrier <= ClientRectangle.Width - AxisMargin)
                                        {
                                            _graphics2.DrawLine(carrierPen, xCarrier, 0, xCarrier, ClientRectangle.Height);
                                        }
                                    }
                                    if (_trackingX >= AxisMargin && _trackingX <= ClientRectangle.Width - AxisMargin)
                                    {
                                        if (!_changingFrequency && !_changingCenterFrequency && !_changingBandwidth)
                                        {
                                            _graphics2.DrawLine(hotTrackPen, _trackingX, 0, _trackingX, ClientRectangle.Height);
                                        }

                                        string fstring;
                                        if (_changingFrequency)
                                        {
                                            fstring = "VFO = " + SpectrumAnalyzer.GetFrequencyDisplay(_frequency);
                                        }
                                        else if (_changingBandwidth)
                                        {
                                            fstring = "BW = " + SpectrumAnalyzer.GetFrequencyDisplay(_filterBandwidth);
                                        }
                                        else if (_changingCenterFrequency)
                                        {
                                            fstring = "Center Freq. = " + SpectrumAnalyzer.GetFrequencyDisplay(_centerFrequency);
                                        }
                                        else
                                        {
                                            fstring = SpectrumAnalyzer.GetFrequencyDisplay(_trackingFrequency);
                                        }

                                        path.AddString(fstring, fontFamily, (int)FontStyle.Regular, TrackingFontSize, Point.Empty, StringFormat.GenericTypographic);
                                        var stringSize    = path.GetBounds();
                                        var currentCursor = Cursor.Current;
                                        var xOffset       = _trackingX + 15.0f;
                                        var yOffset       = _trackingY + (currentCursor == null ? SpectrumAnalyzer.DefaultCursorHeight : currentCursor.Size.Height) - 8.0f;
                                        xOffset = Math.Min(xOffset, ClientRectangle.Width - stringSize.Width - 5);
                                        yOffset = Math.Min(yOffset, ClientRectangle.Height - stringSize.Height - 5);
                                        path.Reset();
                                        path.AddString(fstring, fontFamily, (int)FontStyle.Regular, TrackingFontSize, new Point((int)xOffset, (int)yOffset), StringFormat.GenericTypographic);
                                        var smoothingMode     = _graphics2.SmoothingMode;
                                        var interpolationMode = _graphics2.InterpolationMode;
                                        _graphics2.SmoothingMode     = SmoothingMode.AntiAlias;
                                        _graphics2.InterpolationMode = InterpolationMode.HighQualityBicubic;
                                        outlinePen.Width             = 2;
                                        _graphics2.DrawPath(outlinePen, path);
                                        _graphics2.FillPath(Brushes.White, path);
                                        _graphics2.SmoothingMode     = smoothingMode;
                                        _graphics2.InterpolationMode = interpolationMode;
                                    }
                                }
        }
Exemplo n.º 2
0
        private void DrawCursor()
        {
            this._lower = 0f;
            float num  = (float)((int)Math.Max((float)this._filterBandwidth * this._xIncrement, 2f) | 1);
            float num2 = (float)this._buffer.Width * 0.5f + (float)(this._frequency - this._displayCenterFrequency) * this._xIncrement;

            switch (this._bandType)
            {
            case BandType.Upper:
                this._lower = num2;
                break;

            case BandType.Lower:
                this._lower = num2 - num;
                break;

            case BandType.Center:
                this._lower = num2 - num * 0.5f;
                break;
            }
            this._lower += (float)this._filterOffset * this._xIncrement;
            this._upper  = this._lower + num;
            using (SolidBrush brush = new SolidBrush(Color.FromArgb(80, Color.DarkGray)))
            {
                using (SolidBrush brush2 = new SolidBrush(Color.FromArgb(200, 50, 50, 50)))
                {
                    using (Pen pen5 = new Pen(Color.FromArgb(200, Color.Gray)))
                    {
                        using (Pen pen3 = new Pen(Color.DodgerBlue))
                        {
                            using (Pen pen2 = new Pen(Color.LimeGreen))
                            {
                                using (Pen pen = new Pen(Color.Red))
                                {
                                    using (FontFamily family = new FontFamily("Verdana"))
                                    {
                                        using (GraphicsPath graphicsPath = new GraphicsPath())
                                        {
                                            using (Pen pen4 = new Pen(Color.Black))
                                            {
                                                if (this._enableFilter && num < (float)this._buffer.Width)
                                                {
                                                    float num3 = this._lower;
                                                    float num4 = num;
                                                    if (this._lower < 30f)
                                                    {
                                                        num3  = 31f;
                                                        num4 -= num3 - this._lower;
                                                    }
                                                    if (this._upper > (float)(this._buffer.Width - 30))
                                                    {
                                                        num4 -= this._upper - (float)(this._buffer.Width - 30);
                                                    }
                                                    this._graphics2.FillRectangle(brush, num3, 0f, num4, (float)this._buffer.Height);
                                                }
                                                if (this._enableFrequencyMarker && num2 > 30f && num2 < (float)(this._buffer.Width - 30))
                                                {
                                                    pen.Width = 1f;
                                                    this._graphics2.DrawLine(pen, num2, 0f, num2, (float)this._buffer.Height);
                                                }
                                                if (this._enableHotTracking && this._cursorPosition.X >= 30 && this._cursorPosition.X <= this._buffer.Width - 30)
                                                {
                                                    if (this.Cursor != Cursors.SizeWE && ((float)this._cursorPosition.X < this._lower || (float)this._cursorPosition.X > this._upper) && !this._changingFrequency && !this._changingCenterFrequency && !this._changingBandwidth)
                                                    {
                                                        pen2.DashStyle = DashStyle.Dash;
                                                        this._graphics2.DrawLine(pen3, this._snappedX, 0f, this._snappedX, (float)this._buffer.Height);
                                                        float num5 = num / 2f;
                                                        switch (this._bandType)
                                                        {
                                                        case BandType.Center:
                                                            this._graphics2.DrawLine(pen2, this._snappedX - num5, 0f, this._snappedX - num5, (float)this._buffer.Height);
                                                            this._graphics2.DrawLine(pen2, this._snappedX + num5, 0f, this._snappedX + num5, (float)this._buffer.Height);
                                                            break;

                                                        case BandType.Lower:
                                                            this._graphics2.DrawLine(pen2, this._snappedX - num, 0f, this._snappedX - num, (float)this._buffer.Height);
                                                            break;

                                                        case BandType.Upper:
                                                            this._graphics2.DrawLine(pen2, this._snappedX + num, 0f, this._snappedX + num, (float)this._buffer.Height);
                                                            break;
                                                        }
                                                    }
                                                    string s = (this._changingBandwidth || this.Cursor == Cursors.SizeWE) ? ("Bandwidth: " + SpectrumAnalyzer.GetFrequencyDisplay(this._filterBandwidth)) : (string.IsNullOrEmpty(this._customTitle) ? ((this._changingFrequency || ((float)this._cursorPosition.X >= this._lower && (float)this._cursorPosition.X <= this._upper)) ? ("VFO: " + SpectrumAnalyzer.GetFrequencyDisplay(this._frequency)) : ((!this._changingCenterFrequency) ? SpectrumAnalyzer.GetFrequencyDisplay(this._trackingFrequency) : ("Center Frequency: " + SpectrumAnalyzer.GetFrequencyDisplay(this._centerFrequency)))) : this._customTitle);
                                                    graphicsPath.AddString(s, family, 0, 16f, Point.Empty, StringFormat.GenericTypographic);
                                                    RectangleF bounds  = graphicsPath.GetBounds();
                                                    Cursor     current = Cursor.Current;
                                                    float      val     = (float)this._cursorPosition.X + 30f;
                                                    float      val2    = (float)this._cursorPosition.Y + ((current == (Cursor)null) ? 32f : ((float)current.Size.Height)) - 8f;
                                                    val  = Math.Min(val, (float)this._buffer.Width - bounds.Width - 30f - 20f);
                                                    val2 = Math.Min(val2, (float)this._buffer.Height - bounds.Height - 20f);
                                                    graphicsPath.Reset();
                                                    graphicsPath.AddString(s, family, 0, 16f, new Point((int)val, (int)val2), StringFormat.GenericTypographic);
                                                    SmoothingMode     smoothingMode     = this._graphics2.SmoothingMode;
                                                    InterpolationMode interpolationMode = this._graphics2.InterpolationMode;
                                                    this._graphics2.SmoothingMode     = SmoothingMode.AntiAlias;
                                                    this._graphics2.InterpolationMode = InterpolationMode.HighQualityBilinear;
                                                    pen4.Width = 2f;
                                                    RectangleF bounds2 = graphicsPath.GetBounds();
                                                    bounds2.X      -= 10f;
                                                    bounds2.Y      -= 10f;
                                                    bounds2.Width  += 20f;
                                                    bounds2.Height += 20f;
                                                    this._graphics2.FillRoundedRectangle(brush2, bounds2, 6);
                                                    this._graphics2.DrawRoundedRectangle(pen5, bounds2, 6);
                                                    this._graphics2.DrawPath(pen4, graphicsPath);
                                                    this._graphics2.FillPath(Brushes.White, graphicsPath);
                                                    this._graphics2.SmoothingMode     = smoothingMode;
                                                    this._graphics2.InterpolationMode = interpolationMode;
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }