Exemplo n.º 1
0
        private void DrawIndicatorV(Rect rect, float value, float minV, float maxV)
        {
            GUI.BeginGroup(rect);

            bool clamped = false;

            if (value < minV)
            {
                value   = minV;
                clamped = true;
            }
            if (value > maxV)
            {
                value   = maxV;
                clamped = true;
            }

            float sx = rect.width;
            float sy = rect.height;

            GUI.Box(new Rect(0, 0, sx, sy), "");

            Color color = XKCDColors.NeonGreen;

            float spacing  = (float)Math.Floor(sy * 0.11f + 0.5f);
            float middle   = (float)Math.Floor(sy * 0.5f + 0.5f);
            Rect  lineRect = new Rect(3, 0, sx - 6, 1);

            for (float y = middle + spacing; y < sy; y += spacing)
            {
                lineRect.y = y;
                Drawing.DrawRect(lineRect, color);
            }

            for (float y = middle - spacing; y > 0; y -= spacing)
            {
                lineRect.y = y;
                Drawing.DrawRect(lineRect, color);
            }

            lineRect.y      = middle - 1;
            lineRect.x      = 1;
            lineRect.width  = sx - 3;
            lineRect.height = 3;
            color           = XKCDColors.NeonBlue;

            Drawing.DrawRect(lineRect, color);

            // our box runs for 0 to sy-1
            // we do not want diamond to get clipped
            // so lowest y should be 0 and highest should be (sy-1)-9
            // center should draw at middle - 4
            float frac  = -0.5f + (value - minV) / (maxV - minV);            // range -0.5 to 0.5
            float range = (sy - 1) - 9;
            float yy    = middle + range * frac - 4;

            Color dcolor = clamped ? XKCDColors.NeonRed : XKCDColors.NeonBlue;

            Drawing.DrawDiamond(new Rect(3, yy, 15, 9), dcolor);

            GUI.EndGroup();
        }