Beispiel #1
0
        void _drawFFTVerticalGridLines(CustomGraphics g)
        {
            /* Draw x-grid lines and label the frequencies in the FFT that they point to. */
            int    prevEnd      = 0;
            int    divs         = 20;
            double maxFrequency = 1 / (ControlPanel.TimeStep * Speed * divs * 2);

            g.LineColor = Color.FromArgb(0x88, 0x00, 0x00);
            for (int i = 0; i < divs; i++)
            {
                int x = BoundingBox.Width * i / divs;
                if (x < prevEnd)
                {
                    continue;
                }
                string s      = ((int)Math.Round(i * maxFrequency)) + "Hz";
                int    sWidth = (int)Math.Ceiling(g.GetTextSize(s).Width);
                prevEnd = x + sWidth + 4;
                if (i > 0)
                {
                    g.DrawLine(x, 0, x, BoundingBox.Height);
                }
                g.DrawLeftText(s, x + 2, BoundingBox.Height - 12);
            }
        }
Beispiel #2
0
        void _drawCrosshairs(CustomGraphics g)
        {
            if (CirSim.Sim.DialogIsShowing())
            {
                return;
            }
            if (!BoundingBox.Contains(CirSim.Sim.MouseCursorX, CirSim.Sim.MouseCursorY))
            {
                return;
            }
            if (SelectedPlot < 0 && !ShowFFT)
            {
                return;
            }
            var info = new string[4];
            int ipa  = mPlots[0].StartIndex(BoundingBox.Width);
            int ip   = (CirSim.Sim.MouseCursorX - BoundingBox.X + ipa) & (mScopePointCount - 1);
            int ct   = 0;
            int maxy = (BoundingBox.Height - 1) / 2;
            int y    = maxy;

            if (SelectedPlot >= 0)
            {
                var plot = mVisiblePlots[SelectedPlot];
                info[ct++] = plot.GetUnitText(plot.MaxValues[ip]);
                int maxvy = (int)(mMainGridMult * (plot.MaxValues[ip] - mMainGridMid));
                g.LineColor = plot.Color;
                g.FillCircle(CirSim.Sim.MouseCursorX, BoundingBox.Y + y - maxvy, 2.5f);
            }
            if (ShowFFT)
            {
                double maxFrequency = 1 / (ControlPanel.TimeStep * Speed * 2);
                info[ct++] = Utils.UnitText(maxFrequency * (CirSim.Sim.MouseCursorX - BoundingBox.X) / BoundingBox.Width, "Hz");
            }
            if (mVisiblePlots.Count > 0)
            {
                double t = CirSim.Sim.Time - ControlPanel.TimeStep * Speed * (BoundingBox.X + BoundingBox.Width - CirSim.Sim.MouseCursorX);
                info[ct++] = Utils.TimeText(t);
            }

            int szw = 0, szh = 15 * ct;

            for (int i = 0; i != ct; i++)
            {
                int w = (int)g.GetTextSize(info[i]).Width;
                if (w > szw)
                {
                    szw = w;
                }
            }

            g.LineColor = CustomGraphics.WhiteColor;
            g.DrawLine(CirSim.Sim.MouseCursorX, BoundingBox.Y, CirSim.Sim.MouseCursorX, BoundingBox.Y + BoundingBox.Height);

            int bx = CirSim.Sim.MouseCursorX;

            if (bx < szw / 2)
            {
                bx = szw / 2;
            }

            g.LineColor = ControlPanel.ChkPrintable.Checked ? Color.White : Color.Black;
            g.FillRectangle(bx - szw / 2, BoundingBox.Y - szh, szw, szh);

            for (int i = 0; i != ct; i++)
            {
                int w = (int)g.GetTextSize(info[i]).Width;
                g.DrawLeftText(info[i], bx - w / 2, BoundingBox.Y - 2 - (ct - 1 - i) * 15);
            }
        }