예제 #1
0
        /// <summary>
        /// Draw waveform. Argument's units are grid divisions (GD)
        /// </summary>
        /// <param name="channel">Channel</param>
        /// <param name="smpBeg">Index of first sample</param>
        /// <param name="smpEnd">Index of last sample</param>
        /// <param name="pxStart">Start pixel</param>
        /// <param name="pxPerSample">Pixels per sample</param>
        /// <param name="color">Waveform color</param>
        public void PlotFloatLogic(
            OscChannel channel,
            int smpBeg,
            int smpEnd,
            float pxStart,
            float pxPerSample,
            Color color)
        {
            // do not render empty buffer
            const int CHAR_OFFSET_Y = -10;
            const int CHAR_OFFSET_X = -66;
            var       position      = channel.Position;
            var       texCenterY    = oscSettings.textureCenter.y;
            var       pixPerDivs    = oscSettings.pixelsPerDivision;
            var       topY          = Mathf.RoundToInt((position + channel.Scale) * pixPerDivs + texCenterY);
            var       botY          = Mathf.RoundToInt(position * pixPerDivs + texCenterY);
            // first sample position
            var fpx = pxStart;
            var x1  = Mathf.RoundToInt(pxStart - pxPerSample);
            var v1  = (int)(channel.GetFloat(smpBeg - 1) - position);

            // iterate over all samples (starts from sample 2)
            for (var i = smpBeg; i <= smpEnd; i++)
            {
                var x2 = Mathf.RoundToInt(fpx);
                var v2 = (int)(channel.GetFloat(i) - position);
                if (v1 == v2)
                {
                    if (i != smpEnd)
                    {
                        v1   = v2;
                        fpx += pxPerSample;
                        continue;                         // skip
                    }
                    else
                    {
                        // horizontal lines
                        OscUtils.PlotLine(screenTexture, x1, topY, x2 - 1, topY, color);
                        OscUtils.PlotLine(screenTexture, x1, botY, x2 - 1, botY, color);
                        return;
                    }
                }
                // horizontal lines
                OscUtils.PlotLine(screenTexture, x1, topY, x2 - 2, topY, color);
                OscUtils.PlotLine(screenTexture, x1, botY, x2 - 2, botY, color);
                // cross over lines
                OscUtils.PlotLine(screenTexture, x2 - 2, topY, x2, botY, color);
                OscUtils.PlotLine(screenTexture, x2 - 2, botY, x2, topY, color);
                // display value (previous value)
                OscFont.DrawText(screenTexture, v1.ToString("x8"), x2 + CHAR_OFFSET_X, botY + CHAR_OFFSET_Y, color);
                x1   = x2;
                v1   = v2;
                fpx += pxPerSample;
            }
        }
예제 #2
0
        /// <summary>
        /// Draw waveform. Argument's units are grid divisions (GD)
        /// </summary>
        /// <param name="channel">Channel</param>
        /// <param name="smpBeg">Index of first sample</param>
        /// <param name="smpEnd">Index of last sample</param>
        /// <param name="pxStart">Start pixel</param>
        /// <param name="pxPerSample">Pixels per sample</param>
        /// <param name="color">Waveform color</param>
        public void PlotVector2(
            OscChannel channel,
            int smpBeg,
            int smpEnd,
            float pxStart,
            float pxPerSample,
            Color color)
        {
            // do not render empty buffer
            var texCenterY = oscSettings.textureCenter.y;
            var pixPerDivs = oscSettings.pixelsPerDivision;
            // first sample position
            var fpx    = pxStart;
            var x1     = Mathf.RoundToInt(pxStart - pxPerSample);
            var sample = channel.GetVector2(smpBeg - 1);
            var y1a    = Mathf.RoundToInt(sample.x * pixPerDivs + texCenterY);
            var y1b    = Mathf.RoundToInt(sample.y * pixPerDivs + texCenterY);

            // iterate over all samples (starts from sample 2)
            for (var i = smpBeg; i <= smpEnd; i++)
            {
                var x2 = Mathf.RoundToInt(fpx);
                sample = channel.GetVector2(i);
                var y2a = Mathf.RoundToInt(sample.x * pixPerDivs + texCenterY);
                var y2b = Mathf.RoundToInt(sample.y * pixPerDivs + texCenterY);
                // first line at the sample 2
                var dx = Math.Abs(x1 - x2);

                var dya = Math.Abs(y1a - y2a);
                if (dx > 1 || dya > 1)
                {
                    OscUtils.PlotLine(screenTexture, x1, y1a, x2, y2a, colorX);
                }
                else
                {
                    screenTexture.SetPixel(x2, y2a, colorX);
                }

                var dyb = Math.Abs(y1b - y2b);
                if (dx > 1 || dyb > 1)
                {
                    OscUtils.PlotLine(screenTexture, x1, y1b, x2, y2b, colorY);
                }
                else
                {
                    screenTexture.SetPixel(x2, y2b, colorY);
                }

                x1   = x2;
                y1a  = y2a;
                y1b  = y2b;
                fpx += pxPerSample;
            }
        }
예제 #3
0
        // ============================================================================================
        // Draw grid
        // ============================================================================================

        /// <summary>
        /// Draw oscilloscope grid
        /// </summary>
        /// <param name="color"></param>
        public void PlotGrid(Color color)
        {
            var w       = oscSettings.textureSize.x;
            var h       = oscSettings.textureSize.y;
            var xcenter = oscSettings.textureCenter.x;
            var ycenter = oscSettings.textureCenter.y;
            var pxDiv   = oscSettings.pixelsPerDivision;
            var pxSub   = oscSettings.pixelsPerSubdivision;

            if (drawGrid)
            {
                // -- draw main grid
                for (var x = xcenter; x < w; x += pxDiv)
                {
                    PlotDotedLineVertical(screenTexture, x, ycenter, pxSub, color);
                }
                for (var x = xcenter - pxDiv; x >= 0; x -= pxDiv)
                {
                    PlotDotedLineVertical(screenTexture, x, ycenter, pxSub, color);
                }
                for (var y = ycenter; y < h; y += pxDiv)
                {
                    PlotDotedLineHorizontal(screenTexture, xcenter, y, pxSub, color);
                }
                for (var y = ycenter - pxDiv; y >= 0; y -= pxDiv)
                {
                    PlotDotedLineHorizontal(screenTexture, xcenter, y, pxSub, color);
                }
            }

            if (drawRulerX)
            {
                // -- draw horizontal ruler bar in center
                PlotDotedLineHorizontal(screenTexture, xcenter, ycenter + 2, pxSub, color);
                PlotDotedLineHorizontal(screenTexture, xcenter, ycenter + 1, pxSub, color);
                PlotDotedLineHorizontal(screenTexture, xcenter, ycenter - 1, pxSub, color);
                PlotDotedLineHorizontal(screenTexture, xcenter, ycenter - 2, pxSub, color);
            }

            if (drawRulerY)
            {
                // -- draw verticals ruler bar in center
                PlotDotedLineVertical(screenTexture, xcenter + 2, ycenter, pxSub, color);
                PlotDotedLineVertical(screenTexture, xcenter + 1, ycenter, pxSub, color);
                PlotDotedLineVertical(screenTexture, xcenter - 1, ycenter, pxSub, color);
                PlotDotedLineVertical(screenTexture, xcenter - 2, ycenter, pxSub, color);
            }

            // -- draw frame around
            OscUtils.PlotRectangle(screenTexture, 0, 0, w - 1, h - 1, color);
        }
예제 #4
0
        // ============================================================================================
        // Draw time diagram on screen
        // ============================================================================================

        /// <summary>
        ///     Draw waveform. Argument's units are grid divisions (GD)
        /// </summary>
        /// <param name="channel">Channel</param>
        /// <param name="smpBeg">Index of first sample</param>
        /// <param name="smpEnd">Index of last sample</param>
        /// <param name="pxStart">Start pixel</param>
        /// <param name="pxPerSample">Pixels per sample</param>
        /// <param name="color">Waveform color</param>
        public void PlotFloat(
            OscChannel channel,
            int smpBeg,
            int smpEnd,
            float pxStart,
            float pxPerSample,
            Color color)
        {
            // do not render empty buffer
            var texCenterY = oscSettings.textureCenter.y;
            var pixPerDivs = oscSettings.pixelsPerDivision;
            // first sample position
            var fpx = pxStart;
            var x1  = Mathf.RoundToInt(pxStart - pxPerSample);
            var y1  = Mathf.RoundToInt(channel.GetFloat(smpBeg - 1) * pixPerDivs + texCenterY);

            y1 = oscSettings.ClampPixelInsideScreenY(y1);
            // iterate over all samples (starts from sample 2)
            for (var i = smpBeg; i <= smpEnd; i++)
            {
                var x2 = Mathf.RoundToInt(fpx);
                var y2 = Mathf.RoundToInt(channel.GetFloat(i) * pixPerDivs + texCenterY);
                y2 = oscSettings.ClampPixelInsideScreenY(y2);
                // first line at the sample 2
                var absDx = Math.Abs(x1 - x2);
                var absDy = Math.Abs(y1 - y2);
                if (absDx > 1 || absDy > 1)
                {
                    OscUtils.PlotLine(screenTexture, x1, y1, x2, y2, color);
                }
                else
                {
                    screenTexture.SetPixel(x2, y2, color);
                }
                x1   = x2;
                y1   = y2;
                fpx += pxPerSample;
            }
        }
예제 #5
0
        /// <summary>
        /// Draw marker at the x,y position in the division units
        /// </summary>
        /// <param name="text"></param>
        /// <param name="color"></param>
        /// <param name="x"></param>
        /// <param name="y"></param>
        /// <param name="scale">Vertical scale</param>
        /// <param name="position">Vertical position</param>
        /// <param name="clampPosition">If label does not fit on screen render it with blinking</param>
        public void DrawLabel(string text, float x, float y, Color color, bool clampPosition = false)
        {
            var pxX      = oscSettings.GetPixelPositionIntX(x);
            var pxY      = oscSettings.GetPixelPositionIntY(y);
            var isNotFit = !oscSettings.TestPixelInsideScreenY(pxY);

            if (isNotFit)
            {
                // if the label outside it modify name
                if (clampPosition)
                {
                    pxY   = oscSettings.ClampPixelInsideScreenY(pxY);
                    text += '!';                     // mark it clamped
                }
                else
                {
                    return;                     // do not render label outside
                }
            }
            // Render little cross hor. and vert. lines.
            OscUtils.PlotLine(screenTexture, pxX, pxY, pxX + 16, pxY, color);
            OscUtils.PlotLine(screenTexture, pxX, pxY - 8, pxX, pxY + 8, color);
            // Render text (if text is not fit move it below the line)
            const int CHAR_HEIGHT = 8;
            const int CHAR_OFFSET = 2;

            if (pxY < oscSettings.textureSize.y - (CHAR_HEIGHT + CHAR_OFFSET))
            {
                // fit on screen
                OscFont.DrawText(screenTexture, text, pxX + 1, pxY + CHAR_OFFSET, color);
            }
            else
            {
                // does not fit on screen
                OscFont.DrawText(screenTexture, text, pxX + 1, pxY - (CHAR_HEIGHT + CHAR_OFFSET), color);
            }
        }
예제 #6
0
        /// <summary>
        /// Draw horizontal line at position Y
        /// </summary>
        /// <param name="color"></param>
        /// <param name="y"></param>
        /// <param name="scale"></param>
        /// <param name="position"></param>
        public void DrawHorizontalLine(float y, Color color)
        {
            var pxY = oscSettings.GetPixelPositionIntY(y);

            OscUtils.PlotLine(screenTexture, 1, pxY, oscSettings.textureSize.x - 1, pxY, color);
        }