/// <summary>
            /// Draws a rectangle representing a single color key in the gradient.
            /// </summary>
            /// <param name="color">Color to display.</param>
            /// <param name="t">Time at which to draw the rectangle, in range [0, 1].</param>
            /// <param name="selected">True to draw the rectangle as selected, plain otherwise.</param>
            private void DrawColor(Color color, float t, bool selected)
            {
                int x = TimeToPixel(t);

                Vector2I a = new Vector2I(x + RECT_WIDTH / 2, 0);
                Vector2I b = new Vector2I(x + RECT_WIDTH / 2, height - 1);
                Vector2I c = new Vector2I(x - RECT_WIDTH / 2, 0);
                Vector2I d = new Vector2I(x - RECT_WIDTH / 2, height - 1);

                Vector2I[] linePoints     = new Vector2I[] { a, b, d, c, a };
                Vector2I[] trianglePoints = new Vector2I[] { a, b, c, d };

                Color colorNoAlpha = color;

                colorNoAlpha.a = 1.0f;

                canvas.DrawTriangleStrip(trianglePoints, colorNoAlpha, 102);
                canvas.DrawPolyLine(linePoints, selected ? SELECTED_COLOR : PLAIN_COLOR, 100);

                Vector2I alphaA = new Vector2I(x - 1, height - 1);
                Vector2I alphaB = new Vector2I(x + RECT_WIDTH / 2, height / 2);
                Vector2I alphaC = new Vector2I(x + RECT_WIDTH / 2, height - 1);

                canvas.DrawTriangleList(new [] { alphaA, alphaB, alphaC }, Color.White * color.a, 101);
            }
Пример #2
0
        private void OnInitialize()
        {
            canvas = new GUICanvas(GUIOption.FixedWidth(200), GUIOption.FixedHeight(200));

            {
                Vector2I a = new Vector2I(0, 0);
                Vector2I b = new Vector2I(200, 0);
                Vector2I c = new Vector2I(200, 200);
                Vector2I d = new Vector2I(0, 200);

                canvas.DrawTriangleStrip(new Vector2I[] { b, c, a, d }, Color.BansheeOrange);
            }

            {
                Vector2I a = new Vector2I(50, 20);
                Vector2I b = new Vector2I(100, 20);
                Vector2I c = new Vector2I(240, 60);

                Vector2I[] vertices = { c, b };
                canvas.DrawPolyLine(vertices, 1.0f);
            }

            GUI.AddElement(canvas);
        }