Esempio n. 1
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;
            }
        }
Esempio n. 2
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);
            }
        }